简体   繁体   English

查找针对其生成核心转储的可执行文件

[英]Find executable that a core dump was generated against

有没有一种方法可以将版本信息(例如git commit hash)嵌入到ELF可执行文件中,以便可以从其生成的核心转储中进行检索?

See this question to get the git hash. 查看此问题以获取git哈希。

Then, change your build procedure (eg your Makefile ) to include it. 然后,更改构建过程(例如Makefile )以包含它。 For instance, generate a one line C file with 例如,使用

  git log --pretty=format:'const char program_git_hash[] = "%H";' \
      -n 1 > _prog_hash.c

then link your program with _prog_hash.c and remove that file after linking. 然后将程序与_prog_hash.c链接,并在链接后删除该文件。 You could add timestamping information with eg 您可以添加时间戳信息,例如

 date +'const char program_timestamp="%c";%n' >> _prog_hash.c

Then you could use gdb or strings on the binary executable to find it. 然后,您可以在二进制可执行文件上使用gdbstrings来查找它。

You may want to declare extern const char program_git_hash[]; 您可能需要声明extern const char program_git_hash[]; in some header file, and perhaps display it (eg when passing the --version option to your program) 在某些头文件中,并可能显示它(例如,将--version选项传递给程序时)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM