Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a linux script before launching gdb debugging in Eclipse

How do I give commands to run before starting gdb debugging in Eclipse ?

Actually I want to execute few scripts that set environment variables (export vars) and execute a bunch of other programs before gdb process is launched from eclipse to debug my program.

I tried doing the following in debugger tab option:

<command> && <path-to-gdb-executable> 

But I got the error that eclipse cannot execute gdb as given in above statement. Please help - I actually want to execute a script called "before-launch-commands.sh" before debugging is started by gdb. I am trying to execute a cpp program under eclipse kepler.

Thanks.

like image 462
Dhwanit Avatar asked Aug 15 '26 11:08

Dhwanit


1 Answers

The Eclipse Debug Configurations can already setup environment variables for you. I'm going to assume that that isn't sufficient, or you'd have already done it.

The first thing to do is create a new script, wrapped-gdb.sh:

#!/bin/sh

# Export any variables we need.
# Note that '.' (dot) is like an "include" statement.
. /path/to/before-launch-commands.sh

# Run GDB using the parameters passed in
exec /path/to/gdb "$@"

Next, set that script executable:

chmod +x /path/to/wrapped-gdb.sh

Finally, go to the Debugger tab in the debug configuration dialog, and in the box marked "GDB Debugger" enter /path/to/wrapped-gdb.sh.

When you launch your debug session it should now Do The Right Thing.

like image 60
ams Avatar answered Aug 17 '26 23:08

ams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!