From 3340a7acff26413f967cd6909e1fc8b9cb1839ef Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Wed, 10 Jun 2020 17:25:07 +0200 Subject: [PATCH] Move the Alr.Main exception handler to a last chance handler (#442) * Move the Alr.Main exception handler to a last chance handler This way the exceptions raised during elaboration will also be caught. #441 * Alr.Main: restore an exception handler to catch after elaboration Relying only on the __gnat_last_chance_handler means that an extra backtrace is printed by the GNAT run-time (with Notify_Unhandled_Exception). --- src/alr/alr-main.adb | 11 +++-------- src/alr/last_chance_handler.adb | 14 ++++++++++++++ src/alr/last_chance_handler.ads | 4 ++++ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src/alr/last_chance_handler.adb create mode 100644 src/alr/last_chance_handler.ads diff --git a/src/alr/alr-main.adb b/src/alr/alr-main.adb index 89aaf964..1018bada 100644 --- a/src/alr/alr-main.adb +++ b/src/alr/alr-main.adb @@ -1,13 +1,13 @@ with Alire; with Alire_Early_Elaboration; pragma Elaborate_All (Alire_Early_Elaboration); -with Alire.Errors; with Alr.Bootstrap; with Alr.Commands; -with Alr.OS_Lib; with Alr.Platform.Init; with Alr.Platforms.Current; +with Last_Chance_Handler; + procedure Alr.Main is begin Alr.Platform.Init (Alr.Platforms.Current.New_Platform); @@ -16,11 +16,6 @@ begin Commands.Execute; exception - -- Ensure we do not show an exception trace to unsuspecting users when E : others => - Alire.Log_Exception (E); - Trace.Error (Alire.Errors.Get (E)); - Trace.Error ("alr encountered an unexpected error," - & " re-run with -d for details."); - OS_Lib.Bailout (1); + Last_Chance_Handler (E); end Alr.Main; diff --git a/src/alr/last_chance_handler.adb b/src/alr/last_chance_handler.adb new file mode 100644 index 00000000..f8e39728 --- /dev/null +++ b/src/alr/last_chance_handler.adb @@ -0,0 +1,14 @@ +with Alire.Errors; + +with Alr; +with Alr.OS_Lib; + +procedure Last_Chance_Handler (E : Ada.Exceptions.Exception_Occurrence) is +begin + -- Ensure we do not show an exception trace to unsuspecting users + Alire.Log_Exception (E); + Alr.Trace.Error (Alire.Errors.Get (E)); + Alr.Trace.Error ("alr encountered an unexpected error," + & " re-run with -d for details."); + Alr.OS_Lib.Bailout (1); +end Last_Chance_Handler; diff --git a/src/alr/last_chance_handler.ads b/src/alr/last_chance_handler.ads new file mode 100644 index 00000000..eeb015c6 --- /dev/null +++ b/src/alr/last_chance_handler.ads @@ -0,0 +1,4 @@ +with Ada.Exceptions; + +procedure Last_Chance_Handler (E : Ada.Exceptions.Exception_Occurrence); +pragma Export (C, Last_Chance_Handler, "__gnat_last_chance_handler"); -- 2.39.5