【问题标题】:What does this std::ostream related stack trace mean?这个与 std::ostream 相关的堆栈跟踪是什么意思?
【发布时间】:2012-05-31 22:48:00
【问题描述】:

我正在尝试为集成/移动平台构建 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 没有任何问题。拆解第 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 输出运算符,我会理解事情会变得疯狂,但它只是文本。有人有什么建议吗?

【问题讨论】:

  • 除了 ildjarn 所说的之外,安装到您的流中的某些方面似乎没有实现正确的类型(__check_facet 中的dynamic_cast 失败)。您是否使用任何自定义方面?

标签: c++ stl stack-trace ostream


【解决方案1】:

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&lt; ctype&lt;char_type&gt; &gt;(getloc()).widen(c)

use_facet 本身将抛出 bad_cast 如果分面不存在于灌输的语言环境中(第 22.3.2/3 节),但您的堆栈跟踪并不表明是这种情况。 (话又说回来,我还没有深入研究 libstdc++ 的内部结构来验证它是否按照书本行事......)

我假设__check_facetuse_facet 之前被调用(或者use_facet 被内联并从堆栈跟踪中消失),具有相同的净效果;这意味着 OSG_INFO 被灌输了一些没有 std::ctype&lt;char&gt; 方面的语言环境——糟糕的时代!

或者,它可能已经充满了一些带有刻面呈现的语言环境,根本无法优雅地处理widen('\n')。但是没有办法确切地知道,而且我们无法告诉您其他任何事情,除非您不知道 OSG_INFO 是什么和/或它是如何实现的。

【讨论】:

  • 感谢您富有洞察力的回答。我需要仔细查看源代码......以及我的编译过程。我担心我可能会在途中意外链接到两个不同的 STL,这可能会解释语言环境不匹配。
猜你喜欢
  • 2015-05-14
  • 2020-06-26
  • 1970-01-01
  • 1970-01-01
  • 2011-01-06
  • 2011-09-13
  • 2019-06-30
  • 2011-11-09
相关资源
最近更新 更多