我使用的是Solaris 10,我的C程序崩溃并创建了一个核心文件。在调试时,似乎核心是在libc.so.1中创建的。如果有人有任何线索,请告诉我。 以下是dbx报告。
dbx prock.new core
For information about new features see `help changes'
To remove this message, put `dbxenv suppress_startup_message 7.6' in your .dbxrc
Reading prock.new
core file header read successfully
Reading ld.so.1
Reading libsocket.so.1
Reading libnsl.so.1
Reading libl.so.1
Reading libpthread.so.1
Reading librt.so.1
Reading libthread.so.1
Reading libc.so.1
Reading libaio.so.1
Reading libmd.so.1
Reading libc_psr.so.1
WARNING!!
A loadobject was found with an unexpected checksum value.
See `help core mismatch' for details, and run `proc -map'
to see what checksum values were expected and found.
dbx: warning: Some symbolic information might be incorrect.
t@null (l@1) terminated by signal SEGV (no mapping at the fault address)
0xffffffff7ea3bc14: strcasecmp+0x0134: orn %i0, %i3, %i0
(dbx) where
=>[1] strcasecmp(0x10014b68e, 0x57, 0x7ffffc00, 0x1001332d7, 0x27, 0x24), at 0xffffffff7ea3bc14
[2] 0x10000af48(0x27, 0x10014b68e, 0x57, 0x10014b68e, 0x57, 0x0), at 0x10000af48
[3] 0x100009c08(0x27, 0x5e, 0x0, 0x9, 0x1001332c3, 0x2b), at 0x100009c08
(dbx) whereis strcasecmp
function: `libc.so.1`strcasecmp
(dbx)
我的solaris版本是
Solaris 10 8/07 s10s_u4wos_12b SPARC
Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 16 August 2007
答案 0 :(得分:2)
不,问题不在于C标准库。您将无效参数(空字符串指针等)传递给strcasecmp()
。如果没有实际代码(您尚未发布),则无法推断出错误究竟是什么。
(另外,你最好用调试符号编译你的程序 - 关闭优化!如果你在Solaris上,你最有可能使用GCC:
gcc -O0 -g etc...
)
答案 1 :(得分:1)
1)编译程序以包含调试信息(将“-g”添加到编译器的选项列表中),以便实际获取信息而不是:
[2] 0x10000af48(0x27, 0x10014b68e, 0x57, 0x10014b68e, 0x57, 0x0), at 0x10000af48
[3] 0x100009c08(0x27, 0x5e, 0x0, 0x9, 0x1001332c3, 0x2b), at 0x100009c08
2)DBX现在会告诉你哪些功能正在调用 strcasecmp
。逐步执行源代码(或让它生成日志输出),检查致命函数调用的参数是否有异常(如无效指针)。
与您调用该函数的错误机会相比,您发现libc函数中的错误的可能性是无穷小的。
答案 2 :(得分:0)
1)运行bt(backtrace)以查看谁正在调用strcasecmp [这将列出#0,#1等帧]
2)现在跳转到特定帧以获取值[frame 0]
3)然后显示/打印传递给strcasecmp的参数值(使用print或display)
我觉得调用strcasecmp时参数为NULL,这就是你遇到段错误的原因。