1 //===-- ProcessElfCore.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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 contiguous range of process address
15 //===----------------------------------------------------------------------===//
17 #ifndef liblldb_ProcessElfCore_h_
18 #define liblldb_ProcessElfCore_h_
25 // Other libraries and framework includes
27 #include "lldb/Target/Process.h"
28 #include "lldb/Utility/ConstString.h"
29 #include "lldb/Utility/Status.h"
31 #include "Plugins/ObjectFile/ELF/ELFHeader.h"
32 #include "Plugins/Process/elf-core/RegisterUtilities.h"
36 class ProcessElfCore : public lldb_private::Process {
38 //------------------------------------------------------------------
39 // Constructors and Destructors
40 //------------------------------------------------------------------
41 static lldb::ProcessSP
42 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
43 const lldb_private::FileSpec *crash_file_path);
45 static void Initialize();
47 static void Terminate();
49 static lldb_private::ConstString GetPluginNameStatic();
51 static const char *GetPluginDescriptionStatic();
53 //------------------------------------------------------------------
54 // Constructors and Destructors
55 //------------------------------------------------------------------
56 ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
57 const lldb_private::FileSpec &core_file);
59 ~ProcessElfCore() override;
61 //------------------------------------------------------------------
62 // Check if a given Process
63 //------------------------------------------------------------------
64 bool CanDebug(lldb::TargetSP target_sp,
65 bool plugin_specified_by_name) override;
67 //------------------------------------------------------------------
68 // Creating a new process, or attaching to an existing one
69 //------------------------------------------------------------------
70 lldb_private::Status DoLoadCore() override;
72 lldb_private::DynamicLoader *GetDynamicLoader() override;
74 //------------------------------------------------------------------
75 // PluginInterface protocol
76 //------------------------------------------------------------------
77 lldb_private::ConstString GetPluginName() override;
79 uint32_t GetPluginVersion() override;
81 //------------------------------------------------------------------
83 //------------------------------------------------------------------
84 lldb_private::Status DoDestroy() override;
86 void RefreshStateAfterStop() override;
88 lldb_private::Status WillResume() override {
89 lldb_private::Status error;
90 error.SetErrorStringWithFormat(
91 "error: %s does not support resuming processes",
92 GetPluginName().GetCString());
96 //------------------------------------------------------------------
98 //------------------------------------------------------------------
99 bool IsAlive() override;
101 bool WarnBeforeDetach() const override { return false; }
103 //------------------------------------------------------------------
105 //------------------------------------------------------------------
106 size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
107 lldb_private::Status &error) override;
109 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
110 lldb_private::Status &error) override;
113 GetMemoryRegionInfo(lldb::addr_t load_addr,
114 lldb_private::MemoryRegionInfo ®ion_info) override;
116 lldb::addr_t GetImageInfoAddress() override;
118 lldb_private::ArchSpec GetArchitecture();
120 // Returns AUXV structure found in the core file
121 const lldb::DataBufferSP GetAuxvData() override;
123 bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
128 bool UpdateThreadList(lldb_private::ThreadList &old_thread_list,
129 lldb_private::ThreadList &new_thread_list) override;
132 struct NT_FILE_Entry {
135 lldb::addr_t file_ofs;
136 lldb_private::ConstString path;
139 //------------------------------------------------------------------
140 // For ProcessElfCore only
141 //------------------------------------------------------------------
142 typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange;
143 typedef lldb_private::RangeDataArray<lldb::addr_t, lldb::addr_t, FileRange, 1>
145 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t>
146 VMRangeToPermissions;
148 lldb::ModuleSP m_core_module_sp;
149 lldb_private::FileSpec m_core_file;
150 std::string m_dyld_plugin_name;
151 DISALLOW_COPY_AND_ASSIGN(ProcessElfCore);
153 // True if m_thread_contexts contains valid entries
154 bool m_thread_data_valid = false;
156 // Contain thread data read from NOTE segments
157 std::vector<ThreadData> m_thread_data;
159 // AUXV structure found from the NOTE segment
160 lldb_private::DataExtractor m_auxv;
162 // Address ranges found in the core
163 VMRangeToFileOffset m_core_aranges;
165 // Permissions for all ranges
166 VMRangeToPermissions m_core_range_infos;
168 // NT_FILE entries found from the NOTE segment
169 std::vector<NT_FILE_Entry> m_nt_file_entries;
171 // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
172 llvm::Error ParseThreadContextsFromNoteSegment(
173 const elf::ELFProgramHeader *segment_header,
174 lldb_private::DataExtractor segment_data);
176 // Returns number of thread contexts stored in the core file
177 uint32_t GetNumThreadContexts();
179 // Parse a contiguous address range of the process from LOAD segment
181 AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *header);
183 llvm::Expected<std::vector<lldb_private::CoreNote>>
184 parseSegment(const lldb_private::DataExtractor &segment);
185 llvm::Error parseFreeBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
186 llvm::Error parseNetBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
187 llvm::Error parseOpenBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
188 llvm::Error parseLinuxNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
191 #endif // liblldb_ProcessElfCore_h_