1

Before I debug or execute a program on my system at work, I have to source a file that contains numerous paths and settings that are specific to each project. Is there a way I can do this from gdb? I tried putting it into a .gdbinit file in the working directory, but that doesn't seem to be working. I tried to see if the environmental variable was set by typing

(gdb) shell echo $MY_VAR

and it was blank. Any ideas?

2 Answers 2

2

Basically to set the environment variable in the command prompt, you can use the set environment varname [=value]. More information is present here. Since you have noted down there are huge number of paths to be set, you can add them to a file like myGdbSrc and then load them explicitly using source [-s] [-v] filename. You can find details on loading a file here.

I have tried both of them and it works.
HTH.


PS: I have tried it on GNU GDB 6.6 version on SUSE Linux. However, it must work across all version since it seems to be basic command.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to execute a bash file, or am I limited to python?
0

How about writing a wrapper script which sources your settings before loading gdb?

E.g. some trivial example:

#!/bin/sh

source my-script-which-sets-up-the-environment
gdb $*

This can of course also add arguments to the gdb invocation to setup paths, load a gdb script, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.