From patchwork Fri May 15 15:04:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 6740 Received: (qmail 32000 invoked by alias); 15 May 2015 15:04:52 -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 31986 invoked by uid 89); 15 May 2015 15:04:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_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; Fri, 15 May 2015 15:04:49 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 9EC8EBACAA; Fri, 15 May 2015 15:04:48 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4FF4knq026009; Fri, 15 May 2015 11:04:47 -0400 Message-ID: <55560B0D.8030307@redhat.com> Date: Fri, 15 May 2015 16:04:45 +0100 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: asmwarrior , GDB Patches Subject: Re: [all pushed] Re: [PATCH 00/36] Support building GDB as a C++ program References: <1423524046-20605-1-git-send-email-palves@redhat.com> <54F0B52F.1050909@redhat.com> <54FB20E2.2040403@redhat.com> <54FB3C58.6050702@redhat.com> <550660C5.2060009@gmail.com> <5506661C.1040103@gmail.com> <5506C18C.9080408@redhat.com> <5555AC9F.7020206@gmail.com> In-Reply-To: <5555AC9F.7020206@gmail.com> On 05/15/2015 09:21 AM, asmwarrior wrote: > Hi, Pedro, I just found another build issue when building gdb under g++. Thanks! > > Building mingw GDB with --enable-build-with-cxx shows: > > ../../binutils-gdb/gdb/python/py-unwind.c:500:45: error: cannot convert 'cached_frame_info::reg_info*' to 'pyuw_prev_register(frame_info*, void**, int)::reg_info*' in initialization > struct reg_info *reg_info = cached_frame->reg; > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:501:60: error: invalid use of incomplete type 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' > struct reg_info *reg_info_end = reg_info + cached_frame->reg_count; > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:500:10: error: forward declaration of 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' > struct reg_info *reg_info = cached_frame->reg; > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:505:37: error: cannot increment a pointer to incomplete type 'pyuw_prev_register(frame_info*, void**, int)::reg_info' > for (; reg_info < reg_info_end; ++reg_info) > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:507:29: error: invalid use of incomplete type 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' > if (regnum == reg_info->number) > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:500:10: error: forward declaration of 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' > struct reg_info *reg_info = cached_frame->reg; > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:508:68: error: invalid use of incomplete type 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' > return frame_unwind_got_bytes (this_frame, regnum, reg_info->data); > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:500:10: error: forward declaration of 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' > struct reg_info *reg_info = cached_frame->reg; > ^ > ../../binutils-gdb/gdb/python/py-unwind.c: In function 'int pyuw_sniffer(const frame_unwind*, frame_info*, void**)': > ../../binutils-gdb/gdb/python/py-unwind.c:574:70: warning: invalid conversion from 'void*' to 'cached_frame_info*' [-fpermissive] > reg_count * sizeof (cached_frame->reg[0])); > ^ > ../../binutils-gdb/gdb/python/py-unwind.c: In function 'void pyuw_on_new_gdbarch(gdbarch*)': > ../../binutils-gdb/gdb/python/py-unwind.c:636:47: warning: invalid conversion from 'void*' to 'pyuw_gdbarch_data_type*' [-fpermissive] > gdbarch_data (newarch, pyuw_gdbarch_data); > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:647:29: warning: invalid conversion from 'void*' to 'const frame_data*' [-fpermissive] > unwinder->unwind_data = (void *) newarch; > ^ > ../../binutils-gdb/gdb/python/py-unwind.c: At global scope: > ../../binutils-gdb/gdb/python/py-unwind.c:699:21: error: redefinition of 'PyTypeObject pending_frame_object_type' > static PyTypeObject pending_frame_object_type = > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:96:21: error: 'PyTypeObject pending_frame_object_type' previously declared here > static PyTypeObject pending_frame_object_type > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:749:21: error: redefinition of 'PyTypeObject unwind_info_object_type' > static PyTypeObject unwind_info_object_type = > ^ > ../../binutils-gdb/gdb/python/py-unwind.c:99:21: error: 'PyTypeObject unwind_info_object_type' previously declared here > static PyTypeObject unwind_info_object_type > ^ > > > The first kind of error is caused by embedded struct definition, so I moved it out of the parent struct. That's the right fix. > The second kind of error is caused by using static keyword on a CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF decoreated variable, I see that all other files use extern, so I changed to extern. That too, is the right fix, though the problem isn't caused by CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF. The problem is that with C we can "forward declare" variables like this: static int foo; void use_foo (void) { if (foo == 2) bar (); } static int foo = 3; But that's not valid C++ (and a link error with C and -fno-common). So we need to fix the definition too, though, otherwise we have a static / extern mismatch. G++ warns about it, but until we get rid of -fpermissive and enable -Werror in C++ mode, it's easy to miss. Building in C mode does catch that with an error though. Here's what I pushed. From 13fa0398d7dd8d2b468acf0aba5610ce014709a6 Mon Sep 17 00:00:00 2001 From: Yuanhui Zhang Date: Fri, 15 May 2015 16:00:40 +0100 Subject: [PATCH] Fix a couple C++ build issues Building mingw GDB with --enable-build-with-cxx shows: ../../binutils-gdb/gdb/python/py-unwind.c:500:45: error: cannot convert 'cached_frame_info::reg_info*' to 'pyuw_prev_register(frame_info*, void**, int)::reg_info*' in initialization struct reg_info *reg_info = cached_frame->reg; ^ ../../binutils-gdb/gdb/python/py-unwind.c:501:60: error: invalid use of incomplete type 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' struct reg_info *reg_info_end = reg_info + cached_frame->reg_count; ^ ../../binutils-gdb/gdb/python/py-unwind.c:500:10: error: forward declaration of 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' struct reg_info *reg_info = cached_frame->reg; ^ ../../binutils-gdb/gdb/python/py-unwind.c:505:37: error: cannot increment a pointer to incomplete type 'pyuw_prev_register(frame_info*, void**, int)::reg_info' for (; reg_info < reg_info_end; ++reg_info) ^ ../../binutils-gdb/gdb/python/py-unwind.c:507:29: error: invalid use of incomplete type 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' if (regnum == reg_info->number) ^ ../../binutils-gdb/gdb/python/py-unwind.c:500:10: error: forward declaration of 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' struct reg_info *reg_info = cached_frame->reg; ^ ../../binutils-gdb/gdb/python/py-unwind.c:508:68: error: invalid use of incomplete type 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' return frame_unwind_got_bytes (this_frame, regnum, reg_info->data); ^ ../../binutils-gdb/gdb/python/py-unwind.c:500:10: error: forward declaration of 'struct pyuw_prev_register(frame_info*, void**, int)::reg_info' struct reg_info *reg_info = cached_frame->reg; ^ ../../binutils-gdb/gdb/python/py-unwind.c: In function 'int pyuw_sniffer(const frame_unwind*, frame_info*, void**)': ../../binutils-gdb/gdb/python/py-unwind.c:574:70: warning: invalid conversion from 'void*' to 'cached_frame_info*' [-fpermissive] reg_count * sizeof (cached_frame->reg[0])); ^ ../../binutils-gdb/gdb/python/py-unwind.c: In function 'void pyuw_on_new_gdbarch(gdbarch*)': ../../binutils-gdb/gdb/python/py-unwind.c:636:47: warning: invalid conversion from 'void*' to 'pyuw_gdbarch_data_type*' [-fpermissive] gdbarch_data (newarch, pyuw_gdbarch_data); ^ ../../binutils-gdb/gdb/python/py-unwind.c:647:29: warning: invalid conversion from 'void*' to 'const frame_data*' [-fpermissive] unwinder->unwind_data = (void *) newarch; ^ ../../binutils-gdb/gdb/python/py-unwind.c: At global scope: ../../binutils-gdb/gdb/python/py-unwind.c:699:21: error: redefinition of 'PyTypeObject pending_frame_object_type' static PyTypeObject pending_frame_object_type = ^ ../../binutils-gdb/gdb/python/py-unwind.c:96:21: error: 'PyTypeObject pending_frame_object_type' previously declared here static PyTypeObject pending_frame_object_type ^ ../../binutils-gdb/gdb/python/py-unwind.c:749:21: error: redefinition of 'PyTypeObject unwind_info_object_type' static PyTypeObject unwind_info_object_type = ^ ../../binutils-gdb/gdb/python/py-unwind.c:99:21: error: 'PyTypeObject unwind_info_object_type' previously declared here static PyTypeObject unwind_info_object_type ^ The first kind of error is caused by the embedded struct definition, so move it out of the parent struct. The second kind of error is caused by forward declaring a static global variable, which works in C, but not in C++ (or C with -fno-common). Make it using extern instead, like done in other similar cases. gdb/ChangeLog: 2015-05-15 Yuanhui Zhang * python/py-unwind.c (struct reg_info): Move out of ... (struct cached_frame_info): ... this scope. (pending_frame_object_type, unwind_info_object_type): Make extern. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-unwind.c | 26 ++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1492981..1fdc4f4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2015-05-15 Yuanhui Zhang + + * python/py-unwind.c (struct reg_info): Move out of ... + (struct cached_frame_info): ... this scope. + (pending_frame_object_type, unwind_info_object_type): Make extern. + 2015-05-15 Joel Brobecker * ada-lang.c (ada_value_primitive_packed_val): Make sure diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index bcfea4b..b6e8a75 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -72,6 +72,15 @@ typedef struct /* The data we keep for a frame we can unwind: frame ID and an array of (register_number, register_value) pairs. */ +struct reg_info +{ + /* Register number. */ + int number; + + /* Register data bytes pointer. */ + gdb_byte data[MAX_REGISTER_SIZE]; +}; + typedef struct { /* Frame ID. */ @@ -83,20 +92,13 @@ typedef struct /* Length of the `reg' array below. */ int reg_count; - struct reg_info - { - /* Register number. */ - int number; - - /* Register data bytes pointer. */ - gdb_byte data[MAX_REGISTER_SIZE]; - } reg[]; + struct reg_info reg[]; } cached_frame_info; -static PyTypeObject pending_frame_object_type +extern PyTypeObject pending_frame_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pending_frame_object"); -static PyTypeObject unwind_info_object_type +extern PyTypeObject unwind_info_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object"); static unsigned int pyuw_debug = 0; @@ -696,7 +698,7 @@ static PyMethodDef pending_frame_object_methods[] = {NULL} /* Sentinel */ }; -static PyTypeObject pending_frame_object_type = +PyTypeObject pending_frame_object_type = { PyVarObject_HEAD_INIT (NULL, 0) "gdb.PendingFrame", /* tp_name */ @@ -746,7 +748,7 @@ static PyMethodDef unwind_info_object_methods[] = { NULL } /* Sentinel */ }; -static PyTypeObject unwind_info_object_type = +PyTypeObject unwind_info_object_type = { PyVarObject_HEAD_INIT (NULL, 0) "gdb.UnwindInfo", /* tp_name */