From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102899 invoked by alias); 3 Aug 2015 23:31:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 102886 invoked by uid 89); 3 Aug 2015 23:31:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ig0-f169.google.com Received: from mail-ig0-f169.google.com (HELO mail-ig0-f169.google.com) (209.85.213.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 03 Aug 2015 23:31:50 +0000 Received: by iggf3 with SMTP id f3so550605igg.1 for ; Mon, 03 Aug 2015 16:31:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=cSVs00qu6bW2712pPHh1fTBYMpAIliMUEXQWR3rtCx0=; b=Uv4gRUQvmdnfuodC+oh5G4QPa0lU8+QS4iM5Hc8lHeOXUPjtT7Qt4T/0CYOuZM86qp RTOTMrPSeI9DvGZ6zUyeqxtgae3zoV5Nby//qOYTd8KuEeq1HFSoEWnxC11UO5ARA8Xe /d5j+2P4kf1j6Vw+izdFolS+Erhc/xkKx1IvdK0bas7rpj5Adk8NypifenWlnQYn8A/w xeQGcBB91ShnnONZ4zxbvhYjOSPkZBKsSvmP4MwfRJsKjoXOQKq+aClGidqlMZdXST4d j8tpT3fh3jt/5HkUwnFjh6wERM9DechG5IW1sFN+llKrv/FMgJe0qjr7yYJVbOnNzYGq gTvw== X-Gm-Message-State: ALoCoQl8voq6LPUBxf/8/HkFm9DA6aldf/90xkG3kbBfzVid19kplU5J+3Yy01QxfJn9JXP8F0/T X-Received: by 10.50.79.196 with SMTP id l4mr23375136igx.48.1438644708677; Mon, 03 Aug 2015 16:31:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.93.102 with HTTP; Mon, 3 Aug 2015 16:31:08 -0700 (PDT) In-Reply-To: <20150803154721.29a6a4ec@pinnacle.lan> References: <20150803154721.29a6a4ec@pinnacle.lan> From: Doug Evans Date: Mon, 03 Aug 2015 23:31:00 -0000 Message-ID: Subject: Re: [PATCH] dwarf2read.c: Check type of linkage name attribute prior to decoding To: Kevin Buettner Cc: gdb-patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-08/txt/msg00055.txt.bz2 On Mon, Aug 3, 2015 at 3:47 PM, Kevin Buettner wrote: > This is a fix for PR 16822. Keith Seitz wrote the patch for the fix. I > wrote the test case. > > The Texas Instruments compiler uses the encoding for > DW_AT_MIPS_linkage_name for other purposes. TI uses the encoding, > 0x2007, for TI_AT_TI_end_line which, unlike DW_AT_MIPS_linkage_name, > does not have a string-typed value. Keith's patch simply makes sure > that linkage_name attributes have a string type prior to attempting to > decode them as such. > > My test case causes GDB to segfault in an unpatched GDB. There > will be one PASS in a patched GDB. > > Unpatched GDB: > > (gdb) file testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name > Reading symbols from testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name...done. > ERROR: Couldn't load testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name into gdb (eof). > ERROR: Couldn't send ptype return_true to GDB. > UNRESOLVED: gdb.dwarf2/dw2-bad-mips-linkage-name.exp: ptype return_true > > Patched GDB: > > (gdb) file testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name > Reading symbols from /mesquite2/sourceware-git/mesquite-native-5894223/bld/gdb/testsuite/gdb.dwarf2/dw2-bad-mips-linkage-name...done. > (gdb) ptype return_true > type = bool (void) > (gdb) PASS: gdb.dwarf2/dw2-bad-mips-linkage-name.exp: ptype return_true > > gdb/ChangeLog: > > * dwarf2read.c (dwarf2_physname): Verify that the attribute > is a string prior to decoding it as such. > > gdb/testsuite/ChangeLog: > > * gdb.dwarf2/dw2-bad-mips-linkage-name.S: New file. > * gdb.dwarf2/dw2-bad-mips-linkage-name.exp: New file. Hi. If I wanted to regenerate the .S how would I do it? [generated .S files needs such instructions] I wonder, though, if this is a good place for using the dwarf assembler. Seems so. We just need a MIPS_linkage_name attribute that isn't a string. The dwarf assembler test would be a lot smaller. > > diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c > index 24a4022..9eb7cbc 100644 > --- a/gdb/dwarf2read.c > +++ b/gdb/dwarf2read.c > @@ -8722,7 +8722,10 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) > > /* DW_AT_linkage_name is missing in some cases - depend on what GDB > has computed. */ > - if (attr && DW_STRING (attr)) > + if (attr > + && (attr->form == DW_FORM_strp || attr->form == DW_FORM_string > + || attr->form == DW_FORM_GNU_strp_alt) > + && DW_STRING (attr)) > { > char *demangled; One thought that comes to mind is that gdb should protect itself from all such mistakes. What if there was a wrapper on dwarf2_attr, dwarf2_string_attr or some such, and it returned either the attribute (if the attribute is present *and* is a string) or NULL. And if the attribute is present but not a string it logs a complaint (standard bad debug info complaint) and returns NULL.