Skip to content

Commit d5317b4

Browse files
committed
[Process/NetBSD] Copy changes from FreeBSDRemote and reformat
Copy changes, including: - NativeProcessNetBSD::GetLoadedModuleFileSpec() and NativeProcessNetBSD::GetFileLoadAddress() methods - split x86 register sets by CPU extensions - use offset/size-based register reading/writing Differential Revision: https://reviews.llvm.org/D93541
1 parent 54a1c86 commit d5317b4

File tree

7 files changed

+339
-774
lines changed

7 files changed

+339
-774
lines changed

lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
213213

214214
LLDB_LOG(log, "got SIGTRAP, pid = {0}, lwpid = {1}, si_code = {2}", pid,
215215
info.psi_lwpid, info.psi_siginfo.si_code);
216-
NativeThreadNetBSD* thread = nullptr;
216+
NativeThreadNetBSD *thread = nullptr;
217217

218218
if (info.psi_lwpid > 0) {
219219
for (const auto &t : m_threads) {
@@ -224,8 +224,7 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
224224
static_cast<NativeThreadNetBSD *>(t.get())->SetStoppedWithNoReason();
225225
}
226226
if (!thread)
227-
LLDB_LOG(log,
228-
"thread not found in m_threads, pid = {0}, LWP = {1}", pid,
227+
LLDB_LOG(log, "thread not found in m_threads, pid = {0}, LWP = {1}", pid,
229228
info.psi_lwpid);
230229
}
231230

@@ -266,30 +265,27 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
266265
}
267266

268267
switch (pst.pe_report_event) {
269-
case PTRACE_LWP_CREATE: {
270-
LLDB_LOG(log,
271-
"monitoring new thread, pid = {0}, LWP = {1}", pid,
272-
pst.pe_lwp);
273-
NativeThreadNetBSD& t = AddThread(pst.pe_lwp);
274-
error = t.CopyWatchpointsFrom(
275-
static_cast<NativeThreadNetBSD &>(*GetCurrentThread()));
276-
if (error.Fail()) {
277-
LLDB_LOG(log,
278-
"failed to copy watchpoints to new thread {0}: {1}",
279-
pst.pe_lwp, error);
280-
SetState(StateType::eStateInvalid);
281-
return;
282-
}
283-
} break;
284-
case PTRACE_LWP_EXIT:
285-
LLDB_LOG(log,
286-
"removing exited thread, pid = {0}, LWP = {1}", pid,
287-
pst.pe_lwp);
288-
RemoveThread(pst.pe_lwp);
289-
break;
268+
case PTRACE_LWP_CREATE: {
269+
LLDB_LOG(log, "monitoring new thread, pid = {0}, LWP = {1}", pid,
270+
pst.pe_lwp);
271+
NativeThreadNetBSD &t = AddThread(pst.pe_lwp);
272+
error = t.CopyWatchpointsFrom(
273+
static_cast<NativeThreadNetBSD &>(*GetCurrentThread()));
274+
if (error.Fail()) {
275+
LLDB_LOG(log, "failed to copy watchpoints to new thread {0}: {1}",
276+
pst.pe_lwp, error);
277+
SetState(StateType::eStateInvalid);
278+
return;
279+
}
280+
} break;
281+
case PTRACE_LWP_EXIT:
282+
LLDB_LOG(log, "removing exited thread, pid = {0}, LWP = {1}", pid,
283+
pst.pe_lwp);
284+
RemoveThread(pst.pe_lwp);
285+
break;
290286
}
291287

292-
error = PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast<void*>(1), 0);
288+
error = PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast<void *>(1), 0);
293289
if (error.Fail())
294290
SetState(StateType::eStateInvalid);
295291
return;
@@ -301,12 +297,13 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
301297
auto &regctx = static_cast<NativeRegisterContextNetBSD &>(
302298
thread->GetRegisterContext());
303299
uint32_t wp_index = LLDB_INVALID_INDEX32;
304-
Status error = regctx.GetWatchpointHitIndex(wp_index,
305-
(uintptr_t)info.psi_siginfo.si_addr);
300+
Status error = regctx.GetWatchpointHitIndex(
301+
wp_index, (uintptr_t)info.psi_siginfo.si_addr);
306302
if (error.Fail())
307303
LLDB_LOG(log,
308304
"received error while checking for watchpoint hits, pid = "
309-
"{0}, LWP = {1}, error = {2}", pid, info.psi_lwpid, error);
305+
"{0}, LWP = {1}, error = {2}",
306+
pid, info.psi_lwpid, error);
310307
if (wp_index != LLDB_INVALID_INDEX32) {
311308
thread->SetStoppedByWatchpoint(wp_index);
312309
regctx.ClearWatchpointHit(wp_index);
@@ -494,16 +491,14 @@ Status NativeProcessNetBSD::Resume(const ResumeActionList &resume_actions) {
494491
signal = siginfo->psi_siginfo.si_signo;
495492
}
496493

497-
ret = PtraceWrapper(PT_CONTINUE, GetID(), reinterpret_cast<void *>(1),
498-
signal);
494+
ret =
495+
PtraceWrapper(PT_CONTINUE, GetID(), reinterpret_cast<void *>(1), signal);
499496
if (ret.Success())
500497
SetState(eStateRunning, true);
501498
return ret;
502499
}
503500

504-
Status NativeProcessNetBSD::Halt() {
505-
return PtraceWrapper(PT_STOP, GetID());
506-
}
501+
Status NativeProcessNetBSD::Halt() { return PtraceWrapper(PT_STOP, GetID()); }
507502

508503
Status NativeProcessNetBSD::Detach() {
509504
Status error;
@@ -667,8 +662,8 @@ Status NativeProcessNetBSD::PopulateMemoryRegionCache() {
667662
if (vm[i].kve_path[0])
668663
info.SetName(vm[i].kve_path);
669664

670-
m_mem_region_cache.emplace_back(
671-
info, FileSpec(info.GetName().GetCString()));
665+
m_mem_region_cache.emplace_back(info,
666+
FileSpec(info.GetName().GetCString()));
672667
}
673668
free(vm);
674669

@@ -706,21 +701,47 @@ Status NativeProcessNetBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size,
706701

707702
Status NativeProcessNetBSD::GetLoadedModuleFileSpec(const char *module_path,
708703
FileSpec &file_spec) {
709-
return Status("Unimplemented");
704+
Status error = PopulateMemoryRegionCache();
705+
if (error.Fail())
706+
return error;
707+
708+
FileSpec module_file_spec(module_path);
709+
FileSystem::Instance().Resolve(module_file_spec);
710+
711+
file_spec.Clear();
712+
for (const auto &it : m_mem_region_cache) {
713+
if (it.second.GetFilename() == module_file_spec.GetFilename()) {
714+
file_spec = it.second;
715+
return Status();
716+
}
717+
}
718+
return Status("Module file (%s) not found in process' memory map!",
719+
module_file_spec.GetFilename().AsCString());
710720
}
711721

712722
Status NativeProcessNetBSD::GetFileLoadAddress(const llvm::StringRef &file_name,
713723
lldb::addr_t &load_addr) {
714724
load_addr = LLDB_INVALID_ADDRESS;
715-
return Status();
725+
Status error = PopulateMemoryRegionCache();
726+
if (error.Fail())
727+
return error;
728+
729+
FileSpec file(file_name);
730+
for (const auto &it : m_mem_region_cache) {
731+
if (it.second == file) {
732+
load_addr = it.first.GetRange().GetRangeBase();
733+
return Status();
734+
}
735+
}
736+
return Status("No load address found for file %s.", file_name.str().c_str());
716737
}
717738

718739
void NativeProcessNetBSD::SigchldHandler() {
719740
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
720741
// Process all pending waitpid notifications.
721742
int status;
722-
::pid_t wait_pid =
723-
llvm::sys::RetryAfterSignal(-1, waitpid, GetID(), &status, WALLSIG | WNOHANG);
743+
::pid_t wait_pid = llvm::sys::RetryAfterSignal(-1, waitpid, GetID(), &status,
744+
WALLSIG | WNOHANG);
724745

725746
if (wait_pid == 0)
726747
return; // We are done.
@@ -802,8 +823,8 @@ Status NativeProcessNetBSD::Attach() {
802823
int wstatus;
803824
// Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
804825
// point we should have a thread stopped if waitpid succeeds.
805-
if ((wstatus = llvm::sys::RetryAfterSignal(-1, waitpid,
806-
m_pid, nullptr, WALLSIG)) < 0)
826+
if ((wstatus = llvm::sys::RetryAfterSignal(-1, waitpid, m_pid, nullptr,
827+
WALLSIG)) < 0)
807828
return Status(errno, eErrorTypePOSIX);
808829

809830
// Initialize threads and tracing status
@@ -911,7 +932,8 @@ NativeProcessNetBSD::GetAuxvData() const {
911932
Status NativeProcessNetBSD::SetupTrace() {
912933
// Enable event reporting
913934
ptrace_event_t events;
914-
Status status = PtraceWrapper(PT_GET_EVENT_MASK, GetID(), &events, sizeof(events));
935+
Status status =
936+
PtraceWrapper(PT_GET_EVENT_MASK, GetID(), &events, sizeof(events));
915937
if (status.Fail())
916938
return status;
917939
// TODO: PTRACE_FORK | PTRACE_VFORK | PTRACE_POSIX_SPAWN?

lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ class NativeProcessNetBSD : public NativeProcessELF {
6969
Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
7070
bool hardware) override;
7171

72+
// The two following methods are probably not necessary and probably
73+
// will never be called. Nevertheless, we implement them right now
74+
// to reduce the differences between different platforms and reduce
75+
// the risk of the lack of implementation actually breaking something,
76+
// at least for the time being.
7277
Status GetLoadedModuleFileSpec(const char *module_path,
7378
FileSpec &file_spec) override;
74-
7579
Status GetFileLoadAddress(const llvm::StringRef &file_name,
7680
lldb::addr_t &load_addr) override;
7781

0 commit comments

Comments
 (0)