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
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);
}
8条答案
按热度按时间eanckbw91#
(This这不是你想要的,但几乎是:)
在Visual Studio中,可以在类的每个成员函数上放置断点,方法是打开 New Breakpoint 对话框并输入:
有关详细信息,请参见Link。
kiayqfof2#
以下是1800 INFORMATION的快速实现:
ghg1uchk3#
我不知道要使用什么DTE函数,但你可以非常简单地记录一个宏,它几乎可以做到这一点:
1.转到文件的顶部
1.{(搜索第一个{字符)。
现在只需要一遍又一遍地运行这个程序(ctrl - shift P重复),直到到达文件的末尾。
如果你有命名空间,那么将4.改为:
1.((在函数定义的开头搜索“(”))
1.停止增量搜索
1.{(函数体的开始)
这种东西可以无限修改以适合您的代码库
u5rb5r594#
就像康斯坦丁的方法...这看起来像是风的领域。
既然你有了cpp(即使你没有,你也可以编写一些脚本),使用windows调试工具的logger部分应该没有问题......这是一个非常方便的工具,遗憾的是很少有人使用它。
logger可以轻松调试C/COM/C++,具有丰富的符号信息,hooks/profiling/灵活的插装;
One way to activate Logger is to start CDB or WinDbg and attach to a user-mode target application as usual. Then, use the !logexts.logi or !logexts.loge extension command. This will insert code at the current breakpoint that will jump off to a routine that loads and initializes Logexts.dll in the target application process. This is referred to as "injecting Logger into the target application."
js5cn81o5#
下面是如何在WinDbg中实现类似的功能:
这将在模块
mymodule
中的类(或命名空间)CSpam
的每个方法中放置断点。我仍然在寻找Visual Studio中与此功能接近的任何东西。
mm5n2pyu6#
有一个宏,但我只用C#测试了它。
p8h8hvxi7#
这里有一个方法来做到这一点(我警告你,这是黑客):
cunj1qz18#
把这个放在文件的顶部:
然后在每个函数的开头插入DEBUG_BREAK,如下所示:
当您不再需要调试中断时,请注解该行
在文件的顶部。