在 Mac OSX 中读取 DWARF 文件

发布于 2024-07-18 06:05:01 字数 54 浏览 1 评论 0原文

任何人都可以帮我编写一个可以读取 DWARF 文件并提供文件名、行号和函数名称详细信息的程序。

Can anybody help me writing a program which can read DWARF files and gives me the file name, line number and function name details.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔女人霸气范 2024-07-25 06:05:01

DWARF-2 和 DWARF-2 的规范 DWARF-3 在这里:

http://dwarfstd.org/dwarf-2.0.0.pdf< /a>

http://dwarfstd.org/Dwarf3.pdf

有一个不错的阅读 DWARF 的库文件在这里:

http://reality.sgiweb.org/davea/dwarf.html

您可以获取并使用该库来读取 DWARF 文件(它读取 DWARF-2 和 DWARF-3),或者您可以查看源代码来弄清楚如何编写自己的一组库/函数来执行以下操作工作。

The specification for DWARF-2 & DWARF-3 is here:

http://dwarfstd.org/dwarf-2.0.0.pdf

http://dwarfstd.org/Dwarf3.pdf

There is a decent library for reading DWARF files here:

http://reality.sgiweb.org/davea/dwarf.html

You can either get and use that library to read your DWARF files (it reads DWARF-2 and DWARF-3) or you can take a look at the source code to puzzle out how to write your own set of libraries/functions to do the job.

苹果你个爱泡泡 2024-07-25 06:05:01

你可以看看 binutils 中的 avr-readelf 。 binutils/dwarf.c 中的 display_debug_lines() 函数负责解码 DWARF 行号信息。

另外,正如上面所建议的,您可以使用 libdwarf。 这很好地隐藏了 DWARF 的低级复杂性,让您专注于获取数据。

使用 elfdescriptor 设置 libdwarf 并获取 Dwarf_Debug 结构后,您可以执行以下操作:

  1. 使用dwarf_srclines() 遍历所有编译单元
  2. 在每个 cu 上使用 dwarf_srclines()
  3. 在从 dwarf_srclines() 返回的数组中的每个条目上使用 dwarf_lineaddr()
  4. 记住在正确的地方使用 dwarf_dealloc() 。

You could have a look at avr-readelf in binutils. The display_debug_lines() function in binutils/dwarf.c does the job of decoding the DWARF linenumber information.

Also, as suggested above, you could use libdwarf. This does a nice job of hiding the low-level complexities of DWARF and lets you focus on getting the data out.

After setting up libdwarf with an elfdescriptor and getting a Dwarf_Debug struct, you can do the following:

  1. Traverse all compilation units with dwarf_srclines()
  2. use dwarf_srclines() on each cu
  3. use dwarf_lineaddr() on each entry in the array returned from dwarf_srclines()
  4. remember to use dwarf_dealloc() in the right places.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文