LinuxÏÂʹÓÃGDBµ÷ÊÔǶÈëʽARM³ÌÐòµÄ³£¼ûÉèÖÃÒªÁì
linuxÏÂʹÓÃgdbµ÷ÊÔǶÈëʽarm³ÌÐòµÄ³£¼ûÉèÖÃÒªÁì
ǶÈëʽϵͳ×÷ΪһÖÖÌØÊâµÄÅÌËã»úϵͳ£¬Í¨³£¼¯³ÉÔÚµç×Ó×°±¸ÖУ¬ÓÃÓÚ¿ØÖƺÍÖÎÀíÓ²¼þ×ÊÔ´¡£ÎªÁ˵÷ÊÔºÍÆÊÎöǶÈëʽϵͳµÄÔËÐÐ״̬£¬ÎÒÃÇÐèҪʹÓÃרÃŵŤ¾ß¡£ÆäÖУ¬GDBÊÇÒ»ÖÖ³£ÓõĿªÔ´µ÷ÊÔÆ÷£¬ËüÄܹ»ÔÚǶÈëʽϵͳÉÏÔËÐв¢Óë³ÌÐò¾ÙÐÐͨѶ¡£±¾ÎĽ«ÏÈÈÝÔÚlinuxÏÂʹÓÃgdbµ÷ÊÔǶÈëʽarm³ÌÐòµÄ³£¼ûÉèÖÃÒªÁ죬²¢¸ø³ö´úÂëʾÀý¡£
×°ÖÃÐëÒªµÄÈí¼þºÍ¹¤¾ß
ÔÚ×îÏÈ֮ǰ£¬ÎÒÃÇÐèҪװÖÃһЩÐëÒªµÄÈí¼þºÍ¹¤¾ß¡£Ê×ÏÈ£¬È·±£LinuxϵͳÖÐÒѾװÖÃÁËGCC¹¤¾ßÁ´£¬ÓÃÓÚ±àÒëARM³ÌÐò¡£½ÓÏÂÀ´£¬Ê¹ÓÃÒÔÏÂÏÂÁî×°ÖÃGDBµ÷ÊÔÆ÷£º
sudo apt-get install gdb-multiarch
µÇ¼ºó¸´ÖÆ
±àÒëǶÈëʽARM³ÌÐò
ÔÚ¾ÙÐе÷ÊÔ֮ǰ£¬ÎÒÃÇÐèÒªÏȱàÒëÒ»¸ö¼òÆÓµÄǶÈëʽARM³ÌÐò¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý³ÌÐò£¬ÓÃÓÚÅÌËãÁ½¸öÊýµÄºÍ£º
#include <stdio.h> int main() { int a = 5; int b = 10; int sum = a + b; printf("Sum: %d ", sum); return 0; }
µÇ¼ºó¸´ÖÆ
ÉúÑÄÒÔÉÏ´úÂëΪsum.cÎļþ¡£
ʹÓÃÒÔÏÂÏÂÁî±àÒë¸Ã³ÌÐò£º
arm-linux-gnueabi-gcc -o sum sum.c
µÇ¼ºó¸´ÖÆ
±àÒëÍê³Éºó£¬½«ÔÚÄ¿½ñĿ¼ÏÂÌìÉúÒ»¸öÃûΪsumµÄ¿ÉÖ´ÐÐÎļþ¡£
ÅþÁ¬Ç¶ÈëʽARM×°±¸
½«Ç¶ÈëʽARM×°±¸ÅþÁ¬µ½LinuxÖ÷»ú¡£Ê¹ÓÃUSBÏßÀÂÅþÁ¬Á½Õߣ¬²¢È·±£×°±¸´¦ÓÚµ÷ÊÔģʽÏ¡£
Æô¶¯GDBµ÷ÊÔÆ÷
ÔÚLinuxÖ÷»úÉÏÆô¶¯GDBµ÷ÊÔÆ÷£¬²¢Ê¹ÓÃÒÔÏÂÏÂÁî·¿ª¿ÉÖ´ÐÐÎļþ£º
gdb-multiarch sum
µÇ¼ºó¸´ÖÆ
´Ëʱ£¬GDB»áÏÔʾһ¸öÏÂÁîÐнçÃ棬ÆÚ´ýÊäÈëµ÷ÊÔÖ¸Áî¡£
ÉèÖÃGDBÅþÁ¬
ÔÚGDBÏÂÁîÐнçÃæÖУ¬ÊäÈëÒÔÏÂÏÂÁîÉèÖÃGDBÅþÁ¬µ½Ç¶ÈëʽARM×°±¸£º
target remote :8888
µÇ¼ºó¸´ÖÆ
ÕâÀïµÄ8888ÊÇÉè±¹ØÁ¬ÄGDBЧÀÍÆ÷¼àÌý¶Ë¿ÚºÅ¡£Çë×¢ÖØ£¬ÏêϸµÄ¶Ë¿ÚºÅ¿ÉÄÜÒò×°±¸¶øÒ죬ÐèҪƾ֤ÏÖÕæÏàÐξÙÐе÷½â¡£
ÉèÖöϵã
ÔÚGDBÏÂÁîÐнçÃæÖУ¬ÊäÈëÒÔÏÂÏÂÁîÉèÖöϵ㣺
break main
µÇ¼ºó¸´ÖÆ
Õ⽫ÔÚ³ÌÐòµÄmainº¯ÊýÖÐÉèÖÃÒ»¸ö¶Ïµã£¬ÒÔ±ãÔÚ³ÌÐòÖ´Ðе½¸Ãº¯ÊýʱÔÝÍ£¡£
×îÏȵ÷ÊÔ
ÊäÈëÒÔÏÂÏÂÁî×îÏȵ÷ÊÔ£º
continue
µÇ¼ºó¸´ÖÆ
Õ⽫ʹ³ÌÐò×îÏÈÖ´ÐУ¬²¢ÔÚÓöµ½¶Ïµãʱ×èÖ¹¡£
µ÷ÊÔÀú³Ì
ÔÚ³ÌÐò×èÖ¹Ö´ÐÐʱ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐе÷ÊÔ£º
next£ºÖ´ÐÐÏÂÒ»ÐдúÂë
step£º½øÈ뺯ÊýÄÚ²¿
list£ºÏÔʾԴ´úÂë
print£º´òÓ¡±äÁ¿Öµ
watch£º¼àÊÓ±äÁ¿Öµ×ª±ä
continue£º¼ÌÐø³ÌÐòÖ´ÐÐ
quit£ÎÂ˳öGDBµ÷ÊÔÆ÷
ÒÔ´ËÀàÍÆ¡£
¿¢Êµ÷ÊÔ
µ±µ÷ÊÔÍê³Éʱ£¬¿ÉÒÔÊäÈëÒÔÏÂÏÂÁîÍ˳öGDBµ÷ÊÔÆ÷£º
quit
µÇ¼ºó¸´ÖÆ
±¾ÎÄÏÈÈÝÁËÔÚlinuxÏÂʹÓÃgdbµ÷ÊÔǶÈëʽarm³ÌÐòµÄ³£¼ûÉèÖÃÒªÁ죬²¢ÌṩÁ˼òÆӵĴúÂëʾÀý¡£Ï£Íûͨ¹ý±¾ÎĵÄÏÈÈÝ£¬¶ÁÕßÄܹ»ÏàʶÔõÑùʹÓÃGDBÔÚLinuxÇéÐÎϵ÷ÊÔǶÈëʽARM³ÌÐò£¬ÒÔ¸üºÃµØÆÊÎöºÍµ÷ÊÔǶÈëʽϵͳµÄÔËÐÐ״̬¡£
ÒÔÉϾÍÊÇLinuxÏÂʹÓÃGDBµ÷ÊÔǶÈëʽARM³ÌÐòµÄ³£¼ûÉèÖÃÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡