Patchwork [Ada] Improve debugging facilities

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 29, 2011, 1:55 p.m.
Message ID <20110829135514.GA21498@adacore.com>
Download mbox | patch
Permalink /patch/112057/
State New
Headers show

Comments

Arnaud Charlet - Aug. 29, 2011, 1:55 p.m.
This patch adds new debugging routines (pp to print a node, node list, name_id,
 etc., and ppp to print a tree). No change in functionality; no test available.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-29  Bob Duff  <duff@adacore.com>

	* treepr.ads: Improve debugging facilities. pn(x) no longer crashes in
	gdb when x is not a node (it can be a node list, name_id, etc). pp is
	an alias for pn. ppp is an alias for pt.

Patch

Index: treepr.adb
===================================================================
--- treepr.adb	(revision 178155)
+++ treepr.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -263,11 +263,40 @@ 
    -- pn --
    --------
 
-   procedure pn (N : Node_Id) is
+   procedure pn (N : Union_Id) is
    begin
-      Print_Tree_Node (N);
+      case N is
+         when List_Low_Bound .. List_High_Bound - 1 =>
+            pl (Int (N));
+         when Node_Range =>
+            Print_Tree_Node (Node_Id (N));
+         when Elist_Range =>
+            Print_Tree_Elist (Elist_Id (N));
+         when Elmt_Range =>
+            raise Program_Error;
+         when Names_Range =>
+            Namet.wn (Name_Id (N));
+         when Strings_Range =>
+            Write_String_Table_Entry (String_Id (N));
+         when Uint_Range =>
+            Uintp.pid (From_Union (N));
+         when Ureal_Range =>
+            Urealp.pr (From_Union (N));
+         when others =>
+            Write_Str ("Invalid Union_Id: ");
+            Write_Int (Int (N));
+      end case;
    end pn;
 
+   --------
+   -- pp --
+   --------
+
+   procedure pp (N : Union_Id) is
+   begin
+      pn (N);
+   end pp;
+
    ----------------
    -- Print_Char --
    ----------------
@@ -1471,6 +1500,15 @@ 
       Print_Node_Subtree (N);
    end pt;
 
+   ---------
+   -- ppp --
+   ---------
+
+   procedure ppp (N : Node_Id) is
+   begin
+      pt (N);
+   end ppp;
+
    -------------------
    -- Serial_Number --
    -------------------
Index: treepr.ads
===================================================================
--- treepr.ads	(revision 178155)
+++ treepr.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -57,25 +57,36 @@ 
    --  Prints the subtree consisting of the given element list and all its
    --  referenced descendants.
 
+   --  The following debugging procedures are intended to be called from gdb
+
+   procedure pp (N : Union_Id);
+   pragma Export (Ada, pp);
+   --  Prints a node, node list, uint, or anything else that falls under
+   --  Union_Id.
+
+   procedure ppp (N : Node_Id);
+   pragma Export (Ada, ppp);
+   --  Same as Print_Node_Subtree
+
+   --  The following are no longer needed; you can use pp or ppp instead
+
    procedure pe (E : Elist_Id);
    pragma Export (Ada, pe);
-   --  Debugging procedure (to be called within gdb), same as Print_Tree_Elist
+   --  Same as Print_Tree_Elist
 
    procedure pl (L : Int);
    pragma Export (Ada, pl);
-   --  Debugging procedure (to be called within gdb), same as Print_Tree_List,
-   --  except that you can use e.g. 66 instead of -99999966. In other words
-   --  for the positive case we fill out to 8 digits on the left and add a
-   --  minus sign. This just saves some typing in the debugger.
+   --  Same as Print_Tree_List, except that you can use e.g. 66 instead of
+   --  -99999966. In other words for the positive case we fill out to 8 digits
+   --  on the left and add a minus sign. This just saves some typing in the
+   --  debugger.
 
-   procedure pn (N : Node_Id);
+   procedure pn (N : Union_Id);
    pragma Export (Ada, pn);
-   --  Debugging procedure (to be called within gdb)
-   --  same as Print_Tree_Node with Label = ""
+   --  Same as pp
 
    procedure pt (N : Node_Id);
    pragma Export (Ada, pt);
-   --  Debugging procedure (to be called within gdb)
-   --  same as Print_Node_Subtree
+   --  Same as ppp
 
 end Treepr;