LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 989|回复: 10

GDB问题

[复制链接]
发表于 2004-11-3 16:19:45 | 显示全部楼层 |阅读模式
我用GDB调程序,得到以下结果:

********************************************************
Program received signal SIGSEGV, Segmentation fault.
0x4056da51 in _int_malloc () from /lib/tls/libc.so.6
********************************************************

我怎样才可以知道错误在哪?编译时已加入-g -Wall选项。

谢谢
发表于 2004-11-3 16:53:00 | 显示全部楼层

bt

分析可能出问题的地方b #line_no
然后s or n
 楼主| 发表于 2004-11-3 17:12:47 | 显示全部楼层
No symbol table info available

编译时,已加了-ggdb 选项
 楼主| 发表于 2004-11-3 17:19:42 | 显示全部楼层
hi, lzlz,

下面是gdb的信息,能帮忙看看,多谢了

Program received signal SIGSEGV, Segmentation fault.
0x4056bd90 in malloc_consolidate () from /lib/tls/libc.so.6
(gdb) bt full
#0  0x4056bd90 in malloc_consolidate () from /lib/tls/libc.so.6
No symbol table info available.
#1  0x00000030 in ?? ()
No symbol table info available.
#2  0x4061d568 in main_arena () from /lib/tls/libc.so.6
No symbol table info available.
#3  0x085b83c8 in ?? ()
No symbol table info available.
#4  0x4061d554 in main_arena () from /lib/tls/libc.so.6
No symbol table info available.
#5  0x4061d538 in main_arena () from /lib/tls/libc.so.6
No symbol table info available.
#6  0x4061d520 in __malloc_initialize_hook () from /lib/tls/libc.so.6
No symbol table info available.
#7  0x4061d520 in __malloc_initialize_hook () from /lib/tls/libc.so.6
No symbol table info available.
#8  0x081369a8 in ?? ()
No symbol table info available.
#9  0xbfffb37c in ?? ()
No symbol table info available.
#10 0x4056db7e in _int_malloc () from /lib/tls/libc.so.6
No symbol table info available.
Previous frame inner to this frame (corrupt stack?)
发表于 2004-11-4 01:52:00 | 显示全部楼层
这些 No symbol table info available 是说 libc,不是你的程序
 楼主| 发表于 2004-11-4 01:56:13 | 显示全部楼层
怎样得到有用的信息?
发表于 2004-11-4 02:12:06 | 显示全部楼层
出现了Segmentation fault.错误,先检查一下你的代码有没有一下错误:

1.Trying to write to a NULL pointer, eg
[PHP]
char *foo = NULL;
strcpy(foo, "bang!");
[/PHP]

2.Using a pointer that has not been initialized, eg
[PHP]
char *foo;
strcpy(foo, "bang!");
[/PHP]  

3.Trying to access past the end of an array, eg
[PHP]
int bar[20];
bar[27] = 6;
[/PHP]

4.Trying to store something in read-only memory, eg
[PHP]
char *foo = "My string";
strcpy(foo, "bang!");
[/PHP]

5.Doing naughty things with malloc() and free(), eg
[PHP]
char bar[80];
free(bar);
[/PHP]
or
[PHP]
char *foo = malloc(27);
free(foo);
free(foo);
[/PHP]
发表于 2004-11-4 09:11:01 | 显示全部楼层
bt后面不用加参数了,但程序异常退出时,bt能打印出最后的函数调用层次,已帮助分析。

编译时指定 -g 就可以了

gdb的相关内容可以找一下帮助
 楼主| 发表于 2004-11-4 16:36:57 | 显示全部楼层
请问在一个子程序中如何初始化数组指针

{
    char *row[19]

    row[0] = somefunction();
    row[1] = somefunction ();
      .
      .
}

以上要运行许多次,我试着把上面的函数不运行,就没有问题。所以感觉问题在于char *row[19]。

另外,我用了 static char *row[19]在子程序中,请问他用不用初始化,如果用,怎么做?

谢谢!!
发表于 2004-11-4 19:30:24 | 显示全部楼层
static char * row[19]; 不用初始化,第一次运行到的时候自动全部初始化为 NULL

问题是不是出在 somefunction 里面?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表