在MODE=release
中调试时,我在执行应用程序代码时遇到问题。而它在调试模式下执行时没有问题。
我尝试调试代码并尝试了几乎所有绑定到我的容量的东西,而且我没有选择。
下面我提供gdb
,valgring
的输出和原始应用程序代码。我希望有人可以指导我解决问题。
GDB:
Program received signal SIGSEGV, Segmentation fault.
Mac1609_4::EDCA::queuePacket (this=0x0, ac=Mac1609_4::AC_VO, msg=0x11f8da0)
at veins/modules/mac/ieee80211p/Mac1609_4.cc:582
582 if (maxQueueSize && myQueues[ac].queue.size() >= maxQueueSize) { // FIXME: crash here
(gdb) bt
#0 Mac1609_4::EDCA::queuePacket (this=0x0, ac=Mac1609_4::AC_VO, msg=0x11f8da0)
at veins/modules/mac/ieee80211p/Mac1609_4.cc:582
#1 0x00007fffeff6d54d in Mac1609_4::handleUpperMsg (this=0x117bb20, msg=
0x11f8da0) at veins/modules/mac/ieee80211p/Mac1609_4.cc:306
#2 0x00007fffefe756c9 in BaseLayer::handleMessage (this=0x117bb20,
msg=0x11f8da0) at veins/base/modules/BaseLayer.cc:81
#3 0x00007ffff6f2843e in cSimulation::doOneEvent (this=0x764ad0, mod=
0x117bb20) at csimulation.cc:617
#4 0x00007ffff72a10c1 in Cmdenv::simulate (this=0x7648e0) at cmdenv.cc:425
#5 0x00007ffff72a090e in Cmdenv::run (this=0x7648e0) at cmdenv.cc:292
#6 0x00007ffff77d3e03 in EnvirBase::run (this=0x7648e0, argc=11,
argv=0x7fffffffe008, configobject=0x740630) at envirbase.cc:279
#7 0x00007ffff77d13fc in setupUserInterface (argc=11, argv=0x7fffffffe008)
at startup.cc:239
#8 0x00007ffff77d1c52 in evMain (argc=11, argv=0x7fffffffe008) at evmain.cc:38
#9 0x00000000004017db in main (argc=11, argv=0x7fffffffe008) at opp_run.cc:298
在gdb中打印:请注意与valgrind输出对应的maxQueueSize
(0x3c
)的地址
(gdb) p this
$1 = (Mac1609_4::EDCA *) 0x0
(gdb) p maxQueueSize
Cannot access memory at address 0x3c
(gdb) p myQueues
Cannot access memory at address 0x8
(gdb) p myQueues[ac].queue.size()
Attempt to take address of value not located in memory.
Valgrind:对于相同的功能,即queuePacket()
Valgrind说:
==10224== Conditional jump or move depends on uninitialised value(s)
==10224== at 0xD043749: std::_Rb_tree<t_channel, std::pair<t_channel const, Mac1609_4::EDCA*>, std::_Select1st<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::_M_lower_bound(std::_Rb_tree_node<std::pair<t_channel const, Mac1609_4::EDCA*> >*, std::_Rb_tree_node<std::pair<t_channel const, Mac1609_4::EDCA*> >*, t_channel const&) (stl_tree.h:1141)
==10224== by 0xD0436F0: std::_Rb_tree<t_channel, std::pair<t_channel const, Mac1609_4::EDCA*>, std::_Select1st<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::lower_bound(t_channel const&) (stl_tree.h:879)
==10224== by 0xD0426CC: std::map<t_channel, Mac1609_4::EDCA*, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::lower_bound(t_channel const&) (stl_map.h:864)
==10224== by 0xD03E6CE: std::map<t_channel, Mac1609_4::EDCA*, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::operator[](t_channel const&) (stl_map.h:461)
==10224== by 0xD03B54D: Mac1609_4::handleUpperMsg(cMessage*) (Mac1609_4.cc:306)
==10224== by 0xCF43DB8: BaseLayer::handleMessage(cMessage*) (BaseLayer.cc:81)
==10224== by 0x5B7543D: cSimulation::doOneEvent(cSimpleModule*) (csimulation.cc:617)
==10224== by 0x57740C0: Cmdenv::simulate() (cmdenv.cc:425)
==10224== by 0x577390D: Cmdenv::run() (cmdenv.cc:292)
==10224== by 0x5225E02: EnvirBase::run(int, char**, cConfiguration*) (envirbase.cc:279)
==10224== by 0x52233FB: setupUserInterface(int, char**) (startup.cc:239)
==10224== by 0x5223C51: evMain (evmain.cc:38)
==10224==
==10224== Conditional jump or move depends on uninitialised value(s)
==10224== at 0xD042B45: std::_Rb_tree<t_channel, std::pair<t_channel const, Mac1609_4::EDCA*>, std::_Select1st<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<t_channel const, Mac1609_4::EDCA*> >, t_channel const&) (stl_tree.h:1422)
==10224== by 0xD04280C: std::_Rb_tree_iterator<std::pair<t_channel const, Mac1609_4::EDCA*> > std::_Rb_tree<t_channel, std::pair<t_channel const, Mac1609_4::EDCA*>, std::_Select1st<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<t_channel const&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::piecewise_construct_t const&, std::tuple<t_channel const&>&&, std::tuple<>&&) (stl_tree.h:1673)
==10224== by 0xD03E761: std::map<t_channel, Mac1609_4::EDCA*, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::operator[](t_channel const&) (stl_map.h:465)
==10224== by 0xD03B54D: Mac1609_4::handleUpperMsg(cMessage*) (Mac1609_4.cc:306)
==10224== by 0xCF43DB8: BaseLayer::handleMessage(cMessage*) (BaseLayer.cc:81)
==10224== by 0x5B7543D: cSimulation::doOneEvent(cSimpleModule*) (csimulation.cc:617)
==10224== by 0x57740C0: Cmdenv::simulate() (cmdenv.cc:425)
==10224== by 0x577390D: Cmdenv::run() (cmdenv.cc:292)
==10224== by 0x5225E02: EnvirBase::run(int, char**, cConfiguration*) (envirbase.cc:279)
==10224== by 0x52233FB: setupUserInterface(int, char**) (startup.cc:239)
==10224== by 0x5223C51: evMain (evmain.cc:38)
==10224== by 0x4017DA: main (opp_run.cc:298)
==10224==
==10224== Conditional jump or move depends on uninitialised value(s)
==10224== at 0x6A8FC0F: std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==10224== by 0xD042EE1: std::_Rb_tree<t_channel, std::pair<t_channel const, Mac1609_4::EDCA*>, std::_Select1st<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::_M_insert_node(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node<std::pair<t_channel const, Mac1609_4::EDCA*> >*) (stl_tree.h:1575)
==10224== by 0xD042858: std::_Rb_tree_iterator<std::pair<t_channel const, Mac1609_4::EDCA*> > std::_Rb_tree<t_channel, std::pair<t_channel const, Mac1609_4::EDCA*>, std::_Select1st<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<t_channel const&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<t_channel const, Mac1609_4::EDCA*> >, std::piecewise_construct_t const&, std::tuple<t_channel const&>&&, std::tuple<>&&) (stl_tree.h:1676)
==10224== by 0xD03E761: std::map<t_channel, Mac1609_4::EDCA*, std::less<t_channel>, std::allocator<std::pair<t_channel const, Mac1609_4::EDCA*> > >::operator[](t_channel const&) (stl_map.h:465)
==10224== by 0xD03B54D: Mac1609_4::handleUpperMsg(cMessage*) (Mac1609_4.cc:306)
==10224== by 0xCF43DB8: BaseLayer::handleMessage(cMessage*) (BaseLayer.cc:81)
==10224== by 0x5B7543D: cSimulation::doOneEvent(cSimpleModule*) (csimulation.cc:617)
==10224== by 0x57740C0: Cmdenv::simulate() (cmdenv.cc:425)
==10224== by 0x577390D: Cmdenv::run() (cmdenv.cc:292)
==10224== by 0x5225E02: EnvirBase::run(int, char**, cConfiguration*) (envirbase.cc:279)
==10224== by 0x52233FB: setupUserInterface(int, char**) (startup.cc:239)
==10224== by 0x5223C51: evMain (evmain.cc:38)
==10224==
==10224== Invalid read of size 4
==10224== at 0xD03B987: Mac1609_4::EDCA::queuePacket(Mac1609_4::t_access_category, WaveShortMessage*) (Mac1609_4.cc:582)
==10224== by 0xD03B55C: Mac1609_4::handleUpperMsg(cMessage*) (Mac1609_4.cc:306)
==10224== by 0xCF43DB8: BaseLayer::handleMessage(cMessage*) (BaseLayer.cc:81)
==10224== by 0x5B7543D: cSimulation::doOneEvent(cSimpleModule*) (csimulation.cc:617)
==10224== by 0x57740C0: Cmdenv::simulate() (cmdenv.cc:425)
==10224== by 0x577390D: Cmdenv::run() (cmdenv.cc:292)
==10224== by 0x5225E02: EnvirBase::run(int, char**, cConfiguration*) (envirbase.cc:279)
==10224== by 0x52233FB: setupUserInterface(int, char**) (startup.cc:239)
==10224== by 0x5223C51: evMain (evmain.cc:38)
==10224== by 0x4017DA: main (opp_run.cc:298)
==10224== Address 0x3c is not stack'd, malloc'd or (recently) free'd
==10224==
==10224==
==10224== Process terminating with default action of signal 11 (SIGSEGV)
==10224== Access not within mapped region at address 0x3C
==10224== at 0xD03B987: Mac1609_4::EDCA::queuePacket(Mac1609_4::t_access_category, WaveShortMessage*) (Mac1609_4.cc:582)
==10224== by 0xD03B55C: Mac1609_4::handleUpperMsg(cMessage*) (Mac1609_4.cc:306)
==10224== by 0xCF43DB8: BaseLayer::handleMessage(cMessage*) (BaseLayer.cc:81)
==10224== by 0x5B7543D: cSimulation::doOneEvent(cSimpleModule*) (csimulation.cc:617)
==10224== by 0x57740C0: Cmdenv::simulate() (cmdenv.cc:425)
==10224== by 0x577390D: Cmdenv::run() (cmdenv.cc:292)
==10224== by 0x5225E02: EnvirBase::run(int, char**, cConfiguration*) (envirbase.cc:279)
==10224== by 0x52233FB: setupUserInterface(int, char**) (startup.cc:239)
==10224== by 0x5223C51: evMain (evmain.cc:38)
==10224== by 0x4017DA: main (opp_run.cc:298)
==10224== If you believe this happened as a result of a stack
==10224== overflow in your program's main thread (unlikely but
==10224== possible), you can try to increase the size of the
==10224== main thread stack using the --main-stacksize= flag.
==10224== The main thread stack size used in this run was 8388608.
==10224==
==10224== HEAP SUMMARY:
==10224== in use at exit: 10,620,167 bytes in 137,073 blocks
==10224== total heap usage: 891,187 allocs, 754,114 frees, 88,925,514 bytes allocated
C ++中的原始函数:
int Mac1609_4::EDCA::queuePacket(t_access_category ac,WaveShortMessage* msg) {
if (maxQueueSize && myQueues[ac].queue.size() >= maxQueueSize) { // FIXME: crash here
delete msg;
return -1;
}
myQueues[ac].queue.push(msg);
return myQueues[ac].queue.size();
}
更新1:以下代码遭到投诉,并按照@PaulMcKenzie和@WhozCraig的建议,按照正确的map::erase()
使用情况解决了问题:How can I delete elements of a std::map with an iterator?
C ++中的原始函数: getNonCrossingRoads()
std::map<TraCIRoad*, std::list<std::pair<Coord, Coord> > > structure = getTrafficLightStructure();
std::set<std::string> allLanes = cccTable.getLanes();
for (auto it : structure){ // FIXME: problem occurs here
TraCIRoad* road = it.first;
auto found = allLanes.find(road->getEndLane());
if(found == allLanes.end()) {
structure.erase(road);
}
}