Closed Anarion-zuo closed 11 months ago
I don't think objdump -S -d hello -l --insn-width=16
has any debug info. It's just disassembly and hex. If you pass -S to clang and run the asm parser on that I'd expect it to work. Partouf will be the expert on all things asm parser though.
So we can't get anything from objdump output, and must use compiler's output? What I need is a mapping from assembly code to source code, along with the opcodes and stuff. It would be better if mapping points to a location into the source code file, though I would be satisfied with a line in the source code without knowing its location.
I tried this, and got nothing from asm-parser.
$llvm_home/bin/clang -S -g -O2 -o hello.s hello.c
cat hello.s | ../asm-parser -stdin -whitespace > hello.s.json
What I got:
{"asm": [],"labelDefinitions": {}, "parsingTime": 1}
Then I tried this:
$llvm_home/bin/clang -S -g -O2 -o hello.s hello.c
cat hello.s | ../asm-parser -stdin -whitespace > hello.s.json
part of what I got:
{
"labels": [],
"source": null,
"text": " .long 42 # DW_AT_type"
},
{
"labels": [],
"source": null,
"text": " .byte 0 # DW_AT_decl_file"
},
{
"labels": [],
"source": null,
"text": " .byte 4 # DW_AT_decl_line"
},
{
"labels": [],
"source": null,
"text": " .byte 3 # Abbrev [3] 0x2a:0xc DW_TAG_array_type"
},
{
"labels": [],
"source": null,
"text": " .long 54 # DW_AT_type"
},
{
"labels": [],
"source": null,
"text": " .byte 4 # Abbrev [4] 0x2f:0x6 DW_TAG_subrange_type"
},
Perhaps @partouf can be so kindly to shed light on this?
To my best knowledge, the compiled binaries have debug info attached to them if the -g
option is given at compile time. objdump can show it, and perhaps this project can parse it. So the problem is two-fold:
I think the issue here is probably the default clang -g, which probably uses dwarf 5, maybe?
Can you try compiling with -gdwarf-4
and then retry?
I don't think
objdump -S -d hello -l --insn-width=16
has any debug info. It's just disassembly and hex. If you pass -S to clang and run the asm parser on that I'd expect it to work. Partouf will be the expert on all things asm parser though.
objdump always has debugging at the top of a sections that contains code as long as you compile with -g. Just not all objdumps and compilers and settings are compatible.
It worked! You are my lifesaver!
During this time of anxiously waiting for your guidance, I have implemented a rather crude objdump parser of my own, nonetheless.
Another quick question if you care to answer. Is there a similar standalone tool for other assembly-ish language, e.g. LLVM IR?
We have some llvm parsing stuff in the main repo but no, not standalone,
I'll go ahead and close since this isn't an asmparser issue but feel free to ask anymore questions you have
Compiler puts debug info in the binary, through e.g.
-g
. I see the output json has a "source" attribute. Is that supposed to be pointing to a position in the original source code file? I only get output that shows"source": null
, and wonder how it may actually print a reference to the source code file here.My C code:
Compile command: (with clang compiled from LLVM master branch
How I invoke asm-parser:
I'm using asm-parser released here: https://github.com/compiler-explorer/asm-parser/releases/tag/v0.9
json output:
As shown in the json string, it only has
"source": null
attributes, while the output in objdump has source code interleaving with assembly code.