How to dump path to source from object-fileUsing GCC to produce readable assembly?How do I use extern to share variables between source files?Improve INSERT-per-second performance of SQLite?What are the GCC default include directories?gcc-arm Compiler produce different object file for the same source fileWhy does GCC generate 15-20% faster code if I optimize for size instead of speed?Objdump gives Segmentation Fault with -S optiongcc feature: generate list of source files from binaryHow to use nm or objdump and/or any other available tool to pinpoint an offending function/method in a .so file?gcc -g flag: Moving the Source Code

Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country

Adding things to bunches of things vs multiplication

What is the best way to use errors in mathematica M12?

Why does this image of cyclocarbon look like a nonagon?

Photoshop older default brushes

Will some rockets really collapse under their own weight?

Tikz: The position of a label change step-wise and not in a continuous way

Meaning and structure of headline "Hair it is: A List of ..."

What's the point of writing that I know will never be used or read?

The anatomy of an organic infrared generator

Why do aircraft leave cruising altitude long before landing just to circle?

Can planar set contain even many vertices of every unit equilateral triangle?

The Roommates' Dilemma

Unconventional examples of mathematical modelling

Is it alright to say good afternoon Sirs and Madams in a panel interview?

Output the list of musical notes

Can an ally use your Shadow Blade without it dissipating?

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

μονάδαι as plural form of μονάς

Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)

Did they ever see Truman doing any private things when filming him for 24 hours 7 days a week?

How do I cope with haze for the photos containing sky and trees at a distance?

Which basis does the wavefunction collapse to?

How to change minor radius of a torus in blender 2.8



How to dump path to source from object-file


Using GCC to produce readable assembly?How do I use extern to share variables between source files?Improve INSERT-per-second performance of SQLite?What are the GCC default include directories?gcc-arm Compiler produce different object file for the same source fileWhy does GCC generate 15-20% faster code if I optimize for size instead of speed?Objdump gives Segmentation Fault with -S optiongcc feature: generate list of source files from binaryHow to use nm or objdump and/or any other available tool to pinpoint an offending function/method in a .so file?gcc -g flag: Moving the Source Code






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Assume I have a C object-file app.o compiled with gcc. How can I dump the file path to the original app.c from which app.o was compiled. My goal is to create a listing of all symbols + respective source file path using the binutils and gcc toolsuite.
By no means am I expecting an all-in-one solution. So I tried playing with multiple tools to gather the information I need.



Inspecting the object-file with a text-editor reveals that (appart from a lot of unreadable binary gibberish) the file does contain a reference to app.c as a string embedded into the object-file format. However I did not find a way to extract that string using objdump or nm.



I was hoping objdump would have some flag that could extract this source file string, but after trying virtually all options documented in the man page I still couldn't find it.



With the path of the source file I was hoping I could run gcc -M <path-to-source>. This would allow me to look through all the headers included by app.c and find the in-source declarations.



Suppose a simple app.c like this:



void foo(void) 



Compile it via gcc -c app.c -o app.o.



Running objdump -t app.o dumps the symbol table, but does not refer anywhere to the original app.c.
Running cat app.o does show that the object-file contains the file path to app.c (relative to pwd at compile-time). But I wasn't exactly planning on writing my own object-file parser just to get to that string.










share|improve this question
























  • could dwarfdump help you?

    – doron
    Mar 27 at 13:42











  • I quickly looked into it, indeed dwarfdump might be usable for what I need. Only downside is that it requires the object file to be built with debug information (gcc -g ...), which isn't that big of a deal tbh. What I'm more worried about is availability on MinGW. I didn't mention it in the original post, but I would like to have it working on native Linux and MinGW.

    – Chief_Gokhlayeh
    Mar 27 at 14:13

















0















Assume I have a C object-file app.o compiled with gcc. How can I dump the file path to the original app.c from which app.o was compiled. My goal is to create a listing of all symbols + respective source file path using the binutils and gcc toolsuite.
By no means am I expecting an all-in-one solution. So I tried playing with multiple tools to gather the information I need.



Inspecting the object-file with a text-editor reveals that (appart from a lot of unreadable binary gibberish) the file does contain a reference to app.c as a string embedded into the object-file format. However I did not find a way to extract that string using objdump or nm.



I was hoping objdump would have some flag that could extract this source file string, but after trying virtually all options documented in the man page I still couldn't find it.



With the path of the source file I was hoping I could run gcc -M <path-to-source>. This would allow me to look through all the headers included by app.c and find the in-source declarations.



Suppose a simple app.c like this:



void foo(void) 



Compile it via gcc -c app.c -o app.o.



Running objdump -t app.o dumps the symbol table, but does not refer anywhere to the original app.c.
Running cat app.o does show that the object-file contains the file path to app.c (relative to pwd at compile-time). But I wasn't exactly planning on writing my own object-file parser just to get to that string.










share|improve this question
























  • could dwarfdump help you?

    – doron
    Mar 27 at 13:42











  • I quickly looked into it, indeed dwarfdump might be usable for what I need. Only downside is that it requires the object file to be built with debug information (gcc -g ...), which isn't that big of a deal tbh. What I'm more worried about is availability on MinGW. I didn't mention it in the original post, but I would like to have it working on native Linux and MinGW.

    – Chief_Gokhlayeh
    Mar 27 at 14:13













0












0








0








Assume I have a C object-file app.o compiled with gcc. How can I dump the file path to the original app.c from which app.o was compiled. My goal is to create a listing of all symbols + respective source file path using the binutils and gcc toolsuite.
By no means am I expecting an all-in-one solution. So I tried playing with multiple tools to gather the information I need.



Inspecting the object-file with a text-editor reveals that (appart from a lot of unreadable binary gibberish) the file does contain a reference to app.c as a string embedded into the object-file format. However I did not find a way to extract that string using objdump or nm.



I was hoping objdump would have some flag that could extract this source file string, but after trying virtually all options documented in the man page I still couldn't find it.



With the path of the source file I was hoping I could run gcc -M <path-to-source>. This would allow me to look through all the headers included by app.c and find the in-source declarations.



Suppose a simple app.c like this:



void foo(void) 



Compile it via gcc -c app.c -o app.o.



Running objdump -t app.o dumps the symbol table, but does not refer anywhere to the original app.c.
Running cat app.o does show that the object-file contains the file path to app.c (relative to pwd at compile-time). But I wasn't exactly planning on writing my own object-file parser just to get to that string.










share|improve this question














Assume I have a C object-file app.o compiled with gcc. How can I dump the file path to the original app.c from which app.o was compiled. My goal is to create a listing of all symbols + respective source file path using the binutils and gcc toolsuite.
By no means am I expecting an all-in-one solution. So I tried playing with multiple tools to gather the information I need.



Inspecting the object-file with a text-editor reveals that (appart from a lot of unreadable binary gibberish) the file does contain a reference to app.c as a string embedded into the object-file format. However I did not find a way to extract that string using objdump or nm.



I was hoping objdump would have some flag that could extract this source file string, but after trying virtually all options documented in the man page I still couldn't find it.



With the path of the source file I was hoping I could run gcc -M <path-to-source>. This would allow me to look through all the headers included by app.c and find the in-source declarations.



Suppose a simple app.c like this:



void foo(void) 



Compile it via gcc -c app.c -o app.o.



Running objdump -t app.o dumps the symbol table, but does not refer anywhere to the original app.c.
Running cat app.o does show that the object-file contains the file path to app.c (relative to pwd at compile-time). But I wasn't exactly planning on writing my own object-file parser just to get to that string.







c gcc objdump object-files nm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 13:32









Chief_GokhlayehChief_Gokhlayeh

12 bronze badges




12 bronze badges















  • could dwarfdump help you?

    – doron
    Mar 27 at 13:42











  • I quickly looked into it, indeed dwarfdump might be usable for what I need. Only downside is that it requires the object file to be built with debug information (gcc -g ...), which isn't that big of a deal tbh. What I'm more worried about is availability on MinGW. I didn't mention it in the original post, but I would like to have it working on native Linux and MinGW.

    – Chief_Gokhlayeh
    Mar 27 at 14:13

















  • could dwarfdump help you?

    – doron
    Mar 27 at 13:42











  • I quickly looked into it, indeed dwarfdump might be usable for what I need. Only downside is that it requires the object file to be built with debug information (gcc -g ...), which isn't that big of a deal tbh. What I'm more worried about is availability on MinGW. I didn't mention it in the original post, but I would like to have it working on native Linux and MinGW.

    – Chief_Gokhlayeh
    Mar 27 at 14:13
















could dwarfdump help you?

– doron
Mar 27 at 13:42





could dwarfdump help you?

– doron
Mar 27 at 13:42













I quickly looked into it, indeed dwarfdump might be usable for what I need. Only downside is that it requires the object file to be built with debug information (gcc -g ...), which isn't that big of a deal tbh. What I'm more worried about is availability on MinGW. I didn't mention it in the original post, but I would like to have it working on native Linux and MinGW.

– Chief_Gokhlayeh
Mar 27 at 14:13





I quickly looked into it, indeed dwarfdump might be usable for what I need. Only downside is that it requires the object file to be built with debug information (gcc -g ...), which isn't that big of a deal tbh. What I'm more worried about is availability on MinGW. I didn't mention it in the original post, but I would like to have it working on native Linux and MinGW.

– Chief_Gokhlayeh
Mar 27 at 14:13












1 Answer
1






active

oldest

votes


















0














To answer my own question minutes after posting it (duh!):



readelf -s app.o prints a symbol table including the name of the source file (app.c). With that I am able to run gcc -M app.c and then parse through all header files to gather the symbol declarations.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378492%2fhow-to-dump-path-to-source-from-object-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To answer my own question minutes after posting it (duh!):



    readelf -s app.o prints a symbol table including the name of the source file (app.c). With that I am able to run gcc -M app.c and then parse through all header files to gather the symbol declarations.






    share|improve this answer































      0














      To answer my own question minutes after posting it (duh!):



      readelf -s app.o prints a symbol table including the name of the source file (app.c). With that I am able to run gcc -M app.c and then parse through all header files to gather the symbol declarations.






      share|improve this answer





























        0












        0








        0







        To answer my own question minutes after posting it (duh!):



        readelf -s app.o prints a symbol table including the name of the source file (app.c). With that I am able to run gcc -M app.c and then parse through all header files to gather the symbol declarations.






        share|improve this answer















        To answer my own question minutes after posting it (duh!):



        readelf -s app.o prints a symbol table including the name of the source file (app.c). With that I am able to run gcc -M app.c and then parse through all header files to gather the symbol declarations.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 19:04

























        answered Mar 27 at 13:39









        Chief_GokhlayehChief_Gokhlayeh

        12 bronze badges




        12 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378492%2fhow-to-dump-path-to-source-from-object-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현