c++cgdbvoidfunction-call

How do I call function(void) in gdb


I am a complete beginner to reverse engg. In recent times I have been going through gdb and how to debug the programss.

I have a big doubt bear me if it is a simple one

#include <stdio.h>
#include <stdlib.h>

int flag(void){
    puts("okay you got this");
}

int main(void){
    puts("nope try again");
}

So i compiled this this program successfully, When I try run this program it gives me main function output

nope try again

so now how do i call the flag function to give the "okay you got this" output in gdb I tried my best evrything and surfed blogs to get the answer but i ended up in failure Hope ill get the solution and kindly suggest me what am I missing and what i needed to know on how does this works


Solution

  • You mean how to call flag() and skip the puts in main?, in this case:

    (gdb) break main
    (gdb) run
    (gdb) print flag()
    okay you got this
    (gdb) break 10
    (gdb) jump 10
    (gdb) quit