1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_ETM_TARGET_MEMORY_READER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_ETM_TARGET_MEMORY_READER_H_ 19 20 #include <cstdint> 21 #include <optional> 22 #include "src/trace_processor/importers/common/address_range.h" 23 24 #include "src/trace_processor/importers/common/address_range.h" 25 #include "src/trace_processor/importers/etm/opencsd.h" 26 namespace perfetto::trace_processor::etm { 27 28 class MappingVersion; 29 class TargetMemory; 30 class MemoryContentProvider; 31 class BinaryIndex; 32 33 class TargetMemoryReader : public ITargetMemAccess { 34 public: TargetMemoryReader(const TargetMemory * memory)35 explicit TargetMemoryReader(const TargetMemory* memory) : memory_(memory) {} 36 37 ocsd_err_t ReadTargetMemory(const ocsd_vaddr_t address, 38 const uint8_t cs_trace_id, 39 const ocsd_mem_space_acc_t mem_space, 40 uint32_t* num_bytes, 41 uint8_t* p_buffer) override; 42 void InvalidateMemAccCache(const uint8_t cs_trace_id) override; 43 44 void SetTs(int64_t ts); 45 void SetPeContext(const ocsd_pe_context&); 46 47 const MappingVersion* FindMapping(uint64_t address) const; 48 49 private: 50 const TargetMemory* memory_; 51 52 std::optional<uint32_t> tid_; 53 int64_t ts_; 54 // Cache last mapping to speedup lookups. 55 mutable const MappingVersion* cached_mapping_; 56 }; 57 58 } // namespace perfetto::trace_processor::etm 59 60 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_ETM_TARGET_MEMORY_READER_H_ 61