public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA 2/3] Return std::string from ada_exception_catchpoint_cond_string
  2018-05-03 21:50 [RFA 0/3] Remove some Ada cleanups Tom Tromey
  2018-05-03 21:50 ` [RFA 1/3] Remove cleanup from old_renaming_is_invisible Tom Tromey
@ 2018-05-03 21:50 ` Tom Tromey
  2018-05-03 21:50 ` [RFA 3/3] Remove cleanup from print_mention_exception Tom Tromey
  2018-05-04 17:53 ` [RFA 0/3] Remove some Ada cleanups Joel Brobecker
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2018-05-03 21:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes ada_exception_catchpoint_cond_string to return a
std::string, allowing for the removal of a cleanup in
create_excep_cond_exprs.

ChangeLog
2018-05-03  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (create_excep_cond_exprs): Update.
	(ada_exception_catchpoint_cond_string): Use std::string.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-lang.c | 36 ++++++++++++++----------------------
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d086240459..1af09bc00e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12431,7 +12431,7 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
   return result;
 }
 
-static char *ada_exception_catchpoint_cond_string
+static std::string ada_exception_catchpoint_cond_string
   (const char *excep_string,
    enum ada_exception_catchpoint_kind ex);
 
@@ -12499,9 +12499,7 @@ static void
 create_excep_cond_exprs (struct ada_catchpoint *c,
                          enum ada_exception_catchpoint_kind ex)
 {
-  struct cleanup *old_chain;
   struct bp_location *bl;
-  char *cond_string;
 
   /* Nothing to do if there's no specific exception to catch.  */
   if (c->excep_string == NULL)
@@ -12513,8 +12511,8 @@ 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, ex);
-  old_chain = make_cleanup (xfree, cond_string);
+  std::string cond_string
+    = ada_exception_catchpoint_cond_string (c->excep_string, ex);
 
   /* Iterate over all the catchpoint's locations, and parse an
      expression for each.  */
@@ -12528,7 +12526,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
 	{
 	  const char *s;
 
-	  s = cond_string;
+	  s = cond_string.c_str ();
 	  TRY
 	    {
 	      exp = parse_exp_1 (&s, bl->address,
@@ -12546,8 +12544,6 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
 
       ada_loc->excep_cond_expr = std::move (exp);
     }
-
-  do_cleanups (old_chain);
 }
 
 /* ada_catchpoint destructor.  */
@@ -13248,29 +13244,25 @@ 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.  */
+   EX: the type of catchpoints used for catching Ada exceptions.  */
 
-static char *
+static std::string
 ada_exception_catchpoint_cond_string (const char *excep_string,
                                       enum ada_exception_catchpoint_kind ex)
 {
   int i;
   bool is_standard_exc = false;
-  const char *actual_exc_expr;
-  char *ref_exc_expr;
+  std::string result;
 
   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)");
+      result = ("long_integer (GNAT_GCC_exception_Access"
+		"(gcc_exception).all.occurrence.id)");
     }
   else
-    actual_exc_expr = "long_integer (e)";
+    result = "long_integer (e)";
 
   /* The standard exceptions are a special case.  They are defined in
      runtime units that have been compiled without debugging info; if
@@ -13300,13 +13292,13 @@ ada_exception_catchpoint_cond_string (const char *excep_string,
 	}
     }
 
+  result += " = ";
+
   if (is_standard_exc)
-    ref_exc_expr = xstrprintf ("long_integer (&standard.%s)", excep_string);
+    string_appendf (result, "long_integer (&standard.%s)", excep_string);
   else
-    ref_exc_expr = xstrprintf ("long_integer (&%s)", excep_string);
+    string_appendf (result, "long_integer (&%s)", excep_string);
 
-  char *result =  xstrprintf ("%s = %s", actual_exc_expr, ref_exc_expr);
-  xfree (ref_exc_expr);
   return result;
 }
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFA 3/3] Remove cleanup from print_mention_exception
  2018-05-03 21:50 [RFA 0/3] Remove some Ada cleanups Tom Tromey
  2018-05-03 21:50 ` [RFA 1/3] Remove cleanup from old_renaming_is_invisible Tom Tromey
  2018-05-03 21:50 ` [RFA 2/3] Return std::string from ada_exception_catchpoint_cond_string Tom Tromey
@ 2018-05-03 21:50 ` Tom Tromey
  2018-05-04 17:53 ` [RFA 0/3] Remove some Ada cleanups Joel Brobecker
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2018-05-03 21:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes a cleanup from print_mention_exception by using
string_printf.

ChangeLog
2018-05-03  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (print_mention_exception): Use std::string.
---
 gdb/ChangeLog  | 4 ++++
 gdb/ada-lang.c | 8 +++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1af09bc00e..7cbf1ec08d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12805,11 +12805,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 ());
 	  }
         else
           uiout->text (_("all Ada exceptions"));
-- 
2.13.6

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFA 1/3] Remove cleanup from old_renaming_is_invisible
  2018-05-03 21:50 [RFA 0/3] Remove some Ada cleanups Tom Tromey
@ 2018-05-03 21:50 ` Tom Tromey
  2018-05-03 21:50 ` [RFA 2/3] Return std::string from ada_exception_catchpoint_cond_string Tom Tromey
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2018-05-03 21:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes a cleanup from ada-lang.c by changing xget_renaming_scope
to return a std::string.

ChangeLog
2018-05-03  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (xget_renaming_scope): Return std::string.
	(old_renaming_is_invisible): Update.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-lang.c | 35 +++++++----------------------------
 2 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index de20c43bed..d086240459 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5180,9 +5180,9 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms)
 /* Given a type that corresponds to a renaming entity, use the type name
    to extract the scope (package name or function name, fully qualified,
    and following the GNAT encoding convention) where this renaming has been
-   defined.  The string returned needs to be deallocated after use.  */
+   defined.  */
 
-static char *
+static std::string
 xget_renaming_scope (struct type *renaming_type)
 {
   /* The renaming types adhere to the following convention:
@@ -5193,8 +5193,6 @@ xget_renaming_scope (struct type *renaming_type)
   const char *name = type_name_no_tag (renaming_type);
   const char *suffix = strstr (name, "___XR");
   const char *last;
-  int scope_len;
-  char *scope;
 
   /* Now, backtrack a bit until we find the first "__".  Start looking
      at suffix - 3, as the <rename> part is at least one character long.  */
@@ -5204,14 +5202,7 @@ xget_renaming_scope (struct type *renaming_type)
       break;
 
   /* Make a copy of scope and return it.  */
-
-  scope_len = last - name;
-  scope = (char *) xmalloc ((scope_len + 1) * sizeof (char));
-
-  strncpy (scope, name, scope_len);
-  scope[scope_len] = '\0';
-
-  return scope;
+  return std::string (name, last);
 }
 
 /* Return nonzero if NAME corresponds to a package name.  */
@@ -5251,21 +5242,14 @@ is_package_name (const char *name)
 static int
 old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
 {
-  char *scope;
-  struct cleanup *old_chain;
-
   if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
     return 0;
 
-  scope = xget_renaming_scope (SYMBOL_TYPE (sym));
-  old_chain = make_cleanup (xfree, scope);
+  std::string scope = xget_renaming_scope (SYMBOL_TYPE (sym));
 
   /* If the rename has been defined in a package, then it is visible.  */
-  if (is_package_name (scope))
-    {
-      do_cleanups (old_chain);
-      return 0;
-    }
+  if (is_package_name (scope.c_str ()))
+    return 0;
 
   /* Check that the rename is in the current function scope by checking
      that its name starts with SCOPE.  */
@@ -5277,12 +5261,7 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
   if (startswith (function_name, "_ada_"))
     function_name += 5;
 
-  {
-    int is_invisible = !startswith (function_name, scope);
-
-    do_cleanups (old_chain);
-    return is_invisible;
-  }
+  return !startswith (function_name, scope.c_str ());
 }
 
 /* Remove entries from SYMS that corresponds to a renaming entity that
-- 
2.13.6

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFA 0/3] Remove some Ada cleanups
@ 2018-05-03 21:50 Tom Tromey
  2018-05-03 21:50 ` [RFA 1/3] Remove cleanup from old_renaming_is_invisible Tom Tromey
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tom Tromey @ 2018-05-03 21:50 UTC (permalink / raw)
  To: gdb-patches

A while back I sent a longer series to remove Ada cleanups:

https://sourceware.org/ml/gdb-patches/2017-11/msg00812.html

I didn't address all the reviews, and that's bit-rotted a bit.

This short series is just a few simple fixes from that older one.  It
doesn't remove all the cleanups from the Ada code; I figured it's a
bit better to do this in smaller pieces.

Tested by the buildbot.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFA 0/3] Remove some Ada cleanups
  2018-05-03 21:50 [RFA 0/3] Remove some Ada cleanups Tom Tromey
                   ` (2 preceding siblings ...)
  2018-05-03 21:50 ` [RFA 3/3] Remove cleanup from print_mention_exception Tom Tromey
@ 2018-05-04 17:53 ` Joel Brobecker
  3 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2018-05-04 17:53 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Hi Tom,

> A while back I sent a longer series to remove Ada cleanups:
> 
> https://sourceware.org/ml/gdb-patches/2017-11/msg00812.html
> 
> I didn't address all the reviews, and that's bit-rotted a bit.
> 
> This short series is just a few simple fixes from that older one.  It
> doesn't remove all the cleanups from the Ada code; I figured it's a
> bit better to do this in smaller pieces.

I reviewed your patches, and they look good to me, so go right
ahead and push. For the record, I also ran them through AdaCore's
gdb testsuite on x86_64-linux, just in case, and the results
were clean :).

-- 
Joel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-04 17:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-03 21:50 [RFA 0/3] Remove some Ada cleanups Tom Tromey
2018-05-03 21:50 ` [RFA 1/3] Remove cleanup from old_renaming_is_invisible Tom Tromey
2018-05-03 21:50 ` [RFA 2/3] Return std::string from ada_exception_catchpoint_cond_string Tom Tromey
2018-05-03 21:50 ` [RFA 3/3] Remove cleanup from print_mention_exception Tom Tromey
2018-05-04 17:53 ` [RFA 0/3] Remove some Ada cleanups Joel Brobecker

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).