SectionLoadHistory.h revision 269024
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// C Includes
14// C++ Includes
15#include <map>
16
17// Project includes
18#include "lldb/lldb-public.h"
19#include "lldb/Host/Mutex.h"
20
21namespace lldb_private {
22
23class SectionLoadHistory
24{
25public:
26    enum {
27        // Pass eStopIDNow to any function that takes a stop ID to get
28        // the current value.
29        eStopIDNow = UINT32_MAX
30    };
31    //------------------------------------------------------------------
32    // Constructors and Destructors
33    //------------------------------------------------------------------
34    SectionLoadHistory () :
35        m_stop_id_to_section_load_list(),
36        m_mutex (Mutex::eMutexTypeRecursive)
37    {
38    }
39
40    ~SectionLoadHistory()
41    {
42        // Call clear since this takes a lock and clears the section load list
43        // in case another thread is currently using this section load list
44        Clear();
45    }
46
47    SectionLoadList &
48    GetCurrentSectionLoadList ();
49
50    bool
51    IsEmpty() const;
52
53    void
54    Clear ();
55
56    uint32_t
57    GetLastStopID() const;
58
59    // Get the section load address given a process stop ID
60    lldb::addr_t
61    GetSectionLoadAddress (uint32_t stop_id,
62                           const lldb::SectionSP &section_sp);
63
64    bool
65    ResolveLoadAddress (uint32_t stop_id,
66                        lldb::addr_t load_addr,
67                        Address &so_addr);
68
69    bool
70    SetSectionLoadAddress (uint32_t stop_id,
71                           const lldb::SectionSP &section_sp,
72                           lldb::addr_t load_addr,
73                           bool warn_multiple = false);
74
75    // The old load address should be specified when unloading to ensure we get
76    // the correct instance of the section as a shared library could be loaded
77    // at more than one location.
78    bool
79    SetSectionUnloaded (uint32_t stop_id,
80                        const lldb::SectionSP &section_sp,
81                        lldb::addr_t load_addr);
82
83    // Unload all instances of a section. This function can be used on systems
84    // that don't support multiple copies of the same shared library to be
85    // loaded at the same time.
86    size_t
87    SetSectionUnloaded (uint32_t stop_id,
88                        const lldb::SectionSP &section_sp);
89
90    void
91    Dump (Stream &s,
92          Target *target);
93
94protected:
95
96    SectionLoadList *
97    GetSectionLoadListForStopID (uint32_t stop_id, bool read_only);
98
99    typedef std::map<uint32_t, lldb::SectionLoadListSP> StopIDToSectionLoadList;
100    StopIDToSectionLoadList m_stop_id_to_section_load_list;
101    mutable Mutex m_mutex;
102
103private:
104    DISALLOW_COPY_AND_ASSIGN (SectionLoadHistory);
105};
106
107} // namespace lldb_private
108
109#endif  // liblldb_SectionLoadHistory_h_
110