I have at my disposal a pretty elaborate printing function to help me debug. Unfortunately, it prints directly to a specified file stream, rather than returning a string (it returns some irrelevant value instead). call
doesn't seem to have any parameters when I call help call
in GDB. Is it really not possible to hide the return result of the call
command? Or is there another command I should be entertaining?
Asked
Active
Viewed 301 times
1

llf
- 610
- 10
- 11
-
1Hm. Just a wild guess: `call (void)func(whatever)` ? – Eugene Sh. Jan 25 '18 at 18:44
-
Damned good guess - it worked! Thanks! I'll post a MWE in a second. – llf Jan 25 '18 at 18:53
1 Answers
1
We can cast the result of the function to void
to discard its value.
MWE
callnoresult.c
#include <stdio.h>
void pretty_printer() {
fprintf(stderr, "Hello world!\n");
}
int main() {
return 0;
}
Then, in terminal:
gcc callnoresult.c -o callnoresult
gdb ./callnoresult
<gdb message>
b main
run
call (void) pretty_printer()
<"Hello world!">
See What does casting to void
really do?
for more info on the cast.