visual-studio 从 Visual Studio 内存窗口保存数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4155624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:45:12  来源:igfitidea点击:

save data from visual studio memory window

visual-studiodebuggingmemorywindow

提问by StNickolay

Is any possiblility to save some buffer in any binary file, to view in standalone hex editor.

是否有可能在任何二进制文件中保存一些缓冲区,以便在独立的十六进制编辑器中查看。

For example, can I save data from memory window in VS to hex dump, but not as ASCII ?

例如,我可以将 VS 内存窗口中的数据保存到十六进制转储,但不能保存为 ASCII 吗?

回答by StNickolay

user142207 has done a great job investigating VS internals, I recommend that solution. I have another way that was invented by my colleague, Sergey S., which is very useful:

user142207 在调查 VS 内部结构方面做得很好,我推荐该解决方案。我的同事 Sergey S. 发明了另一种方法,非常有用:

Windows: Use a couple of functions ReadProcessMemory/WriteProcessMemory. It needs a standalone app that calls these functions with a target process id like:

Windows:使用几个函数ReadProcessMemory/ WriteProcessMemory。它需要一个独立的应用程序,使用目标进程 ID 调用这些函数,例如:

dumper.exe <debugged process id> <memory_start_addr> <memory_length>

This app can be called directly during the VS debug session(compared to Linux, which doesn't have such a possibility). We can capture the memory address in the watch window, then pass the address to the dumper and voila. As user142207 says in his article, it's very useful in long-time recompiled projects.

这个应用程序可以在 VS 调试会话期间直接调用(与 Linux 相比,它没有这种可能性)。我们可以在观察窗口中捕获内存地址,然后将地址传递给转储程序,瞧。正如 user142207 在他的文章中所说,它在长时间重新编译的项目中非常有用。

Linux/MacOS has different approaches. For example: from the gdb console, use command dump memory. This command can also be used directly during the debug session.

Linux/MacOS 有不同的方法。例如:从 gdb 控制台,使用命令转储内存。此命令也可以在调试会话期间直接使用。

回答by Sasha Goldshtein

I don't know if this helps, but you can use WinDbg's .writememcommand. It takes a filename and a memory range and dumps it (as binary) to the disk.

我不知道这是否有帮助,但您可以使用 WinDbg 的.writemem命令。它需要一个文件名和一个内存范围并将其(作为二进制)转储到磁盘。

回答by Alexander Vostres

StNickolay has the answer that references some tool called "dumper" but, somehow, I was unable to find it around the net (also, user142207 is long gone). So I created the very same tool - it opens up running process (even with a debugger attached) and copies portion of its memory into the file. Very useful when you want to store some structure for later and don't want to struggle with VS Memory View "copy" output. Enjoy!

StNickolay 的答案引用了一些名为“dumper”的工具,但不知何故,我无法在网上找到它(而且,user142207 早已不复存在)。所以我创建了相同的工具——它打开正在运行的进程(即使附加了调试器)并将其内存的一部分复制到文件中。当您想为以后存储一些结构并且不想为 VS 内存视图“复制”输出而烦恼时,这非常有用。享受!

https://github.com/Alexx999/Dumper

https://github.com/Alexx999/Dumper

回答by Steed

There is an extension for that: https://marketplace.visualstudio.com/items?itemName=OvidiuIonescu.VSDebugTool. It opens its console in VisualStudio window and allows dumping memory to file and a couple of other memory operation (enter "help" in the console for details).

有一个扩展:https: //marketplace.visualstudio.com/items?itemName=OvidiuIonescu.VSDebugTool。它在 VisualStudio 窗口中打开其控制台,并允许将内存转储到文件和其他一些内存操作(在控制台中输入“帮助”以获取详细信息)。

Also, some hex editors (e.g. Hex Editor Neo) can browse process memory as an ordinary file. Maybe you'll find a free editor with this feature too.

此外,一些十六进制编辑器(例如Hex Editor Neo)可以像普通文件一样浏览进程内存。也许您也会找到具有此功能的免费编辑器。

回答by erankor

The watch window in the Visual Studio debugger can run functions, if you are debugging your own code, you can just add some function to your code for saving a buffer to file and call it from the watch window. for example:

Visual Studio 调试器中的监视窗口可以运行函数,如果您正在调试自己的代码,您只需在代码中添加一些函数以将缓冲区保存到文件并从监视窗口调用它。例如:

void WriteToFile(char* name, void* buffer, size_t size)
{
    FILE* fp;
    fopen_s(&fp, name, "wb");
    fwrite(buffer, 1, size, fp);
    fclose(fp);
}

Then just type something like this in the watch window:

然后只需在监视窗口中键入如下内容:

WriteToFile("c:\temp\dump.dat", buffer, len)

回答by BanksySan

I suspect that you can get what you want from the ClrMD, you can then same the data however you want.

我怀疑您可以从ClrMD获得您想要的东西,然后您可以随意使用相同的数据。

If you literally want a core dump then WinDbg might be what you're looking for?

如果您真的想要一个核心转储,那么 WinDbg 可能就是您要找的?

There is also this post on MSDN Blogs: https://blogs.msdn.microsoft.com/dondu/2010/10/24/writing-minidumps-in-c/

MSDN 博客上也有这篇文章:https: //blogs.msdn.microsoft.com/dondu/2010/10/24/writing-minidumps-in-c/

It describes how to create dump-ish things in .NET programmatically.

它描述了如何以编程方式在 .NET 中创建转储式的东西。