gpt4 book ai didi

c - 使用 Windows 调试器查看用 C 写入的内存位置?

转载 作者:可可西里 更新时间:2023-11-01 10:34:52 25 4
gpt4 key购买 nike

我在 dosbox 中运行了 Turbo C 和 Windows 调试

我有这个C程序,它有两条主线,如你所见。 int a=5 然后一行显示a的地址,printf("address of a=%x",&a)

enter image description here

我运行它

enter image description here

好像告诉我a已经分配到了fff4的地址

现在我想使用调试来希望在该内存地址看到 5 的值

但是没有显示

enter image description here

如何在调试中看到它?

最佳答案

这是编译后的 main 函数的 DEBUG 输出:

16E1:01FA 55            PUSH    BP                                 
16E1:01FB 8BEC MOV BP,SP
16E1:01FD 83EC02 SUB SP,+02
16E1:0200 C746FE0500 MOV WORD PTR [BP-02],0005
16E1:0205 8D46FE LEA AX,[BP-02]
16E1:0208 50 PUSH AX
16E1:0209 B89401 MOV AX,0194
16E1:020C 50 PUSH AX
16E1:020D E8AA06 CALL 08BA
16E1:0210 59 POP CX
16E1:0211 59 POP CX
16E1:0212 8BE5 MOV SP,BP
16E1:0214 5D POP BP
16E1:0215 C3 RET

int a=5; 是函数 main 中的一个local 变量,存储在堆栈中(MOV WORD PTR [BP-02],0005).当您离开函数 (RET) 时,堆栈上的值将丢失。在运行程序之外是看不到的。

你的计划可以顺利进行,如果你

  1. 初始化一个全局变量并
  2. 制作一个小型 .com 程序。

simplepr.c:

#include <stdio.h>

int a=5;

void main()
{
printf ("address of a=%x",&a);
}

编译:

TCC.EXE -mt -lt simplepr.c

调试 session :

n simplepr.com
l
g -> address of a=125c (example)
d 125c -> or what the address is

关于c - 使用 Windows 调试器查看用 C 写入的内存位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32962626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com