public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 08/25] Don't require inferior execution for Ada catchpoints
Date: Wed, 24 May 2023 10:36:59 -0600	[thread overview]
Message-ID: <20230427-ada-catch-exception-v1-8-947caa9905e3@adacore.com> (raw)
In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com>

Currently, Ada catchpoints require that the inferior be running.
However, there's no deep reason for this -- for example, C++ exception
catchpoints do not have this requirement.  Instead, those work like
ordinary breakpoints: they are pending until the needed runtime
locations are seen.

This patch changes Ada catchpoints to work the same way.
---
 gdb/ada-lang.c | 115 +++++++++++++++------------------------------------------
 1 file changed, 29 insertions(+), 86 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6ee507147cb..f9d5965f055 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -790,18 +790,6 @@ ada_get_decoded_type (struct type *type)
 
 				/* Language Selection */
 
-/* If the main program is in Ada, return language_ada, otherwise return LANG
-   (the main program is in Ada iif the adainit symbol is found).  */
-
-static enum language
-ada_update_initial_language (enum language lang)
-{
-  if (lookup_minimal_symbol ("adainit", NULL, NULL).minsym != NULL)
-    return language_ada;
-
-  return lang;
-}
-
 /* If the main procedure is written in Ada, then return its name.
    The result is good until the next call.  Return NULL if the main
    procedure doesn't appear to be in Ada.  */
@@ -11827,31 +11815,8 @@ ada_exception_support_info_sniffer (void)
       return;
     }
 
-  /* Sometimes, it is normal for us to not be able to find the routine
-     we are looking for.  This happens when the program is linked with
-     the shared version of the GNAT runtime, and the program has not been
-     started yet.  Inform the user of these two possible causes if
-     applicable.  */
-
-  if (ada_update_initial_language (language_unknown) != language_ada)
-    error (_("Unable to insert catchpoint.  Is this an Ada main program?"));
-
-  /* If the symbol does not exist, then check that the program is
-     already started, to make sure that shared libraries have been
-     loaded.  If it is not started, this may mean that the symbol is
-     in a shared library.  */
-
-  if (inferior_ptid.pid () == 0)
-    error (_("Unable to insert catchpoint. Try to start the program first."));
-
-  /* At this point, we know that we are debugging an Ada program and
-     that the inferior has been started, but we still are not able to
-     find the run-time symbols.  That can mean that we are in
-     configurable run time mode, or that a-except as been optimized
-     out by the linker...  In any case, at this point it is not worth
-     supporting this feature.  */
-
-  error (_("Cannot insert Ada exception catchpoints in this configuration."));
+  throw_error (NOT_FOUND_ERROR,
+	       _("Could not find Ada runtime exception support"));
 }
 
 /* True iff FRAME is very likely to be that of a function that is
@@ -12135,44 +12100,19 @@ struct ada_catchpoint : public code_breakpoint
 {
   ada_catchpoint (struct gdbarch *gdbarch_,
 		  enum ada_exception_catchpoint_kind kind,
-		  struct symtab_and_line sal,
-		  const char *addr_string_,
+		  const char *cond_string,
 		  bool tempflag,
 		  bool enabled,
 		  bool from_tty,
 		  std::string &&excep_string_)
-    : code_breakpoint (gdbarch_, bp_catchpoint, tempflag),
+    : code_breakpoint (gdbarch_, bp_catchpoint, tempflag, cond_string),
       m_excep_string (std::move (excep_string_)),
       m_kind (kind)
   {
-    add_location (sal);
-
     /* Unlike most code_breakpoint types, Ada catchpoints are
        pspace-specific.  */
-    gdb_assert (sal.pspace != nullptr);
-    this->pspace = sal.pspace;
-
-    if (from_tty)
-      {
-	struct gdbarch *loc_gdbarch = get_sal_arch (sal);
-	if (!loc_gdbarch)
-	  loc_gdbarch = gdbarch;
-
-	describe_other_breakpoints (loc_gdbarch,
-				    sal.pspace, sal.pc, sal.section, -1);
-	/* FIXME: brobecker/2006-12-28: Actually, re-implement a special
-	   version for exception catchpoints, because two catchpoints
-	   used for different exception names will use the same address.
-	   In this case, a "breakpoint ... also set at..." warning is
-	   unproductive.  Besides, the warning phrasing is also a bit
-	   inappropriate, we should use the word catchpoint, and tell
-	   the user what type of catchpoint it is.  The above is good
-	   enough for now, though.  */
-      }
-
+    pspace = current_program_space;
     enable_state = enabled ? bp_enabled : bp_disabled;
-    locspec = string_to_location_spec (&addr_string_,
-				       language_def (language_ada));
     language = language_ada;
 
     re_set ();
@@ -12217,15 +12157,29 @@ class ada_catchpoint_location : public bp_location
   expression_up excep_cond_expr;
 };
 
+static struct symtab_and_line ada_exception_sal
+     (enum ada_exception_catchpoint_kind ex);
+
 /* Implement the RE_SET method in the structure for all exception
    catchpoint kinds.  */
 
 void
 ada_catchpoint::re_set ()
 {
-  /* Call the base class's method.  This updates the catchpoint's
-     locations.  */
-  this->code_breakpoint::re_set ();
+  std::vector<symtab_and_line> sals;
+  try
+    {
+      struct symtab_and_line sal = ada_exception_sal (m_kind);
+      sals.push_back (sal);
+    }
+  catch (const gdb_exception_error &ex)
+    {
+      /* For NOT_FOUND_ERROR, the breakpoint will be pending.  */
+      if (ex.error != NOT_FOUND_ERROR)
+	throw;
+    }
+
+  update_breakpoint_locations (this, pspace, sals, {});
 
   /* Reparse the exception conditional expressions.  One for each
      location.  */
@@ -12756,16 +12710,11 @@ ada_exception_catchpoint_cond_string (const char *excep_string,
   return result;
 }
 
-/* Return the symtab_and_line that should be used to insert an exception
-   catchpoint of the TYPE kind.
-
-   ADDR_STRING returns the name of the function where the real
-   breakpoint that implements the catchpoints is set, depending on the
-   type of catchpoint we need to create.  */
+/* Return the symtab_and_line that should be used to insert an
+   exception catchpoint of the TYPE kind.  */
 
 static struct symtab_and_line
-ada_exception_sal (enum ada_exception_catchpoint_kind ex,
-		   std::string *addr_string)
+ada_exception_sal (enum ada_exception_catchpoint_kind ex)
 {
   const char *sym_name;
   struct symbol *sym;
@@ -12779,14 +12728,12 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex,
   sym = standard_lookup (sym_name, NULL, VAR_DOMAIN);
 
   if (sym == NULL)
-    error (_("Catchpoint symbol not found: %s"), sym_name);
+    throw_error (NOT_FOUND_ERROR, _("Catchpoint symbol not found: %s"),
+		 sym_name);
 
   if (sym->aclass () != LOC_BLOCK)
     error (_("Unable to insert catchpoint. %s is not a function."), sym_name);
 
-  /* Set ADDR_STRING.  */
-  *addr_string = sym_name;
-
   return find_function_start_sal (sym, 1);
 }
 
@@ -12814,15 +12761,11 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
 				 int enabled,
 				 int from_tty)
 {
-  std::string addr_string;
-  struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string);
-
   std::unique_ptr<ada_catchpoint> c
-    (new ada_catchpoint (gdbarch, ex_kind, sal, addr_string.c_str (),
+    (new ada_catchpoint (gdbarch, ex_kind,
+			 cond_string.empty () ? nullptr : cond_string.c_str (),
 			 tempflag, enabled, from_tty,
 			 std::move (excep_string)));
-  if (!cond_string.empty ())
-    set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty, false);
   install_breakpoint (0, std::move (c), 1);
 }
 

-- 
2.40.0


  parent reply	other threads:[~2023-05-24 16:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 16:36 [PATCH 00/25] Many updates to DAP implementation Tom Tromey
2023-05-24 16:36 ` [PATCH 01/25] Stop gdb in gnat_runtime_has_debug_info Tom Tromey
2023-05-24 16:36 ` [PATCH 02/25] Use gnat_runtime_has_debug_info in Ada catchpoint tests Tom Tromey
2023-06-13 20:10   ` Tom de Vries
2023-06-19  9:49     ` Tom de Vries
2023-06-20 13:56       ` Tom Tromey
2023-05-24 16:36 ` [PATCH 03/25] Pass tempflag to ada_catchpoint constructor Tom Tromey
2023-05-24 16:36 ` [PATCH 04/25] Transfer ownership of exception string to ada_catchpoint Tom Tromey
2023-05-24 16:36 ` [PATCH 05/25] Combine create_excep_cond_exprs and ada_catchpoint::re_set Tom Tromey
2023-05-24 16:36 ` [PATCH 06/25] Turn should_stop_exception into a method of ada_catchpoint Tom Tromey
2023-05-24 16:36 ` [PATCH 07/25] Mark members of ada_catchpoint "private" Tom Tromey
2023-05-24 16:36 ` Tom Tromey [this message]
2023-05-24 16:37 ` [PATCH 09/25] Implement DAP setExceptionBreakpoints request Tom Tromey
2023-05-24 16:37 ` [PATCH 10/25] Implement DAP attach request Tom Tromey
2023-05-24 16:53   ` Eli Zaretskii
2023-05-24 16:37 ` [PATCH 11/25] Implement DAP stepOut request Tom Tromey
2023-05-24 16:37 ` [PATCH 12/25] Add singleThread support to some DAP requests Tom Tromey
2023-05-24 16:37 ` [PATCH 13/25] Rename one DAP function Tom Tromey
2023-05-24 16:37 ` [PATCH 14/25] Add test for DAP pause request Tom Tromey
2023-05-24 16:37 ` [PATCH 15/25] Fix a latent bug in DAP request decorator Tom Tromey
2023-05-24 16:37 ` [PATCH 16/25] Use tuples for default arguments in DAP Tom Tromey
2023-05-24 16:37 ` [PATCH 17/25] Add type-checking to DAP requests Tom Tromey
2023-05-24 16:37 ` [PATCH 18/25] Add gdb.Value.assign method Tom Tromey
2023-05-24 16:54   ` Eli Zaretskii
2023-05-24 16:37 ` [PATCH 19/25] Implement DAP setExpression request Tom Tromey
2023-05-24 16:37 ` [PATCH 20/25] Handle DAP supportsVariableType capability Tom Tromey
2023-05-24 16:37 ` [PATCH 21/25] Add "target" parameter to DAP attach request Tom Tromey
2023-05-24 16:55   ` Eli Zaretskii
2023-05-24 16:37 ` [PATCH 22/25] Add "stop at main" extension to DAP launch request Tom Tromey
2023-05-24 16:56   ` Eli Zaretskii
2023-05-24 16:37 ` [PATCH 23/25] Implement DAP breakpointLocations request Tom Tromey
2023-05-24 16:37 ` [PATCH 24/25] Do not report totalFrames from DAP stackTrace request Tom Tromey
2023-05-24 16:37 ` [PATCH 25/25] Implement DAP conditional breakpoints Tom Tromey
2023-06-12 18:11 ` [PATCH 00/25] Many updates to DAP implementation Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427-ada-catch-exception-v1-8-947caa9905e3@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).