File : s-traceb-xi-arm.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . T R A C E B A C K --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1999-2015, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
18 -- --
19 -- --
20 -- --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This is the bare board version of this package for ARM targets
33 with System.Machine_Code; use System.Machine_Code;
34
35 package body System.Traceback is
36
37 function Return_Address (Level : Natural) return System.Address;
38 pragma Import (Intrinsic, Return_Address, "__builtin_return_address");
39
40 ----------------
41 -- Call_Chain --
42 ----------------
43
44 procedure Call_Chain
45 (Traceback : in out System.Traceback_Entries.Tracebacks_Array;
46 Max_Len : Natural;
47 Len : out Natural;
48 Exclude_Min : System.Address := System.Null_Address;
49 Exclude_Max : System.Address := System.Null_Address;
50 Skip_Frames : Natural := 1)
51 is
52 begin
53 Len := 0;
54
55 -- On ARM, no traceback is possible without extra unwind information,
56 -- so we can at most return our own address and that of our caller.
57
58 for J in 1 .. Max_Len loop
59 case J + Skip_Frames - 1 is
60 when 0 => Asm ("mov %0,pc", Outputs => Address'Asm_Output
61 ("=r", Traceback (Traceback'First + Len)),
62 Volatile => True);
63 when 1 => Traceback (Traceback'First + Len) := Return_Address (0);
64 when others => exit;
65 end case;
66
67 if Traceback (Len + 1) not in Exclude_Min .. Exclude_Max then
68 Len := Len + 1;
69 end if;
70 end loop;
71 end Call_Chain;
72
73 end System.Traceback;