[LLVMdev] Failure while calling a function in GDB session
Karthik Bhat
karthikthecool at gmail.com
Fri Nov 23 09:30:33 PST 2012
Hi Guys any inputs on this issue?
On Fri, Nov 16, 2012 at 8:29 PM, KARTHIKVENKATESH BHAT
<kv.bhat at samsung.com> wrote:
> Hi All,
> I compiled the following code on my linux PC using clang with PIE option-
>
> struct struct4 {char a; char b; char c; char d; };
> struct struct4 foo4 = {'a','2','c','4'};
> struct struct4 fun4()
> {
> return foo4;
> }
>
> int main()
> {
> fun4();
> return 0;
> }
>
>
>> clang -g -fPIE structs.c
>
> In GDB session when i call p/c fun4() i get something like below-
> (gdb) p/c fun4()
> Cannot access memory at address 0x34633261
>
> Disassemble of the code is as follows -
>
> (gdb) disassemble
> Dump of assembler code for function fun4:
> 0x080483e0 <+0>: call 0x80483e5 <fun4+5>
> 0x080483e5 <+5>: pop %eax
> 0x080483e6 <+6>: add $0x1c0f,%eax
> 0x080483ec <+12>: mov 0x4(%esp),%ecx
> 0x080483f0 <+16>: mov -0x8(%eax),%eax
> 0x080483f6 <+22>: mov (%eax),%eax
> => 0x080483f8 <+24>: mov %eax,(%ecx)
> 0x080483fa <+26>: ret $0x4
> End of assembler dump.
> (gdb) i r
> eax 0x34633261 878916193
> ecx 0xbffff128 -1073745624
> edx 0xbffff164 -1073745564
> ebx 0x8049ff4 134520820
> esp 0xbffff11c 0xbffff11c
> ebp 0xbffff138 0xbffff138
> esi 0x0 0
> edi 0x0 0
> eip 0x80483f8 0x80483f8 <fun4+24>
> eflags 0x212 [ AF IF ]
> cs 0x73 115
> ss 0x7b 123
> ds 0x7b 123
> es 0x7b 123
> fs 0x0 0
> gs 0x33 51
>
>
> Seems value in EAX register is getting corrupted in this case as a result of
> mov (%eax),%eax Call.
> Could anyone guide me how i can fix this issue and which part of code to look into.
>
> Thanks
> Karthik
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list