Note that there are some explanatory texts on larger screens.

plurals
  1. POgdb and debugging problems with an STL list
    primarykey
    data
    text
    <p>I recently asked a question here, and didn't get an answer I could use, unfortunately:</p> <p><a href="https://stackoverflow.com/questions/14899678/c-stl-list-functions-segfaulting-with-empty-list">C++ STL list functions segfaulting with empty list</a></p> <p>I've been trying to use gdb to debug the issue, and I have a question about what something means:</p> <p>I declare a list as a member of a class like so:</p> <pre><code>std::list&lt;Thing*&gt; inventory; </code></pre> <p>...and then instantiate the class it's in (an object called 'pc'). In gdb, I presume this shows that I have some memory allocated to it?</p> <pre><code>(gdb) p &amp;pc.inventory $7 = (std::list&lt;Thing*, std::allocator&lt;Thing*&gt; &gt; *) 0xbffff22c </code></pre> <p>Further in, one line before the problem line of the code (in essence, calling 'inventory.size()' causes a segfault), this still holds:</p> <pre><code>(gdb) p &amp;inventory $8 = (std::list&lt;Thing*, std::allocator&lt;Thing*&gt; &gt; *) 0xbffff22c </code></pre> <p>...however I still get the segfault:</p> <pre><code>(gdb) n 558 if (inventory.size() == 52) { (gdb) n Program received signal SIGSEGV, Segmentation fault. 0x0804e3fe in std::_List_const_iterator&lt;Thing*&gt;::operator++ (this=0xbfff94e0) at /usr/include/c++/4.4/bits/stl_list.h:223 223 _M_node = _M_node-&gt;_M_next; </code></pre> <p>My question is essentialy this: Surely, if I have an address for the member list, the list exists, and I should be able to use size() on it?? If not, why not? And how could I further debug?</p> <p>Thanks all!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload