2

Does gcc having feature which can list of source files (.c/.c++/.h) from binary (if binary is having debug information)..??

I know same be can be achieved through objdump and GDB too. But "objdump" and "GDB" give the list of only ".c" file.

For Exapmle: I have two file (test.c and test.h) and i have compiled test code with "-g" option and used "objdump" as below:

bdk4user@llvm:~/home$ objdump --dwarf=decodedline a.out 

a.out:     file format elf64-x86-64

Decoded dump of debug contents of section .debug_line:

CU: test.c:
File name                            Line number    Starting address
test.c                                         4            0x40057d
test.c                                         6            0x400585 
test.c                                         7            0x40058f
test.c                                         8            0x4005a1
...

But it doesn't list the ".h" file which is also used.

So my question is, does GCC having any feature which can give list of all file which are being used in binary.??

OR any other utility to achieved the same..??

Thanks in advance.

5
  • Seems like an XY question ("I want to do X, I think Y is the right solution, so I ask how to do Y"). What are you actually trying to achieve? Commented Apr 3, 2015 at 10:35
  • When you compile the program, pass option -E, and look at the lines starting with # in the output. Any other place in the toolchain is too late. Commented Apr 3, 2015 at 10:55
  • @ Mats Petersson: I just want to know whether gcc also hold the feature of listing the source file from binary. sorry i could not convey in proper way. Commented Apr 3, 2015 at 11:31
  • 1
    @AnshuSharma As mentioned gcc isn't used to inspect binaries. Commented Apr 3, 2015 at 11:33
  • @ πάντα ῥε: Thank you for sharing your experience. Commented Apr 3, 2015 at 11:36

1 Answer 1

1

"But it doesn't list the ".h" file which is also used."

Since header files are processed with the C/C++ preprocessor, even before the .o files are generated, none of these tools can have a notion of them.

Sign up to request clarification or add additional context in comments.

13 Comments

The preprocessor introduces (proprietary) indications of the origin of each line, that is used for warnings and also stored in the debug information. If there is actual code in the .h, the OP's command will list it.
@πάντα ῥεῖ for quick reply. so mean to say "No tool" can give ".h" files information.Does gcc' give the list of source file as objdump gives..??
@Marc Glisse : Thank you for reply. i did not get you "If there is actual code in the .h, the OP's command will list it"..? What is OP's command.?
@AnshuSharma "What is OP's command.?" What you wrote in your question: objdump --dwarf=decodedline a.out
OP = "Original Post(er)" - OP's comand = "Command posted in the original post".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.