aboutsummaryrefslogtreecommitdiff
path: root/gdb/solib.c
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2015-07-15 17:37:28 +0200
committerJan Kratochvil <jan.kratochvil@redhat.com>2015-07-15 17:42:07 +0200
commitca5268b6be265580b91ef75c1a1a9815f581ae42 (patch)
treebfe99b4ca46a726297c74f34ea68abe95d546ec2 /gdb/solib.c
parent700ca40f6fc1addd7238f4ab57f76c095ad3c99f (diff)
Validate symbol file using build-id
Consumer part of the "build-id" attribute. gdb/ChangeLog 2015-07-15 Aleksandar Ristovski <aristovski@qnx.com Jan Kratochvil <jan.kratochvil@redhat.com> Validate symbol file using build-id. * NEWS (Changes since GDB 7.10): Add 'set validate-build-id' and 'show validate-build-id'. Add build-id attribute. * solib-darwin.c (_initialize_darwin_solib): Assign validate value. * solib-dsbt.c (_initialize_dsbt_solib): Ditto. * solib-frv.c (_initialize_frv_solib): Ditto. * solib-spu.c (set_spu_solib_ops): Ditto. * solib-svr4.c: Include rsp-low.h. (NOTE_GNU_BUILD_ID_NAME): New define. (svr4_validate): New function. (svr4_copy_library_list): Duplicate field build_id. (library_list_start_library): Parse 'build-id' attribute. (svr4_library_attributes): Add 'build-id' attribute. (_initialize_svr4_solib): Assign validate value. * solib-target.c (solib.h): Include. (_initialize_solib_target): Assign validate value. * solib.c (validate_build_id, show_validate_build_id): New. (solib_map_sections): Use ops->validate. (clear_so): Free build_id. (default_solib_validate): New function. (_initialize_solib): Add "validate-build-id". * solib.h (default_solib_validate): New declaration. * solist.h (struct so_list): New fields 'build_idsz' and 'build_id'. (target_so_ops): New field 'validate'. gdb/doc/ChangeLog 2015-07-15 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.texinfo (Files): Add 'set validate-build-id' and 'show validate-build-id'.
Diffstat (limited to 'gdb/solib.c')
-rw-r--r--gdb/solib.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/gdb/solib.c b/gdb/solib.c
index eb933c044d..01c66dba8e 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -518,6 +518,20 @@ solib_bfd_open (char *pathname)
return abfd;
}
+/* Boolean for command 'set validate-build-id'. */
+static int validate_build_id = 1;
+
+/* Implement 'show validate-build-id'. */
+
+static void
+show_validate_build_id (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Validation a build-id matches to load a shared "
+ "library is %s.\n"),
+ value);
+}
+
/* Given a pointer to one of the shared objects in our list of mapped
objects, use the recorded name to open a bfd descriptor for the
object, build a section table, relocate all the section addresses
@@ -534,7 +548,7 @@ static int
solib_map_sections (struct so_list *so)
{
const struct target_so_ops *ops = solib_ops (target_gdbarch ());
- char *filename;
+ char *filename, *validate_error;
struct target_section *p;
struct cleanup *old_chain;
bfd *abfd;
@@ -550,6 +564,29 @@ solib_map_sections (struct so_list *so)
/* Leave bfd open, core_xfer_memory and "info files" need it. */
so->abfd = abfd;
+ gdb_assert (ops->validate != NULL);
+
+ validate_error = ops->validate (so);
+ if (validate_error != NULL)
+ {
+ if (validate_build_id)
+ {
+ warning (_("Shared object \"%s\" could not be validated (%s) and "
+ "will be ignored; "
+ "or use 'set validate-build-id off'."),
+ so->so_name, validate_error);
+ xfree (validate_error);
+ gdb_bfd_unref (so->abfd);
+ so->abfd = NULL;
+ return 0;
+ }
+ warning (_("Shared object \"%s\" could not be validated (%s) "
+ "but it is being loaded due to "
+ "'set validate-build-id off'."),
+ so->so_name, validate_error);
+ xfree (validate_error);
+ }
+
/* Copy the full path name into so_name, allowing symbol_file_add
to find it later. This also affects the =library-loaded GDB/MI
event, and in particular the part of that notification providing
@@ -626,6 +663,9 @@ clear_so (struct so_list *so)
of the symbol file. */
strcpy (so->so_name, so->so_original_name);
+ xfree (so->build_id);
+ so->build_id = NULL;
+
/* Do the same for target-specific data. */
if (ops->clear_so != NULL)
ops->clear_so (so);
@@ -1657,6 +1697,14 @@ remove_user_added_objfile (struct objfile *objfile)
}
}
+/* Default implementation does not perform any validation. */
+
+char *
+default_solib_validate (const struct so_list *const so)
+{
+ return NULL; /* No validation. */
+}
+
extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
void
@@ -1714,4 +1762,18 @@ PATH and LD_LIBRARY_PATH."),
reload_shared_libraries,
show_solib_search_path,
&setlist, &showlist);
+
+ add_setshow_boolean_cmd ("validate-build-id", class_support,
+ &validate_build_id, _("\
+Set validation a build-id matches to load a shared library."), _("\
+SHow validation a build-id matches to load a shared library."), _("\
+Inferior shared library and symbol file may contain unique build-id.\n\
+If both build-ids are present but they do not match then this setting\n\
+enables (off) or disables (on) loading of such symbol file.\n\
+Loading non-matching symbol file may confuse debugging including breakage\n\
+of backtrace output."),
+ NULL,
+ show_validate_build_id,
+ &setlist, &showlist);
+
}