MDBG debugging - how to check value of static variable - mdbg

I am using MDBG to debug running process, but i don't know how to check a value of static variable. Is there some way to do it?
Thanks.

MDbg can capture "local" variables - I assume this means staic as well. If the variable is associated with a stack frame, you can get the value using the GetActiveLocalVars function.
MDbgThread t = proc.Threads.Active;
MDbgFrame f=t.CurrentFrame;
foreach (MDbgValue v in f.Function.GetActiveLocalVars(f))
{
Console.WriteLine(v.Name);
Console.WriteLine(v.Value);
}

Related

Node - look up the value of an arbitrary variable

Take this code for an example:
(() => {
const data = []
const ws = new WebSocket('ws:/localhost:5555');
ws.onmessage = (frame) => data.push(frame.data);
})();
Is it possible to look up the value of data without stopping the application, or breakpointing onmessage and waiting for it to occur? Is it possible to just look up the value of any variable that I know to be stored persistently somewhere?
Variables inside a function are private to within that function scope. Only code inside that function scope can examine them.
If you're in the debugger, you will need to be at a breakpoint inside that function scope in order to see that variable.
Sometimes it's appropriate to move the declaration of a variable to a higher scope so that after it is modified inside some local scope, it's value will persist and can be accessed from a higher scope. I don't know what real problem you're trying to solve here to know whether that makes sense for your situation or not.
More likely, since variables like your data variable get modified at some unknown time, the only way some outside code can know when to look at an updated value is by participating in some sort of event system or callback system that notifies outside that it now has a new value. In that case, it's common to just pass the new value to the callback or along with the event. Then the outside code gets the value that way, rather than having to declare it in some parent scope.

duktape, modify variable argument in native C code

I'm trying to modify a variable passed in an argument in a native function like this:
var MyVar = 'foo';
myNativeFunc(MyVar);
and inside my native, I can read the content of MyVar, with :
std::string(duk_to_string(ctx, 0));
but, I need to modify the value of this variable inside native function.
what is the best way for does it? (I can't use the return statement) thanks.
That's not possible as it would implement pass-by-reference (which is not supported in JS). Read also the answer to the question Pass Variables by Reference in Javascript
So, either pass in an object reference and change the object properties or use a return value.

variable does not properly update

Xilinx SDK 2016.1 freeRTOS823_xlinx OS platform
My code seemed to work fine until I introduced some freeRTOS elements. The general functionality of my code as follows:
In the Interrupt subroutine, I assign a value to a variable focusPosition that is read from the IP register of the Zynq Soc:
// separate file
u32 focusPosition=0;
static void ISR(void *CallbackRef)
{
focusPosition = XRb_focus_Get_position_o(CallbackRef);
}
Then I printf the value to the console in the main function:
// separate file
extern u32 focusPosition;
main{
...
while(1){
sleep(1);
xil_printf("%d\n",focusPosition);
}
}
The code prints the correct value, however, when I try to implement some additional lines in the code, like xTaskCreate() xEventGroupCreate(), something messes up all the memory and the printed value stays constant, which is not correct.
How can simple addition of the code that has nothing to do with the variable have any influence on that variable? As far as I understand, the xTaskCreate() and xEventGroupCreate() are created on the heap. I tired pocking around to see if Xil_DCacheDisable() would help, but no. Any ideas? Is my focusPosition variable properly defined/declared?
You should declare focusPosition as volatile otherwise the compiler does not expect it to be modified outside of the while loop so may optimize the code. Adding extra code may of caused this to happen. Any variable modified in an interrupt but used elsewhere should be declared volatile.

Why is the property value not instantly updated when multi-threading? C#

I have a Task running which updates a Property in another thread.
The moment it updates it, inside a loop it rechecks the variable and often happens that the variable still isn't updated? (a second, two)
Here's an example:
while (true)
{
if (someProperty) // Fails to recognize the set variable of True.
{
// Do something...
}
someProperty = true;
}
Is it a multi-thread issue and those should be synchronized? What would be the best way to solve that?
if this variable is shared between threads, it must be declared as volatile.
https://msdn.microsoft.com/en-us/library/x13ttww7.aspx

Is it possible to take the name of a variable and turn it into a string in ActionScript 3.0?

I am making a simple debugger window in ActionScript for myself where I can add and remove variables I want to track. I was to be able to add variables to the list by just doing something like
DebuggerMonitor.trackVar(variable).
My question is, is there any way I can turn "variable" itself (the name, not the value) into a String to be added into a text field?
Depending on how "intelligent" your debugger should be, you could just pass the name along:
DebuggerMonitor.trackVar( variable, "variable" );
since obviously, when used in a context like this, the name should be known at the time you are writing the program.
You can also do some reflection magic to get instance variable names, but it won't work for temp variables (their names are dropped at compilation time):
public function getVariableName( instance:*, match:* ):String {
var typeDescription:XML = describeType( instance );
var variables:XMLList = typeDescription..variable;
var accessors:XMLList = typeDescription..accessor;
for each(var variable:XML in variables)
if(matchesXMLName( instance, variable, match ))
return variable.#name;
for each(var accessor:XML in accessors)
if(matchesXMLName( instance, accessor, match ))
return accessor.#name;
return "No name found.";
}
private function matchesXMLName( instance:*, xml:XML, match:* ):Boolean {
return match == instance[xml.#name.toString()];
}
var varName:String = getVariableName ( myObject, variable );
Using reflections like this will also be quite costly, if used often - you will have to think of a way to cache the type descriptions.
I recommend you check out the as3commons reflections package - there is a lot of useful functionality in there...
Short answer - No :(
You can access the type name but not individual instance names, as these are lost at run-time.
There is a confusion caused by the keyword 'var' because it is used to create several types of bindings.
Lexical bindings (the keyword 'var' was used inside a function).
Dynamic bindings (the keyword 'var' was used to declare a class' field).
Lexical bindings are interpreted by the compiler at compile time as addresses of the registers of the registers space occupied by the function. The names given to lexical bindings perish at this time and it is not possible to restore them at runtime - therefore you can't get the "name" of the variable.
Dynamic bindings are a kind of "public API" of the objects that declare them, they may be accessed from the code that was not compiled together with the code that created them, this is why, for the purpose of reflection the names of these bindings are stored in compiled code. However, ActionScript has no way of referencing LHS values, so you cannot, even if you know the name of the variable and the object declaring it, pass it to another function. But you can look it up in the debugger or by calling describeType on the object declaring the variable. Note that describeType will not show information on private variables even if you are calling it from the scope of the object in question.

Resources