gdb crashes when printing value of atomic enum - c++

When compiling the following program with g++ [gcc version 8.3.1 20190223 (Red Hat 8.3.1-2) (GCC)], debugging with gdb [GNU gdb (GDB) Fedora 8.2-6.fc29] causes a segmentation fault.
#include <atomic>
enum class foo {ONE, TWO, THREE, FOUR, FIVE, SIX};
int main(int argc, char **argv)
{
std::atomic<foo> x = foo::FOUR;
std::atomic<int> y = int(foo::FOUR);
return 0;
}
compiled with g++ -Wall -Wextra -Wpedantic -std=gnu++2a -O0 -g3, the gdb session has the following behavior:
(gdb) break main
(gdb) r
(gdb) p y
$1 = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = 3}, static is_always_lock_free = true}
(gdb) p x
$2 = {static _S_min_alignment = 4, static _S_alignment = 4, _M_i = foo::FOUR,
Segmentation fault (core dumped)
As can be seen, the value of atomic<int> y can be inspected, but attempting to inspect atomic<foo> x causes a segfault.
Am I abusing c++, or is this a bug in gdb?

is this a bug in gdb?
Yes, it is, gdb crashes with the following stack trace:
(gdb) bt
#0 0x000055dd368292ac in value_entirely_covered_by_range_vector (value=0x0, ranges=<error reading variable: Cannot access memory at address 0xa0>) at ../../gdb/value.c:417
#1 0x000055dd3666e854 in cp_print_static_field (options=0x7ffd14597de0, recurse=1, stream=0x55dd384ea5c0, val=0x0, type=0x55dd385531f0) at ../../gdb/cp-valprint.c:631
#2 cp_print_value_fields (type=<optimized out>, real_type=<optimized out>, offset=0, address=140737488343980, stream=0x55dd384ea5c0, recurse=0, val=0x55dd38903ed0, options=0x7ffd14597de0, dont_print_vb=0x0, dont_print_statmem=0) at ../../gdb/cp-valprint.c:332
#3 0x000055dd3666f02c in cp_print_value_fields_rtti (type=<optimized out>, type#entry=0x55dd38662a30, valaddr=valaddr#entry=0x55dd38903f90 "\003", offset=offset#entry=0, address=address#entry=140737488343980, stream=stream#entry=0x55dd384ea5c0, recurse=<optimized out>, val=0x55dd38903ed0, options=0x7ffd14597de0, dont_print_vb=0x0, dont_print_statmem=0) at ../../gdb/cp-valprint.c:449
#4 0x000055dd366492e5 in c_val_print_struct (type=0x55dd38662a30, valaddr=0x55dd38903f90 "\003", embedded_offset=0, address=140737488343980, stream=0x55dd384ea5c0, recurse=<optimized out>, original_value=0x55dd38903ed0, options=0x7ffd14597de0) at ../../gdb/c-valprint.c:411
#5 0x000055dd36649800 in c_val_print (type=<optimized out>, embedded_offset=0, address=140737488343980, stream=0x55dd384ea5c0, recurse=0, original_value=0x55dd38903ed0, options=0x7ffd14597de0) at ../../gdb/c-valprint.c:532
#6 0x000055dd36820c50 in val_print (type=type#entry=0x55dd38662a30, embedded_offset=0, address=address#entry=140737488343980, stream=stream#entry=0x55dd384ea5c0, recurse=recurse#entry=0, val=val#entry=0x55dd38903ed0, options=<optimized out>, language=0x55dd36d4f2c0 <cplus_language_defn>) at ../../gdb/valprint.c:1061
#7 0x000055dd3664a00d in c_value_print (val=0x55dd38903ed0, stream=0x55dd384ea5c0, options=<optimized out>) at ../../gdb/c-valprint.c:723
#8 0x000055dd36758da1 in print_value (val=val#entry=0x55dd38903ed0, fmtp=fmtp#entry=0x7ffd14597ff0) at ../../gdb/printcmd.c:1173
#9 0x000055dd36758e65 in print_command_1 (exp=<optimized out>, voidprint=1) at ../../gdb/printcmd.c:1205
#10 0x000055dd365504ba in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>) at ../../gdb/cli/cli-decode.c:1857
#11 0x000055dd367f44a1 in execute_command (p=<optimized out>, p#entry=0x55dd37bf19f0 "p x", from_tty=1) at ../../gdb/top.c:630
#12 0x000055dd366cf884 in command_handler (command=0x55dd37bf19f0 "p x") at ../../gdb/event-top.c:586
#13 0x000055dd366d074e in command_line_handler (rl=<optimized out>) at ../../gdb/event-top.c:777
#14 0x000055dd366cef90 in gdb_rl_callback_handler (rl=0x55dd38cba750 "p x") at ../../gdb/event-top.c:214
#15 0x00007f3231ae1ede in rl_callback_read_char () from /lib64/libreadline.so.7
#16 0x000055dd366ceea6 in gdb_rl_callback_read_char_wrapper_noexcept () at ../../gdb/event-top.c:176
#17 0x000055dd366cef2d in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>) at ../../gdb/event-top.c:192
#18 0x000055dd366cf458 in stdin_event_handler (error=<optimized out>, client_data=0x55dd37be9990) at ../../gdb/event-top.c:514
#19 0x000055dd366ce29d in gdb_wait_for_event (block=<optimized out>) at ../../gdb/event-loop.c:859
#20 gdb_wait_for_event (block=<optimized out>) at ../../gdb/event-loop.c:746
#21 0x000055dd366ce448 in gdb_do_one_event () at ../../gdb/event-loop.c:347
#22 0x000055dd366ce55e in gdb_do_one_event () at ../../gdb/event-loop.c:371
#23 start_event_loop () at ../../gdb/event-loop.c:371
#24 0x000055dd3673342b in captured_command_loop () at ../../gdb/main.c:331
#25 0x000055dd36734afd in captured_main (data=0x7ffd14598470) at ../../gdb/main.c:1267
#26 gdb_main (args=0x7ffd14598470) at ../../gdb/main.c:1284
#27 0x000055dd3648489f in main (argc=<optimized out>, argv=<optimized out>) at ../../gdb/gdb.c:40
(gdb)
There are similar stack traces in already reported bug https://sourceware.org/bugzilla/show_bug.cgi?id=20020. Also there is already a patch which fixes this crash, see https://sourceware.org/bugzilla/show_bug.cgi?id=20020#c16.

Related

Crash when sending data using async_write_some

My server has been running for more than 20 hours for a long time. During this period, I stress test the server uninterruptedly. Sometimes it crashes, sometimes it does not crash. I am using Asio only Asio Only Source Code to handle my network class.
void AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>& packet)
{
sendding_.store(true);
auto self = shared_from_this();
socket_.async_write_some(asio::buffer(packet->peek(), packet->readableBytes()),
[self, packet](const std::error_code& err, std::size_t writen)
{
self->AsyncWriteSomeCallback(err,packet,writen);
});
}
void AsioChannel::AsyncWriteSomeCallback(const std::error_code& error, const std::shared_ptr<Buffer>& packet, std::size_t writen)
{
if (error)
{
return;
}
if (writen < packet->readableBytes())
{
packet->retrieve(writen);
AsyncSendData(packet);
}
else
{
if(!waitwriteq_.empty())
{
auto next = waitwriteq_.front();
waitwriteq_.pop();
AsyncSendData(next);
}
else
{
sendding_.store(false);
}
}
}
The crash stack is as follows
#0 0x00007f172a8255f7 in raise () from /lib64/libc.so.6
#1 0x00007f172a826e28 in abort () from /lib64/libc.so.6
#2 0x00007f172a865317 in __libc_message () from /lib64/libc.so.6
#3 0x00007f172a86cfe1 in _int_free () from /lib64/libc.so.6
#4 0x00007f172b92b49d in allocate<asio::detail::thread_info_base::default_tag> (size=168, this_thread=<optimized out>) at /opt/env/include/c++/10.2.0/ext/atomicity.h:97
#5 allocate (size=168, this_thread=<optimized out>) at asio/detail/thread_info_base.hpp:73
#6 asio_handler_allocate (size=168) at asio/impl/handler_alloc_hook.ipp:34
#7 allocate<net::AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>&)::<lambda(const std::error_code&, std::size_t)> > (h=..., s=168)
at asio/detail/handler_alloc_helpers.hpp:70
#8 allocate (n=1, this=<synthetic pointer>) at asio/detail/handler_alloc_helpers.hpp:127
#9 allocate (handler=...) at asio/detail/reactive_socket_send_op.hpp:103
#10 async_send<asio::const_buffers_1, net::AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>&)::<lambda(const std::error_code&, std::size_t)>, asio::execution::any_executor<asio::execution::context_as_t<asio::execution_context&>, asio::execution::detail::blocking::never_t<0>, asio::execution::prefer_only<asio::execution::detail::blocking::possibly_t<0> >, asio::execution::prefer_only<asio::execution::detail::outstanding_work::tracked_t<0> >, asio::execution::prefer_only<asio::execution::detail::outstanding_work::untracked_t<0> >, asio::execution::prefer_only<asio::execution::detail::relationship::fork_t<0> >, asio::execution::prefer_only<asio::execution::detail::relationship::continuation_t<0> > > > (io_ex=..., handler=..., flags=0,
buffers=..., impl=..., this=0x7f17080009f8) at asio/detail/reactive_socket_service_base.hpp:281
#11 operator()<net::AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>&)::<lambda(const std::error_code&, std::size_t)>, asio::const_buffers_1> (flags=0, buffers=...,
handler=<unknown type in /libgamesh.net.so, CU 0x0, DIE 0x6e7c8>, this=<optimized out>)
at asio/basic_stream_socket.hpp:1005
#12 initiate<asio::basic_stream_socket<asio::ip::tcp>::initiate_async_send, net::AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>&)::<lambda(const std::error_code&, std::size_t)>, const asio::const_buffers_1&, int> (token=<unknown type in /libgamesh.net.so, CU 0x0, DIE 0x6e78e>,
initiation=<optimized out>) at asio/async_result.hpp:151
#13 async_initiate<net::AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>&)::<lambda(const std::error_code&, std::size_t)>, void(std::error_code, long unsigned int), asio::basic_stream_socket<asio::ip::tcp>::initiate_async_send, const asio::const_buffers_1&, int> (token=..., initiation=<optimized out>)
at asio/async_result.hpp:364
#14 async_write_some<asio::const_buffers_1, net::AsioChannel::AsyncSendData(const std::shared_ptr<Buffer>&)::<lambda(const std::error_code&, std::size_t)> > (
handler=<unknown type in /libgamesh.net.so, CU 0x0, DIE 0x6e6e1>, buffers=..., this=0x7f1708143480)
at asio/basic_stream_socket.hpp:855
#15 net::AsioChannel::AsyncSendData (this=0x7f1708143460, packet=...) at net/asio_channel.cpp:326
#16 0x00007f172b92b964 in net::AsioChannel::SendPacket (this=<optimized out>, packet=..., size=<optimized out>)
at net/asio_channel.cpp:284
#17 0x00007f172b93cb1e in net::AsioServerHandler::SendPacket (this=<optimized out>, pPacket=..., size=<optimized out>) at /opt/env/include/c++/10.2.0/bits/shared_ptr_base.h:1324
#18 0x00007f172b946831 in operator() (__closure=<optimized out>) at /opt/env/include/c++/10.2.0/bits/shared_ptr_base.h:1324
#19 __invoke_impl<void, net::Asio_SendPacket(uint32_t, char const*, uint32_t)::<lambda()>&> (__f=...) at /opt/env/include/c++/10.2.0/bits/invoke.h:60
#20 __invoke_r<void, net::Asio_SendPacket(uint32_t, char const*, uint32_t)::<lambda()>&> (__fn=...) at /opt/env/include/c++/10.2.0/bits/invoke.h:110
#21 std::_Function_handler<void(), net::Asio_SendPacket(uint32_t, char const*, uint32_t)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...)
at /opt/env/include/c++/10.2.0/bits/std_function.h:291
#22 0x00007f172c42ee26 in std::function<void ()>::operator()() const (this=<optimized out>) at /opt/env/include/c++/10.2.0/bits/std_function.h:248
#23 0x00007f172b93b0b4 in asio_handler_invoke<std::function<void()> > (function=...)
at asio/handler_invoke_hook.hpp:85
#24 invoke<std::function<void()>, std::function<void()> > (context=..., function=...)
at asio/detail/handler_invoke_helpers.hpp:54
#25 complete<std::function<void()> > (handler=..., function=..., this=<synthetic pointer>)
at asio/detail/handler_work.hpp:424
#26 asio::detail::completion_handler<std::function<void ()>, asio::io_context::basic_executor_type<std::allocator<void>, 0u> >::do_complete(void*, asio::detail::scheduler_operation*, std::error_code const&, unsigned long) (owner=0x5011470, base=0x7f15c7b2f4a0) at asio/detail/completion_handler.hpp:73
#27 0x00007f172b932d88 in complete (bytes_transferred=0, ec=..., owner=0x5011470, this=0x7f15c7b2f4a0)
at asio/detail/scheduler_operation.hpp:39
#28 asio::detail::scheduler::do_run_one (this=this#entry=0x5011470, lock=..., this_thread=..., ec=...)
at asio/detail/impl/scheduler.ipp:480
#29 0x00007f172b934336 in asio::detail::scheduler::run (this=0x5011470, ec=...)
at asio/detail/impl/scheduler.ipp:203
---Type <return> to continue, or q <return> to quit---
#30 0x00007f172b9394c6 in run (this=0x50113c8) at asio/impl/io_context.ipp:62
#31 net::AsioEventLoop::Run (this=0x50113c0) at net/asio_event_loop.cpp:30
#32 0x00007f172b942ae1 in net::EventLoopThread::Run(std::function<int ()> const&, std::function<int ()> const&) (this=0x4fe9ec0, pre=..., post=...)
at /opt/env/include/c++/10.2.0/bits/unique_ptr.h:421
#33 0x00007f172b942e6f in __invoke_impl<void, void (net::EventLoopThread::*&)(const std::function<int()>&, const std::function<int()>&), net::EventLoopThread*&, std::function<int()>&, std::function<int()>&> (__t=<optimized out>, __f=<optimized out>) at /opt/env/include/c++/10.2.0/bits/invoke.h:89
#34 __invoke<void (net::EventLoopThread::*&)(const std::function<int()>&, const std::function<int()>&), net::EventLoopThread*&, std::function<int()>&, std::function<int()>&> (
__fn=<optimized out>) at /opt/env/include/c++/10.2.0/bits/invoke.h:95
#35 __call<void, 0, 1, 2> (__args=<optimized out>, this=<optimized out>) at /opt/env/include/c++/10.2.0/functional:416
#36 operator()<> (this=<optimized out>) at /opt/env/include/c++/10.2.0/functional:499
#37 __invoke_impl<void, std::_Bind<void (net::EventLoopThread::*(net::EventLoopThread*, std::function<int()>, std::function<int()>))(const std::function<int()>&, const std::function<int()>&)> > (__f=<optimized out>) at /opt/env/include/c++/10.2.0/bits/invoke.h:60
#38 __invoke<std::_Bind<void (net::EventLoopThread::*(net::EventLoopThread*, std::function<int()>, std::function<int()>))(const std::function<int()>&, const std::function<int()>&)> > (__fn=<optimized out>) at /opt/env/include/c++/10.2.0/bits/invoke.h:95
#39 _M_invoke<0> (this=<optimized out>) at /opt/env/include/c++/10.2.0/thread:264
#40 operator() (this=<optimized out>) at /opt/env/include/c++/10.2.0/thread:271
#41 std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind<void (net::EventLoopThread::*(net::EventLoopThread*, std::function<int ()>, std::function<int ()>))(std::function<int ()> const&, std::function<int ()> const&)> > > >::_M_run() (this=<optimized out>) at /opt/env/include/c++/10.2.0/thread:215
#42 0x00007f172aca2f70 in execute_native_thread_routine () at ../../../../../libstdc++-v3/src/c++11/thread.cc:80
#43 0x00007f172c1c8dc5 in start_thread () from /lib64/libpthread.so.0
#44 0x00007f172a8e61cd in clone () from /lib64/libc.so.6
(gdb)
Why is the response causing a crash?
Not using Boost
Compiled with g++ 10.2.0 in C++17 mode
Running libstdc++ of GCC10 for C++17 feature support
Running on Red Hat Enterprise Linux Server release 7.2 (Maipo)
Everything compiled with -O2

Running custom protoc-plugin on linux causes

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.

How to get more information about an exception using GDB?

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()

Segmentation Fault with SOCI rowset

I get a segmentation fault when using SOCI rowset. Here is a simplified version of my code:
query << "select * from mytable";
soci::rowset<MyObject> rs = (sql.prepare << query.str());
Here is an excerpt from gdb:
Thread 3 "MyProgram" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffef14c700 (LWP 15369)]
0x00007ffff6b73428 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) bt
#0 0x00007ffff6b73428 in __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff6b7502a in __GI_abort () at abort.c:89
#2 0x00007ffff6bc0503 in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, str=<optimized out>, action=<optimized out>) at malloc.c:5010
#3 _int_malloc (av=av#entry=0x7ffff6f02b20 <main_arena>, bytes=bytes#entry=33) at malloc.c:3386
#4 0x00007ffff6bc0e59 in malloc_check (sz=32, caller=<optimized out>) at hooks.c:295
#5 0x0000000001307668 in operator new(unsigned long) ()
#6 0x0000000001298b25 in soci::postgresql_statement_backend::make_into_type_backend() ()
#7 0x00000000012941b4 in soci::details::standard_into_type::define(soci::details::statement_impl&, int&) ()
#8 0x000000000128fd13 in soci::details::statement_impl::define_for_row() ()
#9 0x0000000001292be8 in soci::details::statement_impl::execute(bool) ()
#10 0x0000000000db420a in soci::statement::execute (this=0x3d261d0, withDataExchange=false) at /usr/include/soci/statement.h:210
#11 0x0000000001076d46 in soci::details::rowset_impl<MyObject>::rowset_impl (this=0xb027c80, prep=...) at /usr/include/soci/rowset.h:126
#12 0x0000000001072fb1 in soci::rowset<sim_mob::SinglePath>::rowset (this=0x7fffef14a890, prep=...) at /usr/include/soci/rowset.h:185

ACE crash in __GI_raise

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.