Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using gdb to debug a interactive program that reads input from stdin

Tags:

c

gdb

pthreads

I'm writing a client/server program in C.

My client has a thread reading input from stdin, it's just a while(1) loop to read input from stdin. Whenever it reads a line, it deliver it to another thread that handles message parsing and framing.

As I enter gdb, the command line is occupied by gdb prompt and I can no longer input lines into stdin.

Is there a way to do it? (I don't want to redirect stdin to an input file because I've tried this method and it didn't work)

like image 574
zanyman Avatar asked Feb 03 '17 01:02

zanyman


1 Answers

Run your program in one terminal and attach to it from gdb in another terminal.

To attach to a running program, find the process ID (PID) of the program you want to attach to, then execute gdb <executable> <PID>.

like image 93
Jonathon Reinhart Avatar answered Sep 21 '22 00:09

Jonathon Reinhart