Reputation: 2513
I've used gdb for a lot of my work in university and at my current job, but I need to learn how to use CDB and WinDBG for development on Windows. I'd prefer to use CDB because there is a nice mode for it in Emacs.
How can I change the current directory after starting CDB? This is useful because the current directory defaults to the executable directory (cdb C:/dev/myexe.exe
would give a current dir=c:/dev, although I launched cdb from C:/testdir
), but I may have a testing directory on a different drive which I'd prefer to use as the working directory. Or I may have multiple testing directories and I'd like to switch between them easily without losing breakpoints for the process. Changing the working directory can be done in GDB using cd
. How can this be done in CDB?
Suppose I start debugging a new process using cdb my.exe arg1 arg2
and after a few minutes of setting breakpoints and code stepping, I realize I should specify an additional argument. In GDB, I can set the command line arguments whenever I run the process (r arg1 arg2 newarg3 ...
). My breakpoints and everything in the workspace stay the same. Is it possible to do this in CDB? It looks like I need to save the workspace, restart CDB with the new arguments for the debugging process, and then load the workspace to get the breakpoints, which is significantly more work than just issuing a run command.
I haven't found answers for these after searching on and off the past few weeks, and I'd really like to get away from Visual Studio debugging.
Edit: Clarified #1 and #2
Upvotes: 2
Views: 4589
Reputation: 3975
Well, it isn't as easy as in GDB but it is possible in CDB.
To change the working directory and maintain the breakpoints you have to .kill the process, tell it where to startup using .creatdir, and restart the process with .create.
For example:
0:000> bp CreateFileW
0:000> bl 0 e 750316af
0001 (0001) 0:**** kernel32!CreateFileW
0:000> .kill
Terminated. Exit thread and process events will occur.
0:000> .createdir d:\dev
Process creation dir: d:\dev
Process will inherit handles
0:000> .create c:\windows\system32\notepad.exe
CommandLine: c:\windows\system32\notepad.exe
Starting directory: d:\dev
Create will proceed with next execution
0:000> g
Symbol search path is: SRV*d:\symbols*http://msdl.microsoft.com/download/symbols
Executable search path is: ModLoad: 00880000 008b0000 notepad.exe eax=00000000
ebx=00000000 ecx=25c50000 edx=0009dc08 esi=fffffffe edi=00000000 eip=774d0fac
esp=000df398 ebp=000df3c4 iopl=0 nv up ei pl zr na pe nc cs=0023 ss=002b
ds=002b es=002b fs=0053 gs=002b efl=00000244
ntdll!LdrpDoDebuggerBreak+0x2d: 774d0fac 8975fc mov dword ptr [ebp-4],esi ss:002b:000df3c0=00000000
0:000> bl 0 e 750316af
0001 (0001) 0:**** kernel32!CreateFileW
0:000> g
To restart with different arguments you do the same .kill and then pass new arguments to the .create command.
If you are going to be doing this a lot then I would invest some time in writing a script that made this multi-step process easier.
Upvotes: 6