diff options
author | Christopher Ferris <cferris@google.com> | 2015-11-30 13:36:08 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2015-11-30 14:39:52 -0800 |
commit | da750a79c9fe503d52feb7af2c417b19f763649c (patch) | |
tree | e76b3c1ffc3be2112772d803a471f60fc587d6d9 /libbacktrace | |
parent | e08e4656db4454fb44cf3ee95d0eda75230086f1 (diff) | |
download | core-da750a79c9fe503d52feb7af2c417b19f763649c.tar.gz core-da750a79c9fe503d52feb7af2c417b19f763649c.tar.bz2 core-da750a79c9fe503d52feb7af2c417b19f763649c.zip |
Change the way some maps are printed.
Before, an anonymous map wound up printing the pc as relative.
Unfortunately, this meant that it was impossible to tell the actual
pc. The new code prints the map name as <anonymous:map_start> and
still prints the pc as relative.
In addition, add the start of the map for map names that begin with a
'[' character.
Bug: 25844836
Change-Id: Ie0b6149dde258fe13f0e5a3e5739d85374512f4b
Diffstat (limited to 'libbacktrace')
-rw-r--r-- | libbacktrace/Backtrace.cpp | 22 | ||||
-rw-r--r-- | libbacktrace/backtrace_test.cpp | 21 |
2 files changed, 33 insertions, 10 deletions
diff --git a/libbacktrace/Backtrace.cpp b/libbacktrace/Backtrace.cpp index 9ead452cf..555e8cf20 100644 --- a/libbacktrace/Backtrace.cpp +++ b/libbacktrace/Backtrace.cpp @@ -93,16 +93,26 @@ std::string Backtrace::FormatFrameData(size_t frame_num) { } std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { - const char* map_name; - if (BacktraceMap::IsValid(frame->map) && !frame->map.name.empty()) { - map_name = frame->map.name.c_str(); + uintptr_t relative_pc; + std::string map_name; + if (BacktraceMap::IsValid(frame->map)) { + relative_pc = BacktraceMap::GetRelativePc(frame->map, frame->pc); + if (!frame->map.name.empty()) { + map_name = frame->map.name.c_str(); + if (map_name[0] == '[' && map_name[map_name.size() - 1] == ']') { + map_name.resize(map_name.size() - 1); + map_name += StringPrintf(":%" PRIPTR "]", frame->map.start); + } + } else { + map_name = StringPrintf("<anonymous:%" PRIPTR ">", frame->map.start); + } } else { map_name = "<unknown>"; + relative_pc = frame->pc; } - uintptr_t relative_pc = BacktraceMap::GetRelativePc(frame->map, frame->pc); - - std::string line(StringPrintf("#%02zu pc %" PRIPTR " %s", frame->num, relative_pc, map_name)); + std::string line(StringPrintf("#%02zu pc %" PRIPTR " ", frame->num, relative_pc)); + line += map_name; // Special handling for non-zero offset maps, we need to print that // information. if (frame->map.offset != 0) { diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index 9ebd63913..ce04817db 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -775,16 +775,29 @@ TEST(libbacktrace, format_test) { backtrace->FormatFrameData(&frame)); // Check map name empty, but exists. - frame.map.start = 1; - frame.map.end = 1; + frame.pc = 0xb0020; + frame.map.start = 0xb0000; + frame.map.end = 0xbffff; frame.map.load_base = 0; #if defined(__LP64__) - EXPECT_EQ("#01 pc 0000000000000001 <unknown>", + EXPECT_EQ("#01 pc 0000000000000020 <anonymous:00000000000b0000>", #else - EXPECT_EQ("#01 pc 00000001 <unknown>", + EXPECT_EQ("#01 pc 00000020 <anonymous:000b0000>", #endif backtrace->FormatFrameData(&frame)); + // Check map name begins with a [. + frame.pc = 0xc0020; + frame.map.start = 0xc0000; + frame.map.end = 0xcffff; + frame.map.load_base = 0; + frame.map.name = "[anon:thread signal stack]"; +#if defined(__LP64__) + EXPECT_EQ("#01 pc 0000000000000020 [anon:thread signal stack:00000000000c0000]", +#else + EXPECT_EQ("#01 pc 00000020 [anon:thread signal stack:000c0000]", +#endif + backtrace->FormatFrameData(&frame)); // Check relative pc is set and map name is set. frame.pc = 0x12345679; |