aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAaron Merey <amerey@redhat.com>2023-08-15 12:17:48 -0400
committerAaron Merey <amerey@redhat.com>2023-10-02 14:04:59 -0400
commit8546d15ba9421fbb5bd9bdab0f7def235f33f05a (patch)
tree47621581143548d95cc360f2ae8575a5d0848d88 /gdb
parenta0f18a2547b263a8ddd7c1a81c81dd716d246df1 (diff)
downloadgdb-8546d15ba9421fbb5bd9bdab0f7def235f33f05a.zip
gdb-8546d15ba9421fbb5bd9bdab0f7def235f33f05a.tar.gz
gdb-8546d15ba9421fbb5bd9bdab0f7def235f33f05a.tar.bz2
gdb/debuginfod: Add debuginfod_section_query
Add new function debuginfod_section_query. This function queries debuginfod servers for an individual ELF/DWARF section associated with a given build-id. Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/debuginfod-support.c60
-rw-r--r--gdb/debuginfod-support.h24
2 files changed, 84 insertions, 0 deletions
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index a41a4c9..2ca0e46 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -80,6 +80,15 @@ debuginfod_exec_query (const unsigned char *build_id,
return scoped_fd (-ENOSYS);
}
+scoped_fd
+debuginfod_section_query (const unsigned char *build_id,
+ int build_id_len,
+ const char *filename,
+ const char *section_name,
+ gdb::unique_xmalloc_ptr<char> *destname)
+{
+ return scoped_fd (-ENOSYS);
+}
#define NO_IMPL _("Support for debuginfod is not compiled into GDB.")
#else
@@ -412,6 +421,57 @@ debuginfod_exec_query (const unsigned char *build_id,
return fd;
}
+
+/* See debuginfod-support.h */
+
+scoped_fd
+debuginfod_section_query (const unsigned char *build_id,
+ int build_id_len,
+ const char *filename,
+ const char *section_name,
+ gdb::unique_xmalloc_ptr<char> *destname)
+{
+#if !defined (HAVE_LIBDEBUGINFOD_FIND_SECTION)
+ return scoped_fd (-ENOSYS);
+#else
+
+ if (!debuginfod_is_enabled ())
+ return scoped_fd (-ENOSYS);
+
+ debuginfod_client *c = get_debuginfod_client ();
+
+ if (c == nullptr)
+ return scoped_fd (-ENOMEM);
+
+ char *dname = nullptr;
+ std::string desc = std::string ("section ") + section_name + " for";
+ scoped_fd fd;
+ gdb::optional<target_terminal::scoped_restore_terminal_state> term_state;
+
+ {
+ user_data data (desc.c_str (), filename);
+ debuginfod_set_user_data (c, &data);
+ if (target_supports_terminal_ours ())
+ {
+ term_state.emplace ();
+ target_terminal::ours ();
+ }
+
+ fd = scoped_fd (debuginfod_find_section (c, build_id, build_id_len,
+ section_name, &dname));
+ debuginfod_set_user_data (c, nullptr);
+ }
+
+ print_outcome (fd.get (), desc.c_str (), filename);
+ gdb_assert (destname != nullptr);
+
+ if (fd.get () >= 0)
+ destname->reset (dname);
+
+ return fd;
+#endif /* HAVE_LIBDEBUGINFOD_FIND_SECTION */
+}
+
#endif
/* Set callback for "set debuginfod enabled". */
diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h
index 633600a..9701e3b 100644
--- a/gdb/debuginfod-support.h
+++ b/gdb/debuginfod-support.h
@@ -81,4 +81,28 @@ extern scoped_fd debuginfod_exec_query (const unsigned char *build_id,
const char *filename,
gdb::unique_xmalloc_ptr<char>
*destname);
+
+/* Query debuginfod servers for the binary contents of a ELF/DWARF section
+ from a file matching BUILD_ID. BUILD_ID can be given as a binary blob
+ or a null-terminated string. If given as a binary blob, BUILD_ID_LEN
+ should be the number of bytes. If given as a null-terminated string,
+ BUILD_ID_LEN should be 0.
+
+ FILENAME should be the name or path associated with the file matching
+ BUILD_ID. It is used for printing messages to the user.
+
+ SECTION_NAME should be the name of an ELF/DWARF section.
+
+ If the file is successfully retrieved, return a file descriptor and store
+ the file's local path in DESTNAME. If unsuccessful, print an error message
+ and return a negative errno. If GDB is not built with debuginfod or
+ libdebuginfod does not support section queries, this function returns
+ -ENOSYS. */
+
+extern scoped_fd debuginfod_section_query (const unsigned char *build_id,
+ int build_id_len,
+ const char *filename,
+ const char *section_name,
+ gdb::unique_xmalloc_ptr<char>
+ *destname);
#endif /* DEBUGINFOD_SUPPORT_H */