c++ - GetThreadContext 寄存器总是返回 0xCCCCCCCC

标签 c++ windows winapi msdn

我正在尝试利用 GetThreadContext 查看当前调试寄存器的设置。无论我调试什么程序,它都返回0xCCCCCCCC。我能够成功设置断点 ctx.Dr0,然后使用自定义异常处理程序捕获这些中断,但如果我尝试查看存储在 ctx.Dr0 的地址,它总是显示为 0xCCCCCCCC。这是为什么?

谢谢

    CONTEXT ctx;
    GetThreadContext(GetCurrentThread(),&ctx);
    cout << hex << ctx.Eip << endl;

编辑**

我觉得我的问题问得不够好,因为当时我没有意识到我的思路有问题。我实际上是在尝试从我想要获取其上下文的线程中调用 GetThreadContext。由于显而易见的原因,这不起作用。相反,我认为 CONTEXT ctx = {CONTEXT_FULL} 有效。最有帮助的答案是下面的 Hans Passant 评论。

最佳答案

您无法获得正在运行的线程的有效上下文。您需要挂起要获取上下文的线程。因此,尝试在当前线程中执行此操作是行不通的。 GetThreadContext() 中明确说明了这一点文档:

You cannot get a valid context for a running thread. Use the SuspendThread function to suspend the thread before calling GetThreadContext.

If you call GetThreadContext for the current thread, the function returns successfully; however, the context returned is not valid.

关于c++ - GetThreadContext 寄存器总是返回 0xCCCCCCCC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18195934/

相关文章:

windows - 由于PathTooLongException而使用PowerShell和Robocopy获取ACL信息

c++ - 获取不同进程中线程的EBP

c++ - 如果处理没有响应,我该如何抛出异常

c++ - 将 const char 转换为 char 时出现未处理的异常

Delphi 中的 Windows API 参数 - 使用或不使用 @ 运算符传递 var 参数?

delphi - LsaOpenPolicy 在我的代码中抛出异常。为什么?

c++ - std::string 析构函数中的访问冲突仅在调试中

c++ - 各种编译器上的 RDRAND 和 RDSEED 内在函数?

c++ - X11 上的 Vulkan : vkGetPhysicalDeviceSurfaceCapabilitiesKHR error

c++ - Win32/Direct2D - 如何呈现无限滚动列表框