Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up gdb's environment when running it through emacs

Tags:

emacs

gdb

gud

I have a program that I'd like to debug with gdb via emacs. In order to run development versions of this program, I have a shell script that I can source that sets up the calling environment to see the right libraries, etc. What I can't sort out is how to ask emacs/gud to source this file before executing gdb.

I've tried using a command like "source env.sourceme && gdb my_program", but emacs complains that it doesn't know what "source" means. I guess it's not really running gdb in a shell, so these kinds of tricks won't work.

So, how can I convince gud/emacs/whatever to run gdb in my custom environment? I've got a hacky solution in place, but I feel like I must be missing something.

like image 759
abingham Avatar asked Mar 12 '12 13:03

abingham


People also ask

How to set breakpoint in Emacs?

You can also break on function entry by typing "b functionName." Typing "d 1" deletes breakpoint 1. Typing "disable 1" disables breakpoint 1. You can enable this breakpoint again by typing "enable 1".

How do I open GDB in Emacs?

To use this interface, use the command M-x gdb in Emacs. Give the executable file you want to debug as an argument. This command starts GDB as a subprocess of Emacs, with input and output through a newly created Emacs buffer.

What is Emacs gud?

The Grand Unified Debugger, or GUD for short, is an Emacs major mode for debugging. It works on top of command line debuggers. GUD handles interaction with gdb, dbx, xdb, sdb, perldb, jdb, and pdb, by default.


2 Answers

gdb has its own syntax for setting environment variables:

set environment varname [=value]

Instead of a shell script, write your variable definitions in a file using the above syntax, then source the file from a running gdb session. Note that this is not bash's built-in source command, but gdb's own, so naturally bash-style environment variable definitions will not work.

like image 103
Thomas Avatar answered Oct 12 '22 11:10

Thomas


What's your hacky solution?

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

#!/usr/bin/env bash

source env.sourceme
gdb -i=mi $1
like image 23
event_jr Avatar answered Oct 12 '22 11:10

event_jr