Corruption in C++ constructor - c++

I'm facing corruption in constructor . Can someone help me ?
2873 int rc = _db->fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct, HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) p selectConstruct
$1 = {distinct = false, colsToBeSelected = {cols = {<std::_Vector_base<dbCol, std::allocator<dbCol> >> = {_M_impl = {<std::allocator<dbCol>> = {<__gnu_cxx::new_allocator<dbCol>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}}, tableName = {static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x3dd36f32d8 ""}}, where = {whereExprs = {<std::_Vector_base<whereExpr, std::allocator<whereExpr> >> = {_M_impl = {<std::allocator<whereExpr>> = {<__gnu_cxx::new_allocator<whereExpr>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}, ops = {<std::_Vector_base<adjoinOperator, std::allocator<adjoinOperator> >> = {_M_impl = {<std::allocator<adjoinOperator>> = {<__gnu_cxx::new_allocator<adjoinOperator>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}, namespaceCounts = {<std::_Vector_base<unsigned int, std::allocator<unsigned int> >> = {_M_impl = {<std::allocator<unsigned int>> = {<__gnu_cxx::new_allocator<unsigned int>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}, useAsON = false}, groupBy = {cols = {<std::_Vector_base<dbCol, std::allocator<dbCol> >> = {_M_impl = {<std::allocator<dbCol>> = {<__gnu_cxx::new_allocator<dbCol>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}}, orders = {orders = {<std::_Vector_base<orderingTerm, std::allocator<orderingTerm> >> = {_M_impl = {<std::allocator<orderingTerm>> = {<__gnu_cxx::new_allocator<orderingTerm>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}}, limit = -1}
(gdb) stepi
0x00007ffff0df9b49 2873 int rc = _db- >fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct, HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) stepi
0x00007ffff0df9b50 2873 int rc = _db->fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct, HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) stepi
0x00007ffff0df9b53 2873 int rc = _db->fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct, HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) stepi
0x00007ffff0df9b5b 2873 int rc = _db->fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct, HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) stepi
0x00007ffff0df9b5e 2873 int rc = _db->fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct, HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) stepi
0x00007ffff0da8000 in simpleSelectConstruct::simpleSelectConstruct () from /opt/OV/lbin/OpsAgt/libDMLSegment.so
(gdb) stepi
simpleSelectConstruct::simpleSelectConstruct (this=0x7fffdbffdbb0) at /home/parakkal/COLLABNET_11.10_NEW/hpsw-oa/AgentFramework/cpp/src/include/OpsAgt/DBsupports.h:170
170 class simpleSelectConstruct{
/include/OpsAgt/DBsupports.h:170
170 class simpleSelectConstruct{
(gdb) p *this
$2 = {distinct = false, colsToBeSelected = {cols = {<std::_Vector_base<dbCol, std::allocator<dbCol> >> = {_M_impl = {<std::allocator<dbCol>> = {<__gnu_cxx::new_allocator<dbCol>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}}, tableName = {static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x0}}, where = {whereExprs = {<std::_Vector_base<whereExpr, std::allocator<whereExpr> >> = {_M_impl = {<std::allocator<whereExpr>> = {<__gnu_cxx::new_allocator<whereExpr>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}, ops = {<std::_Vector_base<adjoinOperator, std::allocator<adjoinOperator> >> = {_M_impl = {<std::allocator<adjoinOperator>> = {<__gnu_cxx::new_allocator<adjoinOperator>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x3dd34bd704, _M_end_of_storage = 0x7ffff7ca52b0}}, <No data fields>}, namespaceCounts = {<std::_Vector_base<unsigned int, std::allocator<unsigned int> >> = {_M_impl = {<std::allocator<unsigned int>> = {<__gnu_cxx::new_allocator<unsigned int>> = {<No data fields>}, <No data fields>}, _M_start = 0x7fffdbffe910, _M_finish = 0x6, _M_end_of_storage = 0x4e}}, <No data fields>}, useAsON = false}, groupBy = {cols = {<std::_Vector_base<dbCol, std::allocator<dbCol> >> = {_M_impl = {<std::allocator<dbCol>> = {<__gnu_cxx::new_allocator<dbCol>> = {<No data fields>}, <No data fields>}, _M_start = 0x7fffdbffe910, _M_finish = 0x0, _M_end_of_storage = 0x7ffff6f54d1f}}, <No data fields>}}, orders = {orders = {<std::_Vector_base<orderingTerm, std::allocator<orderingTerm> >> = {_M_impl = {<std::allocator<orderingTerm>> = {<__gnu_cxx::new_allocator<orderingTerm>> = {<No data fields>}, <No data fields>}, _M_start = 0x7ffff7ca52b0, _M_finish = 0x7ffff6f5584d, _M_end_of_storage = 0x5509f0}}, <No data fields>}}, limit = -603988688}
(gdb) stepi
If you see above limit is corrupted in the constructor , so is _M_start , _M_finish and _M_end_of_storage. The simpleSelectConstruct class is shown here
class simpleSelectConstruct{
public:
DBSupportsInterface simpleSelectConstruct()
{
distinct=false;
limit=-1;
}
bool distinct;
dbCols colsToBeSelected;
string tableName;
whereConstruct where;
dbCols groupBy;
orderBy orders;
int limit;
};
I've posted the complete info at
https://gcc.gnu.org/ml/gcc-help/2014-08/msg00104.html

(gdb) stepi
0x00007ffff0df9b5e 2873 int rc =
_db->fetch_custom_sql_query(rwc.GetQueryName(),selectConstruct,HandleCustomSqlQueryResponse, (void*)&holder);
(gdb) stepi
0x00007ffff0da8000 in simpleSelectConstruct::simpleSelectConstruct ()
from /opt/OV/lbin/OpsAgt/libDMLSegment.so
(gdb) stepi
simpleSelectConstruct::simpleSelectConstruct (this=0x7fffdbffdbb0)
[SNIP]
(gdb) p *this
[SNIP OUTPUT BEFORE CONSTRUCTOR RUNS]
(gdb) stepi
0x00007ffff0e11892 170 class simpleSelectConstruct{
(gdb) stepi
0x00007ffff0e11894 170 class simpleSelectConstruct{
(gdb) stepi
0x00007ffff0e11896 170 class simpleSelectConstruct{
(gdb) stepi
0x00007ffff0e11898 170 class simpleSelectConstruct{
(gdb) p *this
[SNIP OUTPUT DURING CONSTRUCTOR]
(gdb)
[END OF DEBUGGING SESSION]
I see no evidence of corruption. I see that you print out a non-corrupted variable selectConstruct, step into the simpleSelectConstruct constructor, print the simpleSelectConstruct that's about to be constructed, make four steps, and then print the simpleSelectConstruct that is only half constructed. (Neither of which is the selectConstruct variable). Did you try waiting until after the constructor completed?
When constructor begins:
distinct = false
colsToBeSelected =
cols = ..._M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0 ...
tableName = ..._M_p = 0x0 ...
where =
whereExprs = ..._M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0...
ops = ..._M_start = 0x0, _M_finish = 0x3dd34bd704, _M_end_of_storage = 0x7ffff7ca52b0...
namespaceCounts = ..._M_start = 0x7fffdbffe910, _M_finish = 0x6, _M_end_of_storage = 0x4e...
useAsON = false
groupBy =
cols = ..._M_start = 0x7fffdbffe910, _M_finish = 0x0, _M_end_of_storage = 0x7ffff6f54d1f...
orders = ..._M_start = 0x7ffff7ca52b0, _M_finish = 0x7ffff6f5584d, _M_end_of_storage = 0x5509f0...
limit = -603988688
After four steps in the constructor:
distinct = false
colsToBeSelected =
cols = ..._M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0 ...
tableName = ..._M_p = 0x0...
where =
whereExprs = ..._M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0...
ops = ..._M_start = 0x0, _M_finish = 0x3dd34bd704, _M_end_of_storage = 0x7ffff7ca52b0...
namespaceCounts = ..._M_start = 0x7fffdbffe910, _M_finish = 0x6, _M_end_of_storage = 0x4e...
useAsON = false
groupBy =
cols = ..._M_start = 0x7fffdbffe910, _M_finish = 0x0, _M_end_of_storage = 0x7ffff6f54d1f...
orders = ..._M_start = 0x7ffff7ca52b0, _M_finish = 0x7ffff6f5584d, _M_end_of_storage = 0x5509f0...
limit = -603988688
The constructor clearly hasn't finished executing yet. It appears to be pretty early in the construction process still. I would assume that the four operations are assinging false, and then cols, so the next step would be to construct tableName.

Related

what is "emergency_buffer"?

I'm doing some coredump debugging, when I printed the content of a string variable, I got this:
$8 = {static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
_M_p = 0x7f25c1a48d98 <emergency_buffer+7464> ""}}
I want to know what does the "emergency_buffer" mean here? Thanks.

Debugging C++ code of an R package with Rcpp using gdb cannot print variable value with R_PV (unknown return type)

I have used RStudio on Ubuntu 18.04 to create an hello world R package using Rcpp like described here in Rcpp Package Development:
My ~/.R/Makevars contain only the line
CXXFLAGS=-g -O0 -Wall
and during pkg build I can see that these flags are applied.
How can print the current value of an R vector (C++ classes CharacterVector or NumericVector in gdb after hitting a breakpoint?
(gdb) p R_PV(x) (as explained in Writing R Extensions) shows an error (perhaps because the SEXP is wrapped?):
(gdb) whatis x
type = Rcpp::CharacterVector
My debug session:
R -d gdb --vanilla
(gdb) run
library(RcppTestPkg)
# type Strg + X to break into gdb to set a breakpoint
(gdb) break rcpp_hello_world.cpp:8
(gdb) cont
rcpp_hello_world()
Breakpoint 1, rcpp_hello_world () at rcpp_hello_world.cpp:8
8 NumericVector y = NumericVector::create( 0.0, 1.0 ) ;
(gdb) n
9 List z = List::create( x, y ) ;
(gdb) n
11 return z ;
(gdb) info locals
x = {<Rcpp::PreserveStorage<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {
data = 0x5555562c4360}, <Rcpp::SlotProxyPolicy<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::AttributeProxyPolicy<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::NamesProxyPolicy<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::RObjectMethods<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::VectorBase<16, true, Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<Rcpp::traits::expands_to_logical__impl<16>> = {<No data fields>}, <No data fields>}, cache = {
p = 0x7fffffffba10}}
y = {<Rcpp::PreserveStorage<Rcpp::Vector<14, Rcpp::PreserveStorage> >> = {
data = 0x5555562c43d0}, <Rcpp::SlotProxyPolicy<Rcpp::Vector<14, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::AttributeProxyPolicy<Rcpp::Vector<14, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::NamesProxyPolicy<Rcpp::Vector<14, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::RObjectMethods<Rcpp::Vector<14, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::VectorBase<14, true, Rcpp::Vector<14, Rcpp::PreserveStorage> >> = {<Rcpp::traits::expands_to_logical__impl<14>> = {<No data fields>}, <No data fields>}, cache = {
start = 0x5555562c43f8}}
z = {<Rcpp::PreserveStorage<Rcpp::Vector<19, Rcpp::PreserveStorage> >> = {
data = 0x5555562c4440}, <Rcpp::SlotProxyPolicy<Rcpp::Vector<19, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::AttributeProxyPolicy<Rcpp::Vector<19, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::NamesProxyPolicy<Rcpp::Vector<19, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::RObjectMethods<Rcpp::Vector<19, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::VectorBase<19, true, Rcpp::Vector<19, Rcpp::PreserveStorage> >> = {<Rcpp::traits::expands_to_logical__impl<19>> = {<No data fields>}, <No data fields>}, cache = {
p = 0x7fffffffbab0}}
(gdb) p x
$3 = {<Rcpp::PreserveStorage<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {
data = 0x5555562c4360}, <Rcpp::SlotProxyPolicy<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::AttributeProxyPolicy<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::NamesProxyPolicy<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::RObjectMethods<Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<No data fields>}, <Rcpp::VectorBase<16, true, Rcpp::Vector<16, Rcpp::PreserveStorage> >> = {<Rcpp::traits::expands_to_logical__impl<16>> = {<No data fields>}, <No data fields>}, cache = {
p = 0x7fffffffba10}}
(gdb) p R_PV(x)
'R_PV' has unknown return type; cast the call to its declared return type
(gdb) p x->data
$5 = (SEXP) 0x5555566d2308
(gdb) p R_PV(x->data)
'R_PV' has unknown return type; cast the call to its declared return type
Edit: Here`s the source code of the function:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List rcpp_hello_world() {
CharacterVector x = CharacterVector::create( "foo", "bar" ) ;
NumericVector y = NumericVector::create( 0.0, 1.0 ) ;
List z = List::create( x, y ) ;
return z ;
}
(gdb) p R_PV(x)
In my R source, R_PV is a function returning void. Try this instead:
(gdb) call R_PV(x)
As Dirk Eddelbuettel noted, you still need to pass the right type to R_PV, so perhaps the correct command is:
(gdb) call R_PV(Rcpp::wrap(&x))

Shared pointee is not the same in the caller and the callee

I am working on a module of the ns-3 simulator. For people unfamiliar with it, they exhibit a custom-made shared pointer: Ptr<T>. These objects are usually created using the CreateObject<T>(…) function which basically calls new T(…) and wraps it in a Ptr<T>.
I’m having troubles using one of these that I created in a constructor:
SatUtHelper::SatUtHelper (SatTypedefs::CarrierBandwidthConverter_t carrierBandwidthConverter,
uint32_t fwdLinkCarrierCount,
Ptr<SatSuperframeSeq> seq,
SatMac::ReadCtrlMsgCallback readCb,
SatMac::ReserveCtrlMsgCallback reserveCb,
SatMac::SendCtrlMsgCallback sendCb,
RandomAccessSettings_s randomAccessSettings)
: m_superframeSeq (seq),
m_llsConf (),
[...snip...]
{
[...snip...]
m_llsConf = CreateObject<SatLowerLayerServiceConf> ();
}
and that I use like so:
Ptr<SatRandomAccessConf> randomAccessConf = CreateObject<SatRandomAccessConf> (m_llsConf, m_superframeSeq);
The SatRandomAccessConf constructor begins like so:
SatRandomAccessConf::SatRandomAccessConf (Ptr<SatLowerLayerServiceConf> llsConf, Ptr<SatSuperframeSeq> superframeSeq)
: m_configurationIdPerAllocationChannel (),
m_slottedAlohaControlRandomizationIntervalInMilliSeconds (),
m_allocationChannelCount (llsConf->GetRaServiceCount ()),
m_crdsaSignalingOverheadInBytes (5),
m_slottedAlohaSignalingOverheadInBytes (3)
{
NS_LOG_FUNCTION (this);
if (m_allocationChannelCount < 1)
{
NS_FATAL_ERROR ("SatRandomAccessConf::SatRandomAccessConf - No random access allocation channel");
}
m_slottedAlohaControlRandomizationIntervalInMilliSeconds = (llsConf->GetDefaultControlRandomizationInterval ()).GetMilliSeconds ();
DoSlottedAlohaVariableSanityCheck ();
and contains some checks past that point which blows up due to having llsConf in an incoherent state.
I have used GDB to inspect the state of the llsConf object:
I put a breakpoint on the DoSlottedAlohaVariableSanityCheck ();
I called methods on llsConf that indeed returned garbage values;
I checked values of m_allocationChannelCount and m_slottedAlohaControlRandomizationIntervalInMilliSeconds that were not the same as the return values from the methods of llsConf;
I checked in upper frames the values on m_llsConf which were as expected;
I checked the content of the objects in both frames that differed in the caller and the callee; the content of llsConf having a suspiciously large amount of attributes set to 0.
Relevant parts of the GDB session:
(gdb) bt
#0 ns3::SatRandomAccessConf::DoSlottedAlohaVariableSanityCheck (this=0x55555a160a00) at ../contrib/satellite/model/satellite-random-access-container-conf.cc:146
#1 0x00007ffff76fe0e1 in ns3::SatRandomAccessConf::SatRandomAccessConf (this=0x55555a160a00, llsConf=..., superframeSeq=...) at ../contrib/satellite/model/satellite-random-access-container-conf.cc:75
#2 0x00007ffff781fa26 in ns3::CreateObject<ns3::SatRandomAccessConf, ns3::Ptr<ns3::SatLowerLayerServiceConf>, ns3::Ptr<ns3::SatSuperframeSeq> > (a1=..., a2=...) at ./ns3/object.h:557
#3 0x00007ffff781d494 in ns3::SatUtHelper::Install (this=0x555555841990, n=..., beamId=10, fCh=..., rCh=..., gwNd=..., ncc=..., cbChannel=..., cbRouting=...) at ../contrib/satellite/helper/satellite-ut-helper.cc:425
#4 0x00007ffff781b307 in ns3::SatUtHelper::Install (this=0x555555841990, c=..., beamId=10, fCh=..., rCh=..., gwNd=..., ncc=..., cbChannel=..., cbRouting=...) at ../contrib/satellite/helper/satellite-ut-helper.cc:231
#5 0x00007ffff77b03bc in ns3::SatBeamHelper::Install (this=0x5555557ecb20, ut=..., gwNode=..., gwId=3, beamId=10, ulFreqId=3, flFreqId=1, routingCallback=...) at ../contrib/satellite/helper/satellite-beam-helper.cc:475
#6 0x00007ffff77f0262 in ns3::SatHelper::DoCreateScenario (this=0x5555557ec810, beamInfos=std::map with 0 elements, gwUsers=1) at ../contrib/satellite/helper/satellite-helper.cc:566
#7 0x00007ffff77ee873 in ns3::SatHelper::CreateUserDefinedScenario (this=0x5555557ec810, infos=std::map with 0 elements) at ../contrib/satellite/helper/satellite-helper.cc:389
#8 0x00007ffff7844e0b in ns3::SimulationHelper::CreateSatScenario (this=0x5555557ec5a0, scenario=ns3::SatHelper::NONE, mobileUtsFolder="contrib/satellite/data/utpositions/mobiles/")
at ../contrib/satellite/helper/simulation-helper.cc:1170
#9 0x00007ffff784a1dc in ns3::SimulationHelper::ConfigureAttributesFromFile (this=0x5555557ec5a0, filePath="/tmp/sns-3-qs4ebg47/parameters.xml", overrideManualConfiguration=true) at ../contrib/satellite/helper/simulation-helper.cc:1555
#10 0x0000555555557225 in main (argc=3, argv=0x7fffffffe798) at ../contrib/satellite/examples/sat-generic-launcher.cc:60
(gdb) p llsConf->GetRaServiceCount()
$1 = 0 '\000'
(gdb) p llsConf->GetDefaultControlRandomizationInterval()
$2 = {static g_markingTimes = 0x7ffff39447a0 <ns3::Time::StaticInit()::markingTimes>, m_data = 93824994540112}
(gdb) p llsConf->GetDefaultControlRandomizationInterval().GetMilliSeconds()
$3 = 93824994
(gdb) p m_allocationChannelCount
$4 = 1
(gdb) p m_slottedAlohaControlRandomizationIntervalInMilliSeconds
$5 = 100
(gdb) p llsConf
$6 = {m_ptr = 0x7fffffffd718}
(gdb) p *(llsConf.m_ptr)
$7 = {<ns3::Object> = {<ns3::SimpleRefCount<ns3::Object, ns3::ObjectBase, ns3::ObjectDeleter>> = {<ns3::ObjectBase> = {_vptr.ObjectBase = 0x5555557af810}, m_count = 1434627024}, m_tid = {m_tid = 21845}, m_disposed = false,
m_initialized = false, m_aggregates = 0x91c8f8cb8ee26900, m_getObjectCount = 0}, static m_minDaServiceEntries = 2 '\002', static m_minRaServiceEntries = 1 '\001', static m_maxDaServiceEntries = 4 '\004',
static m_maxRaServiceEntries = 3 '\003', m_dynamicRatePersistence = 0 '\000', m_volumeBacklogPersistence = 0 '\000', m_defaultControlRandomizationInterval = {
static g_markingTimes = 0x7ffff39447a0 <ns3::Time::StaticInit()::markingTimes>, m_data = 93824994540112}, m_daServiceEntryCount = 102 'f', m_daServiceEntries = {{m_constantAssignmentProvided = false, m_rbdcAllowed = false,
m_volumeAllowed = false, m_constantServiceRateStream = {m_ptr = 0x7fffffffdb50}, m_maximumServiceRateKbps = 54420, m_minimumServiceRateKbps = 63361, m_maximumBacklogInKbytes = 32767}, {m_constantAssignmentProvided = 54,
m_rbdcAllowed = 62, m_volumeAllowed = 103, m_constantServiceRateStream = {m_ptr = 0x0}, m_maximumServiceRateKbps = 51468, m_minimumServiceRateKbps = 63349, m_maximumBacklogInKbytes = 32767}, {m_constantAssignmentProvided = false,
m_rbdcAllowed = false, m_volumeAllowed = false, m_constantServiceRateStream = {m_ptr = 0x7ffff7710ce6 <ns3::SatRequestManager::AssignedDaResources(unsigned char, unsigned int)>}, m_maximumServiceRateKbps = 0,
m_minimumServiceRateKbps = 0, m_maximumBacklogInKbytes = 0}, {m_constantAssignmentProvided = 192, m_rbdcAllowed = 189, m_volumeAllowed = 112, m_constantServiceRateStream = {m_ptr = 0x0}, m_maximumServiceRateKbps = 65,
m_minimumServiceRateKbps = 0, m_maximumBacklogInKbytes = 0}}, m_raServiceIndexDefault = 0 '\000', m_raServiceEntryCount = 0 '\000', m_raServiceEntries = {{m_maxUniquePayloadPerBlock = 118 'v',
m_maxConsecutiveBlockAccessed = 130 '\202', m_minimumIdleBlock = 112 'p', m_backOffTimeInMilliSeconds = 32767, m_highLoadBackOffTimeInMilliSeconds = 0, m_backOffProbability = 0, m_highLoadBackOffProbability = 0,
m_numberOfInstances = 0 '\000', m_averageNormalizedOfferedLoadThreshold = 6.9533487051292957e-310, m_isCrdsaAllowed = false, m_isSlottedAlohaAllowed = false}, {m_maxUniquePayloadPerBlock = 54 '6',
m_maxConsecutiveBlockAccessed = 62 '>', m_minimumIdleBlock = 103 'g', m_backOffTimeInMilliSeconds = 32767, m_highLoadBackOffTimeInMilliSeconds = 0, m_backOffProbability = 0, m_highLoadBackOffProbability = 0,
m_numberOfInstances = 0 '\000', m_averageNormalizedOfferedLoadThreshold = 7.5592043813710721e-322, m_isCrdsaAllowed = false, m_isSlottedAlohaAllowed = false}, {m_maxUniquePayloadPerBlock = 113 'q',
m_maxConsecutiveBlockAccessed = 0 '\000', m_minimumIdleBlock = 0 '\000', m_backOffTimeInMilliSeconds = 0, m_highLoadBackOffTimeInMilliSeconds = 0, m_backOffProbability = 0, m_highLoadBackOffProbability = 0,
m_numberOfInstances = 0 '\000', m_averageNormalizedOfferedLoadThreshold = 6.9533487349484301e-310, m_isCrdsaAllowed = false, m_isSlottedAlohaAllowed = false}}}
(gdb) up
#2 0x00007ffff781fa26 in ns3::CreateObject<ns3::SatRandomAccessConf, ns3::Ptr<ns3::SatLowerLayerServiceConf>, ns3::Ptr<ns3::SatSuperframeSeq> > (a1=..., a2=...) at ./ns3/object.h:557
557 return CompleteConstruct (new T (a1,a2));
(gdb) up
#3 0x00007ffff781d494 in ns3::SatUtHelper::Install (this=0x555555841990, n=..., beamId=10, fCh=..., rCh=..., gwNd=..., ncc=..., cbChannel=..., cbRouting=...) at ../contrib/satellite/helper/satellite-ut-helper.cc:425
425 Ptr<SatRandomAccessConf> randomAccessConf = CreateObject<SatRandomAccessConf> (m_llsConf, m_superframeSeq);
(gdb) p m_llsConf->GetRaServiceCount()
$8 = 1 '\001'
(gdb) p m_llsConf->GetDefaultControlRandomizationInterval().GetMilliSeconds()
$9 = 100
(gdb) p m_llsConf
$10 = {m_ptr = 0x5555557af810}
(gdb) p *(m_llsConf.m_ptr)
$11 = {<ns3::Object> = {<ns3::SimpleRefCount<ns3::Object, ns3::ObjectBase, ns3::ObjectDeleter>> = {<ns3::ObjectBase> = {_vptr.ObjectBase = 0x7ffff7d93850 <vtable for ns3::SatLowerLayerServiceConf+16>}, m_count = 6}, m_tid = {
m_tid = 406}, m_disposed = false, m_initialized = false, m_aggregates = 0x5555564d2540, m_getObjectCount = 0}, static m_minDaServiceEntries = 2 '\002', static m_minRaServiceEntries = 1 '\001',
static m_maxDaServiceEntries = 4 '\004', static m_maxRaServiceEntries = 3 '\003', m_dynamicRatePersistence = 5 '\005', m_volumeBacklogPersistence = 7 '\a', m_defaultControlRandomizationInterval = {
static g_markingTimes = 0x7ffff39447a0 <ns3::Time::StaticInit()::markingTimes>, m_data = 100000000}, m_daServiceEntryCount = 4 '\004', m_daServiceEntries = {{m_constantAssignmentProvided = false, m_rbdcAllowed = false,
m_volumeAllowed = false, m_constantServiceRateStream = {m_ptr = 0x5555561d07d0}, m_maximumServiceRateKbps = 9216, m_minimumServiceRateKbps = 10, m_maximumBacklogInKbytes = 384}, {m_constantAssignmentProvided = false,
m_rbdcAllowed = false, m_volumeAllowed = false, m_constantServiceRateStream = {m_ptr = 0x555555e48b20}, m_maximumServiceRateKbps = 9216, m_minimumServiceRateKbps = 10, m_maximumBacklogInKbytes = 384}, {
m_constantAssignmentProvided = false, m_rbdcAllowed = false, m_volumeAllowed = false, m_constantServiceRateStream = {m_ptr = 0x55555581d600}, m_maximumServiceRateKbps = 9216, m_minimumServiceRateKbps = 10,
m_maximumBacklogInKbytes = 384}, {m_constantAssignmentProvided = false, m_rbdcAllowed = false, m_volumeAllowed = false, m_constantServiceRateStream = {m_ptr = 0x5555557a95f0}, m_maximumServiceRateKbps = 9216,
m_minimumServiceRateKbps = 16, m_maximumBacklogInKbytes = 384}}, m_raServiceIndexDefault = 0 '\000', m_raServiceEntryCount = 1 '\001', m_raServiceEntries = {{m_maxUniquePayloadPerBlock = 1 '\001',
m_maxConsecutiveBlockAccessed = 6 '\006', m_minimumIdleBlock = 0 '\000', m_backOffTimeInMilliSeconds = 150, m_highLoadBackOffTimeInMilliSeconds = 500, m_backOffProbability = 1, m_highLoadBackOffProbability = 1,
m_numberOfInstances = 3 '\003', m_averageNormalizedOfferedLoadThreshold = 0.98999999999999999, m_isCrdsaAllowed = true, m_isSlottedAlohaAllowed = true}, {m_maxUniquePayloadPerBlock = 3 '\003',
m_maxConsecutiveBlockAccessed = 4 '\004', m_minimumIdleBlock = 2 '\002', m_backOffTimeInMilliSeconds = 250, m_highLoadBackOffTimeInMilliSeconds = 500, m_backOffProbability = 10000, m_highLoadBackOffProbability = 30000,
m_numberOfInstances = 2 '\002', m_averageNormalizedOfferedLoadThreshold = 0.5, m_isCrdsaAllowed = true, m_isSlottedAlohaAllowed = true}, {m_maxUniquePayloadPerBlock = 3 '\003', m_maxConsecutiveBlockAccessed = 4 '\004',
m_minimumIdleBlock = 2 '\002', m_backOffTimeInMilliSeconds = 250, m_highLoadBackOffTimeInMilliSeconds = 500, m_backOffProbability = 10000, m_highLoadBackOffProbability = 30000, m_numberOfInstances = 5 '\005',
m_averageNormalizedOfferedLoadThreshold = 0.5, m_isCrdsaAllowed = true, m_isSlottedAlohaAllowed = true}}}
Now if I add the line Ptr<SatLowerLayerServiceConf> uglyHack = llsConf; before the breakpoint, I can in fact see that, somehow, they are equal:
(gdb) p uglyHack
$1 = {m_ptr = 0x5555557af810}
(gdb) p llsConf
$2 = {m_ptr = 0x7fffffffd718}
(gdb) up
#2 0x00007ffff781fa56 in ns3::CreateObject<ns3::SatRandomAccessConf, ns3::Ptr<ns3::SatLowerLayerServiceConf>, ns3::Ptr<ns3::SatSuperframeSeq> > (a1=..., a2=...) at ./ns3/object.h:557
557 return CompleteConstruct (new T (a1,a2));
(gdb)
#3 0x00007ffff781d4c4 in ns3::SatUtHelper::Install (this=0x555555841990, n=..., beamId=10, fCh=..., rCh=..., gwNd=..., ncc=..., cbChannel=..., cbRouting=...) at ../contrib/satellite/helper/satellite-ut-helper.cc:425
425 Ptr<SatRandomAccessConf> randomAccessConf = CreateObject<SatRandomAccessConf> (m_llsConf, m_superframeSeq);
(gdb) p m_llsConf
$3 = {m_ptr = 0x5555557af810}
Does someone have any idea how the parameter passing and the copy assignment can allow such behaviour?

How to read the structure values in gdb?

For example, when I type
p dest-msgs[count]
The following values are displayed. How to understand the significance of these values ?
p dest->msgs[count]
$9 = {hdr = {ver = 5 '\005', magic = 18 '\022', evt_len = 588}, evt = {hdr = {ver = 3 '\003', magic = 18 '\022', evt_len = 552}, service_id = 1, instance = 0, comp_id = -2136604671,
comp_name = "tsd", '\0' <repeats 14 times>, flags = 0, objid = 0, file = "ts.c", '\0' <repeats 11 times>, func = "tsTimeMcast_h\000\000", line = 1667, local_time_sec = 1483252020,
local_time_usec = 28575, time_sec = 1483252020, time_usec = 28675, global_seq = 4014, external_seq = 2146, iq_drop = 0, rq_drop = 0,
arg_offset = "\000\002\005\006", '\0' <repeats 11 times>, arg = "LOCL\000\000\000\000External\000\000\000\000EXT\000LOCL", '\0' <repeats 227 times>, msgdef = {msg_id = 0,
attributes = 0, class = 0, severity = 0, msg_value = "\000\000\000\000\000\000\000\000\000", message = '\0' <repeats 128 times>, arg_type = 0, arg_num = 0,
cat_name = "\000\000\000\000\000\000\000"}}, name = '\0' <repeats 31 times>}
Let's see what we have here:
p dest->msgs[count]
So, you print one particular element from an array, it seems. Gdb responds:
$9 = {
This $9 is just an artificial name that you could use later to refer to this result. The result begins with an opening brace. This means that it is a structure. It goes on:
hdr = {ver = 5 '\005', magic = 18 '\022', evt_len = 588},
The first member of the structure has the name hdr and its value is, see the next opening brace, again a structure. This nested structure has three members (the closing brace tells us where we have to stop counting) named ver, magic, and evt_len. You see their respective values. Then follows
evt = {hdr = {ver = ...
that is, evt is the second member of the outer structure, which is again a structure, which has member hdr, which is again a structure. Et cetera.

Why the mysql reconnect failed and cause a segment fault?

This is the stacktrace of the crash of my program
Program terminated with signal 11, Segmentation fault.
#0 0x00002ae1caf18008 in safer_scalable_free ()
from /home/is_admin/tbb40_233oss/build/linux_intel64_gcc_cc4.1.2_libc2.5_kernel2.6.18_release/libtbbmalloc.so.2
(gdb) bt
#0 0x00002ae1caf18008 in safer_scalable_free ()
from /home/is_admin/tbb40_233oss/build/linux_intel64_gcc_cc4.1.2_libc2.5_kernel2.6.18_release/libtbbmalloc.so.2
#1 0x00002ae1cad12189 in free ()
from /home/is_admin/tbb40_233oss/build/linux_intel64_gcc_cc4.1.2_libc2.5_kernel2.6.18_release/libtbbmalloc_proxy.so.2
#2 0x00002ae1cb56fb60 in mysql_close_free (mysql=0x2ae1cc491600)
at /home/is_admin/MRPlatform/src/mysql-5.5.17/sql-common/client.c:3643
#3 0x00002ae1cb570ef1 in mysql_close (mysql=0x2ae1cc491600) at /home/is_admin/MRPlatform/src/mysql-5.5.17/sql-common/client.c:3744
#4 0x00002ae1cb573ad4 in mysql_reconnect (mysql=0x2ae1cc491600)
at /home/is_admin/MRPlatform/src/mysql-5.5.17/sql-common/client.c:3561
#5 0x00002ae1cb573c37 in cli_advanced_command (mysql=0x2ae1cc491600, command=<value optimized out>, header=0x0, header_length=0,
arg=0x0, arg_length=0, skip_check=0 '\000', stmt=0x0) at /home/is_admin/MRPlatform/src/mysql-5.5.17/sql-common/client.c:852
#6 0x00002ae1cb56a3e1 in mysql_ping (mysql=0x1) at /home/is_admin/MRPlatform/src/mysql-5.5.17/libmysql/libmysql.c:969
#7 0x000000000042ded6 in TDRNetwork::DataAccess::ExecuteSQL(char const*) ()
#8 0x000000000041c511 in MRSystem::Master::Process(TDRNetwork::JobMsg*) ()
#9 0x000000000042a33f in MRSystem::MasterWorker::Run() ()
#10 0x000000000042fc99 in TDRNetwork::Thread::StartThread(void*) ()
#11 0x00000033b080673d in start_thread () from /lib64/libpthread.so.0
#12 0x00000033b00d44bd in clone () from /lib64/libc.so.6
At frame 6 I noticed that the mysql=0x1 which is outof bound. It seems the mysql link auto closed after 8 hours if no action taken. So why the reconnection failed? Thanks.
EDIT:
the error occurs at client.c:3643 my_free(mysql->info_buffer);
#if defined(EMBEDDED_LIBRARY) || MYSQL_VERSION_ID >= 50100
my_free(mysql->info_buffer);
mysql->info_buffer= 0;
#endif
And the info_buffer is out of bound:
(gdb) p *mysql
$2 = {net = {vio = 0x0, buff = 0x0, buff_end = 0x2aaaabcf5080 "", write_pos = 0x2aaaabcf3080 "", read_pos = 0x2aaaabcf3080 "",
fd = 10, remain_in_buf = 0, length = 0, buf_length = 0, where_b = 0, max_packet = 8192, max_packet_size = 1073741824,
pkt_nr = 1, compress_pkt_nr = 0, write_timeout = 31536000, read_timeout = 31536000, retry_count = 1, fcntl = 0,
return_status = 0x0, reading_or_writing = 0 '\000', save_char = 0 '\000', unused1 = 0 '\000', unused2 = 0 '\000',
compress = 0 '\000', unused3 = 0 '\000', unused = 0x0, last_errno = 0, error = 2 '\002', unused4 = 0 '\000',
unused5 = 0 '\000', last_error = '\000' <repeats 511 times>, sqlstate = "00000", extension = 0x0}, connector_fd = 0x0,
host = 0x2aaaabea34b8 "127.0.0.1", user = 0x2aaaabeb3bf8 "", passwd = 0x2aaaabeb3c00 "\370;뫪*", unix_socket = 0x0,
server_version = 0x2aaaabea34d0 "5.5.17", host_info = 0x2aaaabea34a0 "", info = 0x0, db = 0x2aaaabeb3c08 "",
charset = 0x2aaaab661060, fields = 0x0, field_alloc = {free = 0x0, used = 0x0, pre_alloc = 0x0, min_malloc = 32,
block_size = 8160, block_num = 4, first_block_usage = 0, error_handler = 0}, affected_rows = 18446744073709551615,
insert_id = 0, extra_info = 0, thread_id = 472, packet_length = 7, port = 3306, client_flag = 959117,
server_capabilities = 18446744071563114495, protocol_version = 10, field_count = 0, server_status = 2, server_language = 33,
warning_count = 0, options = {connect_timeout = 0, read_timeout = 0, write_timeout = 0, port = 0, protocol = 0, client_flag = 0,
host = 0x0, user = 0x0, password = 0x0, unix_socket = 0x0, db = 0x0, init_commands = 0x0, my_cnf_file = 0x0,
my_cnf_group = 0x0, charset_dir = 0x0, charset_name = 0x0, ssl_key = 0x0, ssl_cert = 0x0, ssl_ca = 0x0, ssl_capath = 0x0,
ssl_cipher = 0x0, shared_memory_base_name = 0x0, max_allowed_packet = 0, use_ssl = 0 '\000', compress = 0 '\000',
named_pipe = 0 '\000', unused1 = 0 '\000', unused2 = 0 '\000', unused3 = 0 '\000', unused4 = 0 '\000',
methods_to_use = MYSQL_OPT_CONNECT_TIMEOUT, client_ip = 0x0, secure_auth = 0 '\000', report_data_truncation = 0 '\000',
local_infile_init = 0, local_infile_read = 0, local_infile_end = 0, local_infile_error = 0, local_infile_userdata = 0x0,
extension = 0x0}, status = MYSQL_STATUS_READY, free_me = 0 '\000', reconnect = 1 '\001', scramble = "[k)(,EVacN<#96B(?E{_",
unused1 = 0 '\000', unused2 = 0x0, unused3 = 0x0, unused4 = 0x0, unused5 = 0x0, stmts = 0x0, methods = 0x2aaaab650100,
thd = 0x0, unbuffered_fetch_owner = 0x0, **info_buffer = 0x1 <Address 0x1 out of bounds>**, extension = 0x2aaaabebb708}