OSDN Git Service

simpleperf: Fix cached map in OfflineUnwinder.
authorYabin Cui <yabinc@google.com>
Wed, 7 Mar 2018 23:55:48 +0000 (15:55 -0800)
committerYabin Cui <yabinc@google.com>
Wed, 7 Mar 2018 23:55:48 +0000 (15:55 -0800)
In system wide profiling, sometimes a sample record goes before all
mmap records of a process. Then thread.maps->version = 0 and
cached_map.map isn't created.

This is caught by simpleperf_unit_test.

Bug: none
Test: run simpleperf_unit_test.
Change-Id: I99254396d0fb22531f735ff3193b8d3b1f9641dd

simpleperf/OfflineUnwinder.cpp

index ae33caf..9d56144 100644 (file)
@@ -131,7 +131,7 @@ bool OfflineUnwinder::UnwindCallChain(const ThreadEntry& thread, const RegSet& r
   auto map_it = cached_maps_.find(thread.pid);
   CachedMap& cached_map = (map_it == cached_maps_.end() ? cached_maps_[thread.pid]
                                                         : map_it->second);
-  if (cached_map.version < thread.maps->version) {
+  if (!cached_map.map || cached_map.version < thread.maps->version) {
     std::vector<backtrace_map_t> bt_maps(thread.maps->maps.size());
     size_t map_index = 0;
     for (auto& map : thread.maps->maps) {