LinuxÏÂʹÓÃGDBµ÷ÊÔǶÈëʽARM»ã±à³ÌÐòµÄ³£¼ûÉèÖÃÒªÁì
linuxÏÂʹÓÃgdbµ÷ÊÔǶÈëʽarm»ã±à³ÌÐòµÄ³£¼ûÉèÖÃÒªÁì
ͻ񻣼
ÔÚǶÈëʽϵͳ¿ª·¢ÖУ¬ARM¼Ü¹¹µÄ´¦Öóͷ£Æ÷ÆÕ±éÓ¦ÓÃÓÚ¸÷¸öÁìÓò¡£ÎªÁ˵÷ÊÔǶÈëʽARM»ã±à³ÌÐò£¬ÎÒÃÇ¿ÉÒÔʹÓÃGNUµ÷ÊÔÆ÷£¨GDB£©¡£±¾ÎĽ«ÏÈÈÝÔÚLinuxÇéÐÎÏÂÉèÖÃGDBÀ´µ÷ÊÔǶÈëʽARM»ã±à³ÌÐòµÄ³£¼ûÒªÁ죬²¢Ìṩ´úÂëʾÀý¡£
×°ÖÃGDBºÍARM½»Ö¯±àÒ빤¾ßÁ´
ÔÚ×îÏÈ֮ǰ£¬ÎÒÃÇÐèÒªÔÚLinuxϵͳÉÏ×°ÖÃGDBºÍARM½»Ö¯±àÒ빤¾ßÁ´¡£¿ÉÒÔͨ¹ý°ü¹ÜÀíÆ÷£¨Èçapt£©»òÕß´Ó¹Ù·½ÍøÕ¾ÏÂÔؾÙÐÐ×°Öá£
±àдǶÈëʽARM»ã±à³ÌÐò
Ê×ÏÈ£¬ÎÒÃÇÐèÒª±àдһ¸ö¼òÆÓµÄǶÈëʽARM»ã±à³ÌÐò£¬ÒÔ¹©ºóÐøµ÷ÊÔ¡£ÏÂÃæÊÇÒ»¸öʾÀý³ÌÐò£º
.global _start .extern printf .section .data message: .asciz "Hello, World! " .section .text _start: ldr r0, =message bl printf mov r7, #1 swi 0
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÊ×ÏȽç˵ÁËÈ«¾Ö±êºÅ _start ºÍÍⲿº¯Êý printf¡£È»ºó£¬.data ¶ÎÖнç˵ÁËÒ»¸ö×Ö·û´® message£¬.text ¶ÎÖÐʹÓà ldr ºÍ bl Ö¸ÁîʵÏÖÁË×Ö·û´®µÄÊä³ö¡£×îºóÁ½ÐдúÂëʹÓà mov ºÍ swi Ö¸ÁîÍ˳ö³ÌÐò¡£
ʹÓÃARM½»Ö¯±àÒ빤¾ßÁ´¾ÙÐбàÒë
ʹÓÃARM½»Ö¯±àÒ빤¾ßÁ´½«ÉÏÊö»ã±à³ÌÐò±àÒëΪ¿ÉÖ´ÐÐÎļþ¡£¼ÙÉè½»Ö¯±àÒ빤¾ßÁ´µÄǰ׺Ϊ arm-none-eabi-£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐбàÒ룺
$ arm-none-eabi-as -mcpu=cortex-m3 -o program.o program.s $ arm-none-eabi-ld -o program program.o
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬-mcpu=cortex-m3 Ö¸¶¨ÁËÄ¿µÄ´¦Öóͷ£Æ÷µÄÀàÐÍ¡£
ÉèÖÃGDB
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÉèÖÃGDBÀ´µ÷ÊÔ±àÒëÌìÉúµÄ¿ÉÖ´ÐÐÎļþ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÆô¶¯GDB£º
$ gdb
µÇ¼ºó¸´ÖÆ
È»ºó£¬Ê¹ÓÃÒÔÏÂÏÂÁ¿ÉÖ´ÐÐÎļþ¼ÓÔص½GDBÖУº
(gdb) file program
µÇ¼ºó¸´ÖÆ
ÉèÖÃGDBµÄÄ¿µÄ×°±¸
ÎÒÃÇ»¹ÐèÒªÉèÖÃGDBÅþÁ¬µ½Ä¿µÄ×°±¸£¬ÒÔ±ã¾ÙÐе÷ÊÔ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÉèÖÃÅþÁ¬Æ÷²ÎÊý£º
(gdb) target remote localhost:1234
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬localhost:1234 ÊÇÄ¿µÄ×°±¸µÄÅþÁ¬µØµãºÍ¶Ë¿ÚºÅ¡£ÕâÀï¼ÙÉèʹÓÃÁ˵±ÌïÖ÷»úºÍĬÈ϶˿ںÅ1234¡£
µ÷ÊÔ»ã±à³ÌÐò
ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔ×îÏȵ÷ÊÔ»ã±à³ÌÐòÁË¡£ÒÔÏÂÊÇһЩ³£ÓõÄGDBµ÷ÊÔÏÂÁîʾÀý£º
¹Û²ì¼Ä´æÆ÷µÄÖµ£º
(gdb) info registers
µÇ¼ºó¸´ÖÆ
µ¥²½Ö´ÐгÌÐò£º
(gdb) step
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÍêÄ¿½ñº¯ÊýµÄÊ£Óಿ·Ö£º
(gdb) next
µÇ¼ºó¸´ÖÆ
ÉèÖöϵ㣺
(gdb) break main
µÇ¼ºó¸´ÖÆ
¼ÌÐøÖ´ÐгÌÐò£º
(gdb) continue
µÇ¼ºó¸´ÖÆ
Éó²éÄÚ´æÄÚÈÝ£º
(gdb) x/16x $sp
µÇ¼ºó¸´ÖÆ
´òÓ¡±äÁ¿Öµ£º
(gdb) print $r0
µÇ¼ºó¸´ÖÆ
Éó²éÔ´´úÂ룺
(gdb) list
µÇ¼ºó¸´ÖÆ
¿¢Êµ÷ÊԻỰ
µ±ÎÒÃÇÍê³ÉÁ˶ԳÌÐòµÄµ÷ÊԺ󣬿ÉÒÔʹÓÃÒÔÏÂÏÂÁʵ÷ÊԻỰ£º
(gdb) quit
µÇ¼ºó¸´ÖÆ
½áÂÛ£º
±¾ÎÄÏÈÈÝÁËÔÚLinuxÇéÐÎÏÂʹÓÃGDBµ÷ÊÔǶÈëʽARM»ã±à³ÌÐòµÄ³£¼ûÉèÖÃÒªÁì¡£Ê×ÏÈ£¬ÎÒÃÇ×°ÖÃÁËGDBºÍARM½»Ö¯±àÒ빤¾ßÁ´¡£È»ºó£¬±àдÁËÒ»¸ö¼òÆÓµÄǶÈëʽARM»ã±à³ÌÐò£¬²¢Ê¹ÓÃARM½»Ö¯±àÒ빤¾ßÁ´¾ÙÐбàÒë¡£½ÓÏÂÀ´£¬ÎÒÃÇÉèÖÃÁËGDB²¢ÅþÁ¬µ½Ä¿µÄ×°±¸¡£×îºó£¬ÎÒÃÇʹÓÃGDBµÄÖÖÖÖµ÷ÊÔÏÂÁî¶Ô»ã±à³ÌÐò¾ÙÐÐÁ˵÷ÊÔ¡£Í¨¹ýÉèÖÃGDB£¬ÎÒÃÇ¿ÉÒÔÀû±ãµØµ÷ÊÔǶÈëʽARM»ã±à³ÌÐò£¬¼ÓËÙ¿ª·¢µÄЧÂÊ¡£
²Î¿¼×ÊÁÏ£º
https://sourceware.org/gdb/onlinedocs/gdb/
https://gcc.gnu.org/onlinedocs/
https://www.keil.com/support/man/docs/armclang_intro/armclang_intro_dom1361289859837.htm
ÒÔÉϾÍÊÇLinuxÏÂʹÓÃGDBµ÷ÊÔǶÈëʽARM»ã±à³ÌÐòµÄ³£¼ûÉèÖÃÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡