]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
improve Ada exception catchpoint MI notification
authorJoel Brobecker <brobecker@gnat.com>
Tue, 17 May 2011 21:25:57 +0000 (21:25 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Tue, 17 May 2011 21:25:57 +0000 (21:25 +0000)
This rewrites the code generating the Ada exception catchpoint hit
notification for both the GDB/MI case as well as the non-MI case,
by using the relevant ui_out_* functions to generate the output.
the MI notifications for Ada exception catchpoints now include
the stop reason, and the breakpoint "disp", much like other breakpoint
events do.  It also introduces a new field "exception-name" for
exception catchpoints (excluding "failed assertion catchpoints,
where we just want to know that it was a failed assertion).

gdb/ChangeLog:

        * breakpoint.h (bpdisp_text): Add declaration.
        * breakpoint.c (bpdisp_text): Make non-static.
        * ada-lang.c: #include "mi/mi-common.h".
        (print_it_exception): Rewrite to improve GDB/MI output.

gdb/doc/ChangeLog:

        * gdb.texinfo (GDB/MI Ada Exception Information): Document
        the "exception-name" field in the *stopped async record.

gdb/testsuite/ChangeLog:

        * gdb.ada/mi_catch_ex: New testcase.

gdb/ChangeLog
gdb/ada-lang.c
gdb/breakpoint.c
gdb/breakpoint.h
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/testsuite/ChangeLog

index 336a47ea462501a6df66fac224d61191da04609f..94e14bd71bbd5cec329e44c729399f0a20253a08 100644 (file)
@@ -1,3 +1,10 @@
+2011-04-01  Joel Brobecker  <brobecker@adacore.com>
+
+       * breakpoint.h (bpdisp_text): Add declaration.
+       * breakpoint.c (bpdisp_text): Make non-static.
+       * ada-lang.c: #include "mi/mi-common.h".
+       (print_it_exception): Rewrite to improve GDB/MI output.
+
 2011-04-01  Pedro Alves  <pedro@codesourcery.com>
 
        * arm-tdep.h (struct address_space): Add forward declaration.
index 8fc8b1591351659dc6c802551ddb51a476adb0f0..dee69052a50500a27b64eba65bcfe2b888adc36e 100644 (file)
@@ -60,6 +60,7 @@
 
 #include "psymtab.h"
 #include "value.h"
+#include "mi/mi-common.h"
 
 /* Define whether or not the C operator '/' truncates towards zero for
    differently signed operands (truncation direction is undefined in C).
@@ -10744,40 +10745,63 @@ ada_exception_name_addr (enum exception_catchpoint_kind ex,
 static enum print_stop_action
 print_it_exception (enum exception_catchpoint_kind ex, struct breakpoint *b)
 {
-  const CORE_ADDR addr = ada_exception_name_addr (ex, b);
-  char exception_name[256];
+  annotate_catchpoint (b->number);
 
-  if (addr != 0)
+  if (ui_out_is_mi_like_p (uiout))
     {
-      read_memory (addr, exception_name, sizeof (exception_name) - 1);
-      exception_name [sizeof (exception_name) - 1] = '\0';
+      ui_out_field_string (uiout, "reason",
+                          async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
+      ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
     }
 
-  ada_find_printable_frame (get_current_frame ());
+  ui_out_text (uiout, "\nCatchpoint ");
+  ui_out_field_int (uiout, "bkptno", b->number);
+  ui_out_text (uiout, ", ");
 
-  annotate_catchpoint (b->number);
   switch (ex)
     {
       case ex_catch_exception:
-        if (addr != 0)
-          printf_filtered (_("\nCatchpoint %d, %s at "),
-                           b->number, exception_name);
-        else
-          printf_filtered (_("\nCatchpoint %d, exception at "), b->number);
-        break;
       case ex_catch_exception_unhandled:
-        if (addr != 0)
-          printf_filtered (_("\nCatchpoint %d, unhandled %s at "),
-                           b->number, exception_name);
-        else
-          printf_filtered (_("\nCatchpoint %d, unhandled exception at "),
-                           b->number);
-        break;
+       {
+         const CORE_ADDR addr = ada_exception_name_addr (ex, b);
+         char exception_name[256];
+
+         if (addr != 0)
+           {
+             read_memory (addr, exception_name, sizeof (exception_name) - 1);
+             exception_name [sizeof (exception_name) - 1] = '\0';
+           }
+         else
+           {
+             /* For some reason, we were unable to read the exception
+                name.  This could happen if the Runtime was compiled
+                without debugging info, for instance.  In that case,
+                just replace the exception name by the generic string
+                "exception" - it will read as "an exception" in the
+                notification we are about to print.  */
+             sprintf (exception_name, "exception");
+           }
+         /* In the case of unhandled exception breakpoints, we print
+            the exception name as "unhandled EXCEPTION_NAME", to make
+            it clearer to the user which kind of catchpoint just got
+            hit.  We used ui_out_text to make sure that this extra
+            info does not pollute the exception name in the MI case.  */
+         if (ex == ex_catch_exception_unhandled)
+           ui_out_text (uiout, "unhandled ");
+         ui_out_field_string (uiout, "exception-name", exception_name);
+       }
+       break;
       case ex_catch_assert:
-        printf_filtered (_("\nCatchpoint %d, failed assertion at "),
-                         b->number);
-        break;
+       /* In this case, the name of the exception is not really
+          important.  Just print "failed assertion" to make it clearer
+          that his program just hit an assertion-failure catchpoint.
+          We used ui_out_text because this info does not belong in
+          the MI output.  */
+       ui_out_text (uiout, "failed assertion");
+       break;
     }
+  ui_out_text (uiout, " at ");
+  ada_find_printable_frame (get_current_frame ());
 
   return PRINT_SRC_AND_LOC;
 }
index f93500f019ddd55a572793cb9d52b96f19469800..ce58ff3c684071baad4cc071dcee2a66b0f6aeb5 100644 (file)
@@ -251,7 +251,7 @@ breakpoint_commands (struct breakpoint *b)
 
 static int breakpoint_proceeded;
 
-static const char *
+const char *
 bpdisp_text (enum bpdisp disp)
 {
   /* NOTE: the following values are a part of MI protocol and
index 18a7ce791ae5f088e63714409585e5d0e3f8b1e3..7a9c2d4729d6a1fd8e7dc0e310caa8041cc95aeb 100644 (file)
@@ -961,6 +961,10 @@ extern void breakpoint_auto_delete (bpstat);
    is hit.  */
 extern struct command_line *breakpoint_commands (struct breakpoint *b);
 
+/* Return a string image of DISP.  The string is static, and thus should
+   NOT be deallocated after use.  */
+const char *bpdisp_text (enum bpdisp disp);
+
 extern void break_command (char *, int);
 
 extern void hbreak_command_wrapper (char *, int);
index 6dc88c16fdb64a3e6952b507d6d57e074f30606a..be75667202c85227e4f5a091b5756f06f2086f4c 100644 (file)
@@ -1,3 +1,8 @@
+2011-04-01  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.texinfo (GDB/MI Ada Exception Information): Document
+       the "exception-name" field in the *stopped async record.
+
 2011-05-03  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.texinfo (titlepage): Dedicate GDB version 7.3 to
index 437ca43ec6b7c1a1be72c3a90a4fef7eef889e6d..010eb8b34fecb05bf1e0a2d94a9386f17bbea250 100644 (file)
@@ -24947,6 +24947,7 @@ follow development on @email{gdb@@sourceware.org} and
 * GDB/MI Async Records::
 * GDB/MI Frame Information::
 * GDB/MI Thread Information::
+* GDB/MI Ada Exception Information
 @end menu
 
 @node GDB/MI Result Records
@@ -25212,6 +25213,13 @@ The value of this field is an integer number of the processor core the
 thread was last seen on.  This field is optional.
 @end table
 
+@node GDB/MI Ada Exception Information
+@subsection @sc{gdb/mi} Ada Exception Information
+
+Whenever a @code{*stopped} record is emitted because the program
+stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
+@value{GDBN} provides the name of the exception that was raised via
+the @code{exception-name} field.
 
 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 @node GDB/MI Simple Examples
index 2fe165ce89b0b18cb584a2da53027ddcfe0f9350..cfe84a3bece7a66e95efd0daaa4e5cd614d1e1ac 100644 (file)
@@ -1,3 +1,7 @@
+2011-04-01  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.ada/mi_catch_ex: New testcase.
+
 2011-04-01  Pedro Alves  <pedro@codesourcery.com>
 
        * gdb.cp/cpexprs.exp (Overloaded methods): No longer try the