Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2024-10

CaptureBacktrace

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adriaan van Os

It looks like the FPC RTL function CaptureBacktrace uses a system call if FPC_SYSTEM_HAS_CAPTUREBACKTRACE is true and a custom routine if it is false. The define FPC_SYSTEM_HAS_CAPTUREBACKTRACE seems to be true for Windows with Structured Exception Handling (FPC_USE_WIN64_SEH) where RtlCaptureStackBackTrace is called instead of the FPC built-in routine.

My question now is if there is a reason why FPC doesn't call backtrace (see man backtrace) on Linux and Unix (including MacOS) platforms ?

Another question is whether and how NSException.callStackReturnAddresses and NSException.callStackSymbols can be used here (on MacOS) ?

Regards,

Adriaan van Os

Reply by email

Karoly Balogh
to Adriaan van Os

Hi,

Adriaan van Os wrote
My question now is if there is a reason why FPC doesn't call backtrace (see man backtrace) on Linux and Unix (including MacOS) platforms ?

It seems this is a relatively recent addition to libc, which means, after
2000. :)

I suppose we could call it on macOS, as we always link against libc there. Althouh we used support earlier systems than OS X 10.5, where it first appeared, according to the macOS man page. I guess Jonas could say something more about that.

Same applies to BSDs. We used to support earlier BSD version than where this call existed. Not sure that is still true tho'.

But on Linux we don't always link against libc, and we do support just running on top of kernel. In fact this is the default. We only link against libc, when multithreading is involved, or linking against any other C-style library.

Charlie

Reply by email

Marco van de Voort
to Karoly Balogh

Op 04/10/2024 om 17:44 schreef Karoly Balogh via fpc-devel:

Same applies to BSDs. We used to support earlier BSD version than where this call existed. Not sure that is still true tho'.

FreeBSD is also a syscall port.

Reply by email

Adriaan van Os
to Karoly Balogh: It seems this is a relatively recent addition to libc, which means, after 2000. :) I…
Karoly Balogh wrote 9 lines
Hi, On Fri, 4 Oct 2024, Adriaan van Os via fpc-devel wrote: > My question now is if there is a reason why FPC doesn't call backtrace (see > man backtrace) on Linux and Unix (including MacOS) platforms ? It seems this is a relatively recent addition to libc, which means, after 2000. :)
program TestBacktrace;
procedure StackMe
         ( theDepth : integer);
begin
   writeln
     ( 'theDepth = ', theDepth);
   Dump_Stack
     ( stdout, 0);
   writeln;
   if theDepth > 1
     then StackMe
        ( theDepth - 1)
end;
begin
   writeln
     ( 'main program');
   writeln;
   StackMe
     ( 6)
end.

prints

main program

theDepth = 6

theDepth = 5

theDepth = 4
$00011680

theDepth = 3
$00011680
$000116C5

theDepth = 2
$00011680
$000116C5
$000116C5

theDepth = 1
$00011680
$000116C5
$000116C5
$000116C5

So, how should I call Dump_Stack ?

Also, there is no symbol information (on MacOS). Is this because of the separate .dSYM file ?

Regards,

Adriaan van Os

Reply by email

Adriaan van Os
to Adriaan van Os
Also, there is no symbol information (on MacOS). Is this because of the separate .dSYM file ?

But if I call backtrace_symbols in stead of DUmp_Stack, I do get symbol names ....

Regards,

Adriaan van Os

main program
0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x0001177d PASCALMAIN + 61 2 Test 0x00023515 FPC_SYSTEMMAIN + 69 3 Test 0x000114c5 start + 53

theDepth = 6

0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x000116ee P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 110 2 Test 0x000117ac PASCALMAIN + 108 3 Test 0x00023515 FPC_SYSTEMMAIN + 69 4 Test 0x000114c5 start + 53

theDepth = 5

0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x000116ee P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 110 2 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 3 Test 0x000117ac PASCALMAIN + 108 4 Test 0x00023515 FPC_SYSTEMMAIN + 69 5 Test 0x000114c5 start + 53

theDepth = 4

0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x000116ee P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 110 2 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 3 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 4 Test 0x000117ac PASCALMAIN + 108 5 Test 0x00023515 FPC_SYSTEMMAIN + 69 6 Test 0x000114c5 start + 53

theDepth = 3

0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x000116ee P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 110 2 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 3 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 4 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 5 Test 0x000117ac PASCALMAIN + 108 6 Test 0x00023515 FPC_SYSTEMMAIN + 69 7 Test 0x000114c5 start + 53

theDepth = 2

0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x000116ee P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 110 2 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 3 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 4 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 5 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 6 Test 0x000117ac PASCALMAIN + 108 7 Test 0x00023515 FPC_SYSTEMMAIN + 69 8 Test 0x000114c5 start + 53

theDepth = 1

0 Test 0x00011560 P$MBTESTBACKTRACE2_$$_WRITEBACKTRACE + 144 1 Test 0x000116ee P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 110 2 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 3 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 4 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 5 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 6 Test 0x00011733 P$MBTESTBACKTRACE2_$$_STACKME$SMALLINT + 179 7 Test 0x000117ac PASCALMAIN + 108 8 Test 0x00023515 FPC_SYSTEMMAIN + 69 9 Test 0x000114c5 start + 53

Reply by email