From dcae9fd7d768b033502368decadf98ab1edd29e3 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Sun, 12 Jul 2020 14:35:26 +0200 Subject: [PATCH] Implement R_PDB loading in bfd We disable symbol_file_add_separate for now so the old symbol loading still works. --- bfd/Makefile.in | 2 +- bfd/pdb.c | 44 +++++++++++++++++++++++++++++++++++++++++++- bfd/pdb.h | 9 ++++++++- gdb/coffread.c | 4 ++-- gdb/pdb.c | 2 +- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 8dea121..991ab0c 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -210,7 +210,7 @@ AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = -DEFAULT_INCLUDES = -I.@am__isrc@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I/usr/include/libr depcomp = $(SHELL) $(top_srcdir)/../depcomp am__depfiles_maybe = depfiles am__mv = mv -f diff --git a/bfd/pdb.c b/bfd/pdb.c index faec57b..384510f 100644 --- a/bfd/pdb.c +++ b/bfd/pdb.c @@ -6,7 +6,7 @@ bfd_boolean bfd_pdb_close_and_cleanup (bfd *abfd) { - return FALSE; + return TRUE; } /* Ask the BFD to free all cached information. */ @@ -89,9 +89,51 @@ bfd_pdb_find_nearest_line (bfd *abfd, #define bfd_pdb_read_minisymbols _bfd_generic_read_minisymbols #define bfd_pdb_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol +static st64 +r_buffer_read (RBuffer *buffer, ut8 *out, ut64 length) +{ + bfd *abfd = buffer->priv; + return abfd->iovec->bread (abfd, out, length); +} + +static st64 +r_buffer_seek (RBuffer *buffer, st64 address, int whence) +{ + bfd *abfd = buffer->priv; + return abfd->iovec->bseek (abfd, address, whence); +} + +static bfd_pdb_data_struct * +get_bfd_pdb_data (bfd *abfd) +{ + RBufferMethods *buffer_methods = bfd_zalloc (abfd, sizeof (RBufferMethods)); + buffer_methods->read = &r_buffer_read; + buffer_methods->seek = &r_buffer_seek; + + RBuffer *r_buffer = bfd_zalloc (abfd, sizeof (RBuffer)); + r_buffer->methods = buffer_methods; + r_buffer->priv = abfd; + r_buffer->readonly = TRUE; + + R_PDB *pdb = bfd_zalloc (abfd, sizeof (R_PDB)); + if (init_pdb_parser_with_buf (pdb, r_buffer)) + { + bfd_pdb_data_struct *result = bfd_alloc (abfd, sizeof (bfd_pdb_data_struct)); + result->pdb = pdb; + return result; + } + + return NULL; +} + const bfd_target * bfd_pdb_check_format (bfd *abfd) { + if ((abfd->tdata.pdb_data = get_bfd_pdb_data (abfd))) + { + return abfd->xvec; + } + bfd_set_error (bfd_error_wrong_format); return NULL; } diff --git a/bfd/pdb.h b/bfd/pdb.h index 9b533b5..b861bdc 100644 --- a/bfd/pdb.h +++ b/bfd/pdb.h @@ -2,4 +2,11 @@ #include "sysdep.h" #include "bfd.h" -#include "libbfd.h" \ No newline at end of file +#include "libbfd.h" + +#include + +typedef struct pdb_data_struct +{ + R_PDB* pdb; +} bfd_pdb_data_struct; diff --git a/gdb/coffread.c b/gdb/coffread.c index 382cbb8..4f73487 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -732,8 +732,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) gdb_bfd_ref_ptr debug_bfd (try_load_pdb_bfd (objfile)); if (debug_bfd.get ()) { - symbol_file_add_separate (debug_bfd.get (), debug_bfd->filename, - symfile_flags, objfile); + //symbol_file_add_separate (debug_bfd.get (), debug_bfd->filename, + // symfile_flags, objfile); } } } diff --git a/gdb/pdb.c b/gdb/pdb.c index c7029e8..bdfcd47 100644 --- a/gdb/pdb.c +++ b/gdb/pdb.c @@ -238,7 +238,7 @@ get_pdb_paths (struct objfile *objfile) auto codeview_pdb_path = get_codeview_pdb_path (objfile); if (!codeview_pdb_path) - return paths; + return paths; //if there is no CodeView PDB path, we assume no PDB exists paths.push_back (*codeview_pdb_path); paths.push_back ("target:" + *codeview_pdb_path);