gdb: define COFF file offsets with file_ptr

The arguments to these functions are file_ptr, so these declarations
were accidentally implicitly down-casting them to signed int. This
allows for reading files between 2 and 4 GB in size in my testing (I
don't have a larger dll currently to test). These may not be natively
supported by Windows, but can appear when using split-dwarf information.

This solves a "can't get string table" error resulting from attempting
to pass a negative offset to bfd_seek. I encountered this occuring while
trying to use a debug file for libLLVM.dll, but searching online reveals
at least one other person may have run into a similar problem with
Firefox?

    https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/CA+cU71k2bU0azQxjy4-77ynQj1O+TKmgtaTKe59n7Bjub1y7Tg@mail.gmail.com/

With this patch, the debug file appears to load successfully and I can
see debug information in gdb for the library.

gdb/ChangeLog:

	* coffread.c (linetab_offset): Change type to file_ptr.
	(linetab_size): Likewise.
	(enter_linenos): Change parameter type to file_ptr.
	(init_lineno): Likewise.
	(init_stringtab): Likewise.
	(coff_symtab_read): Likewise.
	(coff_symfile_read): Change variable types to file_ptr.

Change-Id: I6ae3bf31efc51c826734ade6731ea6b1c32129f3
This commit is contained in:
Jameson Nash 2020-12-18 14:08:53 -05:00 committed by Simon Marchi
parent 86ef42bd73
commit a9e48095a8
2 changed files with 25 additions and 15 deletions

View file

@ -1,3 +1,13 @@
2020-12-18 Jameson Nash <vtjnash@gmail.com>
* coffread.c (linetab_offset): Change type to file_ptr.
(linetab_size): Likewise.
(enter_linenos): Change parameter type to file_ptr.
(init_lineno): Likewise.
(init_stringtab): Likewise.
(coff_symtab_read): Likewise.
(coff_symfile_read): Change variable types to file_ptr.
2020-12-17 Tom Tromey <tromey@adacore.com> 2020-12-17 Tom Tromey <tromey@adacore.com>
* printcmd.c (print_variable_and_value): Don't use n_spaces. * printcmd.c (print_variable_and_value): Don't use n_spaces.

View file

@ -155,8 +155,8 @@ static int type_vector_length;
#define INITIAL_TYPE_VECTOR_LENGTH 160 #define INITIAL_TYPE_VECTOR_LENGTH 160
static char *linetab = NULL; static char *linetab = NULL;
static long linetab_offset; static file_ptr linetab_offset;
static unsigned long linetab_size; static file_ptr linetab_size;
static char *stringtab = NULL; static char *stringtab = NULL;
@ -188,23 +188,23 @@ static struct symbol *process_coff_symbol (struct coff_symbol *,
static void patch_opaque_types (struct symtab *); static void patch_opaque_types (struct symtab *);
static void enter_linenos (long, int, int, struct objfile *); static void enter_linenos (file_ptr, int, int, struct objfile *);
static int init_lineno (bfd *, long, int, gdb::unique_xmalloc_ptr<char> *); static int init_lineno (bfd *, file_ptr, file_ptr, gdb::unique_xmalloc_ptr<char> *);
static char *getsymname (struct internal_syment *); static char *getsymname (struct internal_syment *);
static const char *coff_getfilename (union internal_auxent *); static const char *coff_getfilename (union internal_auxent *);
static int init_stringtab (bfd *, long, gdb::unique_xmalloc_ptr<char> *); static int init_stringtab (bfd *, file_ptr, gdb::unique_xmalloc_ptr<char> *);
static void read_one_sym (struct coff_symbol *, static void read_one_sym (struct coff_symbol *,
struct internal_syment *, struct internal_syment *,
union internal_auxent *); union internal_auxent *);
static void coff_symtab_read (minimal_symbol_reader &, static void coff_symtab_read (minimal_symbol_reader &,
long, unsigned int, struct objfile *); file_ptr, unsigned int, struct objfile *);
/* We are called once per section from coff_symfile_read. We /* We are called once per section from coff_symfile_read. We
need to examine each section we are passed, check to see need to examine each section we are passed, check to see
if it is something we are interested in processing, and if it is something we are interested in processing, and
@ -540,9 +540,9 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
const char *filename = bfd_get_filename (abfd); const char *filename = bfd_get_filename (abfd);
int val; int val;
unsigned int num_symbols; unsigned int num_symbols;
int symtab_offset; file_ptr symtab_offset;
int stringtab_offset; file_ptr stringtab_offset;
int stabstrsize; unsigned int stabstrsize;
info = coff_objfile_data_key.get (objfile); info = coff_objfile_data_key.get (objfile);
symfile_bfd = abfd; /* Kludge for swap routines. */ symfile_bfd = abfd; /* Kludge for swap routines. */
@ -750,7 +750,7 @@ coff_symfile_finish (struct objfile *objfile)
static void static void
coff_symtab_read (minimal_symbol_reader &reader, coff_symtab_read (minimal_symbol_reader &reader,
long symtab_offset, unsigned int nsyms, file_ptr symtab_offset, unsigned int nsyms,
struct objfile *objfile) struct objfile *objfile)
{ {
struct gdbarch *gdbarch = objfile->arch (); struct gdbarch *gdbarch = objfile->arch ();
@ -796,7 +796,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
bfd_seek (objfile->obfd, 0, 0); bfd_seek (objfile->obfd, 0, 0);
/* Position to read the symbol table. */ /* Position to read the symbol table. */
val = bfd_seek (objfile->obfd, (long) symtab_offset, 0); val = bfd_seek (objfile->obfd, symtab_offset, 0);
if (val < 0) if (val < 0)
perror_with_name (objfile_name (objfile)); perror_with_name (objfile_name (objfile));
@ -1270,7 +1270,7 @@ read_one_sym (struct coff_symbol *cs,
/* Support for string table handling. */ /* Support for string table handling. */
static int static int
init_stringtab (bfd *abfd, long offset, gdb::unique_xmalloc_ptr<char> *storage) init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *storage)
{ {
long length; long length;
int val; int val;
@ -1366,7 +1366,7 @@ coff_getfilename (union internal_auxent *aux_entry)
them into GDB's data structures. */ them into GDB's data structures. */
static int static int
init_lineno (bfd *abfd, long offset, int size, init_lineno (bfd *abfd, file_ptr offset, file_ptr size,
gdb::unique_xmalloc_ptr<char> *storage) gdb::unique_xmalloc_ptr<char> *storage)
{ {
int val; int val;
@ -1399,7 +1399,7 @@ init_lineno (bfd *abfd, long offset, int size,
#endif #endif
static void static void
enter_linenos (long file_offset, int first_line, enter_linenos (file_ptr file_offset, int first_line,
int last_line, struct objfile *objfile) int last_line, struct objfile *objfile)
{ {
struct gdbarch *gdbarch = objfile->arch (); struct gdbarch *gdbarch = objfile->arch ();