views:

253

answers:

1

I have an application that is sensitive to the directory it gets invoked from — it loads some files using relative paths.

When I start the program through a debugger, how can I control what the initial current directory will be?

I'd prefer to avoid adding special code to the debugged program to make it call chdir; my instinct is that the debugger should provide some way to specify that externally, since it's inherently an external setting anyway.

The debugger I'm using is TotalView, but I'm open to answers for other Linux debuggers since it could help me find a comparable setting in TV. I can specify environment variables when I invoke the program, so on a lark, I tried setting PWD, but no luck.

+3  A: 

With GDB, the initial working directory is the directory you instantiate GDB from. So, just run GDB from whatever you want the working directory to be. Alternatively, while the program is running, you can change the current working directory just by doing:

(gdb) print chdir("new/working/directory")

GDB also had a built-in command for changing the process' working directory from the GDB prompt:

(gdb) cd new/working/directory

I've never used TotalView, but it should have a similar functionality for executing code (with side effects) from within the debugger.

Adam Rosenfield
Wow, that was easy. Changing the directory I start TotalView from worked. It also has an "Evaluate" command in the Tools menu for running immediate commands like chdir. Thanks for the nudge in the right direction!
Rob Kennedy