在可执行文件中嵌入版本信息并从 Linux 核心转储中检索它?

Embedding version info in executable and retrieving it from Linux core dump?

我非常依赖核心转储来查找和修复我个人应用程序中的罕见错误。

我并排安装了多个版本的应用程序,并决定安装哪个版本 运行(这取决于其他一些应用程序)。在任何给定时间,同一工具只有一个版本可以 运行。我的启动器以“ulimit -c unlimited”开头。 When/if 应用程序崩溃,生成核心转储。

一个问题是“file somecoredump”告诉我生成核心文件的进程的名称,但我无法知道哪个版本的应用程序生成了它,所以很难分辨使用哪个可执行文件.

我想知道如何解决这个问题?

我能想到几个不好的方法:

  1. 将版本信息嵌入到进程名称中,例如MyProcess2.1c。现在“文件核心文件”告诉我版本。真的很丑,不考虑了
  2. 每个启动器都会修改/proc/sys/kernel/core_pattern并将其设置为带有版本信息的路径,例如/var/crash/2.1c/core。丑陋,因为此设置会影响所有应用程序,而不仅仅是我的。而且它现在才有效,因为我只允许一个应用程序版本同时 运行,有一天我可能需要并排 运行 多个版本。

对我来说最理想的是,如果有一种方法可以将版本信息嵌入到可执行文件中,并从核心文件中检索它。这可能吗?

您可以使用 linux 中的 strings 命令在二进制文件中查找唯一字符串。也许您可以将版本编译成二进制文件,例如来自 bash 的示例,然后 grep 所有输出的字符串以找到它。只需在它前面加上一个唯一的字符串,以便于查找?:

~]$ strings /usr/bin/bash | grep version
shell_version_string
build_version
sccs_version
rl_library_version
rl_do_lowercase_version
show_shell_version
rl_readline_version
dist_version
GNU bash, version %s-(%s)
GNU bash, version %s (%s)
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
@(#)Bash version 4.2.46(2) release GNU
display-shell-version
      -l    do not print tilde-prefixed versions of directories relative
    HOSTTYPE    The type of CPU this version of Bash is running under.
    OSTYPE  The version of Unix this version of Bash is running on.
    version, type `enable -n test'.
do-lowercase-version
.gnu.version
.gnu.version_r
~]$