compilation option (-g) doubt?

  • Thread starter saravanan.linux
  • Start date
S

saravanan.linux

Hi,
Is there any way to find out, whether the executable is compiled with
-g option enabled?
ThankX in advace.
 
W

Walter Roberson

Is there any way to find out, whether the executable is compiled with
-g option enabled?

The C standard has no knowledge of compile options, so any
answer would have to be system dependant, for the system type
you did not specify.


What's the -g option anyhow? On SGI's IRIX cc compiler,
the -g option has to do with the variety of debugging information
produced, and with whether some optimizations will be allowed even
though they make the debugging information less accurate. The
default for IRIX's cc is -g0 -- so *every* program compiled with
IRIX's cc is "compiled with -g option enabled".

gcc has a suite of -g options, which control what the format of
debugging information is, but the man page talks in terms of
"extra" debugging information. I guess for at least some versions
of gcc, it is meaningful to ask whether the -extra- debugging
information has been included.

One of the items normally included in the output of IRIX's objects is
a copy of the command line argument used for the compilation. This
is especially useful for C++ compilations in order to [automatically]
detect whether a pre-compiled template was compiled with compatable
arguments and so may be reused without having to be regenerated.
Possibly your system has something similar, and possibly your
system provides a non-standard extension such as libdwarf or
libelf to allow you to probe the headers from within a program.
But if you just want a one-shot check, then you may wish to
investigate whether your system supports a program such as
elfdump or dwarfdump, or whether your system has a version of
'nm' that will give up the information. And there's always "strings"
on the executable ;-)
 
C

Chris Croughton

On 8 Apr 2005 23:06:19 -0700, (e-mail address removed)

Is there any way to find out, whether the executable is compiled with
-g option enabled?

Compile it without the -g option and compare the size?
Open it with gdb and see if it has line numbers?
Use objdump to see whether it has line numbers?

If you mean from within the program, why would you want to do it and why
would it make any difference? The code in memory will be identical.

(I'm assuming from context that you are talking about the gcc -g option,
which enables debugging information in the executable file, but if your
-g option does something different anything could happen. That's why
it's off-topic in comp.lang.c, it's nothing to do with the C language,
it's specific to your system...)

Chris C
 
R

Richard Bos

Is there any way to find out, whether the executable is compiled with
-g option enabled?

No. If tcc -gN program.c does not create a program.exe, there were more
than N warnings. If, however, it _does_ create program.exe, there were
fewer, but it is not possible from the resulting executable to see
whether -g was used or warnings were simply ignored.

Oh, that wasn't what you wanted to know? The perhaps you should select
your newsgroups with more care...

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top