Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb won't accept user input

I'm currently following this video on how to work with assembly and gdb, using this C program, but I'm running into a problem. Here's what I do to compile and run gdb:

chiggins@host:~/assem$ gcc -ggdb -o SimpleDemo SimpleDemo.c
chiggins@host:~/assem$ gdb ./SimpleDemo
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/chiggins/assem/SimpleDemo...done.
(gdb) list
4       int add(int x, int y)
5       {
6               int z =10;
7
8               z = x + y;
9               return z;
10      }
11
12      main(int argc, char **argv)
13      {
(gdb)
14              int a = atoi(argv[1]);
15              int b = atoi(argv[2]);
16              int c;
17              char buffer[100];
18
19              gets(buffer);
20              puts(buffer);
21
22              c = add(a,b);
23
(gdb)
24              printf("Sum of %d+%d = %d\n",a, b, c);
25
26              exit(0);
27
28      }
(gdb) run 10 20
Starting program: /home/chiggins/assem/SimpleDemo 10 20
demo

Now from where I have "demo" typed at the end, that's where the program is supposed to be accepting user input. But when I press return after typing enter, nothing happens. I can't ctrl+c out of the program, can't do anything. I end up having to kill the process from another session just so I can get control back. Any ideas why gdb is doing this, or what I might be doing wrong?

Thanks!

like image 446
Chiggins Avatar asked Nov 03 '22 21:11

Chiggins


1 Answers

I'm not sure why that doesn't work for you; it works as expected here...

Still, I find it easier to run programs performing interactive I/O in a separate terminal, and perhaps it will help you.

In one terminal,

$ gdbserver --multi localhost:4242
listening on port 4242

and in another,

$ gdb ./SimpleDemo
(gdb) target extended-remote localhost:4242
Remote debugging using localhost:4242
(gdb) run 10 20

Back to the terminal running gdbserver,

Remote debugging from host 127.0.0.1
Process ./SimpleDemo created; pid=PID
demo
demo
Sum of 10+20 = 30

Child exited with status 0
like image 183
ephemient Avatar answered Nov 07 '22 20:11

ephemient