Operating System - Linux
1827948 Members
3395 Online
109973 Solutions
New Discussion

attach process to gdb through script

 
monu_1
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 '
gdb


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


.gdbinit
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.
1 REPLY 1
Goran Koruga
Honored Contributor

Re: attach process to gdb through script

Hello.

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.

Regards,
Goran