LLDB mainline
ThreadElfCore.h
Go to the documentation of this file.
1//===-- ThreadElfCore.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//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
11
13#include "lldb/Target/Thread.h"
15#include "llvm/ADT/DenseMap.h"
16#include <optional>
17#include <string>
18
20 alignas(8) uint64_t tv_sec;
21 alignas(8) uint64_t tv_usec;
22};
23
24namespace lldb_private {
25class ProcessInstanceInfo;
26}
27
28// PRSTATUS structure's size differs based on architecture.
29// This is the layout in the x86-64 arch.
30// In the i386 case we parse it manually and fill it again
31// in the same structure
32// The gp registers are also a part of this struct, but they are handled
33// separately
34
35#undef si_signo
36#undef si_code
37#undef si_errno
38#undef si_addr
39#undef si_addr_lsb
40
42 int32_t si_signo;
43 int32_t si_code;
44 int32_t si_errno;
45
46 int16_t pr_cursig;
47
48 alignas(8) uint64_t pr_sigpend;
49 alignas(8) uint64_t pr_sighold;
50
51 uint32_t pr_pid;
52 uint32_t pr_ppid;
53 uint32_t pr_pgrp;
54 uint32_t pr_sid;
55
60
62
64 const lldb_private::ArchSpec &arch);
65
66 static std::optional<ELFLinuxPrStatus>
67 Populate(const lldb::ThreadSP &thread_sp);
68
69 // Return the bytesize of the structure
70 // 64 bit - just sizeof
71 // 32 bit - hardcoded because we are reusing the struct, but some of the
72 // members are smaller -
73 // so the layout is not the same
74 static size_t GetSize(const lldb_private::ArchSpec &arch);
75};
76
77static_assert(sizeof(ELFLinuxPrStatus) == 112,
78 "sizeof ELFLinuxPrStatus is not correct!");
79
81
82 int32_t si_signo; // Order matters for the first 3.
83 int32_t si_errno;
84 int32_t si_code;
85 // Copied from siginfo_t so we don't have to include signal.h on non 'Nix
86 // builds. Slight modifications to ensure no 32b vs 64b differences.
87 struct alignas(8) {
88 lldb::addr_t si_addr; /* faulting insn/memory ref. */
89 int16_t si_addr_lsb; /* Valid LSB of the reported address. */
90 union {
91 /* used when si_code=SEGV_BNDERR */
92 struct {
96 /* used when si_code=SEGV_PKUERR */
97 uint32_t _pkey;
100
103
105
107 const lldb_private::ArchSpec &arch,
108 const lldb_private::UnixSignals &unix_signals);
109
110 std::string
111 GetDescription(const lldb_private::UnixSignals &unix_signals) const;
112
113 // Return the bytesize of the structure
114 // 64 bit - just sizeof
115 // 32 bit - hardcoded because we are reusing the struct, but some of the
116 // members are smaller -
117 // so the layout is not the same
118 static size_t GetSize(const lldb_private::ArchSpec &arch);
119};
120
121static_assert(sizeof(ELFLinuxSigInfo) == 56,
122 "sizeof ELFLinuxSigInfo is not correct!");
123
124// PRPSINFO structure's size differs based on architecture.
125// This is the layout in the x86-64 arch case.
126// In the i386 case we parse it manually and fill it again
127// in the same structure
133 alignas(8) uint64_t pr_flag;
134 uint32_t pr_uid;
135 uint32_t pr_gid;
136 int32_t pr_pid;
137 int32_t pr_ppid;
138 int32_t pr_pgrp;
139 int32_t pr_sid;
140 char pr_fname[16];
141 char pr_psargs[80];
142
144
146 const lldb_private::ArchSpec &arch);
147
148 static std::optional<ELFLinuxPrPsInfo>
149 Populate(const lldb::ProcessSP &process_sp);
150
151 static std::optional<ELFLinuxPrPsInfo>
153 lldb::StateType state);
154
155 // Return the bytesize of the structure
156 // 64 bit - just sizeof
157 // 32 bit - hardcoded because we are reusing the struct, but some of the
158 // members are smaller -
159 // so the layout is not the same
160 static size_t GetSize(const lldb_private::ArchSpec &arch);
161};
162
163static_assert(sizeof(ELFLinuxPrPsInfo) == 136,
164 "sizeof ELFLinuxPrPsInfo is not correct!");
165
168 std::vector<lldb_private::CoreNote> notes;
170 std::string name;
173};
174
176public:
178
179 ~ThreadElfCore() override;
180
181 void RefreshStateAfterStop() override;
182
184
187
188 static bool ThreadIDIsValid(lldb::tid_t thread) { return thread != 0; }
189
190 const char *GetName() override {
191 if (m_thread_name.empty())
192 return nullptr;
193 return m_thread_name.c_str();
194 }
195
196 void SetName(const char *name) override {
197 if (name && name[0])
198 m_thread_name.assign(name);
199 else
200 m_thread_name.clear();
201 }
202
204 const lldb_private::UnixSignals &unix_signals);
205
206protected:
207 // Member variables.
208 std::string m_thread_name;
210
212 std::vector<lldb_private::CoreNote> m_notes;
214
215 bool CalculateStopInfo() override;
216};
217
218#endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
void RefreshStateAfterStop() override
lldb::RegisterContextSP GetRegisterContext() override
~ThreadElfCore() override
std::string m_thread_name
const char * GetName() override
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
std::vector< lldb_private::CoreNote > m_notes
lldb::RegisterContextSP m_thread_reg_ctx_sp
lldb_private::DataExtractor m_gpregset_data
bool CalculateStopInfo() override
Ask the thread subclass to set its stop info.
static bool ThreadIDIsValid(lldb::tid_t thread)
void CreateStopFromSigInfo(const ELFLinuxSigInfo &siginfo, const lldb_private::UnixSignals &unix_signals)
void SetName(const char *name) override
ELFLinuxSigInfo m_siginfo
An architecture specification class.
Definition: ArchSpec.h:31
An data extractor class.
Definition: DataExtractor.h:48
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
This base class provides an interface to stack frames.
Definition: StackFrame.h:44
An error handling class.
Definition: Status.h:118
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
StateType
Process and Thread States.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Definition: lldb-forward.h:394
uint64_t tid_t
Definition: lldb-types.h:84
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
static size_t GetSize(const lldb_private::ArchSpec &arch)
static std::optional< ELFLinuxPrPsInfo > Populate(const lldb::ProcessSP &process_sp)
static size_t GetSize(const lldb_private::ArchSpec &arch)
uint64_t pr_sighold
Definition: ThreadElfCore.h:49
compat_timeval pr_cutime
Definition: ThreadElfCore.h:58
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
uint64_t pr_sigpend
Definition: ThreadElfCore.h:48
compat_timeval pr_stime
Definition: ThreadElfCore.h:57
compat_timeval pr_utime
Definition: ThreadElfCore.h:56
static std::optional< ELFLinuxPrStatus > Populate(const lldb::ThreadSP &thread_sp)
compat_timeval pr_cstime
Definition: ThreadElfCore.h:59
struct ELFLinuxSigInfo::alignas::@76::@77 _addr_bnd
union ELFLinuxSigInfo::alignas::@76 bounds
struct ELFLinuxSigInfo::alignas sigfault
static size_t GetSize(const lldb_private::ArchSpec &arch)
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch, const lldb_private::UnixSignals &unix_signals)
SigInfoNoteType note_type
std::string GetDescription(const lldb_private::UnixSignals &unix_signals) const
lldb::tid_t tid
ELFLinuxSigInfo siginfo
std::string name
lldb_private::DataExtractor gpregset
std::vector< lldb_private::CoreNote > notes
uint64_t tv_sec
Definition: ThreadElfCore.h:20
uint64_t tv_usec
Definition: ThreadElfCore.h:21