gdb安裝與遠程調試

   爲了在pc端調試開發板中的程序,需要通過gdb遠程調試來實現,具體步驟如下:

    1、正確安裝arm-linux-gdb

          下載源文件:http://ftp.gnu.org/gnu/gdb/

          解壓:# tar -zxvf gdb-7.6.1.tar.gz 

         進入解壓後的目錄,配置編譯參數:

         # ./configure --target=arm-linux --prefix=/usr/local/arm/4.5.1 

         # make

         # sudo make install

        一定要確保install 否則輸入arm-linux-gdb後會出現找不到該文件。安裝完成後可以找到arm-linux-gdb文件。

            

         也可以通過命令查看是否安裝成功:

         root@width-virtual-machine:/opt/gdb# arm-linux-gdb --version
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

 

    2、gdb調試

        (1)  準備程序如下,程序名爲hello2.c

            #include<stdio.h>
             void main()
             {
                 printf("1111111111111\n");
                 printf("123456789\n");
             }

         

        (2) 編譯程序:

        

       (3) 從開發板運行程序

            首先安裝好gdbserver,並將gdbserver拷貝到運行程序所在的目錄。

            從開發板掛載虛擬機中的目錄,

           掛載前:

           

          掛載後:

          

                 ip:192.168.0.2爲pc端的ip地址。

          進入運行文件所在文件夾:

          

         運行開發板端程序:

         

         PC端進行調試:

        

       連接開發板:

           輸入:target remote 192.168.0.7:2345 

           其中開發板ip爲:192.168.0.7, 另外要保證開發板啓動時的端口號與PC調試時的端口號一致。

       

    開始調試:

    (gdb) list
Cannot access memory at address 0x0
1 #include<stdio.h>
2 void main()
3 {
4    printf("1111111111111\n");
5   printf("123456789\n");
6 }
(gdb) c

    運行結果爲:

    /mnt/hello # ./gdbserver 192.168.0.2:2345 hello2
Process hello2 created; pid = 1084
Listening on port 2345
Remote debugging from host 192.168.0.2
1111111111111
123456789

Child exited with status 10
GDBserver exiting
/mnt/hello # 

 

    3、ddd調試

        (1)  先安裝好ddd軟件;

        (2)  開發板端啓動和前面是一樣的;

        (3)  以debug方式啓動ddd軟件

             

             一定要記得加中間的參數:-debugger , 否則圖像框中就沒有辦法進行單步調試。

             ddd啓動時的路徑應該爲源文件所在目錄,否則可能找不到程序,啓動後界面爲:

            

            在最下面輸入框(gdb)後面輸入連接開發板的命令,格式和gdb調試時一樣,如下:

        

         退出ddd軟件:

        (gdb)q

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章