Search code examples
text-processingobjdumphexdumpobject-files

Can I get objdump --full-contents to only print the raw text?


I have an object file which with a section containing proper ASCII (or Latin-1?) text. So, if I write:

$ objdump -s my_file.so --section=.rodata

looks like this (only presenting a few lines from the middle, it's obviously very long):

 070a80 656d3b0a 73697a65 5f742073 68617265  em;.size_t share
 070a90 644d656d 50657242 6c6f636b 3b0a696e  dMemPerBlock;.in
 070aa0 74207265 67735065 72426c6f 636b3b0a  t regsPerBlock;.
 070ab0 696e7420 77617270 53697a65 3b0a7369  int warpSize;.si
 070ac0 7a655f74 206d656d 50697463 683b0a69  ze_t memPitch;.i
 070ad0 6e74206d 61785468 72656164 73506572  nt maxThreadsPer
 070ae0 426c6f63 6b3b0a69 6e74206d 61785468  Block;.int maxTh

My question: Can I get objdump to just print the text, without the line indices and the hexadecimal values? And to print at least all the printing characters properly (e.g. a newline for 0x0a)? Or - must I perform a bunch of text processing to correlate the dots to their values, replace them with the proper characters, cut the line prefixes, drop the artificial newlines etc?


Solution

  • Use xxd

    Using xxd will avoid cuting and awking, and is your best solution short of a objdump flag.

    Saving your formatted hexdump to file temp, we can pipe the result to xxd -r, (which expects such a formatted hexdump):

    $ cat temp | xxd -r
    em;
    size_t sharedMemPerBlock;
    int regsPerBlock;
    int warpSize;
    size_t memPitch;
    int maxThreadsPerBlock;
    int maxTh
    

    If you need to pass in a hex string with no line numbers or ascii representation instead, use xxd -r -p.