Battery of NetBSD support improvements
Summary: Include initial support for: - single step mode (PT_STEP) - single step trap handling (TRAP_TRACE) - exec() trap (TRAP_EXEC) - add placeholder interfaces for FPR - initial code for NetBSD core(5) files - minor tweaks While there improve style of altered elf-core/ files. This code raises the number of passing tests on NetBSD to around 50% (600+/1200+). The introduced code is subject to improve afterwards for additional features and bug fixes. Sponsored by <The NetBSD Foundation> Reviewers: labath, joerg, emaste, kettenis Reviewed By: labath Subscribers: srhines, #lldb Tags: #lldb Differential Revision: https://reviews.llvm.org/D31450 llvm-svn: 299109
This commit is contained in:
@@ -235,6 +235,24 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
|
||||
}
|
||||
SetState(StateType::eStateStopped, true);
|
||||
break;
|
||||
case TRAP_TRACE:
|
||||
for (const auto &thread_sp : m_threads) {
|
||||
static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByTrace();
|
||||
}
|
||||
SetState(StateType::eStateStopped, true);
|
||||
break;
|
||||
case TRAP_EXEC: {
|
||||
Error error = ReinitializeThreads();
|
||||
if (error.Fail()) {
|
||||
SetState(StateType::eStateInvalid);
|
||||
return;
|
||||
}
|
||||
|
||||
// Let our delegate know we have just exec'd.
|
||||
NotifyDidExec();
|
||||
|
||||
SetState(StateType::eStateStopped, true);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -389,11 +407,13 @@ Error NativeProcessNetBSD::Resume(const ResumeActionList &resume_actions) {
|
||||
return Error();
|
||||
}
|
||||
|
||||
Error error;
|
||||
|
||||
switch (action->state) {
|
||||
case eStateRunning: {
|
||||
// Run the thread, possibly feeding it the signal.
|
||||
Error error = NativeProcessNetBSD::PtraceWrapper(PT_CONTINUE, GetID(),
|
||||
(void *)1, action->signal);
|
||||
error = NativeProcessNetBSD::PtraceWrapper(PT_CONTINUE, GetID(), (void *)1,
|
||||
action->signal);
|
||||
if (!error.Success())
|
||||
return error;
|
||||
for (const auto &thread_sp : m_threads) {
|
||||
@@ -403,7 +423,15 @@ Error NativeProcessNetBSD::Resume(const ResumeActionList &resume_actions) {
|
||||
break;
|
||||
}
|
||||
case eStateStepping:
|
||||
return Error("Not implemented");
|
||||
// Run the thread, possibly feeding it the signal.
|
||||
error = NativeProcessNetBSD::PtraceWrapper(PT_STEP, GetID(), (void *)1,
|
||||
action->signal);
|
||||
if (!error.Success())
|
||||
return error;
|
||||
for (const auto &thread_sp : m_threads) {
|
||||
static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStepping();
|
||||
}
|
||||
SetState(eStateStepping, true);
|
||||
break;
|
||||
|
||||
case eStateSuspended:
|
||||
@@ -732,22 +760,11 @@ Error NativeProcessNetBSD::LaunchInferior(MainLoop &mainloop,
|
||||
|
||||
ResolveProcessArchitecture(m_pid, m_arch);
|
||||
|
||||
/* Initialize threads */
|
||||
struct ptrace_lwpinfo info = {};
|
||||
error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
|
||||
error = ReinitializeThreads();
|
||||
if (error.Fail()) {
|
||||
SetState(StateType::eStateInvalid);
|
||||
return error;
|
||||
}
|
||||
while (info.pl_lwpid != 0) {
|
||||
NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
|
||||
thread_sp->SetStoppedBySignal(SIGSTOP);
|
||||
error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
|
||||
if (error.Fail()) {
|
||||
SetState(StateType::eStateInvalid);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set process stopped */
|
||||
SetState(StateType::eStateStopped);
|
||||
@@ -850,9 +867,6 @@ NativeThreadNetBSDSP NativeProcessNetBSD::AddThread(lldb::tid_t thread_id) {
|
||||
::pid_t NativeProcessNetBSD::Attach(lldb::pid_t pid, Error &error) {
|
||||
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
||||
|
||||
// Use a map to keep track of the threads which we have attached/need to
|
||||
// attach.
|
||||
Host::TidMap tids_to_attach;
|
||||
if (pid <= 1) {
|
||||
error.SetErrorToGenericError();
|
||||
error.SetErrorString("Attaching to process 1 is not allowed.");
|
||||
@@ -874,21 +888,11 @@ NativeThreadNetBSDSP NativeProcessNetBSD::AddThread(lldb::tid_t thread_id) {
|
||||
m_pid = pid;
|
||||
|
||||
/* Initialize threads */
|
||||
struct ptrace_lwpinfo info = {};
|
||||
error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
|
||||
error = ReinitializeThreads();
|
||||
if (error.Fail()) {
|
||||
SetState(StateType::eStateInvalid);
|
||||
return -1;
|
||||
}
|
||||
while (info.pl_lwpid != 0) {
|
||||
NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
|
||||
thread_sp->SetStoppedBySignal(SIGSTOP);
|
||||
error = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
|
||||
if (error.Fail()) {
|
||||
SetState(StateType::eStateInvalid);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Let our process instance know the thread has stopped.
|
||||
SetState(StateType::eStateStopped);
|
||||
@@ -989,3 +993,26 @@ NativeProcessNetBSD::GetAuxvData() const {
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
Error NativeProcessNetBSD::ReinitializeThreads() {
|
||||
// Clear old threads
|
||||
m_threads.clear();
|
||||
|
||||
// Initialize new thread
|
||||
struct ptrace_lwpinfo info = {};
|
||||
Error error = PtraceWrapper(PT_LWPINFO, GetID(), &info, sizeof(info));
|
||||
if (error.Fail()) {
|
||||
return error;
|
||||
}
|
||||
// Reinitialize from scratch threads and register them in process
|
||||
while (info.pl_lwpid != 0) {
|
||||
NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
|
||||
thread_sp->SetStoppedByExec();
|
||||
error = PtraceWrapper(PT_LWPINFO, GetID(), &info, sizeof(info));
|
||||
if (error.Fail()) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user