24owls
2021-03-23 02:33:55 +08:00
gdb 修改 cat stdin/stdout/stderr 的例子
```
$ cat > /tmp/test-in
1
22
333
$ cat
^Z
[1]+ Stopped cat
$ jobs -l
[1]+ 6138 Stopped cat
$ gdb -q
(gdb) attach 6138
Attaching to process 6138
[ noise ]
(gdb) call (int) close (0)
$1 = 0
(gdb) call (int) open ("/tmp/test-in", 0200)
$2 = 0
(gdb) call (int) close (1)
$3 = 0
(gdb) call (int) open ("/tmp/test-out-err", 0501, 0644)
$4 = 1
(gdb) call (int) close (2)
$5 = 0
(gdb) call (int) dup (1)
$6 = 2
(gdb) detach
Detaching from program: /usr/bin/cat, process 6138
[Inferior 1 (process 6138) detached]
(gdb) quit
$ bg
[1]+ cat &
$ jobs -l
[1]+ 6138 Done cat
$ cat /tmp/test-out
1
22
333
```