]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Print gnat diagnostics with the gnat command
authorViljar Indus <indus@adacore.com>
Tue, 25 Nov 2025 12:46:08 +0000 (14:46 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 9 Jan 2026 10:57:19 +0000 (11:57 +0100)
Remove the support for printing the diagnostic report
in the compiler when -gnatd_E is used. Instead print it
when the "gnat --diagnostics" command is used.

gcc/ada/ChangeLog:

* debug.adb: remove use case for -gnatd_E
* errout.adb (Output_Messages): remove printing of
the diagnostic repository when -gnatd_E is used.
* gnatcmd.adb: Add support for printing the diagnostic repository.

gcc/ada/debug.adb
gcc/ada/errout.adb
gcc/ada/gnatcmd.adb

index 4c0435e0bd52b308dea48f6b51985f52ebcdc136..f6acb2644944071bcebe4189013a766624a463cb 100644 (file)
@@ -169,7 +169,7 @@ package body Debug is
    --  d_B  Warn on build-in-place function calls
    --  d_C
    --  d_D
-   --  d_E  Print diagnostics and switch repository
+   --  d_E
    --  d_F  Encode full invocation paths in ALI files
    --  d_G
    --  d_H
index a5c68dd87183d5f64c94226e561936941dfa9520..59993da9608b0d31cbff18302aa397487f69be92 100644 (file)
@@ -2889,7 +2889,6 @@ package body Errout is
 
       Sarif_File_Name       : constant String :=
         Get_First_Main_File_Name & ".gnat.sarif";
-      Diagnostics_File_Name : constant String := "gnat_diagnostics.sarif";
 
       Printer : Erroutc.SARIF_Emitter.SARIF_Printer;
 
@@ -2997,28 +2996,6 @@ package body Errout is
          end if;
       end if;
 
-      if Debug_Flag_Underscore_EE then
-
-         --  Print the diagnostics repository to a file
-
-         System.OS_Lib.Delete_File (Diagnostics_File_Name, Dummy);
-         declare
-            Output_FD : constant System.OS_Lib.File_Descriptor :=
-              System.OS_Lib.Create_New_File
-                (Diagnostics_File_Name,
-                 Fmode => System.OS_Lib.Text);
-
-         begin
-            Set_Output (Output_FD);
-
-            Print_Diagnostic_Repository;
-
-            Set_Standard_Output;
-
-            System.OS_Lib.Close (Output_FD);
-         end;
-      end if;
-
       --  Full source listing case
 
       if Full_List then
index 5e3802e7f8ae051eecefac5e6078c7054777d304..adfea9c7bd35c7757c283b1651453672ae2afeec 100644 (file)
 ------------------------------------------------------------------------------
 
 with Gnatvsn;
+with Errid;    use Errid;
 with Namet;    use Namet;
 with Opt;      use Opt;
 with Osint;    use Osint;
 with Output;   use Output;
 with Switch;   use Switch;
+with System.OS_Lib;
 with Table;
 with Usage;
 
@@ -47,6 +49,10 @@ procedure GNATCmd is
    Ada_Help_Switch : constant String := "--help-ada";
    --  Flag to display available build switches
 
+   Ada_Diagnostics_Switch : constant String := "--diagnostics";
+
+   Diagnostics_File_Name : constant String := "gnat_diagnostics.sarif";
+
    Error_Exit : exception;
    --  Raise this exception if error detected
 
@@ -113,6 +119,7 @@ procedure GNATCmd is
 
    My_Exit_Status : Exit_Status := Success;
    --  The exit status of the spawned tool
+   Dummy : Boolean;
 
    type Command_Entry is record
       Cname : String_Access;
@@ -347,6 +354,29 @@ begin
             Keep_Temporary_Files := True;
             Command_Arg := Command_Arg + 1;
 
+         elsif Command_Arg <= Argument_Count
+           and then Argument (Command_Arg) = Ada_Diagnostics_Switch
+         then
+            --  Print the diagnostics repository to a file
+
+            System.OS_Lib.Delete_File (Diagnostics_File_Name, Dummy);
+            declare
+               Output_FD : constant System.OS_Lib.File_Descriptor :=
+                 System.OS_Lib.Create_New_File
+                   (Diagnostics_File_Name, Fmode => System.OS_Lib.Text);
+
+            begin
+               Set_Output (Output_FD);
+               Print_Diagnostic_Repository;
+               Set_Standard_Output;
+               System.OS_Lib.Close (Output_FD);
+            end;
+
+            Write_Line
+              ("gnat diagnostic information exported to "
+               & Diagnostics_File_Name);
+            Exit_Program (E_Success);
+
          elsif Command_Arg <= Argument_Count
            and then Argument (Command_Arg) = Ada_Help_Switch
          then