奇妙な問題があります。std::map を内部的に参照する工場登録パターンを使用しています。私はこのアプローチを複数のコンポーネントに使用しており、登録はさまざまなコンパイル単位 (別名 .cpp ファイル) の複数のポイントで行われます。これは、静的変数の初期化時 (「main」が呼び出される前) に発生します。何らかの奇妙な理由で、参照しているときにセグメンテーション違反が発生します
map[key] = value;
(基本的に、特定の pfn を登録するとき)。ここで、問題のある特定のコンポーネントの登録を同じコンパイル ユニットに移動すると、すべてが機能します。ここでも、コンポーネントの登録を 1 つだけ戻すと、segfault が発生します。
このパターンを使用するのはこれが初めてではなく、他のコンポーネントの同じ実行可能ファイルで機能します (つまり、別のファクトリ タイプの複数の .cpp にまたがるコンポーネントは、基本的に同様のソース コードを使用して、初期化時に問題なく登録されます)。 .
私は何をすべきか?今のところ、コンポーネントの登録を同じ .cpp に残しました (そして問題なく動作します)。どうすればもっとよく調査できますか?
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 を使用しています
スタックトレースの下
/usr/lib/libstdc++.so.6 からの std::_Rb_tree_decrement(std::_Rb_tree_node_base*) の 0x00007ffff793da1a (gdb) ところで #0 0x00007ffff793da1a in std::_Rb_tree_decrement(std::_Rb_tree_node_base*) () from /usr/lib/libstdc++.so.6 #1 std::_Rb_tree_iterator の 0x0000000000413fe9、std::allocator > const、http::servlet* (*)()> >::operator-- ( this=0x7fffffffdff0) /usr/include/c++/4.4/bits/stl_tree.h:199 で #2 std::_Rb_tree で 0x000000000041379d、std::allocator >、std::pair、std::allocator > const、http::servlet* (*)()>、std::_Select1st、std::allocator > const , http::servlet* (*)()> >, std::less, std::allocator > >, std::allocator, std::allocator > const, http::servlet* (*)()> > >::_M_insert_unique (this=0x632a20, __v=...) /usr/include/c++/4.4/bits/stl_tree.h:1179 #3 0x00000000004125f2 in std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, http::servlet* (*)()>, std::_Select1st, std::allocator > const , http::servlet* (*)()> >, std::less, std::allocator > >, std::allocator, std::allocator > const, http::servlet* (*)()> > >::_M_insert_unique_ (this=0x632a20, __position=..., __v=...) /usr/include/c++/4.4/bits/stl_tree.h:1217 #4 0x00000000004116c4 in std::map, std::allocator >, http::servlet* (*)(), std::less, std::allocator > >, std::allocator, std::allocator > const, http::サーブレット* (*)()> > >::挿入 ( this=0x632a20, __position=..., __x=...) /usr/include/c++/4.4/bits/stl_map.h:540 に #5 0x0000000000410a63 in std::map, std::allocator >, http::servlet* (*)(), std::less, std::allocator > >, std::allocator, std::allocator > const, http::サーブレット* (*)()> > >::operator[] ( this=0x632a20, __k=...) /usr/include/c++/4.4/bits/stl_map.h:450 に #6 http::servlet::add_creator の 0x000000000040e3b1 (type=0x4234d0 "/gpu/european_opt_xyz", func=0x421567 ) ./src/http.cpp:336 で