Skip to content
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

Crashes when config files are present #706

Closed
yurivict opened this issue Feb 9, 2019 · 18 comments
Closed

Crashes when config files are present #706

yurivict opened this issue Feb 9, 2019 · 18 comments

Comments

@yurivict
Copy link

yurivict commented Feb 9, 2019

It runs fine the first time, but crashes the second time when it parses configs that the first run wrote:

$ CubicSDR 
Loading:: configuration file '/home/yuri/.CubicSDR/config.xml'
LoadFromFileXML[error loading]: /home/yuri/.CubicSDR/config.xml
Segmentation fault

rev. b0505b0
FreeBSD 11.2 amd64

@vsonnier
Copy link
Collaborator

vsonnier commented Feb 10, 2019

@yurivict Hiello ! A backtrace on a debug build would be greatly appreciated because obviously It Works For Me :)
It would be interesting to have the CMake command line, especially the enabled options (like Digital Lab on/off, Hamlib on/off...etc.)

@yurivict
Copy link
Author

Starting program: /usr/local/bin/CubicSDR 
Loading:: configuration file '/home/yuri/.CubicSDR/config.xml'
LoadFromFileXML[error loading]: /home/yuri/.CubicSDR/config.xml

Program received signal SIGSEGV, Segmentation fault.
__je_arena_mapbits_get (chunk=0x0, pageind=<optimized out>) at /usr/src/contrib/jemalloc/include/jemalloc/internal/arena.h:806
806		return (arena_mapbitsp_read(arena_mapbitsp_get_const(chunk, pageind)));
(gdb) bt
#0  0x0000000803f1e939 in __je_arena_mapbits_get (chunk=0x0, pageind=<optimized out>) at /usr/src/contrib/jemalloc/include/jemalloc/internal/arena.h:806
#1  0x0000000803f1e939 in __je_arena_mapbits_binind_get (chunk=0x0, pageind=<optimized out>) at /usr/src/contrib/jemalloc/include/jemalloc/internal/arena.h:863
#2  0x0000000803f1e939 in __je_arena_salloc (demote=false, tsdn=<optimized out>, ptr=<optimized out>) at /usr/src/contrib/jemalloc/include/jemalloc/internal/arena.h:1384
#3  0x0000000803f1e939 in __je_isalloc (demote=false, tsdn=<optimized out>, ptr=<optimized out>)
    at /usr/src/contrib/jemalloc/include/jemalloc/internal/jemalloc_internal.h:951
#4  0x0000000803f1e939 in ifree (tsd=0x0, ptr=<optimized out>, tcache=<optimized out>, slow_path=<optimized out>) at jemalloc_jemalloc.c:1810
#5  0x0000000803f1efd1 in __free (ptr=0x1) at jemalloc_jemalloc.c:1935
#6  0x0000000000644664 in TiXmlDocument::~TiXmlDocument() (this=0x7fffffffbe78) at /usr/local/include/tinyxml.h:1411
#7  0x000000000063dc61 in DataTree::LoadFromFileXML(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DT_FloatingPointPolicy)
    (this=0x7fffffffcab8, filename=..., fpp=USE_FLOAT) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/util/DataTree.cpp:1708
#8  0x00000000004a8e2e in AppConfig::load() (this=0x811e9da98) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/AppConfig.cpp:684
#9  0x000000000043b7dc in CubicSDR::OnCmdLineParsed(wxCmdLineParser&) (this=0x811e9d800, parser=...)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/CubicSDR.cpp:531
#10 0x000000080206e297 in wxAppConsoleBase::OnInit() () at /usr/local/lib/libwx_baseu-3.1.so.2
#11 0x0000000000437e7a in CubicSDR::OnInit() (this=0x811e9d800) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/CubicSDR.cpp:238
#12 0x0000000000446b69 in wxAppConsoleBase::CallOnInit() (this=0x811e9d800) at /usr/local/include/wx-3.1/wx/app.h:93
#13 0x0000000802105f93 in wxEntry(int&, wchar_t**) () at /usr/local/lib/libwx_baseu-3.1.so.2
#14 0x0000000000432fe6 in main(int, char**) (argc=1, argv=0x7fffffffe800) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/CubicSDR.cpp:28

@vsonnier
Copy link
Collaborator

vsonnier commented Feb 11, 2019

Thanks. Please add the compiling command line, and the config.xml that created the crash.
According to your backtrace, following some error while reading the config.xml (TiXmlDocument::LoadFile() returned false) the virtual destructor TiXmlDocument::~TiXmlDocument() is called as expected, and triggers the crash because its pointer TiXmlDocument this is invalid.

From this, I cannot say more and don't see why the TiXmlDocument would get corrupted, since its created on the stack from DataTree::LoadFromFileXML().
Maybe having your config.xml would help.

@yurivict
Copy link
Author

yurivict commented Feb 11, 2019

config.xml is empty:

ls -l /home/yuri/.CubicSDR/
total 0
-rw-r--r--  1 yuri  users  0 Feb  9 10:00 config.xml

And this is repeatable, from run to run.

It also crashes during the first run, when there is no xml file:

Thread 1 received signal SIGSEGV, Segmentation fault.
strlen (str=0x30323316 <error: Cannot access memory at address 0x30323316>) at /usr/src/lib/libc/string/strlen.c:100
100		va = (*lp - mask01);
(gdb) bt
#0  0x0000000803fb26bf in strlen (str=0x30323316 <error: Cannot access memory at address 0x30323316>) at /usr/src/lib/libc/string/strlen.c:100
#1  0x0000000803f4f339 in __vfprintf (fp=<optimized out>, locale=0x8041fa388 <__xlocale_global_locale>, fmt0=<optimized out>, ap=<optimized out>)
    at /usr/src/lib/libc/stdio/vfprintf.c:852
#2  0x0000000803f4cf44 in vfprintf_l (fp=0x804212eb0, locale=0x8041fa388 <__xlocale_global_locale>, fmt0=0x79202e "<![CDATA[%s]]>\n", ap=0x7fffffffcea0)
    at /usr/src/lib/libc/stdio/vfprintf.c:283
#3  0x0000000803f5445b in fprintf (fp=0x804212eb0, fmt=0x79202e "<![CDATA[%s]]>\n") at /usr/src/lib/libc/stdio/fprintf.c:55
#4  0x0000000000747f22 in TiXmlText::Print(__sFILE*, int) const (this=0x811f509c0, cfile=0x804212eb0, depth=3)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:1342
#5  0x0000000000746847 in TiXmlElement::Print(__sFILE*, int) const (this=0x811f90380, cfile=0x804212eb0, depth=2)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:829
#6  0x00000000007468fa in TiXmlElement::Print(__sFILE*, int) const (this=0x811f90440, cfile=0x804212eb0, depth=1)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:842
#7  0x00000000007468fa in TiXmlElement::Print(__sFILE*, int) const (this=0x811f90500, cfile=0x804212eb0, depth=0)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:842
#8  0x0000000000747718 in TiXmlDocument::Print(__sFILE*, int) const (this=0x7fffffffd328, cfile=0x804212eb0, depth=0)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:1150
#9  0x00000000007475c7 in TiXmlDocument::SaveFile(__sFILE*) const (this=0x7fffffffd328, fp=0x804212eb0)
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:1110
#10 0x000000000074719d in TiXmlDocument::SaveFile(char const*) const (this=0x7fffffffd328, filename=0x8163f2840 "/home/yuri/.CubicSDR/config.xml")
    at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/external/tinyxml/tinyxml.cpp:1090
#11 0x000000000063e139 in DataTree::SaveToFileXML(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
    (this=0x7fffffffda58, filename=...) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/util/DataTree.cpp:1723
#12 0x00000000004a8572 in AppConfig::save() (this=0x811e9da98) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/AppConfig.cpp:646
#13 0x0000000000455fa1 in AppFrame::OnClose(wxCloseEvent&) (this=0x811ffc000, event=...) at /usr/ports/comms/cubicsdr/work/CubicSDR-0.2.5-38-gb0505b0/src/AppFrame.cpp:1996
#14 0x00000008021df250 in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () at /usr/local/lib/libwx_baseu-3.1.so.2
#15 0x00000008021e0bfd in wxEvtHandler::ProcessEventLocally(wxEvent&) () at /usr/local/lib/libwx_baseu-3.1.so.2
#16 0x00000008021e0a84 in wxEvtHandler::ProcessEvent(wxEvent&) () at /usr/local/lib/libwx_baseu-3.1.so.2
#17 0x00000008021e114c in wxEvtHandler::SafelyProcessEvent(wxEvent&) () at /usr/local/lib/libwx_baseu-3.1.so.2
#18 0x00000008016bf6f9 in wxWindowBase::Close(bool) () at /usr/local/lib/libwx_gtk3u_core-3.1.so.2
#19 0x0000000801506841 in  () at /usr/local/lib/libwx_gtk3u_core-3.1.so.2
#20 0x0000000804851ea6 in  () at /usr/local/lib/libgtk-3.so.0
#21 0x000000080634b045 in  () at /usr/local/lib/libgobject-2.0.so.0
#22 0x0000000806360414 in g_signal_emit_valist () at /usr/local/lib/libgobject-2.0.so.0
#23 0x0000000806360d84 in g_signal_emit () at /usr/local/lib/libgobject-2.0.so.0
#24 0x00000008049ac6e9 in  () at /usr/local/lib/libgtk-3.so.0
#25 0x000000080484fe57 in gtk_main_do_event () at /usr/local/lib/libgtk-3.so.0
#26 0x0000000804f17201 in  () at /usr/local/lib/libgdk-3.so.0
#27 0x0000000804f4c307 in  () at /usr/local/lib/libgdk-3.so.0
--Type <RET> for more, q to quit, c to continue without paging--

@vsonnier
Copy link
Collaborator

vsonnier commented Feb 11, 2019

Thanks again 👍 So the root problem was that the DataTree::SaveToFileXML() failed because at some point TinyXML used a buffer overflow strlen. While attempting a print of <![CDATA[%s]]> which we don't use in CubicSDR anyway.

Hem. I'll try to investigate later I hope the bug is not in TinyXML itself...

@vsonnier
Copy link
Collaborator

vsonnier commented Feb 20, 2019

I've seen no trace in our code where the TiXmlText::cdata could be set to true, so what I'm supposing is that the field go smashed by our DataTree wrapper around TinyXML using at least one memcpy too many.

Please test this branch: https://github.com/cjcliffe/CubicSDR/tree/vso_dataelement_rework
where I've rewritten DataElement handling using templates and vector of bytes instead of raw pointer handling. Tell me if it's better for you.

I've also removed serialization support from DataTree to lighten the maintainance burden.

@vsonnier
Copy link
Collaborator

Forced-push another version into https://github.com/cjcliffe/CubicSDR/tree/vso_dataelement_rework, fix a crash on empty string XML tag (by re-introducing the old code), also removed long double support which is not a distinct type on all machines and which support was incomplete anyway.

@vsonnier
Copy link
Collaborator

I think I've got the thing right this time, could you please @yurivict test the branch https://github.com/cjcliffe/CubicSDR/tree/vso_dataelement_rework ? Thanks !

@vsonnier vsonnier mentioned this issue Feb 28, 2019
@Mur77
Copy link

Mur77 commented Feb 28, 2019

Hello,

I'm unable to build this branch, because of errors:
[ 1%] Building CXX object CMakeFiles/CubicSDR.dir/src/CubicSDR.cpp.o
In file included from /home/mur/pf/CubicSDR-vso/src/CubicSDR.cpp:17:
In file included from /home/mur/pf/CubicSDR-vso/src/CubicSDR.h:16:
In file included from /home/mur/pf/CubicSDR-vso/src/sdr/SoapySDRThread.h:11:
In file included from /home/mur/pf/CubicSDR-vso/src/AppConfig.h:13:
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:134:25: error: explicit
specialization of 'determineScalarDataType' in class scope
DataElementTypeEnum determineScalarDataType(const char& type_in) { r...
____________________^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:137:25: error: explicit
specialization of 'determineScalarDataType' in class scope
DataElementTypeEnum determineScalarDataType(const unsigned char& typ...
____________________^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:140:25: error: explicit
specialization of 'determineScalarDataType' in class scope
DataElementTypeEnum determineScalarDataType(const int& type_in) { re...
____________________^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:143:25: error: explicit
specialization of 'determineScalarDataType' in class scope
DataElementTypeEnum determineScalarDataType(const unsigned int& type...

There are some more of such errors!

@vsonnier
Copy link
Collaborator

@Mur77 Aaaah Templates ! I push a commit on the branch to try to fix this, tell me if it works.

@Mur77
Copy link

Mur77 commented Mar 1, 2019

Hi!

I got similar errors at the other place:
[ 2%] Building CXX object CMakeFiles/CubicSDR.dir/src/CubicSDR.cpp.o
In file included from /home/mur/pf/CubicSDR-vso/src/CubicSDR.cpp:17:
In file included from /home/mur/pf/CubicSDR-vso/src/CubicSDR.h:16:
In file included from /home/mur/pf/CubicSDR-vso/src/sdr/SoapySDRThread.h:11:
In file included from /home/mur/pf/CubicSDR-vso/src/AppConfig.h:13:
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:248:10: error: explicit
specialization of 'set' in class scope
void set(const string& str_in) {
_____^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:257:10: error: explicit
specialization of 'set' in class scope
void set(const wstring& wstr_in) {
_____^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:278:10: error: explicit
specialization of 'set' in class scope
void set(const vector<string>& vector_str_in) {
_____^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:417:10: error: explicit
specialization of 'get' in class scope
void get(string& str_out) {
_____^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:439:10: error: explicit
specialization of 'get' in class scope
void get(wstring& wstr_out) {
_____^
/home/mur/pf/CubicSDR-vso/src/util/DataTree.h:474:10: error: explicit
specialization of 'get' in class scope
void get(vector<string>& vector_str_out) {
_____^
6 errors generated.

@vsonnier
Copy link
Collaborator

vsonnier commented Mar 1, 2019

I forgot some fake partial templates last time. How about now ?

@Mur77
Copy link

Mur77 commented Mar 2, 2019

Hello, now I can build it and run successfully!

@vsonnier
Copy link
Collaborator

vsonnier commented Mar 2, 2019

Great news! So contrary to @yurivict, no trouble runing, saving settings, and so on ?

@Mur77
Copy link

Mur77 commented Mar 2, 2019

It runs without problems. Actually, I have one problem. It runs great. But when I click to waterfall to set demodulator frequency, the program slows down twice, like it's not enough CPU power, and sound is intermittent.
I'm not sure where is the problem. My CPU is Intel Celeron D 3.06 GHz.

@vsonnier
Copy link
Collaborator

vsonnier commented Mar 2, 2019

According to this site : https://www.cpubenchmark.net/cpu_list.php
Your CPU and mine has the following perfomance by comparison:

  • Intel Celeron D 347 @ 3.06GHz : 270
  • Intel Core i7-7700HQ @ 2.80GHz: 8822

Although mine is quite recent and powerful, yours is indeed very weak and has only 1 core.
CubicSDR is heavily multithreaded, and would need such a multicore processor.

You can try to lower the Sample rate to the minimum possible for your device, and see where it goes.

@Mur77
Copy link

Mur77 commented Mar 2, 2019

I got it. At minimum rate (250 KHz) it produces stable sound.
Thank you!

@vsonnier
Copy link
Collaborator

vsonnier commented Mar 2, 2019

Thanks @Mur77 for your report. Sorry for your so weak machine, I wish you'll got fun with Cubic anyway.
I think this issue can be closed now.

@vsonnier vsonnier closed this as completed Mar 2, 2019
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