2

I'm writing a python script to go through my list of currently executing processes, look for the ones run by a certain user, and then run GDB to hook onto all of those.

I currently get a list of all the processes run by a certain user. (I used http://andreinc.net/2010/11/07/how-to-get-the-active-process-list-on-a-linux-machine-using-python/ for that)

However, I for the life of me can't square that with how to launch gdb and hook onto each of those with a separate inferior from Python. I know how to launch gdb with a Python script, just not with the appropriate sequencing to attach multiple processes inside that gdb and create an inferior for each one.

I know that once you're running gdb, you can create new inferiors with create-inferior, then switch to them and attach a process. Is there a way to add an inferior and immediately have it attach to a process?

Better yet, is there a way to launch gdb with multiple inferiors, each one attaching to a different process in the argument list?

Thanks!

1 Answer 1

1

you can create new inferiors with create-inferior

You probably mean add-inferior. This works, but isn't very elegant:

$ sleep 1800 & sleep 1800 & sleep 1900 &
[1] 80375
[2] 80376
[3] 80377

$ gdb -q -ex 'attach 80375' \
  -ex 'add-inferior' -ex 'inferior 2' -ex 'attach 80376' \
  -ex 'add-inferior' -ex 'inferior 3' -ex 'attach 80377'
...
(gdb) info inferiors
  Num  Description       Executable
* 3    process 80377     /bin/sleep
  2    process 80376     /bin/sleep
  1    process 80375     /bin/sleep
(gdb) q
Detaching from program: /bin/sleep, process 80377
Detaching from program: /bin/sleep, process 80376
Detaching from program: /bin/sleep, process 80375

Consider filing a feature request in GDB bugzilla: if add-inferior accepted a pid (in addition to or instead of executable filename), your task would be simpler.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, yeah I did mean add-inferior...and thanks for the help! That feature request is a good idea, I may well ask for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.