C 如何查看LPVOID类型变量的内容

C 如何查看LPVOID类型变量的内容,c,visual-c++,windbg,C,Visual C++,Windbg,我有一个C函数,它接受LPVOID类型的参数。传入的值是\0个单独的字符数组。如何在visual studio/windbg中强制转换参数以查看传入值?只需强制转换到char*即可 void f(LPVOID s) { char* ss = (char*) s; // put breakpoint here or watch the variable for(char* r = ss; *r != '\0'; r += (strlen(r)+1)) { // it

我有一个C函数,它接受LPVOID类型的参数。传入的值是\0个单独的字符数组。如何在visual studio/windbg中强制转换参数以查看传入值?

只需强制转换到
char*
即可

  void f(LPVOID s)
  {
      char* ss = (char*) s; // put breakpoint here or watch the variable
      for(char* r = ss; *r != '\0'; r += (strlen(r)+1)) { // iterate the string
          printf("%s \n", r);
       }   
  }

没有任何石膏可以让你在手表窗口中观察到这一点。对于VS,您必须在空分隔块开头的地址上打开一个内存窗口

在WinDbg中,命令
db
将原始内存与ASCII转换一起转储。如果块大于128字节,则在命令中添加选项
l
。例如,这将打印出局部变量pVoid的第一个0x200字节:

db poi pVoid l200

您可以在脚本中执行此操作。类似于下面的方法可以工作,它假设char*字符串,并且列表以双null结尾(类似于MULTI_SZ):

保存到文本文件,然后在WinDBG中运行以下操作:

0:000> $$>a<c:\dumps\multisz.txt 0x012210ec
012210ec  "Foo"
012210f0  "Bar"
012210f4  "FooBar"

0:000>$$$>a又是一个非常晚的答案,但windbg中的
dpa
可以用来打印列表

lpvoid:\>dir /b
lpvoid.cpp

lpvoid:\>type lpvoid.cpp
#include <stdio.h>
#include <windows.h>

    int somefunc(LPVOID blah)
    {
        printf("%s\n",*(PCHAR *)blah);
        return 0;
    }
    int main (void)
    {
        PCHAR foo[] = { "yay" , "boy" , "dog" , "cat" , "monkey" , "weedinducedweird
    o" };
        somefunc( foo);
        return 0;
    }

    lpvoid:\>cl /Zi /nologo lpvoid.cpp
    lpvoid.cpp

    lpvoid:\>dir /b *.exe
    lpvoid.exe

    lpvoid:\>lpvoid.exe
    yay
假设这里没有符号

lpvoid:\>cdb -c "bp 401020 \"dpa (@esp+8) l?6;q\";g;q" lpvoid.exe | grep -A 6 ya
y
0013ff60  00417c60 "yay"
0013ff64  00417c64 "boy"
0013ff68  00417c68 "dog"
0013ff6c  00417c6c "cat"
0013ff70  00417c70 "monkey"
0013ff74  00417c78 "weedinducedweirdo"
quit:

直接对char*
进行强制转换不起作用?是的。因为有空值来分隔它们。您必须手动遍历它们。
    lpvoid:\>cdb -c "bp somefunc \"dpa poi(blah) l?6;q\";g;q" lpvoid.exe | grep -A 6
     yay
    0013ff60  00417c60 "yay"
    0013ff64  00417c64 "boy"
    0013ff68  00417c68 "dog"
    0013ff6c  00417c6c "cat"
    0013ff70  00417c70 "monkey"
    0013ff74  00417c78 "weedinducedweirdo"
    quit:
lpvoid:\>cdb -c "bp 401020 \"dpa (@esp+8) l?6;q\";g;q" lpvoid.exe | grep -A 6 ya
y
0013ff60  00417c60 "yay"
0013ff64  00417c64 "boy"
0013ff68  00417c68 "dog"
0013ff6c  00417c6c "cat"
0013ff70  00417c70 "monkey"
0013ff74  00417c78 "weedinducedweirdo"
quit: