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 
24 #include "lldb/Utility/Status.h"
25 
28 
29 struct ThreadData;
30 
32 public:
33  // Constructors and Destructors
34  static lldb::ProcessSP
35  CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
36  const lldb_private::FileSpec *crash_file_path,
37  bool can_connect);
38 
39  static void Initialize();
40 
41  static void Terminate();
42 
43  static llvm::StringRef GetPluginNameStatic() { return "elf-core"; }
44 
45  static llvm::StringRef GetPluginDescriptionStatic();
46 
47  // Constructors and Destructors
48  ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
49  const lldb_private::FileSpec &core_file);
50 
51  ~ProcessElfCore() override;
52 
53  // Check if a given Process
54  bool CanDebug(lldb::TargetSP target_sp,
55  bool plugin_specified_by_name) override;
56 
57  // Creating a new process, or attaching to an existing one
59 
61 
62  // PluginInterface protocol
63  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
64 
65  // Process Control
67 
68  void RefreshStateAfterStop() override;
69 
72  error.SetErrorStringWithFormatv(
73  "error: {0} does not support resuming processes", GetPluginName());
74  return error;
75  }
76 
77  // Process Queries
78  bool IsAlive() override;
79 
80  bool WarnBeforeDetach() const override { return false; }
81 
82  // Process Memory
83  size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
84  lldb_private::Status &error) override;
85 
86  size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
87  lldb_private::Status &error) override;
88 
90 
92 
93  // Returns AUXV structure found in the core file
95 
97 
98 protected:
99  void Clear();
100 
101  bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
102  lldb_private::ThreadList &new_thread_list) override;
103 
106  lldb_private::MemoryRegionInfo &region_info) override;
107 
108 private:
109  struct NT_FILE_Entry {
114  };
115 
116  // For ProcessElfCore only
122 
123  lldb::ModuleSP m_core_module_sp;
126 
127  // True if m_thread_contexts contains valid entries
128  bool m_thread_data_valid = false;
129 
130  // Contain thread data read from NOTE segments
131  std::vector<ThreadData> m_thread_data;
132 
133  // AUXV structure found from the NOTE segment
135 
136  // Address ranges found in the core
138 
139  // Permissions for all ranges
141 
142  // NT_FILE entries found from the NOTE segment
143  std::vector<NT_FILE_Entry> m_nt_file_entries;
144 
145  // Parse thread(s) data structures(prstatus, prpsinfo) from given NOTE segment
147  const elf::ELFProgramHeader &segment_header,
148  const lldb_private::DataExtractor &segment_data);
149 
150  // Returns number of thread contexts stored in the core file
152 
153  // Parse a contiguous address range of the process from LOAD segment
156 
157  llvm::Expected<std::vector<lldb_private::CoreNote>>
159  llvm::Error parseFreeBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
160  llvm::Error parseNetBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
161  llvm::Error parseOpenBSDNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
162  llvm::Error parseLinuxNotes(llvm::ArrayRef<lldb_private::CoreNote> notes);
163 };
164 
165 #endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_PROCESSELFCORE_H
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
ProcessElfCore::Initialize
static void Initialize()
Definition: ProcessElfCore.cpp:385
ProcessElfCore::GetAuxvData
lldb_private::DataExtractor GetAuxvData() override
Definition: ProcessElfCore.cpp:943
lldb_private::ArchSpec
Definition: ArchSpec.h:33
ProcessElfCore::parseLinuxNotes
llvm::Error parseLinuxNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
A description of a linux process usually contains the following NOTE entries:
Definition: ProcessElfCore.cpp:810
ProcessElfCore::ReadMemory
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
Definition: ProcessElfCore.cpp:283
ProcessElfCore::AddAddressRangeFromLoadSegment
lldb::addr_t AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader &header)
Definition: ProcessElfCore.cpp:114
ProcessElfCore::m_dyld_plugin_name
std::string m_dyld_plugin_name
Definition: ProcessElfCore.h:125
ProcessElfCore::m_core_file
lldb_private::FileSpec m_core_file
Definition: ProcessElfCore.h:124
ProcessElfCore::IsAlive
bool IsAlive() override
Check if a process is still alive.
Definition: ProcessElfCore.cpp:280
ProcessElfCore::RefreshStateAfterStop
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
Definition: ProcessElfCore.cpp:274
ProcessElfCore::WillResume
lldb_private::Status WillResume() override
Called before resuming to a process.
Definition: ProcessElfCore.h:70
RegisterUtilities.h
ProcessElfCore::m_core_range_infos
VMRangeToPermissions m_core_range_infos
Definition: ProcessElfCore.h:140
ProcessElfCore::m_thread_data_valid
bool m_thread_data_valid
Definition: ProcessElfCore.h:128
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
ProcessElfCore::DoLoadCore
lldb_private::Status DoLoadCore() override
Definition: ProcessElfCore.cpp:148
ProcessElfCore::m_core_aranges
VMRangeToFileOffset m_core_aranges
Definition: ProcessElfCore.h:137
ProcessElfCore::NT_FILE_Entry
Definition: ProcessElfCore.h:109
ProcessElfCore::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessElfCore.h:43
ProcessElfCore::GetDynamicLoader
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Definition: ProcessElfCore.cpp:253
ELFHeader.h
ProcessElfCore::GetImageInfoAddress
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
Definition: ProcessElfCore.cpp:394
ProcessElfCore::VMRangeToFileOffset
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, FileRange > VMRangeToFileOffset
Definition: ProcessElfCore.h:119
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
ProcessElfCore::Terminate
static void Terminate()
Definition: ProcessElfCore.cpp:46
lldb_private::DataExtractor
Definition: DataExtractor.h:48
ProcessElfCore::FileRange
lldb_private::Range< lldb::addr_t, lldb::addr_t > FileRange
Definition: ProcessElfCore.h:117
ProcessElfCore::~ProcessElfCore
~ProcessElfCore() override
Definition: ProcessElfCore.cpp:105
ProcessElfCore::VMRangeToPermissions
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, uint32_t > VMRangeToPermissions
Definition: ProcessElfCore.h:121
ProcessElfCore::GetNumThreadContexts
uint32_t GetNumThreadContexts()
Definition: ProcessElfCore.cpp:921
ProcessElfCore::GetProcessInfo
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override
Definition: ProcessElfCore.cpp:950
ProcessElfCore::m_auxv
lldb_private::DataExtractor m_auxv
Definition: ProcessElfCore.h:134
lldb_private::ThreadList
Definition: ThreadList.h:26
lldb_private::ConstString
Definition: ConstString.h:40
ProcessElfCore::ParseThreadContextsFromNoteSegment
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 ...
Definition: ProcessElfCore.cpp:897
lldb_private::PostMortemProcess
Definition: PostMortemProcess.h:23
ProcessElfCore::m_thread_data
std::vector< ThreadData > m_thread_data
Definition: ProcessElfCore.h:131
ProcessElfCore::DoGetMemoryRegionInfo
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...
Definition: ProcessElfCore.cpp:293
lldb_private::Range< lldb::addr_t, lldb::addr_t >
ProcessElfCore::DoUpdateThreadList
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.
Definition: ProcessElfCore.cpp:260
ProcessElfCore::DoReadMemory
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.
Definition: ProcessElfCore.cpp:333
ProcessElfCore::parseSegment
llvm::Expected< std::vector< lldb_private::CoreNote > > parseSegment(const lldb_private::DataExtractor &segment)
Definition: ProcessElfCore.cpp:509
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
ProcessElfCore::ProcessElfCore
ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec &core_file)
Definition: ProcessElfCore.cpp:99
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
ProcessElfCore::WarnBeforeDetach
bool WarnBeforeDetach() const override
Before lldb detaches from a process, it warns the user that they are about to lose their debug sessio...
Definition: ProcessElfCore.h:80
ProcessElfCore::m_core_module_sp
lldb::ModuleSP m_core_module_sp
Definition: ProcessElfCore.h:123
PostMortemProcess.h
ProcessElfCore::Clear
void Clear()
Definition: ProcessElfCore.cpp:379
ProcessElfCore::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: ProcessElfCore.cpp:42
ProcessElfCore::NT_FILE_Entry::file_ofs
lldb::addr_t file_ofs
Definition: ProcessElfCore.h:112
lldb_private::Status
Definition: Status.h:44
uint32_t
ProcessElfCore::NT_FILE_Entry::start
lldb::addr_t start
Definition: ProcessElfCore.h:110
ThreadData
Definition: ThreadElfCore.h:126
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, FileRange >
elf::ELFProgramHeader
Definition: ELFHeader.h:192
ProcessElfCore::parseNetBSDNotes
llvm::Error parseNetBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
NetBSD specific Thread context from PT_NOTE segment.
Definition: ProcessElfCore.cpp:606
ProcessElfCore::DoDestroy
lldb_private::Status DoDestroy() override
Definition: ProcessElfCore.cpp:276
ProcessElfCore::parseFreeBSDNotes
llvm::Error parseFreeBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
Definition: ProcessElfCore.cpp:529
ProcessElfCore::GetPluginName
llvm::StringRef GetPluginName() override
Definition: ProcessElfCore.h:63
Status.h
ProcessElfCore::NT_FILE_Entry::path
lldb_private::ConstString path
Definition: ProcessElfCore.h:113
ProcessElfCore::parseOpenBSDNotes
llvm::Error parseOpenBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
Definition: ProcessElfCore.cpp:766
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
ProcessElfCore::m_nt_file_entries
std::vector< NT_FILE_Entry > m_nt_file_entries
Definition: ProcessElfCore.h:143
ConstString.h
ProcessElfCore::NT_FILE_Entry::end
lldb::addr_t end
Definition: ProcessElfCore.h:111
ProcessElfCore
Definition: ProcessElfCore.h:31
ProcessElfCore::CreateInstance
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
Definition: ProcessElfCore.cpp:50
ProcessElfCore::CanDebug
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
Definition: ProcessElfCore.cpp:82
ProcessElfCore::GetArchitecture
lldb_private::ArchSpec GetArchitecture()
Definition: ProcessElfCore.cpp:927