SectionLoadList.h revision a414e679c425c5bd1574f801c5bd8f516faa74cb
1//===-- SectionLoadList.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_SectionLoadList_h_
11#define liblldb_SectionLoadList_h_
12
13// C Includes
14// C++ Includes
15#include <map>
16
17// Other libraries and framework includes
18#include "llvm/ADT/DenseMap.h"
19// Project includes
20#include "lldb/lldb-public.h"
21#include "lldb/Host/Mutex.h"
22
23namespace lldb_private {
24
25class SectionLoadList
26{
27public:
28    //------------------------------------------------------------------
29    // Constructors and Destructors
30    //------------------------------------------------------------------
31    SectionLoadList () :
32        m_addr_to_sect (),
33        m_sect_to_addr (),
34        m_mutex (Mutex::eMutexTypeRecursive)
35
36    {
37    }
38
39    ~SectionLoadList()
40    {
41    }
42
43    bool
44    IsEmpty() const;
45
46    void
47    Clear ();
48
49    lldb::addr_t
50    GetSectionLoadAddress (const Section *section) const;
51
52    bool
53    ResolveLoadAddress (lldb::addr_t load_addr, Address &so_addr) const;
54
55    bool
56    SetSectionLoadAddress (const Section *section, lldb::addr_t load_addr, bool warn_multiple = false);
57
58    // The old load address should be specified when unloading to ensure we get
59    // the correct instance of the section as a shared library could be loaded
60    // at more than one location.
61    bool
62    SetSectionUnloaded (const Section *section, lldb::addr_t load_addr);
63
64    // Unload all instances of a section. This function can be used on systems
65    // that don't support multiple copies of the same shared library to be
66    // loaded at the same time.
67    size_t
68    SetSectionUnloaded (const Section *section);
69
70    void
71    Dump (Stream &s, Target *target);
72
73protected:
74    typedef std::map<lldb::addr_t, const Section *> addr_to_sect_collection;
75    typedef llvm::DenseMap<const Section *, lldb::addr_t> sect_to_addr_collection;
76    addr_to_sect_collection m_addr_to_sect;
77    sect_to_addr_collection m_sect_to_addr;
78    mutable Mutex m_mutex;
79
80private:
81    DISALLOW_COPY_AND_ASSIGN (SectionLoadList);
82};
83
84} // namespace lldb_private
85
86#endif  // liblldb_SectionLoadList_h_
87