Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: J. on December 04, 2016, 01:15:20 am

Title: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: J. on December 04, 2016, 01:15:20 am
How to pass the dynamically determined PID to the debugger to attach to this PID? This is to avoid manual edits of the PID each time when gdb is asked to attach to the host process.

Living on Win10 with CB16.01.

Thanks,
J. 
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: oBFusCATed on December 04, 2016, 02:49:00 am
Debug -> Attach is the only possible way to attach to a process and you need to know the pid of the process to succeed.
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: J. on December 04, 2016, 11:47:27 am
Thanks - are you saying that it is not possible to pass the PID dynamically determined by some script to GDB? Even not by using
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: oBFusCATed on December 04, 2016, 12:30:40 pm
I don't think, so it is possible at the moment.
But if you describe your use case and it is something generally useful and easy to implement I can do something about it.
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: ollydbg on December 04, 2016, 12:39:10 pm
@J.
Please tell use what is the steps you want to get the automatic pid value?
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: J. on December 04, 2016, 01:18:48 pm
@Ollydbg:

On the GDB shell the pid can be determined by
Code
(gdb) shell ps -W | gawk "/APP\.EXE/{ print $1 }"
where the -W flag retrieves the windows processes as well.  Outside GDB, i.e. using cmd, the same works with 'tasklist' instead of 'ps -W'.

What could be an easy and quick solution is a canned sequence of commands loaded at gdb start (.gdbinit?). But up to now I could not manage to define the local gdb variable $PID using 'set $PID=...' and then passing that to 'attach'. Any ideas?


Ultimately I want to debug a .dll compiled by MinGW which is called by the host excel.exe.

Sorry for the pure formatting, I am travelling right now.
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: oBFusCATed on December 04, 2016, 05:15:08 pm
What could be an easy and quick solution is a canned sequence of commands loaded at gdb start (.gdbinit?). But up to now I could not manage to define the local gdb variable $PID using 'set $PID=...' and then passing that to 'attach'. Any ideas?

Adding stuff to .gdbinit won't help, because C::B is the one that starts gdb and it won't ever start it if you don't use the debug->start or debug->attach menu items.
Without gdb starting .gdbinit does nothing.
Title: Re: [GDB] How to pass a dynamically defined parameter to the debugger?
Post by: ollydbg on December 07, 2016, 01:00:57 am
Ultimately I want to debug a .dll compiled by MinGW which is called by the host excel.exe.
What is the method to get the pid of excel.exe? You want to get this pid in C::B, and then let C::B to call the gdb to attach the excel.exe?