Dwarf hello world assembly example or tutoral?

2019-04-12 00:17发布

I'm writing an assembly level human speakable programming language in nasm. I've noticed that Dwarf debugging is an essential component to developing it.

In order for it to become self-hosting later on, will not only have to compile to ELF, but also support Dwarf to make debugging viable. For ELF there is a wonderful nasm example of how to make an ELF header http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://blog.markloiseau.com/2012/05/tiny-64-bit-elf-executables/

I'm wondering if there is or even could be made something similar for DWARF, an example hello world, that includes the DWARF sections required for it to work with gdb. With such an example it would be much easier to understand DWARF, rather than going through rather cryptic documentation, that mostly refers to C. The closest I've found is a guide by IBM that has a little program that lets you selectively dwarf dump on a per function basis www.ibm.com/developerworks/library/os-debugging/

Anyways if you happen to be able to make a nasm hello world dwarf example, I'm sure the world will much appreciate it, since it will make the dwarf format more accessible. Maybe someone will then even be able to implement it in fasm or other assemblers than nasm.

1条回答
做自己的国王
2楼-- · 2019-04-12 01:15

If you don't mind digging a bit, there is a simple "DWARF assembler" in the gdb test suite. See src/gdb/testsuite/lib/dwarf.exp. It's pretty easy to understand and despite its name it writes out assembly code. You can grep through the rest of the test suite to see examples of how it is used.

查看更多
登录 后发表回答