GCC - 为调试符号中的#includes生成绝对路径 [英] GCC - generate absolute paths for #includes in debug symbols

查看:300
本文介绍了GCC - 为调试符号中的#includes生成绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OS是Windows,GCC是4.7.2,GDB是7.3。



我在C:/ project / src /文件夹中有一个.c文件,包括:

  #include../inc/header.h

编译后,我在调试符号中有一个相对路径:

 > objdump -WL obj.o | grep header.h 
C:/ project / src /../inc/ header.h
...

然而我希望它是C:/project/inc/header.h,因为如果我在发出set breakpoint命令时使用绝对路径,那么在gdb中设置BP会失败。



这种情况很模糊,但由于环境条件的原因,唯一的解决办法是在调试符号中生成绝对路径,或者教GDB解析相对路径。



是否有一个开关让GCC打开调试符号中的绝对路径生成?

解决方案

解决方案在GDB中,而不是GCC。

最简单的方法是将包含标题的目录添加到搜索路径中:

 (gdb)directory / path / to / include / 

您可能需要的更复杂的是路径名替换规则:

 (gdb)set substitute -path ../inc / path / to / inc 


OS is Windows, GCC is 4.7.2, GDB is 7.3.

I have a .c file in the C:/project/src/ folder with an include:

#include "../inc/header.h"

After the compilation I have a relative path in the debug symbols:

> objdump -WL obj.o | grep header.h
C:/project/src/../inc/header.h
...

Yet I want it to be C:/project/inc/header.h, because setting BPs in gdb fail for me if I use absolute paths when issuing the set breakpoint command.

This situation is artificial, but due to the environmental conditions the only solution to my issue will be either absolute paths generation in the debug symbols or teaching GDB to resolve relative paths.

Is there a switch for GCC to turn on the absolute path generation in the debug symbols?

解决方案

The solution is in GDB, not GCC.

The easiest way is to add the directory containing the header to the search path:

(gdb) directory /path/to/include/

A more complicated one that you might need is pathname substitution rules:

(gdb) set substitute-path ../inc /path/to/inc

这篇关于GCC - 为调试符号中的#includes生成绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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