Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Finding Source file name from object or executable

Occasional Contributor

Finding Source file name from object or executable

Is it possible to find the source file name [including path] from the either the object or executable. The code doesn't have debug information so gdb also did not work.

Amit
8 REPLIES
Acclaimed Contributor [Founder]

Re: Finding Source file name from object or executable

Hi Amit:

You could try:

# what filename

Regards!

...JRF...
Acclaimed Contributor [Founder]

Re: Finding Source file name from object or executable

Hi (again) Amit:

Another useful view would be provided by:

# nm filename

Regards!

...JRF...
Acclaimed Contributor [Founder]

Re: Finding Source file name from object or executable

As a general rule, no. That's the kind of information that compiling with -g does provide. You can try the nm command and what but unless -g was used in the compile then no references to the source files exist. Normally, that name of the source file can be inferred from the object but that is not definitive and certainly does not include the full path.
If it ain't broke, I can fix that.
Occasional Contributor

Re: Finding Source file name from object or executable

nm also only works when the compilation is done by using -g option. Unfortunately the option wasn't used.

Amit
Honored Contributor [Founder]

Re: Finding Source file name from object or executable

"what" (sccs) or "ident" (rcs) might shed some light, but its a longshot.
Acclaimed Contributor [Founder]

Re: Finding Source file name from object or executable

[ Edited ]

See my answer to your question in your other thread:

http://h30499.www3.hp.com/t5/Languages-and-Scripting/Extracing-function-names-from-a-C-object-file/m-p/2457315

 

>The code doesn't have debug information so gdb also did not work.

If you are on IPF, you can usually get this info, even if -g isn't used. Unless the executable is stripped.

>Clay: As a general rule, no. That's the kind of information that compiling with -g does provide.

This info is available with commands mentioned in the link above.
Compiler option summary is available with footprints(1).

>nm also only works when the compilation is done by using -g option.

-g has nothing to do with nm(1), it doesn't look at debug info.

Occasional Contributor

Re: Finding Source file name from object or executable

The odump does provide the filenames but without absolute path. However, the elfdump -dc option does not work and exits with Bad input file type -elfdumperr 2003

Regards,
Amit
Highlighted
Acclaimed Contributor [Founder]

Re: Finding Source file name from object or executable

>The odump does provide the filenames but without absolute path.

Sure it does. You just have to glue the base name to the CWD on the next line.

>the elfdump -dc option does not work

Sure it does. ;-)
elfdump works on ELF files (IPF and PA64). odump works on SOM files, PA32.