2011-01-21 8 views
40

en la terminal, tengo¿Cómo usar gdb con la redirección de entrada?

myapp < myfileinput 

Pero si quiero usar GDB,

gdb myapp < myfileinput 

No se ha ejecutado correctamente.

¿Cómo usar gdb aquí?

+0

duplicado posible de [Cómo cargar la entrada estándar de lectura del programa y tomando parámetros en GDB?] (Http://stackoverflow.com/questions/455544/how-to-load -program-reading-stdin-and-taking-parameters-in-gdb) –

Respuesta

70
~$ gdb <executable> 

GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08 
Copyright (C) 2011 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 "i686-linux-gnu". 
For bug reporting instructions, please see: 
<http://bugs.launchpad.net/gdb-linaro/>... 
Reading symbols from /home/abhishek/maxtest...done. 

(gdb) run < input.txt 

Esto está haciendo el truco para mí. Preguntándose si esto era lo que estabas buscando.

+1

Esto [no funciona en cygwin] (https://www.cygwin.com/ml/cygwin/1999-04/msg00304.html) – user2284570

+1

También funciona con 'start

8

¿Intenta ejecutar su aplicación desde dentro de gdb?

(gdb) file /usr/bin/head 
Reading symbols from /usr/bin/head...(no debugging symbols found)...done. 
(gdb) run -2 < /etc/passwd 
Starting program: /usr/bin/head -2 < /etc/passwd 
root:x:0:0:root:/root:/bin/bash 
daemon:x:1:1:daemon:/usr/sbin:/bin/sh 

Program exited normally. 
(gdb) 

EDIT: Como alternativa:

gdb -q -ex 'set args -2 < /etc/passwd' /usr/bin/head 
Reading symbols from /usr/bin/head...done. 

(gdb) run 
root:x:0:0:root:/root:/bin/bash 
daemon:x:1:1:daemon:/usr/sbin:/bin/sh 

Program exited normally. 
(gdb) quit 
+0

Lo sentimos, pero ¿por qué el '-2'? ¿Por qué no simplemente 'gdb -ex 'set args

+0

¡Oh! ¡De acuerdo! Te refieres a 'cabeza -2', las dos primeras líneas de un archivo. Solo otro arg. Mi error. ;) –

1

Puede intentar esto.

(BGF) ejecutar < entrada.txt

+0

Esto [no funciona en cygwin] (https://www.cygwin.com/ml/cygwin/1999-04/msg00304.html) – user2284570

Cuestiones relacionadas