高级Visual Studio功夫测试 - 在调试期间从即时窗口调用函数 [英] advanced Visual Studio kung-fu test -- Calling functions from the Immediate Window during debugging

查看:374
本文介绍了高级Visual Studio功夫测试 - 在调试期间从即时窗口调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些相关的问题已经被问到了,但是对于我来说,他们太过先进,无法从头到尾掌握或缺乏分步指南(大多数人最终都是自己的实验结果的内幕话题) )。确定这里是给定这个简单的程序:

I see some related questions have been asked, but they're either too advanced for me to grasp or lacking a step-by-step guide from start to finish (most of them end up being insider talk of their own experiment results). OK here it is, given this simple program:

#include <stdio.h>
#include <string.h>

int main()
{
    FILE * f;
    char buffer[100];

    memset(buffer, 0, 100);

    fun();

    f = fopen("main.cpp", "r");
    fread(buffer, 1, 99, f);
    printf(buffer);
    fclose(f);

    return 0;
}

它的作用基本上是打印本身(假设文件名为 main.cpp )。

What it does is basically print itself (assume file name is main.cpp).

打印另一个文件,说 foobar.txt 而不修改源代码?它与通过VS进行运行有关,通过调用函数,并在调用 fread()之前劫持FILE指针。没有必要担心通过调用 fclose()来泄漏资源。

How can I have it print another file, say foobar.txt without modifying the source code? It has something to do with running it through VS's, stepping through the functions and hijacking the FILE pointer right before fread() is called. No need to worry about leaking resources by calling fclose().

我尝试了简单的 f = fopen(foobar.txt,r)它给了

CXX0017: Error: symbol "fopen" not found

任何想法?

我在在Windows上调试Mozilla常见问题。正确的命令放入立即窗口是

I found out the solution accidentally on Debugging Mozilla on Windows FAQ. The correct command to put into the Immediate Window is

f = {,,MSVCR100D}fopen("foo.txt", "r")

但是,它并没有真正回答这个问题:

However, it doesn't really answer this question:


  • 我仍然不明白这里发生了什么。

  • 如何系统地找出 {,, MSVCR100D} 部分为任何给定的方法?我知道MSVCR版本从系统到系统的变化。如何找到这个?

  • 有没有人可以解释大括号的语法,特别是那两个逗号在那里做什么?是否有更多隐藏的宝石使用这种语法?

  • I still don't understand what is going on here.
  • How to systematically find out the {,,MSVCR100D} part for any given method? I know the MSVCR version changes from system to system. How can I find that out?
  • Could anyone explain the curly brace syntax, especially, what are those two commas doing there? Are there more hidden gems using this syntax?

推荐答案

大括号语法是VS 上下文运算符,这主要是破碎的 - 如链接(或至少,几乎不是隐藏的宝石)。它在VS表达式评估引擎需要在运行时解析函数的任何地方使用,例如在立即/命令窗口中,在监视窗口中,评估复合表达式,设置断点,或(如目前看到的)。

The curly-braces syntax is the VS Context Operator, which is mostly broken - as elaborated at the link (or at least, hardly a hidden gem). It is used anywhere the VS expression-evaluation-engine needs to resolve functions at runtime, e.g. evaluating compound expressions in the watch window, setting breakpoints, or (as you witnessed) in the immediate/command windows.

它的第三个参数是包含执行您希望调用的功能。对于诸如fopen的CRT功能,通常相当于 -

Its 3rd argument is the binary which includes the implementation of the function you wish to call. For a CRT function such as fopen, that usually amounts to -


MSVCR [VS版本] [D] .dll

MSVCR[VS version][D].dll

(我似乎记得扩展是必需的 - 但也许在VS2010中更改)。 'D'表示debug dll版本。 VS版本号解码为:VS2005 - > 8,VS2008 - > 9,VS2010 - > 10。

(I seem to recall the extension was needed - but maybe that changed in VS2010). The 'D' indicates the debug dll version. The VS version number is decoded as: VS2005 -> 8, VS2008 -> 9, VS2010 -> 10.

另请注意,评估引擎有各种其他疑点,以备注意。

Also note the evaluation-engine has various other gotchas to watch out for.

这篇关于高级Visual Studio功夫测试 - 在调试期间从即时窗口调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆