#include "NativeProcessLinux.h"
#include <cerrno>
#include <cstdint>
#include <cstring>
#include <unistd.h>
#include <fstream>
#include <mutex>
#include <optional>
#include <sstream>
#include <string>
#include <unordered_map>
#include "NativeThreadLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/LinuxProcMaps.h"
#include "Procfs.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/common/NativeRegisterContext.h"
#include "lldb/Host/linux/Host.h"
#include "lldb/Host/linux/Ptrace.h"
#include "lldb/Host/linux/Uio.h"
#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StringExtractor.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Threading.h"
#include <linux/unistd.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/user.h>
#include <sys/wait.h>
#ifdef __aarch64__
#include <asm/hwcap.h>
#include <sys/auxv.h>
#endif
#ifndef TRAP_HWBKPT
#define TRAP_HWBKPT …
#endif
#ifndef HWCAP2_MTE
#define HWCAP2_MTE …
#endif
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacelldb_private::process_linux;
usingnamespacellvm;
static bool ProcessVmReadvSupported() { … }
static void MaybeLogLaunchInfo(const ProcessLaunchInfo &info) { … }
static void DisplayBytes(StreamString &s, void *bytes, uint32_t count) { … }
static void PtraceDisplayBytes(int &req, void *data, size_t data_size) { … }
static constexpr unsigned k_ptrace_word_size = …;
static_assert …;
static Status EnsureFDFlags(int fd, int flags) { … }
static llvm::Error AddPtraceScopeNote(llvm::Error original_error) { … }
NativeProcessLinux::Manager::Manager(MainLoop &mainloop)
: … { … }
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
NativeProcessLinux::Manager::Launch(ProcessLaunchInfo &launch_info,
NativeDelegate &native_delegate) { … }
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
NativeProcessLinux::Manager::Attach(
lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) { … }
NativeProcessLinux::Extension
NativeProcessLinux::Manager::GetSupportedExtensions() const { … }
static std::optional<std::pair<lldb::pid_t, WaitStatus>> WaitPid() { … }
void NativeProcessLinux::Manager::SigchldHandler() { … }
void NativeProcessLinux::Manager::CollectThread(::pid_t tid) { … }
NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd,
NativeDelegate &delegate,
const ArchSpec &arch, Manager &manager,
llvm::ArrayRef<::pid_t> tids)
: … { … }
llvm::Expected<std::vector<::pid_t>> NativeProcessLinux::Attach(::pid_t pid) { … }
Status NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid) { … }
bool NativeProcessLinux::TryHandleWaitStatus(lldb::pid_t pid,
WaitStatus status) { … }
void NativeProcessLinux::MonitorCallback(NativeThreadLinux &thread,
WaitStatus status) { … }
void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
NativeThreadLinux &thread) { … }
void NativeProcessLinux::MonitorTrace(NativeThreadLinux &thread) { … }
void NativeProcessLinux::MonitorBreakpoint(NativeThreadLinux &thread) { … }
void NativeProcessLinux::MonitorWatchpoint(NativeThreadLinux &thread,
uint32_t wp_index) { … }
void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
NativeThreadLinux &thread) { … }
bool NativeProcessLinux::MonitorClone(NativeThreadLinux &parent,
lldb::pid_t child_pid, int event) { … }
bool NativeProcessLinux::SupportHardwareSingleStepping() const { … }
Status NativeProcessLinux::Resume(const ResumeActionList &resume_actions) { … }
Status NativeProcessLinux::Halt() { … }
Status NativeProcessLinux::Detach() { … }
Status NativeProcessLinux::Signal(int signo) { … }
Status NativeProcessLinux::Interrupt() { … }
Status NativeProcessLinux::Kill() { … }
Status NativeProcessLinux::GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) { … }
Status NativeProcessLinux::PopulateMemoryRegionCache() { … }
void NativeProcessLinux::DoStopIDBumped(uint32_t newBumpId) { … }
llvm::Expected<uint64_t>
NativeProcessLinux::Syscall(llvm::ArrayRef<uint64_t> args) { … }
llvm::Expected<addr_t>
NativeProcessLinux::AllocateMemory(size_t size, uint32_t permissions) { … }
llvm::Error NativeProcessLinux::DeallocateMemory(lldb::addr_t addr) { … }
Status NativeProcessLinux::ReadMemoryTags(int32_t type, lldb::addr_t addr,
size_t len,
std::vector<uint8_t> &tags) { … }
Status NativeProcessLinux::WriteMemoryTags(int32_t type, lldb::addr_t addr,
size_t len,
const std::vector<uint8_t> &tags) { … }
size_t NativeProcessLinux::UpdateThreads() { … }
Status NativeProcessLinux::SetBreakpoint(lldb::addr_t addr, uint32_t size,
bool hardware) { … }
Status NativeProcessLinux::RemoveBreakpoint(lldb::addr_t addr, bool hardware) { … }
llvm::Expected<llvm::ArrayRef<uint8_t>>
NativeProcessLinux::GetSoftwareBreakpointTrapOpcode(size_t size_hint) { … }
Status NativeProcessLinux::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
size_t &bytes_read) { … }
Status NativeProcessLinux::WriteMemory(lldb::addr_t addr, const void *buf,
size_t size, size_t &bytes_written) { … }
Status NativeProcessLinux::GetSignalInfo(lldb::tid_t tid, void *siginfo) const { … }
Status NativeProcessLinux::GetEventMessage(lldb::tid_t tid,
unsigned long *message) { … }
Status NativeProcessLinux::Detach(lldb::tid_t tid) { … }
bool NativeProcessLinux::HasThreadNoLock(lldb::tid_t thread_id) { … }
void NativeProcessLinux::StopTrackingThread(NativeThreadLinux &thread) { … }
void NativeProcessLinux::NotifyTracersProcessDidStop() { … }
void NativeProcessLinux::NotifyTracersProcessWillResume() { … }
Status NativeProcessLinux::NotifyTracersOfNewThread(lldb::tid_t tid) { … }
Status NativeProcessLinux::NotifyTracersOfThreadDestroyed(lldb::tid_t tid) { … }
NativeThreadLinux &NativeProcessLinux::AddThread(lldb::tid_t thread_id,
bool resume) { … }
Status NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path,
FileSpec &file_spec) { … }
Status NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef &file_name,
lldb::addr_t &load_addr) { … }
NativeThreadLinux *NativeProcessLinux::GetThreadByID(lldb::tid_t tid) { … }
NativeThreadLinux *NativeProcessLinux::GetCurrentThread() { … }
Status NativeProcessLinux::ResumeThread(NativeThreadLinux &thread,
lldb::StateType state, int signo) { … }
void NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid) { … }
void NativeProcessLinux::SignalIfAllThreadsStopped() { … }
void NativeProcessLinux::ThreadWasCreated(NativeThreadLinux &thread) { … }
Status NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
void *data, size_t data_size,
long *result) { … }
llvm::Expected<TraceSupportedResponse> NativeProcessLinux::TraceSupported() { … }
Error NativeProcessLinux::TraceStart(StringRef json_request, StringRef type) { … }
Error NativeProcessLinux::TraceStop(const TraceStopRequest &request) { … }
Expected<json::Value> NativeProcessLinux::TraceGetState(StringRef type) { … }
Expected<std::vector<uint8_t>> NativeProcessLinux::TraceGetBinaryData(
const TraceGetBinaryDataRequest &request) { … }