1 //===-- SectionLoadHistory.h ------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_SectionLoadHistory_h_ 11 #define liblldb_SectionLoadHistory_h_ 12 13 #include <map> 14 #include <mutex> 15 16 #include "lldb/lldb-public.h" 17 18 namespace lldb_private { 19 20 class SectionLoadHistory { 21 public: 22 enum : unsigned { 23 // Pass eStopIDNow to any function that takes a stop ID to get the current 24 // value. 25 eStopIDNow = UINT32_MAX 26 }; 27 //------------------------------------------------------------------ 28 // Constructors and Destructors 29 //------------------------------------------------------------------ SectionLoadHistory()30 SectionLoadHistory() : m_stop_id_to_section_load_list(), m_mutex() {} 31 ~SectionLoadHistory()32 ~SectionLoadHistory() { 33 // Call clear since this takes a lock and clears the section load list in 34 // case another thread is currently using this section load list 35 Clear(); 36 } 37 38 SectionLoadList &GetCurrentSectionLoadList(); 39 40 bool IsEmpty() const; 41 42 void Clear(); 43 44 uint32_t GetLastStopID() const; 45 46 // Get the section load address given a process stop ID 47 lldb::addr_t GetSectionLoadAddress(uint32_t stop_id, 48 const lldb::SectionSP §ion_sp); 49 50 bool ResolveLoadAddress(uint32_t stop_id, lldb::addr_t load_addr, 51 Address &so_addr); 52 53 bool SetSectionLoadAddress(uint32_t stop_id, 54 const lldb::SectionSP §ion_sp, 55 lldb::addr_t load_addr, 56 bool warn_multiple = false); 57 58 // The old load address should be specified when unloading to ensure we get 59 // the correct instance of the section as a shared library could be loaded at 60 // more than one location. 61 bool SetSectionUnloaded(uint32_t stop_id, const lldb::SectionSP §ion_sp, 62 lldb::addr_t load_addr); 63 64 // Unload all instances of a section. This function can be used on systems 65 // that don't support multiple copies of the same shared library to be loaded 66 // at the same time. 67 size_t SetSectionUnloaded(uint32_t stop_id, 68 const lldb::SectionSP §ion_sp); 69 70 void Dump(Stream &s, Target *target); 71 72 protected: 73 SectionLoadList *GetSectionLoadListForStopID(uint32_t stop_id, 74 bool read_only); 75 76 typedef std::map<uint32_t, lldb::SectionLoadListSP> StopIDToSectionLoadList; 77 StopIDToSectionLoadList m_stop_id_to_section_load_list; 78 mutable std::recursive_mutex m_mutex; 79 80 private: 81 DISALLOW_COPY_AND_ASSIGN(SectionLoadHistory); 82 }; 83 84 } // namespace lldb_private 85 86 #endif // liblldb_SectionLoadHistory_h_ 87