From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by sourceware.org (Postfix) with ESMTPS id 283533972035 for ; Thu, 26 Nov 2020 18:12:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 283533972035 Received: by mail-qk1-x735.google.com with SMTP id x25so2280864qkj.3 for ; Thu, 26 Nov 2020 10:12:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2KQJXLgBYoDFlrT9lxEizVgACS8mqR2pCymzKEAlqzs=; b=ES/8Gg4RyEE5mis1UJ7wJb6Sub33INlg43o9D9qAm4x5EF5cjsNDCr+5Fx4qq1GHv0 a5jde/nJ8iwBu3vZdtL7INBhRGxcl7cZsU3qgEHlJt56qR06CqmH9cuT5448yBQp/kNZ RZvo6yM3IxiCvUubEz2fgV/39h9UylPU69XZueeoPZyWYyRiYfegL6L2vKUm/TrCoRe3 8PFGxqQLFM6LzrFEO8ikGYdeNHZjixO3nS0fIqFr/Ce1Wb56kf6vMz0zHaKxJh1YXlQq MfoSXqB6Y9WwyiHN3mzmUp9bIwZ01qJsxIhHacB+e6Ly04OBqBTfMSL57B3Wxc1UnVLc puAw== X-Gm-Message-State: AOAM531zmYjV7h86P//xH6U5OP68/Bzpq2isF1+ruaumHZwMdqIQdQLd ohH+OS5Atwu/wnmlGLm35+kEqhhw9fpUqw== X-Google-Smtp-Source: ABdhPJx81S/ZddJkkUfthelaNfIHxrhbD7s9s+Ka7/hIiIxXkVlLrD0Bn72GiF3C1YbrTA73o311IQ== X-Received: by 2002:a05:620a:15ce:: with SMTP id o14mr4455934qkm.231.1606414367325; Thu, 26 Nov 2020 10:12:47 -0800 (PST) Received: from localhost.localdomain (c-66-30-9-171.hsd1.ma.comcast.net. [66.30.9.171]) by smtp.gmail.com with ESMTPSA id q20sm3605997qke.0.2020.11.26.10.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 10:12:46 -0800 (PST) From: Jameson Nash To: gdb-patches@sourceware.org Cc: Jameson Nash Subject: [PATCH] gdb: define COFF file offsets with file_ptr Date: Thu, 26 Nov 2020 13:11:21 -0500 Message-Id: <20201126181121.31219-1-vtjnash@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Nov 2020 18:12:50 -0000 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: Define COFF file offsets with file_ptr to support files over 2GB. --- gdb/coffread.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index c61c9a7ca1..8e0e9543ae 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -155,8 +155,8 @@ static int type_vector_length; #define INITIAL_TYPE_VECTOR_LENGTH 160 static char *linetab = NULL; -static long linetab_offset; -static unsigned long linetab_size; +static file_ptr linetab_offset; +static file_ptr linetab_size; 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 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 *); +static int init_lineno (bfd *, file_ptr, file_ptr, gdb::unique_xmalloc_ptr *); static char *getsymname (struct internal_syment *); static const char *coff_getfilename (union internal_auxent *); -static int init_stringtab (bfd *, long, gdb::unique_xmalloc_ptr *); +static int init_stringtab (bfd *, file_ptr, gdb::unique_xmalloc_ptr *); static void read_one_sym (struct coff_symbol *, struct internal_syment *, union internal_auxent *); 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 need to examine each section we are passed, check to see 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); int val; unsigned int num_symbols; - int symtab_offset; - int stringtab_offset; - int stabstrsize; + file_ptr symtab_offset; + file_ptr stringtab_offset; + unsigned int stabstrsize; info = coff_objfile_data_key.get (objfile); symfile_bfd = abfd; /* Kludge for swap routines. */ @@ -741,7 +741,7 @@ coff_symfile_finish (struct objfile *objfile) /* Let stabs reader clean up. */ stabsread_clear_cache (); } - + /* Given pointers to a symbol table in coff style exec file, analyze them and create struct symtab's describing the symbols. @@ -750,7 +750,7 @@ coff_symfile_finish (struct objfile *objfile) static void coff_symtab_read (minimal_symbol_reader &reader, - long symtab_offset, unsigned int nsyms, + file_ptr symtab_offset, unsigned int nsyms, struct objfile *objfile) { struct gdbarch *gdbarch = objfile->arch (); @@ -796,7 +796,7 @@ coff_symtab_read (minimal_symbol_reader &reader, bfd_seek (objfile->obfd, 0, 0); /* 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) perror_with_name (objfile_name (objfile)); @@ -1183,7 +1183,7 @@ coff_symtab_read (minimal_symbol_reader &reader, coffread_objfile = NULL; } - + /* Routines for reading headers and symbols from executable. */ /* Read the next symbol, swap it, and return it in both @@ -1270,7 +1270,7 @@ read_one_sym (struct coff_symbol *cs, /* Support for string table handling. */ static int -init_stringtab (bfd *abfd, long offset, gdb::unique_xmalloc_ptr *storage) +init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr *storage) { long length; int val; @@ -1366,7 +1366,7 @@ coff_getfilename (union internal_auxent *aux_entry) them into GDB's data structures. */ static int -init_lineno (bfd *abfd, long offset, int size, +init_lineno (bfd *abfd, file_ptr offset, file_ptr size, gdb::unique_xmalloc_ptr *storage) { int val; @@ -1399,7 +1399,7 @@ init_lineno (bfd *abfd, long offset, int size, #endif 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) { struct gdbarch *gdbarch = objfile->arch (); -- 2.29.2