|
1 | 1 | /*
|
2 |
| - debug.cpp - debug helper functions |
3 |
| - Copyright (c) 2015 Markus Sattler. All rights reserved. |
4 |
| - This file is part of the esp8266 core for Arduino environment. |
| 2 | + debug.cpp - debug helper functions |
| 3 | + Copyright (c) 2015 Markus Sattler. All rights reserved. |
| 4 | + This file is part of the esp8266 core for Arduino environment. |
5 | 5 |
|
6 |
| - This library is free software; you can redistribute it and/or |
7 |
| - modify it under the terms of the GNU Lesser General Public |
8 |
| - License as published by the Free Software Foundation; either |
9 |
| - version 2.1 of the License, or (at your option) any later version. |
| 6 | + This library is free software; you can redistribute it and/or |
| 7 | + modify it under the terms of the GNU Lesser General Public |
| 8 | + License as published by the Free Software Foundation; either |
| 9 | + version 2.1 of the License, or (at your option) any later version. |
10 | 10 |
|
11 |
| - This library is distributed in the hope that it will be useful, |
12 |
| - but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
| - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
| - Lesser General Public License for more details. |
| 11 | + This library is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + Lesser General Public License for more details. |
15 | 15 |
|
16 |
| - You should have received a copy of the GNU Lesser General Public |
17 |
| - License along with this library; if not, write to the Free Software |
18 |
| - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 |
| - */ |
| 16 | + You should have received a copy of the GNU Lesser General Public |
| 17 | + License along with this library; if not, write to the Free Software |
| 18 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | +*/ |
20 | 20 |
|
21 | 21 | #include "Arduino.h"
|
22 | 22 | #include "debug.h"
|
23 | 23 | #include "osapi.h"
|
24 | 24 |
|
25 |
| -void ICACHE_RAM_ATTR hexdump(const void *mem, uint32_t len, uint8_t cols) { |
26 |
| - const uint8_t* src = (const uint8_t*) mem; |
27 |
| - os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); |
28 |
| - for(uint32_t i = 0; i < len; i++) { |
29 |
| - if(i % cols == 0) { |
30 |
| - os_printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); |
31 |
| - yield(); |
| 25 | +IRAM_ATTR |
| 26 | +void hexdump(const void *mem, uint32_t len, uint8_t cols) |
| 27 | +{ |
| 28 | + const char* src = (const char*)mem; |
| 29 | + os_printf("\n[HEXDUMP] Address: %p len: 0x%X (%d)", src, len, len); |
| 30 | + while (len > 0) |
| 31 | + { |
| 32 | + uint32_t linesize = cols > len ? len : cols; |
| 33 | + os_printf("\n[%p] 0x%04x: ", src, src - (const char*)mem); |
| 34 | + for (uint32_t i = 0; i < linesize; i++) |
| 35 | + { |
| 36 | + os_printf("%02x ", *(src + i)); |
32 | 37 | }
|
33 |
| - os_printf("%02X ", *src); |
34 |
| - src++; |
| 38 | + os_printf(" "); |
| 39 | + for (uint32_t i = linesize; i < cols; i++) |
| 40 | + { |
| 41 | + os_printf(" "); |
| 42 | + } |
| 43 | + for (uint32_t i = 0; i < linesize; i++) |
| 44 | + { |
| 45 | + unsigned char c = *(src + i); |
| 46 | + os_putc(isprint(c) ? c : '.'); |
| 47 | + } |
| 48 | + src += linesize; |
| 49 | + len -= linesize; |
| 50 | + yield(); |
35 | 51 | }
|
36 | 52 | os_printf("\n");
|
37 | 53 | }
|
0 commit comments