From patchwork Thu Mar 26 10:23:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 5822 Received: (qmail 84533 invoked by alias); 26 Mar 2015 10:23:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 84523 invoked by uid 89); 26 Mar 2015 10:23:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 26 Mar 2015 10:23:16 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2QANAr3005342 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 26 Mar 2015 06:23:10 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2QAN9YF011588; Thu, 26 Mar 2015 06:23:09 -0400 Message-ID: <5513DE0C.3020107@redhat.com> Date: Thu, 26 Mar 2015 10:23:08 +0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Jon TURNEY , gdb-patches@sourceware.org Subject: Re: [PATCH] Don't set breakpoints on import stubs on Windows amd64 References: <1425646709-5216-1-git-send-email-jon.turney@dronecode.org.uk> <550A09BE.7020601@redhat.com> <550C44D2.5070306@dronecode.org.uk> In-Reply-To: <550C44D2.5070306@dronecode.org.uk> On 03/20/2015 04:03 PM, Jon TURNEY wrote: > On 18/03/2015 23:26, Pedro Alves wrote: >>> diff --git a/gdb/coffread.c b/gdb/coffread.c >>> index 366d828..21e7a77 100644 >>> --- a/gdb/coffread.c >>> +++ b/gdb/coffread.c >>> @@ -675,7 +675,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) >>> && (strncmp (name, "__imp_", 6) == 0 >>> || strncmp (name, "_imp_", 5) == 0)) >>> { >>> - const char *name1 = (name[1] == '_' ? &name[7] : &name[6]); >>> + const char *name1 = &name[6]; >>> struct bound_minimal_symbol found; >> >> As is, that would make it look suspiciously like a bug to a casual >> reader. It'd be very good to have a comment here. >> But maybe if we rewrite this in terms of bfd_get_symbol_leading_char, >> it ends up being "self commenting". Something like the hunk below. > > Yes, that is better, and seems to work fine. Alright, now pushed. ---- From 20d35291fb30a2fa5de46af56887f9bc4da7e53e Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 26 Mar 2015 10:21:07 +0000 Subject: [PATCH] Don't set breakpoints on import stubs on Windows amd64 On Windows amd64, setting a breakpoint on a symbol imported from a shared library after that library is loaded creates a breakpoint with two locations, one on the import stub, and another in the shared library, while on i386, the breakpoint is only set in the shared library. This is due to the minimal symbol for the import stub not being correctly given the type mst_solib_trampoline on Windows amd64, unlike Windows i386. As currently written, coff_symfile_read is always skipping over the character after the "__imp_" (amd64) or "_imp_" (i386) prefix, assuming that it is '_'. However, while i386 is an underscored target, amd64 is not. On x86_64-pc-cygwin, it fixes: - FAIL: gdb.base/solib-symbol.exp: foo in libmd + PASS: gdb.base/solib-symbol.exp: foo in libmd Unfortunately, several other tests which passed now fail but that's because this issue was masking other problems. No change on i686-pc-cygwin. gdb/ChangeLog: 2015-03-26 Pedro Alves Jon TURNEY * coffread.c (coff_symfile_read): When constructing the name of an import stub symbol from import symbol for amd64, only skip the char after _imp_ if the target is underscored (like i386) and the char is indeed the target's leading char. --- gdb/ChangeLog | 8 ++++++++ gdb/coffread.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index febc377..66bfbae 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2015-03-26 Pedro Alves + Jon TURNEY + + * coffread.c (coff_symfile_read): When constructing the name of an + import stub symbol from import symbol for amd64, only skip the + char after _imp_ if the target is underscored (like i386) and the + char is indeed the target's leading char. + 2015-03-25 Pedro Alves * target.h : Replace 'callback' and 'context' parameters diff --git a/gdb/coffread.c b/gdb/coffread.c index 28f7b18..3b5a968 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -671,20 +671,31 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags) or "_imp_", get rid of the prefix, and search the minimal symbol in OBJFILE. Note that 'maintenance print msymbols' shows that type of these "_imp_XXXX" symbols is mst_data. */ - if (MSYMBOL_TYPE (msym) == mst_data - && (startswith (name, "__imp_") - || startswith (name, "_imp_"))) + if (MSYMBOL_TYPE (msym) == mst_data) { - const char *name1 = (name[1] == '_' ? &name[7] : &name[6]); - struct bound_minimal_symbol found; - - found = lookup_minimal_symbol (name1, NULL, objfile); - /* If found, there are symbols named "_imp_foo" and "foo" - respectively in OBJFILE. Set the type of symbol "foo" - as 'mst_solib_trampoline'. */ - if (found.minsym != NULL - && MSYMBOL_TYPE (found.minsym) == mst_text) - MSYMBOL_TYPE (found.minsym) = mst_solib_trampoline; + const char *name1 = NULL; + + if (startswith (name, "_imp_")) + name1 = name + 5; + else if (startswith (name, "__imp_")) + name1 = name + 6; + if (name1 != NULL) + { + int lead = bfd_get_symbol_leading_char (objfile->obfd); + struct bound_minimal_symbol found; + + if (lead != '\0' && *name1 == lead) + name1 += 1; + + found = lookup_minimal_symbol (name1, NULL, objfile); + + /* If found, there are symbols named "_imp_foo" and "foo" + respectively in OBJFILE. Set the type of symbol "foo" + as 'mst_solib_trampoline'. */ + if (found.minsym != NULL + && MSYMBOL_TYPE (found.minsym) == mst_text) + MSYMBOL_TYPE (found.minsym) = mst_solib_trampoline; + } } } }