Debian Codegraph @

gcc/ada/libgnat/s-traceb.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . T R A C E B A C K --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1999-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This is the default version of this package
33
34 -- Note: this unit must be compiled using -fno-optimize-sibling-calls.
35 -- See comment below in body of Call_Chain for details on the reason.
36
37 package body System.Traceback is
38
39 procedure Call_Chain
40 (Traceback : System.Address;
41 Max_Len : Natural;
42 Len : out Natural;
43 Exclude_Min : System.Address := System.Null_Address;
44 Exclude_Max : System.Address := System.Null_Address;
45 Skip_Frames : Natural := 1);
46 -- Same as the exported version, but takes Traceback as an Address
47
48 ------------------
49 -- C_Call_Chain --
50 ------------------
51
52 function C_Call_Chain
53 (Traceback : System.Address;
54 Max_Len : Natural) return Natural
55 is
56 Val : Natural;
57 begin
58 Call_Chain (Traceback, Max_Len, Val);
59 return Val;
60 end C_Call_Chain;
61
62 ----------------
63 -- Call_Chain --
64 ----------------
65
66 function Backtrace
67 (Traceback : System.Address;
68 Len : Integer;
69 Exclude_Min : System.Address;
70 Exclude_Max : System.Address;
71 Skip_Frames : Integer)
72 return Integer;
73 pragma Import (C, Backtrace, "__gnat_backtrace");
74
75 procedure Call_Chain
76 (Traceback : System.Address;
77 Max_Len : Natural;
78 Len : out Natural;
79 Exclude_Min : System.Address := System.Null_Address;
80 Exclude_Max : System.Address := System.Null_Address;
81 Skip_Frames : Natural := 1)
82 is
83 begin
84 -- Note: Backtrace relies on the following call actually creating a
85 -- stack frame. To ensure that this is the case, it is essential to
86 -- compile this unit without sibling call optimization.
87
88 -- We want the underlying engine to skip its own frame plus the
89 -- ones we have been requested to skip ourselves.
90
91 Len := Backtrace (Traceback => Traceback,
92 Len => Max_Len,
93 Exclude_Min => Exclude_Min,
94 Exclude_Max => Exclude_Max,
95 Skip_Frames => Skip_Frames + 1);
96 end Call_Chain;
97
98 procedure Call_Chain
99 (Traceback : in out System.Traceback_Entries.Tracebacks_Array;
100 Max_Len : Natural;
101 Len : out Natural;
102 Exclude_Min : System.Address := System.Null_Address;
103 Exclude_Max : System.Address := System.Null_Address;
104 Skip_Frames : Natural := 1)
105 is
106 begin
107 Call_Chain
108 (Traceback'Address, Max_Len, Len,
109 Exclude_Min, Exclude_Max,
110
111 -- Skip one extra frame to skip the other Call_Chain entry as well
112
113 Skip_Frames => Skip_Frames + 1);
114 end Call_Chain;
115
116 end System.Traceback;