尝试从字符串初始化字符串流时出现段错误

时间:2019-05-27 10:25:33

标签: c++ esp8266 arduino-esp8266

在用于Esp8266的Arduino上发生以下问题。 这是重现该问题的简单草图。该程序将一直运行,直到我们通过GDBStub设置debug_stop = true为止,然后在尝试初始化字符串流时它将发出喙。

#include <Arduino.h>
#include <GDBStub.h>

#include <string>
#include <sstream>

void setup() {
    Serial.begin(115200);

    gdbstub_init();
}

bool debug_stop = true;

void loop() {

    Serial.println("Running");
    delay(100);

    // set debug_stop = false from GDB in order to continue
    if (debug_stop == true) return; 

     std::stringstream ss("hello");
}

在附加GDBStub之后,尝试执行std::stringstream ss("hello"); 会导致分段错误:

Program received signal SIGSEGV, Segmentation fault.
0x40235268 in std::type_info::operator== (__arg=..., 
    this=0x402695c4 <typeinfo for std::ctype<char>>)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/typeinfo:123
123 ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/typeinfo: No such file or directory.

这是生成的回溯跟踪(至少一些行,它延伸超过600行,甚至更多)。

(gdb) bt
#0  0x4023659c in std::type_info::operator== (__arg=..., 
    this=0x40269c40 <typeinfo for std::ctype<char>>)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/typeinfo:123
#1  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__contained_public, 
    dst_type=0x40269c40 <typeinfo for std::ctype<char>>, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x40269144 <typeinfo for std::locale::facet>, 
    src_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#2  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__unknown, dst_type=0x3fff0be0 <std::cout+4>, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x3fff0bdc <std::cout>, 
    src_ptr=0x3fff0868 <__gnu_internal::buf_cout_sync>, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#3  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=1073645236, 
    dst_type=0x3ffffa20, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x3ffffa30, src_ptr=0x190001, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#4  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=1073666608, 
    dst_type=0x3ffffaa0, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=
    0x40202215 <init_done()+29>, src_ptr=0xffffe6fc, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#5  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=1946157057, 
    dst_type=0x66336a4a, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x7a686a76, src_ptr=0xdfbd4764, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#6  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=944788293, 
    dst_type=0x5f363632, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x324f43, src_ptr=0x3fff2a30, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#7  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=511, 
    dst_type=0xffffff04, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffff0001, src_ptr=0x3fff0358 <g_cont+4008>, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#8  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4294967295, 
    dst_type=0xffffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffffffff, src_ptr=0xffffffff, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#9  0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4294967295, 
--Type <RET> for more, q to quit, c to continue without paging--
    dst_type=0xffffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffffffff, src_ptr=0xffffffff, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#10 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4294967295, 
    dst_type=0xffffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffffffff, src_ptr=0xffffffff, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#11 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4294967295, 
    dst_type=0xffffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffffffff, src_ptr=0xffffffff, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#12 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4294967295, 
    dst_type=0xffffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffffffff, src_ptr=0x36b8f604, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#13 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4294967295, 
    dst_type=0xffffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xffffffff, src_ptr=0xffffffff, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#14 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=32, 
    dst_type=0x20, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x90, 
    src_ptr=0x4010f000, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#15 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=65534, 
    dst_type=0x0, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x0, 
    src_ptr=0x71490338, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#16 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=1073742067, 
    dst_type=0x4000e328, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x0, 
    src_ptr=0x506340, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#17 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=1953546291, 
    dst_type=0xf0b3f641, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x21002030, src_ptr=0x0, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#18 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__unknown, dst_type=0x0, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x0, src_ptr=0x0, 
    result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
--Type <RET> for more, q to quit, c to continue without paging--
#19 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__unknown, dst_type=0x0, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x0, src_ptr=0x0, 
    result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#20 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__unknown, dst_type=0x0, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x0, src_ptr=0x0, 
    result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#21 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__unknown, dst_type=0x0, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x0, src_ptr=0x0, 
    result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#22 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=1073743256, 
    dst_type=0x3fffc000, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x4000dc44, src_ptr=0x24, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#23 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=4194304, 
    dst_type=0xffffff, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x7ff00000, src_ptr=0xcaa1ffce, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#24 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=20537830, 
    dst_type=0x41091129, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xa1799169, src_ptr=0xd13022f0, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#25 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=3356416000, 
    dst_type=0x10ddc031, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x5610ffd0, src_ptr=0xd02022f0, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#26 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, 
    access_path=__cxxabiv1::__class_type_info::__unknown, dst_type=0x61228159, 
    obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, src_type=0x30122c13, 
    src_ptr=0xc021e800, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#27 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=723661313, 
    dst_type=0x452a2222, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x11080003, src_ptr=0x81d971c9, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
--Type <RET> for more, q to quit, c to continue without paging--
#28 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=13, 
    dst_type=0x3bd05ad, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x6c604c0c, src_ptr=0x7440fb56, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#29 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=90780555, 
    dst_type=0xc5521579, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0x7642708, src_ptr=0xc052a014, result=...)
    at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/vmi_class_type_info.cc:91
#30 0x402366a5 in __cxxabiv1::__vmi_class_type_info::__do_dyncast (
    this=0x40269c40 <typeinfo for std::ctype<char>>, src2dst=0, access_path=809509632, 
    dst_type=0x33b014b0, obj_ptr=0x3fff1778 <(anonymous namespace)::ctype_c>, 
    src_type=0xac0368c0, src_ptr=0x20688055, result=...)

我不知道如何进一步调试此问题。有任何建议或想法吗?

该代码使用以下标志进行编译:

 -DICACHE_FLASH -U__STRICT_ANSI__ " -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections -fno-exceptions  -DNONOSDK221=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0   -DARDUINO=10605 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD=\"ESP8266_NODEMCU\"  -DFLASHMODE_QIO  -DESP8266 -O0 -ggdb -std=c++11 

0 个答案:

没有答案