@@ -213,7 +213,7 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
213
213
214
214
LLDB_LOG (log, " got SIGTRAP, pid = {0}, lwpid = {1}, si_code = {2}" , pid,
215
215
info.psi_lwpid , info.psi_siginfo .si_code );
216
- NativeThreadNetBSD* thread = nullptr ;
216
+ NativeThreadNetBSD * thread = nullptr ;
217
217
218
218
if (info.psi_lwpid > 0 ) {
219
219
for (const auto &t : m_threads) {
@@ -224,8 +224,7 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
224
224
static_cast <NativeThreadNetBSD *>(t.get ())->SetStoppedWithNoReason ();
225
225
}
226
226
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,
229
228
info.psi_lwpid );
230
229
}
231
230
@@ -266,30 +265,27 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
266
265
}
267
266
268
267
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 ;
290
286
}
291
287
292
- error = PtraceWrapper (PT_CONTINUE, pid, reinterpret_cast <void *>(1 ), 0 );
288
+ error = PtraceWrapper (PT_CONTINUE, pid, reinterpret_cast <void *>(1 ), 0 );
293
289
if (error.Fail ())
294
290
SetState (StateType::eStateInvalid);
295
291
return ;
@@ -301,12 +297,13 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
301
297
auto ®ctx = static_cast <NativeRegisterContextNetBSD &>(
302
298
thread->GetRegisterContext ());
303
299
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 );
306
302
if (error.Fail ())
307
303
LLDB_LOG (log,
308
304
" 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);
310
307
if (wp_index != LLDB_INVALID_INDEX32) {
311
308
thread->SetStoppedByWatchpoint (wp_index);
312
309
regctx.ClearWatchpointHit (wp_index);
@@ -494,16 +491,14 @@ Status NativeProcessNetBSD::Resume(const ResumeActionList &resume_actions) {
494
491
signal = siginfo->psi_siginfo .si_signo ;
495
492
}
496
493
497
- ret = PtraceWrapper (PT_CONTINUE, GetID (), reinterpret_cast < void *>( 1 ),
498
- signal);
494
+ ret =
495
+ PtraceWrapper (PT_CONTINUE, GetID (), reinterpret_cast < void *>( 1 ), signal);
499
496
if (ret.Success ())
500
497
SetState (eStateRunning, true );
501
498
return ret;
502
499
}
503
500
504
- Status NativeProcessNetBSD::Halt () {
505
- return PtraceWrapper (PT_STOP, GetID ());
506
- }
501
+ Status NativeProcessNetBSD::Halt () { return PtraceWrapper (PT_STOP, GetID ()); }
507
502
508
503
Status NativeProcessNetBSD::Detach () {
509
504
Status error;
@@ -667,8 +662,8 @@ Status NativeProcessNetBSD::PopulateMemoryRegionCache() {
667
662
if (vm[i].kve_path [0 ])
668
663
info.SetName (vm[i].kve_path );
669
664
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 ()));
672
667
}
673
668
free (vm);
674
669
@@ -706,21 +701,47 @@ Status NativeProcessNetBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size,
706
701
707
702
Status NativeProcessNetBSD::GetLoadedModuleFileSpec (const char *module_path,
708
703
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 ());
710
720
}
711
721
712
722
Status NativeProcessNetBSD::GetFileLoadAddress (const llvm::StringRef &file_name,
713
723
lldb::addr_t &load_addr) {
714
724
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 ());
716
737
}
717
738
718
739
void NativeProcessNetBSD::SigchldHandler () {
719
740
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
720
741
// Process all pending waitpid notifications.
721
742
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);
724
745
725
746
if (wait_pid == 0 )
726
747
return ; // We are done.
@@ -802,8 +823,8 @@ Status NativeProcessNetBSD::Attach() {
802
823
int wstatus;
803
824
// Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
804
825
// 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 )
807
828
return Status (errno, eErrorTypePOSIX);
808
829
809
830
// Initialize threads and tracing status
@@ -911,7 +932,8 @@ NativeProcessNetBSD::GetAuxvData() const {
911
932
Status NativeProcessNetBSD::SetupTrace () {
912
933
// Enable event reporting
913
934
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));
915
937
if (status.Fail ())
916
938
return status;
917
939
// TODO: PTRACE_FORK | PTRACE_VFORK | PTRACE_POSIX_SPAWN?
0 commit comments