Move map data into backtrace data proper.
The backtrace structure used to include a pointer to a backtrace_map_t
that represented the map data for a particular pc. This introduced a
race condition where the pointer could be discarded, but the backtrace
structure still contained a pointer to garbage memory. Now all of the map
information is right in the structure.
Bug: 19028453
Change-Id: If7088a73f3c6bf1f3bc8cdd2bb4b62e7cab831c0
diff --git a/libbacktrace/BacktraceImpl.cpp b/libbacktrace/BacktraceImpl.cpp
index 405b042..fb8a725 100644
--- a/libbacktrace/BacktraceImpl.cpp
+++ b/libbacktrace/BacktraceImpl.cpp
@@ -99,15 +99,15 @@
std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) {
const char* map_name;
- if (frame->map && !frame->map->name.empty()) {
- map_name = frame->map->name.c_str();
+ if (BacktraceMap::IsValid(frame->map) && !frame->map.name.empty()) {
+ map_name = frame->map.name.c_str();
} else {
map_name = "<unknown>";
}
uintptr_t relative_pc;
- if (frame->map) {
- relative_pc = frame->pc - frame->map->start;
+ if (BacktraceMap::IsValid(frame->map)) {
+ relative_pc = frame->pc - frame->map.start;
} else {
relative_pc = frame->pc;
}
@@ -128,8 +128,8 @@
return buf;
}
-const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) {
- return map_->Find(pc);
+void Backtrace::FillInMap(uintptr_t pc, backtrace_map_t* map) {
+ map_->FillIn(pc, map);
}
//-------------------------------------------------------------------------
@@ -147,8 +147,9 @@
return false;
}
- const backtrace_map_t* map = FindMap(ptr);
- if (map && map->flags & PROT_READ) {
+ backtrace_map_t map;
+ FillInMap(ptr, &map);
+ if (BacktraceMap::IsValid(map) && map.flags & PROT_READ) {
*out_value = *reinterpret_cast<word_t*>(ptr);
return true;
} else {