When running M-x pdb
from Emacs, the current directory seems to be set to that of the directory of the script you are running, so
pdb ~/path/to/project/__main__.py
Would set the working directory to ~/path/to/project/
. However, what if I need the working directory to be a different directory - say, one directory back? Is there a way to set the directory that pdb/gud uses as the "working directory"? At the first pdb
prompt I can change the directory with os.chdir()
, which works, but I would like to not have to do this every time. Thank you!
Update:
I have found that one potential solution would be to set gud-chdir-before-run
(mentioned by @Nsukami_ below) to nil
and then change to the desired directory with (cd "/path/to/directory")
before running pdb
. I tried doing this with the gud-mode-hook
but the directory is changed too late. I have also, tried to do this with by advising pdb
and gud-mode-hook
, but don't yet have the lisp skills for this apparently...Is there a good way to call cd
before gud-mode-hook
/ before the dubugger starts?
gud-chdir-before-run
not sure if what you're looking for. – Nsukami _ Nov 21 '15 at 4:26gud-chdir-before-run
sounds like exactly what I need. I won't be able to try it until I get to work next week though. It is hard for me to explain better, because I don't quite understand yet what was causing the problem. What I know is, exceptions were being thrown only during debugging, and the way to fix it was to change the working directory to the parent directory of the__main__.py
script. All the necessary paths were included in my PYTHONPATH though, as far as I could tell, and everything seemed to be properly imported - that was a problem you already helped me fix the other day ; ) – elethan Nov 21 '15 at 4:40M-x gdb
within Emacs, I traced thedefault-directory
tocomint-exec-1
and then I worked backwards to set mydefault-directory
from withingud-common-init
. My goal was to set the working directory so that my preferred.gdbinit
was taken into consideration when firing up thegdb
executable. I had to modifygud-common-init
to prompt me for my preferred working directory and set it accordingly -- of course, we know that it must also have a forward trailing slash for certain platforms ... However, I have no idea about python or pdb. – lawlist Dec 5 '17 at 5:12