Debian Codegraph @

gcc/ada/libgnat/s-trasym.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . T R A C E B A C K . S Y M B O L I C --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1999-2025, AdaCore --
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 implementation for platforms where the full capability
33 -- is not supported. It returns tracebacks as lists of hexadecimal addresses
34 -- of the form "0x...".
35
36 with Ada.Exceptions.Traceback; use Ada.Exceptions.Traceback;
37 with System.Address_Image;
38
39 package body System.Traceback.Symbolic is
40
41 -- Note that Suppress_Hex is ignored in this version of this package.
42
43 ------------------------
44 -- Symbolic_Traceback --
45 ------------------------
46
47 function Symbolic_Traceback
48 (Traceback : System.Traceback_Entries.Tracebacks_Array) return String
49 is
50 begin
51 if Traceback'Length = 0 then
52 return "";
53
54 else
55 declare
56 Img : String := System.Address_Image (Traceback (Traceback'First));
57
58 Result : String (1 .. (Img'Length + 3) * Traceback'Length);
59 Last : Natural := 0;
60
61 begin
62 for J in Traceback'Range loop
63 Img := System.Address_Image (Traceback (J));
64 Result (Last + 1 .. Last + 2) := "0x";
65 Last := Last + 2;
66 Result (Last + 1 .. Last + Img'Length) := Img;
67 Last := Last + Img'Length + 1;
68 Result (Last) := ' ';
69 end loop;
70
71 Result (Last) := ASCII.LF;
72
73 declare
74 function Executable_Load_Address return System.Address;
75 pragma Import
76 (C, Executable_Load_Address,
77 "__gnat_get_executable_load_address");
78
79 Load_Address : constant System.Address :=
80 Executable_Load_Address;
81 begin
82 if Load_Address = System.Null_Address then
83 return Result (1 .. Last);
84 else
85 return "Load address: 0x"
86 & System.Address_Image (Load_Address)
87 & ASCII.LF
88 & Result (1 .. Last);
89 end if;
90 end;
91 end;
92 end if;
93 end Symbolic_Traceback;
94
95 -- "No_Hex" is ignored in this version, because otherwise we have nothing
96 -- at all to print.
97
98 function Symbolic_Traceback_No_Hex
99 (Traceback : System.Traceback_Entries.Tracebacks_Array) return String is
100 begin
101 return Symbolic_Traceback (Traceback);
102 end Symbolic_Traceback_No_Hex;
103
104 function Symbolic_Traceback
105 (E : Ada.Exceptions.Exception_Occurrence) return String
106 is
107 begin
108 return Symbolic_Traceback (Ada.Exceptions.Traceback.Tracebacks (E));
109 end Symbolic_Traceback;
110
111 function Symbolic_Traceback_No_Hex
112 (E : Ada.Exceptions.Exception_Occurrence) return String is
113 begin
114 return Symbolic_Traceback (E);
115 end Symbolic_Traceback_No_Hex;
116
117 ------------------
118 -- Enable_Cache --
119 ------------------
120
121 procedure Enable_Cache (Include_Modules : Boolean := False) is
122 begin
123 null;
124 end Enable_Cache;
125
126 end System.Traceback.Symbolic;