boost gzip_decompressor() Segmentation fault on free() - c++

im using gzip_decompressor() from the boost library but i'm getting a strange Segmentation fault on free().
stringstream gzMessage;
stringstream rawMessage;
gzMessage << (*iter)->message;
filtering_streambuf<input> gzFilter;
gzFilter.push(gzip_decompressor());
gzFilter.push(gzMessage);
boost::iostreams::copy(gzFilter, rawMessage);
message = rawMessage.str();
cout << "ungzipped: " << message << endl;
The line in question is boost::iostreams::copy(gzFilter, rawMessage);
if i comment this one out everything works fine.
the backtrace:
(gdb) bt
#0 0x00007ffff640fd29 in free () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x0000000000453f8c in boost::detail::sp_counted_impl_p<boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl>::dispose()
()
#2 0x0000000000427f49 in boost::detail::shared_count::~shared_count() ()
#3 0x00000000004598ae in boost::iostreams::stream_buffer<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >, std::char_traits<char>, std::allocator<char>, boost::iostreams::input>::~stream_buffer() ()
#4 0x0000000000459c39 in boost::iostreams::detail::chain_base<boost::iostreams::chain<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char> >, char, std::char_traits<char>, std::allocator<char>, boost::iostreams::input>::chain_impl::~chain_impl() ()
#5 0x0000000000459d12 in boost::detail::sp_counted_impl_p<boost::iostreams::detail::chain_base<boost::iostreams::chain<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char> >, char, std::char_traits<char>, std::allocator<char>, boost::iostreams::input>::chain_impl>::dispose() ()
#6 0x0000000000427f49 in boost::detail::shared_count::~shared_count() ()
any hints ?

Related

How to debug a sycl runtime compilation that fails with segmentation fault

The point of the question
I have a minimal program that segfaults during sycl runtime compilation. For the sake of detail i have precise reproduction details below. However, the point of this question is to understand how to debug this. It took me a long time to make the minimal example. I suspect if i could get the runtimes for dpcpp i could probably have cut this right down. When the runtime compiler fails, it should throw an exception. I want to know what steps i should take to discover why it is instead segfaulting, and if it is a compiler bug or a bug in my code.
Reproduction details below
starting with the code:
#include <CL/sycl/queue.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/context.hpp>
#include <CL/sycl.hpp>
#include <iostream>
namespace
{
auto is_sign_same(sycl::short3 idx1, sycl::short3 idx2)
{
return (idx1 < 0) == (idx2 < 0);
}
} // namespace
int main()
{
sycl::device device = sycl::device{sycl::gpu_selector{}};
std::cout
<< "\n\nRunning occupancy grid profile. The profile will have the following "
"properties:\n\n Device:\t"
<< device.get_info<sycl::info::device::name>() << "\n\n";
sycl::context context{device};
sycl::property_list properties{sycl::property::queue::enable_profiling()};
sycl::queue queue{device, properties};
auto event = queue.submit(
[](sycl::handler& cgh)
{
// 1. This must be captured or it does not crash. If i put this in the
// kernel, then it does not fail.
sycl::id<3> robot_index{0, 0, 0};
sycl::stream out(1024, 256, cgh);
cgh.parallel_for(
sycl::range<3>{4, 4, 4},
[out, robot_index](sycl::id<3> id)
{
sycl::short3 new_signed_idx{short(0)};
// 2. I cannot remove the subtract between the 2 sycl::short3 here.
// It will not fail.
sycl::short3 old_signed_idx =
sycl::short3{
(short)id.get(0), (short)id.get(1), (short)id.get(2)} -
sycl::short3{
(short)robot_index.get(0),
(short)robot_index.get(1),
(short)robot_index.get(2)};
// 3. I cannot replace this function call with the operation that
// the function performs inline here. It does not fail.
auto s_same = is_sign_same(new_signed_idx, old_signed_idx);
out << s_same;
}
);
}
);
return 0;
}
When compiled using:
/opt/intel/oneapi/compiler/2022.1.0/linux/bin/dpcpp -fclang-abi-compat=7 -fsycl --gcc-toolchain=/usr -sycl-std=2020 -fp-model=precise -Wall -Werror -fsycl -O2 -g -DNDEBUG -std=gnu++17 sgfaulting_file.cpp
will fail at runtime. The failure is a segfault. It is caused by something do do with building the kernel. If we run the output in GDB we get the following stack trace when it dies:
(gdb) where
#0 0x00007f49e3683b8c in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#1 0x00007f49e36b440c in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#2 0x00007f49e36b0dda in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#3 0x00007f49e36b430f in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#4 0x00007f49e36bac6a in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#5 0x00007f49e36b0bed in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#6 0x00007f49e36b430f in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#7 0x00007f49e36bac6a in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#8 0x00007f49e36bf027 in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#9 0x00007f49e36bf908 in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#10 0x00007f49e35ab7bc in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#11 0x00007f49e35abfba in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#12 0x00007f49e35ae90d in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#13 0x00007f49e36ec3d4 in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#14 0x00007f49e35b21fb in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#15 0x00007f49e36ced9a in ?? () from /usr/lib/x86_64-linux-gnu/libigc.so.1
#16 0x00007f49f487f1bb in ?? () from /usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so
#17 0x00007f49f43ef178 in ?? () from /usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so
#18 0x00007f49f4397b33 in ?? () from /usr/lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so
#19 0x00007f49f9327aa4 in cl::sycl::detail::ProgramManager::build(std::unique_ptr<_pi_program, _pi_result (*)(_pi_program*)>, std::shared_ptr<cl::sycl::detail::context_impl>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _pi_device* const&, std::map<std::pair<cl::sycl::detail::DeviceLibExt, _pi_device*>, _pi_program*, std::less<std::pair<cl::sycl::detail::DeviceLibExt, _pi_device*> >, std::allocator<std::pair<std::pair<cl::sycl::detail::DeviceLibExt, _pi_device*> const, _pi_program*> > >&, unsigned int) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#20 0x00007f49f9321336 in cl::sycl::detail::ProgramManager::getBuiltPIProgram(long, std::shared_ptr<cl::sycl::detail::context_impl> const&, std::shared_ptr<cl::sycl::detail::device_impl> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cl::sycl::detail::program_impl const*, bool) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#21 0x00007f49f932243c in cl::sycl::detail::ProgramManager::getOrCreateKernel(long, std::shared_ptr<cl::sycl::detail::context_impl> const&, std::shared_ptr<cl::sycl::detail::device_impl> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cl::sycl::detail::program_impl const*) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#22 0x00007f49f93630f1 in cl::sycl::detail::enqueueImpKernel(std::shared_ptr<cl::sycl::detail::queue_impl> const&, cl::sycl::detail::NDRDescT&, std::vector<cl::sycl::detail::ArgDesc, std::allocator<cl::sycl::detail::ArgDesc> >&, std::shared_ptr<cl::sycl::detail::kernel_bundle_impl> const&, std::shared_ptr<cl::sycl::detail::kernel_impl> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long const&, std::vector<_pi_event*, std::allocator<_pi_event*> >&, _pi_event**, std::function<void* (cl::sycl::detail::AccessorImplHost*)> const&) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#23 0x00007f49f9369f3b in cl::sycl::detail::ExecCGCommand::enqueueImp() ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#24 0x00007f49f93566c5 in cl::sycl::detail::Command::enqueue(cl::sycl::detail::EnqueueResultT&, cl::sycl::detail::BlockingT, std::vector<cl::sycl::detail::Command*, std::allocator<cl::sycl::detail::Command*> >&) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#25 0x00007f49f9373b7b in cl::sycl::detail::Scheduler::addCG(std::unique_ptr<cl::sycl::detail::CG, std::default_delete<cl::sycl::detail::CG> >, std::shared_ptr<cl::sycl::detail::queue_impl>) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#26 0x00007f49f93aef30 in cl::sycl::handler::finalize() ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#27 0x00007f49f93dc3ea in cl::sycl::detail::queue_impl::finalizeHandler(cl::sycl::handler&, cl::sycl::detail::CG::CGTYPE const&, cl::sycl::event&) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#28 0x00007f49f93dc13b in cl::sycl::detail::queue_impl::submit_impl(std::function<void (cl::sycl::handler&)> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, cl::sycl::detail::code_location const&, std::function<void (bool, bool, cl::sycl::event&)> const*) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#29 0x00007f49f93db744 in cl::sycl::detail::queue_impl::submit(std::function<void (cl::sycl::handler&)> const&, std::shared_ptr<cl::sycl::detail::queue_impl> const&, cl::sycl::detail::code_location const&, std:--Type <RET> for more, q to quit, c to continue without paging--
:function<void (bool, bool, cl::sycl::event&)> const*) ()
from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#30 0x00007f49f93db715 in cl::sycl::queue::submit_impl(std::function<void (cl::sycl::handler&)>, cl::sycl::detail::code_location const&) () from /opt/intel/oneapi/compiler/2022.1.0/linux/lib/libsycl.so.5
#31 0x00000000004026d8 in cl::sycl::queue::submit<main::{lambda(cl::sycl::handler&)#1}>(main::{lambda(cl::sycl::handler&)#1}, cl::sycl::detail::code_location const&) (this=0x7ffc5da1b200, CodeLoc=..., CGF=...)
at /opt/intel/oneapi/compiler/2022.1.0/linux/bin-llvm/../include/sycl/CL/sycl/queue.hpp:275
#32 main () at occupancy_grid_point_cloud_creation.cpp:31
The important part being stack position #19:
cl::sycl::detail::ProgramManager::build
The runtime compilation is occurring on the device (from sycl-ls):
[opencl:gpu:2] Intel(R) OpenCL HD Graphics, Intel(R) UHD Graphics [0x9bc4] 3.0 [22.28.23726.1]
if we run the same program but use a host or cpu selector, we do not fail to build and can run successfully. It also seems that if we change minimal details about the program, it also no longer segfaults. These small changes are detailed in the comments in the program.

opencv c++ corrupted double-linked list

I'm trying to get the fps from multiple cameras. This is the main:
int main(int argc, char* argv[])
{
//Load all cameras IP
map<string, string> camerasIp; //camera ID and Streaming URL
LoadConfig(&camerasIp);
//Get FPS of all cameras
map<string,string>::iterator it_cam;
while(true)
{
for(it_cam = camerasIp.begin(); it_cam != camerasIp.end(); ++it_cam)
{
GetCamFps(it_cam->second);
}
cout << "" << endl;
}
//Send FPS to server
...
return 0;
}
This is the GetCamFps method:
void GetCamFps(string url)
{
cout << "VideoCapture" << endl;
VideoCapture video(url);
cout << "Get frames" << endl;
double fps = video.get(CAP_PROP_FPS);
cout <<"Frames: " << fps << endl;
video.release();
}
And this is the exit:
VideoCapture
Get frames
Frames: 30
VideoCapture
corrupted double-linked list
Aborted (core dumped)
I tried adding a sleep to let some time between opening one url and another but didn't works. I checked the map and it's correct.
When I comment the two firsts cout in the method it works but after a while it fail again.
Output of gdb with backtrace:
Thread 1 "Fps_Monitoring" received signal SIGABRT, Aborted.
__GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007ffff51cc801 in __GI_abort () at abort.c:79
#2 0x00007ffff5215897 in __libc_message (action=action#entry=do_abort, fmt=fmt#entry=0x7ffff5342b9a "%s\n") at ../sysdeps/posix/libc_fatal.c:181
#3 0x00007ffff521c90a in malloc_printerr (str=str#entry=0x7ffff5340cba "corrupted double-linked list") at malloc.c:5350
#4 0x00007ffff521cac4 in malloc_consolidate (av=av#entry=0x7ffff5577c40 <main_arena>) at malloc.c:4456
#5 0x00007ffff52207d8 in _int_malloc (av=av#entry=0x7ffff5577c40 <main_arena>, bytes=bytes#entry=1600) at malloc.c:3703
#6 0x00007ffff52214eb in _int_memalign (av=0x7ffff5577c40 <main_arena>, alignment=64, bytes=<optimized out>) at malloc.c:4694
#7 0x00007ffff5226fba in _mid_memalign (address=<optimized out>, bytes=1496, alignment=<optimized out>) at malloc.c:3314
#8 __posix_memalign (memptr=0x7fffffffdad0, alignment=<optimized out>, size=1496) at malloc.c:5369
#9 0x00007ffff028e7e3 in av_malloc () from /usr/local/lib/libavutil.so.56
#10 0x00007ffff06b253b in avformat_alloc_context () from /usr/local/lib/libavformat.so.58
#11 0x00007ffff5f8b9a3 in CvCapture_FFMPEG::open(char const*) () from /usr/local/lib/libopencv_videoio.so.4.2
#12 0x00007ffff5f8e9ff in cv::cvCreateFileCapture_FFMPEG_proxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
from /usr/local/lib/libopencv_videoio.so.4.2
#13 0x00007ffff5f71566 in cv::StaticBackend::createCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const ()
from /usr/local/lib/libopencv_videoio.so.4.2
#14 0x00007ffff5f4cc17 in cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ()
from /usr/local/lib/libopencv_videoio.so.4.2
#15 0x00007ffff5f4f595 in cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) ()
from /usr/local/lib/libopencv_videoio.so.4.2
#16 0x000055555555f9b3 in GetCamFps(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) ()
#17 0x000055555555d5df in main ()
Any idea why the second videocapture doesn't work?
Thanks.

Segmentation fault in getting secret from vault while using libvault library in c++

I am trying to connect with vault using libvault library. but, i am getting segmentation fault like below
Trying ..*....
TCP_NODELAY set
Connected to vault..-...net (..*.) port 8200 (#0)
ALPN, offering http/1.1
successfully set certificate verify locations:
CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
Thread 5 "batch" received signal SIGSEGV, Segmentation fault.
Code i have written is below
Vault::Token rootToken{"*******"};
Vault::TokenStrategy tokenStrategy{rootToken};
Vault::HttpErrorCallback httpErrorCallback = [&](std::string err) {
std::cout << err << std::endl;
};
Vault::Host host{"vault.*****.***-**.***.***.net"};
Vault:: Port port{"8200"};
//Vault:: ConnectTimeout timeout{10000};
Vault::Config config = Vault::ConfigBuilder().withDebug(true).withTlsEnabled(true).withHost(host).withPort(port).build();
Vault::Client vaultClient{config, tokenStrategy, httpErrorCallback};
Vault::SecretMount mount{"/****/*****/*****"};
Vault::KeyValue kv{vaultClient,mount};
Vault::Path key{"**/***/***"};
std::cout<<"vault check initial<<std::endl;
auto response = kv.read(key);
if (response) {
std::cout<<"vault check"<<std::endl;
std::cout << response.value() << std::endl;
} else {
std::cout << "Unable to read secrets" << std::endl;
}
exception is during reading the kv.read(key)
Below is the stacktrace ...
(gdb) bt
#0 0x0000000000000009 in ?? ()
#1 0x00000000011687be in ossl_connect_step1 (conn=conn#entry=0x7fffe40288a0, sockindex=sockindex#entry=0)
at /3rdparty/curl/lib/vtls/openssl.c:2605
#2 0x000000000116acde in ossl_connect_common (conn=0x7fffe40288a0, sockindex=0, nonblocking=nonblocking#entry=true,
done=0x7ffff488e17d) at /3rdparty/curl/lib/vtls/openssl.c:3457
#3 0x000000000116aed2 in Curl_ossl_connect_nonblocking (conn=<optimized out>, sockindex=<optimized out>,
done=<optimized out>) at /3rdparty/curl/lib/vtls/openssl.c:3543
#4 0x0000000001141f4c in Curl_ssl_connect_nonblocking (conn=conn#entry=0x7fffe40288a0, sockindex=sockindex#entry=0,
done=done#entry=0x7ffff488e17d) at /3rdparty/curl/lib/vtls/vtls.c:275
#5 0x0000000001151cdb in https_connecting (conn=conn#entry=0x7fffe40288a0, done=done#entry=0x7ffff488e17d)
at /3rdparty/curl/lib/http.c:1507
#6 0x000000000115349e in Curl_http_connect (conn=0x7fffe40288a0, done=0x7ffff488e17d)
at /3rdparty/curl/lib/http.c:1436
#7 0x000000000113d346 in Curl_protocol_connect (conn=0x7fffe40288a0, protocol_done=protocol_done#entry=0x7ffff488e17d)
at /3rdparty/curl/lib/url.c:1647
#8 0x000000000112dfd7 in multi_runsingle (multi=multi#entry=0x7fffe4007ed0, now=..., data=data#entry=0x7fffe401e2a0)
at /3rdparty/curl/lib/multi.c:1610
#9 0x000000000112ecd4 in curl_multi_perform (multi=multi#entry=0x7fffe4007ed0,
running_handles=running_handles#entry=0x7ffff488e2c0) at /3rdparty/curl/lib/multi.c:2171
#10 0x00000000011256b2 in easy_transfer (multi=multi#entry=0x7fffe4007ed0)
at /3rdparty/curl/lib/easy.c:686
#11 0x0000000001125809 in easy_perform (data=0x7fffe401e2a0, events=events#entry=false)
at /3rdparty/curl/lib/easy.c:779
--Type <RET> for more, q to quit, c to continue without paging--c
#12 0x0000000001125b08 in curl_easy_perform (data=<optimized out>) at /3rdparty/curl/lib/easy.c:798
#13 0x0000000001115d93 in Vault::HttpClient::CurlWrapper::execute (this=this#entry=0x7ffff488e4a0) at /3rdparty/libvault/include/VaultClient.h:201
#14 0x0000000001114ef6 in Vault::HttpClient::executeRequest(Vault::Tiny<Vault::UrlDetail, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, Vault::Tiny<Vault::TokenDetail, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, Vault::Tiny<Vault::NamespaceDetail, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, std::function<void (void*)> const&, std::function<curl_slist* (curl_slist*)> const&, std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)> const&) const (this=this#entry=0x7ffff488e920, url=..., token=..., ns=..., setupCallback=..., curlHeaderCallback=..., errorCallback=...) at /3rdparty/libvault/src/support/HttpClient.cpp:184
#15 0x0000000001114fc5 in Vault::HttpClient::get (this=this#entry=0x7ffff488e920, url=..., token=..., ns=...) at 3rdparty/libvault/src/support/HttpClient.cpp:33
#16 0x0000000001116199 in Vault::HttpConsumer::get (client=..., url=...) at /3rdparty/libvault/src/support/HttpConsumer.cpp:12
#17 0x000000000110f940 in Vault::KeyValue::read (this=this#entry=0x7ffff488e840, path=...) at /3rdparty/libvault/src/engines/KeyValue.cpp:48
With same mount and key , i am able to connect with vault using python library

How is this producing a segmentation fault error?

I am receiving a segmentation fault whenever I attempt to push a templated object into a vector. I have ran gdb, and am still unable to understand why I get the segmentation fault error.
Program received signal SIGSEGV, Segmentation fault. 0x0000003f5869d4f3 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib64/libstdc++.so.6
This is where I am inserting the object into the vector:
void ReadyDelivery::LoadTruck(){
string name = "";
int capacity = 0;
ifstream inputStream;
inputStream.open(m_truckFile.c_str());
while(inputStream >> name >> capacity ){
Truck<Item, MAX_CAPACITY> t(name,capacity);
cout<<name<<" "<<capacity<<endl;
m_truck.push_back(t);
}
cout<<"Trucks loaded: "<<m_truck.size()<<endl;
inputStream.close();
If I comment out where I push_back the object into the vector, there is no segmentation fault.
I also have a function that returns the vector. I am not sure if this could be causing it though...
vector<Truck<Item,MAX_CAPACITY> > & ReadyDelivery:: GetTruck(){
return m_truck;
}
Thanks for the help!
Here is the definition of m_truck, which is a private member variable:
private:
vector< Truck<Item, MAX_CAPACITY> > m_truck; //Vector of templated trucks
Here is where I construct the truck object in my template:
template <class T, int N>
Truck<T,N>::Truck(string inName, int capacity){
m_name = inName;
m_capacity = capacity;
}
If I run gdb and use the where command... I get this:
#0 0x000000346ce9d4f3 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib64/libstdc++.so.6
#1 0x0000000000402bd9 in Item::operator= (this=0x60eb00) at Item.h:11
#2 0x0000000000402c66 in Tqueue<Item, 200>::~Tqueue (this=0x60e478,
__in_chrg=<value optimized out>) at Tqueue.h:96
#3 0x0000000000402b43 in Truck<Item, 200>::~Truck (this=0x60e450,
__in_chrg=<value optimized out>) at Truck.h:114
#4 0x00000000004027d5 in std::_Destroy<Truck<Item, 200> > (__pointer=0x60e450)
at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_construct.h:90
#5 0x000000000040249c in std::_Destroy_aux<false>::__destroy<Truck<Item, 200>*>
(__first=0x60e450, __last=0x60e488)
at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_construct.h:100
#6 0x00000000004021d3 in std::_Destroy<Truck<Item, 200>*> (__first=0x60e450,
__last=0x60e488)
at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_construct.h:123
#7 0x0000000000401cdf in std::_Destroy<Truck<Item, 200>*, Truck<Item, 200> > (
__first=0x60e450, __last=0x60e488)
at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_construct.h:149
#8 0x000000000040197c in std::vector<Truck<Item, 200>, std::allocator<Truck<Item, 200> > >::~vector (this=0x7fffffffe1b0, __in_chrg=<value optimized out>)
at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_vector.h:313
#9 0x0000000000401593 in main (argc=1, argv=0x7fffffffe2c8) at driver.cpp:29

Runtime error message when using boost::wave

I get the following runtime error message
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::wave::cpplexer::lexing_exception> >'
what(): boost::wave::lexing_exception
When I am trying to run the following code:
#include <vector>
#include <algorithm>
#include <boost/wave.hpp>
#include <boost/wave/cpplexer/cpp_lex_token.hpp>
#include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
std::string strip_comments(std::string const& input)
{
std::string output;
typedef boost::wave::cpplexer::lex_token<> token_type;
typedef boost::wave::cpplexer::lex_iterator<token_type> lexer_type;
typedef token_type::position_type position_type;
position_type pos;
lexer_type it = lexer_type(input.begin(), input.end(), pos,
boost::wave::language_support(
boost::wave::support_cpp|boost::wave::support_option_long_long));
lexer_type end = lexer_type();
for (;it != end; ++it)
{
if (*it != boost::wave::T_CCOMMENT
&& *it != boost::wave::T_CPPCOMMENT)
{
output += std::string(it->get_value().begin(), it->get_value().end());
}
}
return output;
}
int main()
{
std::string text="aaa bbb /*cccc*/ ddd // eee";
std::cout<<strip_comments(text)<<std::endl;
return 0;
}
I use gcc compiler:
g++ -std=c++11 test.cpp -o test -lboost_wave -lboost_system
This code is supposed to remove C++ comments from a text specified by // and /* ... */.
Here is gdb backtrack:
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
[New LWP 10573]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./a.out'.
Program terminated with signal SIGABRT, Aborted.
#0 0x00007ff38fe96cc9 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00007ff38fe96cc9 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007ff38fe9a0d8 in __GI_abort () at abort.c:89
#2 0x00007ff3904cb78d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ff3904c97f6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ff3904c9841 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ff3904c9a58 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ff390a9e063 in void boost::throw_exception<boost::wave::cpplexer::lexing_exception>(boost::wave::cpplexer::lexing_exception const&)
() from /usr/lib/x86_64-linux-gnu/libboost_wave.so.1.54.0
#7 0x00007ff390aa3a5e in boost::wave::cpplexer::re2clex::lexer<__gnu_cxx::__normal_iterator<char const*, std::string>, boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > >, boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >::report_error(boost::wave::cpplexer::re2clex::Scanner const*, int, char const*, ...) ()
from /usr/lib/x86_64-linux-gnu/libboost_wave.so.1.54.0
#8 0x00007ff390aaf2f0 in boost::wave::cpplexer::re2clex::scan(boost::wave::cpplexer::re2clex::Scanner*) ()
from /usr/lib/x86_64-linux-gnu/libboost_wave.so.1.54.0
#9 0x00007ff390aa4329 in boost::wave::cpplexer::re2clex::lexer<__gnu_cxx::__normal_iterator<char const*, std::string>, boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > >, boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >::get(boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > >&) () from /usr/lib/x86_64-linux-gnu/libboost_wave.so.1.54.0
#10 0x000000000040a3b8 in boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >::get_next<boost::spirit::multi_pass<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::split_functor_input, boost::spirit::iterator_policies::split_std_deque> > > (mp=..., result=...)
at /usr/include/boost/wave/cpplexer/cpp_lex_iterator.hpp:80
#11 0x0000000000409efb in boost::spirit::iterator_policies::split_functor_input::unique<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, true>::advance_input<boost::spirit::multi_pass<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util---Type <return> to continue, or q <return> to quit---
::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::split_functor_input, boost::spirit::iterator_policies::split_std_deque> > > (mp=...)
at /usr/include/boost/spirit/home/support/iterators/detail/split_functor_input_policy.hpp:91
#12 0x000000000040969f in boost::spirit::iterator_policies::multi_pass_unique<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, boost::spirit::iterator_policies::ref_counted::unique, boost::spirit::iterator_policies::no_check::unique, boost::spirit::iterator_policies::split_functor_input::unique<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, true>, boost::spirit::iterator_policies::split_std_deque::unique<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, true, true, true>::advance_input<boost::spirit::multi_pass<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::split_functor_input, boost::spirit::iterator_policies::split_std_deque> > > (mp=...)
at /usr/include/boost/spirit/home/support/iterators/detail/combine_policies.hpp:441
#13 0x0000000000408d7c in boost::spirit::iterator_policies::split_std_deque::unique<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >::increment<boost::spirit::multi_pass<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::split_functor_input, boost::spirit::iterator_policies::split_std_deque> > > (mp=...)
at /usr/include/boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp:107
#14 0x0000000000408450 in boost::spirit::multi_pass<std::pair<boost::wave::cpplexer::impl::lex_iterator_functor_shim<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, boost::wave::cpplexer::lex_input_interface<boost:---Type <return> to continue, or q <return> to quit---
:wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >*>, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::split_functor_input, boost::spirit::iterator_policies::split_std_deque> >::operator++ (this=0x7fff7d8f66e0)
at /usr/include/boost/spirit/home/support/iterators/multi_pass.hpp:119
#15 0x000000000040680e in strip_comments (input="aaa bbb /*cccc*/ ddd // eee") at test.cpp:23
#16 0x0000000000406927 in main () at test.cpp:37
Update
Thanks to jpo38 for his comment. I initialized the pos by
position_type pos(0);
And the previous runtime error fixed.
Now, I got a different runtime error:
#0 0x0000000000406ff8 in std::char_traits<char>::length (__s=0x0) at /usr/include/c++/4.9/bits/char_traits.h:263
#1 0x0000000000408504 in boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> >::flex_string (this=0x7ffee3d536a0, s=0x0, a=...)
at /usr/include/boost/wave/util/flex_string.hpp:1502
#2 0x000000000040693f in strip_comments (input="aaa bbb /*cccc*/ ddd // eee") at test.cpp:16
#3 0x0000000000406bf0 in main () at test.cpp:37
I catched the general exception and tried to show it by:
std::cout << "Error occurred: " << ex.what() << std::endl;
while it was not successful.
boost love exception-programming. Meaning exceptions are used to raise errors and warnings....I hate that, but you need to accept it if you use those fantastic c++ libraries. Exceptions lead to "crash" if you don't be careful and catch them, like that:
std::string strip_comments(std::string const& input)
{
std::string output;
typedef boost::wave::cpplexer::lex_token<> token_type;
typedef boost::wave::cpplexer::lex_iterator<token_type> lexer_type;
typedef token_type::position_type position_type;
boost::wave::util::file_position_type current_position; // for error reporting
try
{
position_type pos;
lexer_type it = lexer_type(input.begin(), input.end(), pos,
boost::wave::language_support(
boost::wave::support_cpp|boost::wave::support_option_long_long));
lexer_type end = lexer_type();
for (;it != end; ++it)
{
current_position = (*it).get_position(); // for error reporting
if (*it != boost::wave::T_CCOMMENT
&& *it != boost::wave::T_CPPCOMMENT)
{
output += std::string(it->get_value().begin(), it->get_value().end());
}
}
}
catch (boost::wave::cpplexer::lexing_exception const& e) {
// some lexing error
std::cerr
<< e.file_name() << "(" << e.line_no() << "): "
<< e.description() << std::endl;
}
catch (std::exception const& e) {
// use last recognized token to retrieve the error position
std::cerr
<< current_position.get_file()
<< "(" << current_position.get_line() << "): "
<< "exception caught: " << e.what()
<< std::endl;
}
catch (...) {
// use last recognized token to retrieve the error position
std::cerr
<< current_position.get_file()
<< "(" << current_position.get_line() << "): "
<< "unexpected exception caught." << std::endl;
}
return output;
}
Then, instead of a "crash", you'll get this nice ans safe message:
(1): warning: generic lexer warning: Unterminated 'C++' style comment
You can see that, by not catching exception, a simple boost warning was transformed in a critical crash at your level ;-)
I'm not familiar with wave library, but adding a \n to the end of your string fixes the issue and then no error is reported anymore (by the way, it was actually just a warning):
Change main function text string to: std::string text="aaa bbb /*cccc*/ ddd // eee\n"; and the program will output aaa bbb ddd.
You can add this \n, but you may also rework the code to try/catch within the loop and then report but ignore warnings.
Note: The fact that boost::wave expects a EOL is probably related to this well known C++ warning (but it is really just a warning): "No newline at end of file" compiler warning