System Administration
Showing results for 
Search instead for 
Did you mean: 

attach process to gdb through script

Regular Advisor

attach process to gdb through script

Hello All,

I have a requirement to attach a process to gdb with help of its name in gdb prompt.

I made a script test whose content is :-

Test_script :-:>
VAR=`pgrep '

and requirement is to attach the process-id in VAR variable to gdb

attach VAR

The script has to be automated and has to collect many gdb related logs about the process stack and registers periodically with different process name.
Goran Koruga
Honored Contributor

Re: attach process to gdb through script


You can do this like so:

gdb -p "$VAR"

Put commands in ".gdbinit" or in a different file that you pass to gdb with "-x". I recommend to put this in ".gdbinit":

set paginatin off

Then put the rest in another file and call:

gdb -batch -x "myfile" -p "$VAR" > myoutput

You can also set where gdb logs its output inside gdb if you wish.