Skip to content

Commit b3fe0aa

Browse files
authored
Hexdump fix&update (esp8266#7831)
* hexdump() must be "C"; add ascii data in dump * remove previous version
1 parent 11a2fb3 commit b3fe0aa

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

cores/esp8266/debug.cpp

+40-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,53 @@
11
/*
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.
55
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.
1010
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.
1515
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+
*/
2020

2121
#include "Arduino.h"
2222
#include "debug.h"
2323
#include "osapi.h"
2424

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));
3237
}
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();
3551
}
3652
os_printf("\n");
3753
}

cores/esp8266/debug.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#endif
1414

1515
#ifdef __cplusplus
16-
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16);
16+
extern "C" void hexdump(const void *mem, uint32_t len, uint8_t cols = 16);
1717
#else
1818
void hexdump(const void *mem, uint32_t len, uint8_t cols);
1919
#endif

tests/host/common/mock.h

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ extern "C" {
103103
int ets_printf (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
104104
#define os_printf_plus printf
105105
#define ets_vsnprintf vsnprintf
106+
inline void ets_putc (char c) { putchar(c); }
106107

107108
int mockverbose (const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
108109

tests/restyle.sh

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ libraries/Wire
1616
libraries/lwIP*
1717
cores/esp8266/Lwip*
1818
cores/esp8266/core_esp8266_si2c.cpp
19+
cores/esp8266/debug*
1920
libraries/Netdump
2021
"
2122

0 commit comments

Comments
 (0)