]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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     virtual bool
70     CanDebug (lldb_private::Target &target,
71               bool plugin_specified_by_name);
72     
73     //------------------------------------------------------------------
74     // Creating a new process, or attaching to an existing one
75     //------------------------------------------------------------------
76     virtual lldb_private::Error
77     DoLoadCore ();
78     
79     virtual lldb_private::DynamicLoader *
80     GetDynamicLoader ();
81
82     //------------------------------------------------------------------
83     // PluginInterface protocol
84     //------------------------------------------------------------------
85     virtual lldb_private::ConstString
86     GetPluginName();
87     
88     virtual uint32_t
89     GetPluginVersion();
90     
91     //------------------------------------------------------------------
92     // Process Control
93     //------------------------------------------------------------------    
94     virtual lldb_private::Error
95     DoDestroy ();
96     
97     virtual void
98     RefreshStateAfterStop();
99     
100     //------------------------------------------------------------------
101     // Process Queries
102     //------------------------------------------------------------------
103     virtual bool
104     IsAlive ();
105
106     //------------------------------------------------------------------
107     // Process Memory
108     //------------------------------------------------------------------
109     virtual size_t
110     ReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
111     
112     virtual size_t
113     DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
114     
115     virtual lldb::addr_t
116     GetImageInfoAddress ();
117
118     lldb_private::ArchSpec
119     GetArchitecture();
120
121     // Returns AUXV structure found in the core file
122     const lldb::DataBufferSP
123     GetAuxvData();
124
125 protected:
126     void
127     Clear ( );
128     
129     virtual bool
130     UpdateThreadList (lldb_private::ThreadList &old_thread_list, 
131                       lldb_private::ThreadList &new_thread_list);
132    
133 private:
134     //------------------------------------------------------------------
135     // For ProcessElfCore only
136     //------------------------------------------------------------------
137     typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange;
138     typedef lldb_private::RangeDataArray<lldb::addr_t, lldb::addr_t, FileRange, 1> VMRangeToFileOffset;
139
140     lldb::ModuleSP m_core_module_sp;
141     lldb_private::FileSpec m_core_file;
142     std::string  m_dyld_plugin_name;
143     DISALLOW_COPY_AND_ASSIGN (ProcessElfCore);
144
145     // True if m_thread_contexts contains valid entries
146     bool m_thread_data_valid;
147
148     // Contain thread data read from NOTE segments
149     std::vector<ThreadData> m_thread_data;
150
151     // AUXV structure found from the NOTE segment
152     lldb_private::DataExtractor m_auxv;
153
154     // Address ranges found in the core
155     VMRangeToFileOffset m_core_aranges;
156
157     // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
158     void
159     ParseThreadContextsFromNoteSegment (const elf::ELFProgramHeader *segment_header,
160                                         lldb_private::DataExtractor segment_data);
161
162     // Returns number of thread contexts stored in the core file
163     uint32_t
164     GetNumThreadContexts();
165
166     // Parse a contiguous address range of the process from LOAD segment
167     lldb::addr_t
168     AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *header);
169 };
170
171 #endif  // liblldb_ProcessElffCore_h_