gdb无法访问内存地址错误 [英] gdb can't access memory address error
问题描述
0x0804844d< + 0> ;: push%ebp
0x0804844e< + 1>:mov%esp,%ebp
0x08048450< + 3> ;:和$ 0xfffffff0,%esp
0x08048453< + 6>:sub $ 0x20,%esp
0x08048456< ; + 9>:movl $ 0x8048540,(%esp)
0x0804845d< + 16> ;:呼叫0x8048310< puts @ plt>
0x08048462< + 21> ;: lea 0x1c(%esp),%eax
0x08048466< + 25> ;: mov%eax,0x4(%esp)
0x0804846a< + 29> :movl $ 0x8048555,(%esp)
0x08048471< + 36> ;: call 0x8048320< scanf @ plt>
0x08048476< + 41> ;: mov 0x1c(%esp),%eax
0x0804847a< + 45> ;: cmp $ 0x208c,%eax
0x0804847f< + 50> ;: jne 0x804848f <主+ 66>
0x08048481< + 52> ;: movl $ 0x8048558,(%esp)
0x08048488< + 59> ;:呼叫0x8048310< puts @ plt>
0x0804848d< + 64> ;: jmp 0x804849b< main + 78>
=> 0x0804848f< + 66>:movl $ 0x8048569,(%esp)
0x08048496< + 73> ;:呼叫0x8048310< puts @ plt>
0x0804849b< + 78>:mov $ 0x0,%eax
0x080484a0< + 83> ;:离开
0x080484a1< + 84> ;: ret
我要研究的是$ 0x208c。当我键入x / xw 0x208c时,它给了我一个错误信息,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据这些值打印出来。问题是,这是来自大学的作业,我没有得到代码。希望你能帮助。
当我键入
x / xw 0x208c
它给我回错误说
无法访问地址为0x208c的内存
你的程序的反汇编说它做了这样的事情:
puts(some string);
int i;
scanf(%d,& i); //我不知道实际的格式字符串是什么。
//你可以找到x / s 0x8048555
if(i == 0x208c){...} else {...}
换句话说, 0x208c
是一个值( 8332
)你的程序已经硬编码了,而且不是指针。因此,GDB完全正确地告诉你,如果你将 0x208c
解释为一个指针,那么这个指针并不指向可读的内存。
我终于想出了使用print语句而不是x / xw
不理解 print
和 examine
命令之间的区别。考虑这个例子:
int foo = 42;
int * pfoo =& foo;
如上所述, print pfoo
会给你 foo
和 x pfoo
的地址会为您提供值存储在该地址(即 foo
的值)。
here is my disas code:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
When I type
x/xw 0x208c
it gives me back error which saysCannot access memory at address 0x208c
The disassembly for your program says that it does something like this:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c
is a value (8332
) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c
as a pointer, that pointer does not point to readable memory.
i finally figured out to use print statement instead of x/xw
You appear to not understand the difference between print
and examine
commands. Consider this example:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo
will give you the address of foo
, and x pfoo
will give you the value stored at that address (i.e. the value of foo
).
这篇关于gdb无法访问内存地址错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!