链接时调试符号丢失? [英] Debugging Symbols Lost When Linking?

查看:165
本文介绍了链接时调试符号丢失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用调试符号编译程序,以便valgrind将给我行数字。我发现如果我一次编译一个简单的测试程序(用-g),那么它包含符号。但是,如果我编译两遍(即编译然后链接),那么它不包含调试符号。



以下是单程通用的编译命令:

  g ++ -g file.c -o file 

两次通过

  g ++ -g -c file.c -o file.o 
g ++ -g file.o -o file

实际的程序看起来像这样,包含一个简单的无效写入

  int main(){
int * x = new int [10];
x [10] = 1;

}



如果我用一个编译通过,然后valgrind给出以下(注意末尾的行号)

  == 24114 == 1个块中的40个字节是绝对丢失损失记录2 of 9 
== 24114 == at 0xB823:malloc(vg_replace_malloc.c:266)
== 24114 == by 0x5768D:operator new(unsigned long)(in / usr /lib/libstdc++.6.0.9.dylib)
== 24114 == by 0x576DA:operator new [](unsigned long)(in /usr/lib/libstdc++.6.0.9.dylib)
== 24114 == 0x100000F09:main(file.c:3)

而如果我编译两次通过我得到这个(没有行号):

  == 24135 == 1块中的40个字节绝对丢失损失记录2 of 9 
== 24135 == at 0xB823:malloc(vg_replace_malloc.c:266)
== 24135 == by 0x5768D:operator new(unsigned long)(in / usr / lib / libstdc ++ 6.0.9.dylib)
== 24135 == by 0x576DA:operator new [](unsigned long)(in /usr/lib/libstdc++.6.0.9.d ylib)
== 24135 == by 0x100000F09:main(in ./file)

对此的任何见解都将不胜感激。我在OS X上使用gcc 4.2.1版10.7.3

解决方案

只是为了将这个问题标记为回答(so它不是不必要地打开并被其他人阅读)



=>
答案是从user1288111到最初的问题的评论。


I'm trying to compile a program with debugging symbols so that valgrind will give me line numbers. I have found that if I compile a simple test program in one go (with -g) then it contains the symbols. However, if I compile in two passes (i.e. compile then link) then it does not contain the debugging symbols.

Here's the compile command for the single pass case:

g++ -g file.c -o file

And for two passes

g++ -g -c file.c -o file.o
g++ -g file.o -o file

The actual program looks like this and contains a simple Invalid Write

int main(){
    int* x = new int[10];
    x[10]=1;

}

If I compile with one pass then valgrind gives the following (note the line number at the end)

==24114== 40 bytes in 1 blocks are definitely lost in loss record 2 of 9
==24114==    at 0xB823: malloc (vg_replace_malloc.c:266)
==24114==    by 0x5768D: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==24114==    by 0x576DA: operator new[](unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==24114==    by 0x100000F09: main (file.c:3)

whereas if I compile in two passes I get this (with no line number):

==24135== 40 bytes in 1 blocks are definitely lost in loss record 2 of 9
==24135==    at 0xB823: malloc (vg_replace_malloc.c:266)
==24135==    by 0x5768D: operator new(unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==24135==    by 0x576DA: operator new[](unsigned long) (in /usr/lib/libstdc++.6.0.9.dylib)
==24135==    by 0x100000F09: main (in ./file)

Any insight on this would be much appreciated. I am using gcc version 4.2.1 on OS X 10.7.3

解决方案

Just for marking this question as "answered" (so it's not needlessly opened and read by others).

=> Answer is found as the comment from "user1288111" to the initial question.

这篇关于链接时调试符号丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆