[ILUG] Embedding comments into a binary.
Kenn Humborg
kenn at bluetree.ie
Thu Dec 7 19:04:14 GMT 2000
> On Thu, Dec 07, 2000 at 06:41:11PM +0100, Donal Mcnamee (LMI) mentioned:
> > Is there any utility that can embed comments (e.g. the version of the .c
> > files used to make the binary) into the binary itself.
>
> gcc -g file.c -o file
>
> will make a file with debugging info. It'll include the complete source
> etc.
No it won't. The debugging info doesn't contain the source code.
It contains the filenames of the source files and tables that map
code addresses to line numbers so that a debugger can locate the
relevant source lines.
> > And then is there such program that can be run against this binary to
> > return this information?
>
> Well, gdb will let you run "list" over the binary, showing line numbers &
> the source.
gdb tries to locate the source file and opens it directly.
What you want to do is make static string variables at the top
of each .c file:
static const char id[] = "file.c 1.2.3.4";
(Use the keyword expansion facilities of your revision control system.)
The compiler and linker will then conspire to get these strings into
the resulting binary. You could use the 'strings' command to get them
out again.
However, the 'ident' command does this one better. See the ident manpage.
Later,
Kenn
More information about the ILUG
mailing list