public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [POC] Generating DWARF debugging information
@ 2024-02-19 15:05 Carlos Maniero
  2024-02-21 19:31 ` Johnny Richard
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Maniero @ 2024-02-19 15:05 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel

Hi everyone.

Since it is not that simple to find information about about how to
generate debugging information in a way that the program can be
debuggable on gdb, I'll dump what I found here.

First of all I took the minimal example we have currently in our code
base and manually converted it to assembly.

Minimal example:

  fn main(): u32 {
    return 0
  }

Correspondent assembly:

  .text
  .globl  _start

  _start:
    call main
    mov %eax, %edi
    mov $60, %eax
    syscall

  main:
    nop   ; (this nop is mocking a function prelude)
    mov $32, %eax
    ret

After a few reverse engineer with GCC and C I could be able to make it
work with the assembly bellow:

  .text
  .globl  _start

  _start:
    call main
    mov %eax, %edi
    mov $60, %eax
    syscall

  .file 1 "main_exit.0"
  main:
    .loc 1 1 1
    nop
    .loc 1 2 1
    mov $32, %eax
    ret

compiling:

  as main_exit.s -gdwarf-2; ld a.out -o a

And that is it. 

It was really hard to found any documentation of the gnu assembler (gas)
directives. So I'm going to document it here:

https://software-dl.ti.com/codegen/docs/tiarmclang/rel3_2_0_LTS/gnu_syntax_arm_asm_language/gnu_arm_directives/debugging_directives.html#gar-debug-directives

That's it!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [POC] Generating DWARF debugging information
  2024-02-19 15:05 [POC] Generating DWARF debugging information Carlos Maniero
@ 2024-02-21 19:31 ` Johnny Richard
  0 siblings, 0 replies; 2+ messages in thread
From: Johnny Richard @ 2024-02-21 19:31 UTC (permalink / raw)
  To: Carlos Maniero; +Cc: ~johnnyrichard/olang-devel

On Mon, Feb 19, 2024 at 12:05:48PM -0300, Carlos Maniero wrote:
> Since it is not that simple to find information about about how to
> generate debugging information in a way that the program can be
> debuggable on gdb, I'll dump what I found here.

Great work! We can try to start writing the compiler with debug
information from the beginning.  I think it would be nice if we could
also provide the source code from the binary instead using file
location.

I will read more about it and keep you posted on this thread.

    Johnny Richard

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-21 18:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-19 15:05 [POC] Generating DWARF debugging information Carlos Maniero
2024-02-21 19:31 ` Johnny Richard

Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox