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 <string>
17 
19  alignas(8) uint64_t tv_sec;
20  alignas(8) uint64_t tv_usec;
21 };
22 
23 // PRSTATUS structure's size differs based on architecture.
24 // This is the layout in the x86-64 arch.
25 // In the i386 case we parse it manually and fill it again
26 // in the same structure
27 // The gp registers are also a part of this struct, but they are handled
28 // separately
29 
30 #undef si_signo
31 #undef si_code
32 #undef si_errno
33 
35  int32_t si_signo;
36  int32_t si_code;
37  int32_t si_errno;
38 
39  int16_t pr_cursig;
40 
41  alignas(8) uint64_t pr_sigpend;
42  alignas(8) uint64_t pr_sighold;
43 
48 
53 
55 
57  const lldb_private::ArchSpec &arch);
58 
59  // Return the bytesize of the structure
60  // 64 bit - just sizeof
61  // 32 bit - hardcoded because we are reusing the struct, but some of the
62  // members are smaller -
63  // so the layout is not the same
64  static size_t GetSize(const lldb_private::ArchSpec &arch);
65 };
66 
67 static_assert(sizeof(ELFLinuxPrStatus) == 112,
68  "sizeof ELFLinuxPrStatus is not correct!");
69 
71  int32_t si_signo;
72  int32_t si_code;
73  int32_t si_errno;
74 
76 
78  const lldb_private::ArchSpec &arch);
79 
80  // Return the bytesize of the structure
81  // 64 bit - just sizeof
82  // 32 bit - hardcoded because we are reusing the struct, but some of the
83  // members are smaller -
84  // so the layout is not the same
85  static size_t GetSize(const lldb_private::ArchSpec &arch);
86 };
87 
88 static_assert(sizeof(ELFLinuxSigInfo) == 12,
89  "sizeof ELFLinuxSigInfo is not correct!");
90 
91 // PRPSINFO structure's size differs based on architecture.
92 // This is the layout in the x86-64 arch case.
93 // In the i386 case we parse it manually and fill it again
94 // in the same structure
96  char pr_state;
97  char pr_sname;
98  char pr_zomb;
99  char pr_nice;
100  alignas(8) uint64_t pr_flag;
103  int32_t pr_pid;
104  int32_t pr_ppid;
105  int32_t pr_pgrp;
106  int32_t pr_sid;
107  char pr_fname[16];
108  char pr_psargs[80];
109 
111 
113  const lldb_private::ArchSpec &arch);
114 
115  // Return the bytesize of the structure
116  // 64 bit - just sizeof
117  // 32 bit - hardcoded because we are reusing the struct, but some of the
118  // members are smaller -
119  // so the layout is not the same
120  static size_t GetSize(const lldb_private::ArchSpec &arch);
121 };
122 
123 static_assert(sizeof(ELFLinuxPrPsInfo) == 136,
124  "sizeof ELFLinuxPrPsInfo is not correct!");
125 
126 struct ThreadData {
128  std::vector<lldb_private::CoreNote> notes;
130  int signo = 0;
131  int prstatus_sig = 0;
133 };
134 
136 public:
137  ThreadElfCore(lldb_private::Process &process, const ThreadData &td);
138 
139  ~ThreadElfCore() override;
140 
141  void RefreshStateAfterStop() override;
142 
143  lldb::RegisterContextSP GetRegisterContext() override;
144 
145  lldb::RegisterContextSP
147 
148  static bool ThreadIDIsValid(lldb::tid_t thread) { return thread != 0; }
149 
150  const char *GetName() override {
151  if (m_thread_name.empty())
152  return nullptr;
153  return m_thread_name.c_str();
154  }
155 
156  void SetName(const char *name) override {
157  if (name && name[0])
158  m_thread_name.assign(name);
159  else
160  m_thread_name.clear();
161  }
162 
163 protected:
164  // Member variables.
166  lldb::RegisterContextSP m_thread_reg_ctx_sp;
167 
168  int m_signo;
169 
171  std::vector<lldb_private::CoreNote> m_notes;
172 
173  bool CalculateStopInfo() override;
174 };
175 
176 #endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
ELFLinuxPrStatus::pr_sid
uint32_t pr_sid
Definition: ThreadElfCore.h:47
ELFLinuxPrPsInfo::pr_fname
char pr_fname[16]
Definition: ThreadElfCore.h:107
ELFLinuxPrStatus::GetSize
static size_t GetSize(const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:235
lldb_private::ArchSpec
Definition: ArchSpec.h:33
ELFLinuxPrStatus
Definition: ThreadElfCore.h:34
ELFLinuxPrPsInfo::pr_psargs
char pr_psargs[80]
Definition: ThreadElfCore.h:108
ThreadData::gpregset
lldb_private::DataExtractor gpregset
Definition: ThreadElfCore.h:127
ThreadElfCore::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
Definition: ThreadElfCore.cpp:64
ThreadData::prstatus_sig
int prstatus_sig
Definition: ThreadElfCore.h:131
ELFLinuxSigInfo::Parse
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:398
ELFLinuxSigInfo::GetSize
static size_t GetSize(const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:383
ThreadElfCore::RefreshStateAfterStop
void RefreshStateAfterStop() override
Definition: ThreadElfCore.cpp:52
ThreadData::signo
int signo
Definition: ThreadElfCore.h:130
ELFLinuxPrStatus::pr_stime
compat_timeval pr_stime
Definition: ThreadElfCore.h:50
ELFLinuxPrPsInfo::ELFLinuxPrPsInfo
ELFLinuxPrPsInfo()
Definition: ThreadElfCore.cpp:305
lldb_private::Process
Definition: Process.h:340
ELFLinuxPrStatus::pr_sigpend
uint64_t pr_sigpend
Definition: ThreadElfCore.h:41
RegisterUtilities.h
ELFLinuxPrPsInfo::pr_flag
uint64_t pr_flag
Definition: ThreadElfCore.h:100
ThreadElfCore::m_gpregset_data
lldb_private::DataExtractor m_gpregset_data
Definition: ThreadElfCore.h:170
ELFLinuxPrPsInfo::pr_pgrp
int32_t pr_pgrp
Definition: ThreadElfCore.h:105
ELFLinuxPrStatus::si_code
int32_t si_code
Definition: ThreadElfCore.h:36
ELFLinuxPrStatus::ELFLinuxPrStatus
ELFLinuxPrStatus()
Definition: ThreadElfCore.cpp:231
ELFLinuxSigInfo::si_errno
int32_t si_errno
Definition: ThreadElfCore.h:73
ELFLinuxPrStatus::Parse
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:261
ELFLinuxPrStatus::pr_ppid
uint32_t pr_ppid
Definition: ThreadElfCore.h:45
ELFLinuxPrPsInfo::Parse
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:330
ELFLinuxPrPsInfo
Definition: ThreadElfCore.h:95
ELFLinuxPrPsInfo::GetSize
static size_t GetSize(const lldb_private::ArchSpec &arch)
Definition: ThreadElfCore.cpp:309
ThreadElfCore::~ThreadElfCore
~ThreadElfCore() override
Definition: ThreadElfCore.cpp:50
ThreadElfCore::SetName
void SetName(const char *name) override
Definition: ThreadElfCore.h:156
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::Thread
Definition: Thread.h:60
ELFLinuxPrPsInfo::pr_nice
char pr_nice
Definition: ThreadElfCore.h:99
compat_timeval::tv_usec
uint64_t tv_usec
Definition: ThreadElfCore.h:20
ELFLinuxPrPsInfo::pr_ppid
int32_t pr_ppid
Definition: ThreadElfCore.h:104
ThreadData::tid
lldb::tid_t tid
Definition: ThreadElfCore.h:129
ELFLinuxPrStatus::pr_pgrp
uint32_t pr_pgrp
Definition: ThreadElfCore.h:46
ThreadElfCore::ThreadElfCore
ThreadElfCore(lldb_private::Process &process, const ThreadData &td)
Definition: ThreadElfCore.cpp:46
ThreadElfCore::m_thread_name
std::string m_thread_name
Definition: ThreadElfCore.h:165
ELFLinuxSigInfo::si_signo
int32_t si_signo
Definition: ThreadElfCore.h:71
ELFLinuxPrPsInfo::pr_zomb
char pr_zomb
Definition: ThreadElfCore.h:98
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
Thread.h
compat_timeval
Definition: ThreadElfCore.h:18
ELFLinuxSigInfo
Definition: ThreadElfCore.h:70
ELFLinuxPrStatus::si_errno
int32_t si_errno
Definition: ThreadElfCore.h:37
ThreadElfCore::m_notes
std::vector< lldb_private::CoreNote > m_notes
Definition: ThreadElfCore.h:171
ELFLinuxPrPsInfo::pr_sid
int32_t pr_sid
Definition: ThreadElfCore.h:106
ELFLinuxPrStatus::pr_pid
uint32_t pr_pid
Definition: ThreadElfCore.h:44
ELFLinuxSigInfo::si_code
int32_t si_code
Definition: ThreadElfCore.h:72
ELFLinuxPrStatus::pr_cursig
int16_t pr_cursig
Definition: ThreadElfCore.h:39
lldb_private::Status
Definition: Status.h:44
compat_timeval::tv_sec
uint64_t tv_sec
Definition: ThreadElfCore.h:19
ELFLinuxPrStatus::pr_cutime
compat_timeval pr_cutime
Definition: ThreadElfCore.h:51
uint32_t
ELFLinuxPrStatus::pr_utime
compat_timeval pr_utime
Definition: ThreadElfCore.h:49
ELFLinuxPrPsInfo::pr_sname
char pr_sname
Definition: ThreadElfCore.h:97
ELFLinuxSigInfo::ELFLinuxSigInfo
ELFLinuxSigInfo()
Definition: ThreadElfCore.cpp:381
ThreadData
Definition: ThreadElfCore.h:126
ELFLinuxPrStatus::pr_cstime
compat_timeval pr_cstime
Definition: ThreadElfCore.h:52
ThreadElfCore::ThreadIDIsValid
static bool ThreadIDIsValid(lldb::tid_t thread)
Definition: ThreadElfCore.h:148
ThreadElfCore::m_signo
int m_signo
Definition: ThreadElfCore.h:168
ELFLinuxPrStatus::pr_sighold
uint64_t pr_sighold
Definition: ThreadElfCore.h:42
DataExtractor.h
ThreadElfCore::m_thread_reg_ctx_sp
lldb::RegisterContextSP m_thread_reg_ctx_sp
Definition: ThreadElfCore.h:166
ThreadElfCore::GetName
const char * GetName() override
Definition: ThreadElfCore.h:150
ThreadData::notes
std::vector< lldb_private::CoreNote > notes
Definition: ThreadElfCore.h:128
ELFLinuxPrPsInfo::pr_gid
uint32_t pr_gid
Definition: ThreadElfCore.h:102
ThreadData::name
std::string name
Definition: ThreadElfCore.h:132
ELFLinuxPrStatus::si_signo
int32_t si_signo
Definition: ThreadElfCore.h:35
ELFLinuxPrPsInfo::pr_pid
int32_t pr_pid
Definition: ThreadElfCore.h:103
lldb_private::StackFrame
Definition: StackFrame.h:40
ELFLinuxPrPsInfo::pr_state
char pr_state
Definition: ThreadElfCore.h:96
ThreadElfCore
Definition: ThreadElfCore.h:135
ThreadElfCore::GetRegisterContext
lldb::RegisterContextSP GetRegisterContext() override
Definition: ThreadElfCore.cpp:56
ThreadElfCore::CalculateStopInfo
bool CalculateStopInfo() override
Definition: ThreadElfCore.cpp:221
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
ELFLinuxPrPsInfo::pr_uid
uint32_t pr_uid
Definition: ThreadElfCore.h:101