180814287SRaphael Isemann //===-- ThreadElfCore.cpp -------------------------------------------------===//
24f01ff8bSAshok Thirumurthi //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64f01ff8bSAshok Thirumurthi //
74f01ff8bSAshok Thirumurthi //===----------------------------------------------------------------------===//
84f01ff8bSAshok Thirumurthi
94f01ff8bSAshok Thirumurthi #include "lldb/Target/RegisterContext.h"
104f01ff8bSAshok Thirumurthi #include "lldb/Target/StopInfo.h"
114f01ff8bSAshok Thirumurthi #include "lldb/Target/Target.h"
124f01ff8bSAshok Thirumurthi #include "lldb/Target/Unwind.h"
13666cc0b2SZachary Turner #include "lldb/Utility/DataExtractor.h"
14*c34698a8SPavel Labath #include "lldb/Utility/LLDBLog.h"
156f9e6901SZachary Turner #include "lldb/Utility/Log.h"
164f01ff8bSAshok Thirumurthi
17cacde7dfSTodd Fiala #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
18cacde7dfSTodd Fiala #include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
196256a0eaSJustin Hibbits #include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
20cacde7dfSTodd Fiala #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
21b9c1b51eSKate Stone #include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
22b9c1b51eSKate Stone #include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
23b9c1b51eSKate Stone #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
24d4c437c4SMichał Górny #include "Plugins/Process/Utility/RegisterContextNetBSD_i386.h"
253eef2b5eSKamil Rytarowski #include "Plugins/Process/Utility/RegisterContextNetBSD_x86_64.h"
2612801f1eSKamil Rytarowski #include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h"
2712801f1eSKamil Rytarowski #include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
284b2b6bfbSPavel Labath #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
293f8c7816SPavel Labath #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
30fd2c8d65SPavel Labath #include "Plugins/Process/Utility/RegisterInfoPOSIX_ppc64le.h"
31b9c1b51eSKate Stone #include "ProcessElfCore.h"
323f57216cSOmair Javaid #include "RegisterContextPOSIXCore_arm.h"
337754d21aSEd Maste #include "RegisterContextPOSIXCore_arm64.h"
34b73f844bSEd Maste #include "RegisterContextPOSIXCore_mips64.h"
356256a0eaSJustin Hibbits #include "RegisterContextPOSIXCore_powerpc.h"
36fd2c8d65SPavel Labath #include "RegisterContextPOSIXCore_ppc64le.h"
37bb00d0b6SUlrich Weigand #include "RegisterContextPOSIXCore_s390x.h"
380a37085fSMichael Sartain #include "RegisterContextPOSIXCore_x86_64.h"
39b9c1b51eSKate Stone #include "ThreadElfCore.h"
404f01ff8bSAshok Thirumurthi
41796ac80bSJonas Devlieghere #include <memory>
42796ac80bSJonas Devlieghere
434f01ff8bSAshok Thirumurthi using namespace lldb;
444f01ff8bSAshok Thirumurthi using namespace lldb_private;
454f01ff8bSAshok Thirumurthi
46c05ae522SEd Maste // Construct a Thread object with given data
ThreadElfCore(Process & process,const ThreadData & td)47b9c1b51eSKate Stone ThreadElfCore::ThreadElfCore(Process &process, const ThreadData &td)
48b9c1b51eSKate Stone : Thread(process, td.tid), m_thread_name(td.name), m_thread_reg_ctx_sp(),
49bc8cc867SPavel Labath m_signo(td.signo), m_gpregset_data(td.gpregset), m_notes(td.notes) {}
504f01ff8bSAshok Thirumurthi
~ThreadElfCore()51b9c1b51eSKate Stone ThreadElfCore::~ThreadElfCore() { DestroyThread(); }
524f01ff8bSAshok Thirumurthi
RefreshStateAfterStop()53b9c1b51eSKate Stone void ThreadElfCore::RefreshStateAfterStop() {
544f01ff8bSAshok Thirumurthi GetRegisterContext()->InvalidateIfNeeded(false);
554f01ff8bSAshok Thirumurthi }
564f01ff8bSAshok Thirumurthi
GetRegisterContext()57b9c1b51eSKate Stone RegisterContextSP ThreadElfCore::GetRegisterContext() {
5845d8134cSStella Stamenova if (!m_reg_context_sp) {
5945d8134cSStella Stamenova m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
604f01ff8bSAshok Thirumurthi }
614f01ff8bSAshok Thirumurthi return m_reg_context_sp;
624f01ff8bSAshok Thirumurthi }
634f01ff8bSAshok Thirumurthi
644f01ff8bSAshok Thirumurthi RegisterContextSP
CreateRegisterContextForFrame(StackFrame * frame)65b9c1b51eSKate Stone ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
664f01ff8bSAshok Thirumurthi RegisterContextSP reg_ctx_sp;
674f01ff8bSAshok Thirumurthi uint32_t concrete_frame_idx = 0;
68a007a6d8SPavel Labath Log *log = GetLog(LLDBLog::Thread);
694f01ff8bSAshok Thirumurthi
704f01ff8bSAshok Thirumurthi if (frame)
714f01ff8bSAshok Thirumurthi concrete_frame_idx = frame->GetConcreteFrameIndex();
724f01ff8bSAshok Thirumurthi
73b9c1b51eSKate Stone if (concrete_frame_idx == 0) {
744f01ff8bSAshok Thirumurthi if (m_thread_reg_ctx_sp)
754f01ff8bSAshok Thirumurthi return m_thread_reg_ctx_sp;
764f01ff8bSAshok Thirumurthi
774f01ff8bSAshok Thirumurthi ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
784f01ff8bSAshok Thirumurthi ArchSpec arch = process->GetArchitecture();
7945d8134cSStella Stamenova RegisterInfoInterface *reg_interface = nullptr;
808b5e46a1SEd Maste
81b9c1b51eSKate Stone switch (arch.GetTriple().getOS()) {
82b9c1b51eSKate Stone case llvm::Triple::FreeBSD: {
83b9c1b51eSKate Stone switch (arch.GetMachine()) {
847754d21aSEd Maste case llvm::Triple::aarch64:
8597df86ceSEd Maste case llvm::Triple::arm:
8697df86ceSEd Maste break;
876256a0eaSJustin Hibbits case llvm::Triple::ppc:
886256a0eaSJustin Hibbits reg_interface = new RegisterContextFreeBSD_powerpc32(arch);
896256a0eaSJustin Hibbits break;
906256a0eaSJustin Hibbits case llvm::Triple::ppc64:
916256a0eaSJustin Hibbits reg_interface = new RegisterContextFreeBSD_powerpc64(arch);
926256a0eaSJustin Hibbits break;
93b73f844bSEd Maste case llvm::Triple::mips64:
948b5e46a1SEd Maste reg_interface = new RegisterContextFreeBSD_mips64(arch);
95b73f844bSEd Maste break;
9692b1f7e4SEd Maste case llvm::Triple::x86:
978b5e46a1SEd Maste reg_interface = new RegisterContextFreeBSD_i386(arch);
9892b1f7e4SEd Maste break;
994f01ff8bSAshok Thirumurthi case llvm::Triple::x86_64:
1008b5e46a1SEd Maste reg_interface = new RegisterContextFreeBSD_x86_64(arch);
1017d675373SEd Maste break;
1028b5e46a1SEd Maste default:
1038b5e46a1SEd Maste break;
1048b5e46a1SEd Maste }
1058b5e46a1SEd Maste break;
1068b5e46a1SEd Maste }
1078b5e46a1SEd Maste
1083eef2b5eSKamil Rytarowski case llvm::Triple::NetBSD: {
1093eef2b5eSKamil Rytarowski switch (arch.GetMachine()) {
110d8519f4aSMichal Gorny case llvm::Triple::aarch64:
111d8519f4aSMichal Gorny break;
112d4c437c4SMichał Górny case llvm::Triple::x86:
113d4c437c4SMichał Górny reg_interface = new RegisterContextNetBSD_i386(arch);
114d4c437c4SMichał Górny break;
1153eef2b5eSKamil Rytarowski case llvm::Triple::x86_64:
1163eef2b5eSKamil Rytarowski reg_interface = new RegisterContextNetBSD_x86_64(arch);
1173eef2b5eSKamil Rytarowski break;
1183eef2b5eSKamil Rytarowski default:
1193eef2b5eSKamil Rytarowski break;
1203eef2b5eSKamil Rytarowski }
1213eef2b5eSKamil Rytarowski break;
1223eef2b5eSKamil Rytarowski }
1233eef2b5eSKamil Rytarowski
124b9c1b51eSKate Stone case llvm::Triple::Linux: {
125b9c1b51eSKate Stone switch (arch.GetMachine()) {
126b78e05feSOmair Javaid case llvm::Triple::aarch64:
127b78e05feSOmair Javaid break;
128fd2c8d65SPavel Labath case llvm::Triple::ppc64le:
129fd2c8d65SPavel Labath reg_interface = new RegisterInfoPOSIX_ppc64le(arch);
130fd2c8d65SPavel Labath break;
131bb00d0b6SUlrich Weigand case llvm::Triple::systemz:
132bb00d0b6SUlrich Weigand reg_interface = new RegisterContextLinux_s390x(arch);
133bb00d0b6SUlrich Weigand break;
134023dd64fSDimitar Vlahovski case llvm::Triple::x86:
135023dd64fSDimitar Vlahovski reg_interface = new RegisterContextLinux_i386(arch);
136023dd64fSDimitar Vlahovski break;
1378b5e46a1SEd Maste case llvm::Triple::x86_64:
1388b5e46a1SEd Maste reg_interface = new RegisterContextLinux_x86_64(arch);
1397d675373SEd Maste break;
1407d675373SEd Maste default:
1417d675373SEd Maste break;
1427d675373SEd Maste }
1434f01ff8bSAshok Thirumurthi break;
1444f01ff8bSAshok Thirumurthi }
1458b5e46a1SEd Maste
14612801f1eSKamil Rytarowski case llvm::Triple::OpenBSD: {
14712801f1eSKamil Rytarowski switch (arch.GetMachine()) {
14812801f1eSKamil Rytarowski case llvm::Triple::aarch64:
14912801f1eSKamil Rytarowski break;
15012801f1eSKamil Rytarowski case llvm::Triple::x86:
15112801f1eSKamil Rytarowski reg_interface = new RegisterContextOpenBSD_i386(arch);
15212801f1eSKamil Rytarowski break;
15312801f1eSKamil Rytarowski case llvm::Triple::x86_64:
15412801f1eSKamil Rytarowski reg_interface = new RegisterContextOpenBSD_x86_64(arch);
15512801f1eSKamil Rytarowski break;
15612801f1eSKamil Rytarowski default:
15712801f1eSKamil Rytarowski break;
15812801f1eSKamil Rytarowski }
15912801f1eSKamil Rytarowski break;
16012801f1eSKamil Rytarowski }
16112801f1eSKamil Rytarowski
1628b5e46a1SEd Maste default:
1638b5e46a1SEd Maste break;
1648b5e46a1SEd Maste }
1658b5e46a1SEd Maste
16676953321SMuhammad Omair Javaid if (!reg_interface && arch.GetMachine() != llvm::Triple::aarch64 &&
16776953321SMuhammad Omair Javaid arch.GetMachine() != llvm::Triple::arm) {
16863e5fb76SJonas Devlieghere LLDB_LOGF(log, "elf-core::%s:: Architecture(%d) or OS(%d) not supported",
1698b5e46a1SEd Maste __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS());
1708b5e46a1SEd Maste assert(false && "Architecture or OS not supported");
1718b5e46a1SEd Maste }
1728b5e46a1SEd Maste
173b9c1b51eSKate Stone switch (arch.GetMachine()) {
1747754d21aSEd Maste case llvm::Triple::aarch64:
175d6d3d21cSMuhammad Omair Javaid m_thread_reg_ctx_sp = RegisterContextCorePOSIX_arm64::Create(
176d6d3d21cSMuhammad Omair Javaid *this, arch, m_gpregset_data, m_notes);
1777754d21aSEd Maste break;
1783f57216cSOmair Javaid case llvm::Triple::arm:
179796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_arm>(
18076953321SMuhammad Omair Javaid *this, std::make_unique<RegisterInfoPOSIX_arm>(arch), m_gpregset_data,
18176953321SMuhammad Omair Javaid m_notes);
1823f57216cSOmair Javaid break;
183b8dbd323SNitesh Jain case llvm::Triple::mipsel:
184b8dbd323SNitesh Jain case llvm::Triple::mips:
185796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_mips64>(
186796ac80bSJonas Devlieghere *this, reg_interface, m_gpregset_data, m_notes);
187b8dbd323SNitesh Jain break;
1888b5e46a1SEd Maste case llvm::Triple::mips64:
189b8dbd323SNitesh Jain case llvm::Triple::mips64el:
190796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_mips64>(
191796ac80bSJonas Devlieghere *this, reg_interface, m_gpregset_data, m_notes);
1928b5e46a1SEd Maste break;
1936256a0eaSJustin Hibbits case llvm::Triple::ppc:
1946256a0eaSJustin Hibbits case llvm::Triple::ppc64:
195796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_powerpc>(
196796ac80bSJonas Devlieghere *this, reg_interface, m_gpregset_data, m_notes);
1976256a0eaSJustin Hibbits break;
198fd2c8d65SPavel Labath case llvm::Triple::ppc64le:
199796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_ppc64le>(
200796ac80bSJonas Devlieghere *this, reg_interface, m_gpregset_data, m_notes);
201fd2c8d65SPavel Labath break;
202bb00d0b6SUlrich Weigand case llvm::Triple::systemz:
203796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_s390x>(
204796ac80bSJonas Devlieghere *this, reg_interface, m_gpregset_data, m_notes);
205bb00d0b6SUlrich Weigand break;
2068b5e46a1SEd Maste case llvm::Triple::x86:
2078b5e46a1SEd Maste case llvm::Triple::x86_64:
208796ac80bSJonas Devlieghere m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_x86_64>(
209796ac80bSJonas Devlieghere *this, reg_interface, m_gpregset_data, m_notes);
2108b5e46a1SEd Maste break;
2118b5e46a1SEd Maste default:
2128b5e46a1SEd Maste break;
2138b5e46a1SEd Maste }
2148b5e46a1SEd Maste
2154f01ff8bSAshok Thirumurthi reg_ctx_sp = m_thread_reg_ctx_sp;
21645d8134cSStella Stamenova } else {
217c0b1af68SPavel Labath reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
2184f01ff8bSAshok Thirumurthi }
2194f01ff8bSAshok Thirumurthi return reg_ctx_sp;
2204f01ff8bSAshok Thirumurthi }
2214f01ff8bSAshok Thirumurthi
CalculateStopInfo()222b9c1b51eSKate Stone bool ThreadElfCore::CalculateStopInfo() {
2234f01ff8bSAshok Thirumurthi ProcessSP process_sp(GetProcess());
224b9c1b51eSKate Stone if (process_sp) {
225c05ae522SEd Maste SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
2264f01ff8bSAshok Thirumurthi return true;
2274f01ff8bSAshok Thirumurthi }
2284f01ff8bSAshok Thirumurthi return false;
2294f01ff8bSAshok Thirumurthi }
2304f01ff8bSAshok Thirumurthi
2314f01ff8bSAshok Thirumurthi // Parse PRSTATUS from NOTE entry
ELFLinuxPrStatus()232b9c1b51eSKate Stone ELFLinuxPrStatus::ELFLinuxPrStatus() {
233974acf1cSEd Maste memset(this, 0, sizeof(ELFLinuxPrStatus));
2344f01ff8bSAshok Thirumurthi }
2354f01ff8bSAshok Thirumurthi
GetSize(const lldb_private::ArchSpec & arch)236cef4119cSPavel Labath size_t ELFLinuxPrStatus::GetSize(const lldb_private::ArchSpec &arch) {
237b8dbd323SNitesh Jain constexpr size_t mips_linux_pr_status_size_o32 = 96;
238b8dbd323SNitesh Jain constexpr size_t mips_linux_pr_status_size_n32 = 72;
2396795eb38SGreg Clayton constexpr size_t num_ptr_size_members = 10;
240b8dbd323SNitesh Jain if (arch.IsMIPS()) {
241b8dbd323SNitesh Jain std::string abi = arch.GetTargetABI();
242b8dbd323SNitesh Jain assert(!abi.empty() && "ABI is not set");
243b8dbd323SNitesh Jain if (!abi.compare("n64"))
244b8dbd323SNitesh Jain return sizeof(ELFLinuxPrStatus);
245b8dbd323SNitesh Jain else if (!abi.compare("o32"))
246b8dbd323SNitesh Jain return mips_linux_pr_status_size_o32;
247b8dbd323SNitesh Jain // N32 ABI
248b8dbd323SNitesh Jain return mips_linux_pr_status_size_n32;
249b8dbd323SNitesh Jain }
250b8dbd323SNitesh Jain switch (arch.GetCore()) {
251b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_32_i386:
252b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_32_i486:
253b8dbd323SNitesh Jain return 72;
254b8dbd323SNitesh Jain default:
2556795eb38SGreg Clayton if (arch.GetAddressByteSize() == 8)
2566795eb38SGreg Clayton return sizeof(ELFLinuxPrStatus);
2576795eb38SGreg Clayton else
2586795eb38SGreg Clayton return sizeof(ELFLinuxPrStatus) - num_ptr_size_members * 4;
259b8dbd323SNitesh Jain }
260b8dbd323SNitesh Jain }
261b8dbd323SNitesh Jain
Parse(const DataExtractor & data,const ArchSpec & arch)262cef4119cSPavel Labath Status ELFLinuxPrStatus::Parse(const DataExtractor &data,
263cef4119cSPavel Labath const ArchSpec &arch) {
26497206d57SZachary Turner Status error;
265b9c1b51eSKate Stone if (GetSize(arch) > data.GetByteSize()) {
266b9c1b51eSKate Stone error.SetErrorStringWithFormat(
2675a8ad459SZachary Turner "NT_PRSTATUS size should be %zu, but the remaining bytes are: %" PRIu64,
268023dd64fSDimitar Vlahovski GetSize(arch), data.GetByteSize());
269023dd64fSDimitar Vlahovski return error;
270023dd64fSDimitar Vlahovski }
271023dd64fSDimitar Vlahovski
27205097246SAdrian Prantl // Read field by field to correctly account for endianess of both the core
27305097246SAdrian Prantl // dump and the platform running lldb.
274023dd64fSDimitar Vlahovski offset_t offset = 0;
275023dd64fSDimitar Vlahovski si_signo = data.GetU32(&offset);
276023dd64fSDimitar Vlahovski si_code = data.GetU32(&offset);
277023dd64fSDimitar Vlahovski si_errno = data.GetU32(&offset);
278023dd64fSDimitar Vlahovski
279023dd64fSDimitar Vlahovski pr_cursig = data.GetU16(&offset);
280023dd64fSDimitar Vlahovski offset += 2; // pad
281023dd64fSDimitar Vlahovski
2820863f675SPavel Labath pr_sigpend = data.GetAddress(&offset);
2830863f675SPavel Labath pr_sighold = data.GetAddress(&offset);
284023dd64fSDimitar Vlahovski
285023dd64fSDimitar Vlahovski pr_pid = data.GetU32(&offset);
286023dd64fSDimitar Vlahovski pr_ppid = data.GetU32(&offset);
287023dd64fSDimitar Vlahovski pr_pgrp = data.GetU32(&offset);
288023dd64fSDimitar Vlahovski pr_sid = data.GetU32(&offset);
289023dd64fSDimitar Vlahovski
2900863f675SPavel Labath pr_utime.tv_sec = data.GetAddress(&offset);
2910863f675SPavel Labath pr_utime.tv_usec = data.GetAddress(&offset);
292023dd64fSDimitar Vlahovski
2930863f675SPavel Labath pr_stime.tv_sec = data.GetAddress(&offset);
2940863f675SPavel Labath pr_stime.tv_usec = data.GetAddress(&offset);
295023dd64fSDimitar Vlahovski
2960863f675SPavel Labath pr_cutime.tv_sec = data.GetAddress(&offset);
2970863f675SPavel Labath pr_cutime.tv_usec = data.GetAddress(&offset);
298023dd64fSDimitar Vlahovski
2990863f675SPavel Labath pr_cstime.tv_sec = data.GetAddress(&offset);
3000863f675SPavel Labath pr_cstime.tv_usec = data.GetAddress(&offset);
301023dd64fSDimitar Vlahovski
302023dd64fSDimitar Vlahovski return error;
3034f01ff8bSAshok Thirumurthi }
3044f01ff8bSAshok Thirumurthi
3054f01ff8bSAshok Thirumurthi // Parse PRPSINFO from NOTE entry
ELFLinuxPrPsInfo()306b9c1b51eSKate Stone ELFLinuxPrPsInfo::ELFLinuxPrPsInfo() {
307974acf1cSEd Maste memset(this, 0, sizeof(ELFLinuxPrPsInfo));
3084f01ff8bSAshok Thirumurthi }
3094f01ff8bSAshok Thirumurthi
GetSize(const lldb_private::ArchSpec & arch)310cef4119cSPavel Labath size_t ELFLinuxPrPsInfo::GetSize(const lldb_private::ArchSpec &arch) {
311b8dbd323SNitesh Jain constexpr size_t mips_linux_pr_psinfo_size_o32_n32 = 128;
312b8dbd323SNitesh Jain if (arch.IsMIPS()) {
313b8dbd323SNitesh Jain uint8_t address_byte_size = arch.GetAddressByteSize();
314b8dbd323SNitesh Jain if (address_byte_size == 8)
315b8dbd323SNitesh Jain return sizeof(ELFLinuxPrPsInfo);
316b8dbd323SNitesh Jain return mips_linux_pr_psinfo_size_o32_n32;
317b8dbd323SNitesh Jain }
318b8dbd323SNitesh Jain
319b8dbd323SNitesh Jain switch (arch.GetCore()) {
320b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_s390x_generic:
321b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_64_x86_64:
322b8dbd323SNitesh Jain return sizeof(ELFLinuxPrPsInfo);
323b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_32_i386:
324b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_32_i486:
325b8dbd323SNitesh Jain return 124;
326b8dbd323SNitesh Jain default:
327b8dbd323SNitesh Jain return 0;
328b8dbd323SNitesh Jain }
329b8dbd323SNitesh Jain }
330b8dbd323SNitesh Jain
Parse(const DataExtractor & data,const ArchSpec & arch)331cef4119cSPavel Labath Status ELFLinuxPrPsInfo::Parse(const DataExtractor &data,
332cef4119cSPavel Labath const ArchSpec &arch) {
33397206d57SZachary Turner Status error;
3344f01ff8bSAshok Thirumurthi ByteOrder byteorder = data.GetByteOrder();
335b9c1b51eSKate Stone if (GetSize(arch) > data.GetByteSize()) {
336b9c1b51eSKate Stone error.SetErrorStringWithFormat(
3375a8ad459SZachary Turner "NT_PRPSINFO size should be %zu, but the remaining bytes are: %" PRIu64,
338023dd64fSDimitar Vlahovski GetSize(arch), data.GetByteSize());
339023dd64fSDimitar Vlahovski return error;
340023dd64fSDimitar Vlahovski }
341023dd64fSDimitar Vlahovski size_t size = 0;
342023dd64fSDimitar Vlahovski offset_t offset = 0;
343023dd64fSDimitar Vlahovski
344023dd64fSDimitar Vlahovski pr_state = data.GetU8(&offset);
345023dd64fSDimitar Vlahovski pr_sname = data.GetU8(&offset);
346023dd64fSDimitar Vlahovski pr_zomb = data.GetU8(&offset);
347023dd64fSDimitar Vlahovski pr_nice = data.GetU8(&offset);
3489434690aSHoward Hellyer if (data.GetAddressByteSize() == 8) {
3499434690aSHoward Hellyer // Word align the next field on 64 bit.
3509434690aSHoward Hellyer offset += 4;
3519434690aSHoward Hellyer }
352023dd64fSDimitar Vlahovski
3530863f675SPavel Labath pr_flag = data.GetAddress(&offset);
3549434690aSHoward Hellyer
355b8dbd323SNitesh Jain if (arch.IsMIPS()) {
356b8dbd323SNitesh Jain // The pr_uid and pr_gid is always 32 bit irrespective of platforms
357b8dbd323SNitesh Jain pr_uid = data.GetU32(&offset);
358b8dbd323SNitesh Jain pr_gid = data.GetU32(&offset);
359b8dbd323SNitesh Jain } else {
3609434690aSHoward Hellyer // 16 bit on 32 bit platforms, 32 bit on 64 bit platforms
3619434690aSHoward Hellyer pr_uid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
3629434690aSHoward Hellyer pr_gid = data.GetMaxU64(&offset, data.GetAddressByteSize() >> 1);
363b8dbd323SNitesh Jain }
364023dd64fSDimitar Vlahovski
365023dd64fSDimitar Vlahovski pr_pid = data.GetU32(&offset);
366023dd64fSDimitar Vlahovski pr_ppid = data.GetU32(&offset);
367023dd64fSDimitar Vlahovski pr_pgrp = data.GetU32(&offset);
368023dd64fSDimitar Vlahovski pr_sid = data.GetU32(&offset);
369023dd64fSDimitar Vlahovski
370023dd64fSDimitar Vlahovski size = 16;
371023dd64fSDimitar Vlahovski data.ExtractBytes(offset, size, byteorder, pr_fname);
372023dd64fSDimitar Vlahovski offset += size;
373023dd64fSDimitar Vlahovski
374023dd64fSDimitar Vlahovski size = 80;
375023dd64fSDimitar Vlahovski data.ExtractBytes(offset, size, byteorder, pr_psargs);
376023dd64fSDimitar Vlahovski offset += size;
377023dd64fSDimitar Vlahovski
378023dd64fSDimitar Vlahovski return error;
3794f01ff8bSAshok Thirumurthi }
3801a2ac9bdSHoward Hellyer
3811a2ac9bdSHoward Hellyer // Parse SIGINFO from NOTE entry
ELFLinuxSigInfo()3823eef2b5eSKamil Rytarowski ELFLinuxSigInfo::ELFLinuxSigInfo() { memset(this, 0, sizeof(ELFLinuxSigInfo)); }
3831a2ac9bdSHoward Hellyer
GetSize(const lldb_private::ArchSpec & arch)384b8dbd323SNitesh Jain size_t ELFLinuxSigInfo::GetSize(const lldb_private::ArchSpec &arch) {
385b8dbd323SNitesh Jain if (arch.IsMIPS())
386b8dbd323SNitesh Jain return sizeof(ELFLinuxSigInfo);
387b8dbd323SNitesh Jain switch (arch.GetCore()) {
388b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_64_x86_64:
389b8dbd323SNitesh Jain return sizeof(ELFLinuxSigInfo);
390b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_s390x_generic:
391b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_32_i386:
392b8dbd323SNitesh Jain case lldb_private::ArchSpec::eCore_x86_32_i486:
393b8dbd323SNitesh Jain return 12;
394b8dbd323SNitesh Jain default:
395b8dbd323SNitesh Jain return 0;
396b8dbd323SNitesh Jain }
397b8dbd323SNitesh Jain }
398b8dbd323SNitesh Jain
Parse(const DataExtractor & data,const ArchSpec & arch)399cef4119cSPavel Labath Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch) {
40097206d57SZachary Turner Status error;
4011a2ac9bdSHoward Hellyer if (GetSize(arch) > data.GetByteSize()) {
4021a2ac9bdSHoward Hellyer error.SetErrorStringWithFormat(
4031a2ac9bdSHoward Hellyer "NT_SIGINFO size should be %zu, but the remaining bytes are: %" PRIu64,
4041a2ac9bdSHoward Hellyer GetSize(arch), data.GetByteSize());
4051a2ac9bdSHoward Hellyer return error;
4061a2ac9bdSHoward Hellyer }
4071a2ac9bdSHoward Hellyer
4081a2ac9bdSHoward Hellyer // Parsing from a 32 bit ELF core file, and populating/reusing the structure
4091a2ac9bdSHoward Hellyer // properly, because the struct is for the 64 bit version
4101a2ac9bdSHoward Hellyer offset_t offset = 0;
4111a2ac9bdSHoward Hellyer si_signo = data.GetU32(&offset);
4121a2ac9bdSHoward Hellyer si_code = data.GetU32(&offset);
4131a2ac9bdSHoward Hellyer si_errno = data.GetU32(&offset);
4141a2ac9bdSHoward Hellyer
4151a2ac9bdSHoward Hellyer return error;
4161a2ac9bdSHoward Hellyer }
417