Interpreting GDB output

closed account (3872Nwbp)
Been working on a Seg fault for a while now, I've run my program through Valgrind and GDB, I'm having a hard time interpreting the output though.

I've included the output from GDB, and I'm looking for help understanding the output from these two programs. Specifically, I'm looking for comments on the first 4 frames of the GDB output.

GDB:
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
GNU gdb (GDB) 7.8.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-unknown-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 ./Swift2...done.

warning: exec file is newer than core file.
[New LWP 10524]
[New LWP 10532]
[New LWP 10531]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Core was generated by `'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000000000043e9d0 in std::_Hashtable<std::string, std::pair<std::string const, swift::Component*>, std::allocator<std::pair<std::string const, swift::Component*> >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_find_before_node (this=0xffeffd460, __n=1468669806, __k=..., 
    __code=7974810623683050230) at /usr/include/c++/4.9.2/bits/hashtable.h:1438
1438	      __node_base* __prev_p = _M_buckets[__n];
(gdb) bt
#0  0x000000000043e9d0 in std::_Hashtable<std::string, std::pair<std::string const, swift::Component*>, std::allocator<std::pair<std::string const, swift::Component*> >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_find_before_node (this=0xffeffd460, __n=1468669806, 
    __k="Noisy", __code=7974810623683050230)
    at /usr/include/c++/4.9.2/bits/hashtable.h:1438
#1  0x00000000004399a8 in std::_Hashtable<std::string, std::pair<std::string const, swift::Component*>, std::allocator<std::pair<std::string const, swift::Component*> >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_find_node (this=0xffeffd460, __bkt=1468669806, __key="Noisy", 
    __c=7974810623683050230) at /usr/include/c++/4.9.2/bits/hashtable.h:625
#2  0x0000000000435530 in std::_Hashtable<std::string, std::pair<std::string const, swift::Component*>, std::allocator<std::pair<std::string const, swift::Component*> >, std::__detail::_Select1st, std::equal_to<std::string>, std::hash<std::string>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::find (this=0xffeffd460, __k="Noisy")
    at /usr/include/c++/4.9.2/bits/hashtable.h:1321
#3  0x0000000000432149 in std::unordered_map<std::string, swift::Component*, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, swift::Component*> > >::find (this=0xffeffd460, __x="Noisy")
    at /usr/include/c++/4.9.2/bits/unordered_map.h:578
#4  0x00000000004311ab in swift::Entity::has (this=0xffeffd460, c="Noisy")
    at /home/alec/Code/Swift2/src/Scripting/../EntitySystem/Entity.hpp:125
#5  0x0000000000430114 in swift::Script::has (e=0xffeffd460, c="Noisy")
    at /home/alec/Code/Swift2/src/Scripting/Script.cpp:430
#6  0x000000000043b23e in std::_Function_handler<bool (swift::Entity*, std::string), bool (*)(swift::Entity*, std::string)>::_M_invoke(std::_Any_data const&, swift::Entity*, std::string) (__functor=..., __args#0=0xffeffd460, __args#1="")
    at /usr/include/c++/4.9.2/functional:2025
#7  0x000000000044aa35 in std::function<bool (swift::Entity*, std::string)>::operator()(swift::Entity*, std::string) const (this=0xf27c318, 
    __args#0=0xffeffd460, __args#1="")
    at /usr/include/c++/4.9.2/functional:2439
#8  0x0000000000449358 in detail::tupleToPack<bool, swift::Entity*, std::string, 0ul, 1ul>(std::function<bool (swift::Entity*, std::string)> const&, std::tuple<swift::Entity*, std::string> const&, detail::indices<0ul, 1ul>) (func=..., 
    args=std::tuple containing = {...})
    at /home/alec/Code/Swift2/src/Scripting/LuaCpp/Details/Details.hpp:255
#9  0x00000000004460c9 in detail::tupleToPack<bool, swift::Entity*, std::string>(std::function<bool (swift::Entity*, std::string)> const&, std::tuple<swift::Entity*, std::string>) (func=..., args=std::tuple containing = {...})
    at /home/alec/Code/Swift2/src/Scripting/LuaCpp/Details/Details.hpp:261
#10 0x000000000044514a in lpp::CppFunction<bool, swift::Entity*, std::string>::run (this=0xf27c310, state=0xf277700)
    at /home/alec/Code/Swift2/src/Scripting/LuaCpp/Details/CppFunction.hpp:48
#11 0x0000000000430be1 in lpp::BaseCppFunction::luaDispatcher (state=0xf277700)
    at /home/alec/Code/Swift2/src/Scripting/LuaCpp/Details/CppFunction.hpp:21
#12 0x000000000048575d in luaD_precall ()
#13 0x000000000048f48d in luaV_execute ()
#14 0x0000000000485ab8 in luaD_call ()
#15 0x0000000000485139 in luaD_rawrunprotected ()
#16 0x0000000000485ce1 in luaD_pcall ()
#17 0x0000000000483984 in lua_pcallk ()
#18 0x00000000004321dc in lpp::Selection::operator()<>() (this=0xffeffd800)
    at /home/alec/Code/Swift2/src/Scripting/LuaCpp/Details/Selection.hpp:74
#19 0x000000000042cdf2 in swift::Script::update (this=0xe8d05b0)
    at /home/alec/Code/Swift2/src/Scripting/Script.cpp:68
#20 0x000000000046769f in swift::Play::update (this=0xee0a800, dt=...)
    at /home/alec/Code/Swift2/src/StateSystem/States/Play.cpp:152
#21 0x000000000040a6c1 in swift::Game::update (this=0xffeffda40, dt=...)
    at /home/alec/Code/Swift2/src/Game.cpp:174
#22 0x000000000040a398 in swift::Game::gameLoop (this=0xffeffda40)
    at /home/alec/Code/Swift2/src/Game.cpp:133
#23 0x00000000004105d8 in main (argc=1, argv=0xffefff9b8)
    at /home/alec/Code/Swift2/test/main.cpp:9
(gdb) 


Thanks for any comments.
Last edited on
Can't know much without knowing the flow of your program. Your segmentation fault is caused by breaching the memory allocated to the program by the system (you're pretty much indexing an array you're trying to access incorrectly). The error output by GDB is giving you files and line numbers where it's finding errors in your code, so I would bet if you check on/around those lines it spits out, you'd find the source of segmentation fault.
closed account (3872Nwbp)
Well, I'm using std::unordered_map<std::string, Component*>::find. That's the last place in my code the segfault path occurs.
This is happening in an Entity-Component-System pattern. I have a function:
1
2
3
4
bool Entity::has(const std::string& c)
{
    return components.find(c) != components.end();
}


GDB goes into the call to find there.

This function is called via a call from a static wrapper function for Lua, which is called from a Lua script.

I've stepped through my whole program with GDB, and my pointers/references/values are all valid, expected data through the call to find. It's once the compare method for std::string gets called, the program segfaults.

So, I know the where, I just don't know the why. It seems like, when comparing keys to my std::string set in Entity::has, a std::pair in the unordered_map gets invalidated at some point. It's there, that I get lost.

I'm on GCC 4.9.2 btw.

Here's a list of lines and files mentioned in the GDB output:
- https://github.com/dabbertorres/Swift2/blob/master/src/StateSystem/States/Play.cpp#L152
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/Script.cpp#L68
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/LuaCpp/Details/Selection.hpp#L74
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/LuaCpp/Details/CppFunction.hpp#L21
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/LuaCpp/Details/CppFunction.hpp#L48
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/LuaCpp/Details/Details.hpp#L261
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/LuaCpp/Details/Details.hpp#L255
- https://github.com/dabbertorres/Swift2/blob/master/src/Scripting/Script.cpp#L430
- https://github.com/dabbertorres/Swift2/blob/master/src/EntitySystem/Entity.hpp#L125
Topic archived. No new replies allowed.