Skip to content

Add CFI_SIGNAL_FRAME to ARM64 and RiscV runtimes.#13241

Merged
shindere merged 1 commit intoocaml:trunkfrom
tmcgilchrist:cfi_signal_frame
Jun 19, 2024
Merged

Add CFI_SIGNAL_FRAME to ARM64 and RiscV runtimes.#13241
shindere merged 1 commit intoocaml:trunkfrom
tmcgilchrist:cfi_signal_frame

Conversation

@tmcgilchrist
Copy link
Copy Markdown
Contributor

This change brings the ARM64 and RiscV runtimes into sync with the amd64 and s390x runtimes which tag certain runtime functions as signal handlers (caml_call_realloc_stack, caml_call_gc, caml_c_call, caml_c_call_stack_args, caml_start_program and caml_runstack), for the purpose of displaying backtraces correctly in GDB on Linux. See Retrofitting Effect Handlers onto OCaml paper section 2.3 Stack Unwinding for further details.

With this change backtraces are displayed with <signal handler called> shown whenever GDB encounters these functions e.g.

Breakpoint 2, camlFib.entry () at fib.ml:15
15	let _ = main ()
(gdb) bt
#0  camlFib.entry () at fib.ml:15
#1  0x0000aaaaaaaef244 in caml_program ()
#2  <signal handler called>
#3  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:141
#4  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#5  0x0000aaaaaab4a760 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#6  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#7  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147

and

#0  caml_alloc_stack (hval=281474573335040, hexn=281474573334568, heff=281474573334496) at runtime/fiber.c:226
#1  <signal handler called>
#2  0x0000aaaaaab2e7b4 in camlStdlib__Effect.match_with_496 () at effect.ml:83
#3  0x0000aaaaaaafb1e8 in camlEff.entry () at eff.ml:52
#4  0x0000aaaaaaaf7b34 in caml_program ()
#5  <signal handler called>
#6  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:141
#7  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#8  0x0000aaaaaab578b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#9  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#10 caml_main (argv=<optimized out>) at runtime/startup_nat.c:147

NOTE that power.S is not consistent either but I am working on a fix for it.

@gasche
Copy link
Copy Markdown
Member

gasche commented Jun 17, 2024

There are some aspects of the code, only semi-related to your changes, that I find confusing.

caml_call_gc and caml_c_call are both functions and labels (placed in the function, after the prologue), other functions jump to the labels after their own prologue. But the handling of CFI_SIGNAL_FRAME is inconsistent:

  • currently (in amd64.S) the directive is always placed in the function prologue, before the label, so other functions that jump to the label will not encounter it
  • as a non-expert, my impression is that this choice is probably right for the caml_c_call label (which is only used to call caml_raise_* functions in failure cases of larger functions, and probably wrong for the caml_call_gc label (I suppose that caml_alloc<n> variants would also benefit from the subroutine)
  • in your PR, you do the same as amd64 in arm64, but riscv places the directive after the caml_call_gc label (which is probably better?)

I am not sure if before-the-label or after-the-label is the right choice and would welcome confirmation (this might also deserve a comment in the source), but I would expect all backends to use the same strategy for each function.

Comment thread runtime/arm64.S Outdated
Comment thread runtime/riscv.S Outdated
Comment thread runtime/arm64.S Outdated
@ghost
Copy link
Copy Markdown

ghost commented Jun 17, 2024

I am not sure if before-the-label or after-the-label is the right choice and would welcome confirmation (this might also deserve a comment in the source), but I would expect all backends to use the same strategy for each function.

The cfi annotation should be put after the label.

CFI_SIGNAL_FRAME is required for GDB to correctly display backtraces
through stack swaps.
Comment thread runtime/amd64.S Outdated
@tmcgilchrist
Copy link
Copy Markdown
Contributor Author

@dustanddreams are you satisfied with the changes as they stand?

I would expect all backends to use the same strategy for each function.

The backends should be consistent with each other except for on amd64 where there is an optimisation allowing tail-calling into caml_call_gc function (that @dustanddreams explained to me offline).

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm satisfied with these changes (including the misindentation fixes).

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Jun 19, 2024 via email

@shindere shindere merged commit 76bab61 into ocaml:trunk Jun 19, 2024
@tmcgilchrist tmcgilchrist deleted the cfi_signal_frame branch June 19, 2024 10:20
@kayceesrk
Copy link
Copy Markdown
Contributor

The reason some of the frames were originally tagged as signal handler frames was that GDB cut the backtrace when the stacks did not grow towards 0 address, which happens when the stacks switch at external calls, callbacks and effect handlers. From the original PR message, it is not clear to me whether the stacks were indeed cut at those positions and this PR fixes them; the PR message only shows the effect of applying this patch.

Also, this backtrace seems ill-formed

#3  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:141
#4  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#5  0x0000aaaaaab4a760 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#6  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#7  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147

why does caml_startup_exn call caml_main? The backtrace at entry should look like this

#3  <signal handler called>
#4  0x000055fc66df1a26 in caml_startup_common (pooling=<optimised out>, argv=0x7ffc7d25fc68)
    at runtime/startup_nat.c:128
#5  caml_startup_common (argv=0x7ffc7d25fc68, pooling=<optimised out>) at runtime/startup_nat.c:87
#6  0x000055fc66df1a9f in caml_startup_exn (argv=<optimised out>) at runtime/startup_nat.c:135
#7  caml_startup (argv=<optimised out>) at runtime/startup_nat.c:140
#8  caml_main (argv=<optimised out>) at runtime/startup_nat.c:147
#9  0x000055fc66d9b872 in main (argc=<optimised out>, argv=<optimised out>) at runtime/main.c:37

@tmcgilchrist
Copy link
Copy Markdown
Contributor Author

Thank you for the extra context @kayceesrk

Using the meander example from Retrofitting effect handlers onto OCaml https://dl.acm.org/doi/10.1145/3453483.3454039

$ cat meander.ml 
external ocaml_to_c
         : unit -> int = "ocaml_to_c"
exception E1
exception E2
let c_to_ocaml () = raise E1
let _ = Callback.register
          "c_to_ocaml" c_to_ocaml
let omain () =
  try (* h1 *)
    try (* h2 *) ocaml_to_c ()
    with E2 -> 0
  with E1 -> 42
let _ = assert (omain () = 42)%   
 $ cat meander_c.c 
#include <caml/mlvalues.h>
#include <caml/callback.h>

value ocaml_to_c (value unit) {
    caml_callback(*caml_named_value
                  ("c_to_ocaml"), Val_unit);
    return Val_int(0);
}%                                                        

Compiled using ocamlopt meander_c.c meander.ml -o meander.exe

Before this change on Linux / ARM64 on Ubuntu 24.04:

(gdb) run
Starting program: /home/tsmc/ocaml/meander.exe 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0xfffff7ffb000
[Thread debugging using libthread_db enabled]                                                                                                             
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000aaaaaaabd168 in caml_program ()
(gdb) bt
#0  0x0000aaaaaaabd168 in caml_program ()
#1  <signal handler called>
#2  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:141
#3  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#4  0x0000aaaaaaae91b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#5  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#6  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#7  0x0000000000000001 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) c
Continuing.

Breakpoint 2, ocaml_to_c (unit=1) at meander_c.c:5
5	    caml_callback(*caml_named_value
(gdb) bt
#0  ocaml_to_c (unit=1) at meander_c.c:5
#1  0x0000aaaaaaae9590 in caml_c_call ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) c
Continuing.

Breakpoint 3, camlMeander.c_to_ocaml_273 () at meander.ml:5
5	let c_to_ocaml () = raise E1
(gdb) bt
#0  camlMeander.c_to_ocaml_273 () at meander.ml:5
#1  <signal handler called>
#2  0x0000aaaaaab20d60 in camlMeander.7 ()
#3  0x0000aaaaaab20d60 in camlMeander.data_begin ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) info br
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000aaaaaaabd168 <caml_program>
	breakpoint already hit 1 time
2       breakpoint     keep y   0x0000aaaaaaac3a80 in ocaml_to_c at meander_c.c:5
	breakpoint already hit 1 time
3       breakpoint     keep y   0x0000aaaaaaabda70 in camlMeander.c_to_ocaml_273 at meander.ml:5
	breakpoint already hit 1 time
(gdb) 

There are three issues with this gdb session:

  1. the backtrace for caml_program shows an inaccurate backtrace that doesn't correspond to the program execution.
  2. the jump from OCaml to C at breakpoint 2 ocaml_to_c is not displaying correctly
  3. the second jump from the callback to c_to_ocaml_273 is not displaying correctly

After this change:

(gdb) run
Starting program: /home/tsmc/ocaml/meander.exe 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0xfffff7ffb000
[Thread debugging using libthread_db enabled]                                                                                                             
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000aaaaaaabd168 in caml_program ()
(gdb) bt
#0  0x0000aaaaaaabd168 in caml_program ()
#1  <signal handler called>
#2  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:141
#3  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#4  0x0000aaaaaaae91b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#5  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#6  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#7  0x0000000000000001 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) c
Continuing.

Breakpoint 2, ocaml_to_c (unit=1) at meander_c.c:5
5	    caml_callback(*caml_named_value
(gdb) bt
#0  ocaml_to_c (unit=1) at meander_c.c:5
#1  <signal handler called>
#2  0x0000aaaaaaabdab8 in camlMeander.omain_278 () at meander.ml:10
#3  0x0000aaaaaaabdc9c in camlMeander.entry () at meander.ml:13
#4  0x0000aaaaaaabd210 in caml_program ()
#5  <signal handler called>
#6  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:141
#7  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#8  0x0000aaaaaaae91b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#9  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#10 caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#11 0x0000000000000001 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) c
Continuing.

Breakpoint 3, camlMeander.c_to_ocaml_273 () at meander.ml:5
5	let c_to_ocaml () = raise E1
(gdb) bt
#0  camlMeander.c_to_ocaml_273 () at meander.ml:5
#1  <signal handler called>
#2  0x0000aaaaaab20d60 in camlMeander.7 ()
#3  0x0000aaaaaab20d60 in camlMeander.data_begin ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

The frames are not labelled as <signal handler called> but there are inaccurate stack frames show for the breakpoints caml_program and camlMeander.c_to_ocaml_273. This matches the Linux/x86_64 GDB session below captured on Ubuntu 22.04 (minor issues with gdb not associating OCaml frames with source files).

(gdb) run
Starting program: /home/tsmc/ocaml/meander.exe 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 3, 0x000055555556d980 in caml_program ()
(gdb) bt
#0  0x000055555556d980 in caml_program ()
#1  <signal handler called>
#2  0x0000555555599196 in caml_startup_common (pooling=<optimised out>, argv=0x7fffffffe518) at runtime/startup_nat.c:128
#3  caml_startup_common (argv=0x7fffffffe518, pooling=<optimised out>) at runtime/startup_nat.c:87
#4  0x000055555559920f in caml_startup_exn (argv=<optimised out>) at runtime/startup_nat.c:135
#5  caml_startup (argv=<optimised out>) at runtime/startup_nat.c:140
#6  caml_main (argv=<optimised out>) at runtime/startup_nat.c:147
#7  0x000055555556d882 in main (argc=<optimised out>, argv=<optimised out>) at runtime/main.c:37
(gdb) c
Continuing.

Breakpoint 1, 0x0000555555572e50 in ocaml_to_c ()
(gdb) bt
#0  0x0000555555572e50 in ocaml_to_c ()
#1  <signal handler called>
#2  0x000055555556e063 in camlMeander.omain_278 ()
#3  0x000055555556e1e2 in camlMeander.entry ()
#4  0x000055555556d9e3 in caml_program ()
#5  <signal handler called>
#6  0x0000555555599196 in caml_startup_common (pooling=<optimised out>, argv=0x7fffffffe518) at runtime/startup_nat.c:128
#7  caml_startup_common (argv=0x7fffffffe518, pooling=<optimised out>) at runtime/startup_nat.c:87
#8  0x000055555559920f in caml_startup_exn (argv=<optimised out>) at runtime/startup_nat.c:135
#9  caml_startup (argv=<optimised out>) at runtime/startup_nat.c:140
#10 caml_main (argv=<optimised out>) at runtime/startup_nat.c:147
#11 0x000055555556d882 in main (argc=<optimised out>, argv=<optimised out>) at runtime/main.c:37
(gdb) c
Continuing.

Breakpoint 2, 0x000055555556e010 in camlMeander.c_to_ocaml_273 ()
(gdb) bt
#0  0x000055555556e010 in camlMeander.c_to_ocaml_273 ()
#1  <signal handler called>
#2  0x0000555555574078 in caml_callback_exn (closure=<optimised out>, arg=<optimised out>) at runtime/callback.c:206
#3  0x000055555557467d in caml_callback (closure=<optimised out>, arg=<optimised out>) at runtime/callback.c:347
#4  0x0000555555572e71 in ocaml_to_c ()
#5  <signal handler called>
#6  0x000055555556e063 in camlMeander.omain_278 ()
#7  0x000055555556e1e2 in camlMeander.entry ()
#8  0x000055555556d9e3 in caml_program ()
#9  <signal handler called>
#10 0x0000555555599196 in caml_startup_common (pooling=<optimised out>, argv=0x7fffffffe518) at runtime/startup_nat.c:128
#11 caml_startup_common (argv=0x7fffffffe518, pooling=<optimised out>) at runtime/startup_nat.c:87
#12 0x000055555559920f in caml_startup_exn (argv=<optimised out>) at runtime/startup_nat.c:135
#13 caml_startup (argv=<optimised out>) at runtime/startup_nat.c:140
#14 caml_main (argv=<optimised out>) at runtime/startup_nat.c:147
#15 0x000055555556d882 in main (argc=<optimised out>, argv=<optimised out>) at runtime/main.c:37
(gdb) info br
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000555555572e50 <ocaml_to_c>
	breakpoint already hit 1 time
2       breakpoint     keep y   0x000055555556e010 <camlMeander.c_to_ocaml_273>
	breakpoint already hit 1 time
3       breakpoint     keep y   0x000055555556d980 <caml_program>
	breakpoint already hit 1 time

There are still issues with inaccurate stack frames which requires a small fix to the CFI directives on ARM64 tmcgilchrist@761f333 after that you get an equivalent gdb session to Linux / x86_64.

(gdb) run
Starting program: /home/tsmc/ocaml/meander.exe 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0xfffff7ffb000
[Thread debugging using libthread_db enabled]                                                                                                             
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000aaaaaaabd168 in caml_program ()
(gdb) bt
#0  0x0000aaaaaaabd168 in caml_program ()
#1  <signal handler called>
#2  0x0000aaaaaaae9138 in caml_startup_common (pooling=0, argv=0xfffffffffc78) at runtime/startup_nat.c:128
#3  caml_startup_common (argv=0xfffffffffc78, pooling=0) at runtime/startup_nat.c:87
#4  0x0000aaaaaaae91b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#5  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#6  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#7  0x0000aaaaaaabcfd0 in main (argc=<optimized out>, argv=<optimized out>) at runtime/main.c:37
(gdb) c
Continuing.

Breakpoint 2, ocaml_to_c (unit=1) at meander_c.c:5
5	    caml_callback(*caml_named_value
(gdb) bt
#0  ocaml_to_c (unit=1) at meander_c.c:5
#1  <signal handler called>
#2  0x0000aaaaaaabdab8 in camlMeander.omain_278 () at meander.ml:10
#3  0x0000aaaaaaabdc9c in camlMeander.entry () at meander.ml:13
#4  0x0000aaaaaaabd210 in caml_program ()
#5  <signal handler called>
#6  0x0000aaaaaaae9138 in caml_startup_common (pooling=4, argv=0xaaaaaab24ac8) at runtime/startup_nat.c:128
#7  caml_startup_common (argv=0xaaaaaab24ac8, pooling=4) at runtime/startup_nat.c:87
#8  0x0000aaaaaaae91b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#9  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#10 caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#11 0x0000aaaaaaabcfd0 in main (argc=<optimized out>, argv=<optimized out>) at runtime/main.c:37
(gdb) c
Continuing.

Breakpoint 3, camlMeander.c_to_ocaml_273 () at meander.ml:5
5	let c_to_ocaml () = raise E1
(gdb) bt
#0  camlMeander.c_to_ocaml_273 () at meander.ml:5
#1  <signal handler called>
#2  0x0000aaaaaaac4d28 in caml_callback_exn (closure=<optimized out>, arg=<optimized out>, arg@entry=1) at runtime/callback.c:206
#3  0x0000aaaaaaac531c in caml_callback (closure=<optimized out>, arg=arg@entry=1) at runtime/callback.c:347
#4  0x0000aaaaaaac3aa0 in ocaml_to_c (unit=<optimized out>) at meander_c.c:5
#5  <signal handler called>
#6  0x0000aaaaaaabdab8 in camlMeander.omain_278 () at meander.ml:10
#7  0x0000aaaaaaabdc9c in camlMeander.entry () at meander.ml:13
#8  0x0000aaaaaaabd210 in caml_program ()
#9  <signal handler called>
#10 0x0000aaaaaaae9138 in caml_startup_common (pooling=4, argv=0xaaaaaab24ac8) at runtime/startup_nat.c:128
#11 caml_startup_common (argv=0xaaaaaab24ac8, pooling=4) at runtime/startup_nat.c:87
#12 0x0000aaaaaaae91b0 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#13 caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#14 caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#15 0x0000aaaaaaabcfd0 in main (argc=<optimized out>, argv=<optimized out>) at runtime/main.c:37
(gdb)

@kayceesrk
Copy link
Copy Markdown
Contributor

kayceesrk commented Jun 26, 2024

Thanks for the clarification.

There are still issues with inaccurate stack frames which requires a small fix to the CFI directives on ARM64 tmcgilchrist@761f333

Is this commit part of a PR?

@tmcgilchrist
Copy link
Copy Markdown
Contributor Author

For Linux / RiscV the situation is worse.

Before this change:

(gdb) run
Starting program: /home/tsmc/ocaml/meander.exe 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000002aaaac5350 in caml_program ()
(gdb) bt
#0  0x0000002aaaac5350 in caml_program ()
#1  0x0000002aaaae70a4 in caml_start_program ()
#2  0x0000000000000001 in ?? ()
(gdb) c
Continuing.

Breakpoint 3, 0x0000002aaaacb3f0 in ocaml_to_c ()
(gdb) bt
#0  0x0000002aaaacb3f0 in ocaml_to_c ()
#1  0x0000002aaaae6f98 in caml_c_call ()
#2  0x0000002aaab31878 in ?? ()
(gdb) c
Continuing.

Breakpoint 2, 0x0000002aaaac5c88 in camlMeander.c_to_ocaml_273 ()
(gdb) bt
#0  0x0000002aaaac5c88 in camlMeander.c_to_ocaml_273 ()
#1  0x0000002aaaae70a4 in caml_start_program ()
#2  0x0000002aaaac5ce0 in camlMeander.omain_278 ()
#3  0x0000000000000002 in ?? ()
(gdb) info br
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000002aaaac5350 <caml_program+8>
	breakpoint already hit 1 time
2       breakpoint     keep y   0x0000002aaaac5c88 <camlMeander.c_to_ocaml_273+28>
	breakpoint already hit 1 time
3       breakpoint     keep y   0x0000002aaaacb3f0 <ocaml_to_c+12>
	breakpoint already hit 1 time
(gdb) 

After this change:

(gdb) run
Starting program: /home/tsmc/ocaml/meander.exe 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x0000002aaaac5350 in caml_program ()
(gdb) bt
#0  0x0000002aaaac5350 in caml_program ()
#1  <signal handler called>
#2  0x0000000000000001 in ?? ()
(gdb) br caml_startup_common
Breakpoint 5 at 0x2aaaae6990: caml_startup_common. (2 locations)
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/tsmc/ocaml/meander.exe 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".

Breakpoint 5.1, caml_startup_common (argv=0x3ffffff398, pooling=0) at runtime/startup_nat.c:88
88	{
(gdb) bt
#0  caml_startup_common (argv=0x3ffffff398, pooling=0) at runtime/startup_nat.c:88
#1  0x0000002aaaae6ab6 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#2  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#3  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#4  0x0000002aaaac528a in main (argc=<optimized out>, argv=<optimized out>) at runtime/main.c:37
(gdb) c
Continuing.

Breakpoint 5.2, caml_startup_common (pooling=<optimized out>, argv=0x3ffffff398) at runtime/startup_nat.c:100
100	  caml_init_codefrag();
(gdb) bt
#0  caml_startup_common (pooling=<optimized out>, argv=0x3ffffff398) at runtime/startup_nat.c:100
#1  caml_startup_common (argv=0x3ffffff398, pooling=<optimized out>) at runtime/startup_nat.c:87
#2  0x0000002aaaae6ab6 in caml_startup_exn (argv=<optimized out>) at runtime/startup_nat.c:135
#3  caml_startup (argv=<optimized out>) at runtime/startup_nat.c:140
#4  caml_main (argv=<optimized out>) at runtime/startup_nat.c:147
#5  0x0000002aaaac528a in main (argc=<optimized out>, argv=<optimized out>) at runtime/main.c:37
(gdb) c
Continuing.

Breakpoint 1, 0x0000002aaaac5350 in caml_program ()
(gdb) bt
#0  0x0000002aaaac5350 in caml_program ()
#1  <signal handler called>
#2  0x0000000000000001 in ?? ()
(gdb) c
Continuing.

Breakpoint 3, 0x0000002aaaacb3f0 in ocaml_to_c ()
(gdb) bt
#0  0x0000002aaaacb3f0 in ocaml_to_c ()
#1  <signal handler called>
#2  0x0000002aaab31878 in ?? ()
(gdb) info br
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000002aaaac5350 <caml_program+8>
	breakpoint already hit 1 time
2       breakpoint     keep y   0x0000002aaaac5c88 <camlMeander.c_to_ocaml_273+28>
3       breakpoint     keep y   0x0000002aaaacb3f0 <ocaml_to_c+12>
	breakpoint already hit 1 time
4       breakpoint     keep y   0x0000002aaaac5350 <caml_program+8>
	breakpoint already hit 1 time
5       breakpoint     keep y   <MULTIPLE>         
	breakpoint already hit 2 times
5.1                         y   0x0000002aaaae6990 in caml_startup_common at runtime/startup_nat.c:88
5.2                         y   0x0000002aaaae69c6 in caml_startup_common at runtime/startup_nat.c:100

Small improvement as sections of the backtrace get labelled correctly with <signal handler called> but the CFI information for this backend is clearly broken and we loose track of frames when initially transitioning from C runtime into OCaml. I haven't got a fix for this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants