如何將板端的console(STDOUT,STDERR)重導到pts
更新記錄
item | note |
---|---|
20161213 | 第一版 |
目錄
pts debug
將STDOUT導向PTS
查看目前的導向
1
2
3
4
5# ls -l /proc/$(pidof dvrmain)/fd | grep null
lr-x------ 1 root root 64 Dec 13 10:50 0 -> /dev/null
# ls -l /proc/$(pidof dvrmain)/fd | grep console
lrwx------ 1 root root 64 Dec 13 10:50 1 -> /dev/console
lrwx------ 1 root root 64 Dec 13 10:50 2 -> /dev/console查看目前的pts
使用telnet登入,將會產生新的pts1
2
3
4
5# who
USER TTY IDLE TIME HOST
root ttyS000 00:00 Dec 13 10:47:53
root pts/0 00:20 Dec 13 10:49:38
root pts/1 00:19 Dec 13 11:10:46設定stdout為/dev/pts/x
關閉STDOUT, close(1)
使用dup2重新設定STDOUT1
2
3
4
5
6
7
8./gdb-arm-hisiv200-linux -p $(pidof dvrmain)
(gdb) p close(1)
$1 = 0
(gdb) p dup2(open("/dev/pts/1",2),1)
$2 = 1
(gdb) detach
Detaching from program: /opt/dvr_rdk/dvr_board/bin/dvrmain, process 1311
(gdb) quit- gdb –pid=PID Attach to running process PID.
檢查STDOUT導向
1
2
3# ls -l /proc/$(pidof dvrmain)/fd | grep pts
lrwx------ 1 root root 64 Dec 13 10:50 1 -> /dev/pts/1
lrwx------ 1 root root 64 Dec 13 11:21 247 -> /dev/pts/1
若要debug,記得STDOUT(1)及STDERR(2)都要設定
將STDOUT導向檔案
- 設定dup2為檔案即可
dup2(open(“/tmp/log2”,2),1)1
2
3
4
5
6
7
8
9
10
11./gdb-arm-hisiv200-linux -p $(pidof dvrmain)
(gdb) p close(1)
[Switching to Thread 0xb6f96000 (LWP 1311)]
$1 = 0
(gdb) p dup2(open("/tmp/tt/log33",2),1)
$2 = -1
(gdb) p dup2(open("/tmp/tt/dvrmain-log",2),1)
$3 = 1
(gdb) detach
Detaching from program: /opt/dvr_rdk/dvr_board/bin/dvrmain, process 1311
(gdb) quit
若回傳(-1)表示有錯,記得先產生檔案
- 將檔案導到pts
1
tail -f /tmp/tt/dvrmain-log > /dev/pts/1 &
這個比較方便,先將log導到檔案(可以記錄),再由tail輸出到pts
其它
STDIN、STDOUT、STDERR 與 Bash Redirection 測試
0 (stdin) 1 (fdisk.log) 2 (stderr)
0: stdin (Standard input) 標準輸入串流 (鍵盤輸入)
1: stdout (Standard output) 標準輸出串流 (輸出於 Cli 視窗)
2: stderr (Standard error) 標準錯誤輸出串流 (輸出於 Cli 視窗)fcntl.h
open mode 設定為2, 表示O_RDWR模式1
2
3
4#define O_RDONLY 0x0000
#define O_WRONLY 0x0001
#define O_RDWR 0x0002
#define O_ACCMODE 0x0003
板端gdb取得
gdb
- gdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47# ./gdb-arm-hisiv200-linux -help
This is the GNU debugger. Usage:
gdb [options] [executable-file [core-file or process-id]]
gdb [options] --args executable-file [inferior-arguments ...]
Options:
--args Arguments after executable-file are passed to inferior
-b BAUDRATE Set serial port baud rate used for remote debugging.
--batch Exit after processing options.
--batch-silent As for --batch, but suppress all gdb stdout output.
--return-child-result
GDB exit code will be the child's exit code.
--cd=DIR Change current directory to DIR.
--command=FILE, -x Execute GDB commands from FILE.
--eval-command=COMMAND, -ex
Execute a single GDB command.
May be used multiple times and in conjunction
with --command.
--core=COREFILE Analyze the core dump COREFILE.
--pid=PID Attach to running process PID.
--dbx DBX compatibility mode.
--directory=DIR Search for source files in DIR.
--epoch Output information used by epoch emacs-GDB interface.
--exec=EXECFILE Use EXECFILE as the executable.
--fullname Output information used by emacs-GDB interface.
--help Print this message.
--interpreter=INTERP
Select a specific interpreter / user interface
-l TIMEOUT Set timeout in seconds for remote debugging.
--nw Do not use a window interface.
--nx Do not read .gdbinit file.
--quiet Do not print version number on startup.
--readnow Fully read symbol files on first access.
--se=FILE Use FILE as symbol file and executable file.
--symbols=SYMFILE Read symbols from SYMFILE.
--tty=TTY Use TTY for input/output by the program being debugged.
--tui Use a terminal user interface.
--version Print version information and then exit.
-w Use a window interface.
--write Set writing into executable and core files.
--xdb XDB compatibility mode.
For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
Report bugs to "bug-gdb@gnu.org".