Re: [patch] Fix a crash when displaying variables from shared library.

Paul Pluzhnikov
2009-03-06T22:06:24Z

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

On Fri, Mar 6, 2009 at 9:48 AM, Joel Brobecker <brobecker@adacore.com> wrote:

>> C) the call to "solib_address (block->startaddr)" should be replaced with
>> something like "solib_contains_p (solib, block->startaddr)" (which would
>> then work independently of the so_list_head).
>
> Duh! Yes - this sounds like a pretty simple way to do this. We know
> which solib we're trying to match our expression against, why are we
> iterating over all SOs again? I like your suggestion.
>
> The body of solib_contains_p (can we rename it to "solib_contains_address"
> or "solib_has_address") can be extracted from solib_address.

Attached patch implements this; regtested on Linux/x86_64 with
no regressions.

Thanks,
--
Paul Pluzhnikov

2009-03-06 Paul Pluzhnikov <ppluzhnikov@google.com>

* solib.c (solib_contains_address_p): New function.
(solib_name_from_address): Use it.
* printcmd.c (display_uses_solib_p): Use it.
* solib.h (solib_contains_address_p): Declare it.

[-- Attachment #2: gdb-display-crash-20090306.txt --]
[-- Type: text/plain, Size: 2652 bytes --]

Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.146
diff -u -p -u -r1.146 printcmd.c
--- printcmd.c 6 Mar 2009 18:51:05 -0000 1.146
+++ printcmd.c 6 Mar 2009 20:32:59 -0000
@@ -1767,7 +1767,7 @@ display_uses_solib_p (const struct displ
struct expression *const exp = d->exp;

if (d->block != NULL
- && solib_name_from_address (d->block->startaddr) == solib->so_name)
+ && solib_contains_address_p (solib, d->block->startaddr))
return 1;

for (i = 0; i < exp->nelts; )
@@ -1783,7 +1783,7 @@ display_uses_solib_p (const struct displ
SYMBOL_OBJ_SECTION (symbol);

if (block != NULL
- && solib_name_from_address (block->startaddr) == solib->so_name)
+ && solib_contains_address_p (solib, block->startaddr))
return 1;

if (section && section->objfile == solib->objfile)
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.113
diff -u -p -u -r1.113 solib.c
--- solib.c 6 Mar 2009 18:51:05 -0000 1.113
+++ solib.c 6 Mar 2009 20:32:59 -0000
@@ -834,6 +834,21 @@ info_sharedlibrary_command (char *ignore
}
}

+/* Return 1 if ADDRESS lies within SOLIB. */
+
+int
+solib_contains_address_p (const struct so_list *const solib,
+ CORE_ADDR address)
+{
+ struct section_table *p;
+
+ for (p = solib->sections; p < solib->sections_end; p++)
+ if (p->addr <= address && address < p->endaddr)
+ return 1;
+
+ return 0;
+}
+
/*

GLOBAL FUNCTION
@@ -862,15 +877,8 @@ solib_name_from_address (CORE_ADDR addre
struct so_list *so = 0; /* link map state variable */

for (so = so_list_head; so; so = so->next)
- {
- struct section_table *p;
-
- for (p = so->sections; p < so->sections_end; p++)
- {
- if (p->addr <= address && address < p->endaddr)
- return (so->so_name);
- }
- }
+ if (solib_contains_address_p (so, address))
+ return (so->so_name);

return (0);
}
Index: solib.h
===================================================================
RCS file: /cvs/src/src/gdb/solib.h,v
retrieving revision 1.22
diff -u -p -u -r1.22 solib.h
--- solib.h 6 Mar 2009 18:51:05 -0000 1.22
+++ solib.h 6 Mar 2009 20:32:59 -0000
@@ -47,6 +47,10 @@ extern void solib_create_inferior_hook (

extern char *solib_name_from_address (CORE_ADDR);

+/* Return 1 if ADDR lies within SOLIB. */
+
+extern int solib_contains_address_p (const struct so_list *, CORE_ADDR);
+
/* Return 1 if PC lies in the dynamic symbol resolution code of the
run time loader. */