From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18355 invoked by alias); 14 Feb 2013 00:14:08 -0000 Received: (qmail 18346 invoked by uid 22791); 14 Feb 2013 00:14:06 -0000 X-SWARE-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-vb0-f74.google.com (HELO mail-vb0-f74.google.com) (209.85.212.74) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Feb 2013 00:13:58 +0000 Received: by mail-vb0-f74.google.com with SMTP id r6so188019vbi.3 for ; Wed, 13 Feb 2013 16:13:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:subject:date:message-id:mime-version :content-type:x-gm-message-state; bh=IpTWJ2tRbB5D4dvfH/XQOmem1HfDepOkugXduLJwR90=; b=XRu9T+cCtDdUcwlB9Vfu4s/QoG7ipKFknzNGKEzuBah83df9DVPGSZ04bXHvePpxzv m8OhexVFYrFdc2g3hNl0wI/TQdZBc08M8JhWDCJOuoRNrmF584KJ6yw2MXv2gvXu76B6 gzUARVey1kMH/8eQB+PohLBKU71EVV4XWWkMt4oxCSfvKIPV2VPe/BUa8K+bbJWMqBHU IJSdB5yArveM+7bJXzrOeyHcsJAeIPlQMMCVHGy/p3Igst6KMI4QhF3ncU4GJ7qq3Hhe WAhGLkHN5q+czNPQgpIdJgOTyHLyxbWnkAavWO2dwur5Umi/CuJYp370KUeC6ezL/QOx awBw== X-Received: by 10.101.105.17 with SMTP id h17mr1338091anm.17.1360800837564; Wed, 13 Feb 2013 16:13:57 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id e7si2049943yhk.3.2013.02.13.16.13.57 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 13 Feb 2013 16:13:57 -0800 (PST) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.108]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 3549C31C200 for ; Wed, 13 Feb 2013 16:13:57 -0800 (PST) From: Doug Evans To: gdb-patches@sourceware.org Subject: [RFA] fix disassemble foo::bar::~bar Date: Thu, 14 Feb 2013 00:14:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQlSiPS7wUpO03kDZBoSFJ3PYwdkISRR6tV56AP0lY7SvwC+aRT5/uvyhw1rx/h6nxp7Uwa68ipy3fPBxJLp8mweHM/U5uXCt8eVutT90zl4S+JcBP+We7lh+5h4hItFYOrOea0saCrZK6WOH+6DqlabtKocSLfoKIZUepcMZddzOxOSRMN6WDMPp6CV+tVMCmOhird1Uj1ZrsIghv2WiCqWCzDrJnO9PEc72b/OJ1Zdnu/fnA8= X-IsSubscribed: yes 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 X-SW-Source: 2013-02/txt/msg00334.txt.bz2 I happened to try this and noticed it failing with "name of destructor must equal name of class". This is because destructor_name_p doesn't handle foo::bar for the type's name. Regression tested on amd64-linux. Ok to commit? 2013-02-13 Doug Evans * valops.c (destructor_name_p): Fix handling of classes in namespaces. testsuite/ * gdb.cp/cp-disasm.cc: New file. * gdb.cp/cp-disasm.exp: New file. Index: valops.c =================================================================== RCS file: /cvs/src/src/gdb/valops.c,v retrieving revision 1.312 diff -u -p -r1.312 valops.c --- valops.c 11 Feb 2013 18:05:33 -0000 1.312 +++ valops.c 14 Feb 2013 00:13:16 -0000 @@ -3160,20 +3160,28 @@ destructor_name_p (const char *name, str { if (name[0] == '~') { - const char *dname = type_name_no_tag_or_error (type); - const char *cp = strchr (dname, '<'); + char *type_name = xstrdup (type_name_no_tag_or_error (type)); + char *cp = strchr (type_name, '<'); + char *colon; + struct cleanup *cleanups = make_cleanup (xfree, type_name); unsigned int len; /* Do not compare the template part for template classes. */ - if (cp == NULL) - len = strlen (dname); - else - len = cp - dname; - if (strlen (name + 1) != len || strncmp (dname, name + 1, len) != 0) + if (cp != NULL) + *cp = '\0'; + + /* If TYPE_TYPE is foo::bar, we only want bar. */ + colon = strrchr (type_name, ':'); + if (colon != NULL) + type_name = colon + 1; + + if (strcmp (type_name, name + 1) != 0) error (_("name of destructor must equal name of class")); - else - return 1; + + do_cleanups (cleanups); + return 1; } + return 0; } Index: testsuite/gdb.cp/cp-disasm.cc =================================================================== RCS file: testsuite/gdb.cp/cp-disasm.cc diff -N testsuite/gdb.cp/cp-disasm.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/cp-disasm.cc 14 Feb 2013 00:13:16 -0000 @@ -0,0 +1,44 @@ +/* This test file is part of GDB, the GNU debugger. + + Copyright 2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +class bar +{ + public: + int x; + bar () {} + ~bar () {} +}; + +namespace foo +{ + class bar + { + public: + int x; + bar () {} + ~bar () {} + }; +} + +bar x; +foo::bar y; + +int +main () +{ + return 0; +} Index: testsuite/gdb.cp/cp-disasm.exp =================================================================== RCS file: testsuite/gdb.cp/cp-disasm.exp diff -N testsuite/gdb.cp/cp-disasm.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.cp/cp-disasm.exp 14 Feb 2013 00:13:16 -0000 @@ -0,0 +1,52 @@ +# Copyright 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test disassembling ctors and dtors. + +standard_testfile .cc + +if { [skip_cplus_tests] } { continue } + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { + return -1 +} + +set name "disassemble ctor" +gdb_test_multiple "disassemble bar::bar,+1" $name { + -re "Dump of assembler code.*$gdb_prompt $" { + pass "$name" + } +} + +set name "disassemble dtor" +gdb_test_multiple "disassemble bar::~bar,+1" "$name" { + -re "Dump of assembler code.*$gdb_prompt $" { + pass "$name" + } +} + +set name "disassemble namespace ctor" +gdb_test_multiple "disassemble foo::bar::bar,+1" "$name" { + -re "Dump of assembler code.*$gdb_prompt $" { + pass "$name" + } +} + +set name "disassemble namespace dtor" +gdb_test_multiple "disassemble foo::bar::~bar,+1" "$name" { + -re "Dump of assembler code.*$gdb_prompt $" { + pass "$name" + } +}