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