Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Finding Source file name from object or executable

amit1209
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
James R. Ferguson
Acclaimed Contributor

Re: Finding Source file name from object or executable

Hi Amit:

You could try:

# what filename

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Finding Source file name from object or executable

Hi (again) Amit:

Another useful view would be provided by:

# nm filename

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

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.
amit1209
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
OldSchool
Honored Contributor

Re: Finding Source file name from object or executable

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

Re: Finding Source file name from object or executable

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.

amit1209
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
Dennis Handly
Acclaimed Contributor

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.