public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Backport memory leak fix to 7.1
@ 2010-03-23 16:07 Sami Wagiaalla
  2010-03-24  0:01 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Sami Wagiaalla @ 2010-03-23 16:07 UTC (permalink / raw)
  To: GDB Patches

[-- Attachment #1: Type: text/plain, Size: 7620 bytes --]

this is a combination of the patches posted
here http://sourceware.org/ml/gdb-patches/2010-03/msg00124.html
and here http://sourceware.org/ml/gdb-patches/2010-03/msg00475.html
and commited to HEAD

    2010-03-22  Sami Wagiaalla  <swagiaal@redhat.com>
    
    	PR Breakpoints/11408:
    	* cp-namespace.c (cp_add_using): Deleted.
    	(cp_add_using_directive): Use obstack allocations.
    	Merged the function cp_add_using into this one.
    	Added 'struct obstack *' argument.
    	(cp_scan_for_anonymous_namespaces): Updated.
    	* cp-support.h: Updated.
    	* dwarf2read.c (read_import_statement): Updated.
    	(read_namespace): Updated.
    	* buildsym.c (finish_block): Reset using_directives pointer
    	after block initialization.
    
    2010-03-22  Sami Wagiaalla  <swagiaal@redhat.com>
    
    	* gdb.cp/gdb2384-base.h: Created 'namespace B'.
    	* gdb.cp/gdb2384-base.cc: Use 'namespace B'.

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index ff2c9b1..35e4663 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -387,6 +387,7 @@ finish_block (struct symbol *symbol, struct pending **listhead,
     }
 
   block_set_using (block, using_directives, &objfile->objfile_obstack);
+  using_directives = NULL;
 
   record_pending_block (objfile, block, opblock);
 
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 5e894d4..7593475 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -117,7 +117,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
 		 anonymous namespace.  So add symbols in it to the
 		 namespace given by the previous component if there is
 		 one, or to the global namespace if there isn't.  */
-	      cp_add_using_directive (dest, src, NULL);
+	      cp_add_using_directive (dest, src, NULL,
+	                              &SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack);
 	    }
 	  /* The "+ 2" is for the "::".  */
 	  previous_component = next_component + 2;
@@ -128,11 +129,18 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
     }
 }
 
-/* Add a using directive to using_list. If the using directive in question
-   has already been added, don't add it twice.  */
+
+/* Add a using directive to using_directives.  If the using directive in
+   question has already been added, don't add it twice.
+   Create a new struct using_direct which imports the namespace SRC into the
+   scope DEST.  ALIAS is the name of the imported namespace in the current
+   scope.  If ALIAS is NULL then the namespace is known by its original name.
+   The arguments are copied into newly allocated memory so they can be 
+   temporaries.  */
 
 void
-cp_add_using_directive (const char *dest, const char *src, const char *alias)
+cp_add_using_directive (const char *dest, const char *src, const char *alias,
+                        struct obstack *obstack)
 {
   struct using_direct *current;
   struct using_direct *new;
@@ -142,12 +150,23 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias)
   for (current = using_directives; current != NULL; current = current->next)
     {
       if (strcmp (current->import_src, src) == 0
-          && strcmp (current->import_dest, dest) == 0)
+          && strcmp (current->import_dest, dest) == 0
+          && ((alias == NULL && current->alias == NULL)
+              || (alias != NULL && current->alias != NULL
+        	  && strcmp (alias, current->alias) == 0)))
 	return;
     }
 
-  using_directives = cp_add_using (dest, src, alias, using_directives);
+  new = OBSTACK_ZALLOC (obstack, struct using_direct);
 
+  new->import_src = obsavestring (src, strlen (src), obstack);
+  new->import_dest = obsavestring (dest, strlen (dest), obstack);
+
+  if (alias != NULL)
+    new->alias = obsavestring (alias, strlen (alias), obstack);
+
+  new->next = using_directives;
+  using_directives = new;
 }
 
 /* Record the namespace that the function defined by SYMBOL was
@@ -198,36 +217,6 @@ cp_is_anonymous (const char *namespace)
 	  != NULL);
 }
 
-/* Create a new struct using direct which imports the namespace SRC into the
-   scope DEST.  ALIAS is the name of the imported namespace in the current
-   scope.  If ALIAS is NULL then the namespace is known by its original name.
-   Set its next member in the linked list to NEXT; allocate all memory
-   using xmalloc.  It copies the strings, so NAME can be a temporary
-   string.  */
-
-struct using_direct *
-cp_add_using (const char *dest,
-              const char *src,
-              const char *alias,
-	      struct using_direct *next)
-{
-  struct using_direct *retval;
-
-  retval = xmalloc (sizeof (struct using_direct));
-  retval->import_src = savestring (src, strlen(src));
-  retval->import_dest = savestring (dest, strlen(dest));
-
-  if (alias != NULL)
-    retval->alias = savestring (alias, strlen (alias));
-  else
-    retval->alias = NULL;
-
-  retval->next = next;
-  retval->searched = 0;
-
-  return retval;
-}
-
 /* The C++-specific version of name lookup for static and global
    names.  This makes sure that names get looked for in all namespaces
    that are in scope.  NAME is the natural name of the symbol that
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index a6a9af1..3921a5f 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -90,12 +90,8 @@ extern int cp_is_anonymous (const char *namespace);
 
 extern void cp_add_using_directive (const char *dest,
                                     const char *src,
-                                    const char *alias);
-
-extern struct using_direct *cp_add_using (const char *dest,
-                                          const char *src,
-                                          const char *alias,
-					  struct using_direct *next);
+                                    const char *alias,
+                                    struct obstack *obstack);
 
 extern void cp_initialize_namespace (void);
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index b144dc1..6345a9c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3470,10 +3470,10 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
       strcpy (canonical_name, imported_name);
     }
 
-  using_directives = cp_add_using (import_prefix,
-                                   canonical_name,
-                                   import_alias,
-                                   using_directives);
+  cp_add_using_directive (import_prefix,
+                          canonical_name,
+                          import_alias,
+                          &cu->objfile->objfile_obstack);
 }
 
 static void
@@ -5632,7 +5632,8 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
       if (is_anonymous)
 	{
 	  const char *previous_prefix = determine_prefix (die, cu);
-	  cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL);
+	  cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
+	                          &objfile->objfile_obstack);
 	}
     }
 
diff --git a/gdb/testsuite/gdb.cp/gdb2384-base.cc b/gdb/testsuite/gdb.cp/gdb2384-base.cc
index 09ed04e..b58f30d 100644
--- a/gdb/testsuite/gdb.cp/gdb2384-base.cc
+++ b/gdb/testsuite/gdb.cp/gdb2384-base.cc
@@ -23,6 +23,8 @@ base::base (int _x)
 {
 }
 
+using namespace B;
+
 int
 base::meth ()
 {
diff --git a/gdb/testsuite/gdb.cp/gdb2384-base.h b/gdb/testsuite/gdb.cp/gdb2384-base.h
index b09701e..981943c 100644
--- a/gdb/testsuite/gdb.cp/gdb2384-base.h
+++ b/gdb/testsuite/gdb.cp/gdb2384-base.h
@@ -16,6 +16,10 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
 
+namespace B{
+  int x;
+}
+
 class base
 {
  public:

[-- Attachment #2: memoryleak.patch --]
[-- Type: text/plain, Size: 7422 bytes --]

    2010-03-22  Sami Wagiaalla  <swagiaal@redhat.com>
    
    	PR Breakpoints/11408:
    	* cp-namespace.c (cp_add_using): Deleted.
    	(cp_add_using_directive): Use obstack allocations.
    	Merged the function cp_add_using into this one.
    	Added 'struct obstack *' argument.
    	(cp_scan_for_anonymous_namespaces): Updated.
    	* cp-support.h: Updated.
    	* dwarf2read.c (read_import_statement): Updated.
    	(read_namespace): Updated.
    	* buildsym.c (finish_block): Reset using_directives pointer
    	after block initialization.
    
    2010-03-22  Sami Wagiaalla  <swagiaal@redhat.com>
    
    	* gdb.cp/gdb2384-base.h: Created 'namespace B'.
    	* gdb.cp/gdb2384-base.cc: Use 'namespace B'.

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index ff2c9b1..35e4663 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -387,6 +387,7 @@ finish_block (struct symbol *symbol, struct pending **listhead,
     }
 
   block_set_using (block, using_directives, &objfile->objfile_obstack);
+  using_directives = NULL;
 
   record_pending_block (objfile, block, opblock);
 
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 5e894d4..7593475 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -117,7 +117,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
 		 anonymous namespace.  So add symbols in it to the
 		 namespace given by the previous component if there is
 		 one, or to the global namespace if there isn't.  */
-	      cp_add_using_directive (dest, src, NULL);
+	      cp_add_using_directive (dest, src, NULL,
+	                              &SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack);
 	    }
 	  /* The "+ 2" is for the "::".  */
 	  previous_component = next_component + 2;
@@ -128,11 +129,18 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
     }
 }
 
-/* Add a using directive to using_list. If the using directive in question
-   has already been added, don't add it twice.  */
+
+/* Add a using directive to using_directives.  If the using directive in
+   question has already been added, don't add it twice.
+   Create a new struct using_direct which imports the namespace SRC into the
+   scope DEST.  ALIAS is the name of the imported namespace in the current
+   scope.  If ALIAS is NULL then the namespace is known by its original name.
+   The arguments are copied into newly allocated memory so they can be 
+   temporaries.  */
 
 void
-cp_add_using_directive (const char *dest, const char *src, const char *alias)
+cp_add_using_directive (const char *dest, const char *src, const char *alias,
+                        struct obstack *obstack)
 {
   struct using_direct *current;
   struct using_direct *new;
@@ -142,12 +150,23 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias)
   for (current = using_directives; current != NULL; current = current->next)
     {
       if (strcmp (current->import_src, src) == 0
-          && strcmp (current->import_dest, dest) == 0)
+          && strcmp (current->import_dest, dest) == 0
+          && ((alias == NULL && current->alias == NULL)
+              || (alias != NULL && current->alias != NULL
+        	  && strcmp (alias, current->alias) == 0)))
 	return;
     }
 
-  using_directives = cp_add_using (dest, src, alias, using_directives);
+  new = OBSTACK_ZALLOC (obstack, struct using_direct);
 
+  new->import_src = obsavestring (src, strlen (src), obstack);
+  new->import_dest = obsavestring (dest, strlen (dest), obstack);
+
+  if (alias != NULL)
+    new->alias = obsavestring (alias, strlen (alias), obstack);
+
+  new->next = using_directives;
+  using_directives = new;
 }
 
 /* Record the namespace that the function defined by SYMBOL was
@@ -198,36 +217,6 @@ cp_is_anonymous (const char *namespace)
 	  != NULL);
 }
 
-/* Create a new struct using direct which imports the namespace SRC into the
-   scope DEST.  ALIAS is the name of the imported namespace in the current
-   scope.  If ALIAS is NULL then the namespace is known by its original name.
-   Set its next member in the linked list to NEXT; allocate all memory
-   using xmalloc.  It copies the strings, so NAME can be a temporary
-   string.  */
-
-struct using_direct *
-cp_add_using (const char *dest,
-              const char *src,
-              const char *alias,
-	      struct using_direct *next)
-{
-  struct using_direct *retval;
-
-  retval = xmalloc (sizeof (struct using_direct));
-  retval->import_src = savestring (src, strlen(src));
-  retval->import_dest = savestring (dest, strlen(dest));
-
-  if (alias != NULL)
-    retval->alias = savestring (alias, strlen (alias));
-  else
-    retval->alias = NULL;
-
-  retval->next = next;
-  retval->searched = 0;
-
-  return retval;
-}
-
 /* The C++-specific version of name lookup for static and global
    names.  This makes sure that names get looked for in all namespaces
    that are in scope.  NAME is the natural name of the symbol that
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index a6a9af1..3921a5f 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -90,12 +90,8 @@ extern int cp_is_anonymous (const char *namespace);
 
 extern void cp_add_using_directive (const char *dest,
                                     const char *src,
-                                    const char *alias);
-
-extern struct using_direct *cp_add_using (const char *dest,
-                                          const char *src,
-                                          const char *alias,
-					  struct using_direct *next);
+                                    const char *alias,
+                                    struct obstack *obstack);
 
 extern void cp_initialize_namespace (void);
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index b144dc1..6345a9c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3470,10 +3470,10 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
       strcpy (canonical_name, imported_name);
     }
 
-  using_directives = cp_add_using (import_prefix,
-                                   canonical_name,
-                                   import_alias,
-                                   using_directives);
+  cp_add_using_directive (import_prefix,
+                          canonical_name,
+                          import_alias,
+                          &cu->objfile->objfile_obstack);
 }
 
 static void
@@ -5632,7 +5632,8 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
       if (is_anonymous)
 	{
 	  const char *previous_prefix = determine_prefix (die, cu);
-	  cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL);
+	  cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
+	                          &objfile->objfile_obstack);
 	}
     }
 
diff --git a/gdb/testsuite/gdb.cp/gdb2384-base.cc b/gdb/testsuite/gdb.cp/gdb2384-base.cc
index 09ed04e..b58f30d 100644
--- a/gdb/testsuite/gdb.cp/gdb2384-base.cc
+++ b/gdb/testsuite/gdb.cp/gdb2384-base.cc
@@ -23,6 +23,8 @@ base::base (int _x)
 {
 }
 
+using namespace B;
+
 int
 base::meth ()
 {
diff --git a/gdb/testsuite/gdb.cp/gdb2384-base.h b/gdb/testsuite/gdb.cp/gdb2384-base.h
index b09701e..981943c 100644
--- a/gdb/testsuite/gdb.cp/gdb2384-base.h
+++ b/gdb/testsuite/gdb.cp/gdb2384-base.h
@@ -16,6 +16,10 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
 
+namespace B{
+  int x;
+}
+
 class base
 {
  public:

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

* Re: [patch] Backport memory leak fix to 7.1
  2010-03-23 16:07 [patch] Backport memory leak fix to 7.1 Sami Wagiaalla
@ 2010-03-24  0:01 ` Tom Tromey
  2010-03-24  2:06   ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2010-03-24  0:01 UTC (permalink / raw)
  To: Sami Wagiaalla; +Cc: GDB Patches

>>>>> "Sami" == Sami Wagiaalla <swagiaal@redhat.com> writes:

Sami> this is a combination of the patches posted
Sami> here http://sourceware.org/ml/gdb-patches/2010-03/msg00124.html
Sami> and here http://sourceware.org/ml/gdb-patches/2010-03/msg00475.html
Sami> and commited to HEAD

I think it is fine to put these on the 7.1 branch, pending , but for
future reference, it would be good to mention the reason.  I have been
following along PR 11408, but I'm not sure everybody has.

Tom

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

* Re: [patch] Backport memory leak fix to 7.1
  2010-03-24  0:01 ` Tom Tromey
@ 2010-03-24  2:06   ` Tom Tromey
  2010-04-08 16:07     ` Sami Wagiaalla
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2010-03-24  2:06 UTC (permalink / raw)
  To: Sami Wagiaalla; +Cc: GDB Patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

>>>>> "Sami" == Sami Wagiaalla <swagiaal@redhat.com> writes:
Sami> this is a combination of the patches posted
Sami> here http://sourceware.org/ml/gdb-patches/2010-03/msg00124.html
Sami> and here http://sourceware.org/ml/gdb-patches/2010-03/msg00475.html
Sami> and commited to HEAD

Tom> I think it is fine to put these on the 7.1 branch, pending , but for

Oops, bad edit ... I was going to write "pending resolution of the issue
Ulrich just raised", but then I saw the rest of the thread and forgot to
either finish the clause or delete it.

Tom

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

* Re: [patch] Backport memory leak fix to 7.1
  2010-03-24  2:06   ` Tom Tromey
@ 2010-04-08 16:07     ` Sami Wagiaalla
  2010-04-08 17:12       ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Sami Wagiaalla @ 2010-04-08 16:07 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Sami Wagiaalla, GDB Patches


> Tom> I think it is fine to put these on the 7.1 branch, pending , but for
> 
> Oops, bad edit ... I was going to write "pending resolution of the issue
> Ulrich just raised", but then I saw the rest of the thread and forgot to
> either finish the clause or delete it.

Is this okay to go into the gdb_7_1-branch ?
The issue Ulrich raised was resolved by marking the tests are known
failures; that version of the compiler provides incorrect debuginfo.

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

* Re: [patch] Backport memory leak fix to 7.1
  2010-04-08 16:07     ` Sami Wagiaalla
@ 2010-04-08 17:12       ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2010-04-08 17:12 UTC (permalink / raw)
  To: Sami Wagiaalla; +Cc: Sami Wagiaalla, GDB Patches

>>>>> "Sami" == Sami Wagiaalla <swagiaal@redha.com> writes:

Sami> Is this okay to go into the gdb_7_1-branch ?

Yes, thanks.

Tom

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

end of thread, other threads:[~2010-04-08 17:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-23 16:07 [patch] Backport memory leak fix to 7.1 Sami Wagiaalla
2010-03-24  0:01 ` Tom Tromey
2010-03-24  2:06   ` Tom Tromey
2010-04-08 16:07     ` Sami Wagiaalla
2010-04-08 17:12       ` Tom Tromey

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