[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-ports
Subject:    Re: Need some help with c++/qt5 code
From:       Dimitry Andric <dim () FreeBSD ! org>
Date:       2016-04-14 22:32:42
Message-ID: CC7B253B-DE3B-4049-96D8-A06DB52A0346 () FreeBSD ! org
[Download RAW message or body]

On 14 Apr 2016, at 13:58, Shane Ambler <FreeBSD@ShaneWare.Biz> wrote:
> 
> 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<QString, TPanelFactory *> m_table;
> 
> public:
> TPanelFactory(QString panelType);
> ~TPanelFactory();
> 
> QString getPanelType() const { return m_panelType; }
> 
> virtual void initialize(TPanel *panel) = 0;
> virtual TPanel *createPanel(QWidget *parent);
> static TPanel *createPanel(QWidget *parent, QString panelType);
> };
> 
> m_table is then in the source file as
> 
> QMap<QString, TPanelFactory *> TPanelFactory::m_table;
> 
> The segfault happens in the constructor -
> 
> TPanelFactory::TPanelFactory(QString panelType)
> > m_panelType(panelType)
> {
> assert(m_table.count(panelType) == 0);
> m_table[m_panelType] = this;
> }
> 
> 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.
> 
> How can I get this working?
> 
> 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 -
> 
> % 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 = 101033, 0x00000000004f2026 \
> opentoonz`TPanelFactory::TPanelFactory(QString) + 70, stop reason = 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 = 101033, 0x00000000004f2026 \
> opentoonz`TPanelFactory::TPanelFactory(QString) + 70, stop reason = 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


["signature.asc" (signature.asc)]

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.30

iEYEARECAAYFAlcQGooACgkQsF6jCi4glqP1DwCg2g/z8793VNL3MQ3eBHjOrgiR
b9gAn1OArTqnSFdDDIIIu3V6pG4jFSgv
=gqqu
-----END PGP SIGNATURE-----


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic