从应用程序在运行时读取调试信息 [英] Read debugging information at runtime from an application

查看:167
本文介绍了从应用程序在运行时读取调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于调试符号,什么可以跟他们做的,再说,还有,调试的一些问题。我在关于GCC的答案大多是感兴趣,但我也很乐意知道它是如何看起来像在其他的编译器,包括MSVC。

首先:


  • 什么是常见的格式/类型的调试符号?

  • 如何它们与编译器和平台?是不是总是在平台间GCC和MinGW相同的格式?

  • 我可以为您在运行时生成是否有他们,什么样的格式是他们?

和一些更实际的问题... 如何


  • 检查当前文件和行号?

  • 获取(合格)函数名被执行?

  • 获得完整当前的堆栈跟踪?

我要强调,我说的是运行时检查。所有这些都可以读取和GDB pretty打,但我不知道有多少信息来自调试符号本身,多少从源头code这GDB也可以访问。

也许有,它能够解析调试符号,并产生这样的信息库?

是标准化的调试符号不够好,我可以期待某种程度的便携性这样的解决方案?


解决方案

  

什么是常见的格式/类型的调试符号?


矮并且刺(那些被嵌入里面的可执行文件,在特殊路段),程序数据库(PDB;外部文件,由MSVC使用)。


  

他们如何涉及到编译器和平台?是不是总是在平台间GCC和MinGW相同的格式?


GCC使用DWARF / STABS(我认为这是一个GCC编译时的选项)都在Linux(ELF)和Windows(PE),不知道其他人。 MSVC总是使用PDB。


  

我可以为您在运行时生成是否有他们,什么样的格式是他们?


您可以分析可执行映像,看看是否有部分与调试信息(见刺文档 DWARF规格的)。 PDB文件分布或者与可执行文件或通过符号服务器(所以如果你不想去上网,检查是否有X.pdb为X.exe / X.dll)。

关于如何阅读和使用这些符号 - 我不知道矮/ STABS(有大概在GNU binutils的东西,可以定位并提取这些),但PDB你最好的选择是使用的dbghelp - 其用法的$p$ptty有据可查并有在网络上提供了大量的例子。还有 DIA人员可用于查询PDB文件


  

是标准化的调试符号不够好,我可以期待某种程度的便携性这样的解决方案?


矮有一个正式的规范,它是复杂得要命。 PDB AFAIK没有记载,但DBGHELP / DIA的,并且是推荐的方式。

I have some questions regarding debugging symbols and what can be done with them, besides, well, debugging. I'm mostly interested in answers regarding GCC, but I'd also be happy to know how it looks like under other compilers, including MSVC.

First of all:

  • What are the common formats/types of debugging symbols?
  • How do they relate to compilers and platforms? Is it always the same format on GCC and MinGW among platforms?
  • Can I check in runtime whether the build has them and what format are they in?

And some more practical questions... How can I:

  • Check the current file and line number?
  • Obtain the (qualified) function name being executed?
  • Obtain a full current stack trace?

Let me emphasize that I'm talking about run-time checks. All of those can be read and pretty-printed by GDB, but I don't know how much info comes from the debugging symbols themselves and how much from the source code which GDB also has access to.

Maybe there's a library which is able to parse the debugging symbols and yield such information?

Are the debugging symbols standardised well enough that I can expect some degree of portability for such solutions?

解决方案

What are the common formats/types of debugging symbols?

DWARF and STABS (those are embedded inside executable, in special sections), Program Database (PDB; external file, used by MSVC).

How do they relate to compilers and platforms? Is it always the same format on GCC and MinGW among platforms?

GCC uses DWARF/STABS (I think it's a GCC compile-time option) both on Linux (ELF) and Windows (PE), don't know about others. MSVC always uses PDB.

Can I check in runtime whether the build has them and what format are they in?

You can parse the executable image and see if there are sections with debugging info (see STABS documentation and DWARF specs). PDB files are distributed either with executables or via symbol servers (so if you don't want to go online, check if there is X.pdb for X.exe/X.dll).

About how to read and use those symbols — I don't know about DWARF/STABS (there's probably something around GNU binutils that can locate and extract those), but for PDB your best bet is to use dbghelp — its usage is pretty well documented and there are a lot of examples available on the net. There's also DIA SDK that can be used to query PDB files.

Are the debugging symbols standardised well enough that I can expect some degree of portability for such solutions?

DWARF has a formal specification, and it's complicated as hell. PDB AFAIK is not documented, but dbghelp/DIA are, and are the recommended way.

这篇关于从应用程序在运行时读取调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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