xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
15ffd83dbSDimitry Andric //===-- PlatformNetBSD.cpp ------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "PlatformNetBSD.h"
100b57cec5SDimitry Andric #include "lldb/Host/Config.h"
110b57cec5SDimitry Andric 
12fe6060f1SDimitry Andric #include <cstdio>
13480093f4SDimitry Andric #if LLDB_ENABLE_POSIX
140b57cec5SDimitry Andric #include <sys/utsname.h>
150b57cec5SDimitry Andric #endif
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
180b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
190b57cec5SDimitry Andric #include "lldb/Host/HostInfo.h"
200b57cec5SDimitry Andric #include "lldb/Target/Process.h"
210b57cec5SDimitry Andric #include "lldb/Target/Target.h"
220b57cec5SDimitry Andric #include "lldb/Utility/FileSpec.h"
2381ad6265SDimitry Andric #include "lldb/Utility/LLDBLog.h"
240b57cec5SDimitry Andric #include "lldb/Utility/Log.h"
250b57cec5SDimitry Andric #include "lldb/Utility/State.h"
260b57cec5SDimitry Andric #include "lldb/Utility/Status.h"
270b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h"
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric // Define these constants from NetBSD mman.h for use when targeting remote
300b57cec5SDimitry Andric // netbsd systems even when host has different values.
310b57cec5SDimitry Andric #define MAP_PRIVATE 0x0002
320b57cec5SDimitry Andric #define MAP_ANON 0x1000
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric using namespace lldb;
350b57cec5SDimitry Andric using namespace lldb_private;
360b57cec5SDimitry Andric using namespace lldb_private::platform_netbsd;
370b57cec5SDimitry Andric 
385ffd83dbSDimitry Andric LLDB_PLUGIN_DEFINE(PlatformNetBSD)
395ffd83dbSDimitry Andric 
400b57cec5SDimitry Andric static uint32_t g_initialize_count = 0;
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric 
CreateInstance(bool force,const ArchSpec * arch)430b57cec5SDimitry Andric PlatformSP PlatformNetBSD::CreateInstance(bool force, const ArchSpec *arch) {
4481ad6265SDimitry Andric   Log *log = GetLog(LLDBLog::Platform);
450b57cec5SDimitry Andric   LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
460b57cec5SDimitry Andric            arch ? arch->GetArchitectureName() : "<null>",
470b57cec5SDimitry Andric            arch ? arch->GetTriple().getTriple() : "<null>");
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   bool create = force;
500b57cec5SDimitry Andric   if (!create && arch && arch->IsValid()) {
510b57cec5SDimitry Andric     const llvm::Triple &triple = arch->GetTriple();
520b57cec5SDimitry Andric     switch (triple.getOS()) {
530b57cec5SDimitry Andric     case llvm::Triple::NetBSD:
540b57cec5SDimitry Andric       create = true;
550b57cec5SDimitry Andric       break;
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric     default:
580b57cec5SDimitry Andric       break;
590b57cec5SDimitry Andric     }
600b57cec5SDimitry Andric   }
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric   LLDB_LOG(log, "create = {0}", create);
630b57cec5SDimitry Andric   if (create) {
640b57cec5SDimitry Andric     return PlatformSP(new PlatformNetBSD(false));
650b57cec5SDimitry Andric   }
660b57cec5SDimitry Andric   return PlatformSP();
670b57cec5SDimitry Andric }
680b57cec5SDimitry Andric 
GetPluginDescriptionStatic(bool is_host)69349cc55cSDimitry Andric llvm::StringRef PlatformNetBSD::GetPluginDescriptionStatic(bool is_host) {
700b57cec5SDimitry Andric   if (is_host)
710b57cec5SDimitry Andric     return "Local NetBSD user platform plug-in.";
720b57cec5SDimitry Andric   return "Remote NetBSD user platform plug-in.";
730b57cec5SDimitry Andric }
740b57cec5SDimitry Andric 
Initialize()750b57cec5SDimitry Andric void PlatformNetBSD::Initialize() {
760b57cec5SDimitry Andric   PlatformPOSIX::Initialize();
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   if (g_initialize_count++ == 0) {
790b57cec5SDimitry Andric #if defined(__NetBSD__)
800b57cec5SDimitry Andric     PlatformSP default_platform_sp(new PlatformNetBSD(true));
810b57cec5SDimitry Andric     default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
820b57cec5SDimitry Andric     Platform::SetHostPlatform(default_platform_sp);
830b57cec5SDimitry Andric #endif
840b57cec5SDimitry Andric     PluginManager::RegisterPlugin(
850b57cec5SDimitry Andric         PlatformNetBSD::GetPluginNameStatic(false),
860b57cec5SDimitry Andric         PlatformNetBSD::GetPluginDescriptionStatic(false),
870b57cec5SDimitry Andric         PlatformNetBSD::CreateInstance, nullptr);
880b57cec5SDimitry Andric   }
890b57cec5SDimitry Andric }
900b57cec5SDimitry Andric 
Terminate()910b57cec5SDimitry Andric void PlatformNetBSD::Terminate() {
920b57cec5SDimitry Andric   if (g_initialize_count > 0) {
930b57cec5SDimitry Andric     if (--g_initialize_count == 0) {
940b57cec5SDimitry Andric       PluginManager::UnregisterPlugin(PlatformNetBSD::CreateInstance);
950b57cec5SDimitry Andric     }
960b57cec5SDimitry Andric   }
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   PlatformPOSIX::Terminate();
990b57cec5SDimitry Andric }
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric /// Default Constructor
PlatformNetBSD(bool is_host)1020b57cec5SDimitry Andric PlatformNetBSD::PlatformNetBSD(bool is_host)
1030b57cec5SDimitry Andric     : PlatformPOSIX(is_host) // This is the local host platform
104349cc55cSDimitry Andric {
105349cc55cSDimitry Andric   if (is_host) {
1060b57cec5SDimitry Andric     ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
107349cc55cSDimitry Andric     m_supported_architectures.push_back(hostArch);
108349cc55cSDimitry Andric     if (hostArch.GetTriple().isArch64Bit()) {
109349cc55cSDimitry Andric       m_supported_architectures.push_back(
110349cc55cSDimitry Andric           HostInfo::GetArchitecture(HostInfo::eArchKind32));
1110b57cec5SDimitry Andric     }
1120b57cec5SDimitry Andric   } else {
113349cc55cSDimitry Andric     m_supported_architectures = CreateArchList(
114349cc55cSDimitry Andric         {llvm::Triple::x86_64, llvm::Triple::x86}, llvm::Triple::NetBSD);
115349cc55cSDimitry Andric   }
116349cc55cSDimitry Andric }
117349cc55cSDimitry Andric 
11881ad6265SDimitry Andric std::vector<ArchSpec>
GetSupportedArchitectures(const ArchSpec & process_host_arch)11981ad6265SDimitry Andric PlatformNetBSD::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
1200b57cec5SDimitry Andric   if (m_remote_platform_sp)
12181ad6265SDimitry Andric     return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
122349cc55cSDimitry Andric   return m_supported_architectures;
1230b57cec5SDimitry Andric }
1240b57cec5SDimitry Andric 
GetStatus(Stream & strm)1250b57cec5SDimitry Andric void PlatformNetBSD::GetStatus(Stream &strm) {
1260b57cec5SDimitry Andric   Platform::GetStatus(strm);
1270b57cec5SDimitry Andric 
128480093f4SDimitry Andric #if LLDB_ENABLE_POSIX
1290b57cec5SDimitry Andric   // Display local kernel information only when we are running in host mode.
1300b57cec5SDimitry Andric   // Otherwise, we would end up printing non-NetBSD information (when running
1310b57cec5SDimitry Andric   // on Mac OS for example).
1320b57cec5SDimitry Andric   if (IsHost()) {
1330b57cec5SDimitry Andric     struct utsname un;
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric     if (uname(&un))
1360b57cec5SDimitry Andric       return;
1370b57cec5SDimitry Andric 
1380b57cec5SDimitry Andric     strm.Printf("    Kernel: %s\n", un.sysname);
1390b57cec5SDimitry Andric     strm.Printf("   Release: %s\n", un.release);
1400b57cec5SDimitry Andric     strm.Printf("   Version: %s\n", un.version);
1410b57cec5SDimitry Andric   }
1420b57cec5SDimitry Andric #endif
1430b57cec5SDimitry Andric }
1440b57cec5SDimitry Andric 
145e8d8bef9SDimitry Andric uint32_t
GetResumeCountForLaunchInfo(ProcessLaunchInfo & launch_info)1460b57cec5SDimitry Andric PlatformNetBSD::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
147e8d8bef9SDimitry Andric   uint32_t resume_count = 0;
1480b57cec5SDimitry Andric 
1490b57cec5SDimitry Andric   // Always resume past the initial stop when we use eLaunchFlagDebug
1500b57cec5SDimitry Andric   if (launch_info.GetFlags().Test(eLaunchFlagDebug)) {
1510b57cec5SDimitry Andric     // Resume past the stop for the final exec into the true inferior.
1520b57cec5SDimitry Andric     ++resume_count;
1530b57cec5SDimitry Andric   }
1540b57cec5SDimitry Andric 
1550b57cec5SDimitry Andric   // If we're not launching a shell, we're done.
1560b57cec5SDimitry Andric   const FileSpec &shell = launch_info.GetShell();
1570b57cec5SDimitry Andric   if (!shell)
1580b57cec5SDimitry Andric     return resume_count;
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric   std::string shell_string = shell.GetPath();
1610b57cec5SDimitry Andric   // We're in a shell, so for sure we have to resume past the shell exec.
1620b57cec5SDimitry Andric   ++resume_count;
1630b57cec5SDimitry Andric 
1640b57cec5SDimitry Andric   // Figure out what shell we're planning on using.
1650b57cec5SDimitry Andric   const char *shell_name = strrchr(shell_string.c_str(), '/');
1660b57cec5SDimitry Andric   if (shell_name == nullptr)
1670b57cec5SDimitry Andric     shell_name = shell_string.c_str();
1680b57cec5SDimitry Andric   else
1690b57cec5SDimitry Andric     shell_name++;
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric   if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 ||
1720b57cec5SDimitry Andric       strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) {
1730b57cec5SDimitry Andric     // These shells seem to re-exec themselves.  Add another resume.
1740b57cec5SDimitry Andric     ++resume_count;
1750b57cec5SDimitry Andric   }
1760b57cec5SDimitry Andric 
1770b57cec5SDimitry Andric   return resume_count;
1780b57cec5SDimitry Andric }
1790b57cec5SDimitry Andric 
CanDebugProcess()1800b57cec5SDimitry Andric bool PlatformNetBSD::CanDebugProcess() {
1810b57cec5SDimitry Andric   if (IsHost()) {
1820b57cec5SDimitry Andric     return true;
1830b57cec5SDimitry Andric   } else {
1840b57cec5SDimitry Andric     // If we're connected, we can debug.
1850b57cec5SDimitry Andric     return IsConnected();
1860b57cec5SDimitry Andric   }
1870b57cec5SDimitry Andric }
1880b57cec5SDimitry Andric 
CalculateTrapHandlerSymbolNames()1890b57cec5SDimitry Andric void PlatformNetBSD::CalculateTrapHandlerSymbolNames() {
1900b57cec5SDimitry Andric   m_trap_handlers.push_back(ConstString("_sigtramp"));
1910b57cec5SDimitry Andric }
1920b57cec5SDimitry Andric 
GetMmapArgumentList(const ArchSpec & arch,addr_t addr,addr_t length,unsigned prot,unsigned flags,addr_t fd,addr_t offset)1930b57cec5SDimitry Andric MmapArgList PlatformNetBSD::GetMmapArgumentList(const ArchSpec &arch,
1940b57cec5SDimitry Andric                                                 addr_t addr, addr_t length,
1950b57cec5SDimitry Andric                                                 unsigned prot, unsigned flags,
1960b57cec5SDimitry Andric                                                 addr_t fd, addr_t offset) {
1970b57cec5SDimitry Andric   uint64_t flags_platform = 0;
1980b57cec5SDimitry Andric 
1990b57cec5SDimitry Andric   if (flags & eMmapFlagsPrivate)
2000b57cec5SDimitry Andric     flags_platform |= MAP_PRIVATE;
2010b57cec5SDimitry Andric   if (flags & eMmapFlagsAnon)
2020b57cec5SDimitry Andric     flags_platform |= MAP_ANON;
2030b57cec5SDimitry Andric 
2040b57cec5SDimitry Andric   MmapArgList args({addr, length, prot, flags_platform, fd, offset});
2050b57cec5SDimitry Andric   return args;
2060b57cec5SDimitry Andric }
20704eeddc0SDimitry Andric 
GetSiginfoType(const llvm::Triple & triple)20804eeddc0SDimitry Andric CompilerType PlatformNetBSD::GetSiginfoType(const llvm::Triple &triple) {
209bdd1243dSDimitry Andric   {
210bdd1243dSDimitry Andric     std::lock_guard<std::mutex> guard(m_mutex);
211bdd1243dSDimitry Andric     if (!m_type_system)
212bdd1243dSDimitry Andric       m_type_system = std::make_shared<TypeSystemClang>("siginfo", triple);
213bdd1243dSDimitry Andric   }
214bdd1243dSDimitry Andric   TypeSystemClang *ast = m_type_system.get();
21504eeddc0SDimitry Andric 
21604eeddc0SDimitry Andric   // generic types
21704eeddc0SDimitry Andric   CompilerType int_type = ast->GetBasicType(eBasicTypeInt);
21804eeddc0SDimitry Andric   CompilerType uint_type = ast->GetBasicType(eBasicTypeUnsignedInt);
21904eeddc0SDimitry Andric   CompilerType long_type = ast->GetBasicType(eBasicTypeLong);
22004eeddc0SDimitry Andric   CompilerType long_long_type = ast->GetBasicType(eBasicTypeLongLong);
22104eeddc0SDimitry Andric   CompilerType voidp_type = ast->GetBasicType(eBasicTypeVoid).GetPointerType();
22204eeddc0SDimitry Andric 
22304eeddc0SDimitry Andric   // platform-specific types
22404eeddc0SDimitry Andric   CompilerType &pid_type = int_type;
22504eeddc0SDimitry Andric   CompilerType &uid_type = uint_type;
22604eeddc0SDimitry Andric   CompilerType &clock_type = uint_type;
22704eeddc0SDimitry Andric   CompilerType &lwpid_type = int_type;
22804eeddc0SDimitry Andric 
22904eeddc0SDimitry Andric   CompilerType sigval_type = ast->CreateRecordType(
23004eeddc0SDimitry Andric       nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_sigval_t",
231*5f757f3fSDimitry Andric       llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
23204eeddc0SDimitry Andric   ast->StartTagDeclarationDefinition(sigval_type);
23304eeddc0SDimitry Andric   ast->AddFieldToRecordType(sigval_type, "sival_int", int_type,
23404eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
23504eeddc0SDimitry Andric   ast->AddFieldToRecordType(sigval_type, "sival_ptr", voidp_type,
23604eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
23704eeddc0SDimitry Andric   ast->CompleteTagDeclarationDefinition(sigval_type);
23804eeddc0SDimitry Andric 
23904eeddc0SDimitry Andric   CompilerType ptrace_option_type = ast->CreateRecordType(
24004eeddc0SDimitry Andric       nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
241*5f757f3fSDimitry Andric       llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
24204eeddc0SDimitry Andric   ast->StartTagDeclarationDefinition(ptrace_option_type);
24304eeddc0SDimitry Andric   ast->AddFieldToRecordType(ptrace_option_type, "_pe_other_pid", pid_type,
24404eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
24504eeddc0SDimitry Andric   ast->AddFieldToRecordType(ptrace_option_type, "_pe_lwp", lwpid_type,
24604eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
24704eeddc0SDimitry Andric   ast->CompleteTagDeclarationDefinition(ptrace_option_type);
24804eeddc0SDimitry Andric 
24904eeddc0SDimitry Andric   // siginfo_t
25004eeddc0SDimitry Andric   CompilerType siginfo_type = ast->CreateRecordType(
25104eeddc0SDimitry Andric       nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_siginfo_t",
252*5f757f3fSDimitry Andric       llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
25304eeddc0SDimitry Andric   ast->StartTagDeclarationDefinition(siginfo_type);
25404eeddc0SDimitry Andric 
25504eeddc0SDimitry Andric   // struct _ksiginfo
25604eeddc0SDimitry Andric   CompilerType ksiginfo_type = ast->CreateRecordType(
25704eeddc0SDimitry Andric       nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
258*5f757f3fSDimitry Andric       llvm::to_underlying(clang::TagTypeKind::Struct), lldb::eLanguageTypeC);
25904eeddc0SDimitry Andric   ast->StartTagDeclarationDefinition(ksiginfo_type);
26004eeddc0SDimitry Andric   ast->AddFieldToRecordType(ksiginfo_type, "_signo", int_type,
26104eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
26204eeddc0SDimitry Andric   ast->AddFieldToRecordType(ksiginfo_type, "_code", int_type,
26304eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
26404eeddc0SDimitry Andric   ast->AddFieldToRecordType(ksiginfo_type, "_errno", int_type,
26504eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
26604eeddc0SDimitry Andric 
26704eeddc0SDimitry Andric   // the structure is padded on 64-bit arches to fix alignment
26804eeddc0SDimitry Andric   if (triple.isArch64Bit())
26904eeddc0SDimitry Andric     ast->AddFieldToRecordType(ksiginfo_type, "__pad0", int_type,
27004eeddc0SDimitry Andric                               lldb::eAccessPublic, 0);
27104eeddc0SDimitry Andric 
27204eeddc0SDimitry Andric   // union used to hold the signal data
27304eeddc0SDimitry Andric   CompilerType union_type = ast->CreateRecordType(
27404eeddc0SDimitry Andric       nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
275*5f757f3fSDimitry Andric       llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
27604eeddc0SDimitry Andric   ast->StartTagDeclarationDefinition(union_type);
27704eeddc0SDimitry Andric 
27804eeddc0SDimitry Andric   ast->AddFieldToRecordType(
27904eeddc0SDimitry Andric       union_type, "_rt",
28006c3fb27SDimitry Andric       ast->CreateStructForIdentifier(llvm::StringRef(),
28104eeddc0SDimitry Andric                                      {
28204eeddc0SDimitry Andric                                          {"_pid", pid_type},
28304eeddc0SDimitry Andric                                          {"_uid", uid_type},
28404eeddc0SDimitry Andric                                          {"_value", sigval_type},
28504eeddc0SDimitry Andric                                      }),
28604eeddc0SDimitry Andric       lldb::eAccessPublic, 0);
28704eeddc0SDimitry Andric 
28804eeddc0SDimitry Andric   ast->AddFieldToRecordType(
28904eeddc0SDimitry Andric       union_type, "_child",
29006c3fb27SDimitry Andric       ast->CreateStructForIdentifier(llvm::StringRef(),
29104eeddc0SDimitry Andric                                      {
29204eeddc0SDimitry Andric                                          {"_pid", pid_type},
29304eeddc0SDimitry Andric                                          {"_uid", uid_type},
29404eeddc0SDimitry Andric                                          {"_status", int_type},
29504eeddc0SDimitry Andric                                          {"_utime", clock_type},
29604eeddc0SDimitry Andric                                          {"_stime", clock_type},
29704eeddc0SDimitry Andric                                      }),
29804eeddc0SDimitry Andric       lldb::eAccessPublic, 0);
29904eeddc0SDimitry Andric 
30004eeddc0SDimitry Andric   ast->AddFieldToRecordType(
30104eeddc0SDimitry Andric       union_type, "_fault",
30206c3fb27SDimitry Andric       ast->CreateStructForIdentifier(llvm::StringRef(),
30304eeddc0SDimitry Andric                                      {
30404eeddc0SDimitry Andric                                          {"_addr", voidp_type},
30504eeddc0SDimitry Andric                                          {"_trap", int_type},
30604eeddc0SDimitry Andric                                          {"_trap2", int_type},
30704eeddc0SDimitry Andric                                          {"_trap3", int_type},
30804eeddc0SDimitry Andric                                      }),
30904eeddc0SDimitry Andric       lldb::eAccessPublic, 0);
31004eeddc0SDimitry Andric 
31104eeddc0SDimitry Andric   ast->AddFieldToRecordType(
31204eeddc0SDimitry Andric       union_type, "_poll",
31306c3fb27SDimitry Andric       ast->CreateStructForIdentifier(llvm::StringRef(),
31404eeddc0SDimitry Andric                                      {
31504eeddc0SDimitry Andric                                          {"_band", long_type},
31604eeddc0SDimitry Andric                                          {"_fd", int_type},
31704eeddc0SDimitry Andric                                      }),
31804eeddc0SDimitry Andric       lldb::eAccessPublic, 0);
31904eeddc0SDimitry Andric 
32004eeddc0SDimitry Andric   ast->AddFieldToRecordType(union_type, "_syscall",
32104eeddc0SDimitry Andric                             ast->CreateStructForIdentifier(
32206c3fb27SDimitry Andric                                 llvm::StringRef(),
32304eeddc0SDimitry Andric                                 {
32404eeddc0SDimitry Andric                                     {"_sysnum", int_type},
32504eeddc0SDimitry Andric                                     {"_retval", int_type.GetArrayType(2)},
32604eeddc0SDimitry Andric                                     {"_error", int_type},
32704eeddc0SDimitry Andric                                     {"_args", long_long_type.GetArrayType(8)},
32804eeddc0SDimitry Andric                                 }),
32904eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
33004eeddc0SDimitry Andric 
33104eeddc0SDimitry Andric   ast->AddFieldToRecordType(
33204eeddc0SDimitry Andric       union_type, "_ptrace_state",
33306c3fb27SDimitry Andric       ast->CreateStructForIdentifier(llvm::StringRef(),
33404eeddc0SDimitry Andric                                      {
33504eeddc0SDimitry Andric                                          {"_pe_report_event", int_type},
33604eeddc0SDimitry Andric                                          {"_option", ptrace_option_type},
33704eeddc0SDimitry Andric                                      }),
33804eeddc0SDimitry Andric       lldb::eAccessPublic, 0);
33904eeddc0SDimitry Andric 
34004eeddc0SDimitry Andric   ast->CompleteTagDeclarationDefinition(union_type);
34104eeddc0SDimitry Andric   ast->AddFieldToRecordType(ksiginfo_type, "_reason", union_type,
34204eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
34304eeddc0SDimitry Andric 
34404eeddc0SDimitry Andric   ast->CompleteTagDeclarationDefinition(ksiginfo_type);
34504eeddc0SDimitry Andric   ast->AddFieldToRecordType(siginfo_type, "_info", ksiginfo_type,
34604eeddc0SDimitry Andric                             lldb::eAccessPublic, 0);
34704eeddc0SDimitry Andric 
34804eeddc0SDimitry Andric   ast->CompleteTagDeclarationDefinition(siginfo_type);
34904eeddc0SDimitry Andric   return siginfo_type;
35004eeddc0SDimitry Andric }
351