2013-06-21 29 views
1

回覆瞭如何將自定義LLDB類型摘要添加到Xcode中的a question。我發現我們可以通過加載一個Python腳本來實現。如何加載多個lldb類型摘要Python文件?

但是,我想知道是否有一種方法來加載多個Python文件?我與許多不同的項目一起工作,所以我想要爲我的所有項目中使用的一般類型提供1個摘要文件,併爲項目特定類型提供1個摘要文件。


〜/ MyGenericSummaries.py

import lldb 

def __lldb_init_module(debugger, dictionary): 
    debugger.HandleCommand('type summary add --summary-string "these are words" MyGenericClass'); 

〜/ MyProjectSummaries.py

import lldb 

def __lldb_init_module(debugger, dictionary): 
    debugger.HandleCommand('type summary add --summary-string "these are more words" MyProjectClass'); 

〜/ .lldbinit

command script import ~/MyGenericSummaries.py 
command script import ~/MyProjectSummaries.py 

這從來沒有加載MyProjectSummaries.py類型總結 - LLDB只是告訴我

error: module importing failed: module already imported

是否有可能保持通用摘要和項目總結在單獨的文件?這真的有幫助,因爲我有一些類型名稱在不同的項目中衝突,所以我寧願將它們分開。

非常感謝:)

回答

1

好,我知道了......隨着一些Python魔法:


〜/ MyGenericSummaries.py

import lldb 

def doLoad(debugger, dictionary): 
    debugger.HandleCommand('type summary add --summary-string "these are words" MyGenericClass'); 

def __lldb_init_module(debugger, dictionary): 
    doLoad(debugger, dictionary); 

〜/ MyProjectSummaries.py

import lldb 
from MyGenericSummaries import doLoad 

def __lldb_init_module(debugger, dictionary): 
    doLoad(debugger, dictionary); 
    debugger.HandleCommand('type summary add --summary-string "these are more words" MyProjectClass'); 

〜/ .lldbinit

command script import ~/MyProjectSummaries.py 

唯一的缺點是,我需要調整.lldbinit並重新啓動的Xcode,每次我切換項目,但是這件事情我可以住在一起。

+0

已發現更多關於可以進入'Handle Command'的文檔 – carbonr

1

我不清楚爲什麼原始代碼不起作用。從你引用的內容來看,我希望這能夠起作用。

你當然可以command script import~/.lldbinit文件中的多個Python文件 - 我一直這麼做。從錯誤消息看,您的~/.lldbinit已經有command script import ~/MyProjectSummaries.py了。小心尋找一個~/.lldbinit-Xcode,它也是在運行Xcode時產生的(或者如果使用的是命令行lldb,則使用~/.lldbinit-lldb。對於正在使用的任何lldb,一般形式爲~/.lldbinit-DRIVER_NAME。如果要啓用某些設置例如,僅當在Xcode中使用lldb庫時)。

您可能希望將type summary條目放在每個項目組中。如果您執行type summary list,您會看到內置摘要已分組到類別中,如libcxx,VectorTypes,CoreGraphics等。可以使用type category enable|disable|list|delete啓用或禁用這些摘要組。

命令行lldb也會在它運行的當前工作目錄中讀取.lldbinit - 儘管這對Xcode的情況沒有幫助。對於你在做什麼,你真的需要一個項目特定的lldbinit文件。如果您在~/.lldbinit文件中添加了這些類型摘要,那麼特定於項目的lldbinit可能會啓用/禁用此項目的正確類型摘要。但是現在Xcode沒有這樣的功能。