1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- G N A T . D E B U G _ U T I L I T I E S --
9 -- Copyright (C) 1997-2024, AdaCore --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with System
; use System
;
33 with System
.Storage_Elements
; use System
.Storage_Elements
;
35 package body GNAT
.Debug_Utilities
is
37 H
: constant array (0 .. 15) of Character := "0123456789ABCDEF";
38 -- Table of hex digits
46 function Image
(A
: Address
) return Image_String
is
54 P
:= Address_Image_Length
- 1;
66 S
(P
) := H
(Integer (N
mod 16));
81 function Image
(S
: String) return String is
82 W
: String (1 .. 2 * S
'Length + 2);
107 function Image_C
(A
: Address
) return Image_C_String
is
109 N
: Integer_Address
:= To_Integer
(A
);
112 for P
in reverse 3 .. S
'Last loop
113 S
(P
) := H
(Integer (N
mod 16));
125 function Value
(S
: String) return System
.Address
is
126 Base
: Integer_Address
:= 10;
127 Res
: Integer_Address
:= 0;
128 Last
: Natural := S
'Last;
133 -- Skip final Ada 95 base character
135 if S
(Last
) = '#' or else S
(Last
) = ':' then
139 -- Loop through characters
141 for J
in S
'First .. Last
loop
144 -- C format hex constant
148 raise Constraint_Error
;
153 -- Ada form based literal
155 elsif C
= '#' or else C
= ':' then
159 -- Ignore all underlines
164 -- Otherwise must have digit
167 if C
in '0' .. '9' then
168 N
:= Character'Pos (C
) - Character'Pos ('0');
169 elsif C
in 'A' .. 'F' then
170 N
:= Character'Pos (C
) - (Character'Pos ('A') - 10);
171 elsif C
in 'a' .. 'f' then
172 N
:= Character'Pos (C
) - (Character'Pos ('a') - 10);
174 raise Constraint_Error
;
178 raise Constraint_Error
;
180 Res
:= Res
* Base
+ N
;
185 return To_Address
(Res
);
188 end GNAT
.Debug_Utilities
;