how to change current working directory while using pdb within emacs
rocky at panix.com
Tue Nov 27 08:21:15 CET 2007
duyanning <duyanning at gmail.com> writes:
> I have written a pyhton script that will process data file in current
> working directory.
> My script is in an different directory to data file.
> When I debug this script using pdb within emacs, emacs will change the
> current working directory to the directory which include the script,
> so my script cannot find the data file.
> I think this is the problem of emacs because when I start pdb from
> console directly, it will not change current working directory to the
> one of script being debugged.
> please help me.
> thank you.
pydb (http://bashdb.sf.net/pydb) has an option to set the current
working directory on invocation. For example, from emacs I can run:
M-x pydb --cd=/tmp --annotate=3 ~/python/hanoi.py 3
And then when I type
import os; os.getcwd()
Inside pydb, there is a "cd" command saving you the trouble of
importing os; the "directory" command can be used to set a search path
for source files. All same as you would do in gdb.
Begin digression ---
The --annotate option listed above, is similar to gdb's annotation
mode. It is a very recent addition and is only in CVS. With annotation
mode turned on, the effect is similar to running gdb (gdb-ui.el) in
Emacs 22. Emacs internal buffers track the state of local variables,
breakpoints and the stack automatically as the code progresses. If the
variable pydb-many-windows is set to true, the each of these buffers
appear in a frame.
For those of you who don't start pydb initially bug enter via a call
such as set_trace() or debugger() and do this inside an Emacs comint
shell with pydb-tracking turned on, issue "set annotation 3" same as
you would if you were in gdb.
More information about the Python-list