public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: "Carlos Maniero" <carlos@maniero.me>
To: <~johnnyrichard/olang-devel@lists.sr.ht>
Subject: [POC] Generating DWARF debugging information
Date: Mon, 19 Feb 2024 12:05:48 -0300	[thread overview]
Message-ID: <CZ95CX0MYNVD.2NXADO1FWXK6J@maniero.me> (raw)

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!

             reply	other threads:[~2024-02-19 15:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 15:05 Carlos Maniero [this message]
2024-02-21 19:31 ` Johnny Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CZ95CX0MYNVD.2NXADO1FWXK6J@maniero.me \
    --to=carlos@maniero.me \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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