From: "Rohit Arul Raj" <rohitarulraj@gmail.com>
To: "Neeraj kushwaha" <kushneeraj@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: value of local variable stored in register
Date: Mon, 04 Feb 2008 05:28:00 -0000 [thread overview]
Message-ID: <c356fd4e0802032128sddec389w5b3dc1e4103744c1@mail.gmail.com> (raw)
In-Reply-To: <df5e18bd0802032053o7dddab55n6b01a369424e727b@mail.gmail.com>
Hi,
1. You are getting segmentation fault because of trying to write to a
invalid memory location (0x0) through pointer a;
2. It is not always true that if u give the storage class specifier as
"Register", a register will be allocated for the local variable. It
always depends on the compiler.
3. It is possible that for arithmetic operations, the compiler may
move your data to register from memory (operation: b*c & your
arithmetic operations does not support memory operands). In that case
u can look at the assembly generated.
Regards,
Rohit
On Feb 4, 2008 10:23 AM, Neeraj kushwaha <kushneeraj@gmail.com> wrote:
> Hi All,
>
> I am trying to find the value of local variable stored in register.
> But I am getting wrong value from gdb.
> Here what i am trying
>
> #include<stdio.h>
>
> int main()
> {
> int *a=0;
> volatile register int b=0xabcd;
> register int c=20;
> printf("%x\n",b*c);
> *a=0;
> return 0;
> }
>
>
> ------------------------------
> -----------------------
> GDB info:
>
> Core was generated by `./a.out'.
> Program terminated with signal 11, Segmentation fault.
> #0 0x080483e1 in main () at 1.c:9
> 9 *a=0;
> (gdb) info local
> a = (int *) 0x0
> b = 43981
> c = 11305136
> (gdb) info reg
> eax 0x0 0
> ecx 0x0 0
> edx 0xac80b0 11305136
> ebx 0xac6ff4 11300852
> esp 0xbfc65a00 0xbfc65a00
> ebp 0xbfc65a28 0xbfc65a28
> esi 0x973ca0 9911456
> edi 0x0 0
> eip 0x80483e1 0x80483e1 <main+61>
> eflags 0x210282 [ SF IF RF ID ]
> cs 0x73 115
> ss 0x7b 123
> ds 0x7b 123
> es 0x7b 123
> fs 0x0 0
> gs 0x33 51
> (gdb)
>
>
> The value of local variable is shown as c = 11305136, but actual value is 20.
>
> How to get the correct value of variables which are stored in register.
>
> Regards
> Neeraj
>
next prev parent reply other threads:[~2008-02-04 5:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-04 4:53 Neeraj kushwaha
2008-02-04 5:28 ` Rohit Arul Raj [this message]
2008-02-04 6:39 ` Neeraj kushwaha
2008-02-04 7:03 ` Rohit Arul Raj
2008-02-04 7:42 ` Rohit Arul Raj
2008-02-04 20:32 ` Eli Zaretskii
2008-02-05 19:42 ` Jim Blandy
2008-02-05 20:35 ` Eli Zaretskii
2008-02-06 0:27 ` Jim Blandy
2008-02-06 4:18 ` Eli Zaretskii
2008-02-06 6:26 ` Jim Blandy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c356fd4e0802032128sddec389w5b3dc1e4103744c1@mail.gmail.com \
--to=rohitarulraj@gmail.com \
--cc=gdb@sourceware.org \
--cc=kushneeraj@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox