Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

What is eax in 64bit machine and why the pointer address get 1 extend in the higher bits [compiled with ICC]?

rudaho
Beginner
507 Views
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.

[bash]int Func() 
{
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]
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
[bash]mov %eax, -0x30(%rbp)
mov -0x30(%rbp), %eax
movslq %eax, %rax[/bash]
And then %rax is 0xffffffff9d65f9a0 which is an invalid memory address.

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

0 Kudos
2 Replies
mecej4
Honored Contributor III
507 Views
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.
[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.
0 Kudos
rudaho
Beginner
507 Views
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
0 Kudos
Reply