In VS2019, automatically change variable value while debugging? - visual-studio

I have an If statement that looks like this:
if (condition1 == "True" && condition2 == "True" && condition3 == "True" && condition4 == "True")
Instead of having to change every value during debugging, is it possible to automatically change the value of condition1 to condition4 to "True" when the breakpoint's hit?
I just want the debugger to enter the If statement even though the conditions aren't met. It's a pain in the butt to edit every value once the If statement's hit.

The simplest solution would most probably be to Change the execution flow while debugging.
With the debugger paused on a line of code, use the mouse to grab the yellow arrow pointer on the left. Move the yellow arrow pointer to a different point in the code execution path. Then you use F5 or a step command to continue running the app.
By changing the execution flow, you can do things like test different code execution paths or rerun code without restarting the debugger.
This enables you to set a breakpoint on the if-statement, and drag execution into the if whenever necessary. This way you don't even have to change variables, but you can simply decide to execute the statement(s) inside the if-statement whenever you want to test them.
Alternatively, look at how you can Observe a single variable or expression with QuickWatch and change the value for the variable(s) there.

Related

if controller not working when I use ${status} == true

I am having a hard time having jemeter working with my if condition
As you see the above I am checking is status variable which I created in earlier car is true and it is true so I expect this if gets executed but it does not. However as soon as I change it to
It works fine.
I need these kind of check for sure(for a case like ${status} == false)
Am I missing anything?
** Update **
when I disable interpret regx I can see it works
This is expected behaviour.
In If Controller When you uncheck "Interpret condition as Variable Expression", Javascript is used to evaluate :
${status} == true
So it works, but it hurts badly performances.
So instead and as per reference documentation:
Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false
So keep "Interpret condition as Variable Expression" checked and use __jexl3 function:
${__jexl3(${status} == true,)}
This give you:

How can I use a variable inside one or multiple hotkeys?

(Very new to AHK, so sorry if this sounds very stupid/trivial)
I have a small AHK script (see below) with a variable called var. I would like to call and modify this variable from within multiple hotkeys. However, even when trying to "yield" its value (with the F8 hotkey) the value doesn't get printed. How can I go about with this?
#SingleInstance, force
+Escape::ExitApp
!r::Reload
!p::Suspend
var := 42
F8::
MsgBox % "Var value is " . var . "."
Return
;F12::
;blabla not relevant yet
Your variable declaration is unreachable code.
The code execution stops when the first hotkey label is encountered. This is called the Auto-execute Section.
Move your hotkey definition to be at the very bottom.
(All hotkeys defined by hotkey labels always get created regardless of being in the auto-execute section or not)
And as a bonus, the concatenation operator . is redundant, you don't need to use it, you can just leave it out.
(Unless you prefer to use it, of course)

How to trigger a break when an Array is empty?

In my app, I have a problème when I try to reach an index in an Array, the Array is actually empty. I cannot find what is emptying it so I was wondering if it's possible with the debugger to create a dynamic breakpoint that will pop up when my array is empty. So as soon as something is either resetting the array or taking away its last object, I'd like to know.
I tried to create a symbolic breakpoint with "myArray.isEmpty == true" as the condition but it doesn't look to work the way I want.
Is it possible or I'm just dreaming?
Thanks
As #kendall mentions, you could use didSet to detect when the array is being emptied, and put a breakpoint on it:
// a acts like a normal variable
var a: [Int] = [] {
// but whenever it’s updated, the following runs:
didSet {
if a.isEmpty {
// put a breakpoint on the next line:
println("Array is empty")
}
}
}
a.append(1)
a.append(2)
println(a.removeLast())
// will print “Array is empty” before the value is printed:
println(a.removeLast())
What you want is called a Watchpoint, which lets you monitor changes in memory. I'm not sure yet how to set one on a Swift Array, but that could be a good starting point for research.
One idea would be to add a didSet{} block to the property that holds the array, adding a log statement within - break on that based on your condition that the array is empty.
To the best of my knowledge this isn't possible with Swift and Xcode (or with any other language of IDE I have used). To make this work the IDE would have to continually evaluate the given expression at every step of programs execution.
Now, if arrays were classes, you could subclass and add a breakpoint in an override isEmpty method, but as they are classed you cannot. :-(

Lua Debugging - Detect when the value of a variable changes

Is it possible to detect when the value of a variable has changed using the lua debug library.
Something like A callback function which would give details like the function in which the value was changed, previous value, etc.
Is such a thing possible?
I read about hooks, but I'm not sure hooks can be set to variables.
If you don't mind using a debugger, then some debuggers allow you to set Watch expressions, which will be triggered when the condition in the expression is true. I'll show how this can be done in MobDebug (it is using lua debug library, but there is no direct way to detect a variable change as far as I know).
Let say we have a script start.lua like the one below and want to detect where foo gets value 2:
print("Start")
local foo = 0
for i = 1, 3 do
local function bar()
print("In bar")
end
foo = i
print("Loop")
bar()
end
print("End")
Download mobdebug.lua and make it available to your scripts (the simplest way is to put it into the folder with your scripts).
Start the server using lua -e "require('mobdebug').listen()" command.
Start the client using lua -e "require('mobdebug').loop()" command.
You will see the prompt in the server window: '>'. Type load start.lua to load the script.
Type step and then step again. You will see "Paused at file start.lua line 3".
Let's see what the value of foo is. Type eval foo and you should see 0.
Now we can set up our watch. Type setw foo == 2. You can specify any Lua expression after setw command; the execution of your script will be stopped when the condition is evaluated as true.
Continue execution of the script using "run" command.
The watch now fires, which will show you the message like: "Paused at file start.lua line 8 (watch expression 1: [foo == 2])". This means that the previous expression changed the value of foo to 2 and the execution is stopped at line 8. You can then inspect your script and the current values (you can use "eval" and "exec" commands to run any Lua code to be evaluated in your script environment) to find what triggered the change.
The benefit of this approach is that you are not limited to monitoring table values and can specify any expression. The main disadvantage is that your script runs under a debugger and the expression is evaluated after each step, which may get really slow.
You can do this to a certain extent in Lua by using metatables and keeping a "proxy" table, and using the __newindex function call to detect attempts to add a variable.
This is covered here in the Programming in Lua book under the section "Tracking Table Accesses":
http://www.lua.org/pil/13.4.4.html
See Also
http://www.gammon.com.au/forum/?id=10887

Setting a watch point in GDB

I am operating a huge code base and want to monitor a value of a particular variable (which is buried deep down inside one of the files)especially when it gets set to zero.
1) Variable does not belong to global scope .Is there a better option than to first set breakpoint into the function where it is defined and then set the watch point?
2) After trying the option in 1 I see that watch point gets deleted after a while saying its out of frame which used this .This way it adds to the tediousness of the procedure since I have to add it again and again?Any workarounds?
3) Is there a way to check ie watch if a particular variable is equal to 0( or any specific constant)?
want to monitor a value of a particular variable
Often this is not the best approach, especially in large codebases.
What you really likely want to do is understand the invariants, and assert that they are true on entry and exit to various parts of the code.
1) Variable does not belong to global scope .Is there a better option than to first set breakpoint into the function where it is defined and then set the watch point?
No. For automatic (stack) variables you have to be in the scope where the variable is "active".
What you can do is set a breakpoint on some line, and attach commands to that breakpoint that will set the watchpoint automatically, e.g.
(gdb) break foo.c:123
(gdb) commands 1
silent
watch some_local
continue
end
3) Is there a way to check ie watch if a particular variable is equal to 0
You can't do that with a watchpoint, but you can with a conditional breakpoint:
(gdb) break foo.c:234 if some_local == 0
I will assume that you are using Linux. You can try this:
The first step is to make the variable static, like:
static int myVar;
Then, after compiling your code using -ggdb, you must discover the address of the variable inside your binary, like so (I have used a real case as example):
readelf -s pdv | grep tmp | c++filt
In my situation, the output is:
47: 081c1474 4 OBJECT LOCAL DEFAULT 25 startProc(int)::tmp
The address in this case is 081c1474. Now you can set a watch point inside GDB:
watch *0x081c1474
Mind the "*0x" before the correct address.
I know this question is old, but I hope it helps anyway.

Resources