From 6342e0bc38b060a34784d7d63374aa35fc9f1707 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Fri, 1 Apr 2022 12:49:05 -0700 Subject: simpleperf: fix a segfault caused by CloseEventFiles. In aosp/2052096, simpleperf closes event files when stopping recording. After that, GetEventAttrWithId()[0].ids is empty, which makes ProcessJITDebugInfo() segfault. To fix it, save result of GetEventAttrWithId() in dumping_attr_id_ when preparing recording, and use dumping_attr_id_ in ProcessJITDebugInfo(). Bug: 227220328 Test: run simpleperf_unit_test Change-Id: I99678ff5defc7ca998a08b2cec22f7a84d1ed7bd --- simpleperf/cmd_record.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 35cab822..4b79eedc 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -1285,8 +1285,9 @@ bool RecordCommand::CreateAndInitRecordFile() { return false; } // Use first perf_event_attr and first event id to dump mmap and comm records. - EventAttrWithId dumping_attr_id = event_selection_set_.GetEventAttrWithId()[0]; - map_record_reader_.emplace(*dumping_attr_id.attr, dumping_attr_id.ids[0], + dumping_attr_id_ = event_selection_set_.GetEventAttrWithId()[0]; + CHECK(!dumping_attr_id_.ids.empty()); + map_record_reader_.emplace(*dumping_attr_id_.attr, dumping_attr_id_.ids[0], event_selection_set_.RecordNotExecutableMaps()); map_record_reader_->SetCallback([this](Record* r) { return ProcessRecord(r); }); @@ -1510,14 +1511,13 @@ bool RecordCommand::SaveRecordWithoutUnwinding(Record* record) { bool RecordCommand::ProcessJITDebugInfo(const std::vector& debug_info, bool sync_kernel_records) { - EventAttrWithId attr_id = event_selection_set_.GetEventAttrWithId()[0]; for (auto& info : debug_info) { if (info.type == JITDebugInfo::JIT_DEBUG_JIT_CODE) { uint64_t timestamp = jit_debug_reader_->SyncWithRecords() ? info.timestamp : last_record_timestamp_; - Mmap2Record record(*attr_id.attr, false, info.pid, info.pid, info.jit_code_addr, + Mmap2Record record(*dumping_attr_id_.attr, false, info.pid, info.pid, info.jit_code_addr, info.jit_code_len, info.file_offset, map_flags::PROT_JIT_SYMFILE_MAP, - info.file_path, attr_id.ids[0], timestamp); + info.file_path, dumping_attr_id_.ids[0], timestamp); if (!ProcessRecord(&record)) { return false; } @@ -1526,8 +1526,9 @@ bool RecordCommand::ProcessJITDebugInfo(const std::vector& debug_i ThreadMmap& map = *info.extracted_dex_file_map; uint64_t timestamp = jit_debug_reader_->SyncWithRecords() ? info.timestamp : last_record_timestamp_; - Mmap2Record record(*attr_id.attr, false, info.pid, info.pid, map.start_addr, map.len, - map.pgoff, map.prot, map.name, attr_id.ids[0], timestamp); + Mmap2Record record(*dumping_attr_id_.attr, false, info.pid, info.pid, map.start_addr, + map.len, map.pgoff, map.prot, map.name, dumping_attr_id_.ids[0], + timestamp); if (!ProcessRecord(&record)) { return false; } -- cgit v1.2.3