0

在Visual Studio中进行调试时,是否有任何方法可以查找指向特定地址的所有指针(如果已知它们位于当前范围内)?查找存储特定地址的所有指针

+1

不知道,但一个稍微黑客的方法可能是删除指向的对象,看看程序落在哪里。这可能会给你一个粗略的指示。 –

+1

@ dr.mo:你在开玩笑吧?免费后使用会导致失败出现在完全不相关的代码中。 –

+0

这就是为什么我说它_might_给你一个_rough_迹象 –

回答

1

对于VS2010,您可以使用宏。

  1. 打开宏窗口,点击“工具 - >宏 - >宏IDE”。
  2. 复制并粘贴下面的宏

    Imports System 
    Imports EnvDTE 
    Imports EnvDTE80 
    Imports EnvDTE90 
    Imports EnvDTE90a 
    Imports EnvDTE100 
    Imports System.Diagnostics 
    Public Module Module1  
        Sub DumpLocals() 
         Dim outputWindow As EnvDTE.OutputWindow 
         Dim address As String = "0x009efedc" 
    
         outputWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object 
         Dim currentStackFrame As EnvDTE.StackFrame 
         currentStackFrame = DTE.Debugger.CurrentStackFrame 
         outputWindow.ActivePane.OutputString("*Dumping Local Variables*" + vbCrLf) 
         For Each exp As EnvDTE.Expression In currentStackFrame.Locals 
          If exp.Value = address Then 
           outputWindow.ActivePane.OutputString("Match: " + exp.Name + " = " + exp.Value.ToString() + vbCrLf) 
          End If 
         Next 
        End Sub  
    End Module 
    

    enter image description here

  3. 设置在你的C++程序断点要列出指针。
  4. 运行你的C++程序。
  5. 当断点被击中时
  6. 回到宏窗口。
  7. 更改宏中地址变量的值。请注意,如果您不使用十六进制,则可能需要删除“0x”。
  8. 按下Ctrl + S保存宏。
  9. 仍然在宏窗口中,按F5运行宏。结果将在Output窗口中(Debug - > Windows - > Output)。 也许你甚至可以给宏添加参数并从立即窗口调用它。

P/S:此宏从http://weblogs.asp.net/scottgu/archive/2010/08/18/debugging-tips-with-visual-studio-2010.aspx

+0

你能解释多一点(即时工作在C + +)? – iajnr

+0

嘿回答变异解释多一点:) – fxam

1

错误修改,我对你的另一个更简单的解决方案。当你打断点:

  1. 打开本地窗口(调试 - > Windows - >本地)。
  2. 按Ctrl + A在本地窗口中选择所有内容。
  3. 按Ctrl + C复制
  4. 它们粘贴到Excel
  5. 排序在Excel中值列。
  6. 查找匹配的指针。