what is wrong with my program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Peer::add_link (this=0x8077398, dest=0x80f6630)
    at /usr/include/c++/4.2/bits/stl_deque.h:1055
1055		if (this->_M_impl._M_finish._M_cur
(gdb) s
56		p_out_links.push_back(new Link(this, dest));
(gdb) s
1055		if (this->_M_impl._M_finish._M_cur
(gdb) s
107	      { ::new(__p) _Tp(__val); }
(gdb) s
1059		    ++this->_M_impl._M_finish._M_cur;
(gdb) s
307		  _M_t._M_insert_unique(__x);
(gdb) s
1062		  _M_push_back_aux(__x);
(gdb) s
307		  _M_t._M_insert_unique(__x);
(gdb) s
std::_Rb_tree<Peer*, Peer*, std::_Identity<Peer*>, std::less<Peer*>, std::allocator<Peer*> >::_M_insert_unique (this=0x80f6708, __v=@0xbfeb2948)
    at /usr/include/c++/4.2/bits/stl_tree.h:475
475	      { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
(gdb) s
486	      { return static_cast<_Link_type>(&this->_M_impl._M_header); }
(gdb) s
977	      while (__x != 0)
(gdb) s
486	      { return static_cast<_Link_type>(&this->_M_impl._M_header); }
(gdb) s
606				(this->_M_impl._M_header._M_left));
(gdb) s
985		if (__j == begin())
(gdb) s
606				(this->_M_impl._M_header._M_left));
(gdb) s
985		if (__j == begin())
(gdb) s
198		_M_node = _Rb_tree_decrement(_M_node);
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0xb7ecf174 in std::_Rb_tree_decrement () from /usr/lib/libstdc++.so.6
(gdb) s
Single stepping until exit from function _ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base, 
which has no line number information.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.


the fatal error arise:

No source available for "std::_Rb_tree_decrement() "

what is the reason?
How is this different from the previous thread?
http://www.cplusplus.com/forum/general/11072/
yes, but this post is more detailed, thanks
Then why not post it on the first thread?
sounds a good idea, but I think this post is different from that one
besides, how do you view this error?
besides, I try to debug the program of previous version(which runs successfully), it doesn't go through this statement below
1
2
198		_M_node = _Rb_tree_decrement(_M_node);


I think the problem is here
You're producing a segmentation fault while adding or removing something from a map or set. These kind of errors never trigger at the line that caused them, but somewhere deeper in the call stack, or when another change is made to the structure, e.g. after a number of insertions into the tree. In this case, the error triggers in the library's implementation of the red-black tree, either at the same moment that you tried to add or remove something, or some steps later. I'll need to see your code, specially the types the set or map is holding, to tell you that's causing the error.
so you mean you need me to send you the source codes? I will be glad to, thank you
No, just post them.
1
2
3
4
5
6
7
8
void Peer::add_link(PPeer dest) {
	myassert(p_po->find_link(id(), dest->id()) == NULL, "Peer::add_link: replicated link");
	p_out_links.push_back(new Link(this, dest));  // the fatal error raised by this line
	dest->add_feeder(this);
	p_po->link_added(this, dest);
}

	

the related definitions are
1
2
typedef std::deque<PLink>	LinkList;
LinkList p_out_links;


but the source codes are big
so, maybe these codes are not sufficient

Last edited on
typedef std::deque<PLink> LinkList;
That's one misleading typedef.

What does Link::Link() do? And is p_out_links modified anywhere else?
I haven't modified p_out_links
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

class Link
{
	PPeer l_to;				///< Receiver peer
	LinksStats l_stats;		///< Link statistics (app. dependent, so a separate class)

public:
	/// Constructor, with source and target peers as parameters.
	Link(PPeer from, PPeer to);

	inline PPeer to() {			///< The destination peer of the link
		return l_to;
	};

	/// A pointer to the link's LinksStats record, used to maintain
	/// purely statistical information about the link and, say, chunk
	/// flows along it.
	PLinkStats stats();

	/// Clear any simulation or statistics data associated with the link.
	/// Called for each link when the Overlay::clear() method is called.
	void clear();
};


Link::Link(PPeer from, PPeer to) : l_to(to) {};
Topic archived. No new replies allowed.