GDB嵌入式调试(以st7162平台为例)

来源:互联网 发布:16詹姆斯数据 编辑:程序博客网 时间:2024/05/16 04:57
目前遇到不少死机问题,缺少调试手段,下面对这种情况作下说明,st7162平台(stlinux)有两种调试手段:
 
一 gdbserver,  较为难用,需在目标板和pc端同时启动相应的程序,且无法调试死机,死机时无法输出堆栈信息
 
二 native gdb(只需在目标板运行) 死机时可打印堆栈信息
    1)/opt/STM/STLinux-2.3/devkit/sh4/target/usr/bin/gdb   将其 copy到目标板 /usr/bin下
  
       2)示例:
调试步骤,死机时可以打印堆栈:
 
 
/test/main对应的测试源码
 
#include <stdio.h>
void fun1()
{
                char *a=0;
        int b=3,c=0;
        printf("string a %s\n",b/c);
}
main()
{
        char *a=0;
        printf("string a\n");
        fun1();
}
 
测试结果:
 gdb
GNU gdb STMicroelectronics/Linux Base 6.5-14 [build Nov  3 2007]
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sh4-linux".
(gdb) file /test/main
Reading symbols from /test/main...done.
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run
Starting program: /test/main 
string a
Unaligned userspace access in "main" pid=352 pc=0x00400506 ins=0x011e
 
Program received signal SIGSEGV, Segmentation fault.  
0x295d87c4 in strlen () from /lib/libc.so.6
(gdb) bt
#0  0x295d87c4 in strlen () from /lib/libc.so.6
#1  0x295b36f2 in vfprintf () from /lib/libc.so.6
Cannot access memory at address 0x7baddf6c
(gdb) 
原创粉丝点击