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]

[patch] Make a function for block->objfile lookups


Hi,

the patch generalizes the `display' command code to use objfile and not
so_list matching; the modified code was created recently by:
	Re: Fix a crash when displaying variables from shared library.
	http://sourceware.org/ml/gdb-patches/2009-03/msg00090.html

This patch was made so that it can be reused from varobj.c where only objfile
(not so_list) is available.
	[patch] [4/5] Types reference counting [varobj-validation]
	http://sourceware.org/ml/gdb-patches/2009-04/threads.html#00203

I found it as a simplification, one may disagree.  I can use
matching_objfiles/block_objfile just for varobj.c.

No regressions on x86_64-unknown-linux-gnu.


Thanks,
Jan


gdb/
2009-04-22  Jan Kratochvil  <jan.kratochvil@redhat.com>
    
	* block.c (block_objfile): New function.
	* block.h (block_objfile): New prototype.
	* objfiles.c (matching_objfiles): New function.
	* objfiles.h (matching_objfiles): New prototype.
	* printcmd.c: Remove include solib.h.
	(display_uses_solib_p): Rename to ...
	(display_uses_objfile): ... a new function name.  Change the SOLIB
	parameter to OBJFILE parameter.  Use now a matching_objfiles call.
	(clear_dangling_display_expressions): Update the caller.

--- gdb/block.c	3 Jan 2009 05:57:50 -0000	1.18
+++ gdb/block.c	22 Apr 2009 18:15:44 -0000
@@ -309,3 +309,20 @@ allocate_block (struct obstack *obstack)
 
   return bl;
 }
+
+/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
+   whatever reason.  */
+
+struct objfile *block_objfile (const struct block *block)
+{
+  struct symbol *func;
+
+  if (block == NULL)
+    return NULL;
+
+  func = block_linkage_function (block);
+  if (func == NULL)
+    return NULL;
+
+  return SYMBOL_SYMTAB (func)->objfile;
+}
--- gdb/block.h	3 Jan 2009 05:57:50 -0000	1.19
+++ gdb/block.h	22 Apr 2009 18:15:44 -0000
@@ -164,4 +164,6 @@ extern const struct block *block_global_
 
 extern struct block *allocate_block (struct obstack *obstack);
 
+extern struct objfile *block_objfile (const struct block *block);
+
 #endif /* BLOCK_H */
--- gdb/objfiles.c	11 Mar 2009 20:26:02 -0000	1.82
+++ gdb/objfiles.c	22 Apr 2009 18:15:44 -0000
@@ -891,3 +891,21 @@ objfile_data (struct objfile *objfile, c
   gdb_assert (data->index < objfile->num_data);
   return objfile->data[data->index];
 }
+
+/* Return non-zero if A and B point to the same OBJFILE, ignoring any binary
+   vs. debuginfo variants of the pointers.  If either A or B is NULL return
+   zero as not a match.  */
+
+int
+matching_objfiles (struct objfile *a, struct objfile *b)
+{
+  if (a == NULL || b == NULL)
+    return 0;
+
+  if (a->separate_debug_objfile_backlink)
+    a = a->separate_debug_objfile_backlink;
+  if (b->separate_debug_objfile_backlink)
+    b = b->separate_debug_objfile_backlink;
+
+  return a == b;
+}
--- gdb/objfiles.h	15 Jan 2009 16:35:22 -0000	1.59
+++ gdb/objfiles.h	22 Apr 2009 18:15:45 -0000
@@ -508,6 +508,7 @@ extern void set_objfile_data (struct obj
 			      const struct objfile_data *data, void *value);
 extern void *objfile_data (struct objfile *objfile,
 			   const struct objfile_data *data);
+extern int matching_objfiles (struct objfile *a, struct objfile *b);
 
 
 /* Traverse all object files.  ALL_OBJFILES_SAFE works even if you delete
--- gdb/printcmd.c	25 Mar 2009 22:38:46 -0000	1.150
+++ gdb/printcmd.c	22 Apr 2009 18:15:45 -0000
@@ -46,7 +46,6 @@
 #include "exceptions.h"
 #include "observer.h"
 #include "solist.h"
-#include "solib.h"
 #include "parser-defs.h"
 #include "charset.h"
 
@@ -1760,19 +1759,17 @@ disable_display_command (char *args, int
       }
 }
 
-/* Return 1 if D uses SOLIB (and will become dangling when SOLIB
+/* Return 1 if D uses OBJFILE (and will become dangling when OBJFILE
    is unloaded), otherwise return 0.  */
 
 static int
-display_uses_solib_p (const struct display *d,
-		      const struct so_list *solib)
+display_uses_objfile (const struct display *d, struct objfile *objfile)
 {
   int endpos;
   struct expression *const exp = d->exp;
   const union exp_element *const elts = exp->elts;
 
-  if (d->block != NULL
-      && solib_contains_address_p (solib, d->block->startaddr))
+  if (matching_objfiles (block_objfile (d->block), objfile))
     return 1;
 
   for (endpos = exp->nelts; endpos > 0; )
@@ -1791,11 +1788,10 @@ display_uses_solib_p (const struct displ
 	  const struct obj_section *const section =
 	    SYMBOL_OBJ_SECTION (symbol);
 
-	  if (block != NULL
-	      && solib_contains_address_p (solib, block->startaddr))
+	  if (matching_objfiles (block_objfile (block), objfile))
 	    return 1;
 
-	  if (section && section->objfile == solib->objfile)
+	  if (section && section->objfile == objfile)
 	    return 1;
 	}
       endpos -= oplen;
@@ -1820,7 +1816,7 @@ clear_dangling_display_expressions (stru
 
   for (d = display_chain; d; d = d->next)
     {
-      if (d->exp && display_uses_solib_p (d, solib))
+      if (d->exp && display_uses_objfile (d, solib->objfile))
 	{
 	  xfree (d->exp);
 	  d->exp = NULL;


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