1 //===-- ThreadElfCore.h -----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
12 #include "Plugins/Process/elf-core/RegisterUtilities.h"
13 #include "lldb/Target/Thread.h"
14 #include "lldb/Utility/DataExtractor.h"
15 #include "llvm/ADT/DenseMap.h"
18 struct compat_timeval
{
19 alignas(8) uint64_t tv_sec
;
20 alignas(8) uint64_t tv_usec
;
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
34 struct ELFLinuxPrStatus
{
41 alignas(8) uint64_t pr_sigpend
;
42 alignas(8) uint64_t pr_sighold
;
49 compat_timeval pr_utime
;
50 compat_timeval pr_stime
;
51 compat_timeval pr_cutime
;
52 compat_timeval pr_cstime
;
56 lldb_private::Status
Parse(const lldb_private::DataExtractor
&data
,
57 const lldb_private::ArchSpec
&arch
);
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
);
67 static_assert(sizeof(ELFLinuxPrStatus
) == 112,
68 "sizeof ELFLinuxPrStatus is not correct!");
70 struct ELFLinuxSigInfo
{
77 lldb_private::Status
Parse(const lldb_private::DataExtractor
&data
,
78 const lldb_private::ArchSpec
&arch
);
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
);
88 static_assert(sizeof(ELFLinuxSigInfo
) == 12,
89 "sizeof ELFLinuxSigInfo is not correct!");
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
95 struct ELFLinuxPrPsInfo
{
100 alignas(8) uint64_t pr_flag
;
112 lldb_private::Status
Parse(const lldb_private::DataExtractor
&data
,
113 const lldb_private::ArchSpec
&arch
);
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
);
123 static_assert(sizeof(ELFLinuxPrPsInfo
) == 136,
124 "sizeof ELFLinuxPrPsInfo is not correct!");
127 lldb_private::DataExtractor gpregset
;
128 std::vector
<lldb_private::CoreNote
> notes
;
132 int prstatus_sig
= 0;
136 class ThreadElfCore
: public lldb_private::Thread
{
138 ThreadElfCore(lldb_private::Process
&process
, const ThreadData
&td
);
140 ~ThreadElfCore() override
;
142 void RefreshStateAfterStop() override
;
144 lldb::RegisterContextSP
GetRegisterContext() override
;
146 lldb::RegisterContextSP
147 CreateRegisterContextForFrame(lldb_private::StackFrame
*frame
) override
;
149 static bool ThreadIDIsValid(lldb::tid_t thread
) { return thread
!= 0; }
151 const char *GetName() override
{
152 if (m_thread_name
.empty())
154 return m_thread_name
.c_str();
157 void SetName(const char *name
) override
{
159 m_thread_name
.assign(name
);
161 m_thread_name
.clear();
166 std::string m_thread_name
;
167 lldb::RegisterContextSP m_thread_reg_ctx_sp
;
172 lldb_private::DataExtractor m_gpregset_data
;
173 std::vector
<lldb_private::CoreNote
> m_notes
;
175 bool CalculateStopInfo() override
;
178 #endif // LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H