Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:54

0001 //===-- SectionLoadHistory.h ------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_TARGET_SECTIONLOADHISTORY_H
0010 #define LLDB_TARGET_SECTIONLOADHISTORY_H
0011 
0012 #include <map>
0013 #include <mutex>
0014 
0015 #include "lldb/lldb-public.h"
0016 
0017 namespace lldb_private {
0018 
0019 class SectionLoadHistory {
0020 public:
0021   enum : unsigned {
0022     // Pass eStopIDNow to any function that takes a stop ID to get the current
0023     // value.
0024     eStopIDNow = UINT32_MAX
0025   };
0026   // Constructors and Destructors
0027   SectionLoadHistory() = default;
0028 
0029   ~SectionLoadHistory() {
0030     // Call clear since this takes a lock and clears the section load list in
0031     // case another thread is currently using this section load list
0032     Clear();
0033   }
0034 
0035   SectionLoadList &GetCurrentSectionLoadList();
0036 
0037   bool IsEmpty() const;
0038 
0039   void Clear();
0040 
0041   uint32_t GetLastStopID() const;
0042 
0043   // Get the section load address given a process stop ID
0044   lldb::addr_t GetSectionLoadAddress(uint32_t stop_id,
0045                                      const lldb::SectionSP &section_sp);
0046 
0047   bool ResolveLoadAddress(uint32_t stop_id, lldb::addr_t load_addr,
0048                           Address &so_addr, bool allow_section_end = false);
0049 
0050   bool SetSectionLoadAddress(uint32_t stop_id,
0051                              const lldb::SectionSP &section_sp,
0052                              lldb::addr_t load_addr,
0053                              bool warn_multiple = false);
0054 
0055   // The old load address should be specified when unloading to ensure we get
0056   // the correct instance of the section as a shared library could be loaded at
0057   // more than one location.
0058   bool SetSectionUnloaded(uint32_t stop_id, const lldb::SectionSP &section_sp,
0059                           lldb::addr_t load_addr);
0060 
0061   // Unload all instances of a section. This function can be used on systems
0062   // that don't support multiple copies of the same shared library to be loaded
0063   // at the same time.
0064   size_t SetSectionUnloaded(uint32_t stop_id,
0065                             const lldb::SectionSP &section_sp);
0066 
0067   void Dump(Stream &s, Target *target);
0068 
0069 protected:
0070   SectionLoadList *GetSectionLoadListForStopID(uint32_t stop_id,
0071                                                bool read_only);
0072 
0073   typedef std::map<uint32_t, lldb::SectionLoadListSP> StopIDToSectionLoadList;
0074   StopIDToSectionLoadList m_stop_id_to_section_load_list;
0075   mutable std::recursive_mutex m_mutex;
0076 
0077 private:
0078   SectionLoadHistory(const SectionLoadHistory &) = delete;
0079   const SectionLoadHistory &operator=(const SectionLoadHistory &) = delete;
0080 };
0081 
0082 } // namespace lldb_private
0083 
0084 #endif // LLDB_TARGET_SECTIONLOADHISTORY_H