Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLDB - How to attach to a process without stopping it

Tags:

macos

ios

lldb

I'm looking for a way to attach to a process using lldb without stopping it. The program I'm debugging has race conditions and I'm worried that the pause is inducing more entropy.

Similar question but for gdb: gdb attach to a process without stop.

Version used:

lldb -v
  lldb-900.3.72
like image 444
Mr_Pouet Avatar asked Feb 24 '18 01:02

Mr_Pouet


1 Answers

That is not really possible on x86_64 or ARMv8-A (I'm making an assumption here but it stands for most modern OS designs/architectures).

In general any time the process (forget about realtime stuff for now) makes a system call or is interrupted (which can happen in many ways, in a preemptive operating system) it will yield to the OS at which point there is an indeterminate period of time it may spend doing other things, depending on the system state and what the scheduler decides on (based on things like timing and priorities) before execution returns to that point.

You should just attach and resume execution straight away. There is no way to do what you actually want without introducing some form of jitter (even launching LLDB itself may happen on the same CPU the process you're after was last "running" on).

This is why race conditions are kind of a pain to debug, because they're a pain to reproduce consistently. There are ways to reduce jitter to a minimum when debugging but they involve fairly complicated, usually OS specific tools.

I would also suggest looking into ThreadSanitizer to help find potential race conditions.

like image 155
Kristina Brooks Avatar answered Sep 20 '22 15:09

Kristina Brooks