有沒有宏?要使用哪個DTE對象?如何在.cpp文件的每個函數中放置斷點?
回答
我不知道是什麼DTE功能使用,但你可以非常簡單地錄製宏,可以幾乎做到這一點:
- 轉到文件
- CTRL頂部 - 轉移 - R(開始錄製)
- ctrl -I(增量搜索)
- {(搜索第一個{字符)。
- F9(設置斷點)
- CTRL - (去匹配}字符)
- CTRL - 移 - R(停止錄音)
現在只要運行這個遍地(CTRL - SHIFT P重複),直到您到達文件末尾。
如果有名稱空間,然後改變4.:
- ((搜索 「(」 在函數定義的開始)
- ESC(停止增量搜索)
- CTRL - 我(再次增量搜索)
- {(函數體開始)
這種東西可以無限修改,以適應你的代碼
我有匿名命名空間,它會工作嗎? (目前沒有VS來檢查) – Constantin 2008-10-01 22:30:07
實際上(忽略我以前的評論)它顯然會跳過命名空間中的代碼。嘗試在 – 2008-10-02 00:40:28
中編輯的更改無法在VS 2010中使用此功能 - 錄製宏時禁用增量搜索。 – 2011-07-26 19:14:12
在文件的頂部將這個:
#define WANT_BREAK_IN_EVERY_FUNCTION
#ifdef WANT_BREAK_IN_EVERY_FUNCTION
#define DEBUG_BREAK DebugBreak();
#else
#define DEBUG_BREAK
#endif
然後在每個函數的開頭插入DEBUG_BREAK,像這樣:
void function1()
{
DEBUG_BREAK
// the rest of the function
}
void function2()
{
DEBUG_BREAK
// the rest of the function
}
當你不再需要調試中斷,評論行
// #define WANT_BREAK_IN_EVERY_FUNCTION
在文件的頂部。
我想要一個不引人注目的自動化解決方案。我可以在每個功能中按F9。 – Constantin 2008-10-02 07:56:33
下面是類似的東西可以在WinDbg中實現:
bm mymodule!CSpam::*
這模塊mymodule
把斷點類(或命名空間)CSpam
的每一個方法。
我仍然在Visual Studio中尋找任何接近此功能的東西。
這裏有一個快速實施的1800信息的想法:
Sub TemporaryMacro()
DTE.ActiveDocument.Selection.StartOfDocument()
Dim returnValue As vsIncrementalSearchResult
While True
DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.StartForward()
returnValue = DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.AppendCharAndSearch(AscW("{"))
DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.Exit()
If Not (returnValue = vsIncrementalSearchResult.vsIncrementalSearchResultFound) Then
Return
End If
DTE.ExecuteCommand("Debug.ToggleBreakpoint")
DTE.ExecuteCommand("Edit.GotoBrace")
DTE.ActiveDocument.Selection.CharRight()
End While
End Sub
+1,但不能接受,因爲它不適用於名稱空間。 – Constantin 2008-12-15 08:28:34
如果您遇到命名空間問題,請將註釋轉到文檔開頭的第一行。您需要手動將光標放在要切換的塊的開頭,但它會起作用。 – tfinniga 2010-08-02 16:00:07
像康斯坦丁的方法......這似乎是WinDbg的領土。
既然你有cpp(即使你沒有腳本可以編寫腳本),使用logger作爲windows調試工具的一部分應該沒有問題......這是一個非常方便的工具,可惜很少有人使用它。
記錄器調試的C/COM/C + +輕鬆,具有豐富的符號信息,鉤/分析/靈活的儀器;
(這不是你問了好東西,但幾乎:)
您可以通過打開將斷點上每個成員函數的類在Visual Studio中新建斷點對話框並輸入:
CMyClass::*
有一個宏,但我只用c#測試它。
Sub BreakAtEveryFunction()
For Each project In DTE.Solution.Projects
SetBreakpointOnEveryFunction(project)
Next project
End Sub
Sub SetBreakpointOnEveryFunction(ByVal project As Project)
Dim cm = project.CodeModel
' Look for all the namespaces and classes in the
' project.
Dim list As List(Of CodeFunction)
list = New List(Of CodeFunction)
Dim ce As CodeElement
For Each ce In cm.CodeElements
If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then
' Determine whether that namespace or class
' contains other classes.
GetClass(ce, list)
End If
Next
For Each cf As CodeFunction In list
DTE.Debugger.Breakpoints.Add(cf.FullName)
Next
End Sub
Sub GetClass(ByVal ct As CodeElement, ByRef list As List(Of CodeFunction))
' Determine whether there are nested namespaces or classes that
' might contain other classes.
Dim aspace As CodeNamespace
Dim ce As CodeElement
Dim cn As CodeNamespace
Dim cc As CodeClass
Dim elements As CodeElements
If (TypeOf ct Is CodeNamespace) Then
cn = CType(ct, CodeNamespace)
elements = cn.Members
Else
cc = CType(ct, CodeClass)
elements = cc.Members
End If
Try
For Each ce In elements
If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then
GetClass(ce, list)
End If
If (TypeOf ce Is CodeFunction) Then
list.Add(ce)
End If
Next
Catch
End Try
End Sub
下面是做這件事(我警告你,這是哈克):
EnvDTE.TextSelection textSelection = (EnvDTE.TextSelection)dte.ActiveWindow.Selection;
// I'm sure there's a better way to get the line count than this...
var lines = File.ReadAllLines(dte.ActiveDocument.FullName).Length;
var methods = new List<CodeElement>();
var oldLine = textSelection.AnchorPoint.Line;
var oldLineOffset = textSelection.AnchorPoint.LineCharOffset;
EnvDTE.CodeElement codeElement = null;
for (var i = 0; i < lines; i++)
{
try
{
textSelection.MoveToLineAndOffset(i, 1);
// I'm sure there's a better way to get a code element by point than this...
codeElement = textSelection.ActivePoint.CodeElement[vsCMElement.vsCMElementFunction];
if (codeElement != null)
{
if (!methods.Contains(codeElement))
{
methods.Add(codeElement);
}
}
}
catch
{
//MessageBox.Show("Add error handling here.");
}
}
// Restore cursor position
textSelection.MoveToLineAndOffset(oldLine, oldLineOffset);
// This could be in the for-loop above, but it's here instead just for
// clarity of the two separate jobs; find all methods, then add the
// breakpoints
foreach (var method in methods)
{
dte.Debugger.Breakpoints.Add(
Line: method.StartPoint.Line,
File: dte.ActiveDocument.FullName);
}
- 1. 在visual studio中,如何在JavaScript文件的每個函數中添加斷點?
- 2. 如何在eclipse中的每個函數中安裝斷點?
- 3. 在命名函數上放置斷點
- 4. 如何在我的應用程序的每個MessageBox中放置一個斷點?
- 5. 如何在libc中放置斷點?
- 6. 如何在另一個.cpp文件中使用函數?
- 7. C++ Win32如何將這個函數放在單獨的cpp文件上?
- 8. gdb,在文件中的所有函數上設置斷點
- 9. 如何判斷.cpp文件位於
- 10. 如何在通過verilog pli調用的.so文件中定義的函數上放置斷點
- 11. 如何在使用Webpack時在node_modules下的TypeScript文件中放置斷點
- 12. cpp文件中函數的順序
- 13. 如何在R-studio的函數體中設置斷點?
- 14. 如何在Windbg的析構函數中設置斷點?
- 15. 如何在提琴手中放置多個斷點?
- 16. 如何在dbx中的內存位置放置斷點?
- 17. 在同一cpp文件中的兩個rcpp函數
- 18. 如何在Visual Studio 2010中的cshtml文件中設置斷點?
- 19. 如何在VS2010中的每種方法中設置斷點
- 20. Visual Studio 2010:是否有任何函數可以在.cpp文件中的所有行處創建斷點?
- 21. 不能在asp.net主頁面文件中放置斷點
- 22. 如何使用共享庫函數在gdb中設置斷點
- 23. 如何在Xcode4中爲函數設置斷點?
- 24. 如何將jQuery函數放置在* .js文件中?
- 25. 將類聲明放在.cpp文件中
- 26. 如何解析cpp文件中的函數以訪問循環
- 27. 從CPP文件中挖掘函數
- 28. 如何在R中的每個文件上應用此函數?
- 29. 如何設置gdb中的python函數的斷點
- 30. gdb:如何在帶空格的文件中設置斷點
今天我見過的最強的論點停止開發Windows下和使用的工具的linux如GDB即會讓你在文件上斷點。 – Owl 2017-06-16 13:36:05