My program appears to run just fine most of the time, but occasionally I get a segmentation fault.
boost version = 1.41.0
running on RHEL 4
compiled with GCC 3.4.6
Backtrace:
#0 0x08138546 in boost::asio::detail::posix_fd_set_adapter::is_set (this=0xb74ed020, descriptor=-1)
at /home/scottl/boost_1_41_0/boost/asio/detail/posix_fd_set_adapter.hpp:57
__result = -1 'ÿ'
#1 0x0813e1b0 in boost::asio::detail::reactor_op_queue::perform_operations_for_descriptors (this=0x97f3b6c, descriptors=#0xb74ed020, result=#0xb74ecec8)
at /home/scottl/boost_1_41_0/boost/asio/detail/reactor_op_queue.hpp:204
op_iter = {_M_node = 0xb4169aa0}
i = {_M_node = 0x97f3b74}
#2 0x081382ca in boost::asio::detail::select_reactor::run (this=0x97f3b08, block=true)
at /home/scottl/boost_1_41_0/boost/asio/detail/select_reactor.hpp:388
read_fds = {fd_set_ = {fds_bits = {16, 0 }}, max_descriptor_ = 65}
write_fds = {fd_set_ = {fds_bits = {0 }}, max_descriptor_ = -1}
retval = 1
lock = { = {}, mutex_ = #0x97f3b1c, locked_ = true}
except_fds = {fd_set_ = {fds_bits = {0 }}, max_descriptor_ = -1}
max_fd = 65
tv_buf = {tv_sec = 0, tv_usec = 710000}
tv = (timeval *) 0xb74ecf88
ec = {m_val = 0, m_cat = 0x81f2c24}
sb = { = {}, blocked_ = true, old_mask_ = {__val = {0, 0, 134590223,
3075395548, 3075395548, 3075395464, 134729792, 3075395360, 135890240, 3075395368, 134593920, 3075395544, 135890240,
3075395384, 134599542, 3020998404, 135890240, 3075395400, 134614095, 3075395544, 4, 3075395416, 134548135, 3021172996,
4294967295, 3075395432, 134692921, 3075395504, 0, 3075395448, 134548107, 3021172992}}}
#3 0x0812eb45 in boost::asio::detail::task_io_service >::do_one (this=0x97f3a70,
lock=#0xb74ed230, this_idle_thread=0xb74ed240, ec=#0xb74ed2c0)
at /home/scottl/boost_1_41_0/boost/asio/detail/task_io_service.hpp:260
more_handlers = false
c = {lock_ = #0xb74ed230, task_io_service_ = #0x97f3a70}
h = (boost::asio::detail::handler_queue::handler *) 0x97f3aa0
polling = false
task_has_run = true
#4 0x0812765f in boost::asio::detail::task_io_service >::run (this=0x97f3a70,
ec=#0xb74ed2c0) at /home/scottl/boost_1_41_0/boost/asio/detail/task_io_service.hpp:103
ctx = { = {}, owner_ = 0x97f3a70, next_ = 0x0}
this_idle_thread = {wakeup_event = { = {}, cond_ = {__c_lock = {
__status = 0, __spinlock = 22446}, __c_waiting = 0x2bd7,
__padding = "\000\000\000\000×+\000\000\000\000\000\000×+\000\000\000\000\000\000\204:\177\t\000\000\000", __align = 0},
signalled_ = true}, next = 0x0}
lock = { = {}, mutex_ = #0x97f3a84, locked_ = false}
n = 11420
#5 0x08125e99 in boost::asio::io_service::run (this=0x97ebbcc) at /home/scottl/boost_1_41_0/boost/asio/impl/io_service.ipp:58
ec = {m_val = 0, m_cat = 0x81f2c24}
s = 8
#6 0x08154424 in boost::_mfi::mf0::operator() (this=0x9800870, p=0x97ebbcc)
at /home/scottl/boost_1_41_0/boost/bind/mem_fn_template.hpp:49
No locals.
#7 0x08154331 in boost::_bi::list1 >::operator(), boost::_bi::list0> (this=0x9800878, f=#0x9800870, a=#0xb74ed337)
at /home/scottl/boost_1_41_0/boost/bind/bind.hpp:236
No locals.
#8 0x081541e5 in boost::_bi::bind_t, boost::_bi::list1 > >::operator() (this=0x9800870) at /home/scottl/boost_1_41_0/boost/bind/bind_template.hpp:20
a = {}
#9 0x08154075 in boost::detail::thread_data, boost::_bi::list1 > > >::run (this=0x98007a0)
at /home/scottl/boost_1_41_0/boost/thread/detail/thread.hpp:56
No locals.
#10 0x0816fefd in thread_proxy () at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
__ioinit = {static _S_refcount = , static _S_synced_with_stdio = }
---Type to continue, or q to quit---
typeinfo for common::RuntimeException = {}
typeinfo name for common::RuntimeException = "N6common16RuntimeExceptionE"
#11 0x00af23cc in start_thread () from /lib/tls/libpthread.so.0
No symbol table info available.
#12 0x00a5c96e in __init_misc () from /lib/tls/libc.so.6
No symbol table info available.
Without seeing the code in question, I can only guess, but I've had asio crash on several occasions due to the object whose method has been passed (via boost::bind) to asio has been deleted before asio calls the method.
Related
I have a multithread application which accesses a DB from multiple thread, and randomically I fall in this error (not the same query)...
__GI___libc_free (mem=0x7fff00042660) at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:3093
QList<_RData>::node_destruct (this=0x7fffebffce08, from=0x7fffe4037fc0, to=0x7fffe4037fd8) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:494
QList<_RData>::dealloc (this=0x7fffebffce08, data=0x7fffe4037fb0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:865
QList<_RData>::~QList (this=0x7fffebffce08) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:827
QList<_RData>::operator= (this=0x55555565cd68, other=#0x7fffebffd880: {<QListSpecialMethods<_RoomData>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x7ffff6ff76c0 <QListData::shared_null>}, d = 0x7ffff6ff76c0 <QListData::shared_null>}}) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:159
AMProcess::doActionAM (this=0x55555565cc30) at /smart/software/AudioIO/AMProcess.cpp:453
QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (AMProcess::*)()>::call(void (AMProcess::*)(), AMProcess*, void**) (f=(void (AMProcess::*)(AMProcess * const)) 0x5555555b943c <AMProcess::doActionAM()>, o=0x55555565cc30, arg=0x7fffebffee40) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:134
QtPrivate::FunctionPointer<void (AMProcess::*)()>::call<QtPrivate::List<>, void>(void (AMProcess::*)(), AMProcess*, void**) (f=(void (AMProcess::*)(AMProcess * const)) 0x5555555b943c <AMProcess::doActionAM()>, o=0x55555565cc30, arg=0x7fffebffee40) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:167
QtPrivate::QSlotObject<void (AMProcess::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1, this_=0x555555661cf0, r=0x55555565cc30, a=0x7fffebffee40, ret=0x0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:396
QMetaObject::activate(QObject*, int, int, void**) () at null:
QThread::started(QThread::QPrivateSignal) () at null:
?? () at null:
start_thread (arg=<optimized out>) at /build/glibc-vjB4T1/glibc-2.28/nptl/pthread_create.c:486
clone () at /build/glibc-vjB4T1/glibc-2.28/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
This is some snippets of my code
rData = DBRManager::ReadRData("R", m_connName);
if (rData.size() > 0) {
}
...and this is the query
QList<_RData> DBRManager::ReadRData(QString tbName, QString dbName)
{
QList<_RData> records;
QSqlQuery query(QSqlDatabase::database(dbName));
query.setForwardOnly(true);
query.exec("DSQLITE_THREADSAFE=2");
query.exec("SELECT * FROM " + tbName);
while (query.next()) {
_RData data;
data.id = query.value("id").toInt();
data.type = query.value("type").toInt();
records.append(data);
}
query.finish();
return records;
}
Some pieces of my code crash randomly when call push_back or erase on std::list, the code is in a long time runing service . I removed the unimportant part and just keep the most relevant.
std::list<RxCCPReport> pendingSync;
size_t AnchorConnection::HandleCCPTxReport(const char *rxBytes, size_t length) {
if (!pendingSync.empty())
{
std::list<RxCCPReport>::iterator iter = pendingSync.begin();
while (iter != pendingSync.end())
{
if (condition1)
{
iter = pendingSync.erase(iter);
}
else
{
if (condition2)
{
++iter;
}
else if (condition3)
{
++iter;
}
else
{
iter = pendingSync.erase(iter);
}
}
}
}
return length; }
size_t AnchorConnection::HandleCCPRxReport(const char *rxBytes, size_t length) {
RxCCPReport rxCCP;
rxCCP.anc = anc;
rxCCP.rxTime = ccpRxTime;
rxCCP.seqNum = pCsMsg->seqNum;
pendingSync.push_back(rxCCP);
return length;
}
The two function runs on the same thread; code will crash at pendingSync.erase(iter) or pendingSync.push_back(rxCCP) sometimes, about 1 time a week.
the backtrace:
crashed at erase
#0 std::__detail::_List_node_base::_M_unhook (this=0x7fffcc024040) at ../../../../../libstdc++-v3/src/c++98/list.cc:142
__next_node = 0x0
__prev_node = 0x7fffcc024040
#1 0x00000000004db14a in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1570
__n = 0x7fffe5ffad80
#2 0x00000000004daddb in std::list<RxCCPReport, std::allocator<RxCCPReport> >::erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/list.tcc:112
__ret = <error reading variable __ret (Cannot access memory at address 0x10)>
#3 0x00000000004e3d8b in AnchorConnection::HandleCCPTxReport (this=0x7fffdc009240, rxBytes=0x7fffc4022abb "0rl\206%M/\004\205O\263\002\216\356\003\002f", length=12)
at LE/Network/rtls_anchor_conn.cpp:731
rxCCP = {rxTime = 3.1943677384753104, seqNum = 114 'r', anc = }
cSeqRxCCP = 114 'r'
cs = 0x7fffdc016430
ccpTx = 203157767788
ccpTxTime = 3.1794272052158457
pCsMsg = 0x7fffc4022abb
cSeqTxCCP = 114 'r'
crashed at push_back another time
> #0 0x00007ffff6dff387 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
resultvar = 0
pid = 5068
selftid = 5418
#1 0x00007ffff6e00a78 in __GI_abort () at abort.c:90
save_stage = 2
act = {__sigaction_handler = {sa_handler = 0x7ffff6ddb76d, sa_sigaction = 0x7ffff6ddb76d}, sa_mask = {__val = {5, 140737336646961, 3, 140737043728478, 2,
140737336643303, 1, 140737336652017, 3, 140737043728452, 12, 140737336652021, 2, 140737043729264, 140737043729264, 140737043731024}}, sa_flags = 16,
sa_restorer = 0x7fffe57f8d70}
sigs = {__val = {32, 0 <repeats 15 times>}}
#2 0x00007ffff6e41ed7 in __libc_message (do_abort=do_abort#entry=2, fmt=fmt#entry=0x7ffff6f54350 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
ap = {{gp_offset = 40, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
ap_copy = {{gp_offset = 16, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
fd = 26
on_2 = <optimized out>
list = <optimized out>
nlist = <optimized out>
cp = <optimized out>
written = <optimized out>
#3 0x00007ffff6e483e4 in malloc_printerr (action=<optimized out>, str=0x7ffff6f54548 "malloc(): memory corruption (fast)", ptr=<optimized out>, ar_ptr=<optimized out>)
at malloc.c:4967
buf = "00007fffd8001570"
cp = <optimized out>
ar_ptr = <optimized out>
ptr = <optimized out>
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
action = <optimized out>
#4 0x00007ffff6e4bb20 in _int_malloc (av=av#entry=0x7fffd0000020, bytes=bytes#entry=40) at malloc.c:3383
p = 0x7fffd8001560
fb = <optimized out>
pp = <optimized out>
nb = 48
idx = <optimized out>
bin = <optimized out>
victim = 0x7fffd8001560
size = <optimized out>
victim_index = <optimized out>
remainder = <optimized out>
remainder_size = <optimized out>
block = <optimized out>
bit = <optimized out>
map = <optimized out>
fwd = <optimized out>
bck = <optimized out>
errstr = <optimized out>
#5 0x00007ffff6e4e6fc in __GI___libc_malloc (bytes=40) at malloc.c:2905
ar_ptr = 0x7fffd0000020
victim = <optimized out>
hook = <optimized out>
#6 0x00007ffff7929ecd in operator new (sz=40) at ../../../../libstdc++-v3/libsupc++/new_op.cc:51
p = <optimized out>
#7 0x00000000004dc6f8 in __gnu_cxx::new_allocator<std::_List_node<RxCCPReport> >::allocate (this=0x7fffdc011930, __n=1) at /usr/include/c++/4.8.2/ext/new_allocator.h:104
No locals.
#8 0x00000000004dc006 in std::_List_base<RxCCPReport, std::allocator<RxCCPReport> >::_M_get_node (this=0x7fffdc011930) at /usr/include/c++/4.8.2/bits/stl_list.h:334
No locals.
#9 0x00000000004db699 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_create_node<RxCCPReport const&> (this=0x7fffdc011930)
at /usr/include/c++/4.8.2/bits/stl_list.h:502
__p = 0x0
#10 0x00000000004db1c2 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_insert<RxCCPReport const&> (this=0x7fffdc011930, __position=...)
at /usr/include/c++/4.8.2/bits/stl_list.h:1561
__tmp = 0x0
#11 0x00000000004dae68 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::push_back (this=0x7fffdc011930, __x=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1016
No locals.
#12 0x00000000004e475b in AnchorConnection::HandleCCPRxReport (this=0x7fffdc01be90, rxBytes=0x7fffd004d7fb "1{\212\211D\021\006\061+\b\250\256i\227#ԺF(ú\002\005\003o\200#",
length=88) at LE/Network/rtls_anchor_conn.cpp:936
rxCCP = {rxTime = 4.3416058279497198, seqNum = 123 '{', anc = 0x7fffdc016320}
prevSeqNum = 122 'z'
master = 0x7fffdc0101a0
cs = 0x7fffdc016450
masterID = 588618078431250826
logNum = 45794088
pCsMsg = 0x7fffe57f9500
ccpRx = 277418192552
ccpRxTime = 4.3416058279497198
txTime = "0000000000\000\334\377\177\000\000\177\236", <incomplete sequence \345>
temp = "\000\000\000\000"
diagMsg2 = "0F000005036F8040001000000412C8A607120000086000BC07390AD806130000040000FC0114000005F9FF0700731500000EA8AE699740D4BA740800EC69974025000010A604C3FB4C07A3F7520743FE260538072E100002EF022700280491FE1F6D2E100"...
csmsg = {type = 49 '1', seqNum = 123 '{', masterID = "\212\211D\021\006\061+\b", csRxTime = "\250\256i\227#", {firstPath16 = 47828, firstPath = "Ժ"},
extLen = 70 'F', {
ext = "(ú\002\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021", {{logNum32 = 45794088, logNum = "(ú\002"},
diagnostics = "\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021"}}}
FP = 747
rxTime = "409769AEA8\000\345\377\177\000\000Н", <incomplete sequence \345>
I was nearly mad, any suggestion appreciated
Code that receive data over socket is as follows:
#define FRAME_HEADER_LEN (6)
#define FRAME_DATA_IDX (3)
virtual void Run()
{
unsigned int length = 0;
std::string rxBytes;
bool msgProcess;
uint8_t fcode;
unsigned int flen = 0;
while (shutdown_select_anc(socket) != -1)
{
int count = socket->ReceiveData();
if (count <= 0) // Something failed. Socket is probably closed.
{
break;
}
length += count;
rxBytes.append(socket->buf_, count);
/*
* the data coming from the anchor is framed:
*<STX><LENlsb><LENmsb><DATA:<FC><XX>.....><CRClsb><CRCmsb><ETX>
* STX = 0x2
* LEN is the length of data message(16 bits)
* CRC is the 16 - bit CRC of the data bytes
* ETX = 0x3
* FC = is the function code (API code)
*/
if (length <= FRAME_HEADER_LEN) //minimum length is 7 bytes (header + 1 byte function code)
{
continue;
}
do {
msgProcess = false;
crc_err_t pckt_crc = CRC_ERROR;
//search through the received data to find the start of frame
while (length > FRAME_HEADER_LEN)
{
if ((rxBytes.c_str())[0] == 0x2) //this is the start - check if length and end match
{
uint8_t hi = (rxBytes.c_str())[2];
uint8_t lo = (rxBytes.c_str())[1];
flen = lo + ((uint16_t)hi << 8);
if ((flen + FRAME_HEADER_LEN) > length) //we don't have all the frame yet
{
break;
}
if ((rxBytes.c_str())[flen + 5] == 0x3) //end of frame present
{
//received whole frame: check frame checksum here
pckt_crc = check_crc16((uint8_t *)&(rxBytes.c_str())[3], (flen + 2));
break;
}
else //no end of frame in the expected place - start byte was not real start
{
rxBytes.erase(0, 1);
length -= 1;
}
}
else //remove the byte and check if next is a start of frame
{
rxBytes.erase(0, 1);
length -= 1;
}
}
//check if we have a frame
if (((flen + FRAME_HEADER_LEN) > length) || (length <= FRAME_HEADER_LEN))
{
break;
}
if (pckt_crc != CRC_OKAY)
{
//frame packet fully received but it's CRC bad
DBG_PRINTF(DBG_DEFAULT, "ACHTUNG ACHTUNG : incompatible software without CRC or network CRC error\n");
//let incompatible software proceed at the moment
}
fcode = (rxBytes.c_str())[FRAME_DATA_IDX]; //get function code
typename std::map<uint8_t, std::pair<size_t, handler> >::iterator it = handlers.find(fcode);
if (it != handlers.end()) //we have found a handler for this function code
{
if (flen >= it->second.first)
{
handler f = it->second.second;
size_t n = (static_cast<Child*>(this)->*f)(&((rxBytes.c_str())[FRAME_DATA_IDX]), flen );
if (n > 0)
{
msgProcess = true;
rxBytes.erase(0, n + FRAME_HEADER_LEN);
length -= (unsigned int)(n + FRAME_HEADER_LEN);
}
else
{
//Unexpected Message
rxBytes.clear();
length = 0;
}
}
}
else
{
rxBytes.clear();
length = 0;
}
} while((length > 0) && msgProcess);
}
socket->Close();
}
In the push_back case you have
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
Suggests that you have an memory corruption elsewhere, most likely shortly before calling HandleCCPRxReport.
I wrote a small app which was compiled on a Raspberry Pi2. The program used program option from boost. The Pi died, so I want to run the the app on a new Pi 3. The compiling/linking works without problems. Starting the application result in a segmentation fault.
Some parts of the code:
v_AppName = boost::filesystem::basename(argv[0]);
po::options_description desc("Opties");
ProgramOptions(desc);
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
....
Program options function (the part which causes the problem):
void Client::ProgramOptions(boost::program_options::options_description & l_Desc)
{
l_Desc.add_options()
("help,h", "Show help")
("view,v", "View something")
("TEST", po::value<int>(), "TEST");
}
The last line with po::value() in it causes the crash. If i remove this line the program runs.
Stacktrace:
#0 0x76f17f24 in
boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, bool) const () from /usr/lib/arm-linux-gnueabihf/libboost_program_options.so.1.55.0
No symbol table info available.
#1 0x76f13220 in boost::program_options::store(boost::program_options::basic_parsed_options<char> const&, boost::program_options::variables_map&, bool) ()
from /usr/lib/arm-linux-gnueabihf/libboost_program_options.so.1.55.0
No symbol table info available.
#2 0x0003cae0 in warmte::Client::Client (this=0x7efff618, argc=1, argv=0x7efff794) at src/client.cpp:38
timeout = {<boost::date_time::base_time<boost::posix_time::ptime, boost::date_time::counted_time_system<boost::date_time::counted_time_rep<boost::posix_time::millisec_posix_time_system_config> > >> = {<boost::operators_impl::less_than_comparable<boost::posix_time::ptime, boost::operators_impl::equality_comparable<boost::posix_time::ptime, boost::posix_time::ptime, boost::operators_impl::operators_detail::empty_base<boost::posix_time::ptime>, boost::operators_impl::operators_detail::false_t>, boost::operators_impl::operators_detail::empty_base<boost::posix_time::ptime>, boost::operators_impl::operators_detail::true_t>> = {<boost::operators_impl::less_than_comparable1<boost::posix_time::ptime, boost::operators_impl::equality_comparable<boost::posix_time::ptime, boost::posix_time::ptime, boost::operators_impl::operators_detail::empty_base<boost::posix_time::ptime>, boost::operators_impl::operators_detail::false_t> >> = {<boost::operators_impl::equality_comparable<boost::posix_time::ptime, boost::posix_time::ptime, boost::operators_impl::operators_detail::empty_base<boost::posix_time::ptime>, boost::operators_impl::operators_detail::false_t>> = {<boost::operators_impl::equality_comparable1<boost::posix_time::ptime, boost::operators_impl::operators_detail::empty_base<boost::posix_time::ptime> >> = {<boost::operators_impl::operators_detail::empty_base<boost::posix_time::ptime>> = {<No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, time_ = {time_count_ = {
value_ = 8569444509916594175}}}, <No data fields>}
desc = {static m_default_line_length = 80, m_caption = "Opties", m_line_length = 80, m_min_description_length = 40,
m_options = std::vector of length 3, capacity 4 = {{px = 0x6d168, pn = {pi_ = 0x6d980}}, {px = 0x6d188, pn = {pi_ = 0x6f588}}, {px = 0x6f628,
pn = {pi_ = 0x6f690}}}, belong_to_group = std::vector<bool> of length 3, capacity 32 = {0, 0, 0},
groups = std::vector of length 0, capacity 0}
vm = <incomplete type>
#3 0x0003c92c in main (argc=1, argv=0x7efff794) at src/client.cpp:17
client = {_vptr.Client = 0x57418 <vtable for warmte::Client+8>, vp_Shm = 0x0, vp_Region = 0x0, v_AppName = "warmteclient", l_Index = 0,
l_Result = 1}
Ok, I linked with the wrong libraries....
The installed boost libraries on a Raspberry will end up in /usr/local/lib
So I added -L/usr/local/lib/ to the linker and changed extend LD_LIBRARY_PATH with /usr/local/lib/. It still remains unclear why this path is not added by default
Simple application causes segfault when I try to connect to the same database twice. It works fine with local database but crashes on second call to open() with any remote tunnel. What could be the cause? Am I doing something I should not be doing?
Obviously this is made up example but in reality I'm trying to manage db connections for a bigger app and manager does similar open/close cycle when requested.
QT version is 5.7.0. Compiled from sources to get better stack trace but not sure if it helped.
Remote MySQL is 5.6.27 (Amazon RDS actually), local is 5.7.17.
It's not eactly happening because I use tunnels. I can create a tunnel to my local database and the app works fine, no crashes.
If I tunnel local database to remote machine and then tunnel back from it to local, app still works. So it's not the latency either.
Code:
#include <QCoreApplication>
#include <QSqlDatabase>
void initDb(QSqlDatabase db) {
QString connectionHost = "127.0.0.1";
int port = 3311; // local tunnel
QString user = "mydbuser";
QString password = "mydbpassword";
QString database = "mydbname";
db.setHostName(connectionHost);
db.setPort(port);
db.setUserName(user);
db.setPassword(password);
db.setDatabaseName(database);
}
int main(int argc, char *argv[]) {
QString name1 = "db1", name2 = "db2";
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", name1);
initDb(db);
db.open();
db.close();
}
QSqlDatabase::removeDatabase(name1);
{
QSqlDatabase db1 = QSqlDatabase::addDatabase("QMYSQL", name2);
initDb(db1);
db1.open();
db1.close();
}
QSqlDatabase::removeDatabase(name2);
return 0;
}
Trace:
Thread 1 (Thread 0x7f7603ee3740 (LWP 3505)):
#0 __GI___pthread_mutex_lock (mutex=0x20) at ../nptl/pthread_mutex_lock.c:67
__PRETTY_FUNCTION__ = "__pthread_mutex_lock"
type = <optimized out>
id = <optimized out>
#1 0x00007f75ff228d79 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#2 0x00007f75ff1ff660 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#3 0x00007f75ff1d65e5 in mysql_real_connect () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#4 0x00007f7603f06a54 in QMYSQLDriver::open (this=0xbd4c90, db=..., user=..., password=..., host=..., port=3311, connOpts=...) at ../../../sql/drivers/mysql/qsql_mysql.cpp:1393
d = 0xbd5ea0
optionFlags = 65536
opts = {<QList<QString>> = {<QListSpecialMethods<QString>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x7f7603b0ffb0 <QListData::shared_null>}, d = 0x7f7603b0ffb0 <QListData::shared_null>}}, <No data fields>}
unixSocket = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCert = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCA = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslKey = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCAPath = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCipher = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
reconnect = 0 '\000'
connectTimeout = 0
readTimeout = 0
writeTimeout = 0
__PRETTY_FUNCTION__ = "virtual bool QMYSQLDriver::open(const QString&, const QString&, const QString&, const QString&, int, const QString&)"
mysql = 0x7ffe4d0aee80
#5 0x00007f7603f2d4b9 in QSqlDatabase::open (this=0x7ffe4d0aef70) at kernel/qsqldatabase.cpp:835
No locals.
#6 0x00000000004010d0 in main (argc=1, argv=0x7ffe4d0af098) at ../main.cpp:31
db1 = {static defaultConnection = 0x7f7603f52bf5 "qt_sql_default_connection", d = 0xbbdee0}
name1 = {static null = {<No data fields>}, d = 0xbbde50}
name2 = {static null = {<No data fields>}, d = 0xbbde80}
For the last week, I've not been able to open files in Xcode. I'm looking to learn why it isn't working, and how to fix it.
I've posted two questions in stack overflow here and here, and received good advice, but no solution.
Additionally, I have another program here which opens files just fine with no issues... I have no idea why one is opening files, and the other isn't. (Reminder, NONE of my recent programs are opening files.)
{Update: checking above program before this post, NOW it fails, saying the files don't exist... This program was running yesterday and I made no changes to it. I promise it was working... So why am I having file issues suddenly?}
Just to be sure, I've:
Gone to Build Phases >> Copy Files >> Add File, adding both files to Absolute Path
Checked the spelling of the files and my code
Here is a simple program that should open a text file, then print the contents, which are "testing 1 2 3" - except it doesn't:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
fstream inFile;
string words;
inFile.open("test.txt");
if (!inFile) {
cout << "Failure." << endl;
exit(1);
}
getline(inFile, words);
cout << words << endl;
return 0;
}
This program fails every time (as do my others).
Here is my output:
Failure.
Program ended with exit code: 1
Setting a breakpoint at the statement inFile.open("test.txt");, I get:
Printing description of inFile:
(std::__1::fstream) inFile = {
std::__1::basic_iostream<char, std::__1::char_traits<char> > = {
std::__1::basic_istream<char, std::__1::char_traits<char> > = {
std::__1::basic_ios<char, std::__1::char_traits<char> > = {
std::__1::ios_base = {
__fmtflags_ = 4098
__precision_ = 6
__width_ = 0
__rdstate_ = 0
__exceptions_ = 0
__rdbuf_ = 0x00007fff5fbff4f8
__loc_ = 0x00007fff7b718c30
__fn_ = 0x0000000000000000
__index_ = 0x0000000000000000
__event_size_ = 0
__event_cap_ = 0
__iarray_ = 0x0000000000000000
__iarray_size_ = 0
__iarray_cap_ = 0
__parray_ = 0x0000000000000000
__parray_size_ = 0
__parray_cap_ = 0
}
__tie_ = 0x0000000000000000
__fill_ = -1
}
__gc_ = 0
}
std::__1::basic_ostream<char, std::__1::char_traits<char> > = {
std::__1::basic_ios<char, std::__1::char_traits<char> > = {
std::__1::ios_base = {
__fmtflags_ = 4098
__precision_ = 6
__width_ = 0
__rdstate_ = 0
__exceptions_ = 0
__rdbuf_ = 0x00007fff5fbff4f8
__loc_ = 0x00007fff7b718c30
__fn_ = 0x0000000000000000
__index_ = 0x0000000000000000
__event_size_ = 0
__event_cap_ = 0
__iarray_ = 0x0000000000000000
__iarray_size_ = 0
__iarray_cap_ = 0
__parray_ = 0x0000000000000000
__parray_size_ = 0
__parray_cap_ = 0
}
__tie_ = 0x0000000000000000
__fill_ = -1
}
}
}
__sb_ = {
std::__1::basic_streambuf<char, std::__1::char_traits<char> > = {
__loc_ = (__locale_ = 0x00007fff7b718c30)
__binp_ = 0x0000000000000000
__ninp_ = 0x0000000000000000
__einp_ = 0x0000000000000000
__bout_ = 0x0000000000000000
__nout_ = 0x0000000000000000
__eout_ = 0x0000000000000000
}
__extbuf_ = 0x0000000102001000 ""
__extbufnext_ = 0x0000000000000000
__extbufend_ = 0x0000000000000000
__extbuf_min_ = ""
__ebs_ = 4096
__intbuf_ = 0x0000000000000000
__ibs_ = 0
__file_ = 0x0000000000000000
__cv_ = 0x00007fff7b718a40
__st_ = (__mbstate8 = "", _mbstateL = 0)
__st_last_ = (__mbstate8 = "", _mbstateL = 0)
__om_ = 0
__cm_ = 0
__owns_eb_ = true
__owns_ib_ = false
__always_noconv_ = true
}
}
(lldb)
And setting a breakpoint at if(!inFile) ... I get (looks that exact same to me):
Printing description of inFile:
(std::__1::fstream) inFile = {
std::__1::basic_iostream<char, std::__1::char_traits<char> > = {
std::__1::basic_istream<char, std::__1::char_traits<char> > = {
std::__1::basic_ios<char, std::__1::char_traits<char> > = {
std::__1::ios_base = {
__fmtflags_ = 4098
__precision_ = 6
__width_ = 0
__rdstate_ = 4
__exceptions_ = 0
__rdbuf_ = 0x00007fff5fbff4f8
__loc_ = 0x00007fff7b718c30
__fn_ = 0x0000000000000000
__index_ = 0x0000000000000000
__event_size_ = 0
__event_cap_ = 0
__iarray_ = 0x0000000000000000
__iarray_size_ = 0
__iarray_cap_ = 0
__parray_ = 0x0000000000000000
__parray_size_ = 0
__parray_cap_ = 0
}
__tie_ = 0x0000000000000000
__fill_ = -1
}
__gc_ = 0
}
std::__1::basic_ostream<char, std::__1::char_traits<char> > = {
std::__1::basic_ios<char, std::__1::char_traits<char> > = {
std::__1::ios_base = {
__fmtflags_ = 4098
__precision_ = 6
__width_ = 0
__rdstate_ = 4
__exceptions_ = 0
__rdbuf_ = 0x00007fff5fbff4f8
__loc_ = 0x00007fff7b718c30
__fn_ = 0x0000000000000000
__index_ = 0x0000000000000000
__event_size_ = 0
__event_cap_ = 0
__iarray_ = 0x0000000000000000
__iarray_size_ = 0
__iarray_cap_ = 0
__parray_ = 0x0000000000000000
__parray_size_ = 0
__parray_cap_ = 0
}
__tie_ = 0x0000000000000000
__fill_ = -1
}
}
}
__sb_ = {
std::__1::basic_streambuf<char, std::__1::char_traits<char> > = {
__loc_ = (__locale_ = 0x00007fff7b718c30)
__binp_ = 0x0000000000000000
__ninp_ = 0x0000000000000000
__einp_ = 0x0000000000000000
__bout_ = 0x0000000000000000
__nout_ = 0x0000000000000000
__eout_ = 0x0000000000000000
}
__extbuf_ = 0x0000000102001000 ""
__extbufnext_ = 0x0000000000000000
__extbufend_ = 0x0000000000000000
__extbuf_min_ = ""
__ebs_ = 4096
__intbuf_ = 0x0000000000000000
__ibs_ = 0
__file_ = 0x0000000000000000
__cv_ = 0x00007fff7b718a40
__st_ = (__mbstate8 = "", _mbstateL = 0)
__st_last_ = (__mbstate8 = "", _mbstateL = 0)
__om_ = 0
__cm_ = 0
__owns_eb_ = true
__owns_ib_ = false
__always_noconv_ = true
}
}
(lldb)
Short answer is, my project was broken because it was trying to run a project in a path where a previous project already existed. Once I deleted both completely, and started anew, my program worked just fine.
While I made no changes to the original project, I started a new project in the same directory, which then caused all my issues.