0

I'm trying to debug a multithreaded function, and there are lots of threads that execute functions that take some time. The program works for a while and then hangs. I'd like to know what each thread is doing when this happens, to know which part of the code is hanging.

Is it possible with lldb?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • How do you define "hang"? Is the thread busy waiting in a syscall e.g. or heavy calculating without giving output? Are all threads "hanging" or only some of them? – RoQuOTriX Aug 07 '20 at 05:59
  • @RoQuOTriX I don't have any idea but it looks like only some of them are hanging, so I'd like to know in which function is each one – Guerlando OCs Aug 07 '20 at 06:08
  • Thats a tough question, are you running on linux? Thats sounds like a good case for using record-replay debugging, e.g. https://rr-project.org/ or https://undo.io/solutions/products/undodb-reverse-debugger/ – RoQuOTriX Aug 07 '20 at 06:11
  • @RoQuOTriX yes im on linux. Thank you very much I didn't know about those – Guerlando OCs Aug 07 '20 at 06:19
  • It seems like no developer knows about such tools (Thats no accusation, I didn't know them also for a long time). Thats a shame and should be basic of every programming tutorial after hello world: Introducing basic debuggers and then reverse debuggers – RoQuOTriX Aug 07 '20 at 06:21

1 Answers1

1

You can run thread backtrace all to list the stack for all threads. This command takes a -c/--count flag, which you can use to limit the output to the top frames. For example to see only the current function of each thread, run thread backtrace -c 1 all.

Dave Lee
  • 6,299
  • 1
  • 36
  • 36
  • 2
    This isn't directly debugger related, but if you are on macOS you can run `spindump prog-name` in Terminal. That dumps out a sample of the current state of the system, with extra info for your `prog-name`. It has the added benefit that if thread A is waiting on a lock held by thread B, it will indicate that in the output. That can sometimes come in really handy for figuring out deadlocks. – Jim Ingham Aug 07 '20 at 22:16