summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2024-03-09 21:05:06 +0300
committerOxore <oxore@protonmail.com>2024-03-09 21:05:54 +0300
commit1e315d97988642f3cf7427fee752340439aa3f6b (patch)
treefe075bcb9781e74975f84f97d44ad11282514b76
parent1b52c6284d47966050a04e162adfc8026e4e9281 (diff)
Add support for hex numbers in PC trace table
-rw-r--r--src/main.cpp7
1 files changed, 4 insertions, 3 deletions
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<const char *>(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) {