尊龙凯时人生就是搏

ʹÓÃGDBµ÷ÊÔLinuxÄں˵ij£ÓÃÉèÖü¼ÇÉ

ʹÓÃgdbµ÷ÊÔlinuxÄں˵ij£ÓÃÉèÖü¼ÇÉ

СÐò£º

ÔÚLinux¿ª·¢ÖÐ £¬Ê¹ÓÃGDBµ÷ÊÔÄÚºËÊÇÒ»ÏîºÜÊÇÖ÷ÒªµÄÊÖÒÕ¡£GDBÊÇÒ»¿î¹¦Ð§Ç¿Ê¢µÄµ÷ÊÔ¹¤¾ß £¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¶¨Î»Ï¢Õù¾öÄÚºËÖеÄbug¡£±¾ÎĽ«ÏÈÈÝһЩ³£ÓõÄGDBÉèÖü¼ÇÉ £¬ÒÔ¼°ÔõÑùʹÓÃGDBµ÷ÊÔLinuxÄںˡ£

Ò»¡¢ÉèÖÃGDBÇéÐÎ

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚLinuxϵͳÉÏÉèÖÃGDBµÄÇéÐΡ£ÇëÈ·±£ÄãµÄϵͳÒѾ­×°ÖÃÁËGDB¹¤¾ß¡£ÈôÊÇûÓÐ×°Öà £¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°Öãº

$ sudo apt-get install gdb

¶þ¡¢±àÒëÄÚºË

ÔÚʹÓÃGDBµ÷ÊÔÄÚºË֮ǰ £¬Ê×ÏÈÐèÒª±àÒëÄÚºË £¬²¢ÌìÉúµ÷ÊÔÐÅÏ¢¡£

ÏÂÔØÄÚºËÔ´Âë

ͨ¹ýGit»òÕß¹Ù·½ÍøÕ¾ÏÂÔØÏëÒªµ÷ÊÔµÄÄÚºËÔ´Âë¡£

ÉèÖÃÄÚºË

½øÈëÄÚºËÔ´ÂëĿ¼ £¬²¢Ö´ÐÐmake menuconfigÏÂÁîÀ´ÉèÖÃÄںˡ£ÔÚÕâÀï £¬ÎÒÃÇÐèÒªÆôÓÃһЩµ÷ÊÔÑ¡Ïî¡ £¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´ÆôÓõ÷ÊÔÑ¡Ï

$ make menuconfig

ÔÚÉèÖýçÃæÖÐÕÒµ½ÒÔÏÂÑ¡Ïî £¬²¢¾ÙÐÐÆôÓãº

Kernel hacking -> Kernel debugging -> GDB/KDB -> Enable KGDB/KDB Support

Kernel hacking -> Compile-time checks and compiler options -> Compile the kernel with debug info

ÉúÑIJ¢Í˳öÉèÖýçÃæ¡£

±àÒëÄÚºË

Ö´ÐÐÒÔÏÂÏÂÁîÀ´±àÒëÄںˣº

$ make

±àÒëÍê³Éºó £¬»áÔÚÔ´ÂëĿ¼ÏÂÌìÉúvmlinuzºÍvmlinuxÎļþ¡£

Èý¡¢ÉèÖÃÄÚºËÆô¶¯²ÎÊý

ÔÚʹÓÃGDBµ÷ÊÔÄÚºË֮ǰ £¬ÎÒÃÇ»¹ÐèÒªÔÚÄÚºËÆô¶¯Ê±Ìí¼ÓһЩ²ÎÊý¡£

ÐÞ¸ÄGRUBÎļþ

·­¿ªGRUBÎļþ £¬²¢ÕÒµ½”default”±äÁ¿¡£½«ÆäÖµÐÞ¸ÄΪËùÖ§³ÖµÄÄں˰汾¡£ÀýÈ磺

default=0

ÉúÑIJ¢Í˳ö¡£

Ìí¼Óµ÷ÊÔ²ÎÊý

ÔÚGRUBÎļþÖÐÕÒµ½ËùÑ¡Ôñ°æ±¾µÄ”linux”ÐÐ £¬²¢ÔÚÆäĩβÌí¼Óµ÷ÊÔ²ÎÊý¡£ÀýÈ磺

linux /boot/vmlinuz-5.4.0-74-generic root=/dev/sda1 ro debug

ÉúÑIJ¢Í˳ö¡£

¸üÐÂGRUBÉèÖÃ

Ö´ÐÐÒÔÏÂÏÂÁîÀ´¸üÐÂGRUBÉèÖãº

$ sudo update-grub

ËÄ¡¢Ê¹ÓÃGDBµ÷ÊÔÄÚºË

ÏÖÔÚ £¬ÉèÖÃÒѾ­Íê³É £¬ÎÒÃÇ¿ÉÒÔʹÓÃGDBÀ´µ÷ÊÔLinuxÄÚºËÁË¡£

Æô¶¯GDB

·­¿ªÖÕ¶Ë £¬²¢Ö´ÐÐÒÔÏÂÏÂÁîÀ´Æô¶¯GDB£º

$ gdb vmlinux

ÉèÖÃGDB

ÔÚGDBÖÐ £¬ÎÒÃÇÐèÒª×öһЩÌØÁíÍâÉèÖá£Ö´ÐÐÒÔÏÂÏÂÁîÀ´ÉèÖÃGDB£º

É趨µ÷ÊÔÄ¿µÄ£º

(gdb) target remote :1234

É趨µ÷ÊÔ·ûºÅÎļþ£º

(gdb) symbol-file vmlinux

ÉèÖöϵ㣺

(gdb) break main

ÉúÑIJ¢Í˳ö¡£

Æô¶¯µ÷ÊԻỰ

Ö´ÐÐÒÔÏÂÏÂÁîÀ´Æô¶¯µ÷ÊԻỰ£º

(gdb) continue

´Ëʱ £¬GDB½«»áÅþÁ¬µ½Äں˵÷ÊÔÆ÷ £¬²¢ÔÚmainº¯Êý´¦×èÖ¹Ö´ÐС£

¾ÙÐе÷ÊÔ

ʹÓÃGDBÌṩµÄÖÖÖÖÏÂÁîºÍµ÷ÊÔ¼¼ÇÉ £¬ÀýÈçÉó²é±äÁ¿Öµ¡¢Ð޸ıäÁ¿Öµ¡¢Éó²éº¯ÊýŲÓÿÍÕ»µÈ £¬À´¶¨Î»Ï¢Õù¾öÄÚºËÖеÄbug¡£

ÀýÈç £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Éó²é±äÁ¿µÄÖµ£º

(gdb) print my_variable

¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Ð޸ıäÁ¿µÄÖµ£º

(gdb) set var my_variable = 123

Îå¡¢×ܽá

±¾ÎÄÏÈÈÝÁËʹÓÃgdbµ÷ÊÔlinuxÄں˵ij£ÓÃÉèÖü¼ÇÉ¡£Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚϵͳÉÏÉèÖÃGDBÇéÐÎ £¬²¢±àÒëÄںˡ£È»ºó £¬Í¨¹ýÌí¼Óµ÷ÊÔ²ÎÊýÀ´ÉèÖÃÄÚºËÆô¶¯²ÎÊý¡£×îºó £¬Ê¹ÓÃGDBÀ´µ÷ÊÔÄÚºË £¬²¢Í¨¹ýʹÓÃGDBÌṩµÄÖÖÖÖÏÂÁîºÍµ÷ÊÔ¼¼ÇÉ £¬À´¶¨Î»Ï¢Õù¾öÄÚºËÖеÄbug¡£Í¨¹ýÕÆÎÕÕâЩ¼¼ÇÉ £¬¿ª·¢Õß¿ÉÒÔÔ½·¢¸ßЧµØ¾ÙÐÐÄں˵÷ÊԺͿª·¢ÊÂÇé¡£

ÒÔÉϾÍÊÇʹÓÃGDBµ÷ÊÔLinuxÄں˵ij£ÓÃÉèÖü¼ÇɵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ