2011-06-02 95 views
16

我使用Qt Creator的使用gdb調試在Linux平臺上我的C++代碼。每當我使用boost::shared_ptr或類似物,調試程序步驟進入含有升壓執行的頭文件(即在/ usr /包括/boost/shared_ptr.hpp)。我想忽略這些文件在調試方面,並簡單地跨過它們。我知道一旦它到達其中一個文件就可以走出去,但是如果每次調試會話都沒有這麼做,調試將變得更加容易。 (它使用gdb作爲調試器)我可以阻止調試器進入Boost或STL頭文件嗎?

我使用gcc編譯器(g++),與QtCreator 2.2在openSUSE 11.2的Linux運行

編輯補充:這個問題向升壓文件面向,但可以也適用於STL文件。

+1

這個怎麼樣?:http://stackoverflow.com/questions/1133365 – 0xC0000022L 2011-06-02 21:14:14

+0

@STATUS,謝謝。這個問題聽起來像是不可能的,至少是自動的,除非目標代碼和動態庫代碼之間存在差異。 – Chance 2011-06-06 14:39:16

回答

0

而不是做S(步驟),你可以
B關於要停止你的函數的第一行(B類::方法,或b file.cpp:行),
則c。

GDB將繞過提升代碼,並在休息,你想讓它

這工作,但似乎乏味b中給出的點。這是習慣的問題。重複變得更容易。

msvc的行爲與gdb相似

3

gdb是可編寫腳本的。它有,而如果,變量,shell子命令,用戶定義的函數(定義)等等等,它具有python接口的腳本功能。

有了一些工作,你可以讓GDB腳本沿着這些線路:

define step-bypass-boost 
    step 
    while 1 
    use "info source", put current source file into variable 
    if source file does not match */boost/* then 
     break-loop 
    end 
    step 
    end 
end 

或發現是否有人已經做了這樣的腳本

3

GDB沒有步入STL和所有其他庫在/ usr

把你.gdbinit文件以下。它搜索通過GDB已加載或將可能加載(GDB命令info sources)的源,並且當它們的絕對路徑以「/ USR」開始跳過它們。它掛鉤了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>)跳過其他目錄也是如此。

+0

不幸的是,該解決方案適用於gcc,但不適用於icc16。無論如何,謝謝你! – shargors 2018-02-21 22:01:30

相關問題