Reputation: 48893
Currently I press right mouse button to select "Copy file path to clipboard"
menu. Next left click to source line until where execute code, outside loop (this line number indicated in bottom right corner of WinDbg).
Next in command prompt I set breakpoint (by inserting from clipboard path to file and typing line number, which read from status bar):
bp `d:\home\devel\plugin\plugin-svn\common\win-gui-admin.c:788`
This seems too complicate. In GDB for leaving loops resurved command until
. Any way to do this in WinDbg?
Upvotes: 1
Views: 487
Reputation: 9007
again a very late answer but one can use source level syntax in windbg
.lines
to enable src line support
l+*
to enable all src options
lsf
to load src file
ls from,to
to inspect src lines from current src file
lsc
to show current src file
`module!srcfile:linenum`
to denaote any line from any src file (src syntax needs to be wrapped in grave accents not single quotes)
here is a sample walkthrough
jmpouttaloo:\>dir /b
jmpouttaloo.cpp
jmpouttaloo:\>type jmpouttaloo.cpp
#include <stdio.h>
int main (void)
{
int i=0,j=0,k=0,l=0;
while (i++ < 100)
{
while (j++ < 100)
{
while(k++ < 100)
{
l++;
}
l++;
}
l++;
}
printf("%d\n",l);
return 0;
}
jmpouttaloo:\>cl /Zi /nologo jmpouttaloo.cpp
jmpouttaloo.cpp
jmpouttaloo:\>dir /b *.exe
jmpouttaloo.exe
jmpouttaloo:\>jmpouttaloo.exe
300
.lines turns on src line support
in cdb (it is on by defaukt in windbg )
l+*
enables all src line options
lsf
load src file jmpouttaloo.cpp
set a bp on main and run
the exe
jmpouttaloo:\>cdb -c ".lines;l+*; lsf jmpouttaloo.cpp; bp jmpouttaloo!main;g" jmpouttaloo.exe
stepping with p steps one src line per step
in 6 steps we land inside the innermost while loop
now we want to get out of each loop systematically
ls start , count
shows the src lines from start number to startnumber+count
to run until we get to certain src line
do g graveaccent colon linenumber graveaccent
the complete src line syntax as follows
graveaccent modulename! filename : linenumber graveaccent
first run
0:000> cdb: Reading initial command '.lines;l+*; lsf jmpouttaloo.cpp; bp jmpouttaloo!main;g'
Breakpoint 0 hit
> 3: {
0:000> p
> 4: int i=0,j=0,k=0,l=0;
0:000>
> 5: while (i++ < 100)
0:000>
> 7: while (j++ < 100)
0:000>
> 9: while(k++ < 100)
0:000>
> 11: l++;
0:000>
> 12: }
0:000>
> 9: while(k++ < 100)
we are in loop line 12 back to line 9 we need to exit out of this loop at line 13
0:000> ls 13,6 view src lines from line number 13 to 18 (6 lines )
13: l++;
14: }
15: l++;
16: }
17: printf("%d\n",l);
18: return 0;
0:000> dv view locals we have stepped only once so all locals must be 1
j = 0n1
l = 0n1
k = 0n1
i = 0n1
0:000> g `:13` lets get out of innermost loop and look at the locals
> 13: l++;
0:000> dv
j = 0n1
l = 0n100 <-------
k = 0n101 <-------------
i = 0n1
0:000> g `:15` getting out of second innermost loop and inspect locals
> 15: l++;
0:000> dv
j = 0n101
l = 0n200
k = 0n200
i = 0n1
0:000> g `:17` getting out of all loops and inspect locals
> 17: printf("%d\n",l);
0:000> dv
j = 0n200
l = 0n300
k = 0n200
i = 0n101
0:000> p
300 <--------------- output of printf
> 18: return 0;
0:000>
second run
another jig this time we break on line 15 straight without even loading the src
jmpouttaloo:\>cdb -c ".lines;g `jmpouttaloo!jmpouttaloo.cpp:15`;dv;q" jmpouttaloo.exe | grep -A 4 "j ="
j = 0n101
l = 0n200
k = 0n200
i = 0n1
quit:
jmpouttaloo:\>
Upvotes: 1
Reputation: 5499
F7 gives you the "Run to Cursor" command, which I think does what you're looking for. Just put the cursor on whatever source line you want and then hit F7.
-scott
Upvotes: 3