3
votes

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.

1

1 Answers

5
votes

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.