- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all~
I have a code section that tries to assign a pointer to a variable in 64bit machine. It's simple but something's wrong currently. The binary is run in Linux 2.6.9-89.ELlargesmp x86-64. The CPU is Intel Xeon CPU X5560 @ 2.80GHz.
Before performing the getPtr(), xor %eax, %eax is performed and then I think %eax should be 0. But I can't
display the eax in gdb and I found in google that %eax is %rax in 64bit machine.
Can anyone show me how to print the %eax in gdb, and any hint about why the address is wrong?
Thanks a lot...
BR
Yi-Ju
I have a code section that tries to assign a pointer to a variable in 64bit machine. It's simple but something's wrong currently. The binary is run in Linux 2.6.9-89.ELlargesmp x86-64. The CPU is Intel Xeon CPU X5560 @ 2.80GHz.
[bash]int Func()In the function getPtr(), the idx is OK and in the return of getPtr(), the rax register is OK (value is 0x9d65f9a0). And in the assignment, it performs
{
int idx = 0;
struct myStruct * ptr = NULL;
... /* somewhere modify idx */
ptr = getPtr(idx);
...
}
struct myStruct* getPtr(int idx)
{
/* S_ptrTbl is of type struct myStruct** */
if (S_ptrTbl) {
return S_ptrTbl[idx];
}
return NULL;
}
[/bash]
[bash]mov %eax, -0x30(%rbp)And then %rax is 0xffffffff9d65f9a0 which is an invalid memory address.
mov -0x30(%rbp), %eax
movslq %eax, %rax[/bash]
Before performing the getPtr(), xor %eax, %eax is performed and then I think %eax should be 0. But I can't
display the eax in gdb and I found in google that %eax is %rax in 64bit machine.
Can anyone show me how to print the %eax in gdb, and any hint about why the address is wrong?
Thanks a lot...
BR
Yi-Ju
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Line 8 references getPtr() without any previous declaration of its type. By default the type is int and, depending on compiler options, int is 4-bytes long.
Try declaring getPtr() as follows before using it.
Even in 64-bit mode, registers al, ah, ax, eax, bl, bh, bx, ebx, etc. are very much available and used everywhere.
Try declaring getPtr() as follows before using it.
[cpp]extern struct myStruct* getPtr(int); [/cpp]You could use the Intel debugger instead of GDB, or the DDD front-end for GDB. At the GDB prompt, try "help p" and it will tell you, among other things that to display the contents of %eax the command is "p $eax".
Even in 64-bit mode, registers al, ah, ax, eax, bl, bh, bx, ebx, etc. are very much available and used everywhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi mecej4~
Yes, you're right. I found that the declarasion of the function was removed from the include file by someone for some means and then this issue happened. I just declare it again and then it's ok now. Thanks a lot...
By the way, previously I used p $eax and I got void in return. Then if I cast it as char by p (char)$eax, it return a value. And I can't cast it as short or int or double* or whatever. It showed invalid cast. Do you have any idea about that? Thanks...
BR
Yi-Ju
Yes, you're right. I found that the declarasion of the function was removed from the include file by someone for some means and then this issue happened. I just declare it again and then it's ok now. Thanks a lot...
By the way, previously I used p $eax and I got void in return. Then if I cast it as char by p (char)$eax, it return a value. And I can't cast it as short or int or double* or whatever. It showed invalid cast. Do you have any idea about that? Thanks...
BR
Yi-Ju

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page