When I'm using

M-x gdb 

when lots of source files are open in emacs, the default directory in emacs is often different with the directory of my working copy to run that file i want to run. It's always painful to type the correct full path of the file which i want to debug. How could I solve this problem? Is there a way to change the current default directory to the working copy of my project?

link|improve this question

65% accept rate
feedback

2 Answers

The current working directory is always the location of the current buffer.

One option is to go into shell-mode and then cd to the preferred directory, then anything you open, or run from within that shell-buffer will default to that directory.

link|improve this answer
it seems the directory changes randomly when i use the gdb in emacs, and i cannot get the correct directory. – Kim Feb 24 '11 at 9:37
It changes within the buffer? like you load a file, it's in directory X, you do some debugging, you load a file, and it's in some other directory Y? Does the program do any CDing itself? – Brian Postow Feb 24 '11 at 14:33
feedback

If you're in a buffer not attached to a file (like *scratch*, gnus' buffer...) you can use M-x cd to change the current directory. Just opening the directory will also do the trick.

In gdb, you can ajso just type cd /where/i/want/to/go

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.