User forums > Using Code::Blocks
get return value of a call while debugging
Ceniza:
Shouldn't be that hard to implement really (at least in the debugger). The common implementation is to save the return value in eax (x86), or save there a pointer to where it's stored if it cannot be saved there, etc. Anyway, the return value is there. If it's a long all you'd need to do is to check eax's value. Haven't tested though :)
[edit]
I just did a quick test and it works, but this'sn't really the best way to do it. I wonder if the plugin could be modified to play with those "internals".
In the meanwhile just be sure to have the "CPU Registers" window enabled or modify your code to save the return value in a temporary.
[/edit]
MoonKid:
--- Quote from: Ceniza on April 17, 2006, 06:44:54 pm ---Shouldn't be that hard to implement really (at least in the debugger).
--- End quote ---
Should I have to patch the hole world? ;)
Patching a debugger is to hard for me. I am not a code hacker.
--- Quote from: Ceniza on April 17, 2006, 06:44:54 pm ---The common implementation is to save the return value in eax (x86), or save there a pointer to where it's stored if it cannot be saved there, etc. Anyway, the return value is there. If it's a long all you'd need to do is to check eax's value.
I just did a quick test and it works, but this'sn't really the best way to do it. I wonder if the plugin could be modified to play with those "internals".
--- End quote ---
Where did you test it? You patched gdb? :)
Which plugin do you mean?
You confuse me! ;)
sethjackson:
He didn't mean patch GDB. :shock: :lol:
He meant make a patch (feature addition) to the Code::Blocks debugger plugin.
Ceniza:
First, just ignore the fact of patching GDB.
This is what I did:
* Created a new console project.
* Created a main.cpp ('cause I created the project totally empty).
* Added this little test program:
--- Code: (cpp) ---#include <iostream>
long function(long n)
{
return n * 7 + 2;
}
int main()
{
long x;
std::cin >> x;
function(x);
std::cin >> x;
function(x);
}
--- End code ---
* In the build options enabled debugging symbols [-g].
* In the debugger toolbar I enabled the "CPU Registers" window.
* Added a breakpoint at line 13 (first call to function).
* Started debugging.
It'll show you a console and will be waiting for a long value. I typed 8 just for fun. When I hit enter the program is interrupted by the debugger.
The current value of eax is before calling function, so I just click on "Next line" button (it's in the debugger toolbar). Now check eax's value: 58 (8 * 7 + 2).
"Next line". It'll ask for another number. I typed 3. "Next line". Once again it's eax's value before the function is called. "Next line". Now eax's value is 23 (3 * 7 + 2).
The plugin I was talking about is the debugger plugin, but I really wonder if Don Corleone would be interested in doing so, or anyone else in writing a patch.
Once again, it's kinda a hack, but works :P
Ceniza:
Another trick, if someone is really feeling like creating a patch for the debugger plugin (sorry if no one is) :)
Howto when the return value is a struct
This is basically the same example, but now everything is evaluated as long and double, stored in a struct and returned.
--- Code: (cpp) ---#include <iostream>
struct longdouble
{
long l;
double d;
};
longdouble function(longdouble n)
{
longdouble r;
r.l = r.d = n.l * 7 + 2;
return r;
}
int main()
{
longdouble x;
std::cin >> x.l;
x.d = x.l;
function(x);
std::cin >> x.l;
x.d = x.l;
function(x);
}
--- End code ---
The breakpoint goes now in line 24 (first call to function).
I just did the same: typed 8, the program was interrupted and clicked on "Next line". Because it's a struct, eax stores a pointer to a temporary struct where the result is saved. In my machine it's 0x22ff50 in hex (eax's value).
If you want the value of l (the long inside struct longdouble): Debug -> Send user command to debugger:
--- Code: ---output ((struct longdouble *)0x22ff50)->l
--- End code ---
The result will be shown in the Debugger thingy in the Messages pane.
I hope all of this be of any use, but once again: sorry.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version