2009-02-01
Programming : Source Code Tracing
- GNU Global - trace source code 的工具 - 把程式原始碼變 HTML 網頁 ,有點類似 LXR
OpenCSL
CGDB
BUGFIX: jfbterm (5)
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h> // include frame buffer header files
#include <sys/ioctl.h>
int main(void)
{
int fbfd = 0 ; // frame buffer file description
/* Get device independent unchangeable information about a frame buffer
* device and a specific video mode by FBIOGET_FSCREENINFO ioctl. */
struct fb_fix_screeninfo finfo;
fbfd = open( "/dev/fb0" , O_RDWR );
if ( !fbfd )
{
printf( "Error: cannot open framebuffer device.\n" );
exit(1);
}
printf("The framebuffer device was opened successfully.\n");
/* Get fixed screen information */
if ( ioctl ( fbfd , FBIOGET_FSCREENINFO , &finfo ) )
{
printf("Error reading fixed screen information.\n");
exit(2);
} else {
printf("Succesfully Read the Fixed Screen Information\n");
}
printf("fb_fix_screeninfo.smem_len = %d\n", finfo.smem_len);
printf("fb_fix_screeninfo.mmio_len = %d\n", finfo.mmio_len);
}
- 在 Ubuntu Intrepid 上執行結果
root@intrepid:~# uname -a
Linux intrepid 2.6.27-7-server #1 SMP Tue Nov 4 20:16:57 UTC 2008 x86_64 GNU/Linux
root@intrepid:~# ./fbinfo
The framebuffer device was opened successfully.
Succesfully Read the Fixed Screen Information
fb_fix_screeninfo.smem_len = 16777216
fb_fix_screeninfo.mmio_len = 0
- 以下是在 Debian Sarge 上執行結果,值得一提的是 jfbterm 在 2.6.8 核心上可以正常執行。(不過還有字型問題需要調整)
root@wsu-admin:~# uname -a
Linux wsu-admin 2.6.8-2-386 #1 Tue Aug 16 12:46:35 UTC 2005 i686 GNU/Linux
root@wsu-admin:~# ./fbinfo
The framebuffer device was opened successfully.
Succesfully Read the Fixed Screen Information
fb_fix_screeninfo.smem_len = 65536
fb_fix_screeninfo.mmio_len = 0
root@wsu-admin:~# jfbterm
jfbterm - Kanji on framebuffer console Version 0.4.7
Copyright (C) 2003 Fumitoshi UKAI
Copyright (C) 1999-2000 Noritoshi Masuichi
This program is based on KON2
Copyright (C) 1992-1996 Takashi MANABE
(**) : Configuration file `/etc/jfbterm.conf'
.... 略 ....
exec : /bin/bash ioctl FBIOGET_CON2FBMAP: Invalid argument
color 0 : 0, 0
color 1 : 2a, 2a
color 2 : 2a, 2a
color 3 : 2a, 2a
color 4 : 2a, 2a
color 5 : 2a, 2a
color 6 : 2a, 2a
color 7 : 2a, 2a
color 8 : 15, 15
color 9 : 3f, 3f
color 10 : 3f, 3f
color 11 : 3f, 3f
color 12 : 3f, 3f
color 13 : 3f, 3f
color 14 : 3f, 3f
color 15 : 3f, 3f
- 以下是在 Debian Etch 上執行結果,有趣的是 jfbterm 0.4.7-7 在 2.6.18-4 上執行,縱使有 cannot mmap(mmio) : Invalid argument 的錯誤訊息,但仍舊可以正常進入 jfbterm 的環境。
root@etch:~# uname -a
Linux etch 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 2007 i686 GNU/Linux
root@etch:~# ./fbinfo
The framebuffer device was opened successfully.
Succesfully Read the Fixed Screen Information
fb_fix_screeninfo.smem_len = 1920000
fb_fix_screeninfo.mmio_len = 0
root@etch:~# jfbterm
jfbterm - Kanji on framebuffer console Version 0.4.7
Copyright (C) 2003 Fumitoshi UKAI
Copyright (C) 1999-2000 Noritoshi Masuichi
This program is based on KON2
Copyright (C) 1992-1996 Takashi MANABE
(**) : Configuration file `/etc/jfbterm.conf'
... 略 ...
exec : /bin/bash color 0 : 0, 0
color 1 : 15, 15
color 2 : 540, 540
color 3 : 555, 555
color 4 : a800, a800
color 5 : a815, a815
color 6 : ad40, ad40
color 7 : ad55, ad55
color 8 : 52aa, 52aa
color 9 : 52bf, 52bf
color 10 : 57ea, 57ea
color 11 : 57ff, 57ff
color 12 : faaa, faaa
color 13 : fabf, fabf
color 14 : ffea, ffea
color 15 : ffff, ffff
cannot mmap(mmio) : Invalid argument
- 為了測試 jfbterm 的中文相容性,我們寫了一隻簡單的 script
#!/bin/bash
echo " TEST 中文測試 "
echo "Press Any Key to continue!"
read
- 在 Ubutnu intriped 的 tty1 上執行 jfbterm -f /etc/jfbterm.conf -e /root/test.sh 可以正常看到" TEST 中文測試 "字樣,但卻無法正常跳出,因此我們再來 DEBUG 一下。
file jfbterm
set args -f /etc/jfbterm.conf -e /root/test.sh
show args
break fbcommon.c:500
break fbcommon.c:557
break fbcommon.c:566
break term.c:103
break term.c:284
r
c
c
c
bt
c
bt
p utp->ut_time
Breakpoint 4, tterm_final (p=0x6147c0) at term.c:103
(gdb) bt
#0 tterm_final (p=0x6147c0) at term.c:103
#1 0x0000000000408adf in sigchld (sig=<value optimized out>) at term.c:82
#2 <signal handler called>
#3 0x00007f5dfc00f433 in select () from /lib/libc.so.6
#4 0x0000000000408873 in tterm_start (p=0x6147c0, tn=<value optimized out>, en=<value optimized out>) at term.c:192
#5 0x0000000000402cf2 in main (argc=<value optimized out>, argv=0x7fff049477f8) at main.c:438
(gdb) c
Continuing.
Breakpoint 5, tterm_reset_utmp (p=<value optimized out>) at term.c:284
(gdb) bt
#0 tterm_reset_utmp (p=<value optimized out>) at term.c:284
#1 0x0000000000408a50 in tterm_final (p=0xe) at term.c:103
#2 0x0000000000408adf in sigchld (sig=<value optimized out>) at term.c:82
#3 <signal handler called>
#4 0x00007fa268131433 in select () from /lib/libc.so.6
#5 0x0000000000408873 in tterm_start (p=0x6147c0, tn=<value optimized out>, en=<value optimized out>) at term.c:192
#6 0x0000000000402cf2 in main (argc=<value optimized out>, argv=0x7fff70a69328) at main.c:438
(gdb) p utp->ut_time
There is no member named ut_time.
- GDB 線上除錯練習
[tty1]
root@etch:~# apt-get build-dep jfbterm
root@etch:~# apt-get source jfbterm
root@etch:~# apt-get install jfbterm
root@etch:~# cd jfbterm-0.4.7
root@etch:~/jfbterm-0.4.7# ./configure --enable-debug
root@etch:~/jfbterm-0.4.7# make
root@etch:~/jfbterm-0.4.7# ./jfbterm -f /etc/jfbterm.conf -e /root/test.sh
[tty2]
root@etch:~# gdb /root/jfbterm-0.4.7/jfbterm `pidof jfbterm`
GNU gdb 6.4.90-debian
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
Attaching to program: /root/jfbterm-0.4.7/jfbterm, process 7480
Reading symbols from /lib/tls/i686/cmov/libutil.so.1...done.
Loaded symbols for /lib/tls/i686/cmov/libutil.so.1
Reading symbols from /lib/tls/i686/cmov/libm.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libm.so.6
Reading symbols from /lib/tls/i686/cmov/libc.so.6...done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/tls/i686/cmov/libnss_compat.so.2...done.
Loaded symbols for /lib/tls/i686/cmov/libnss_compat.so.2
Reading symbols from /lib/tls/i686/cmov/libnsl.so.1...done.
Loaded symbols for /lib/tls/i686/cmov/libnsl.so.1
Reading symbols from /lib/tls/i686/cmov/libnss_nis.so.2...done.
Loaded symbols for /lib/tls/i686/cmov/libnss_nis.so.2
Reading symbols from /lib/tls/i686/cmov/libnss_files.so.2...done.
Loaded symbols for /lib/tls/i686/cmov/libnss_files.so.2
Failed to read a valid object file image from memory.
0xb7fea410 in ?? ()
(gdb) break term.c:284
Breakpoint 1 at 0x804f552: file term.c, line 284.
(gdb) c
Continuing.
Breakpoint 1, tterm_final (p=0x8058be0) at term.c:284
284 time(&(utp->ut_time));
(gdb) c
Continuing.
Breakpoint 1, tterm_final (p=0x8058be0) at term.c:284
284 time(&(utp->ut_time));
(gdb) c
Continuing.
Program exited normally.
- GDB 遠端除錯練習
[tty1]
gdbserver 127.0.0.1:1234 /root/jfbterm-0.4.7/jfbterm
[pts1]
(gdb) target remote 127.0.0.1:1234