aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-04-22 16:52:14 +0200
committerMarc Poulhiès <poulhies@adacore.com>2024-06-13 15:30:27 +0200
commit22085d1900b9c3e214f837a5549e9c9c56a69b99 (patch)
tree3b8bede4c0b99d24c1e847cc2e3f656fa5df439e
parent9e490bea69205ec4cad8caf21f19d8a8a89a7b43 (diff)
downloadgcc-22085d1900b9c3e214f837a5549e9c9c56a69b99.zip
gcc-22085d1900b9c3e214f837a5549e9c9c56a69b99.tar.gz
gcc-22085d1900b9c3e214f837a5549e9c9c56a69b99.tar.bz2
ada: Add support for symbolic backtraces with DLLs on Windows
This puts Windows on par with Linux as far as backtraces are concerned. gcc/ada/ * libgnat/s-tsmona__linux.adb (Get): Move down descriptive comment. * libgnat/s-tsmona__mingw.adb: Add with clause and use clause for System.Storage_Elements. (Get): Pass GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT in the call to GetModuleHandleEx and remove the subsequent call to FreeLibrary. Upon success, set Load_Addr to the base address of the module. * libgnat/s-win32.ads (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS): Use shorter literal. (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT): New constant.
-rw-r--r--gcc/ada/libgnat/s-tsmona__linux.adb34
-rw-r--r--gcc/ada/libgnat/s-tsmona__mingw.adb20
-rw-r--r--gcc/ada/libgnat/s-win32.ads3
3 files changed, 29 insertions, 28 deletions
diff --git a/gcc/ada/libgnat/s-tsmona__linux.adb b/gcc/ada/libgnat/s-tsmona__linux.adb
index 417b57f..4545399 100644
--- a/gcc/ada/libgnat/s-tsmona__linux.adb
+++ b/gcc/ada/libgnat/s-tsmona__linux.adb
@@ -30,7 +30,8 @@
------------------------------------------------------------------------------
-- This is the GNU/Linux specific version of this package
-with Interfaces.C; use Interfaces.C;
+
+with Interfaces.C; use Interfaces.C;
separate (System.Traceback.Symbolic)
@@ -41,18 +42,6 @@ package body Module_Name is
function Is_Shared_Lib (Base : Address) return Boolean;
-- Returns True if a shared library
- -- The principle is:
-
- -- 1. We get information about the module containing the address.
-
- -- 2. We check that the full pathname is pointing to a shared library.
-
- -- 3. for shared libraries, we return the non relocated address (so
- -- the absolute address in the shared library).
-
- -- 4. we also return the full pathname of the module containing this
- -- address.
-
-------------------
-- Is_Shared_Lib --
-------------------
@@ -139,11 +128,22 @@ package body Module_Name is
-- Get --
---------
- function Get (Addr : System.Address;
- Load_Addr : access System.Address)
- return String
- is
+ -- The principle is:
+
+ -- 1. We get information about the module containing the address.
+
+ -- 2. We check whether the module is a shared library.
+ -- 3. For shared libraries, we return the non-relocated address (so
+ -- the absolute address in the shared library).
+
+ -- 4. We also return the full pathname of the module containing this
+ -- address.
+
+ function Get
+ (Addr : System.Address;
+ Load_Addr : access System.Address) return String
+ is
-- Dl_info record for Linux, used to get sym reloc offset
type Dl_info is record
diff --git a/gcc/ada/libgnat/s-tsmona__mingw.adb b/gcc/ada/libgnat/s-tsmona__mingw.adb
index 3100db0..61264da 100644
--- a/gcc/ada/libgnat/s-tsmona__mingw.adb
+++ b/gcc/ada/libgnat/s-tsmona__mingw.adb
@@ -31,7 +31,8 @@
-- This is the Windows specific version of this package
-with System.Win32; use System.Win32;
+with System.Storage_Elements; use System.Storage_Elements;
+with System.Win32; use System.Win32;
separate (System.Traceback.Symbolic)
@@ -50,27 +51,26 @@ package body Module_Name is
-- Get --
---------
- function Get (Addr : System.Address;
- Load_Addr : access System.Address)
- return String
+ function Get
+ (Addr : System.Address;
+ Load_Addr : access System.Address) return String
is
Res : DWORD;
hModule : aliased HANDLE;
- Path : String (1 .. 1_024);
+ Path : String (1 .. 1024);
begin
Load_Addr.all := System.Null_Address;
if GetModuleHandleEx
- (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS +
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
Addr,
hModule'Access) = Win32.TRUE
then
- Res := GetModuleFileName (hModule, Path'Address, Path'Length);
+ Load_Addr.all := To_Address (Integer_Address (hModule));
- if FreeLibrary (hModule) = Win32.FALSE then
- null;
- end if;
+ Res := GetModuleFileName (hModule, Path'Address, Path'Length);
if Res > 0 then
return Path (1 .. Positive (Res));
diff --git a/gcc/ada/libgnat/s-win32.ads b/gcc/ada/libgnat/s-win32.ads
index 6e8e246..963cb57 100644
--- a/gcc/ada/libgnat/s-win32.ads
+++ b/gcc/ada/libgnat/s-win32.ads
@@ -157,7 +157,8 @@ package System.Win32 is
FILE_ATTRIBUTE_VALID_FLAGS : constant := 16#00007fb7#;
FILE_ATTRIBUTE_VALID_SET_FLAGS : constant := 16#000031a7#;
- GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS : constant := 16#00000004#;
+ GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS : constant := 16#04#;
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT : constant := 16#02#;
type OVERLAPPED is record
Internal : access ULONG;