This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] (Ada) New command to stop at start of exception handlers.


Hi Xavier,

Almost there...

On Tue, Dec 19, 2017 at 03:29:25PM +0100, Xavier Roirand wrote:
> When using gdb for debugging Ada source code, there are several catchpoint
> types you can define in order to stop upon certain conditions.  Let's
> use this small example:
> 
> procedure Foo is
> begin
>    begin
>       raise Constraint_Error;
>    exception
>       when Program_Error =>
>          null;
>       when Constraint_Error =>
>          null;
>       when others =>
>          null;
>    end;
> end Foo;
> 
> One can stop when the exception is being raised by using the exception
> catchpoint like below:
> 
> (gdb) catch exception
> Catchpoint 1: all Ada exceptions
> (gdb)
> 
> In that case, when running Foo, gdb will stop at the line where the exception
> was raised:
> 
>    begin
> >>>   raise Constraint_Error;
>    exception
> 
> This patch introduces new type of catchpoint, when the user wants to stop
> at the location of the exception handling.
> Imagine we want to stop on any exception handled by the program, we can do:
> 
> (gdb) catch handlers
> Catchpoint 1: all Ada exceptions handlers
> (gdb) r
> Starting program: /tmp/foo
> 
> By doing so, when running Foo, gdb will stop here:
> 
> Catchpoint 1, exception at 0x000000000040255a in foo () at foo.adb:25
> 25          when Constraint_Error =>
> (gdb)
> 
> It is also possible to stop when the Constraint_Error exception is being
> handled in this program.  With this patch, we can use:
> 
> (gdb) catch handlers Constraint_Error
> Catchpoint 1: `Constraint_Error' Ada exception handlers
> (gdb)
> 
> Like for other catchpoint, you can set a condition when adding a catchpoint
> on exception handlers.
> Here the handlers catchpoint checks Global_Var:
> 
> (gdb) catch handlers Constraint_Error if Global_Var /= 0
> 
> gdb/ChangeLog:
> 
>         * ada-lang.h (ada_exception_catchpoint_kind) <ada_catch_handlers>:
>         Add field.
>         * ada-lang.c (struct exception_support_info) <catch_handlers_sym>:
>         Add field.
>         (default_exception_support_info) <catch_handlers_sym>: Add field.
>         (exception_support_info_fallback) <catch_handlers_sym>: Add field.
>         (ada_exception_name_addr_1): Add "catch handlers" handling.
>         (ada_exception_catchpoint_cond_string) <ex>: New parameter.
>         Update all callers.
>         (create_excep_cond_exprs) <ex>: Add parameter.
>         (re_set_exception): Update create_excep_cond_exprs call.
>         (print_it_exception, print_one_exception, print_mention_exception)
>         (print_recreate_exception): Add "catch handler" handling.
>         (allocate_location_catch_handlers, re_set_catch_handlers)
>         (check_status_catch_handlers, print_it_catch_handlers)
>         (print_one_catch_handlers, print_mention_catch_handlers)
>         (print_recreate_catch_handlers): New function.

You need to document the addition of "catch_handlers_breakpoint_ops".

>         (catch_ada_exception_command_split) <is_catch_handlers_cmd>:
>         Add parameter.  Add "catch handler" handling.
>         (ada_exception_sym_name, ada_exception_breakpoint_ops):
>         Add "catch handler" handling.
>         (ada_exception_catchpoint_cond_string): Add "catch handler"
>         handling.
>         (create_ada_exception_catchpoint): Update create_excep_cond_exprs
>         call.
>         (catch_ada_handlers_command): New function.
>         (initialize_ada_catchpoint_ops): Initialize "catch handlers"
>         operations structure.
>         (_initialize_ada_language): Add "catch handlers" command entry.
>         * NEWS: Document "catch handlers" feature.
> 
> gdb/doc/ChangeLog:
> 
>         * gdb.textinfo (Set Catchpoints): Add documentation for
                ^^^^^^^^
textinfo -> texinfo

Tip: I copy/paste the "stat" information that git provides when
I do a "git commit -v". It helps avoiding these kinds of typos.

>         new "catch handlers" action.
> 
> gdb/testsuite/ChangeLog:

Let's add an empty line after the above as well, to be consistent
with the other ChangeLog entries (others normally do the same as
well, so let's try to follow that layout).

>         gdb.ada/excep_handle.exp: New test.

test -> testcase

>         gdb.ada/excep_handle/foo.adb: New file.
>         gdb.ada/excep_handle/pck.ads: New file.
> ---
>  gdb/NEWS                                   |   3 +
>  gdb/ada-lang.c                             | 213 +++++++++++++++++++++++++----
>  gdb/ada-lang.h                             |   3 +-
>  gdb/doc/gdb.texinfo                        |  19 +++
>  gdb/testsuite/gdb.ada/excep_handle.exp     | 164 ++++++++++++++++++++++
>  gdb/testsuite/gdb.ada/excep_handle/foo.adb | 103 ++++++++++++++
>  gdb/testsuite/gdb.ada/excep_handle/pck.ads |  19 +++
>  7 files changed, 500 insertions(+), 24 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.ada/excep_handle.exp
>  create mode 100644 gdb/testsuite/gdb.ada/excep_handle/foo.adb
>  create mode 100644 gdb/testsuite/gdb.ada/excep_handle/pck.ads
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 44f481d..658d93a 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -665,6 +665,9 @@ show max-value-size
>  * Support for reading/writing memory and extracting values on architectures
>    whose memory is addressable in units of any integral multiple of 8 bits.
>  
> +catch handlers
> +  Allows to break when an Ada exception is handled.
> +
>  * New remote packets
>  
>  exec stop reason
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index dad2b17..3f3295a 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -12021,6 +12021,10 @@ struct exception_support_info
>        a catchpoint on failed assertions.  */
>     const char *catch_assert_sym;
>  
> +   /* The name of the symbol to break on in order to insert
> +      a catchpoint on exception handling.  */
> +   const char *catch_handlers_sym;
> +
>     /* Assuming that the inferior just triggered an unhandled exception
>        catchpoint, this function is responsible for returning the address
>        in inferior memory where the name of that exception is stored.
> @@ -12040,6 +12044,7 @@ static const struct exception_support_info default_exception_support_info =
>    "__gnat_debug_raise_exception", /* catch_exception_sym */
>    "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
>    "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
> +  "__gnat_begin_handler", /* catch_handlers_sym */
>    ada_unhandled_exception_name_addr
>  };
>  
> @@ -12052,6 +12057,7 @@ static const struct exception_support_info exception_support_info_fallback =
>    "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
>    "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
>    "system__assertions__raise_assert_failure",  /* catch_assert_sym */
> +  "__gnat_begin_handler", /* catch_handlers_sym */
>    ada_unhandled_exception_name_addr_from_raise
>  };
>  
> @@ -12320,7 +12326,12 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
>        case ada_catch_exception_unhandled:
>          return data->exception_info->unhandled_exception_name_addr ();
>          break;
> -      
> +
> +      case ada_catch_handlers:
> +        return 0;  /* The runtimes does not provide access to the exception
> +		      name.  */
> +        break;
> +
>        case ada_catch_assert:
>          return 0;  /* Exception name is not relevant in this case.  */
>          break;
> @@ -12426,7 +12437,9 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
>    return result;
>  }
>  
> -static char *ada_exception_catchpoint_cond_string (const char *excep_string);
> +static char *ada_exception_catchpoint_cond_string
> +  (const char *excep_string,
> +   enum ada_exception_catchpoint_kind ex);
>  
>  /* Ada catchpoints.
>  
> @@ -12489,7 +12502,8 @@ struct ada_catchpoint : public breakpoint
>     catchpoint's locations, and store them for later evaluation.  */
>  
>  static void
> -create_excep_cond_exprs (struct ada_catchpoint *c)
> +create_excep_cond_exprs (struct ada_catchpoint *c,
> +                         enum ada_exception_catchpoint_kind ex)
>  {
>    struct cleanup *old_chain;
>    struct bp_location *bl;
> @@ -12505,7 +12519,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
>  
>    /* Compute the condition expression in text form, from the specific
>       expection we want to catch.  */
> -  cond_string = ada_exception_catchpoint_cond_string (c->excep_string);
> +  cond_string = ada_exception_catchpoint_cond_string (c->excep_string, ex);
>    old_chain = make_cleanup (xfree, cond_string);
>  
>    /* Iterate over all the catchpoint's locations, and parse an
> @@ -12573,7 +12587,7 @@ re_set_exception (enum ada_exception_catchpoint_kind ex, struct breakpoint *b)
>  
>    /* Reparse the exception conditional expressions.  One for each
>       location.  */
> -  create_excep_cond_exprs (c);
> +  create_excep_cond_exprs (c, ex);
>  }
>  
>  /* Returns true if we should stop for this breakpoint hit.  If the
> @@ -12662,6 +12676,7 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
>      {
>        case ada_catch_exception:
>        case ada_catch_exception_unhandled:
> +      case ada_catch_handlers:
>  	{
>  	  const CORE_ADDR addr = ada_exception_name_addr (ex, b);
>  	  char exception_name[256];
> @@ -12745,10 +12760,9 @@ print_one_exception (enum ada_exception_catchpoint_kind ex,
>        case ada_catch_exception:
>          if (c->excep_string != NULL)
>            {
> -            char *msg = xstrprintf (_("`%s' Ada exception"), c->excep_string);
> -
> -            uiout->field_string ("what", msg);
> -            xfree (msg);
> +	    uiout->field_fmt ("what", 
> +			      _("`%s' Ada exception"), 
> +			      c->excep_string);

I think this change is independent of the rest of the patch.
I think there is at least one more below (I will point it out).
Let's submit them separately as an independent cleanup, to keep
this patch purely about exception handlers. Can you bunch this
change, and the ones I'll point out below together as a cleanup
patch, and submit it separately? Or, another option is to have
a two-patches series, with the first one being this cleanup, and
the second one being about the new command.

Please note:

  1. Git makes it very easy to do that (think "git reset" and
     also, you can re-use a previous commit's revision log
     when you use the "-c" option of "git commit");

  2. There are trailing spaces on the first two lines. Can you
     remove them, please?

Thank you!

>            }
>          else
>            uiout->field_string ("what", "all Ada exceptions");
> @@ -12759,6 +12773,17 @@ print_one_exception (enum ada_exception_catchpoint_kind ex,
>          uiout->field_string ("what", "unhandled Ada exceptions");
>          break;
>        
> +      case ada_catch_handlers:
> +        if (c->excep_string != NULL)
> +          {
> +	    uiout->field_fmt ("what", 
> +			      _("`%s' Ada exception handlers"), 
> +			      c->excep_string);

Same as above (trailing spaces on a couple of lines).

> +          }
> +        else
> +	  uiout->field_string ("what", "all Ada exceptions handlers");
> +        break;
> +
>        case ada_catch_assert:
>          uiout->field_string ("what", "failed Ada assertions");
>          break;
> @@ -12789,11 +12814,9 @@ print_mention_exception (enum ada_exception_catchpoint_kind ex,
>        case ada_catch_exception:
>          if (c->excep_string != NULL)
>  	  {
> -	    char *info = xstrprintf (_("`%s' Ada exception"), c->excep_string);
> -	    struct cleanup *old_chain = make_cleanup (xfree, info);
> -
> -	    uiout->text (info);
> -	    do_cleanups (old_chain);
> +	    std::string info = string_printf (_("`%s' Ada exception"),
> +					      c->excep_string);
> +	    uiout->text (info.c_str ());

This is another change that could go in the cleanup patch.

>  	  }
>          else
>            uiout->text (_("all Ada exceptions"));
> @@ -12802,7 +12825,19 @@ print_mention_exception (enum ada_exception_catchpoint_kind ex,
>        case ada_catch_exception_unhandled:
>          uiout->text (_("unhandled Ada exceptions"));
>          break;
> -      
> +
> +      case ada_catch_handlers:
> +        if (c->excep_string != NULL)
> +	  {
> +	    std::string info =
> +	      string_printf (_("`%s' Ada exception handlers"),
> +			     c->excep_string);

Formatting: The "=" should be on the next line.

> +	    uiout->text (info.c_str ());
> +	  }
> +        else
> +          uiout->text (_("all Ada exceptions handlers"));
> +        break;
> +
>        case ada_catch_assert:
>          uiout->text (_("failed Ada assertions"));
>          break;
> @@ -12834,6 +12869,10 @@ print_recreate_exception (enum ada_exception_catchpoint_kind ex,
>  	fprintf_filtered (fp, "catch exception unhandled");
>  	break;
>  
> +      case ada_catch_handlers:
> +	fprintf_filtered (fp, "catch handlers");
> +	break;
> +
>        case ada_catch_assert:
>  	fprintf_filtered (fp, "catch assert");
>  	break;
> @@ -12984,6 +13023,54 @@ print_recreate_catch_assert (struct breakpoint *b, struct ui_file *fp)
>  
>  static struct breakpoint_ops catch_assert_breakpoint_ops;
>  
> +/* Virtual table for "catch handlers" breakpoints.  */
> +
> +static struct bp_location *
> +allocate_location_catch_handlers (struct breakpoint *self)
> +{
> +  return allocate_location_exception (ada_catch_handlers, self);
> +}
> +
> +static void
> +re_set_catch_handlers (struct breakpoint *b)
> +{
> +  re_set_exception (ada_catch_handlers, b);
> +}
> +
> +static void
> +check_status_catch_handlers (bpstat bs)
> +{
> +  check_status_exception (ada_catch_handlers, bs);
> +}
> +
> +static enum print_stop_action
> +print_it_catch_handlers (bpstat bs)
> +{
> +  return print_it_exception (ada_catch_handlers, bs);
> +}
> +
> +static void
> +print_one_catch_handlers (struct breakpoint *b,
> +			struct bp_location **last_loc)

The second parameter is mis-aligned (probably after changing
the function name).

> +{
> +  print_one_exception (ada_catch_handlers, b, last_loc);
> +}
> +
> +static void
> +print_mention_catch_handlers (struct breakpoint *b)
> +{
> +  print_mention_exception (ada_catch_handlers, b);
> +}
> +
> +static void
> +print_recreate_catch_handlers (struct breakpoint *b,
> +			     struct ui_file *fp)

Same as above (param alignment)

> +{
> +  print_recreate_exception (ada_catch_handlers, b, fp);
> +}
> +
> +static struct breakpoint_ops catch_handlers_breakpoint_ops;
> +
>  /* Return a newly allocated copy of the first space-separated token
>     in ARGSP, and then adjust ARGSP to point immediately after that
>     token.
> @@ -13022,12 +13109,15 @@ ada_get_next_arg (const char **argsp)
>     Set EX to the appropriate catchpoint type.
>     Set EXCEP_STRING to the name of the specific exception if
>     specified by the user.
> +   IS_CATCH_HANDLERS_CMD: Nonzero if the arguments are for a
> +   "catch handle" command.  Zero otherwise.

This is now a "bool", so we need to update the description of
this parameter to be either "true" or "false".

>     If a condition is found at the end of the arguments, the condition
>     expression is stored in COND_STRING (memory must be deallocated
>     after use).  Otherwise COND_STRING is set to NULL.  */
>  
>  static void
>  catch_ada_exception_command_split (const char *args,
> +				   bool is_catch_handlers_cmd,
>                                     enum ada_exception_catchpoint_kind *ex,
>  				   char **excep_string,
>  				   char **cond_string)
> @@ -13073,7 +13163,13 @@ catch_ada_exception_command_split (const char *args,
>  
>    discard_cleanups (old_chain);
>  
> -  if (exception_name == NULL)
> +  if (is_catch_handlers_cmd)
> +    {
> +      /* Catch handling of exceptions.  */
> +      *ex = ada_catch_handlers;
> +      *excep_string = exception_name;
> +    }
> +  else if (exception_name == NULL)
>      {
>        /* Catch all exceptions.  */
>        *ex = ada_catch_exception;
> @@ -13115,6 +13211,9 @@ ada_exception_sym_name (enum ada_exception_catchpoint_kind ex)
>        case ada_catch_assert:
>          return (data->exception_info->catch_assert_sym);
>          break;
> +      case ada_catch_handlers:
> +        return (data->exception_info->catch_handlers_sym);
> +        break;
>        default:
>          internal_error (__FILE__, __LINE__,
>                          _("unexpected catchpoint kind (%d)"), ex);
> @@ -13138,6 +13237,9 @@ ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex)
>        case ada_catch_assert:
>          return (&catch_assert_breakpoint_ops);
>          break;
> +      case ada_catch_handlers:
> +        return (&catch_handlers_breakpoint_ops);
> +        break;
>        default:
>          internal_error (__FILE__, __LINE__,
>                          _("unexpected catchpoint kind (%d)"), ex);
> @@ -13148,14 +13250,28 @@ ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex)
>     being raised with the exception that the user wants to catch.  This
>     assumes that this condition is used when the inferior just triggered
>     an exception catchpoint.
> +   EX: the type of catchpoints used for catching Ada exceptions.
>     
>     The string returned is a newly allocated string that needs to be
>     deallocated later.  */
>  
>  static char *
> -ada_exception_catchpoint_cond_string (const char *excep_string)
> +ada_exception_catchpoint_cond_string (const char *excep_string,
> +                                      enum ada_exception_catchpoint_kind ex)
>  {
> -  int i;
> +  int i, is_standard_exc = 0;

Sorry I missed in the previous review that is_standard_exc is a boolean,
so it should be a "bool". (make sure to adjust also the values you
assign it to (false here, true below).

> +  const char *actual_exc_expr;
> +  char *ref_exc_expr;
> +
> +  if (ex == ada_catch_handlers)
> +    {
> +      /* For exception handlers catchpoints, the condition string does
> +         not use the same parameter as for the other exceptions.  */
> +      actual_exc_expr = ("long_integer (GNAT_GCC_exception_Access"
> +			 "(gcc_exception).all.occurrence.id)");
> +    }
> +  else
> +    actual_exc_expr = "long_integer (e)";
>  
>    /* The standard exceptions are a special case.  They are defined in
>       runtime units that have been compiled without debugging info; if
> @@ -13180,11 +13296,19 @@ ada_exception_catchpoint_cond_string (const char *excep_string)
>      {
>        if (strcmp (standard_exc [i], excep_string) == 0)
>  	{
> -          return xstrprintf ("long_integer (e) = long_integer (&standard.%s)",
> -                             excep_string);
> +	  is_standard_exc = 1;
> +	  break;
>  	}
>      }
> -  return xstrprintf ("long_integer (e) = long_integer (&%s)", excep_string);
> +
> +  if (is_standard_exc)
> +    ref_exc_expr = xstrprintf ("long_integer (&standard.%s)", excep_string);
> +  else
> +    ref_exc_expr = xstrprintf ("long_integer (&%s)", excep_string);
> +
> +  char *result =  xstrprintf ("%s = %s", actual_exc_expr, ref_exc_expr);
> +  xfree (ref_exc_expr);
> +  return result;
>  }
>  
>  /* Return the symtab_and_line that should be used to insert an exception
> @@ -13267,7 +13391,7 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
>    init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string,
>  				 ops, tempflag, disabled, from_tty);
>    c->excep_string = excep_string;
> -  create_excep_cond_exprs (c.get ());
> +  create_excep_cond_exprs (c.get (), ex_kind);
>    if (cond_string != NULL)
>      set_breakpoint_condition (c.get (), cond_string, from_tty);
>    install_breakpoint (0, std::move (c), 1);
> @@ -13290,7 +13414,32 @@ catch_ada_exception_command (const char *arg_entry, int from_tty,
>  
>    if (!arg)
>      arg = "";
> -  catch_ada_exception_command_split (arg, &ex_kind, &excep_string,
> +  catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string,
> +				     &cond_string);
> +  create_ada_exception_catchpoint (gdbarch, ex_kind,
> +				   excep_string, cond_string,
> +				   tempflag, 1 /* enabled */,
> +				   from_tty);
> +}
> +
> +/* Implement the "catch handlers" command.  */
> +
> +static void
> +catch_ada_handlers_command (const char *arg_entry, int from_tty,
> +			    struct cmd_list_element *command)
> +{
> +  const char *arg = arg_entry;
> +  struct gdbarch *gdbarch = get_current_arch ();
> +  int tempflag;
> +  enum ada_exception_catchpoint_kind ex_kind;
> +  char *excep_string = NULL;
> +  char *cond_string = NULL;
> +
> +  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
> +
> +  if (!arg)
> +    arg = "";
> +  catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string,
>  				     &cond_string);
>    create_ada_exception_catchpoint (gdbarch, ex_kind,
>  				   excep_string, cond_string,
> @@ -14405,6 +14554,16 @@ initialize_ada_catchpoint_ops (void)
>    ops->print_one = print_one_catch_assert;
>    ops->print_mention = print_mention_catch_assert;
>    ops->print_recreate = print_recreate_catch_assert;
> +
> +  ops = &catch_handlers_breakpoint_ops;
> +  *ops = bkpt_breakpoint_ops;
> +  ops->allocate_location = allocate_location_catch_handlers;
> +  ops->re_set = re_set_catch_handlers;
> +  ops->check_status = check_status_catch_handlers;
> +  ops->print_it = print_it_catch_handlers;
> +  ops->print_one = print_one_catch_handlers;
> +  ops->print_mention = print_mention_catch_handlers;
> +  ops->print_recreate = print_recreate_catch_handlers;
>  }
>  
>  /* This module's 'new_objfile' observer.  */
> @@ -14465,6 +14624,14 @@ With an argument, catch only exceptions with the given name."),
>                       NULL,
>  		     CATCH_PERMANENT,
>  		     CATCH_TEMPORARY);
> +
> +  add_catch_command ("handlers", _("\
> +Catch Ada exceptions, when handled.\n\
> +With an argument, catch only exceptions with the given name."),
> +		     catch_ada_handlers_command,
> +                     NULL,
> +		     CATCH_PERMANENT,
> +		     CATCH_TEMPORARY);
>    add_catch_command ("assert", _("\
>  Catch failed Ada assertions, when raised.\n\
>  With an argument, catch only exceptions with the given name."),
> diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
> index 0530e9a..787bc2f 100644
> --- a/gdb/ada-lang.h
> +++ b/gdb/ada-lang.h
> @@ -108,7 +108,8 @@ enum ada_exception_catchpoint_kind
>  {
>    ada_catch_exception,
>    ada_catch_exception_unhandled,
> -  ada_catch_assert
> +  ada_catch_assert,
> +  ada_catch_handlers
>  };
>  
>  /* Ada task structures.  */
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 60ed80c..315a6a5 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -4458,6 +4458,25 @@ called @code{Constraint_Error} is defined in package @code{Pck}, then
>  the command to use to catch such exceptions is @kbd{catch exception
>  Pck.Constraint_Error}.
>  
> +@item handle
> +@kindex catch handle
> +@cindex Ada exception handle catching
> +@cindex catch Ada exceptions when handled
> +An Ada exception being handled.  If an exception name is
> +specified at the end of the command (eg @code{catch exception Program_Error}),
> +the debugger will stop only when this specific exception is handled.
> +Otherwise, the debugger stops execution when any Ada exception is handled.
> +
> +When inserting an handle catchpoint on a user-defined
> +exception whose name is identical to one of the exceptions
> +defined by the language, the fully qualified name must be used
> +as the exception name.  Otherwise, @value{GDBN} will assume that it
> +should stop on the pre-defined exception rather than the
> +user-defined one.  For instance, assuming an exception called
> + @code{Constraint_Error} is defined in package @code{Pck}, then the
> +command to use to catch such exceptions handling is
> +@kbd{catch handle Pck.Constraint_Error}.
> +
>  @item exception unhandled
>  @kindex catch exception unhandled
>  An exception that was raised but is not handled by the program.
> diff --git a/gdb/testsuite/gdb.ada/excep_handle.exp b/gdb/testsuite/gdb.ada/excep_handle.exp
> new file mode 100644
> index 0000000..003cf8d
> --- /dev/null
> +++ b/gdb/testsuite/gdb.ada/excep_handle.exp
> @@ -0,0 +1,164 @@
> +# Copyright 2017 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +load_lib "ada.exp"
> +
> +standard_ada_testfile foo
> +
> +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
> +  return -1
> +}
> +
> +clean_restart ${testfile}
> +
> +# Some global variables used to simplify the maintenance of some of
> +# the regular expressions below.
> +set eol "\[\r\n\]+"
> +set sp "\[ \t\]*"
> +
> +set when "when"
> +set catchpoint_constraint_error_msg \
> +  "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Constraint_Error =>"
> +
> +set catchpoint_program_error_msg \
> +  "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Program_Error =>"
> +
> +set catchpoint_storage_error_msg \
> +  "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Storage_Error =>"
> +
> +############################################
> +# Check that runtime supports catchpoint.  #
> +############################################
> +
> +if ![runto_main] then {
> +   fail "Cannot run to main, testcase aborted"
> +   return 0
> +}
> +
> +set msg "insert catchpoint on all Ada exceptions handlers"
> +gdb_test_multiple "catch handlers" $msg {
> +-re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" {

This line shoudl be indented (similar to the indentation you used in
the second branch below).

> +	pass $msg
> +    }
> +    -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
> +	# If the runtime was not built with enough debug information,
> +	# or if it was stripped, we can not test exception handlers
> +	# catchpoints.
> +	unsupported $msg
> +	return -1
> +    }
> +}
> +
> +############################################
> +# 1. Try catching all exceptions handlers. #
> +############################################
> +
> +# Continue. The program should stop at first exception handling.

Two spaces after a period.

> +gdb_test "continue" \
> +         "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
> +         "continuing to first Constraint_Error exception handlers"
> +
> +# Check that when no exception is raised, the program does not
> +# stop in the exception handling but only in the next handled one.

I still couldn't understand why you mean by "stop in the exception
handling".

Looking at the example program, I see that it has 3 blocks:

  |  -- Part 1 of the testcase
  |
  |  begin
  |     raise Constraint_Error;
  |  exception
  |     when Constraint_Error =>
  |        null;
  |  end;
  |
  |  begin
  |     null;
  |  exception
  |     when others =>
  |        null;
  |  end;
  |
  |  begin
  |     raise Storage_Error;
  |  exception
  |     when Storage_Error =>
  |        null;
  |  end;

Do you mean that the second test verifies that we should not stop
at the exception handler in the second block (because that handler
never gets exercised, obviously), and should instead that we should
stop at the handler in the third block, because that's the handler
for the exception that gets raised next?

Having that block in the middle is an interesting test to be doing.

I would suggest a more descriptive comment, along those lines:

# Resume the program's exception.
#
# The program will first go through a block of code which has an
# exception handler, but since no exception is raised, we should
# not stop there.  Instead, we expect to stop in the handler of
# the next exception being raised.

> +
> +gdb_test "continue" \
> +         "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
> +         "continuing and stopping in Storage_Error exception handlers"
> +
> +gdb_test_no_output "delete 2" \
> +                   "delete catchpoint on all Ada exceptions handlers"
> +
> +##################################################
> +# 2. Try catching some named exception handlers. #
> +##################################################
> +
> +# Insert a catchpoint on Program_Error Ada exception handlers.
> +
> +gdb_test "catch handlers Program_Error" \
> +         "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
> +         "insert catchpoint on Program_Error Ada exception handlers"
> +
> +# Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
> +
> +gdb_test "continue" \
> +         "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
> +         "continuing without stopping to Program_Error exception handlers"
> +
> +gdb_test_no_output "delete 3" \
> +                   "delete catchpoint on all Program_Error Ada exception handlers"

Can you reformat to avoid getting past 80 characters? Eg...

gdb_test_no_output \
    "delete 3" \
    "delete catchpoint on all Program_Error Ada exception handlers"

... should work.

> +
> +# Insert a catchpoint on Storage_Error Ada exception handlers.
> +
> +gdb_test "catch handlers Storage_Error" \
> +         "Catchpoint $decimal: `Storage_Error' Ada exception handlers" \
> +         "insert catchpoint on Storage_Error Ada exception handlers"
> +
> +# Continue, we should stop at Storage_Error handlers.
> +
> +gdb_test "continue" \
> +         "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
> +         "continuing without stopping to Storage_Error exception handlers"
> +
> +gdb_test_no_output "delete 4" \
> +                   "delete catchpoint on all Storage_Error Ada exception handlers"

Same as above (> 80 chars).

> +
> +########################################################################
> +# 3. Try catching with condition and without named exception handlers. #
> +########################################################################
> +
> +# Insert a catchpoint on Ada all exceptions handlers with condition.

"Ada all exceptions" -> "all Ada exceptions"

> +
> +gdb_test "catch handlers if Global_Var = 2" \
> +         "Catchpoint $decimal: all Ada exceptions handlers" \
> +         "insert catchpoint on all Ada exception handlers with condition"
> +
> +# Check that condition is stored and properly displayed.
> +
> +gdb_test "info breakpoint" "stop only if Global_Var = 2" \
> +         "Check catch handlers with condition"
> +
> +# Continue, we should not stop at ABORT_SIGNAL but as Program_Error one.

"as" -> "at"

> +
> +gdb_test "continue" \
> +         "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
> +         "continuing to second Constraint_Error exception handlers"
> +
> +gdb_test_no_output "delete 5" \
> +                   "delete catchpoint on all all Ada exceptions handlers with condition"

Same as above (> 80 chars)

> +
> +################################################################
> +# 4. Try catching with condition and named exception handlers. #
> +################################################################
> +
> +# Insert a catchpoint on Program_Error Ada exception handlers with
> +# condition.
> +
> +gdb_test "catch handlers Program_Error if Global_Var = 4" \
> +         "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
> +         "insert catchpoint on Program_Error Ada exception handlers with condition"

Formatting (> 80 chars)

No further comment past this point.

> +
> +# Continue, we should not stop at first Program_Error handlers but at
> +# the second one.
> +
> +gdb_test "continue" \
> +         "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
> +         "continuing to Program_Error exception handlers"
> +
> +# Continue, the program should exit properly.
> +
> +gdb_test "continue" \
> +         "Continuing\..*$inferior_exited_re.*" \
> +         "continuing to program completion"
> diff --git a/gdb/testsuite/gdb.ada/excep_handle/foo.adb b/gdb/testsuite/gdb.ada/excep_handle/foo.adb
> new file mode 100644
> index 0000000..91e4a16
> --- /dev/null
> +++ b/gdb/testsuite/gdb.ada/excep_handle/foo.adb
> @@ -0,0 +1,103 @@
> +--  Copyright 2017 Free Software Foundation, Inc.
> +--
> +--  This program is free software; you can redistribute it and/or modify
> +--  it under the terms of the GNU General Public License as published by
> +--  the Free Software Foundation; either version 3 of the License, or
> +--  (at your option) any later version.
> +--
> +--  This program is distributed in the hope that it will be useful,
> +--  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +--  GNU General Public License for more details.
> +--
> +--  You should have received a copy of the GNU General Public License
> +--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +with Pck; use Pck;
> +
> +procedure Foo is
> +begin
> +
> +   -- Part 1 of the testcase
> +
> +   begin
> +      raise Constraint_Error;
> +   exception
> +      when Constraint_Error =>
> +         null;
> +   end;
> +
> +   begin
> +      null;
> +   exception
> +      when others =>
> +         null;
> +   end;
> +
> +   begin
> +      raise Storage_Error;
> +   exception
> +      when Storage_Error =>
> +         null;
> +   end;
> +
> +   -- Part 2 of the testcase
> +
> +   begin
> +      raise ABORT_SIGNAL;
> +   exception
> +      when others =>
> +         null;
> +   end;
> +
> +   begin
> +      raise Program_Error;
> +   exception
> +      when Program_Error =>
> +         null;
> +   end;
> +
> +   begin
> +      raise Storage_Error;
> +   exception
> +      when Storage_Error =>
> +         null;
> +   end;
> +
> +  -- Part 3 of the testcase
> +
> +   begin
> +      Global_Var := Global_Var + 1;
> +      raise ABORT_SIGNAL;
> +   exception
> +      when others =>
> +         null;
> +   end;
> +
> +   begin
> +      Global_Var := Global_Var + 1;
> +      raise Constraint_Error;
> +   exception
> +      when Constraint_Error =>
> +         null;
> +   end;
> +
> +   -- Part 4 of the testcase
> +
> +   begin
> +      Global_Var := Global_Var + 1;
> +      raise Program_Error;
> +   exception
> +      when others =>
> +         null;
> +   end;
> +
> +   begin
> +      Global_Var := Global_Var + 1;
> +      raise Program_Error;
> +   exception
> +      when Program_Error =>
> +         null;
> +   end;
> +
> +end Foo;
> diff --git a/gdb/testsuite/gdb.ada/excep_handle/pck.ads b/gdb/testsuite/gdb.ada/excep_handle/pck.ads
> new file mode 100644
> index 0000000..1b438fc
> --- /dev/null
> +++ b/gdb/testsuite/gdb.ada/excep_handle/pck.ads
> @@ -0,0 +1,19 @@
> +--  Copyright 2017 Free Software Foundation, Inc.
> +--
> +--  This program is free software; you can redistribute it and/or modify
> +--  it under the terms of the GNU General Public License as published by
> +--  the Free Software Foundation; either version 3 of the License, or
> +--  (at your option) any later version.
> +--
> +--  This program is distributed in the hope that it will be useful,
> +--  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +--  GNU General Public License for more details.
> +--
> +--  You should have received a copy of the GNU General Public License
> +--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +package Pck is
> +   Global_Var : Integer := 0;
> +   ABORT_SIGNAL : exception;
> +end Pck;
> -- 
> 2.7.4

-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]