[Go to site: main page, start]

LLDB mainline
ProcessElfCore.h
Go to the documentation of this file.
1//===-- ProcessElfCore.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7// Notes about Linux Process core dumps:
8// 1) Linux core dump is stored as ELF file.
9// 2) The ELF file's PT_NOTE and PT_LOAD segments describes the program's
10// address space and thread contexts.
11// 3) PT_NOTE segment contains note entries which describes a thread context.
12// 4) PT_LOAD segment describes a valid contiguous range of process address
13// space.
14//===----------------------------------------------------------------------===//
15
16#ifndef LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_PROCESSELFCORE_H
17#define LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_PROCESSELFCORE_H
18
19#include <functional>
20#include <list>
21#include <set>
22#include <unordered_map>
23#include <vector>
24
27#include "lldb/Utility/Args.h"
28#include "lldb/Utility/Status.h"
29
32
33struct ThreadData;
34
36public:
37 // Constructors and Destructors
38 static lldb::ProcessSP
39 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
40 const lldb_private::FileSpec *crash_file_path,
41 bool can_connect);
42
43 static void Initialize();
44
45 static void Terminate();
46
47 static llvm::StringRef GetPluginNameStatic() { return "elf-core"; }
48
49 static llvm::StringRef GetPluginDescriptionStatic();
50
51 // Constructors and Destructors
52 ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
53 const lldb_private::FileSpec &core_file);
54
55 ~ProcessElfCore() override;
56
57 // Check if a given Process
58 bool CanDebug(lldb::TargetSP target_sp,
59 bool plugin_specified_by_name) override;
60
61 // Creating a new process, or attaching to an existing one
63
65
66 // PluginInterface protocol
67 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
68
69 // Process Control
71
72 void RefreshStateAfterStop() override;
73
76 "error: {0} does not support resuming processes", GetPluginName());
77 }
78
79 // Process Queries
80 bool IsAlive() override;
81
82 bool WarnBeforeDetach() const override { return false; }
83
84 // Process Memory
85 size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
86 lldb_private::Status &error) override;
87
88 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
89 lldb_private::Status &error) override;
90
91 // We do not implement DoReadMemoryTags. Instead all the work is done in
92 // ReadMemoryTags which avoids having to unpack and repack tags.
93 llvm::Expected<std::vector<lldb::addr_t>> ReadMemoryTags(lldb::addr_t addr,
94 size_t len) override;
95
97
99
100 // Returns AUXV structure found in the core file
102
103 std::optional<Process::CoreArgs> GetCoreFileArgs() override;
105
106protected:
107 void Clear();
108
109 bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
110 lldb_private::ThreadList &new_thread_list) override;
111
114 lldb_private::MemoryRegionInfo &region_info) override;
115
116 bool SupportsMemoryTagging() override { return !m_core_tag_ranges.IsEmpty(); }
117
118private:
125
126 // For ProcessElfCore only
130
133
134 // True if m_thread_contexts contains valid entries
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
142
143 // Address ranges found in the core
145
146 // Information for all mapped ranges, ordered by address.
147 std::set<lldb_private::MemoryRegionInfo, std::less<>> m_core_range_infos;
148
149 // Memory tag ranges found in the core
151
152 // NT_FILE entries found from the NOTE segment
153 std::vector<NT_FILE_Entry> m_nt_file_entries;
154
155 // Map from file path to UUID for quick lookup
156 std::unordered_map<std::string, lldb_private::UUID> m_uuids;
157
158 // Executable name found from the ELF PRPSINFO
159 std::string m_executable_name;
160
161 // Command line args found from the ELF PRPSINFO (pr_psargs)
162 Process::CoreArgs m_process_args;
163 // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
165 const elf::ELFProgramHeader &segment_header,
166 const lldb_private::DataExtractor &segment_data);
167
168 // Returns number of thread contexts stored in the core file
169 uint32_t GetNumThreadContexts();
170
171 // Populate gnu uuid for each NT_FILE entry
173
174 // Complete memory region information after all program headers are parsed.
176
177 bool FindModuleUUID(lldb_private::ModuleSpec &spec) override;
178
179 // Extract the executable module spec for the executable in this core file.
181
182 // Returns the value of certain type of note of a given start address
184
185 // Parse a contiguous address range of the process from LOAD segment
188
189 // Parse a contiguous address range from a memory tag segment
192
193 llvm::Expected<std::vector<lldb_private::CoreNote>>
195 llvm::Error parseFreeBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
196 llvm::Error parseNetBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
197 llvm::Error parseOpenBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
198 llvm::Error parseLinuxNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
199
200 /// Find the NT_FILE entry that contains an address.
201 std::optional<NT_FILE_Entry>
203 /// Intelligently find the NT_FILE entry for the executable's ELF header.
204 std::optional<NT_FILE_Entry> GetNTFileEntryForExecutableELFHeader();
205};
206
207#endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_PROCESSELFCORE_H
static llvm::raw_ostream & error(Stream &strm)
Generic structures and typedefs for ELF files.
std::vector< NT_FILE_Entry > m_nt_file_entries
std::optional< NT_FILE_Entry > GetNTFileEntryForExecutableELFHeader()
Intelligently find the NT_FILE entry for the executable's ELF header.
std::set< lldb_private::MemoryRegionInfo, std::less<> > m_core_range_infos
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
lldb::addr_t AddAddressRangeFromMemoryTagSegment(const elf::ELFProgramHeader &header)
lldb_private::DataExtractor m_auxv
bool FindModuleUUID(lldb_private::ModuleSpec &spec) override
Given a module spec, try to find the UUID information.
llvm::Error parseLinuxNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
A description of a linux process usually contains the following NOTE entries:
llvm::Error ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader &segment_header, const lldb_private::DataExtractor &segment_data)
Parse Thread context from PT_NOTE segment and store it in the thread list A note segment consists of ...
void UpdateBuildIdForNTFileEntries()
std::vector< ThreadData > m_thread_data
lldb_private::Range< lldb::addr_t, lldb::addr_t > FileRange
static void Initialize()
llvm::StringRef GetPluginName() override
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
static llvm::StringRef GetPluginDescriptionStatic()
std::unordered_map< std::string, lldb_private::UUID > m_uuids
llvm::Expected< std::vector< lldb_private::CoreNote > > parseSegment(const lldb_private::DataExtractor &segment)
lldb::addr_t AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader &header)
~ProcessElfCore() override
bool GetMainExecutableModuleSpec(lldb_private::ModuleSpec &exe_spec)
llvm::Error parseFreeBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
lldb_private::Status WillResume() override
Called before resuming to a process.
lldb_private::UUID FindBuidIdInCoreMemory(lldb::addr_t address)
bool SupportsMemoryTagging() override
Check whether the process supports memory tagging.
VMRangeToFileOffset m_core_aranges
lldb_private::Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, lldb_private::MemoryRegionInfo &region_info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
Process::CoreArgs m_process_args
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
VMRangeToFileOffset m_core_tag_ranges
llvm::Error parseNetBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
NetBSD specific Thread context from PT_NOTE segment.
bool WarnBeforeDetach() const override
Before lldb detaches from a process, it warns the user that they are about to lose their debug sessio...
lldb_private::Status DoLoadCore() override
static void Terminate()
ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec &core_file)
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
llvm::Expected< std::vector< lldb::addr_t > > ReadMemoryTags(lldb::addr_t addr, size_t len) override
Read memory tags for the range addr to addr+len.
lldb_private::DataExtractor GetAuxvData() override
bool IsAlive() override
Check if a process is still alive.
uint32_t GetNumThreadContexts()
std::string m_dyld_plugin_name
std::string m_executable_name
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
llvm::Error parseOpenBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
lldb_private::ArchSpec GetArchitecture()
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
std::optional< Process::CoreArgs > GetCoreFileArgs() override
Provide arguments of a command that triggered a core dump.
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override
static llvm::StringRef GetPluginNameStatic()
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, FileRange > VMRangeToFileOffset
void FinalizeMemoryRegionInfos()
lldb::ModuleSP m_core_module_sp
std::optional< NT_FILE_Entry > GetNTFileEntryContainingAddress(lldb::addr_t addr)
Find the NT_FILE entry that contains an address.
lldb_private::Status DoDestroy() override
An architecture specification class.
Definition ArchSpec.h:32
An data extractor class.
A plug-in interface definition class for dynamic loaders.
A file utility class.
Definition FileSpec.h:56
Base class for all processes that don't represent a live process, such as coredumps or processes trac...
An error handling class.
Definition Status.h:118
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
Represents UUID's of various sizes.
Definition UUID.h:27
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::string path
lldb::addr_t file_ofs
lldb::addr_t end
lldb::addr_t start
Generic representation of an ELF program header.
Definition ELFHeader.h:192