在脚本里面执行 gdb

1. 

$ echo  disass main | gdb --silent test200
Reading symbols from test200...done.
(gdb) Dump of assembler code for function main:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    $0x0,%eax
   0x080483f3 <+8>:	pop    %ebp
   0x080483f4 <+9>:	ret    
End of assembler dump.
(gdb) quit
charles@xiaotao:~$ 

2.

$ gdb --silent test200 <<< "disass main"
Reading symbols from test200...done.
(gdb) Dump of assembler code for function main:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    $0x0,%eax
   0x080483f3 <+8>:	pop    %ebp
   0x080483f4 <+9>:	ret    
End of assembler dump.
(gdb) quit

3.

$ (echo  -ne "disass main\nquit\n"; cat) | gdb --silent test200
Reading symbols from test200...done.
(gdb) Dump of assembler code for function main:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    $0x0,%eax
   0x080483f3 <+8>:	pop    %ebp
   0x080483f4 <+9>:	ret    
End of assembler dump.
(gdb) 

但是这个不能自动退出gdb.


http://stackoverflow.com/questions/322110/invoke-gdb-to-automatically-pass-arguments-to-the-program-being-debugged

你可能感兴趣的:(Linux)