这个std :: ostream相关的堆栈跟踪意味着什么?

时间:2012-05-31 22:48:00

标签: c++ stl stack-trace ostream

我正在尝试为集成/移动平台构建C ++库。该平台有一组不错的库,包括stdc ++。我试图建立的库使用ofstream,每当它试图使用依赖于ofstream的类时,我都会得到'bad_cast'异常。

0  0xb082d9b1 in SignalKill ()
   from /home/preet/bbndk-2.0.1/target/qnx6/x86/lib/libc.so.3

1  0xb081aa7e in raise ()
   from /home/preet/bbndk-2.0.1/target/qnx6/x86/lib/libc.so.3

2  0xb0818cb8 in abort ()
   from /home/preet/bbndk-2.0.1/target/qnx6/x86/lib/libc.so.3

3  0xb87c48bf in __gnu_cxx::__verbose_terminate_handler ()
    at ../../../../../libstdc++-v3/libsupc++/vterminate.cc:93

4  0xb87c23d6 in __cxxabiv1::__terminate (
    handler=0xb87c47c0 <__gnu_cxx::__verbose_terminate_handler()>)
    at ../../../../../libstdc++-v3/libsupc++/eh_terminate.cc:38

5  0xb87c2421 in std::terminate ()
    at ../../../../../libstdc++-v3/libsupc++/eh_terminate.cc:48

6  0xb87c2563 in __cxxabiv1::__cxa_throw (obj=0x859e710, tinfo=0xb87f4c24, 
    dest=0xb87c0670 <std::bad_cast::~bad_cast()>)
    at ../../../../../libstdc++-v3/libsupc++/eh_throw.cc:83

7  0xb875e88c in std::__throw_bad_cast ()
    at ../../../../../libstdc++-v3/src/functexcept.cc:52

8  0xb8798c0d in __check_facet<std::ctype<char> > (__f=<optimized out>)
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/bits/basic_ios.h:49

9  widen (__c=<optimized out>, this=<optimized out>)
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/bits/basic_ios.h:440

10 std::endl<char, std::char_traits<char> > (__os=...)
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/ostream:539

11 0xb8793c2d in std::ostream::operator<< (this=0x84db220, 
    __pf=0x804f64c <_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@plt>)
    at /home/builder/hudson/650-gcc-4.4/svn/linux-x86-o-ntox86/i486-pc-nto-qnx6.5.0/pic/libstdc++-v3/include/ostream:113

12 0x0805240d in QDecViewport::QDecViewport (this=0x86da6c0, parent=0x0)
    at ../qml_osg_viewport/qdecviewport.cpp:12

13 0x08051cca in QDeclarativePrivate::QDeclarativeElement<QDecViewport>::QDeclarativeElement (this=0x86da6c0)
    at /usr/local/Trolltech/QtLighthouse-4.8.2-i386/include/QtDeclarative/qdeclarativeprivate.h:83

14 0x08051d3c in QDeclarativePrivate::createInto<QDecViewport> (
    memory=0x86da6c0)
    at /usr/local/Trolltech/QtLighthouse-4.8.2-i386/include/QtDeclarative/qdeclarativeprivate.h:91

15 0xb8ad5ec5 in ?? ()

16 0x086da6c0 in ?? ()

17 0x00000000 in ?? ()

框架7-11是相关的,我需要帮助理解。代码帧12的行仅仅是:

OSG_INFO << "Hello OSG" << std::endl;

OSG_INFO是用于记录的流重定向器。我能够以同样的方式使用std :: cout而没有任何问题。 Unmangling frame 11给了我:

__pf=0x804f64c <std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)@plt>)

哪个仍然非常神秘......而且我理解事情会变得疯狂,如果我试图将一些非常奇怪的东西传递给ofstream输出操作符,但它只是文本。有没有人有任何建议?

1 个答案:

答案 0 :(得分:3)

std::endl具有以下行为,引用C ++11§27.7.3.8/ 1:

  

拨打os.put(os.widen('\n')),然后拨打os.flush()

第9帧表示endlwiden的调用失败,即OSG_INFO.widen('\n')失败。反过来,widen具有以下行为(§27.5.5.3/ 12):

  

返回: use_facet< ctype<char_type> >(getloc()).widen(c)

如果facet不在嵌入式语言环境中(第22.3.2 / 3节),

use_facet本身将抛出bad_cast,但是您的堆栈跟踪并不表示这种情况。 (然后,我还没有通过libstdc ++内部挖掘来验证它正在通过本书做什么......)

我假设在__check_facet之前调用use_facet(或use_facet内联并从堆栈跟踪中消失),具有相同的净效果;这意味着OSG_INFO已经充满了一些没有std::ctype<char>方面存在的区域设置 - 糟糕的时代!

或者,它可能已经充满了一些带有facet的语言环境,它只是不能优雅地处理widen('\n')。但是,如果不知道OSG_INFO是什么和/或它是如何实现的,我们无法确切地知道,也没有其他任何我们可以告诉你的。