Windbg: Printing the breakpoint number which triggered - windbg

When I run Windbg and it hits a breakpoint, then it prints the number of the breakpoint which triggered it. When I use a conditional breakpoint, I would want to print this as well. Is there some variable that holds the breakpoint number which triggered?
Because when I some ".printf" in the breakpoint condition, then only the stuff that I specify is printed (which is fine), but I would want to know which one it was as well.

When you define your breakpoints you can specify the ID value, you can then .echo this as a command string:
bp 42 myDLL!myClass::foo ".echo 'breakpoint 42 hit!!!';gc"
You will then know for sure which of your breakpoints was hit.
Alternatively you can list the current breakpoints using bl and this will list the breakpoints and display the ordinal number (actually the ID that is assigned if you didn't specify it when defining the breakpoint).
You can use this ordinal number and redefine you breakpoint and .echo the ordinal number the sam way as above.

Related

Eclipse - Debugging

I am very new to Selenium and Eclipse.
I have a question (actually 2 questions) about debugging.
When I am debugging in Eclipse (Version: 2021-06 (4.20.0)), so I do not get visibility of all variables I have defined in the method.
For example, (see the screen shot attached) I have added string variable testSigned and assigned a value to it. Actually the purpose is to verify the text value contained in web element table_AdditionalDocumentation.
I defined Toggle Line breakpoint at line 395.
I started to execute in debug mode, got to the line 395.
However, I do not see the value of testSigned in Variables tab.
I noticed it does show values only of the variable which would be returned by the method, correct me if I am wrong.
Please, tell me how to get those values I have defined visible.
2.Additionally, please, let me know which button to press if for example after line 395 I want not to go line by line (F6), but just to run the code to the end.
For the first question, I'm not certain, but it might be because you haven't initialized that variable with a value. Try setting it to an empty string on the declaration line.
For the second question, if you set a breakpoint on the line you want to get to, just Resume (F8), and it will stop at the next breakpoint it hits, hopefully the one at the end of your method. Alternatively, if you just want to stop at the line right after the method returns (which will show the return value), you can click "Step Out" (F7) for that.

How to make alias expand upon expression evaluation only?

Suppose I set a breakpoint, that sets another breakpoint that is supposed to trace code execution. It looks like:
bp module!function "as /x {/v:alName} expr;ba w1 ##c++(expr) \".if(${alName}) {actions}\""
How do I make ${alName} evaluate at "ba" breakpoint hit? BTW I tried to enclose "ba" into .block statement right inside "bp" breakpoint command list, but this doesn't work for me either. If I put "bp" command list into a separate file and set "bp" to "$$><scriptName" - works ok. But this sort of "bp" I have here is already specified in another script file.

How to inspect a variable in XCODE?

Is there any command using which we can inspect a object in command line while app is running in DEBUG mode. I do not want to put description message in the code.
Try these resources. one two
(gdb) p varName
Yes sure. If you are debuging, breakpoints are automatically set to on. Just set a breakpoint to the line in which the variable is. The program stops as soon it reaches the line with the breakpoint. Just hold the cursor over the variable and all important data is displayed. I do it also that way all the time. ;-)

Examine data in windbg when a break on address (ba) breakpoint is hit

I'd like to create a breakpoint such that it will create another one-time breakpoint that will 'dd' a certain memory address when that memory is written to.
So when the breakpoint is hit, I'd like to run a command like:
ba w4 #ESP+4 /1 ''dd [memory address of this breakpoint]''
Since this breakpoint is being created by another breakpoint (and could potentially be called several times), I can't specify the breakpoint number. Otherwise I could use a pseudo register like '$bp3' to get the memory address of breakpoint #3
Would anyone have any thoughts on how to create a breakpoint command that can 'dd' the memory address of the breakpoint?
Thank you!
you can elaborate to make use of other general purpose pseudo-registers: t0..t19
bp your-address "r$t1=your-other-address; ba w4 #$t1 /1 \"dd #$t1;gc\""
If you know there will never be more than one "child" ba breakpoint defined, you can actually use a #$bpN pseudo-register by setting the "controlling" breakpoint's command to:
ba1 w4 /1 #esp+4 "dd #$bp1"
That is, specify the breakpoint number that that this new breakpoint should be assigned, and the pseudo-register for that breakpoint is still defined within the breakpoint's command.
However, if you think the controlling breakpoint will be hit multiple times and want multiple ba breakpoints defined, that obviously won't work because then "breakpoint 1" will just be redefined each time. But you can still do it!
The trick is to make the controlling breakpoint's command actually contain the literal address text rather than try to go through a pseudo-register. And you can do that with text aliases.
Try this for your controlling breakpoint:
bu #WHATEVER "aS /x ${/v:baaddy} #esp+4; .block{ ba w4 /1 baaddy \"dd baaddy\"; ad ${/v:baaddy} }"
When the controlling breakpoint is hit, the following happens:
An alias is setup for the text "baaddy" with the value of evaluating the expression #esp+4.
The .block ensures that alias expansion happens for what follows.
The alias interpreter will then expand all occurrences of "baaddy" within the block, except for in the ad command (because of the /v switch).
So if the value of #esp+4 is 0x1234 the access breakpoint command literally becomes: ba w4 /1 0x1234 \"dd 0x1234\" with the actual address embedded in it.
Then the text alias is deleted.
It's important to delete the text alias at the end or the next time this controlling breakpoint is hit, the alias expansion will happen before the aS command, and "baaddy" will be expanded using the previous value. That also means it's important that this text
alias does not exist the first time you set the controlling breakpoint's command.

How can I insert a time string into a GDB log?

I recently discovered that you can set breakpoints in Xcode that will print to the console and auto-continue -- meaning you can insert log statements without having to write NSLog() calls and recompile (on-the-fly logging, woot).
Only problem is that it seems to be a little limited in what you can display when doing a log.
It shows some tokens you can insert, like %B to print out some info about the current breakpoint or %H for the hit count.
I'd like to know if there's any way I can insert a time stamp in a particular format into the log line?
I tried playing with the "shell script" breakpoint action, but it told me that the date command didn't exist.... strange...
Any help would be awesome,
Thanks guys!
Read the GDB manual about Breakpoint Command Lists
You can give any breakpoint (or watchpoint or catchpoint) a series of commands to execute when your program stops due to that breakpoint. For example, you might want to print the values of certain expressions, or enable other breakpoints.
And in particular:
for example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.
break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end
Does this answer your question?