From: Eric Botcazou <ebotca...@adacore.com>

The load address of PIE executables is printed in non-symbolic backtraces
(-E binder switch) but it makes sense to print it in symbolic backtraces
(-Es binder switch) too, because symbolic backtraces may degenerate into
non-symbolic ones when the executable is stripped for example.

gcc/ada/ChangeLog:
        * libgnat/s-trasym__dwarf.adb (LDAD_Header): New String constant.
        (Symbolic_Traceback): Print the load address of the executable at
        the beginning if it is not null.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-trasym__dwarf.adb | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/libgnat/s-trasym__dwarf.adb 
b/gcc/ada/libgnat/s-trasym__dwarf.adb
index 1b368040728..6182316da55 100644
--- a/gcc/ada/libgnat/s-trasym__dwarf.adb
+++ b/gcc/ada/libgnat/s-trasym__dwarf.adb
@@ -637,14 +637,24 @@ package body System.Traceback.Symbolic is
    -- Symbolic_Traceback --
    ------------------------
 
+   LDAD_Header : constant String := "Load address: ";
+   --  Copied from Ada.Exceptions.Exception_Data
+
    function Symbolic_Traceback
      (Traceback    : Tracebacks_Array;
       Suppress_Hex : Boolean) return String
    is
-      Res : Bounded_String (Max_Length => Max_String_Length);
+      Load_Address : constant Address := Get_Executable_Load_Address;
+      Res          : Bounded_String (Max_Length => Max_String_Length);
+
    begin
       System.Soft_Links.Lock_Task.all;
       Init_Exec_Module;
+      if Load_Address /= Null_Address then
+         Append (Res, LDAD_Header);
+         Append_Address (Res, Load_Address);
+         Append (Res, ASCII.LF);
+      end if;
       Symbolic_Traceback_No_Lock (Traceback, Suppress_Hex, Res);
       System.Soft_Links.Unlock_Task.all;
 
-- 
2.43.0

Reply via email to