Brandon Amir
Brandon Amir

Reputation: 400

Debugging Multiprocess Program in C

I am trying to debug a deadlock/race condition in my multiprocess shared memory program. For some reason it is only deadlocking some of the time. I would like to know what each process is doing at this time so that I can find the bug. Any ideas on how I could use gdb or valgrind for this?

Upvotes: 1

Views: 1493

Answers (2)

Sridhar Iyer
Sridhar Iyer

Reputation: 2840

Here's what I'd do:

  1. Recreate the issue and find the processes that are deadlocked (via top/strace).
  2. Once you get the pid, then attach to it using gdb (if it is not directly obvious from the strace output).
  3. Valgrind might not help in this case as it changes the memory layout and the reduced speed can mask the race condition.

Upvotes: 0

user3159253
user3159253

Reputation: 17455

Not a complete answer, just a thought:

you may attach to a working process using gdb -p <processId> /path/to/executable/being/debugged. Or just use strace -p <pid>.

BTW Right now I'm doing this for LibreOffice with KDE4 dialogs plugin hanging on startup (somewhere in libSM interaction) :) A typical race condition, because it works perfectly being run under gdb from start

Upvotes: 2

Related Questions