Skip to content

Seg Fault when trying to initialize stringstream #6151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
blasco opened this issue May 27, 2019 · 7 comments
Closed
6 tasks done

Seg Fault when trying to initialize stringstream #6151

blasco opened this issue May 27, 2019 · 7 comments

Comments

@blasco
Copy link

blasco commented May 27, 2019

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: Esp8266
  • Core Version: latest
  • Development Env: Make
  • Operating System: Arch

Settings in IDE

  • Module: Nodemcu
  • Flash Mode: qio
  • Flash Size: 4MB
  • lwip Variant: v1.4
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

Trying to instantiate a stringstream yields a segmentation fault. I've been trying to debug it with the GDBStub, but I'm stuck.

MCVE Sketch

#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");
}

Debug Messages

The seg fault:

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.

The back trace:

(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=...)
@earlephilhower
Copy link
Collaborator

Looking at the trace you may be out of luck. Seems like it's trying to do RTTI checks and dynamic casts, which are not supported on the 8266 (RTTI is disabled). @devyte, can you take a look too?

@blasco
Copy link
Author

blasco commented May 28, 2019

Why is RTTI disabled? I tried to compile with RTTI enabled but that didn't fix the problem.

@earlephilhower
Copy link
Collaborator

Memory issues and API compatibility w/the binary SDK blobs. RTTI isn't enabled for the precompiled libs, either, so your change didn't have any effect.

@devyte
Copy link
Collaborator

devyte commented May 28, 2019

That is what the trace hints at. I've been trying to find some source that confirms/denies the dependence of std::stringstream on rtti, but no luck.
If it really uses dynamic_cast, we'll have to disable it from the stdc++lib, or roll our own implementation.

@blasco
Copy link
Author

blasco commented May 28, 2019

I guess I can't use stringstreams then. Anyhow, I wanted to compile the SDK my self, to test if the gdb TUI would work, for some reason is disabled in the provided build that one gest with get.py.

I tried compiling https://github.com/pfalcon/esp-open-sdk
But the xtensa gdb tool that I built fails to attach to the board. It says

Remote 'g' packet reply is too long: 680f0040xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1a00000000000000xxxxxxxxxxxxxxxxfada8cc2xxxxxxxx30000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx580f004090ffff3f000000002000000000000000840cff3fe057244001000000800cff3f000000009492fe3f18e7fe3fb0daff3f00000000b0dcff3f50e7fe3f

This also happens with the current master branch of Arduino ESP866. Only works for me when I use the 2.5.2 branch.

I wonder how the SDK tools where built for that branch? I would like to rebuild them and test this issue too, what are your thoughts?

@earlephilhower
Copy link
Collaborator

For GDB you need to use the toolchain we supply (basically plain GNU sources). We don't use pfalcon's repo any more and are building from mostly unchanged GNU sources for everything. See esp-quick-toolchain.

@earlephilhower
Copy link
Collaborator

Actually, this was due to exception handlers accessing progmem, something that started failing when we moved SDKs back due to bugs in pre 3.0.0.

I just tried the example with PR #6273 , and it runs fine. Try that PR, or wait for it to merge. You need to run tools/get.py to download the new toolchain either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants