rohanrhu / gdb-frontend

☕ GDBFrontend is an easy, flexible and extensible gui debugger. Try it on https://debugme.dev
https://oguzhaneroglu.com/projects/gdb-frontend/
GNU General Public License v3.0
2.79k stars 98 forks source link

How to debug apps get inputs from TTY? #54

Closed likyh closed 2 years ago

likyh commented 2 years ago
#include <stdio.h>
int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a+b);
    return 0;
}

got:

image
rohanrhu commented 2 years ago

When you use scanf() and similars, OS sends SIGTTIN to your process and GDB shell and your app can't use the same TTY like this. Your app must use a different TTY than the one that your GDB shell is on.

Simplest way to debug apps that take inputs on TTY

Split terminal and run your app in new terminal

image

Attach GDB to your process

image

When GDB attached to your process, your process will be interrupted immediately, just click to continue

image

Add a breakpoint after the call that gets input from TTY and enter an input and press enter

image

That's all.

likyh commented 2 years ago

thank you~

GitMensch commented 1 year ago

That's very useful - What do you think about adding this to the tutorials and link that in README?

rohanrhu commented 1 year ago

That's very useful - What do you think about adding this to the tutorials and link that in README?

Thank you @GitMensch I will add it to docs and link in README.md.