Changes between Version 6 and Version 7 of jazz/jfbterm


Ignore:
Timestamp:
Feb 2, 2009, 2:13:09 AM (15 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • jazz/jfbterm

    v6 v7  
    445445
    446446 * [wiki:jazz/09-02-01 09-02-01@GMT+8 原紀錄 BUGFIX: jfbterm (5)]
     447{{{
     448#!C
     449#include <unistd.h>
     450#include <stdio.h>
     451#include <fcntl.h>
     452#include <linux/fb.h>       // include frame buffer header files
     453#include <sys/ioctl.h>
     454
     455int main(void)
     456{
     457  int fbfd = 0 ;            // frame buffer file description
     458
     459  /* Get device independent unchangeable information about a frame buffer
     460   * device and a specific video mode by FBIOGET_FSCREENINFO ioctl. */
     461  struct  fb_fix_screeninfo finfo;
     462
     463  fbfd = open( "/dev/fb0" , O_RDWR );
     464  if ( !fbfd )
     465  {
     466    printf( "Error: cannot open framebuffer device.\n" );
     467    exit(1);
     468  }
     469  printf("The framebuffer device was opened successfully.\n");
     470
     471  /* Get fixed screen information */
     472  if ( ioctl ( fbfd ,  FBIOGET_FSCREENINFO , &finfo )  )
     473  {
     474    printf("Error reading fixed screen information.\n");
     475    exit(2);
     476  } else {
     477    printf("Succesfully Read the Fixed Screen Information\n");
     478  }
     479
     480  printf("fb_fix_screeninfo.smem_len = %d\n", finfo.smem_len);
     481  printf("fb_fix_screeninfo.mmio_len = %d\n", finfo.mmio_len);
     482}
     483}}}
     484
     485 * 在 Ubuntu Intrepid 上執行結果
     486{{{
     487root@intrepid:~# uname -a
     488Linux intrepid 2.6.27-7-server #1 SMP Tue Nov 4 20:16:57 UTC 2008 x86_64 GNU/Linux
     489root@intrepid:~# ./fbinfo
     490The framebuffer device was opened successfully.
     491Succesfully Read the Fixed Screen Information
     492fb_fix_screeninfo.smem_len = 16777216
     493fb_fix_screeninfo.mmio_len = 0
     494}}}
     495 * 以下是在 Debian Sarge 上執行結果,值得一提的是 jfbterm 在 2.6.8 核心上可以正常執行。(不過還有字型問題需要調整)
     496{{{
     497root@wsu-admin:~# uname -a
     498Linux wsu-admin 2.6.8-2-386 #1 Tue Aug 16 12:46:35 UTC 2005 i686 GNU/Linux
     499root@wsu-admin:~# ./fbinfo
     500The framebuffer device was opened successfully.
     501Succesfully Read the Fixed Screen Information
     502fb_fix_screeninfo.smem_len = 65536
     503fb_fix_screeninfo.mmio_len = 0
     504}}}
     505{{{
     506root@wsu-admin:~# jfbterm
     507jfbterm - Kanji on framebuffer console Version 0.4.7
     508       Copyright (C) 2003 Fumitoshi UKAI
     509        Copyright (C) 1999-2000 Noritoshi Masuichi
     510This program is based on KON2
     511        Copyright (C) 1992-1996 Takashi MANABE
     512
     513(**) : Configuration file `/etc/jfbterm.conf'
     514.... 略 ....
     515exec : /bin/bash ioctl FBIOGET_CON2FBMAP: Invalid argument
     516color 0 : 0, 0
     517color 1 : 2a, 2a
     518color 2 : 2a, 2a
     519color 3 : 2a, 2a
     520color 4 : 2a, 2a
     521color 5 : 2a, 2a
     522color 6 : 2a, 2a
     523color 7 : 2a, 2a
     524color 8 : 15, 15
     525color 9 : 3f, 3f
     526color 10 : 3f, 3f
     527color 11 : 3f, 3f
     528color 12 : 3f, 3f
     529color 13 : 3f, 3f
     530color 14 : 3f, 3f
     531color 15 : 3f, 3f
     532}}}
     533 * 以下是在 Debian Etch 上執行結果,有趣的是 jfbterm 0.4.7-7 在 2.6.18-4 上執行,縱使有 cannot mmap(mmio) : Invalid argument 的錯誤訊息,但仍舊可以正常進入 jfbterm 的環境。
     534{{{
     535root@etch:~# uname -a
     536Linux etch 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 2007 i686 GNU/Linux
     537root@etch:~# ./fbinfo
     538The framebuffer device was opened successfully.
     539Succesfully Read the Fixed Screen Information
     540fb_fix_screeninfo.smem_len = 1920000
     541fb_fix_screeninfo.mmio_len = 0
     542}}}
     543{{{
     544root@etch:~# jfbterm
     545jfbterm - Kanji on framebuffer console Version 0.4.7
     546       Copyright (C) 2003 Fumitoshi UKAI
     547        Copyright (C) 1999-2000 Noritoshi Masuichi
     548This program is based on KON2
     549        Copyright (C) 1992-1996 Takashi MANABE
     550
     551(**) : Configuration file `/etc/jfbterm.conf'
     552... 略 ...
     553exec : /bin/bash color 0 : 0, 0
     554color 1 : 15, 15
     555color 2 : 540, 540
     556color 3 : 555, 555
     557color 4 : a800, a800
     558color 5 : a815, a815
     559color 6 : ad40, ad40
     560color 7 : ad55, ad55
     561color 8 : 52aa, 52aa
     562color 9 : 52bf, 52bf
     563color 10 : 57ea, 57ea
     564color 11 : 57ff, 57ff
     565color 12 : faaa, faaa
     566color 13 : fabf, fabf
     567color 14 : ffea, ffea
     568color 15 : ffff, ffff
     569cannot mmap(mmio) : Invalid argument
     570}}}
     571 * 為了測試 jfbterm 的中文相容性,我們寫了一隻簡單的 script
     572{{{
     573#!sh
     574#!/bin/bash
     575echo " TEST 中文測試 "
     576echo "Press Any Key to continue!"
     577read
     578}}}
     579 * 在 Ubutnu intriped 的 tty1 上執行 jfbterm -f /etc/jfbterm.conf -e /root/test.sh 可以正常看到" TEST 中文測試 "字樣,但卻無法正常跳出,因此我們再來 DEBUG 一下。
     580{{{
     581file jfbterm
     582set args -f /etc/jfbterm.conf -e /root/test.sh
     583show args
     584break fbcommon.c:500
     585break fbcommon.c:557
     586break fbcommon.c:566
     587break term.c:103
     588break term.c:284
     589r
     590c
     591c
     592c
     593bt
     594c
     595bt
     596p utp->ut_time
     597p utp->ut_tv
     598}}}
     599{{{
     600Breakpoint 4, tterm_final (p=0x6147c0) at term.c:103
     601(gdb) bt
     602#0  tterm_final (p=0x6147c0) at term.c:103
     603#1  0x0000000000408adf in sigchld (sig=<value optimized out>) at term.c:82
     604#2  <signal handler called>
     605#3  0x00007f5dfc00f433 in select () from /lib/libc.so.6
     606#4  0x0000000000408873 in tterm_start (p=0x6147c0, tn=<value optimized out>, en=<value optimized out>) at term.c:192
     607#5  0x0000000000402cf2 in main (argc=<value optimized out>, argv=0x7fff049477f8) at main.c:438
     608(gdb) c
     609Continuing.
     610
     611Breakpoint 5, tterm_reset_utmp (p=<value optimized out>) at term.c:284
     612(gdb) bt
     613#0  tterm_reset_utmp (p=<value optimized out>) at term.c:284
     614#1  0x0000000000408a50 in tterm_final (p=0xe) at term.c:103
     615#2  0x0000000000408adf in sigchld (sig=<value optimized out>) at term.c:82
     616#3  <signal handler called>
     617#4  0x00007fa268131433 in select () from /lib/libc.so.6
     618#5  0x0000000000408873 in tterm_start (p=0x6147c0, tn=<value optimized out>, en=<value optimized out>) at term.c:192
     619#6  0x0000000000402cf2 in main (argc=<value optimized out>, argv=0x7fff70a69328) at main.c:438
     620(gdb) p utp->ut_time
     621There is no member named ut_time.
     622}}}
     623 * [註] utp->ut_time = utp->ut_tv.tv_sec
     624{{{
     625#!C
     626
     627< /usr/include/bits/utmp.h >
     628
     629 59 /* The structure describing an entry in the user accounting database.  */
     630 60 struct utmp
     631 61 {
     632 62   short int ut_type;            /* Type of login.  */
     633 63   pid_t ut_pid;                 /* Process ID of login process.  */
     634 64   char ut_line[UT_LINESIZE];    /* Devicename.  */
     635 65   char ut_id[4];                /* Inittab ID.  */
     636 66   char ut_user[UT_NAMESIZE];    /* Username.  */
     637 67   char ut_host[UT_HOSTSIZE];    /* Hostname for remote login.  */
     638 68   struct exit_status ut_exit;   /* Exit status of a process marked
     639 69                                    as DEAD_PROCESS.  */
     640 70 /* The ut_session and ut_tv fields must be the same size when compiled
     641 71    32- and 64-bit.  This allows data files and shared memory to be
     642 72    shared between 32- and 64-bit applications.  */
     643 73 #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
     644 74   int32_t ut_session;           /* Session ID, used for windowing.  */
     645 75   struct
     646 76   {
     647 77     int32_t tv_sec;             /* Seconds.  */
     648 78     int32_t tv_usec;            /* Microseconds.  */
     649 79   } ut_tv;                      /* Time entry was made.  */
     650 80 #else
     651 81   long int ut_session;          /* Session ID, used for windowing.  */
     652 82   struct timeval ut_tv;         /* Time entry was made.  */
     653 83 #endif
     654 84
     655 85   int32_t ut_addr_v6[4];        /* Internet address of remote host.  */
     656 86   char __unused[20];            /* Reserved for future use.  */
     657 87 };
     658
     659 94 # define ut_time        ut_tv.tv_sec
     660}}}
     661 * GDB 線上除錯練習
     662{{{
     663[tty1]
     664
     665root@etch:~# apt-get build-dep jfbterm
     666root@etch:~# apt-get source jfbterm
     667root@etch:~# apt-get install jfbterm
     668root@etch:~# cd jfbterm-0.4.7
     669root@etch:~/jfbterm-0.4.7# ./configure --enable-debug
     670root@etch:~/jfbterm-0.4.7# make
     671root@etch:~/jfbterm-0.4.7# ./jfbterm -f /etc/jfbterm.conf -e /root/test.sh
     672
     673[tty2]
     674
     675root@etch:~# gdb /root/jfbterm-0.4.7/jfbterm `pidof jfbterm`
     676GNU gdb 6.4.90-debian
     677Copyright (C) 2006 Free Software Foundation, Inc.
     678GDB is free software, covered by the GNU General Public License, and you are
     679welcome to change it and/or distribute copies of it under certain conditions.
     680Type "show copying" to see the conditions.
     681There is absolutely no warranty for GDB.  Type "show warranty" for details.
     682This GDB was configured as "i486-linux-gnu"...Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
     683
     684Attaching to program: /root/jfbterm-0.4.7/jfbterm, process 7480
     685Reading symbols from /lib/tls/i686/cmov/libutil.so.1...done.
     686Loaded symbols for /lib/tls/i686/cmov/libutil.so.1
     687Reading symbols from /lib/tls/i686/cmov/libm.so.6...done.
     688Loaded symbols for /lib/tls/i686/cmov/libm.so.6
     689Reading symbols from /lib/tls/i686/cmov/libc.so.6...done.
     690Loaded symbols for /lib/tls/i686/cmov/libc.so.6
     691Reading symbols from /lib/ld-linux.so.2...done.
     692Loaded symbols for /lib/ld-linux.so.2
     693Reading symbols from /lib/tls/i686/cmov/libnss_compat.so.2...done.
     694Loaded symbols for /lib/tls/i686/cmov/libnss_compat.so.2
     695Reading symbols from /lib/tls/i686/cmov/libnsl.so.1...done.
     696Loaded symbols for /lib/tls/i686/cmov/libnsl.so.1
     697Reading symbols from /lib/tls/i686/cmov/libnss_nis.so.2...done.
     698Loaded symbols for /lib/tls/i686/cmov/libnss_nis.so.2
     699Reading symbols from /lib/tls/i686/cmov/libnss_files.so.2...done.
     700Loaded symbols for /lib/tls/i686/cmov/libnss_files.so.2
     701Failed to read a valid object file image from memory.
     7020xb7fea410 in ?? ()
     703(gdb) break term.c:284
     704Breakpoint 1 at 0x804f552: file term.c, line 284.
     705(gdb) c
     706Continuing.
     707
     708Breakpoint 1, tterm_final (p=0x8058be0) at term.c:284
     709284             time(&(utp->ut_time));
     710(gdb) c
     711Continuing.
     712
     713Breakpoint 1, tterm_final (p=0x8058be0) at term.c:284
     714284             time(&(utp->ut_time));
     715(gdb) c
     716Continuing.
     717
     718Program exited normally.
     719}}}
     720 * GDB 遠端除錯練習
     721{{{
     722[tty1]
     723gdbserver 127.0.0.1:1234 /root/jfbterm-0.4.7/jfbterm
     724[pts1]
     725(gdb) target remote 127.0.0.1:1234
     726}}}
     727 * 在 DEBUG 的時候偶爾會看到 <value optimized out>,但是該怎麼去掉呢??
     728   * [參考] http://www.cs.utk.edu/~vose/c-stuff/onlinedocs/gdb_7.html
     729{{{
     730The values of arguments that were not saved in their stack frames are shown as `<value optimized out>'.
     731
     732If you need to display the values of such optimized-out arguments, either deduce that from other variables whose values depend on the one you are interested in, or recompile without optimizations.
     733}}}
     734   * [作法] 在 configure 的時候加上 CFLAGS
     735     * 註: 因為如果有設定 CFLAGS 的話,在 configure 裡是會直接採用我們提供的 CFLAGS。因此縱使加上 --enable-debug 也沒有用,configure 不會幫你加 -g 進去。
     736{{{
     737root@intrepid:~/jfbterm-0.4.7-dev# CFLAGS="-g -O0" ./configure
     738}}}
     739 * 繼續追為何結束時會收到 SIGSEGV 的主因
     740{{{
     741< 直接在 tty1 或在 screen 中執行 >
     742root@intrepid:~/jfbterm-0.4.7-dev# ./jfbterm -f /etc/jfbterm.conf -e /root/test.sh
     743}}}
     744{{{
     745root@intrepid:~/jfbterm-0.4.7-dev# gdb ./jfbterm `pidof jfbterm`
     746break term.c:103
     747break term.c:284
     748c
     749#### 直接在 tty1 不透過 screen 執行 的結果 #####
     750Breakpoint 1, tterm_final (p=0x617a00) at term.c:103
     751103             tterm_reset_utmp(p);
     752(gdb) s
     753tterm_reset_utmp (p=0x617a00) at term.c:271
     754271     {
     755(gdb) s
     756275             tn = rindex(p->name, '/') + 4;
     757(gdb) p p->name
     758$1 = "/dev/pts/0", '\0' <repeats 53 times>
     759#### 直接在 tty1 有透過 screen 執行 的結果 #####
     760
     761Breakpoint 1, tterm_final (p=0x617a00) at term.c:103
     762103             tterm_reset_utmp(p);
     763(gdb) s
     764tterm_reset_utmp (p=0x617a00) at term.c:271
     765271     {
     766(gdb) s
     767275             tn = rindex(p->name, '/') + 4;
     768(gdb) p p->name
     769$1 = "/dev/pts/1", '\0' <repeats 53 times>
     770}}}
     771 * manpage of getutid(3)
     772{{{
     773SYNOPSIS
     774
     775       struct utmp *getutid(struct utmp *ut);
     776
     777DESCRIPTION
     778
     779       getutid() searches forward from the current file position in  the  utmp
     780       file  based  upon  ut.   If  ut->ut_type  is one of RUN_LVL, BOOT_TIME,
     781       NEW_TIME, or OLD_TIME,  getutid()  will  find  the  first  entry  whose
     782       ut_type  field matches ut->ut_type.  If ut->ut_type is one of INIT_PRO-
     783       CESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid() will find
     784       the first entry whose ut_id field matches ut->ut_id.
     785
     786RETURN VALUE
     787       getutent(), getutid(), getutline() and pututline() return a pointer  to
     788       a  struct  utmp  on  success, and NULL on failure.  This struct utmp is
     789       allocated in static storage,  and  may  be  overwritten  by  subsequent
     790       calls.
     791
     792FILES
     793       /var/run/utmp  database of currently logged-in users
     794       /var/log/wtmp  database of past user logins
     795
     796NOTES
     797   Glibc Notes
     798       The above functions are not thread-safe.  Glibc adds reentrant versions
     799
     800       #define _GNU_SOURCE    /* or _SVID_SOURCE or _BSD_SOURCE */
     801       #include <utmp.h>
     802
     803       int getutent_r(struct utmp *ubuf, struct utmp **ubufp);
     804
     805       int getutid_r(struct utmp *ut,
     806                     struct utmp *ubuf, struct utmp **ubufp);
     807
     808       int getutline_r(struct utmp *ut,
     809                       struct utmp *ubuf, struct utmp **ubufp);
     810
     811       These  functions  are  GNU  extensions, analogs of the functions of the
     812       same name without the _r suffix.  The ubuf parameter gives these  func-
     813       tions  a  place to store their result.  On success they return 0, and a
     814       pointer to the result is written in *ubufp.  On error  these  functions
     815       return -1.
     816
     817}}}
     818{{{
     819root@intrepid:~# w
     820 02:01:29 up 5 min,  5 users,  load average: 0.75, 0.91, 0.41
     821USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
     822root@intrepid:~# w
     823 02:02:14 up 6 min,  5 users,  load average: 0.35, 0.78, 0.39
     824USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
     825root     pts/0    :tty1:S.0        01:58    1:46m  0.24s  0.21s ./jfbterm -f /etc/jfbterm.conf -e /root/test.sh ### screen 0
     826root     pts/1    :tty1:S.1        01:58    3:55m  0.01s  0.01s /bin/bash                                       ### screen 1
     827root     pts/3    172.21.253.1     01:59    1:19m  0.12s  0.10s gdb ./jfbterm 3833                              ### from ssh for gdb
     828root     pts/2    -                01:59    1:46m  0.00s  0.21s ./jfbterm -f /etc/jfbterm.conf -e /root/test.sh ### fb created by jfbterm
     829root     pts/4    172.21.253.1     02:01    0.00s  0.02s  0.00s w                                               ### from ssh for this command `w'
     830}}}