From owner-freebsd-ports@freebsd.org Thu Apr 14 22:32:45 2016 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4DF8DADAE1A for ; Thu, 14 Apr 2016 22:32:45 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:7b8:3a7:1:2d0:b7ff:fea0:8c26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F022A1446 for ; Thu, 14 Apr 2016 22:32:44 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:7b8:3a7::7d3a:d9a8:389c:8c71] (unknown [IPv6:2001:7b8:3a7:0:7d3a:d9a8:389c:8c71]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 641E7291BC; Fri, 15 Apr 2016 00:32:43 +0200 (CEST) Subject: Re: Need some help with c++/qt5 code Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: multipart/signed; boundary="Apple-Mail=_D6BBE725-07EA-42AE-9F7C-E39DB9BC4EE2"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Pgp-Agent: GPGMail 2.6b2 (ebbf3ef) From: Dimitry Andric In-Reply-To: <570F85E3.6060000@ShaneWare.Biz> Date: Fri, 15 Apr 2016 00:32:42 +0200 Cc: FreeBSD-ports Message-Id: References: <570F85E3.6060000@ShaneWare.Biz> To: Shane Ambler X-Mailer: Apple Mail (2.3124) X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2016 22:32:45 -0000 --Apple-Mail=_D6BBE725-07EA-42AE-9F7C-E39DB9BC4EE2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 14 Apr 2016, at 13:58, Shane Ambler wrote: >=20 > Hi there, while I am comfortable with c and python, I only know a = little > c++ and could use some help. ... > class TPanelFactory > { > QString m_panelType; > static QMap m_table; >=20 > public: > TPanelFactory(QString panelType); > ~TPanelFactory(); >=20 > QString getPanelType() const { return m_panelType; } >=20 > virtual void initialize(TPanel *panel) =3D 0; > virtual TPanel *createPanel(QWidget *parent); > static TPanel *createPanel(QWidget *parent, QString panelType); > }; >=20 > m_table is then in the source file as >=20 > QMap TPanelFactory::m_table; >=20 > The segfault happens in the constructor - >=20 > TPanelFactory::TPanelFactory(QString panelType) > : m_panelType(panelType) > { > assert(m_table.count(panelType) =3D=3D 0); > m_table[m_panelType] =3D this; > } >=20 > the last line causes the segfault, if I comment it out then main() is > entered, but I expect removing that line will bite back soon enough. >=20 > How can I get this working? >=20 > Why would this fail on FreeBSD but not OSX or windows? Most likely the program depends on the initialization order of global constructors. This is bad practice, and should be avoided. > The backtrace I get from lldb and gdb - >=20 > % lldb opentoonz > Current executable set to 'opentoonz' (x86_64). > (lldb) run > Process 80086 launching > Process 80086 stopped > (lldb) Process 80086 launched: = '/home/shane/Projects/opentoonz/test_install/bin/opentoonz' (x86_64) > Process 80086 stopped > * (lldb) thread #1: tid =3D 101033, 0x00000000004f2026 = opentoonz`TPanelFactory::TPanelFactory(QString) + 70, stop reason =3D = invalid address (fault address: 0x0) > frame #0: 0x00000000004f2026 = opentoonz`TPanelFactory::TPanelFactory(QString) + 70 > opentoonz`TPanelFactory::TPanelFactory(QString) + 70: > -> 0x4f2026: cmpl $0x2, (%rax) > 0x4f2029: jb 0x4f203d ; = TPanelFactory::TPanelFactory(QString) + 93 > 0x4f202b: movq 0x73eb5e(%rip), %r15 ; opentoonz..got + 6728 > 0x4f2032: movq %r15, %rdi > (lldb) bt > * thread #1: tid =3D 101033, 0x00000000004f2026 = opentoonz`TPanelFactory::TPanelFactory(QString) + 70, stop reason =3D = invalid address (fault address: 0x0) > * frame #0: 0x00000000004f2026 = opentoonz`TPanelFactory::TPanelFactory(QString) + 70 > frame #1: 0x0000000000570cfd = opentoonz`XsheetViewerFactory::XsheetViewerFactory() + 45 > frame #2: 0x000000000056fd47 opentoonz`_GLOBAL__I_a + 1687 > frame #3: 0x0000000000809d22 opentoonz`__do_global_ctors_aux + 34 > frame #4: 0x00000000004854ae opentoonz`_init + 14 > frame #5: 0x0000000800c02c9f > frame #6: 0x0000000800c0228e So what's the value of m_table at this point? It looks a lot like it is still uninitialized. -Dimitry --Apple-Mail=_D6BBE725-07EA-42AE-9F7C-E39DB9BC4EE2 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.30 iEYEARECAAYFAlcQGooACgkQsF6jCi4glqP1DwCg2g/z8793VNL3MQ3eBHjOrgiR b9gAn1OArTqnSFdDDIIIu3V6pG4jFSgv =gqqu -----END PGP SIGNATURE----- --Apple-Mail=_D6BBE725-07EA-42AE-9F7C-E39DB9BC4EE2--