私は Linux プラットフォームで C++ コードをデバッグするために、Qt Creator と gdb を使用しています。boost::shared_ptr
などを使用するたびに、デバッガーは boost 実装を含むヘッダー ファイル (つまり /usr/include /boost/shared_ptr.hpp
) にステップインします。デバッグではこれらのファイルを無視し、単にステップ オーバーしたいと思います。これらのファイルのいずれかに到達したらすぐにステップ アウトできることはわかっていますが、デバッグ セッションごとに何度もステップ アウトするよりも、デバッグがはるかに簡単になります。
私は gcc コンパイラ ( g++
) を使用しており、OpenSuSE Linux 11.2 上で QtCreator 2.2 (gdb
デバッガーとして使用) を実行しています。
編集して追加: この質問は Boost ファイル向けですが、STL ファイルにも当てはまる可能性があります。
ベストアンサー1
STL および /usr 内の他のすべてのライブラリにステップインしない GDB:
ファイルに次のコードを入れます.gdbinit
。gdb がロードした、またはロードする可能性のあるソース (gdb コマンド) を検索し、絶対パスが "/usr" で始まる場合はスキップします。コマンドを実行するとシンボルが再ロードされる可能性があるため、コマンドinfo sources
にフックされます。run
# skip all STL source files
define skipstl
python
# get all sources loadable by gdb
def GetSources():
sources = []
for line in gdb.execute('info sources',to_string=True).splitlines():
if line.startswith("/"):
sources += [source.strip() for source in line.split(",")]
return sources
# skip files of which the (absolute) path begins with 'dir'
def SkipDir(dir):
sources = GetSources()
for source in sources:
if source.startswith(dir):
gdb.execute('skip file %s' % source, to_string=True)
# apply only for c++
if 'c++' in gdb.execute('show language', to_string=True):
SkipDir("/usr")
end
end
define hookpost-run
skipstl
end
スキップするファイルのリストをチェックするには、どこかにブレークポイント (例: break main
) を設定し、gdb (例: run
) を実行して、info sources
ブレークポイントに到達したら でチェックします。
(gdb) info skip
Num Type Enb What
1 file y /usr/include/c++/5/bits/unordered_map.h
2 file y /usr/include/c++/5/bits/stl_set.h
3 file y /usr/include/c++/5/bits/stl_map.h
4 file y /usr/include/c++/5/bits/stl_vector.h
...
の呼び出しを追加することで、これを拡張して他のディレクトリもスキップするのは簡単ですSkipDir(<some/absolute/path>)
。