1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- G N A T . M E M O R Y _ D U M P --
9 -- Copyright (C) 2003-2014, 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
.Img_BIU
; use System
.Img_BIU
;
34 with System
.Storage_Elements
; use System
.Storage_Elements
;
36 with GNAT
.IO
; use GNAT
.IO
;
37 with GNAT
.Debug_Utilities
; use GNAT
.Debug_Utilities
;
39 with Ada
.Unchecked_Conversion
;
41 package body GNAT
.Memory_Dump
is
52 Dump
(Addr
, Count
, Prefix
=> Absolute_Address
);
60 Ctr
: Natural := Count
;
61 -- Count of bytes left to output
63 Offset_Buf
: String (1 .. Standard
'Address_Size / 4 + 4);
64 Offset_Last
: Natural;
65 -- Buffer for prefix in Offset mode
67 Adr
: Address
:= Addr
;
71 -- Number of bytes output on current line
74 -- Character at current storage address
77 -- Number of chars in prefix (including colon and space)
80 -- Line length for entire line
82 Hex
: constant array (0 .. 15) of Character := "0123456789ABCDEF";
84 type Char_Ptr
is access all Character;
86 function To_Char_Ptr
is new Ada
.Unchecked_Conversion
(Address
, Char_Ptr
);
90 when Absolute_Address
=>
91 AIL
:= Address_Image_Length
- 4 + 2;
94 Offset_Last
:= Offset_Buf
'First - 1;
95 Set_Image_Based_Integer
(Ctr
, 16, 0, Offset_Buf
, Offset_Last
);
96 AIL
:= Offset_Last
- 4 + 2;
102 Line_Len
:= AIL
+ 3 * 16 + 2 + 16;
105 Line_Buf
: String (1 .. Line_Len
);
110 -- Start of line processing
114 when Absolute_Address
=>
116 S
: constant String := Image
(Adr
);
118 Line_Buf
(1 .. AIL
) := S
(4 .. S
'Length - 1) & ": ";
127 Set_Image_Based_Integer
128 (Count
- Ctr
, 16, 0, Offset_Buf
, Last
);
131 Line_Buf
(1 .. AIL
- Len
- 2) := (others => '0');
132 Line_Buf
(AIL
- Len
- 1 .. AIL
- 2) :=
133 Offset_Buf
(4 .. Last
- 1);
134 Line_Buf
(AIL
- 1 .. AIL
) := ": ";
140 Line_Buf
(AIL
+ 1 .. Line_Buf
'Last) := (others => ' ');
141 Line_Buf
(AIL
+ 3 * 16 + 1) := '"';
144 -- Add one character to current line
146 C
:= To_Char_Ptr
(Adr
).all;
150 Line_Buf
(AIL
+ 3 * N
+ 1) := Hex
(Character'Pos (C
) / 16);
151 Line_Buf
(AIL
+ 3 * N
+ 2) := Hex
(Character'Pos (C
) mod 16);
153 if C
< ' ' or else C
= Character'Val (16#
7F#
) then
157 Line_Buf
(AIL
+ 3 * 16 + 2 + N
) := C
;
160 -- End of line processing
163 Line_Buf
(Line_Buf
'Last) := '"';
164 GNAT
.IO
.Put_Line
(Line_Buf
);
169 -- Deal with possible last partial line
172 Line_Buf
(AIL
+ 3 * 16 + 2 + N
) := '"';
173 GNAT
.IO
.Put_Line
(Line_Buf
(1 .. AIL
+ 3 * 16 + 2 + N
));
178 end GNAT
.Memory_Dump
;