1 //===-- SectionLoadList.h -----------------------------------------------*- C++ 2 //-*-===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is distributed under the University of Illinois Open Source 7 // License. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #ifndef liblldb_SectionLoadList_h_ 12 #define liblldb_SectionLoadList_h_ 13 14 #include <map> 15 #include <mutex> 16 17 #include "llvm/ADT/DenseMap.h" 18 #include "lldb/Core/Section.h" 19 #include "lldb/lldb-public.h" 20 21 namespace lldb_private { 22 23 class SectionLoadList { 24 public: 25 //------------------------------------------------------------------ 26 // Constructors and Destructors 27 //------------------------------------------------------------------ SectionLoadList()28 SectionLoadList() : m_addr_to_sect(), m_sect_to_addr(), m_mutex() {} 29 30 SectionLoadList(const SectionLoadList &rhs); 31 ~SectionLoadList()32 ~SectionLoadList() { 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 void operator=(const SectionLoadList &rhs); 39 40 bool IsEmpty() const; 41 42 void Clear(); 43 44 lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP §ion_sp) const; 45 46 bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, 47 bool allow_section_end = false) const; 48 49 bool SetSectionLoadAddress(const lldb::SectionSP §ion_sp, 50 lldb::addr_t load_addr, 51 bool warn_multiple = false); 52 53 // The old load address should be specified when unloading to ensure we get 54 // the correct instance of the section as a shared library could be loaded at 55 // more than one location. 56 bool SetSectionUnloaded(const lldb::SectionSP §ion_sp, 57 lldb::addr_t load_addr); 58 59 // Unload all instances of a section. This function can be used on systems 60 // that don't support multiple copies of the same shared library to be loaded 61 // at the same time. 62 size_t SetSectionUnloaded(const lldb::SectionSP §ion_sp); 63 64 void Dump(Stream &s, Target *target); 65 66 protected: 67 typedef std::map<lldb::addr_t, lldb::SectionSP> addr_to_sect_collection; 68 typedef llvm::DenseMap<const Section *, lldb::addr_t> sect_to_addr_collection; 69 addr_to_sect_collection m_addr_to_sect; 70 sect_to_addr_collection m_sect_to_addr; 71 mutable std::recursive_mutex m_mutex; 72 }; 73 74 } // namespace lldb_private 75 76 #endif // liblldb_SectionLoadList_h_ 77