short version:
how to call a (non extern-C) function from visualD's debugger? ( I can do it with extern C) how to call a function with arguments that are stack variables (I can do it with actual numeric values, eg actual pointer addresses)

long version:

when debugging a session inside visual D, it can be very useful to call functions directly, eg:

* to print variables that visual D doesn't display properly (such as dynamic arrays, where visualD just prints the length and pointer)

* for interactive purposes (eg trying a function with different parameters)

Currently, visualD's support for this is limited, but I was able to do certain useful things (I'm not sure if many people realized one can do this in visuald, but this can be useful):

suppose we compile a D program into Main.exe:
we can call extern(C) functions as follows, by adding a watch variable in visual studio debugger and entering in the name field:
Main.exe!main_test@test1(2)
=> will show value=25, type=int, and will print in the command prompt "res=25"

now get address of z1 by looking into "Locals":
it shows:
-               z1      {length=4 ptr=0x01f20f40 {1} }  int[]
then display the dynamic array z1:
Main.exe!main_test@writelnPtr(3,0x01f20f40)

This is nice but not very convenient. Is there a way (if not, can that be addressed in the near future) to support the following?

* Main.exe!main_test@writeln2(z1)
=>currently returns: identifier "z1" is undefined  

* Main.exe!main_test@writeln2([1,2,3])
=>currently returns: expected a type specifier

* Main.exe!main_test@writeln3()
=>currently returns: identifier "main_test@writeln3" is undefined  

I also tried with the mangled name of writeln3 but that didn't work with visuald D. However, it DOES work on OSX, after compiling with debug symbols and then running under lldb:

b _Dmain
r
(lldb) expr (int) _D5tests16test_scratch_tim8testfun5FiZi (4)
=> doesn't work
(lldb) expr (int) D5tests16test_scratch_tim8testfun5FiZi (4)
=> successfully runs the underlying function once we remove the leading underscore

----
module main_test;
void main(){
    int[]z1=[1,2,3];
//breakpoint here
    writeln(z1);
}
extern(C)auto test1(int x){
        auto y=x*x;
        writeln("res=",y);
        return y;
}
extern(C)void writelnPtr(size_t n,void*ptr){
        writeln((cast(int*)ptr)[0..n]);
}
extern(C)void writeln2(int[]z){
        writeln(z);
}
void writeln3(){
        writeln("test");
}
----



Reply via email to