Setting break point using source code line number in WinDBG - windbg

I am aware of setting breakpoint base on function name in WinDBG using bp, bm commands
is there a way to set break point break on source code line number
say
<some command> 20
means it should set breakpoint at line 20
Thanks in advance

bp `source.c:12`
Optionally, you can load the source file in WinDBG, set the cursor to the line you want to set a breakpoint to, and hit F9.
Also try .hh bp for more info

Here is the syntax for setting bp on line number
bp (##masm(`main.c:8+`))
For the above to work .lines should be enabled
HTH

Here's the syntax:
bu `module_name!file.cpp:206`

Related

Data breakpoint matlab Matlab

In Matlab, is it possible to set a data breakpoint on a specific variable as it is done in Visual Studio? I could not find anything online and in the manual, can really such a important feature be missing?
It does its called conditional breakpoints.
You can set them at the command line but its a lot easier to put them in interactively via the editor (right click on "-" next line number and select "Set Conditional Breakpoint"
Commandline:
dbstop in FUNCTION at LINENO if 'EXPRESSION'

Create a matlab debugger breakpoint and enter debugger in .m file code

How can I create a matlab debugger breakpoint on the current line of a .m matlab file, cause matlab to enter the debugger at that point? I.e., pause the current code execution and drop into the debugger?
This would help me because I edit matlab files in an external editor. Wen I save a file, matlab clears any breakpoints I have set in that file. I have tried:
dbstop at [current_file.m]
which does not work because it sets breakpoint at the first line in the file.
As an example, in python, this could be done by:
import IPython
IPython.embed()
You can use dbstop to stop at a specific line:
dbstop in FILESPEC at LINENO
help dbstop gives you all the options.
You can use keyboard to stop at a certain point in the code.
The only problem is that it requires editing the code each time you want to add\remove a breakpoint

how to trigger breakpoint by command in matlab

I have an if state in my code where if something went wrong and I want to debug if it hits there. similar to manually set breakpoint on that line but permanent.
so it will always have that red dot over there by command..
I've seen some dbstop commands but they are all ends with in file or if error..
I couldn't find a basic 'dbstop here' or something..
Is that possible?
Thanks.
Take a look at the keyboard command. It will not create the red dot, but it basically behaves like a breakpoint.
dbstop has more arguments than just in file or if error:
dbstop in file at location sets a breakpoint at the specified location. MATLAB execution pauses immediately before that location, unless the location is an anonymous function. If the location is an anonymous function, then execution pauses just after the breakpoint.

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.