forked from AdaCore/gnatcoverage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disassemblers.adb
98 lines (86 loc) · 3.49 KB
/
disassemblers.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
------------------------------------------------------------------------------
-- --
-- GNATcoverage --
-- --
-- Copyright (C) 2008-2021, AdaCore --
-- --
-- GNATcoverage is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This software is distributed in the hope that it will be useful --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with Arch;
with Interfaces; use Interfaces;
with Hex_Images; use Hex_Images;
with Outputs;
with Version;
package body Disassemblers is
---------
-- "<" --
---------
function "<" (Left, Right : Dest) return Boolean is
begin
if Left.Target < Right.Target then
return True;
elsif Left.Target > Right.Target then
return False;
else
return Left.Delay_Slot < Right.Delay_Slot;
end if;
end "<";
function Dump_Bin (Bin : Binary_Content; Size : Positive) return String;
-- Return a hexadecimal dump for the first Size bytes of the given binary
-- content. A shorter dump is returned if there aren't enough bytes.
--------------
-- Dump_Bin --
--------------
function Dump_Bin (Bin : Binary_Content; Size : Positive) return String
is
Dump : Unbounded_String;
I : Arch.Arch_Addr := Bin.First;
begin
while I <= Bin.Last and then Natural (I - Bin.First) < Size loop
if I > Bin.First then
Append (Dump, " ");
end if;
Append (Dump, Hex_Image (Get (Bin, I)));
I := I + 1;
end loop;
if Length (Dump) = 0 then
Append (Dump, "<empty>");
end if;
return To_String (Dump);
end Dump_Bin;
------------------------------
-- Abort_Disassembler_Error --
------------------------------
procedure Abort_Disassembler_Error
(PC : Pc_Type;
Insn_Bin : Binary_Content;
Exn_Info : String) is
begin
New_Line (Standard_Error);
Put_Line (Standard_Error, "========================================");
Put_Line
(Standard_Error,
"An error occurred while disassembling the instruction at "
& Hex_Image (PC) & ":");
Put (Standard_Error, Exn_Info);
Put_Line
(Standard_Error,
"The involved bytes are: " & Dump_Bin (Insn_Bin, 20));
Put_Line
(Standard_Error,
"This is GNATcoverage " & Version.Xcov_Version);
Outputs.Error ("Aborting.");
raise Outputs.Xcov_Exit_Exc;
end Abort_Disassembler_Error;
end Disassemblers;