# Debugging methodology

**URL:** <https://forum.ada-lang.io/t/debugging-methodology/4528>\
**Category:** Help\
**Tags:** gnat\
**Created:** [June 28, 2026, 6:44pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528 "2026-06-28T18:44:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZenitDS](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zenitds/32/949_2.png) [@ZenitDS](https://forum.ada-lang.io/u/ZenitDS)\
**Post date:** [June 28, 2026, 6:44pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/1 "2026-06-28T18:44:43Z")

</div>

Hi,

When faced with an error which causes an exception, what is your approach for debugging the issue?

I have tried using `-Es` in `Binder` accompanied with `-g` in `Compiler` and `Binder`. However, this just gives me a stack trace with addresses, which then passing to `addr2line` does not seem to work ( maybe because of it being PIE ? ).

> EDIT: it actually gives different addresses for what is the same call stack in different runs

Furthermore, I have tried using `gdb`’s command `catch exception` but it complains that the runtime does not have the necessary debugging information. For this it may be useful to note that I am using `voidlinux-musl`.

Best regards  
– zen

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [June 28, 2026, 7:07pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/2 "2026-06-28T19:07:43Z")

</div>

There is a package: GNAT.Exception\_Actions. Use it to set an exception handler. Inside the handler you can trace the exception and print the call stack using this snippet:

```ada
procedure Call_Stack is
   use GNAT.Traceback, GNAT.Traceback.Symbolic;
   TB : Tracebacks_Array (1..1_000); Len : Natural;
begin
   Call_Chain (TB, Len); Put_Line (Symbolic_Traceback (TB (1..Len)));
end Call_Stack;

```

As for the rest, from my experience:

- _-Es_ does not work
- _ **gdb** _ is useless in most cases
- expect nasty surprizes on ARM targets
- expect issues with tracing relocatable libraries

I never develop on ARM. First I make it work on x86 under Windows. Then I do a short check under a Linux for x86. If both work chances are good that ARM would be OK.

---

<div class="post-metadata">

**Author:** ![ZenitDS](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zenitds/32/949_2.png) [@ZenitDS](https://forum.ada-lang.io/u/ZenitDS)\
**Post date:** [June 28, 2026, 7:14pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/3 "2026-06-28T19:14:06Z")

</div>

I am in X86, just using the musl libc implementation. I tried your snippet but it works the same as -Es for me, it just gives the backtrace addresses but nothing else 😕 .

example:

```ada
raised ADA.ASSERTIONS.ASSERTION_ERROR : failed precondition from rv-instruction-encoding.adb:728
0x7f752b2b6c21 ??? at ???
0x560b6e4fb8ba ??? at ???
0x560b6e4fe48f ??? at ???
0x560b6e525955 ??? at ???
0x560b6e525e5a ??? at ???
0x560b6e4f2ebd ??? at ???
0x560b6e4f3490 ??? at ???
0x7f752b52ae09 ??? at ???

```

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [June 28, 2026, 7:27pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/4 "2026-06-28T19:27:55Z")

</div>

Check -g switch and that symbols are not stripped by the tool chain.

---

<div class="post-metadata">

**Author:** ![ZenitDS](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zenitds/32/949_2.png) [@ZenitDS](https://forum.ada-lang.io/u/ZenitDS)\
**Post date:** [June 28, 2026, 7:48pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/5 "2026-06-28T19:48:40Z")

</div>

I have `.debug_info` and peers in the executable elf. Also, gdb seems to work just fine for stepping, next, etc. Using `backtrace` gives the backtrace correctly, with symbols included.

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [June 28, 2026, 7:52pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/6 "2026-06-28T19:52:17Z")

</div>

Can you get call stack from Hello\_World?

---

<div class="post-metadata">

**Author:** ![Max](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/max/32/21_2.png) [@Max](https://forum.ada-lang.io/u/Max)\
**Post date:** [June 28, 2026, 7:55pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/7 "2026-06-28T19:55:25Z")

</div>

Does this help you execute “catch exception”?

`apk add musl-dbg`

---

<div class="post-metadata">

**Author:** ![ZenitDS](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zenitds/32/949_2.png) [@ZenitDS](https://forum.ada-lang.io/u/ZenitDS)\
**Post date:** [June 28, 2026, 8:05pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/8 "2026-06-28T20:05:29Z")

</div>

main.gpr

```ada
project Main is

    for Main use ("main.adb");

    for Source_Files use ("main.adb");
    for Object_Dir use "obj";

    package Compiler is
      for Default_Switches ("Ada") use ("-g");
    end Compiler;

    package Binder is
      for Default_Switches ("Ada") use ("-g", "-Es");
    end Binder;

end Main;

```

### Explicit exception

main.adb

```ada
with Ada.Text_IO;

procedure Main is
begin
    Ada.Text_IO.Put_Line ("~ Ada Lovelace ~");
    raise Program_Error;
end Main;

```

output

```ada
~ Ada Lovelace ~

raised PROGRAM_ERROR : main.adb:7 explicit raise
0x56094691244b ??? at ???
0x560946912940 ??? at ???
0x7f89b38fee09 ??? at ???

```

### Call\_Stack

main.adb

```ada
with Ada.Text_IO;
with GNAT.Traceback, GNAT.Traceback.Symbolic;

procedure Main is
   procedure Call_Stack is
      use Ada.Text_IO, GNAT.Traceback, GNAT.Traceback.Symbolic;
      TB : Tracebacks_Array (1..1_000); Len : Natural;
   begin
      Call_Chain (TB, Len); Put_Line (Symbolic_Traceback (TB (1..Len)));
   end Call_Stack;
begin
    Ada.Text_IO.Put_Line ("~ Ada Lovelace ~");
    Call_Stack;
end Main;

```

output

```ada
~ Ada Lovelace ~
0x5577db8594e3 ??? at ???
0x5577db859648 ??? at ???
0x5577db859b6a ??? at ???
0x7f5284bdfe09 ??? at ???

```

---

<div class="post-metadata">

**Author:** ![ZenitDS](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zenitds/32/949_2.png) [@ZenitDS](https://forum.ada-lang.io/u/ZenitDS)\
**Post date:** [June 28, 2026, 8:10pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/9 "2026-06-28T20:10:12Z")

</div>

`Void Linux` does not appear to have a similar package to that one. I have seen that package is availiable in `Alpine Linux`. /usr/lib/libc.so does have `debug_info` and others too. 🤔

Here is what it looks like in the debugger:

```ada
Reading symbols from ./obj/main...
(gdb) start
Temporary breakpoint 1 at 0x3608: file /home/xxxx/Codeberg/rv_emu/hello_world/main.adb, line 5.
Starting program: /home/xxxx/Codeberg/rv_emu/hello_world/obj/main 

Temporary breakpoint 1, main () at /home/xxxx/Codeberg/rv_emu/hello_world/main.adb:5
5	procedure Main is
(gdb) catch exception
❌️ Your Ada runtime appears to be missing some debugging information.
Cannot insert Ada exception catchpoint in this configuration.
(gdb) 

```

---

<div class="post-metadata">

**Author:** ![Irvise](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/i/7ba0ec/32.png) [@Irvise](https://forum.ada-lang.io/u/Irvise)\
**Post date:** [June 28, 2026, 8:35pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/10 "2026-06-28T20:35:49Z")

</div>

I recommend the following flags: `-Og` (optimize for debugging), `-ggdb` generate GDB friendly info, `-gnatVa` enable all checks, `-gnatwa` enable all common warnings. Then in GDB do the `catch exception` as you did but also `catch assert`, which seems to be also taking place for you. You can also rebuild the entire RunTime System (RTS) with these flags and if the error takes place in the RTS, you will get all the symbols. For this, please, refer to [3. The GNAT Compilation Model — GNAT User's Guide for Native Platforms 27.0w documentation](https://docs.adacore.com/gnat_ugn-docs/html/gnat_ugn/gnat_ugn/the_gnat_compilation_model.html#rebuilding-the-gnat-run-time-library)

Best regards,  
Fer

---

<div class="post-metadata">

**Author:** ![Max](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/max/32/21_2.png) [@Max](https://forum.ada-lang.io/u/Max)\
**Post date:** [June 29, 2026, 6:13am UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/11 "2026-06-29T06:13:50Z")

</div>

I don’t have void Linux, but Gemini tells me:

> First, enable the debug repository by installing its definition package:

sudo xbps-install -S void-repo-debug  
sudo xbps-install -S musl-dbg

---

<div class="post-metadata">

**Author:** ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)\
**Post date:** [June 29, 2026, 7:47am UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/12 "2026-06-29T07:47:20Z")

</div>

With your files:

Windows 11:

```ada
D:\Temp\r6>obj\main.exe
~ Ada Lovelace ~

raised PROGRAM_ERROR : main.adb:6 explicit raise
[D:\Temp\r6\obj\main.exe]
0x401712 Main at main.adb:6
0x401c8c Main at b__main.adb:247
0x401423 __tmainCRTStartup at ???
0x40113b mainCRTStartup at ???
[C:\WINDOWS\System32\KERNEL32.DLL]
0x7ffabefbe955
[C:\WINDOWS\SYSTEM32\ntdll.dll]
0x7ffac12a7c1a

```

Debian 6.12:

```ada
~ Ada Lovelace ~

raised PROGRAM_ERROR : main.adb:6 explicit raise
[obj/main]
0x55f373a913f0 Main at main.adb:6
0x55f373a918f9 Main at b__main.adb:254
[/lib/x86_64-linux-gnu/libc.so.6]
0x7f0932c35ca6
0x7f0932c35d63
[obj/main]
0x55f373a912df _start at ???
0xfffffffffffffffe

```

---

<div class="post-metadata">

**Author:** ![ZenitDS](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/zenitds/32/949_2.png) [@ZenitDS](https://forum.ada-lang.io/u/ZenitDS)\
**Post date:** [June 29, 2026, 4:12pm UTC](https://forum.ada-lang.io/t/debugging-methodology/4528/13 "2026-06-29T16:12:17Z")

</div>

> [@Max](#):
>
> I don’t have void Linux, but Gemini tells me:
> 
> > First, enable the debug repository by installing its definition package:
> 
> sudo xbps-install -S void-repo-debug  
> sudo xbps-install -S musl-dbg

I was able to install with your commands. I did see `void-repo-debug` while doing some random searches yesterday but thought that it would be some set of tools or something like it. Those commands did actually install `musl-dbg`, but it did not help. I am guessing that what it does is provide debugging symbols for the system `libc`. It appears that the problem lies not on missing symbols but in the actual finding of them. From what I have seen, probably because of missing `backtrace` and similar functions in musl, present only in `glibc`, which GNAT probably assumes for some stuff like this as it is `gcc` from `GNU` afterall.

===

_However_, I then asked gemini, and it suggested to make it non-PIE, since by its reasoning:

> When PIE is active, the OS randomizes the memory addresses every time the program runs, completely throwing off GNAT’s internal symbolic traceback engine and leaving it unable to map those addresses back to your code.

Which is at least highly inaccurate. I then tried that approach using the `-no-pie` flag to the linker that gemini suggested and it is actually able to resolve the symbols now and give names for the trace 🥳 .

I leave here a snippet of this quarter-baked solution for the record:

```ada
    package Linker is
      for Default_Switches ("Ada") use ("-no-pie");
    end Linker;

```

Further interaction with the LLM got nowhere else.

@dmitry-kazakov Yeah, I think it might just be because of musl afterall.

Thanks all for your time and care!  
Have a great day.

– zen
