ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÉÏÕÒ³ö²¢½â¾ö³ÌÐò´íÎó·½·¨£¨Ï£©

·¢²¼Ê±¼ä:2006-11-13 09:43:12À´Ô´:ºìÁª×÷Õß:hlMiracle
¡¡¡¡µÚ 2 ÖÖÇé¿ö£ºÊ¹Óà strace

¡¡¡¡strace ÃüÁîÊÇÒ»ÖÖÇ¿´óµÄ¹¤¾ß£¬ËüÄܹ»ÏÔʾËùÓÐÓÉÓû§¿Õ¼ä³ÌÐò·¢³öµÄϵͳµ÷Óá£strace ÏÔʾÕâЩµ÷ÓõIJÎÊý²¢·µ»Ø·ûºÅÐÎʽµÄÖµ¡£strace ´ÓÄں˽ÓÊÕÐÅÏ¢£¬¶øÇÒ²»ÐèÒªÒÔÈκÎÌØÊâµÄ·½Ê½À´¹¹½¨Äںˡ£½«¸ú×ÙÐÅÏ¢·¢Ë͵½Ó¦ÓóÌÐò¼°Äں˿ª·¢Õ߶¼ºÜÓÐÓá£ÔÚÇåµ¥ 6 ÖУ¬·ÖÇøµÄÒ»ÖÖ¸ñʽÓдíÎó£¬Çåµ¥ÏÔʾÁË strace µÄ¿ªÍ·²¿·Ö£¬ÄÚÈÝÊǹØÓÚµ÷³ö´´½¨Îļþϵͳ²Ù×÷£¨mkfs£©µÄ¡£strace È·¶¨Äĸöµ÷Óõ¼ÖÂÎÊÌâ³öÏÖ¡£

ÒýÓÃ:
execve("/sbin/mkfs.jfs", ["mkfs.jfs", "-f", "/dev/test1"], &
...
open("/dev/test1", O_RDWR|O_LARGEFILE) = 4
stat64("/dev/test1", {st_mode=&, st_rdev=makedev(63, 255), ...}) = 0
ioctl(4, 0x40041271, 0xbfffe128) = -1 EINVAL (Invalid argument)
write(2, "mkfs.jfs: warning - cannot setb" ..., 98mkfs.jfs: warning -
cannot set blocksize on block device /dev/test1: Invalid argument )
= 98
stat64("/dev/test1", {st_mode=&, st_rdev=makedev(63, 255), ...}) = 0
open("/dev/test1", O_RDONLY|O_LARGEFILE) = 5
ioctl(5, 0x80041272, 0xbfffe124) = -1 EINVAL (Invalid argument)
write(2, "mkfs.jfs: can\'t determine device"..., ..._exit(1)
= ?


¡¡¡¡Çåµ¥ 6. mkfs ÉÏ strace µÄ¿ªÍ·²¿·Ö

¡¡¡¡Çåµ¥ 6 ÏÔʾ ioctl µ÷Óõ¼ÖÂÓÃÀ´¸ñʽ»¯·ÖÇøµÄ mkfs ³ÌÐòʧ°Ü¡£ioctl BLKGETSIZE64 ʧ°Ü¡££¨BLKGET-SIZE64 ÔÚµ÷Óà ioctl µÄÔ´´úÂëÖж¨Òå¡£) BLKGETSIZE64 ioctl ½«±»Ìí¼Óµ½ Linux ÖÐËùÓеÄÉ豸£¬¶øÔÚÕâÀÂß¼­¾í¹ÜÀíÆ÷»¹²»Ö§³ÖËü¡£Òò´Ë£¬Èç¹û BLKGETSIZE64 ioctl µ÷ÓÃʧ°Ü£¬mkfs ´úÂ뽫¸ÄΪµ÷ÓýÏÔçµÄ ioctl µ÷Óã»ÕâʹµÃ mkfs ÊÊÓÃÓÚÂß¼­¾í¹ÜÀíÆ÷¡£

¡¡¡¡µÚ 3 ÖÖÇé¿ö£ºÊ¹Óà gdb ºÍ Oops

¡¡¡¡Äú¿ÉÒÔ´ÓÃüÁîÐÐʹÓà gdb ³ÌÐò£¨Free Software Foundation µÄµ÷ÊÔÆ÷£©À´ÕÒ³ö´íÎó£¬Ò²¿ÉÒÔ´ÓÖîÈç Data Display Debugger£¨DDD£©ÕâÑùµÄ¼¸¸öͼÐι¤¾ß֮һʹÓà gdb ³ÌÐòÀ´ÕÒ³ö´íÎó¡£Äú¿ÉÒÔʹÓà gdb À´µ÷ÊÔÓû§¿Õ¼ä³ÌÐò»ò Linux Äںˡ£ÕâÒ»²¿·ÖÖ»ÌÖÂÛ´ÓÃüÁîÐÐÔËÐÐ gdb µÄÇé¿ö¡£

¡¡¡¡Ê¹Óà gdb program name ÃüÁîÆô¶¯ gdb¡£gdb ½«ÔØÈë¿ÉÖ´ÐгÌÐò·ûºÅ²¢ÏÔʾÊäÈëÌáʾ·û£¬ÈÃÄú¿ÉÒÔ¿ªÊ¼Ê¹Óõ÷ÊÔÆ÷¡£Äú¿ÉÒÔͨ¹ýÈýÖÖ·½Ê½Óà gdb ²é¿´½ø³Ì£º

¡¡¡¡Ê¹Óà attach ÃüÁʼ²é¿´Ò»¸öÒѾ­ÔËÐеĽø³Ì£»attach ½«Í£Ö¹½ø³Ì¡£

¡¡¡¡Ê¹Óà run ÃüÁîÖ´ÐгÌÐò²¢´ÓÍ·¿ªÊ¼µ÷ÊÔ³ÌÐò¡£

¡¡¡¡²é¿´ÒÑÓеĺËÐÄÎļþÀ´È·¶¨½ø³ÌÖÕֹʱµÄ״̬¡£Òª²é¿´ºËÐÄÎļþ£¬ÇëÓÃÏÂÃæµÄÃüÁîÆô¶¯ gdb¡£

ÒýÓÃ:
gdb programname corefilename


¡¡¡¡ÒªÓúËÐÄÎļþ½øÐе÷ÊÔ£¬Äú²»½öÐèÒª³ÌÐòµÄ¿ÉÖ´ÐÐÎļþºÍÔ´Îļþ£¬»¹ÐèÒªºËÐÄÎļþ±¾Éí¡£ÒªÓúËÐÄÎļþÆô¶¯ gdb£¬ÇëʹÓà -c Ñ¡Ï

ÒýÓÃ:
gdb -c core programname


¡¡¡¡gdb ÏÔʾÄÄÐдúÂëµ¼Ö³ÌÐò·¢ÉúºËÐÄת´¢¡£

¡¡¡¡ÔÚÔËÐгÌÐò»òÁ¬½Óµ½ÒѾ­ÔËÐеijÌÐò֮ǰ£¬ÇëÁгöÄú¾õµÃÓдíÎóµÄÔ´´úÂ룬ÉèÖöϵ㣬Ȼºó¿ªÊ¼µ÷ÊÔ³ÌÐò¡£Äú¿ÉÒÔʹÓà help ÃüÁî²é¿´È«ÃæµÄ gdb ÔÚÏß°ïÖúºÍÏêϸµÄ½Ì³Ì¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 4 ÌõÆÀÂÛ

  1. hlMiracle ÓÚ 2006-11-13 09:47:00·¢±í:

    ¡¡¡¡×·»÷ÄÚ´æÒç³ö

    ¡¡¡¡Äú¿Ï¶¨²»ÏëÏÝÈëÀàËÆÔÚ¼¸Ç§´Îµ÷ÓÃÖ®ºó·¢Éú·ÖÅäÒç³öÕâÑùµÄÇéÐΡ£ÎÒÃǵÄС×黨ÁËÐíÐí¶à¶àʱ¼äÀ´¸ú×ÙÏ¡Ææ¹Å¹ÖµÄÄÚ´æ´íÎóÎÊÌâ¡£Ó¦ÓóÌÐòÔÚÎÒÃǵĿª·¢¹¤×÷Õ¾ÉÏÄÜÔËÐУ¬µ«ÔÚеIJúÆ·¹¤×÷Õ¾ÉÏ£¬Õâ¸öÓ¦ÓóÌÐòÔÚµ÷Óà malloc() Á½°ÙÍò´ÎÖ®ºó¾Í²»ÄÜÔËÐÐÁË¡£ÕæÕýµÄÎÊÌâÊÇÔÚ´óÔ¼Ò»°ÙÍò´Îµ÷ÓÃÖ®ºó·¢ÉúÁËÒç³ö¡£ÐÂϵͳ֮ËùÓдæÔÚÕâ¸öÎÊÌ⣬ÊÇÒòΪ±»±£ÁôµÄ malloc() ÇøÓòµÄ²¼¾ÖÓÐËù²»Í¬£¬´Ó¶øÕâЩÁãÉ¢ÄÚ´æ±»·ÅÖÃÔÚÁ˲»Í¬µÄµØ·½£¬ÔÚ·¢ÉúÒç³öʱÆÆ»µÁËһЩ²»Í¬µÄÄÚÈÝ¡£

    ¡¡¡¡ÎÒÃÇÓöàÖÖ²»Í¬¼¼ÊõÀ´½â¾öÕâ¸öÎÊÌ⣬ÆäÖÐÒ»ÖÖÊÇʹÓõ÷ÊÔÆ÷£¬ÁíÒ»ÖÖÊÇÔÚÔ´´úÂëÖÐÌí¼Ó¸ú×Ù¹¦ÄÜ¡£ÔÚÎÒÖ°ÒµÉúÑĵĴó¸ÅÒ²ÊÇÕâ¸öʱºò£¬Îұ㿪ʼ¹Ø×¢ÄÚ´æµ÷ÊÔ¹¤¾ß£¬Ï£ÍûÄܸü¿ì¸üÓÐЧµØ½â¾öÕâЩÀàÐ͵ÄÎÊÌâ¡£ÔÚ¿ªÊ¼Ò»¸öÐÂÏîĿʱ£¬ÎÒ×îÏÈ×öµÄÊÂÇéÖ®Ò»¾ÍÊÇÔËÐÐ MEMWATCH ºÍ YAMD£¬¿´¿´ËüÃÇÊDz»ÊÇ»áÖ¸³öÄÚ´æ¹ÜÀí·½ÃæµÄÎÊÌâ¡£

    ¡¡¡¡ÄÚ´æй©ÊÇÓ¦ÓóÌÐòÖг£¼ûµÄÎÊÌ⣬²»¹ýÄú¿ÉÒÔʹÓñ¾ÎÄËù½²ÊöµÄ¹¤¾ßÀ´½â¾öÕâЩÎÊÌâ¡£

    ¡¡¡¡µÚ 4 ÖÖÇé¿ö£ºÊ¹ÓÃħÊõ¼ü¿Ø˳Ðò½øÐлØËݸú×Ù

    ¡¡¡¡Èç¹ûÔÚ Linux ¹ÒÆðʱÄúµÄ¼üÅÌÈÔÈ»ÄÜÓã¬ÄÇÇëÄúʹÓÃÒÔÏ·½·¨À´°ïÖú½â¾ö¹ÒÆðÎÊÌâµÄ¸ùÔ´¡£×ñÑ­ÕâЩ²½Ö裬Äú±ã¿ÉÒÔÏÔʾµ±Ç°ÔËÐеĽø³ÌºÍËùÓÐʹÓÃħÊõ¼ü¿Ø˳ÐòµÄ½ø³ÌµÄ»ØËݸú×Ù¡£

    ¡¡¡¡ÄúÕýÔÚÔËÐеÄÄں˱ØÐëÊÇÔÚÆôÓà CONFIG_MAGIC_SYS-REQ µÄÇé¿öϹ¹½¨µÄ¡£Äú»¹±ØÐë´¦ÔÚÎı¾Ä£Ê½¡£CLTR+ALT+F1 »áʹÄú½øÈëÎı¾Ä£Ê½£¬CLTR+ALT+F7 »áʹÄú»Øµ½ X Windows¡£

    ¡¡¡¡µ±ÔÚÎı¾Ä£Ê½Ê±£¬Çë°´ £¬È»ºó°´ ¡£ÉÏÊöħÊõµÄ»÷¼ü»á·Ö±ð¸ø³öµ±Ç°ÔËÐеĽø³ÌºÍËùÓнø³ÌµÄ¶ÑÕ»¸ú×Ù¡£

    ¡¡¡¡Çë²éÕÒ /var/log/messages¡£Èç¹ûÒ»ÇÐÉèÖÃÕýÈ·£¬ÔòϵͳӦ¸ÃÒѾ­ÎªÄúת»»ÁËÄں˵ķûºÅµØÖ·¡£»ØËݸú×Ù½«±»Ð´µ½ /var/log/messages ÎļþÖС£

    ¡¡¡¡½áÊøÓï

    ¡¡¡¡°ïÖúµ÷ÊÔ Linux ÉϵijÌÐòÓÐÐí¶à²»Í¬µÄ¹¤¾ß¿É¹©Ê¹Óᣱ¾ÎĽ²ÊöµÄ¹¤¾ß¿ÉÒÔ°ïÖúÄú½â¾öÐí¶à±àÂëÎÊÌâ¡£ÄÜÏÔʾÄÚ´æй©¡¢Òç³öµÈµÈµÄλÖõŤ¾ß¿ÉÒÔ½â¾öÄÚ´æ¹ÜÀíÎÊÌ⣬ÎÒ·¢ÏÖ MEMWATCH ºÍ YAMD ºÜÓаïÖú¡£

    ¡¡¡¡Ê¹Óà Linux Äں˲¹¶¡»áʹ gdb ÄÜÔÚ Linux ÄÚºËÉϹ¤×÷£¬Õâ¶Ô½â¾öÎÒ¹¤×÷ÖÐʹÓÃµÄ Linux µÄÎļþϵͳ·½ÃæµÄÎÊÌâºÜÓаïÖú¡£´ËÍ⣬¸ú×ÙʵÓóÌÐòÄÜ°ïÖúÈ·¶¨ÔÚϵͳµ÷ÓÃÆÚ¼äÎļþϵͳʵÓóÌÐòʲôµØ·½³öÁ˹ÊÕÏ¡£Ï´ε±ÄúÒª°Úƽ Linux ÖеĴíÎóʱ£¬ÇëÊÔÊÔÕâЩ¹¤¾ßÖеÄijһ¸ö¡£

  2. hlMiracle ÓÚ 2006-11-13 09:46:16·¢±í:

    ¡¡¡¡Oops ·ÖÎö

    ¡¡¡¡Oops£¨Ò²³Æ panic£¬»ÅÕÅ£©ÏûÏ¢°üº¬ÏµÍ³´íÎóµÄϸ½Ú£¬Èç CPU ¼Ä´æÆ÷µÄÄÚÈÝ¡£ÔÚ Linux ÖУ¬µ÷ÊÔϵͳ±ÀÀ£µÄ´«Í³·½·¨ÊÇ·ÖÎöÔÚ·¢Éú±ÀÀ£Ê±·¢Ë͵½ÏµÍ³¿ØÖÆ̨µÄ Oops ÏûÏ¢¡£Ò»µ©ÄúÕÆÎÕÁËϸ½Ú£¬¾Í¿ÉÒÔ½«ÏûÏ¢·¢Ë͵½ ksymoops ʵÓóÌÐò£¬Ëü½«ÊÔͼ½«´úÂëת»»ÎªÖ¸Áî²¢½«¶ÑÕ»ÖµÓ³Éäµ½Äں˷ûºÅ¡£ÔںܶàÇé¿öÏ£¬ÕâЩÐÅÏ¢¾Í×ã¹»ÄúÈ·¶¨´íÎóµÄ¿ÉÄÜÔ­ÒòÊÇʲôÁË¡£Çë×¢Ò⣬Oops ÏûÏ¢²¢²»°üÀ¨ºËÐÄÎļþ¡£

    ¡¡¡¡ÈÃÎÒÃǼÙÉèϵͳ¸Õ¸Õ´´½¨ÁËÒ»Ìõ Oops ÏûÏ¢¡£×÷Ϊ±àд´úÂëµÄÈË£¬ÄúÏ£Íû½â¾öÎÊÌⲢȷ¶¨Ê²Ã´µ¼ÖÂÁË Oops ÏûÏ¢µÄ²úÉú£¬»òÕßÄúÏ£ÍûÏòÏÔʾÁË Oops ÏûÏ¢µÄ´úÂëµÄ¿ª·¢ÕßÌṩÓйØÄúµÄÎÊÌâµÄ´ó²¿·ÖÐÅÏ¢£¬´Ó¶ø¼°Ê±µØ½â¾öÎÊÌâ¡£Oops ÏûÏ¢ÊǵÈʽµÄÒ»²¿·Ö£¬µ«Èç¹û²»Í¨¹ý ksymoops ³ÌÐòÔËÐÐËüÒ²ÓÚÊÂÎÞ²¹¡£ÏÂÃæµÄͼÏÔʾÁ˸ñʽ»¯ Oops ÏûÏ¢µÄ¹ý³Ì¡£

    ¡¡¡¡¸ñʽ»¯ Oops ÏûÏ¢

    ¡¡¡¡ksymoops ÐèÒª¼¸ÏîÄÚÈÝ£ºOops ÏûÏ¢Êä³ö¡¢À´×ÔÕýÔÚÔËÐеÄÄÚºËµÄ System.map Îļþ£¬»¹ÓÐ /proc/ksyms¡¢vmlinux ºÍ /proc/modules¡£¹ØÓÚÈçºÎʹÓà ksymoops£¬ÄÚºËÔ´´úÂë /usr/src/linux/Documentation/oops-tracing.txt Öлò ksymoops ÊÖ²áÒ³ÉÏÓÐÍêÕûµÄ˵Ã÷¿ÉÒԲο¼¡£Ksymoops ·´»ã±à´úÂ벿·Ö£¬Ö¸³ö·¢Éú´íÎóµÄÖ¸Á²¢ÏÔʾһ¸ö¸ú×Ù²¿·Ö±íÃ÷´úÂëÈçºÎ±»µ÷Óá£

    ¡¡¡¡Ê×ÏÈ£¬½« Oops ÏûÏ¢±£´æÔÚÒ»¸öÎļþÖÐÒÔ±ãͨ¹ý ksymoops ʵÓóÌÐòÔËÐÐËü¡£Çåµ¥ 10 ÏÔʾÁËÓÉ°²×° JFS ÎļþϵͳµÄ mount ÃüÁî´´½¨µÄ Oops ÏûÏ¢£¬ÎÊÌâÊÇÓÉÇåµ¥ 8 ÖÐÌí¼Óµ½ JFS °²×°´úÂëµÄÄÇÈýÐдúÂë²úÉúµÄ¡£

    ÒýÓÃ:
    ksymoops 2.4.0 on i686 2.4.17. Options used
    ... 15:59:37 sfb1 kernel: Unable to handle kernel NULL pointer dereference at
    virtual address 0000000
    ... 15:59:37 sfb1 kernel: c01588fc
    ... 15:59:37 sfb1 kernel: *pde = 0000000
    ... 15:59:37 sfb1 kernel: Oops: 0000
    ... 15:59:37 sfb1 kernel: CPU: 0
    ... 15:59:37 sfb1 kernel: EIP: 0010:[jfs_mount+60/704]

    ... 15:59:37 sfb1 kernel: Call Trace: [jfs_read_super+287/688]
    [get_sb_bdev+563/736] [do_kern_mount+189/336] [do_add_mount+35/208]
    [do_page_fault+0/1264]
    ... 15:59:37 sfb1 kernel: Call Trace: []...
    ... 15:59:37 sfb1 kernel: [>EIP; c01588fc <=====
    ...
    Trace; c0106cf3
    Code; c01588fc
    00000000 <_EIP>:
    Code; c01588fc <=====
    0: 8b 2d 00 00 00 00 mov 0x0,%ebp <=====
    Code; c0158902
    6: 55 push %ebp


    ¡¡¡¡Çåµ¥ 10. ksymoops ´¦ÀíºóµÄ Oops ÏûÏ¢

    ¡¡¡¡½ÓÏÂÀ´£¬ÄúҪȷ¶¨ jfs_mount ÖеÄÄÄÒ»ÐдúÂëÒýÆðÁËÕâ¸öÎÊÌâ¡£Oops ÏûÏ¢¸æËßÎÒÃÇÎÊÌâÊÇÓÉλÓÚÆ«ÒƵØÖ· 3c µÄÖ¸ÁîÒýÆðµÄ¡£×öÕâ¼þʵİ취֮һÊÇ¶Ô jfs_mount.o ÎļþʹÓà objdump ʵÓóÌÐò£¬È»ºó²é¿´Æ«ÒƵØÖ· 3c¡£Objdump ÓÃÀ´·´»ã±àÄ£¿éº¯Êý£¬¿´¿´ÄúµÄ C Ô´´úÂë»á²úÉúʲô»ã±àÖ¸Áî¡£Çåµ¥ 11 ÏÔʾÁËʹÓà objdump ºóÄú½«¿´µ½µÄÄÚÈÝ£¬½Ó×Å£¬ÎÒÃDz鿴 jfs_mount µÄ C ´úÂ룬¿ÉÒÔ¿´µ½¿ÕÖµÊÇµÚ 109 ÐÐÒýÆðµÄ¡£Æ«ÒƵØÖ· 3c Ö®ËùÒÔºÜÖØÒª£¬ÊÇÒòΪ Oops ÏûÏ¢½«¸Ã´¦±êʶΪÒýÆðÎÊÌâµÄλÖá£

    ÒýÓÃ:
    109 printk("%d\n",*ptr);

    objdump jfs_mount.o

    jfs_mount.o: file format elf32-i386

    Disassembly of section .text:

    00000000 :
    0:55 push %ebp
    ...
    2c: e8 cf 03 00 00 call 400
    31: 89 c3 mov %eax,%ebx
    33: 58 pop %eax
    34: 85 db test %ebx,%ebx
    36: 0f 85 55 02 00 00 jne 291
    3c: 8b 2d 00 00 00 00 mov 0x0,%ebp << problem line above
    42: 55 push %ebp


    ¡¡¡¡Çåµ¥ 11. jfs_mount µÄ»ã±à³ÌÐòÇåµ¥

    ¡¡¡¡kdb

    ¡¡¡¡Linux Äں˵÷ÊÔÆ÷£¨Linux kernel debugger£¬kdb£©ÊÇ Linux Äں˵IJ¹¶¡£¬ËüÌṩÁËÒ»ÖÖÔÚϵͳÄÜÔËÐÐʱ¶ÔÄÚºËÄÚ´æºÍÊý¾Ý½á¹¹½øÐмì²éµÄ°ì·¨¡£Çë×¢Ò⣬kdb ²»ÐèÒªÁ½Ì¨»úÆ÷£¬²»¹ýËüÒ²²»ÔÊÐíÄúÏñ kgdb ÄÇÑù½øÐÐÔ´´úÂ뼶±ðÉϵĵ÷ÊÔ¡£Äú¿ÉÒÔÌí¼Ó¶îÍâµÄÃüÁ¸ø³ö¸ÃÊý¾Ý½á¹¹µÄ±êʶ»òµØÖ·£¬ÕâЩÃüÁî±ã¿ÉÒÔ¸ñʽ»¯ºÍÏÔʾ»ù±¾µÄϵͳÊý¾Ý½á¹¹¡£Ä¿Ç°µÄÃüÁÔÊÐíÄú¿ØÖÆ°üÀ¨ÒÔϲÙ×÷ÔÚÄÚµÄÄں˲Ù×÷£º

    ¡¡¡¡´¦ÀíÆ÷µ¥²½Ö´ÐУ»

    ¡¡¡¡Ö´Ðе½Ä³ÌõÌض¨Ö¸Áîʱֹͣ£»

    ¡¡¡¡µ±´æÈ¡£¨»òÐ޸ģ©Ä³¸öÌض¨µÄÐéÄâÄÚ´æλÖÃʱֹͣ£»

    ¡¡¡¡µ±´æÈ¡ÊäÈ룯Êä³öµØÖ·¿Õ¼äÖеļĴæÆ÷ʱֹͣ£»

    ¡¡¡¡¶Ôµ±Ç°»î¶¯µÄÈÎÎñºÍËùÓÐÆäËüÈÎÎñ½øÐжÑÕ»»ØËݸú×Ù£¨Í¨¹ý½ø³Ì ID£©£»

    ¡¡¡¡¶ÔÖ¸Áî½øÐз´»ã±à¡£

  3. hlMiracle ÓÚ 2006-11-13 09:45:05·¢±í:

    ¡¡¡¡ÏÖÔÚÎÒÃÇ¿ÉÒÔͨ¹ý¸ÄΪʹÓÃÄÚºËÔ´´úÂëÊ÷¿ªÊ¼µÄĿ¼À´Æô¶¯¿ª·¢»úÆ÷É쵀 gdb ³ÌÐòÁË¡£ÔÚ±¾Ê¾ÀýÖУ¬ÄÚºËÔ´´úÂëÊ÷λÓÚ /usr/src/linux-2.4.17¡£ÊäÈë gdb Æô¶¯³ÌÐò¡£

    ¡¡¡¡Èç¹ûÒ»ÇÐÕý³££¬²âÊÔ»úÆ÷½«ÔÚÆô¶¯¹ý³ÌÖÐÍ£Ö¹¡£ÊäÈë gdb ÃüÁî cont ÒÔ¼ÌÐøÆô¶¯¹ý³Ì¡£Ò»¸ö³£¼ûµÄÎÊÌâÊÇ£¬¿Õµ÷Öƽâµ÷Æ÷µçÀ¿ÉÄܻᱻÁ¬½Óµ½´íÎóµÄ´®¿Ú¡£Èç¹û gdb ²»Æô¶¯£¬½«¶Ë¿Ú¸ÄΪµÚ¶þ¸ö´®¿Ú£¬Õâ»áʹ gdb Æô¶¯¡£

    ¡¡¡¡Ê¹Óà kgdb µ÷ÊÔÄÚºËÎÊÌâ

    ¡¡¡¡Çåµ¥ 8 ÁгöÁË jfs_mount.c ÎļþµÄÔ´´úÂëÖб»Ð޸ĹýµÄ´úÂ룬ÎÒÃÇÔÚ´úÂëÖд´½¨ÁËÒ»¸ö¿ÕÖ¸ÕëÒì³££¬´Ó¶øʹ´úÂëÔÚµÚ 109 ÐвúÉú¶Î´íÎó¡£

    ÒýÓÃ:
    int jfs_mount(struct super_block *sb)
    {
    ...
    int ptr; /* line 1 added */
    jFYI(1, ("\nMount JFS\n"));
    / *
    * read/validate superblock
    * (initialize mount inode from the superblock)
    * /
    if ((rc = chkSuper(sb))) {
    goto errout20;
    }
    108 ptr=0; /* line 2 added */
    109 printk("%d\n",*ptr); /* line 3 added */


    ¡¡¡¡Çåµ¥ 8. Ð޸ĹýºóµÄ jfs_mount.c ´úÂë

    ¡¡¡¡Çåµ¥ 9 ÔÚÏòÎļþϵͳ·¢³ö mount ÃüÁîÖ®ºóÏÔʾһ¸ö gdb Òì³£¡£kgdb ÌṩÁ˼¸ÌõÃüÁÈçÏÔʾÊý¾Ý½á¹¹ºÍ±äÁ¿ÖµÒÔ¼°ÏÔʾϵͳÖеÄËùÓÐÈÎÎñ´¦ÓÚʲô״̬¡¢ËüÃÇפÁôÔںδ¦¡¢ËüÃÇÔÚÄÄЩµØ·½Ê¹ÓÃÁË CPU µÈµÈ¡£Çåµ¥ 9 ½«ÏÔʾ»ØËݸú×ÙΪ¸ÃÎÊÌâÌṩµÄÐÅÏ¢£»where ÃüÁîÓÃÀ´Ö´Ðз´¸ú×Ù£¬Ëü½«¸æËß±»Ö´Ðеĵ÷ÓÃÔÚ´úÂëÖеÄʲôµØ·½Í£Ö¹¡£

    ÒýÓÃ:
    mount -t jfs /dev/sdb /jfs

    Program received signal SIGSEGV, Segmentation fault.
    jfs_mount (sb=0xf78a3800) at jfs_mount.c:109
    109 printk("%d\n",*ptr);
    (gdb)where
    #0 jfs_mount (sb=0xf78a3800) at jfs_mount.c:109
    #1 0xc01a0dbb in jfs_read_super ... at super.c:280
    #2 0xc0149ff5 in get_sb_bdev ... at super.c:620
    #3 0xc014a89f in do_kern_mount ... at super.c:849
    #4 0xc0160e66 in do_add_mount ... at namespace.c:569
    #5 0xc01610f4 in do_mount ... at namespace.c:683
    #6 0xc01611ea in sys_mount ... at namespace.c:716
    #7 0xc01074a7 in system_call () at af_packet.c:1891
    #8 0x0 in ?? ()
    (gdb)


    ¡¡¡¡Çåµ¥ 9. gdb Òì³£ºÍ·´¸ú×Ù

    ¡¡¡¡ÏÂÒ»²¿·Ö»¹½«ÌÖÂÛÕâ¸öÏàͬµÄ JFS ¶Î´íÎóÎÊÌ⣬µ«²»ÉèÖõ÷ÊÔÆ÷£¬Èç¹ûÄúÔÚ·Ç kgdb Äں˻·¾³ÖÐÖ´ÐÐÇåµ¥ 8 ÖеĴúÂ룬ÄÇôËüʹÓÃÄں˿ÉÄÜÉú³ÉµÄ Oops ÏûÏ¢¡£

  4. hlMiracle ÓÚ 2006-11-13 09:44:15·¢±í:

    ¡¡¡¡kgdb

    ¡¡¡¡kgdb ³ÌÐò£¨Ê¹Óà gdb µÄÔ¶³ÌÖ÷»ú Linux Äں˵÷ÊÔÆ÷£©ÌṩÁËÒ»ÖÖʹÓà gdb µ÷ÊÔ Linux Äں˵ĻúÖÆ¡£kgdb ³ÌÐòÊÇÄں˵ÄÀ©Õ¹£¬ËüÈÃÄúÄܹ»ÔÚÔ¶³ÌÖ÷»úÉÏÔËÐÐ gdb ʱÁ¬½Óµ½ÔËÐÐÓà kgdb À©Õ¹µÄÄں˻úÆ÷¡£Äú¿ÉÒÔ½Ó×ÅÉîÈëµ½ÄÚºËÖС¢ÉèÖöϵ㡢¼ì²éÊý¾Ý²¢½øÐÐÆäËü²Ù×÷£¨ÀàËÆÓÚÄúÔÚÓ¦ÓóÌÐòÉÏʹÓà gdb µÄ·½Ê½£©¡£Õâ¸ö²¹¶¡µÄÖ÷ÒªÌصãÖ®Ò»¾ÍÊÇÔËÐÐ gdb µÄÖ÷»úÔÚÒýµ¼¹ý³ÌÖÐÁ¬½Óµ½Ä¿±ê»úÆ÷£¨ÔËÐÐÒª±»µ÷ÊÔµÄÄںˣ©¡£ÕâÈÃÄúÄܹ»¾¡Ô翪ʼµ÷ÊÔ¡£Çë×¢Ò⣬²¹¶¡Îª Linux ÄÚºËÌí¼ÓÁ˹¦ÄÜ£¬ËùÒÔ gdb ¿ÉÒÔÓÃÀ´µ÷ÊÔ Linux Äںˡ£

    ¡¡¡¡Ê¹Óà kgdb ÐèÒªÁ½Ì¨»úÆ÷£ºÒ»Ì¨ÊÇ¿ª·¢»úÆ÷£¬Áíһ̨ÊDzâÊÔ»úÆ÷¡£Ò»Ìõ´®ÐÐÏߣ¨¿Õµ÷Öƽâµ÷Æ÷µçÀ£©½«Í¨¹ý»úÆ÷µÄ´®¿ÚÁ¬½ÓËüÃÇ¡£ÄúÏ£Íûµ÷ÊÔµÄÄÚºËÔÚ²âÊÔ»úÆ÷ÉÏÔËÐУ»gdb ÔÚ¿ª·¢»úÆ÷ÉÏÔËÐС£gdb ʹÓô®ÐÐÏßÓëÄúÒªµ÷ÊÔµÄÄÚºËͨÐÅ¡£

    ¡¡¡¡Çë×ñÑ­ÏÂÃæµÄ²½ÖèÀ´ÉèÖà kgdb µ÷ÊÔ»·¾³£ºÏÂÔØÄúµÄ Linux Äں˰汾ÊÊÓõIJ¹¶¡¡£

    ¡¡¡¡½«×é¼þ¹¹½¨µ½Äںˣ¬ÒòΪÕâÊÇʹÓà kgdb ×î¼òµ¥µÄ·½·¨¡££¨Çë×¢Ò⣬ÓÐÁ½ÖÖ·½·¨¿ÉÒÔ¹¹½¨¶àÊýÄÚºË×é¼þ£¬±ÈÈç×÷Ϊģ¿é»òÖ±½Ó¹¹½¨µ½ÄÚºËÖС£¾ÙÀýÀ´Ëµ£¬ÈÕÖ¾¼Í¼Îļþϵͳ£¨Journaled File System£¬JFS£©¿ÉÒÔ×÷Ϊģ¿é¹¹½¨£¬»òÖ±½Ó¹¹½¨µ½ÄÚºËÖС£Í¨¹ýʹÓà gdb ²¹¶¡£¬ÎÒÃǾͿÉÒÔ½« JFS Ö±½Ó¹¹½¨µ½ÄÚºËÖС££©Ó¦ÓÃÄں˲¹¶¡²¢ÖØй¹½¨Äںˡ£

    ¡¡¡¡´´½¨Ò»¸öÃûΪ .gdbinit µÄÎļþ£¬²¢½«Æä±£´æÔÚÄÚºËÔ´Îļþ×ÓĿ¼ÖУ¨»»¾ä»°Ëµ¾ÍÊÇ /usr/src/linux£©¡£Îļþ .gdbinit ÖÐÓÐÏÂÃæËÄÐдúÂ룺

    ÒýÓÃ:
    set remotebaud 115200
    symbol-file vmlinux
    target remote /dev/ttyS0
    set output-radix 16


    ¡¡¡¡½« append=gdb ÕâÒ»ÐÐÌí¼Óµ½ lilo£¬lilo ÊÇÓÃÀ´ÔÚÒýµ¼ÄÚºËʱѡÔñʹÓÃÄĸöÄں˵ÄÒýµ¼ÔØÈë³ÌÐò¡£

    ÒýÓÃ:
    image=/boot/bzImage-2.4.17
    label=gdb2417
    read-only
    root=/dev/sda8
    append="gdb gdbttyS=1 gdb-baud=115200 nmi_watchdog=0"


    ¡¡¡¡Çåµ¥ 7 ÊÇÒ»¸ö½Å±¾Ê¾Àý£¬Ëü½«ÄúÔÚ¿ª·¢»úÆ÷ÉϹ¹½¨µÄÄں˺ÍÄ£¿éÒýÈë²âÊÔ»úÆ÷¡£ÄúÐèÒªÐÞ¸ÄÏÂÃ漸Ï

    ¡¡¡¡best@sfb£ºÓû§±êʶºÍ»úÆ÷Ãû¡£

    ¡¡¡¡/usr/src/linux-2.4.17£ºÄÚºËÔ´´úÂëÊ÷µÄĿ¼¡£

    ¡¡¡¡bzImage-2.4.17£º²âÊÔ»úÆ÷ÉϽ«Òýµ¼µÄÄÚºËÃû¡£

    ¡¡¡¡rcp ºÍ rsync£º±ØÐëÔÊÐíËüÔÚ¹¹½¨Äں˵ĻúÆ÷ÉÏÔËÐС£

    ÒýÓÃ:
    set -x
    rcp best@sfb: /usr/src/linux-2.4.17/arch/i386/boot/bzImage /boot/bzImage-2.4.17
    rcp best@sfb:/usr/src/linux-2.4.17/System.map /boot/System.map-2.4.17
    rm -rf /lib/modules/2.4.17
    rsync -a best@sfb:/lib/modules/2.4.17 /lib/modules
    chown -R root /lib/modules/2.4.17
    lilo


    ¡¡¡¡Çåµ¥ 7. ÒýÈë²âÊÔ»úÆ÷µÄÄں˺ÍÄ£¿éµÄ½Å±¾