Repository navigation
Expand file tree
/
Copy pathsymbol.adb
More file actions
100 lines (91 loc) · 4.25 KB
/
Copy pathsymbol.adb
File metadata and controls
100 lines (91 loc) · 4.25 KB
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
99
100
-----------------------------------------------------------------------
-- symbol -- Bfd Ada example to load and search a symbol in the symbol table
-- Copyright (C) 2012, 2015 Free Software Foundation, Inc.
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- This file is part of BfdAda.
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as
-- published by the Free Software Foundation; either version 2,
-- or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY 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
-- along with this program; see the file COPYING. If not, write to
-- the Free Software Foundation,51 Franklin Street - Fifth Floor,
-- Boston, MA 02110-1301, USA.
-----------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Command_Line;
with Bfd;
with Bfd.Files;
with Bfd.Sections;
with Bfd.Symbols;
procedure Symbol is
use type Bfd.Symbols.Symbol;
use type Bfd.Symbol_Flags;
Count : constant Natural := Ada.Command_Line.Argument_Count;
begin
if Count < 2 then
Ada.Text_IO.Put_Line ("Usage: symbol obj-file symbol ...");
return;
end if;
Bfd.Set_Error_Program_Name (To => "symbol");
declare
Path : constant String := Ada.Command_Line.Argument (1);
File : Bfd.Files.File_Type;
Symbols : Bfd.Symbols.Symbol_Table;
begin
Bfd.Files.Open (File, Path, "");
if Bfd.Files.Check_Format (File, Bfd.Files.OBJECT) then
Bfd.Symbols.Read_Symbols (File, Symbols);
for I in 2 .. Count loop
declare
Name : constant String := Ada.Command_Line.Argument (I);
Sym : constant Bfd.Symbols.Symbol := Bfd.Symbols.Get_Symbol (Symbols, Name);
begin
if Sym /= Bfd.Symbols.Null_Symbol then
declare
Sec : constant Bfd.Sections.Section := Bfd.Symbols.Get_Section (Sym);
Flags : constant Bfd.Symbol_Flags := Bfd.Symbols.Get_Flags (Sym);
Value : constant Bfd.Symbol_Value := Bfd.Symbols.Get_Value (Sym);
Size : constant Bfd.Symbol_Value := Bfd.Symbols.Get_Symbol_Size (Sym);
begin
if Bfd.Sections.Is_Undefined_Section (Sec) then
Ada.Text_IO.Put_Line (Name & ": undefined symbol");
elsif (Flags and Bfd.Symbols.BSF_GLOBAL) /= 0 then
Ada.Text_IO.Put_Line (Name & ": global symbol in section "
& Bfd.Sections.Get_Name (Sec)
& "(" & Bfd.Symbol_Value'Image (Value) & ")"
& " - " & Bfd.Symbol_Value'Image (Size));
elsif (Flags and Bfd.Symbols.BSF_LOCAL) /= 0 then
Ada.Text_IO.Put_Line (Name & ": local symbol in section "
& Bfd.Sections.Get_Name (Sec)
& "(" & Bfd.Symbol_Value'Image (Value) & ")"
& " - " & Bfd.Symbol_Value'Image (Size));
else
Ada.Text_IO.Put_Line (Name & ": other symbol in section "
& Bfd.Sections.Get_Name (Sec)
& "(" & Bfd.Symbol_Value'Image (Value) & ")");
end if;
end;
else
Ada.Text_IO.Put_Line (Name & ": not found");
end if;
end;
end loop;
end if;
Bfd.Files.Close (File);
exception
when Bfd.OPEN_ERROR =>
Ada.Text_IO.Put_Line (Ada.Text_IO.Standard_Error,
"Cannot open file '" & Path
& "': " & Bfd.Get_Error_Message (Bfd.Get_Error));
Ada.Command_Line.Set_Exit_Status (1);
end;
end Symbol;