]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
Update clang to trunk r256633.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / elf-core / ProcessElfCore.h
1 //===-- ProcessElfCore.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 // Notes about Linux Process core dumps:
9 //  1) Linux core dump is stored as ELF file.
10 //  2) The ELF file's PT_NOTE and PT_LOAD segments describes the program's
11 //     address space and thread contexts.
12 //  3) PT_NOTE segment contains note entries which describes a thread context.
13 //  4) PT_LOAD segment describes a valid contigous range of process address
14 //     space.
15 //===----------------------------------------------------------------------===//
16
17 #ifndef liblldb_ProcessElfCore_h_
18 #define liblldb_ProcessElfCore_h_
19
20 // C++ Includes
21 #include <list>
22 #include <vector>
23
24 // Other libraries and framework includes
25 #include "lldb/Core/ConstString.h"
26 #include "lldb/Core/Error.h"
27 #include "lldb/Target/Process.h"
28
29 #include "Plugins/ObjectFile/ELF/ELFHeader.h"
30
31 struct ThreadData;
32
33 class ProcessElfCore : public lldb_private::Process
34 {
35 public:
36     //------------------------------------------------------------------
37     // Constructors and Destructors
38     //------------------------------------------------------------------
39     static lldb::ProcessSP
40     CreateInstance (lldb_private::Target& target,
41                     lldb_private::Listener &listener,
42                     const lldb_private::FileSpec *crash_file_path);
43
44     static void
45     Initialize();
46
47     static void
48     Terminate();
49
50     static lldb_private::ConstString
51     GetPluginNameStatic();
52
53     static const char *
54     GetPluginDescriptionStatic();
55
56     //------------------------------------------------------------------
57     // Constructors and Destructors
58     //------------------------------------------------------------------
59     ProcessElfCore(lldb_private::Target& target,
60                     lldb_private::Listener &listener,
61                     const lldb_private::FileSpec &core_file);
62
63     virtual
64     ~ProcessElfCore();
65
66     //------------------------------------------------------------------
67     // Check if a given Process
68     //------------------------------------------------------------------
69     bool CanDebug(lldb_private::Target &target, bool plugin_specified_by_name) override;
70
71     //------------------------------------------------------------------
72     // Creating a new process, or attaching to an existing one
73     //------------------------------------------------------------------
74     lldb_private::Error DoLoadCore() override;
75
76     lldb_private::DynamicLoader *GetDynamicLoader() override;
77
78     //------------------------------------------------------------------
79     // PluginInterface protocol
80     //------------------------------------------------------------------
81     lldb_private::ConstString GetPluginName() override;
82
83     uint32_t GetPluginVersion() override;
84
85     //------------------------------------------------------------------
86     // Process Control
87     //------------------------------------------------------------------
88     lldb_private::Error DoDestroy() override;
89
90     void RefreshStateAfterStop() override;
91
92     //------------------------------------------------------------------
93     // Process Queries
94     //------------------------------------------------------------------
95     bool IsAlive() override;
96
97     //------------------------------------------------------------------
98     // Process Memory
99     //------------------------------------------------------------------
100     size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error) override;
101
102     size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error) override;
103
104     lldb::addr_t GetImageInfoAddress() override;
105
106     lldb_private::ArchSpec
107     GetArchitecture();
108
109     // Returns AUXV structure found in the core file
110     const lldb::DataBufferSP
111     GetAuxvData() override;
112
113 protected:
114     void
115     Clear ( );
116
117     bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
118                           lldb_private::ThreadList &new_thread_list) override;
119
120 private:
121     //------------------------------------------------------------------
122     // For ProcessElfCore only
123     //------------------------------------------------------------------
124     typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange;
125     typedef lldb_private::RangeDataArray<lldb::addr_t, lldb::addr_t, FileRange, 1> VMRangeToFileOffset;
126
127     lldb::ModuleSP m_core_module_sp;
128     lldb_private::FileSpec m_core_file;
129     std::string  m_dyld_plugin_name;
130     DISALLOW_COPY_AND_ASSIGN (ProcessElfCore);
131
132     llvm::Triple::OSType m_os;
133
134     // True if m_thread_contexts contains valid entries
135     bool m_thread_data_valid;
136
137     // Contain thread data read from NOTE segments
138     std::vector<ThreadData> m_thread_data;
139
140     // AUXV structure found from the NOTE segment
141     lldb_private::DataExtractor m_auxv;
142
143     // Address ranges found in the core
144     VMRangeToFileOffset m_core_aranges;
145
146     // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
147     void
148     ParseThreadContextsFromNoteSegment (const elf::ELFProgramHeader *segment_header,
149                                         lldb_private::DataExtractor segment_data);
150
151     // Returns number of thread contexts stored in the core file
152     uint32_t
153     GetNumThreadContexts();
154
155     // Parse a contiguous address range of the process from LOAD segment
156     lldb::addr_t
157     AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *header);
158 };
159
160 #endif  // liblldb_ProcessElffCore_h_