Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [4/10] add back-pointer from global block to symtab
@ 2012-04-25 18:36 Tom Tromey
  2012-05-10 19:55 ` Tom Tromey
  2012-05-10 19:59 ` Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey @ 2012-04-25 18:36 UTC (permalink / raw)
  To: gdb-patches

As mentioned in an earlier patch, one idea behind efficiently handling
PUs is that when we iterate over the static or global symbols of a CU,
we also iterate over the symbols of all the associated PUs.  This mimics
inclusion, but efficiently, because a single PU can be shared by several
CUs.  This means it takes less time to read and less storage.

In order to do this I needed a back-link from the global block to its
defining primary symtab.

In order to keep memory down I did this by introducing a "global_block"
structure which is a subclass of "block".

This patch makes the needed change.  Nothing uses this yet, that comes
in a subsequent patch.

Tom

From 4bc21ac91d29629714271bfdacd866cf060e8edf Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Thu, 19 Apr 2012 15:06:16 -0600
Subject: [PATCH 04/10] make it possible to find the symtab from a global
 block

	* jv-lang.c (get_java_class_symtab): Use allocate_global_block,
	set_block_symtab.
	* jit.c (finalize_symtab): Use allocate_global_block,
	set_block_symtab.
	* buildsym.c (finish_block_internal): New function, from old
	finish_block.
	(finish_block): Rewrite.
	(end_symtab): Use finish_block_internal, set_block_symtab.
	* block.h (struct global_block): New.
	(allocate_global_block, set_block_symtab): Declare.
	* block.c (allocate_global_block, set_block_symtab)
	(get_block_symtab): New functions.
---
 gdb/block.c    |   36 ++++++++++++++++++++++++++++++++++++
 gdb/block.h    |   18 ++++++++++++++++++
 gdb/buildsym.c |   39 ++++++++++++++++++++++++++++-----------
 gdb/jit.c      |    9 ++++++++-
 gdb/jv-lang.c  |    3 ++-
 5 files changed, 92 insertions(+), 13 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 3318cb4..fd87f77 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -370,6 +370,42 @@ allocate_block (struct obstack *obstack)
   return bl;
 }
 
+/* Allocate a global block.  */
+
+struct block *
+allocate_global_block (struct obstack *obstack)
+{
+  struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
+
+  return &bl->block;
+}
+
+/* Set the symtab of the global block.  */
+
+void
+set_block_symtab (struct block *block, struct symtab *symtab)
+{
+  struct global_block *gb;
+
+  gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
+  gb = (struct global_block *) block;
+  gdb_assert (gb->symtab == NULL);
+  gb->symtab = symtab;
+}
+
+/* Return the symtab of the global block.  */
+
+static struct symtab *
+get_block_symtab (const struct block *block)
+{
+  struct global_block *gb;
+
+  gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
+  gb = (struct global_block *) block;
+  gdb_assert (gb->symtab != NULL);
+  return gb->symtab;
+}
+
 \f
 
 /* See block.h.  */
diff --git a/gdb/block.h b/gdb/block.h
index 2eec346..de674a8 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -99,6 +99,21 @@ struct block
   language_specific;
 };
 
+/* The global block is singled out so that we can provide a back-link
+   to the primary symtab.  */
+
+struct global_block
+{
+  /* The block.  */
+
+  struct block block;
+
+  /* This holds a pointer to the primary symtab holding this
+     block.  */
+
+  struct symtab *symtab;
+};
+
 #define BLOCK_START(bl)		(bl)->startaddr
 #define BLOCK_END(bl)		(bl)->endaddr
 #define BLOCK_FUNCTION(bl)	(bl)->function
@@ -161,6 +176,9 @@ extern const struct block *block_global_block (const struct block *block);
 
 extern struct block *allocate_block (struct obstack *obstack);
 
+extern struct block *allocate_global_block (struct obstack *obstack);
+
+extern void set_block_symtab (struct block *, struct symtab *);
 
 /* A block iterator.  This structure should be treated as though it
    were opaque; it is only defined here because we want to support
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 58c2693..ae7f90e 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -214,11 +214,12 @@ free_pending_blocks (void)
    the order the symbols have in the list (reversed from the input
    file).  Put the block on the list of pending blocks.  */
 
-struct block *
-finish_block (struct symbol *symbol, struct pending **listhead,
-	      struct pending_block *old_blocks,
-	      CORE_ADDR start, CORE_ADDR end,
-	      struct objfile *objfile)
+static struct block *
+finish_block_internal (struct symbol *symbol, struct pending **listhead,
+		       struct pending_block *old_blocks,
+		       CORE_ADDR start, CORE_ADDR end,
+		       struct objfile *objfile,
+		       int is_global)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct pending *next, *next1;
@@ -226,7 +227,9 @@ finish_block (struct symbol *symbol, struct pending **listhead,
   struct pending_block *pblock;
   struct pending_block *opblock;
 
-  block = allocate_block (&objfile->objfile_obstack);
+  block = (is_global
+	   ? allocate_global_block (&objfile->objfile_obstack)
+	   : allocate_block (&objfile->objfile_obstack));
 
   if (symbol)
     {
@@ -241,9 +244,6 @@ finish_block (struct symbol *symbol, struct pending **listhead,
 
   BLOCK_START (block) = start;
   BLOCK_END (block) = end;
-  /* Superblock filled in when containing block is made.  */
-  BLOCK_SUPERBLOCK (block) = NULL;
-  BLOCK_NAMESPACE (block) = NULL;
 
   /* Put the block in as the value of the symbol that names it.  */
 
@@ -387,6 +387,15 @@ finish_block (struct symbol *symbol, struct pending **listhead,
   return block;
 }
 
+struct block *
+finish_block (struct symbol *symbol, struct pending **listhead,
+	      struct pending_block *old_blocks,
+	      CORE_ADDR start, CORE_ADDR end,
+	      struct objfile *objfile)
+{
+  return finish_block_internal (symbol, listhead, old_blocks,
+				start, end, objfile, 0);
+}
 
 /* Record BLOCK on the list of all blocks in the file.  Put it after
    OPBLOCK, or at the beginning if opblock is NULL.  This puts the
@@ -1017,8 +1026,8 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
          blockvector.  */
       finish_block (0, &file_symbols, 0, last_source_start_addr,
 		    end_addr, objfile);
-      finish_block (0, &global_symbols, 0, last_source_start_addr,
-		    end_addr, objfile);
+      finish_block_internal (0, &global_symbols, 0, last_source_start_addr,
+			     end_addr, objfile, 1);
       blockvector = make_blockvector (objfile);
     }
 
@@ -1158,6 +1167,14 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
   if (symtab)
     {
       symtab->primary = 1;
+
+      if (symtab->blockvector)
+	{
+	  struct block *b = BLOCKVECTOR_BLOCK (symtab->blockvector,
+					       GLOBAL_BLOCK);
+
+	  set_block_symtab (b, symtab);
+	}
     }
 
   /* Default any symbols without a specified symtab to the primary
diff --git a/gdb/jit.c b/gdb/jit.c
index 24ab016..a76cca1 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -695,7 +695,11 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
   block_iter = NULL;
   for (i = 0; i < FIRST_LOCAL_BLOCK; i++)
     {
-      struct block *new_block = allocate_block (&objfile->objfile_obstack);
+      struct block *new_block;
+
+      new_block = (i == GLOBAL_BLOCK
+		   ? allocate_global_block (&objfile->objfile_obstack)
+		   : allocate_block (&objfile->objfile_obstack));
       BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
                                                    NULL);
       BLOCK_SUPERBLOCK (new_block) = block_iter;
@@ -705,6 +709,9 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       BLOCK_END (new_block) = (CORE_ADDR) end;
 
       BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
+
+      if (i == GLOBAL_BLOCK)
+	set_block_symtab (new_block, symtab);
     }
 
   /* Fill up the superblock fields for the real blocks, using the
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index c3c5298..a7cfb76 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -158,8 +158,9 @@ get_java_class_symtab (struct gdbarch *gdbarch)
       BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
 
       /* Allocate GLOBAL_BLOCK.  */
-      bl = allocate_block (&objfile->objfile_obstack);
+      bl = allocate_global_block (&objfile->objfile_obstack);
       BLOCK_DICT (bl) = dict_create_hashed_expandable ();
+      set_block_symtab (bl, class_symtab);
       BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
 
       /* Arrange to free the dict.  */
-- 
1.7.7.6


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

* Re: [4/10] add back-pointer from global block to symtab
  2012-04-25 18:36 [4/10] add back-pointer from global block to symtab Tom Tromey
@ 2012-05-10 19:55 ` Tom Tromey
  2012-05-10 19:59 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2012-05-10 19:55 UTC (permalink / raw)
  To: gdb-patches

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

Tom> In order to keep memory down I did this by introducing a "global_block"
Tom> structure which is a subclass of "block".

This patch also didn't change.
I'm checking it in.

Tom


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

* Re: [4/10] add back-pointer from global block to symtab
  2012-04-25 18:36 [4/10] add back-pointer from global block to symtab Tom Tromey
  2012-05-10 19:55 ` Tom Tromey
@ 2012-05-10 19:59 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2012-05-10 19:59 UTC (permalink / raw)
  To: gdb-patches

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

Tom> In order to keep memory down I did this by introducing a "global_block"
Tom> structure which is a subclass of "block".

I spoke too soon.  I did need a little change in this patch.

Tom> 	(get_block_symtab): New functions.

This function is static but not used until a later patch.
So, I moved it out of this patch.

I'm appending what I am checking in.

Tom

2012-05-10  Tom Tromey  <tromey@redhat.com>

	* jv-lang.c (get_java_class_symtab): Use allocate_global_block,
	set_block_symtab.
	* jit.c (finalize_symtab): Use allocate_global_block,
	set_block_symtab.
	* buildsym.c (finish_block_internal): New function, from old
	finish_block.
	(finish_block): Rewrite.
	(end_symtab): Use finish_block_internal, set_block_symtab.
	* block.h (struct global_block): New.
	(allocate_global_block, set_block_symtab): Declare.
	* block.c (allocate_global_block, set_block_symtab): New
	functions.

Index: block.c
===================================================================
RCS file: /cvs/src/src/gdb/block.c,v
retrieving revision 1.28
diff -u -r1.28 block.c
--- block.c	10 May 2012 19:50:07 -0000	1.28
+++ block.c	10 May 2012 19:58:25 -0000
@@ -370,6 +370,29 @@
   return bl;
 }
 
+/* Allocate a global block.  */
+
+struct block *
+allocate_global_block (struct obstack *obstack)
+{
+  struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
+
+  return &bl->block;
+}
+
+/* Set the symtab of the global block.  */
+
+void
+set_block_symtab (struct block *block, struct symtab *symtab)
+{
+  struct global_block *gb;
+
+  gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
+  gb = (struct global_block *) block;
+  gdb_assert (gb->symtab == NULL);
+  gb->symtab = symtab;
+}
+
 \f
 
 /* See block.h.  */
Index: block.h
===================================================================
RCS file: /cvs/src/src/gdb/block.h,v
retrieving revision 1.27
diff -u -r1.27 block.h
--- block.h	10 May 2012 19:50:07 -0000	1.27
+++ block.h	10 May 2012 19:58:25 -0000
@@ -99,6 +99,21 @@
   language_specific;
 };
 
+/* The global block is singled out so that we can provide a back-link
+   to the primary symtab.  */
+
+struct global_block
+{
+  /* The block.  */
+
+  struct block block;
+
+  /* This holds a pointer to the primary symtab holding this
+     block.  */
+
+  struct symtab *symtab;
+};
+
 #define BLOCK_START(bl)		(bl)->startaddr
 #define BLOCK_END(bl)		(bl)->endaddr
 #define BLOCK_FUNCTION(bl)	(bl)->function
@@ -161,6 +176,9 @@
 
 extern struct block *allocate_block (struct obstack *obstack);
 
+extern struct block *allocate_global_block (struct obstack *obstack);
+
+extern void set_block_symtab (struct block *, struct symtab *);
 
 /* A block iterator.  This structure should be treated as though it
    were opaque; it is only defined here because we want to support
Index: buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.94
diff -u -r1.94 buildsym.c
--- buildsym.c	10 May 2012 19:50:07 -0000	1.94
+++ buildsym.c	10 May 2012 19:58:25 -0000
@@ -214,11 +214,12 @@
    the order the symbols have in the list (reversed from the input
    file).  Put the block on the list of pending blocks.  */
 
-struct block *
-finish_block (struct symbol *symbol, struct pending **listhead,
-	      struct pending_block *old_blocks,
-	      CORE_ADDR start, CORE_ADDR end,
-	      struct objfile *objfile)
+static struct block *
+finish_block_internal (struct symbol *symbol, struct pending **listhead,
+		       struct pending_block *old_blocks,
+		       CORE_ADDR start, CORE_ADDR end,
+		       struct objfile *objfile,
+		       int is_global)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct pending *next, *next1;
@@ -226,7 +227,9 @@
   struct pending_block *pblock;
   struct pending_block *opblock;
 
-  block = allocate_block (&objfile->objfile_obstack);
+  block = (is_global
+	   ? allocate_global_block (&objfile->objfile_obstack)
+	   : allocate_block (&objfile->objfile_obstack));
 
   if (symbol)
     {
@@ -241,9 +244,6 @@
 
   BLOCK_START (block) = start;
   BLOCK_END (block) = end;
-  /* Superblock filled in when containing block is made.  */
-  BLOCK_SUPERBLOCK (block) = NULL;
-  BLOCK_NAMESPACE (block) = NULL;
 
   /* Put the block in as the value of the symbol that names it.  */
 
@@ -387,6 +387,15 @@
   return block;
 }
 
+struct block *
+finish_block (struct symbol *symbol, struct pending **listhead,
+	      struct pending_block *old_blocks,
+	      CORE_ADDR start, CORE_ADDR end,
+	      struct objfile *objfile)
+{
+  return finish_block_internal (symbol, listhead, old_blocks,
+				start, end, objfile, 0);
+}
 
 /* Record BLOCK on the list of all blocks in the file.  Put it after
    OPBLOCK, or at the beginning if opblock is NULL.  This puts the
@@ -1017,8 +1026,8 @@
          blockvector.  */
       finish_block (0, &file_symbols, 0, last_source_start_addr,
 		    end_addr, objfile);
-      finish_block (0, &global_symbols, 0, last_source_start_addr,
-		    end_addr, objfile);
+      finish_block_internal (0, &global_symbols, 0, last_source_start_addr,
+			     end_addr, objfile, 1);
       blockvector = make_blockvector (objfile);
     }
 
@@ -1158,6 +1167,14 @@
   if (symtab)
     {
       symtab->primary = 1;
+
+      if (symtab->blockvector)
+	{
+	  struct block *b = BLOCKVECTOR_BLOCK (symtab->blockvector,
+					       GLOBAL_BLOCK);
+
+	  set_block_symtab (b, symtab);
+	}
     }
 
   /* Default any symbols without a specified symtab to the primary
Index: jit.c
===================================================================
RCS file: /cvs/src/src/gdb/jit.c,v
retrieving revision 1.28
diff -u -r1.28 jit.c
--- jit.c	22 Mar 2012 20:33:42 -0000	1.28
+++ jit.c	10 May 2012 19:58:25 -0000
@@ -695,7 +695,11 @@
   block_iter = NULL;
   for (i = 0; i < FIRST_LOCAL_BLOCK; i++)
     {
-      struct block *new_block = allocate_block (&objfile->objfile_obstack);
+      struct block *new_block;
+
+      new_block = (i == GLOBAL_BLOCK
+		   ? allocate_global_block (&objfile->objfile_obstack)
+		   : allocate_block (&objfile->objfile_obstack));
       BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
                                                    NULL);
       BLOCK_SUPERBLOCK (new_block) = block_iter;
@@ -705,6 +709,9 @@
       BLOCK_END (new_block) = (CORE_ADDR) end;
 
       BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
+
+      if (i == GLOBAL_BLOCK)
+	set_block_symtab (new_block, symtab);
     }
 
   /* Fill up the superblock fields for the real blocks, using the
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.102
diff -u -r1.102 jv-lang.c
--- jv-lang.c	17 Apr 2012 12:43:20 -0000	1.102
+++ jv-lang.c	10 May 2012 19:58:26 -0000
@@ -158,8 +158,9 @@
       BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
 
       /* Allocate GLOBAL_BLOCK.  */
-      bl = allocate_block (&objfile->objfile_obstack);
+      bl = allocate_global_block (&objfile->objfile_obstack);
       BLOCK_DICT (bl) = dict_create_hashed_expandable ();
+      set_block_symtab (bl, class_symtab);
       BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
 
       /* Arrange to free the dict.  */


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

end of thread, other threads:[~2012-05-10 19:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25 18:36 [4/10] add back-pointer from global block to symtab Tom Tromey
2012-05-10 19:55 ` Tom Tromey
2012-05-10 19:59 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox