SectionLoadList.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //===-- SectionLoadList.h -----------------------------------------------*- C++
  2. //-*-===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLDB_TARGET_SECTIONLOADLIST_H
  10. #define LLDB_TARGET_SECTIONLOADLIST_H
  11. #include <map>
  12. #include <mutex>
  13. #include "llvm/ADT/DenseMap.h"
  14. #include "lldb/Core/Section.h"
  15. #include "lldb/lldb-public.h"
  16. namespace lldb_private {
  17. class SectionLoadList {
  18. public:
  19. // Constructors and Destructors
  20. SectionLoadList() : m_addr_to_sect(), m_sect_to_addr(), m_mutex() {}
  21. SectionLoadList(const SectionLoadList &rhs);
  22. ~SectionLoadList() {
  23. // Call clear since this takes a lock and clears the section load list in
  24. // case another thread is currently using this section load list
  25. Clear();
  26. }
  27. void operator=(const SectionLoadList &rhs);
  28. bool IsEmpty() const;
  29. void Clear();
  30. lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP &section_sp) const;
  31. bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr,
  32. bool allow_section_end = false) const;
  33. bool SetSectionLoadAddress(const lldb::SectionSP &section_sp,
  34. lldb::addr_t load_addr,
  35. bool warn_multiple = false);
  36. // The old load address should be specified when unloading to ensure we get
  37. // the correct instance of the section as a shared library could be loaded at
  38. // more than one location.
  39. bool SetSectionUnloaded(const lldb::SectionSP &section_sp,
  40. lldb::addr_t load_addr);
  41. // Unload all instances of a section. This function can be used on systems
  42. // that don't support multiple copies of the same shared library to be loaded
  43. // at the same time.
  44. size_t SetSectionUnloaded(const lldb::SectionSP &section_sp);
  45. void Dump(Stream &s, Target *target);
  46. protected:
  47. typedef std::map<lldb::addr_t, lldb::SectionSP> addr_to_sect_collection;
  48. typedef llvm::DenseMap<const Section *, lldb::addr_t> sect_to_addr_collection;
  49. addr_to_sect_collection m_addr_to_sect;
  50. sect_to_addr_collection m_sect_to_addr;
  51. mutable std::recursive_mutex m_mutex;
  52. };
  53. } // namespace lldb_private
  54. #endif // LLDB_TARGET_SECTIONLOADLIST_H