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
50 Prefix : Prefix_Type := Absolute_Address)
52 Ctr : Natural := Count;
53 -- Count of bytes left to output
55 Offset_Buf : String (1 .. Standard'Address_Size / 4 + 4);
56 Offset_Last : Natural;
57 -- Buffer for prefix in Offset mode
59 Adr : Address := Addr;
63 -- Number of bytes output on current line
66 -- Character at current storage address
69 -- Number of chars in prefix (including colon and space)
72 -- Line length for entire line
74 Hex : constant array (0 .. 15) of Character := "0123456789ABCDEF";
76 type Char_Ptr is access all Character;
78 function To_Char_Ptr is new Ada.Unchecked_Conversion (Address, Char_Ptr);
82 when Absolute_Address =>
83 AIL := Address_Image_Length - 4 + 2;
85 Offset_Last := Offset_Buf'First - 1;
86 Set_Image_Based_Integer (Ctr, 16, 0, Offset_Buf, Offset_Last);
87 AIL := Offset_Last - 4 + 2;
91 Line_Len := AIL + 3 * 16 + 2 + 16;
94 Line_Buf : String (1 .. Line_Len);
98 -- Start of line processing
102 when Absolute_Address =>
104 S : constant String := Image (Adr);
106 Line_Buf (1 .. AIL) := S (4 .. S'Length - 1) & ": ";
114 Set_Image_Based_Integer
115 (Count - Ctr, 16, 0, Offset_Buf, Last);
118 Line_Buf (1 .. AIL - Len - 2) := (others => '0');
119 Line_Buf (AIL - Len - 1 .. AIL - 2) :=
120 Offset_Buf (4 .. Last - 1);
121 Line_Buf (AIL - 1 .. AIL) := ": ";
127 Line_Buf (AIL + 1 .. Line_Buf'Last) := (others => ' ');
128 Line_Buf (AIL + 3 * 16 + 1) := '"';
131 -- Add one character to current line
133 C := To_Char_Ptr (Adr).all;
137 Line_Buf (AIL + 3 * N + 1) := Hex (Character'Pos (C) / 16);
138 Line_Buf (AIL + 3 * N + 2) := Hex (Character'Pos (C) mod 16);
140 if C < ' ' or else C = Character'Val (16#7F#) then
144 Line_Buf (AIL + 3 * 16 + 2 + N) := C;
147 -- End of line processing
150 Line_Buf (Line_Buf'Last) := '"';
151 GNAT.IO.Put_Line (Line_Buf);
156 -- Deal with possible last partial line
159 Line_Buf (AIL + 3 * 16 + 2 + N) := '"';
160 GNAT.IO.Put_Line (Line_Buf (1 .. AIL + 3 * 16 + 2 + N));
166 end GNAT.Memory_Dump;