2011-01-21 2 views
40

,gdb를 입력 리디렉션과 함께 사용하는 방법은 무엇입니까? 터미널에서

gdb myapp < myfileinput 

이 제대로 실행되지 않았다, 나는

myapp < myfileinput 

을하지만 GDB를 사용하려는 경우.

여기 gdb를 사용하는 방법은 무엇입니까?

+0

가능한 중복 input.txt를 <을 실행 [프로그램 읽기 표준 입력을로드하고 GDB에서 매개 변수를 복용하는 방법?] (http://stackoverflow.com/questions/455544/how-to-load -program-reading-stdin-and-taking-parameters-in-gdb) –

답변

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 

이 나를 위해 트릭을하고있다. 이것이 당신이 찾고있는 것이 었는지 궁금합니다.

+1

이것은 [cygwin에서 동작하지 않습니다] (https://www.cygwin.com/ml/cygwin/1999-04/msg00304.html) – user2284570

+1

디버깅을 시작하려면'start

8

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) 

편집 : 또는 :

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

죄송 합니다만, 왜'-2'입니까? 왜'gdb -ex '가 args

+0

오! 승인! 파일의 두 번째 첫 줄인'head -2'를 의미합니다. 그냥 다른 arg. 내 잘못이야. ;) –

1

시도해 볼 수 있습니다.

(GDB는)의

+0

[cygwin에서 작동하지 않음] (https://www.cygwin.com/ml/cygwin/1999-04/msg00304.html) – user2284570

관련 문제