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 <list>
20#include <vector>
21
23#include "lldb/Utility/Status.h"
24
27
28struct ThreadData;
29
31public:
32 // Constructors and Destructors
33 static lldb::ProcessSP
34 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
35 const lldb_private::FileSpec *crash_file_path,
36 bool can_connect);
37
38 static void Initialize();
39
40 static void Terminate();
41
42 static llvm::StringRef GetPluginNameStatic() { return "elf-core"; }
43
44 static llvm::StringRef GetPluginDescriptionStatic();
45
46 // Constructors and Destructors
47 ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
48 const lldb_private::FileSpec &core_file);
49
50 ~ProcessElfCore() override;
51
52 // Check if a given Process
53 bool CanDebug(lldb::TargetSP target_sp,
54 bool plugin_specified_by_name) override;
55
56 // Creating a new process, or attaching to an existing one
58
60
61 // PluginInterface protocol
62 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
63
64 // Process Control
66
67 void RefreshStateAfterStop() override;
68
71 error.SetErrorStringWithFormatv(
72 "error: {0} does not support resuming processes", GetPluginName());
73 return error;
74 }
75
76 // Process Queries
77 bool IsAlive() override;
78
79 bool WarnBeforeDetach() const override { return false; }
80
81 // Process Memory
82 size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
83 lldb_private::Status &error) override;
84
85 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
86 lldb_private::Status &error) override;
87
88 // We do not implement DoReadMemoryTags. Instead all the work is done in
89 // ReadMemoryTags which avoids having to unpack and repack tags.
90 llvm::Expected<std::vector<lldb::addr_t>> ReadMemoryTags(lldb::addr_t addr,
91 size_t len) override;
92
94
96
97 // Returns AUXV structure found in the core file
99
101
102protected:
103 void Clear();
104
105 bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
106 lldb_private::ThreadList &new_thread_list) override;
107
110 lldb_private::MemoryRegionInfo &region_info) override;
111
112 bool SupportsMemoryTagging() override { return !m_core_tag_ranges.IsEmpty(); }
113
114private:
119 std::string path;
120 };
121
122 // For ProcessElfCore only
128
131
132 // True if m_thread_contexts contains valid entries
134
135 // Contain thread data read from NOTE segments
136 std::vector<ThreadData> m_thread_data;
137
138 // AUXV structure found from the NOTE segment
140
141 // Address ranges found in the core
143
144 // Permissions for all ranges
146
147 // Memory tag ranges found in the core
149
150 // NT_FILE entries found from the NOTE segment
151 std::vector<NT_FILE_Entry> m_nt_file_entries;
152
153 // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
155 const elf::ELFProgramHeader &segment_header,
156 const lldb_private::DataExtractor &segment_data);
157
158 // Returns number of thread contexts stored in the core file
159 uint32_t GetNumThreadContexts();
160
161 // Parse a contiguous address range of the process from LOAD segment
164
165 // Parse a contiguous address range from a memory tag segment
168
169 llvm::Expected<std::vector<lldb_private::CoreNote>>
171 llvm::Error parseFreeBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
172 llvm::Error parseNetBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
173 llvm::Error parseOpenBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
174 llvm::Error parseLinuxNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
175};
176
177#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
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
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 ...
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.
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, uint32_t > VMRangeToPermissions
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
VMRangeToPermissions m_core_range_infos
static llvm::StringRef GetPluginDescriptionStatic()
llvm::Expected< std::vector< lldb_private::CoreNote > > parseSegment(const lldb_private::DataExtractor &segment)
lldb::addr_t AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader &header)
~ProcessElfCore() override
llvm::Error parseFreeBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
lldb_private::Status WillResume() override
Called before resuming to a process.
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...
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()
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
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.
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override
static llvm::StringRef GetPluginNameStatic()
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, FileRange > VMRangeToFileOffset
lldb::ModuleSP m_core_module_sp
lldb_private::Status DoDestroy() override
An architecture specification class.
Definition: ArchSpec.h:31
An data extractor class.
Definition: DataExtractor.h:48
A plug-in interface definition class for dynamic loaders.
Definition: DynamicLoader.h:52
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:44
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:381
std::shared_ptr< lldb_private::Listener > ListenerSP
Definition: lldb-forward.h:360
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:436
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365
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