I am building a custom protoc-compiler that is based on googles c++ libraries for protobuf.
I ran into a strange error when running it on linux, while it runs fine on MacOS
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
After setting up and trying around with my debugger this is the stacktrace:
#1 0x00007f61c097b897 in abort () from /usr/lib/libc.so.6
#2 0x00007f61c0d1381d in __gnu_cxx::__verbose_terminate_handler () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007f61c0d204da in __cxxabiv1::__terminate (handler=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007f61c0d20537 in std::terminate () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007f61c0d2078e in __cxxabiv1::__cxa_throw (obj=obj#entry=0x5568aec89df0, tinfo=tinfo#entry=0x7f61c0e5a750 <typeinfo for std::system_error>, dest=dest#entry=0x7f61c0d4cc60 <std::system_error::~system_error()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00007f61c0d167ff in std::__throw_system_error (__i=-1) at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/new_allocator.h:89
#7 0x00007f61c14b5c63 in std::call_once<void (&)(google::protobuf::internal::DescriptorTable const*), google::protobuf::internal::DescriptorTable const*&> (__f=#0x7f61c14c0780: {void (const google::protobuf::internal::DescriptorTable *)} 0x7f61c14c0780 <google::protobuf::(anonymous namespace)::AssignDescriptorsImpl(google::protobuf::internal::DescriptorTable const*)>, __once=...) at /usr/include/c++/7/mutex:698
#8 google::protobuf::internal::AssignDescriptors (table=<optimized out>, table#entry=0x7f61c17dddc0 <descriptor_table_google_2fprotobuf_2fdescriptor_2eproto>) at google/protobuf/generated_message_reflection.cc:2407
#9 0x00007f61c148f440 in google::protobuf::FileDescriptorProto::GetMetadataStatic () at ./google/protobuf/descriptor.pb.h:623
#10 google::protobuf::FileDescriptorProto::GetMetadata (this=<optimized out>) at google/protobuf/descriptor.pb.cc:2281
#11 0x00005568acbb22ed in google::protobuf::Message::GetReflection (this=0x7ffd47e4efc0) at /home/leo/CLionProjects/protoc-gen-java-leo/protoc/include/google/protobuf/message.h:333
#12 0x00005568acbad61f in google::protobuf::compiler::java_leo::(anonymous namespace)::CollectExtensions (message=..., extensions=0x7ffd47e4eef0) at /home/leo/CLionProjects/protoc-gen-java-leo/src/google/protobuf/compiler/java_leo/java_file.cc:84
#13 0x00005568acbad8ca in google::protobuf::compiler::java_leo::(anonymous namespace)::CollectExtensions (file_proto=..., alternate_pool=..., extensions=0x7ffd47e4eef0, file_data="\n\021addressbook.proto\022\btutorial\032\037google/protobuf/timestamp.proto\032\roptions.proto\"\255\002\n\006Person\022\"\n\002id\030\001 \001(\tB\022\222\202\031\016java.util.UUIDR\002id\022\022\n\004name\030\002 \001(\tR\004name\022\020\n\003age\030\003 \001(\005R\003age\022\024\n\005email\030\004 \001(\tR\005email\022\064\n\006phones\030\005 \003(\v2\034.tutorial.Person.PhoneNumberR\006phones\022=\n\flast_updated\030\006 \001(\v2\032.google.protobuf.TimestampR\vlastUpdated\032N\n\vPhoneNumber\022\026\n\006number\030\001 \001(\tR\006number\022'\n\004type\030\002 \001(\016\062\023.tutorial.PhoneTypeR\004type\"7\n\vAddressBook\022(\n\006people\030\001 \003(\v2\020.tutorial.PersonR\006people*+\n\tPhoneType\022\n\n\006MOBILE\020\000\022\b\n\004HOME\020\001\022\b\n\004WORK\020\002B+\n\024com.example.tutorialB\021AddressBookProtosP\001b\006proto3") at /home/leo/CLionProjects/protoc-gen-java-leo/src/google/protobuf/compiler/java_leo/java_file.cc:122
#14 0x00005568acbaf23f in google::protobuf::compiler::java_leo::FileGenerator::GenerateDescriptorInitializationCodeForImmutable (this=0x5568aec7d590, printer=0x7ffd47e4f380) at /home/leo/CLionProjects/protoc-gen-java-leo/src/google/protobuf/compiler/java_leo/java_file.cc:439
#15 0x00005568acbaed2a in google::protobuf::compiler::java_leo::FileGenerator::Generate (this=0x5568aec7d590, printer=0x7ffd47e4f380) at /home/leo/CLionProjects/protoc-gen-java-leo/src/google/protobuf/compiler/java_leo/java_file.cc:351
#16 0x00005568acbb73ea in google::protobuf::compiler::java_leo::JavaGenerator::Generate (this=0x7ffd47e4f788, file=0x5568aec77500, parameter="", context=0x7ffd47e4f5f0, error=0x7ffd47e4f5d0) at /home/leo/CLionProjects/protoc-gen-java-leo/src/google/protobuf/compiler/java_leo/java_generator.cc:158
#17 0x00007f61c0f06fae in google::protobuf::compiler::CodeGenerator::GenerateAll (this=0x7ffd47e4f788, files=std::vector of length 2, capacity 2 = {...}, parameter="", generator_context=0x7ffd47e4f5f0, error=0x7ffd47e4f5d0) at google/protobuf/compiler/code_generator.cc:58
#18 0x00007f61c0f16733 in google::protobuf::compiler::GenerateCode (request=..., generator=..., response=response#entry=0x7ffd47e4f6a0, error_msg=error_msg#entry=0x7ffd47e4f680) at google/protobuf/compiler/plugin.cc:133
#19 0x00007f61c0f16b17 in google::protobuf::compiler::PluginMain (argc=<optimized out>, argv=0x7ffd47e4f8c8, generator=0x7ffd47e4f788) at google/protobuf/compiler/plugin.cc:169
#20 0x00005568acbe9ed5 in main (argc=1, argv=0x7ffd47e4f8c8) at /home/leo/CLionProjects/protoc-gen-java-leo/main.cpp:10
#21 0x00007f61c097d153 in __libc_start_main () from /usr/lib/libc.so.6
#22 0x00005568acb9598e in _start ()
Since I'm a total C++ noob, it took me around 8 hours trying stuff out and googleing around before I found out the reason, so I wanted to share it here for the next person that might run into this problem.
It turns out, that the "pthread"-library is required and it crashes while calling the "call_once"-method if it's not present. A better error-message would have been great, "what(): Unknown error -1" didn't help out a lot :D
All I did was to add this line in my CMakeLists.txt:
target_link_libraries(${CMAKE_PROJECT_NAME} pthread)
Now it runs like a charm :)
Hope this helps someone.
Related
I'm building a simple utility program that queries a mysql database, and uses regex to isolate strings in the table data.
I'm using MariaDB c++/connector, and the latest versions of MariaDB. The code was copied from the MariaDB website. I have simplified the software to illustrate the problem. See below:
// g++ -o mariadb_connect mariadb_connect.cpp -lmariadbcpp
// From https://mariadb.com/docs/clients/connector-cpp/
// with three additional lines that cause segfault
#include <iostream>
#include <mariadb/conncpp.hpp>
#include <regex> // <-- Added to the example
int main()
{
try
{
// Instantiate Driver
sql::Driver* driver = sql::mariadb::get_driver_instance();
// Configure Connection
// The URL or TCP connection string format is
// ``jdbc:mariadb://host:port/database``.
sql::SQLString url("jdbc:mariadb://localhost:3306/??????");
// Use a properties map for the user name and password
sql::Properties properties({
{"user", "???????"},
{"password", "????????"}
});
// Establish Connection
// Use a smart pointer for extra safety
std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));
// Use Connection
std::cout << "Using the connection" << std::endl; // <-- Added
std::regex regexp("(faststatic.com)(.*)"); // <-- Added (Causes segfault)
// Close Connection
conn->close();
}
// Catch Exceptions
catch (sql::SQLException& e)
{
std::cout << "Error Connecting to MariaDB Platform: "
<< e.what() << std::endl;
// Exit (Failed)
return 1;
}
// Exit (Success)
return 0;
}
(???? used for private data)
Compiled with g++ on an AWS EC2 instance running Amazon Linux 2 AMI.
Compiles fine and runs fine until I added the std::regex regexp(...)
line. It still compiles fine with the addition, but on execution calls
a segfault.
I have used gdb which provides the following output with breakpoint set
to main.
(gdb) b main
Breakpoint 1 at 0x40404b: file mariadb_connect.cpp, line 15.
(gdb) run
Starting program: /home/msellers/proj/preload_images/spike/mariadb_connect
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x000000000064a588 in ?? ()
Here is the output of the gdb bt command after the segfault:
(gdb) bt
#0 0x000000000064a588 in ?? ()
#1 0x0000000000409155 in std::__detail::_Scanner<char>::_M_scan_normal (this=0x7fffffffe018) at /usr/include/c++/7/bits/regex_scanner.tcc:119
#2 0x00000000004084a1 in std::__detail::_Scanner<char>::_M_advance (this=0x7fffffffe018) at /usr/include/c++/7/bits/regex_scanner.tcc:80
#3 0x00007ffff7c3e060 in std::__detail::_Compiler<std::regex_traits<char> >::_M_match_token (this=this#entry=0x7fffffffe000, token=std::__detail::_ScannerBase::_S_token_subexpr_begin) at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:541
#4 0x00007ffff7c513a2 in std::__detail::_Compiler<std::regex_traits<char> >::_M_match_token (token=std::__detail::_ScannerBase::_S_token_subexpr_begin, this=0x7fffffffe000) at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:316
#5 std::__detail::_Compiler<std::regex_traits<char> >::_M_atom (this=this#entry=0x7fffffffe000) at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:326
#6 0x00007ffff7c515b0 in std::__detail::_Compiler<std::regex_traits<char> >::_M_term (this=0x7fffffffe000) at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:136
#7 std::__detail::_Compiler<std::regex_traits<char> >::_M_alternative (this=0x7fffffffe000) at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:118
#8 0x00007ffff7c51809 in std::__detail::_Compiler<std::regex_traits<char> >::_M_disjunction (this=this#entry=0x7fffffffe000) at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:97
#9 0x00007ffff7c51e18 in std::__detail::_Compiler<std::regex_traits<char> >::_Compiler (this=0x7fffffffe000, __b=<optimized out>, __e=<optimized out>, __traits=..., __flags=<optimized out>)
at /usr/local/include/c++/4.9.4/bits/regex_compiler.tcc:82
#10 0x00007ffff7c5222d in std::__detail::__compile_nfa<std::regex_traits<char> > (__first=<optimized out>, __last=<optimized out>, __traits=..., __flags=<optimized out>) at /usr/local/include/c++/4.9.4/bits/regex_compiler.h:158
#11 0x00007ffff7c524da in std::basic_regex<char, std::regex_traits<char> >::basic_regex<char const*> (__f=<optimized out>, __last=<optimized out>, __first=<optimized out>, this=0x7ffff7dc2a40 <sql::mariadb::UrlParser::URL_PARAMETER>)
at /usr/local/include/c++/4.9.4/bits/regex.h:540
#12 std::basic_regex<char, std::regex_traits<char> >::basic_regex (this=0x7ffff7dc2a40 <sql::mariadb::UrlParser::URL_PARAMETER>, __p=<optimized out>, __f=<optimized out>) at /usr/local/include/c++/4.9.4/bits/regex.h:452
#13 0x00007ffff7c331ee in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at /home/buildbot/src/src/UrlParser.cpp:34
#14 _GLOBAL__sub_I_UrlParser.cpp(void) () at /home/buildbot/src/src/UrlParser.cpp:444
#15 0x00007ffff7de7dc2 in call_init (l=<optimized out>, argc=argc#entry=1, argv=argv#entry=0x7fffffffe2b8, env=env#entry=0x7fffffffe2c8) at dl-init.c:72
#16 0x00007ffff7de7eb6 in call_init (env=0x7fffffffe2c8, argv=0x7fffffffe2b8, argc=1, l=<optimized out>) at dl-init.c:119
#17 _dl_init (main_map=0x7ffff7ffe130, argc=1, argv=0x7fffffffe2b8, env=0x7fffffffe2c8) at dl-init.c:120
#18 0x00007ffff7dd9f2a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#19 0x0000000000000001 in ?? ()
#20 0x00007fffffffe520 in ?? ()
#21 0x0000000000000000 in ?? ()
(gdb)
Does this help?
Mark
GCC version 7.3.1
In the backtrace, we see that the crash is happening in the GCC-7 regexp implementation:
#1 0x0000000000409155 in std::__detail::_Scanner<char>::_M_scan_normal (this=0x7fffffffe018) at /usr/include/c++/7/bits/regex_scanner.tcc:119
We also see that this crash is happening while some global inside (presumably1) MariaDB connector is being initialized, while using GCC-4.9.4 version of libstdc++:
#12 std::basic_regex<char, std::regex_traits<char> >::basic_regex (this=0x7ffff7dc2a40 <sql::mariadb::UrlParser::URL_PARAMETER>, __p=<optimized out>, __f=<optimized out>) at /usr/local/include/c++/4.9.4/bits/regex.h:452
#13 0x00007ffff7c331ee in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at /home/buildbot/src/src/UrlParser.cpp:34
It is exceedingly likely that this 4.9.4 vs. 7.3.1 mismatch is the cause of the crash, and that either building the app with g++-4.9.4 or building the MariaDB with g++-7.3.1 will fix the problem.
In theory GCC version of libstdc++ should be backwards compatible, but verifying ABI compatibility in C++ is quite hard, and many mistakes have been made. Also, g++4.9.4 is ancient.
Another possible solution is to build the application with clang using libc++ -- this will avoid any possibility of symbol conflicts2.
1 You can verify whether frame #13 is really coming from the MariaDB by executing these GDB commands: frame 13, info symbol $pc.
2 To achieve this, you may need to explicitly tell clang to use libc++, as it may default to using libstdc++. Use clang++ -stdlib=libc++ ... to be sure. Documentation here.
I have a multithreaded program, in which some thread causes an exception. I ran it in gdb, which gives the following output after the exception occurred and the program is terminated:
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
Thread 46 "MyProgram" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fff3bfff700 (LWP 24491)]
0x00007ffff48f2428 in __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) where
#0 0x00007ffff48f2428 in __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff48f402a in __GI_abort () at abort.c:89
#2 0x00007ffff514d0d5 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff514acc6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff514ad11 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff517719e in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ffff4c8e6ba in start_thread (arg=0x7fff3bfff700) at pthread_create.c:333
#7 0x00007ffff49c441d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
The output from where does not really help to find out which thread causes the problem.
Is there a way to get more information out of this situation?
When you see this output it is too late to find out what thread have thrown an exception because your program is already terminated. I guess what you need is to set catchpoint on std::out_of_range exception and continue running your program until this exception is thrown:
(gdb) catch throw out_of_range
When exception is thrown, gdb should stop and you can print backtrace of thread that causes an exception.
For those ones who go after us. I was come to the same issue:
And it text
Thread 1 "Auditor_Tst" hit Catchpoint 1 (exception thrown), 0xb6a07b48 in __cxa_throw () from /usr/lib/libstdc++.so.6
(gdb) bt
#0 0xb6a07b48 in __cxa_throw () from /usr/lib/libstdc++.so.6
#1 0xb6f3105e in Utils::(anonymous namespace)::getSubJson (j=..., key=...) at ../Src/Auditor/GetterJsonValue.cpp:61
#2 0xb6f31270 in Utils::getJsonValueByPath (json=..., keyList=...) at ../Src/Auditor/GetterJsonValue.cpp:132
#3 0xb6f42b76 in Utils::getJsonValueByPathAs<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (json=..., keyList=...) at ../Src/Auditor/Helper/GetterJsonValue.hpp:136
#4 0xb6f5c852 in Utils::getJsonValueByPathAs<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (json=..., keyList=..., defaultValue=...) at ../Src/Auditor/Helper/GetterJsonValue.hpp:155
#5 0xb6f80488 in Auditor::LogProcessor::extractBeginDate (message=..., isInvalid=#0xbefff2bd: false) at ../Src/Auditor/AuditorProcessor.cpp:320
#6 0xb6f7f9a6 in Auditor::LogProcessor::processHistory (this=0xbefff750, message=...) at ../Src/Auditor/AuditorProcessor.cpp:197
#7 0xb6f7f4ca in Auditor::LogProcessor::process (this=0xbefff750, message=...) at ../Src/Auditor/AuditorProcessor.cpp:135
#8 0x00106eb0 in Auditor::Processor_Test_requestEmptyHitoryJson_Test::TestBody (this=0x16fef8) at ../Tst/Auditor/AuditorProcessorTests.cpp:262
#9 0xb6b75fa2 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=0x16fef8, method=&virtual testing::Test::TestBody(), location=0xb6b86330 "the test body") at ../Tools/googletest/googletest/src/gtest.cc:2607
#10 0xb6b7054a in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x16fef8, method=&virtual testing::Test::TestBody(), location=0xb6b86330 "the test body") at ../Tools/googletest/googletest/src/gtest.cc:2643
#11 0xb6b5092e in testing::Test::Run (this=0x16fef8) at ../Tools/googletest/googletest/src/gtest.cc:2682
#12 0xb6b51056 in testing::TestInfo::Run (this=0x160a00) at ../Tools/googletest/googletest/src/gtest.cc:2861
#13 0xb6b516f2 in testing::TestSuite::Run (this=0x160490) at ../Tools/googletest/googletest/src/gtest.cc:3015
#14 0xb6b5c820 in testing::internal::UnitTestImpl::RunAllTests (this=0x15dd90) at ../Tools/googletest/googletest/src/gtest.cc:5851
#15 0xb6b76d42 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x15dd90, method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0xb6b5c571 <testing::internal::UnitTestImpl::RunAllTests()>, location=0xb6b86dbc "auxiliary test code (environments or event listeners)") at ../Tools/googletest/googletest/src/gtest.cc:2607
#16 0xb6b71136 in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x15dd90, method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0xb6b5c571 <testing::internal::UnitTestImpl::RunAllTests()>, location=0xb6b86dbc "auxiliary test code (environments or event listeners)") at ../Tools/googletest/googletest/src/gtest.cc:2643
#17 0xb6b5b738 in testing::UnitTest::Run (this=0xb6ba6dd8 <testing::UnitTest::GetInstance()::instance>) at ../Tools/googletest/googletest/src/gtest.cc:5434
#18 0x0012a22a in RUN_ALL_TESTS () at ../Tools/googletest/googletest/include/gtest/gtest.h:2471
#19 0x0012a1b6 in main (argc=1, argv=0xbefffc54) at ../Tst/Auditor/AuditorMain.cpp:10
(gdb) frame 1
#1 0xb6f3105e in Utils::(anonymous namespace)::getSubJson (j=..., key=...) at ../Src/Auditor/GetterJsonValue.cpp:61
61 in ../Src/Auditor/GetterJsonValue.cpp
(gdb) info locals
error = {static npos = 4294967295, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x162940 "Key 'begin-date' not found in {\"msg-name\":\"get-audit-log\",\"msg-type\":\"req\",\"val\":12,\"res\":\"ok\"}."}, _M_string_length = 96, {_M_local_buf = "`\000\000\000\330\006\354\266\254\361\377\276`\221\377\266", _M_allocated_capacity = 96}}
__func__ = "getSubJson"
(gdb) p (char*)error
$6 = 0x162940 "Key 'begin-date' not found in {\"msg-name\":\"get-auditor-name\",\"msg-type\":\"req\",\"val\":12,\"res\":\"ok\"}."
last line shows what is passed to constructor of exception, this is what it would return from what()
I am in a bit of a pickle.
My application has one main window (inherits from QMainWindow). The main window is parent to a QTabWidget, which acts as a sort of dialog that shows up when the user clicks a toolbar button on the main window, and hides when its 'Close' button is clicked. In addition, the main window has another toolbar button, which when clicked, calls exec() on a QDialog. While developing the app, I have noticed that once every 40 times or so, clicking one of the two buttons I have mentioned causes an empty widget to appear, but instead of the intended view being drawn, everything freezes. When I click the 'Close' button on the main window, my OS tells me that the application has stopped responding. There is never any way to recover from crashes like this, and I am usually forced to kill the app and restart.
The vexing thing about all this is that I cannot reproduce the crashes at will. They are impossible to predict, and often catch me off-guard.
I used gdb to attach to a frozen instance, and got the following back trace:
#0 pthread_cond_wait##GLIBC_2.3.2 ()
at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1 0x00007f1ba3bf1b03 in QWaitCondition::wait(QMutex*, unsigned long) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#2 0x00007f1ba3bea277 in QReadWriteLock::lockForRead() ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#3 0x00007f1b9bf5ee4e in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#4 0x00007f1b9bf61d71 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#5 0x00007f1b9bf64e54 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#6 0x00007f1b904159d6 in dbus_connection_dispatch () from /lib/x86_64-linux-gnu/libdbus-1.so.3
#7 0x00007f1b9bf579f5 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#8 0x00007f1b9bfa78f5 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#9 0x00007f1ba3e5a326 in QObject::event(QEvent*) () from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#10 0x00007f1ba510b8f4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#11 0x00007f1ba510f506 in QApplication::notify(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#12 0x00007f1ba3e25c84 in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#13 0x00007f1ba3e28868 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#14 0x00007f1ba3e80123 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#15 0x00007f1ba283be04 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#16 0x00007f1ba283c048 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#17 0x00007f1ba283c0ec in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#18 0x00007f1ba3e80554 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
() from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#19 0x00007f1ba3e23eab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#20 0x00007f1ba530a2ed in QDialog::exec() () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#21 0x0000000000425fe4 in MainWindow::AddNewDownload() ()
#22 0x00007f1ba3e57e7a in QMetaObject::activate(QObject*, int, int, void**) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#23 0x00007f1ba50fee52 in QAction::triggered(bool) () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#24 0x00007f1ba5100c77 in QAction::activate(QAction::ActionEvent) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#25 0x00007f1ba520b0b5 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#26 0x00007f1ba520b374 in QAbstractButton::mouseReleaseEvent(QMouseEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#27 0x00007f1ba52cf89a in QToolButton::mouseReleaseEvent(QMouseEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#28 0x00007f1ba514723c in QWidget::event(QEvent*) () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#29 0x00007f1ba52d0730 in QToolButton::event(QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#30 0x00007f1ba510b8f4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#31 0x00007f1ba510f071 in QApplication::notify(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#32 0x00007f1ba3e25c84 in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#33 0x00007f1ba510df88 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#34 0x00007f1ba5162387 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#35 0x00007f1ba5164e78 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
---Type <return> to continue, or q <return> to quit---
It appears that my app is stuck waiting to be woken up when a certain condition is met. The presence of dbus in the back trace suggests that it was trying to talk to another process, which I am guessing is a GUI-related process. I however do not know why the wait condition is met 98% of the time, but fails 2% of the time. When using strace, I was able to find that the system call that blocked is:
futex(0x7f403c00690c, FUTEX_WAIT_PRIVATE, 1, NULL)
I am not using QThreads or mutexes in my code, so I am guessing this problem is Qt-internal. Does anyone with knowledge of low-level workings of Qt know what is happening?
Runnning my application I get a Segmentation fault. I ran gdb to check where my code was failing but I get the following output:
Program received signal SIGSEGV, Segmentation fault.
0x39ca8000 in ?? ()
(gdb) bt
#0 0x39ca8000 in ?? ()
#1 0xb7d5df9a in sc_core::sc_port_base::complete_binding() () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#2 0xb7d5e104 in sc_core::sc_port_registry::complete_binding() () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#3 0xb7d5e13e in sc_core::sc_port_registry::elaboration_done() () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#4 0xb7dc669d in sc_core::sc_simcontext::elaborate() () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#5 0xb7dc8567 in sc_core::sc_simcontext::initialize(bool) () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#6 0xb7dc8b19 in sc_core::sc_simcontext::simulate(sc_core::sc_time const&) () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#7 0xb7dc9708 in sc_core::sc_start(sc_core::sc_time const&) () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#8 0x080555a8 in sc_core::sc_start (duration=40000, time_unit=sc_core::SC_MS) at /opt/systemc-2.2-rel/include/sysc/kernel/sc_simcontext.h:608
#9 0x08055119 in sc_main (argc=1, argv=0xbffff524) at module_pfn.cpp:49
#10 0xb7dbc698 in sc_elab_and_sim () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#11 0xb7d522e7 in main () from /opt/systemc-2.2-rel/lib/libsystemc.so.2.2
#12 0xb7a2e4d3 in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
#13 0x08054da1 in _start ()
As you can see, everything comes from a library, except the 'main' call and 'start',where I set breakpoints, but they fail immediately there. I mean:
#8 0x080555a8 in sc_core::sc_start (duration=40000, time_unit=sc_core::SC_MS) at /opt/systemc-2.2-rel/include/sysc/kernel/sc_simcontext.h:608
#9 0x08055119 in sc_main (argc=1, argv=0xbffff524) at module_pfn.cpp:49
...
(gdb) br /opt/systemc-2.2-rel/include/sysc/kernel/sc_simcontext.h:608
Breakpoint 2 at 0x8055584: file /opt/systemc-2.2-rel/include/sysc/kernel/sc_simcontext.h, line 608.
(gdb) r
Starting program: /home/guest/Solutions/eln/systemc-ams/module_pfn
...
Breakpoint 2, sc_core::sc_start (duration=40000, time_unit=sc_core::SC_MS) at /opt/systemc-2.2-rel/include/sysc/kernel/sc_simcontext.h:608
608 sc_start( sc_time( duration, time_unit ) );
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
0x39ca8000 in ?? ()
And we go back to the start.
I am not able to understand where this is failing. I see there is the name of the place in which this is failing: sc_core::sc_port_base::complete_binding() and I have access to the cpp where this function can be found, but only in the source files (not the library). The problem is that I would really like to go step by step through that code, is it possible?
Thanks :)
Thanks guys!
I used a library with debug info and now I can go through the library code.
My linux(ubuntu 12.04) process crash when I use ACE_5.7.1. My code:
ACE_INET_Addr remote_addr(server_addr.c_str());
ACE_SOCK_Stream stream;
ACE_SOCK_Connector connector;
ACE_Time_Value to(1, 0), to2(2,0);
ret = connector.connect(stream, remote_addr, &to);
Stack info:
Program terminated with signal 6, Aborted
#0 0x00002b47daf8d425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00002b47daf8d425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00002b47daf90b8b in __GI_abort () at abort.c:91
#2 0x00002b47dafcb39e in __libc_message (do_abort=2, fmt=0x2b47db0d2e3f "*** %s ***: %s terminated\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
#3 0x00002b47db061817 in __GI___fortify_fail (msg=0x2b47db0d2dd6 "buffer overflow detected") at fortify_fail.c:32
#4 0x00002b47db060710 in __GI___chk_fail () at chk_fail.c:29
#5 0x00002b47db0617ce in __fdelt_chk (d=<optimized out>) at fdelt_chk.c:26
#6 0x00002b47d9ee9c3b in is_set (handle=1537, this=0x2b48883e9d90) at /home/cfcheng/MSP4.0/source/source/engine/ivs/../../share/ACE-5.7.1/ace/Handle_Set.inl:84
#7 set_bit (handle=1537, this=0x2b48883e9d90) at /home/cfcheng/MSP4.0/source/source/engine/ivs/../../share/ACE-5.7.1/ace/Handle_Set.inl:103
#8 ACE::handle_timed_complete (h=1537, timeout=0x2b48883ea110, is_tli=0) at ACE.cpp:2547
#9 0x00002b47d9f4e5c7 in ACE_SOCK_Connector::complete (this=<optimized out>, new_stream=..., remote_sap=0x0, tv=<optimized out>) at SOCK_Connector.cpp:262
#10 0x00002b47d9f4e737 in ACE_SOCK_Connector::shared_connect_finish (this=0x2b48883ea17f, new_stream=..., timeout=0x2b48883ea110, result=-1) at SOCK_Connector.cpp:155
#11 0x000000000044f4a9 in res_update_work::send_notify(std::string const&, std::string const&) ()
#12 0x000000000044fe7e in res_update_work::batch_send(std::string const&, ACE_Time_Value const&, bool) ()
#13 0x00000000004506c5 in res_update_work::update_all_res() ()
#14 0x0000000000450ada in res_update_work::svc() ()
#15 0x00002b47d9f56427 in ACE_Task_Base::svc_run (args=0x3e5a490) at Task.cpp:275
#16 0x00002b47d9f578c4 in ACE_Thread_Adapter::invoke (this=0x3e5ae90) at Thread_Adapter.cpp:98
#17 0x00002b47dad41e9a in start_thread (arg=0x2b4888401700) at pthread_create.c:308
#18 0x00002b47db04accd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#19 0x0000000000000000 in ?? ()
Who know why these code cause exception.
Thanks very much.
You are passing automatic objects to connect , I suspect this is causing the problem. Try to allocate the objects passed to connect dynamically, or make them attributes of an object which is still alive after the function where you call connect terminates. The same with the connector object.