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.
Related
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.
I have these four lines written in a file called abc.m
function [x, y] = abc(q, r)
x=q;
y=r;
end
When I press CTRL+enter, I first get a popup that says
The selected section cannot be evaluated because it contains an invalid statement
Then in the command prompt it says:
function [x,y]=abc(q,r)
↑
Error: Function definitions are not permitted in this context.
I have read the other questions on this error, and I do not understand why this simple file wont work.
When you press, ctrl+enter, this is the equivalent of Run Selection which will execute a code block surrounded by %%'s. The code in this code block is run as a script which essentially copies and executes the lines of your code block one at a time in the command window. In all current versions of MATLAB, you cannot define a function within a script or directly within the command window, which is the cause for your error.
If you simply want to execute your function, you will want to use Run (or F5) to do so which will run the entire file, as a function.
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.
I wonder what the difference is between entering a few lines in the command window, or letting a script execute them.
In the question Escape from nested try - catch statement I have an example function. I have put the selected code in a script and called it, however then it does not work properly. On the other hand, when I
select the lines and hit f9, it works as expected.
The lines are:
dbclear all
dbquit
dbstop if caught error
I call the example function as such:
dbstop if caught error
mytestmain
And the example function is:
function mytestmain
try
mytestsub
catch
end
% Definition of subfunction, may or may not be in the same .m file
function mytestsub
try
a=b; %Intentionally generate an error as b is not defined
catch
end
I think it's related to MATLAB's just-in-time (JIT) compiler, which compiles functions before it runs them.
It seems that it compiles functions differently if dbstop is set or not (see here for reference). As it currently stands, MATLAB can not recompile a function while it is run (just try saving a changed function during a dbstop, and you will get a message informing you). As you can add and remove breakpoints during a dbstop I think you can also do so programmatically, but it should be impossible to "turn on" debugging if it wasn't turned on at "compile time"
So in your cases:
Using F9 it's just pasted and parsed as if you input it manually. So first dbstop is set, then mytestmain gets compiled and executed.
Running as a script will first compile the script and mytestmain and then execute it - so dbstop would be set after compilation and therefore not in effect.
Depending on what you mean by "doesn't work", it could just be because the debugger is a special context and certain debugger commands - dbup, dbdown, and dbquit - only work when you're at a debugger "K>>" prompt. Once you call a script, you're no longer at the debugger prompt but in normal code execution - inside a nested M-code call stack - and they just don't work there. When you F9, it does the lines individually, so each one is done from the prompt.
As a workaround, if you really want to execute a sequence of debugger commands like this, you could write a little Java Swing widget to enter the text in to the command window just as though you were typing it in.
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.