Setting up the gdb environment when it starts through emacs

I have a program that I would like to debug using gdb via emacs. To run versions for this program, I have a shell script, which can be a source that sets up the calling environment to view the correct libraries, etc. I can't figure out how to ask emacs / gud send this file before gdb is executed.

I tried using the command "source env.sourceme && gdb my_program", but emacs complains that it does not know what "source" means. I assume that this really does not work gdb in the shell, so these tricks will not work.

So how can I convince gud / emacs / whatever to run gdb in my custom environment? I have a hacker solution in place, but I feel like I'm missing something.

+7
source share
3 answers

What is your hacking solution?

Why don't you just have a wrapper script that tells env.sourceme and then run gdb?

 #!/usr/bin/env bash source env.sourceme gdb -i=mi $1 
+3
source

gdb has its own syntax for setting environment variables :

 set environment varname [=value] 

Instead of a shell script, write the variable definitions in the file using the syntax above, then the source file from the gdb session in progress. Note that this is not a bash built-in source command, but gdb own , so the natural definition of environment variables w1> w51 does not work.

+5
source

You can change the Emacs environment using setenv , either interactively ( Mx setenv ) or programmatically:

 (setenv "FOOBAR" "whatever") 

When you run gud-gdb , everything you installed with setenv will be passed to the gdb process.

+3
source

All Articles