将程序的源代码嵌入到使用GCC的GCC二进制文件中 [英] Embedding a program's source code into its binary using GCC for GDB's later use

查看:385
本文介绍了将程序的源代码嵌入到使用GCC的GCC二进制文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我厌倦了让我的源代码保持原样,直到我通过调试。任何时候我更改代码,GDB开始抱怨:

I'm getting tired of having to keep my source code untouched until I'm through with its debugging. Any time I change my code, GDB starts complaining about it:


警告:源文件比可执行文件更新。

warning: Source file is more recent than executable.

,直到我重新编译,这不能总是快速完成。我认为如果可以将程序的源代码包含在其二进制文件中,并使GDB使用它而不是其最新版本,那将是非常好的。

until I recompile it, which can not always be done quickly. I think it would be great if it was possible to include a program's source code into its binary and to make GDB use it instead of its up-to-date version.

有人可以建议一个怎么做的方法吗?这是否已经实现?

Could anyone suggest a way how to do it? Has this been implemented at all?

推荐答案

GCC是开源的 - 你可以修复它。当然,您可能需要修改LD来正确处理信息,并且肯定需要修复GDB才能使用嵌入式源代码。您将使用非标准格式的调试信息,因此您可能需要修改其他可以处理对象文件的工具。

GCC is open source - you can fix it. Of course, you'd probably have to revise LD to handle the information correctly, and you'd definitely have to fix GDB to use the embedded source. You'd be using a non-standard format for the debugging information, so you'd probably have to modify the other tools that manipulate object files.

所以,可能性在那儿。但是,与世界上其他人一样做的更容易做到并保持源代码,直到完成调试。通常,如果需要,您可以在重建可执行文件时多次运行单个GDB会话。而且,通常情况下,最简单的方法是调试当前版本的代码,而不是昨天的版本。如果你需要调试昨天的版本,你需要昨天的代码可用(你有一个很好的VCS,你不是吗?),以便您可以看到昨天的代码实际上是错误的,而不是今天的修改版本的代码

So, the possibility is there. But it is easier to do the same as everyone else in the world does and keep your source around until you've finished debugging it. Normally, you can keep a single GDB session running while you rebuild the executable multiple times, if need so be. And, typically, it is easiest to debug the current version of the code rather than yesterday's version. If you do need to debug yesterday's version, you need yesterday's code available (you do have a good VCS in place, don't you?) so that you can see what was actually wrong with yesterday's code rather than today's modified version of the code.

我会给你信用的问题 - 它需要一些侧面的想法来提出这个想法。做得好!但实际上你的建议是非常简单的。

I'll give you credit for asking the question - it takes some lateral thinking to come up with the idea. Well done! But in practice your suggestion is decidedly non-trivial to implement.

这篇关于将程序的源代码嵌入到使用GCC的GCC二进制文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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