Commit 09624906 by Tristan Gingold Committed by Arnaud Charlet

vxaddr2line.adb: Use Unsigned_32 instead of Integer for address type.

2008-04-08  Tristan Gingold  <gingold@adacore.com>

	* vxaddr2line.adb: Use Unsigned_32 instead of Integer for address type.
	Improve error message generation.

From-SVN: r134058
parent 1b449f6d
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2002-2007, AdaCore -- -- Copyright (C) 2002-2008, AdaCore --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -62,18 +62,21 @@ ...@@ -62,18 +62,21 @@
-- (in a format <host>_<target>), and then an appropriate value to Config_List -- (in a format <host>_<target>), and then an appropriate value to Config_List
-- array -- array
with Text_IO; use Text_IO; with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Command_Line; use Ada.Command_Line;
with Ada.Command_Line; use Ada.Command_Line; with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Interfaces; use Interfaces;
with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Directory_Operations; use GNAT.Directory_Operations; with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.Expect; use GNAT.Expect; with GNAT.Expect; use GNAT.Expect;
with GNAT.Regpat; use GNAT.Regpat; with GNAT.Regpat; use GNAT.Regpat;
procedure VxAddr2Line is procedure VxAddr2Line is
package Unsigned_32_IO is new Modular_IO (Unsigned_32);
-- Instantiate Modular_IO to have Put.
Ref_Symbol : constant String := "adainit"; Ref_Symbol : constant String := "adainit";
-- This is the name of the reference symbol which runtime address shall -- This is the name of the reference symbol which runtime address shall
-- be provided as the <ref_address> argument. -- be provided as the <ref_address> argument.
...@@ -102,7 +105,7 @@ procedure VxAddr2Line is ...@@ -102,7 +105,7 @@ procedure VxAddr2Line is
-- which will avoid computational overflows. Typically only useful when -- which will avoid computational overflows. Typically only useful when
-- 64bit addresses are provided. -- 64bit addresses are provided.
Bt_Offset_From_Call : Integer; Bt_Offset_From_Call : Unsigned_32;
-- Offset from a backtrace address to the address of the corresponding -- Offset from a backtrace address to the address of the corresponding
-- call instruction. This should always be 0, except on platforms where -- call instruction. This should always be 0, except on platforms where
-- the backtrace addresses actually correspond to return and not call -- the backtrace addresses actually correspond to return and not call
...@@ -160,14 +163,14 @@ procedure VxAddr2Line is ...@@ -160,14 +163,14 @@ procedure VxAddr2Line is
procedure Usage; procedure Usage;
-- Displays the short help message and then terminates the program -- Displays the short help message and then terminates the program
function Get_Reference_Offset return Integer; function Get_Reference_Offset return Unsigned_32;
-- Computes the static offset of the reference symbol by calling nm -- Computes the static offset of the reference symbol by calling nm
function Get_Value_From_Hex_Arg (Arg : Natural) return Integer; function Get_Value_From_Hex_Arg (Arg : Natural) return Unsigned_32;
-- Threats the argument number Arg as a C-style hexadecimal literal -- Threats the argument number Arg as a C-style hexadecimal literal
-- and returns its integer value -- and returns its integer value
function Hex_Image (Value : Integer) return String_Access; function Hex_Image (Value : Unsigned_32) return String_Access;
-- Returns access to a string that contains hexadecimal image of Value -- Returns access to a string that contains hexadecimal image of Value
-- Separate functions that provide build-time customization: -- Separate functions that provide build-time customization:
...@@ -238,7 +241,7 @@ procedure VxAddr2Line is ...@@ -238,7 +241,7 @@ procedure VxAddr2Line is
-- Get_Reference_Offset -- -- Get_Reference_Offset --
-------------------------- --------------------------
function Get_Reference_Offset return Integer is function Get_Reference_Offset return Unsigned_32 is
Nm_Cmd : constant String_Access := Nm_Cmd : constant String_Access :=
Locate_Exec_On_Path (Arch_List (Cur_Arch).Nm_Binary.all); Locate_Exec_On_Path (Arch_List (Cur_Arch).Nm_Binary.all);
...@@ -273,11 +276,11 @@ procedure VxAddr2Line is ...@@ -273,11 +276,11 @@ procedure VxAddr2Line is
declare declare
Match_String : constant String := Expect_Out_Match (Pd); Match_String : constant String := Expect_Out_Match (Pd);
Matches : Match_Array (0 .. 1); Matches : Match_Array (0 .. 1);
Value : Integer; Value : Unsigned_32;
begin begin
Match (Reference, Match_String, Matches); Match (Reference, Match_String, Matches);
Value := Integer'Value Value := Unsigned_32'Value
("16#" ("16#"
& Match_String (Matches (1).First .. Matches (1).Last) & "#"); & Match_String (Matches (1).First .. Matches (1).Last) & "#");
...@@ -313,7 +316,7 @@ procedure VxAddr2Line is ...@@ -313,7 +316,7 @@ procedure VxAddr2Line is
-- Get_Value_From_Hex_Arg -- -- Get_Value_From_Hex_Arg --
---------------------------- ----------------------------
function Get_Value_From_Hex_Arg (Arg : Natural) return Integer is function Get_Value_From_Hex_Arg (Arg : Natural) return Unsigned_32 is
Cur_Arg : constant String := Argument (Arg); Cur_Arg : constant String := Argument (Arg);
Offset : Natural; Offset : Natural;
...@@ -332,19 +335,26 @@ procedure VxAddr2Line is ...@@ -332,19 +335,26 @@ procedure VxAddr2Line is
-- Convert to value -- Convert to value
return Integer'Value ("16#" & Cur_Arg (Offset .. Cur_Arg'Last) & "#"); return Unsigned_32'Value
("16#" & Cur_Arg (Offset .. Cur_Arg'Last) & "#");
exception
when Constraint_Error =>
Error ("Can't parse backtrace address '" & Cur_Arg & "'");
raise;
end Get_Value_From_Hex_Arg; end Get_Value_From_Hex_Arg;
--------------- ---------------
-- Hex_Image -- -- Hex_Image --
--------------- ---------------
function Hex_Image (Value : Integer) return String_Access is function Hex_Image (Value : Unsigned_32) return String_Access is
Result : String (1 .. 20); Result : String (1 .. 20);
Start_Pos : Natural; Start_Pos : Natural;
begin begin
Put (Result, Value, 16); Unsigned_32_IO.Put (Result, Value, 16);
Start_Pos := Index (Result, "16#") + 3; Start_Pos := Index (Result, "16#") + 3;
return new String'(Result (Start_Pos .. Result'Last - 1)); return new String'(Result (Start_Pos .. Result'Last - 1));
end Hex_Image; end Hex_Image;
...@@ -362,7 +372,7 @@ procedure VxAddr2Line is ...@@ -362,7 +372,7 @@ procedure VxAddr2Line is
OS_Exit (1); OS_Exit (1);
end Usage; end Usage;
Ref_Static_Offset, Ref_Runtime_Address, Bt_Address : Integer; Ref_Static_Offset, Ref_Runtime_Address, Bt_Address : Unsigned_32;
Addr2line_Cmd : String_Access; Addr2line_Cmd : String_Access;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment