From 1e315d97988642f3cf7427fee752340439aa3f6b Mon Sep 17 00:00:00 2001 From: Oxore Date: Sat, 9 Mar 2024 21:05:06 +0300 Subject: Add support for hex numbers in PC trace table --- src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index a79a0e3..8b6412b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1003,17 +1003,18 @@ static bool RenderDisassembly( static void ParseTraceData(DisasmMap &disasm_map, const DataView &trace_data) { - // FIXME make a full blown parser with various radixes support and different - // trace types support bool parse = true; for (size_t i = 0; i < trace_data.size; i++) { if (trace_data.buffer[i] == '\n' || trace_data.buffer[i] == '\r') { parse = true; } else if (parse) { errno = 0; + // Base 0 enabled strtol to parse octal and hexadecimal numbers with + // prefixes like 0 or 0x. See `man strtol.3p`. + constexpr int base = 0; const char *startptr = reinterpret_cast(trace_data.buffer + i); char *endptr = nullptr; - const long address = strtol(startptr, &endptr, 10); + const long address = strtol(startptr, &endptr, base); if ((address == LONG_MAX || address == LONG_MIN) && errno == ERANGE) { // Parsing error, just skip } else if (startptr == endptr) { -- cgit v1.2.3