From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hmv2AKqx21/JUQAAWB0awg (envelope-from ) for ; Thu, 17 Dec 2020 14:29:46 -0500 Received: by simark.ca (Postfix, from userid 112) id E945B1F0AA; Thu, 17 Dec 2020 14:29:45 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 753701E590 for ; Thu, 17 Dec 2020 14:29:45 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A35FA3851C3D; Thu, 17 Dec 2020 19:29:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A35FA3851C3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608233384; bh=ScN9ygsvixSgrG3kLXb9HAXLuahROKS5UuTUvZKyR3c=; h=To:Subject:Date:References:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Uoy6+Cl9Fsy2mLfMIDrtTSZy2WCteI44cOTnZpzlYKgDUSvakvdxBedlm43thB7P5 w4eItR56y/rwteHdIVX1Y/kKNWOfD/RCuvoKqS6C8oZlevuBFM7xGD5fzv0jOf7hI9 9NzvIihG+/ip0FRt4dOosng+D8eamJ97cTw9KgQs= Received: from sonic305-20.consmr.mail.ir2.yahoo.com (sonic305-20.consmr.mail.ir2.yahoo.com [77.238.177.82]) by sourceware.org (Postfix) with ESMTPS id 344E33851C3D for ; Thu, 17 Dec 2020 19:29:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 344E33851C3D X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1608233380; bh=n9hR5CKLapH4+Js5rhB+MGMGUG1jAR38nRtwVAc5tdL=; h=From:To:Subject:Date:From:Subject; b=PhHn0tQlbRSD2G4XQGSEUYWS55KuWSayBrN6AjMd9Udy9LLVEbKjBKlMD+daVpQx2xv5kLt5xIXPg4so0Sy+Igu8m3NZtCZzJqHzKmCaowW5d+fd3E7fpggVTXsVWA9eoWvXZp4YkqJNyILKNBYyva+DEUDgAvBeukbtuLCRoXEtpPErNJjrRh6/Em2dsAJFbnAktvlD2yMWVhYvXQTfAwMCfr1xOOLJT5gAxtGFqfI76zcFfJJ0qYpyYVMTwJ/wUGcGAuDyYMc/pxgT6XIh8qr4lIXjaYm/V8xi2wbl+Eg7Xhc814cG1epiBMfDeUExwuixW3w0/sDBGAIX4WzYQA== X-YMail-OSG: eCJpQR0VM1knxQxrurmPBBTl88gZefmNOnI.5rtdz07hjKZo0ZC89ReBDo168TC skU6Mn0w8sLUfRCYDUOSDn94Pgc33y7mfUf.e___pq8nfsK3oQvm6.39ydDjFNdDB5AYmoBkCzSW IIAsziFupBvIn0ba6cuLXTsOo2ezgY8Ifvj1HJ1_FugF.yIZwbY2l75RXGGOTA94Jel5nvEsORBT dv3Qkyzg3HSV6j5t_ePPils6w3Ogk.9hrSeP.XXHy1jgjvdkUEyWmSpOKMKCkqQCMHHPgJX3q6al xuR4SbgCE38HjvcLt7v8dNfSjNHSo65taBw1cav1Y6Y.s_LDhlk81Cak.qzXLOxyglRCc16mLHBw frebBzvh9thJ_FrjUk62m4iEM41.4KXaAmg2Y9NrFzUUtAP23tamkYrWM4qqMGOLY_Q1UTVd1ZNH 6HAgpjXXer6cXI5Xj5fwGlgEbYBaSPifXVOrQ1PO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H2Tilzf9VGxTDzb0Tax3Gwdgc9Rvh WoBOT49MrcGpy9WWpYAVrqMBqRA2rQeQro.2iAlLWgEW_skonBq1o8bFn2HkJ3HO.VwEJI2LiVEz E1DfKsSFNoXokSmsr0XFKW0HIUMt5Nm73xpDfiFVtgzNImOHcInDjrGmB..2G4V5d0Pl8VodiO.W RS24zp5H0BKOzhbLF1unrp2CuctAsKyvxA1c9TZloG_9A74CWHa0HTKuFH0Romejncfpoa6F8xBV 1LKNwfNY.u5JJJzeGNUQstbowvza4vIp_yknMPqnndpc1XBuyuZv3qFL3wNE1QncL.I.FH84jMJS 3jZBA5jcrdS8iSnuRTrVKiYGZ4VcA.Vns9Dzig5eC_9DR3RzGVKtvP_VCdpAn2CJ2Mh2RTI3stZ3 EuEaqnltTHg1GYeeAackE4P2RljGWRpm8VNjzkeRap11wRkDcSvlwnM4_IS3F_sMwL477sQLX1.Q oIXDxCyRUIG7Py96Ob3DFqAG3ayMuZ7BoP70iQ2LO.8XLwXa7NU1WQ.ibFQrMUHShwZqYXfdGUQ8 XW5_R845egwwYw4E0UTuNfx6ESx7rYSIIZeBo38Y6UcyWon4JKy3_UMePQa1e7953MZShD57HAVV 4aLjIlF1DUfKlYMc9HHl3zXxNemBcHVAnb1oHmP4qUMM2Wcy1ubnkIekg0hs6Md5.lW3yl5k_vqQ lm27UPEhg52rKD57zELT2mbkhZIVSo4c5P5XmJHFxpwFg2Ubpjk6c8WiDly6ANDUv.FqmhDaxKBS NblGif6qPFMlf386ukfyAZc.3a7jAHDXfuKWoClgVVPk62iwQMACmrqYExEfYhuJbF1BuMAxhU_B GqLGIwIgNvzmw4R_jACEXDDeeilm2WDLdMPw- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ir2.yahoo.com with HTTP; Thu, 17 Dec 2020 19:29:40 +0000 Received: by smtp417.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 14b772e6700698dc2c61194021f653f0; Thu, 17 Dec 2020 19:29:37 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH v2] Don't compare types of enum fields Date: Thu, 17 Dec 2020 20:29:12 +0100 Message-Id: <20201217192912.1981-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 201217-2, 12/17/2020), Outbound message X-Antivirus-Status: Clean References: <20201217192912.1981-1-ssbssa.ref@yahoo.de> 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: , From: Hannes Domani via Gdb-patches Reply-To: Hannes Domani Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Comparing types of enum fields results in a crash, because they don't have a type. It can be reproduced by comparing the types of 2 instances of the same enum type in different objects: enum.h: enum e { zero, one, }; enum-1.c: int func(); enum e e1; int main() { return e1 + func(); } enum-2.c: enum e e2; int func() { return e2; } $ gcc -g -oenum enum-1.c enum-2.c $ gdb -q enum.exe Reading symbols from enum.exe... (gdb) py print(gdb.parse_and_eval("e1").type==gdb.parse_and_eval("e2").type) Thread 1 received signal SIGSEGV, Segmentation fault. [Switching to Thread 6184.0x1cc4] check_typedef (type=0x0) at C:/src/repos/binutils-gdb.git/gdb/gdbtypes.c:2745 2745 while (type->code () == TYPE_CODE_TYPEDEF) gdb/ChangeLog: 2020-12-17 Hannes Domani PR exp/27070 * gdbtypes.c (check_types_equal): Don't compare types of enum fields. gdb/testsuite/ChangeLog: 2020-12-17 Hannes Domani PR exp/27070 * gdb.base/pr27070-a.c: New test. * gdb.base/pr27070-b.c: New test. * gdb.base/pr27070.exp: New file. * gdb.base/pr27070.h: New test. --- v2: - Add detailed problem description in commit message and test case. --- gdb/gdbtypes.c | 4 +++- gdb/testsuite/gdb.base/pr27070-a.c | 27 +++++++++++++++++++++++++++ gdb/testsuite/gdb.base/pr27070-b.c | 25 +++++++++++++++++++++++++ gdb/testsuite/gdb.base/pr27070.exp | 29 +++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/pr27070.h | 22 ++++++++++++++++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/pr27070-a.c create mode 100644 gdb/testsuite/gdb.base/pr27070-b.c create mode 100644 gdb/testsuite/gdb.base/pr27070.exp create mode 100644 gdb/testsuite/gdb.base/pr27070.h diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index a40ae5f30e..2207613eef 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -4036,7 +4036,9 @@ check_types_equal (struct type *type1, struct type *type2, case FIELD_LOC_KIND_ENUMVAL: if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2)) return false; - break; + /* Don't compare types of enum fields, because they don't + have a type. */ + continue; case FIELD_LOC_KIND_PHYSADDR: if (FIELD_STATIC_PHYSADDR (*field1) != FIELD_STATIC_PHYSADDR (*field2)) diff --git a/gdb/testsuite/gdb.base/pr27070-a.c b/gdb/testsuite/gdb.base/pr27070-a.c new file mode 100644 index 0000000000..f3850803ea --- /dev/null +++ b/gdb/testsuite/gdb.base/pr27070-a.c @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2020 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 . */ + +#include "pr27070.h" + +int func(); + +enum e e1; + +int main() +{ + return e1 + func(); +} diff --git a/gdb/testsuite/gdb.base/pr27070-b.c b/gdb/testsuite/gdb.base/pr27070-b.c new file mode 100644 index 0000000000..39962c671a --- /dev/null +++ b/gdb/testsuite/gdb.base/pr27070-b.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2020 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 . */ + +#include "pr27070.h" + +enum e e2; + +int func() +{ + return e2; +} diff --git a/gdb/testsuite/gdb.base/pr27070.exp b/gdb/testsuite/gdb.base/pr27070.exp new file mode 100644 index 0000000000..3f565da661 --- /dev/null +++ b/gdb/testsuite/gdb.base/pr27070.exp @@ -0,0 +1,29 @@ +# Copyright 2020 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 . + +set testname pr27070 +set sources "pr27070-a.c pr27070-b.c" + +if {[build_executable ${testname}.exp $testname $sources {debug}] == -1} { + return -1 +} + +# Start with a fresh gdb. + +clean_restart ${testname} + +if { [skip_python_tests] } { continue } + +gdb_test "py print(gdb.parse_and_eval('e1').type == gdb.parse_and_eval('e2').type)" "True" diff --git a/gdb/testsuite/gdb.base/pr27070.h b/gdb/testsuite/gdb.base/pr27070.h new file mode 100644 index 0000000000..f149fc1a7e --- /dev/null +++ b/gdb/testsuite/gdb.base/pr27070.h @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2020 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 . */ + +enum e +{ + zero, + one, +}; -- 2.29.2