From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1268 invoked by alias); 4 Feb 2008 07:42:46 -0000 Received: (qmail 1255 invoked by uid 22791); 4 Feb 2008 07:42:45 -0000 X-Spam-Check-By: sourceware.org Received: from ti-out-0910.google.com (HELO ti-out-0910.google.com) (209.85.142.188) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 04 Feb 2008 07:42:27 +0000 Received: by ti-out-0910.google.com with SMTP id a1so69559tib.12 for ; Sun, 03 Feb 2008 23:42:25 -0800 (PST) Received: by 10.110.86.3 with SMTP id j3mr2299262tib.25.1202110944934; Sun, 03 Feb 2008 23:42:24 -0800 (PST) Received: by 10.110.50.8 with HTTP; Sun, 3 Feb 2008 23:42:24 -0800 (PST) Message-ID: Date: Mon, 04 Feb 2008 07:42:00 -0000 From: "Rohit Arul Raj" To: "Neeraj kushwaha" Subject: Re: value of local variable stored in register Cc: gdb@sourceware.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-02/txt/msg00009.txt.bz2 Hi, Since the live range of value 'c' is dead after printf, the compiler may be discarding it. Try to use something like b = c + 200; after printf statement, so that we extend the live range of variable 'c'. Regards, Rohit On Feb 4, 2008 12:32 PM, Rohit Arul Raj wrote: > Hi, > > Then, the register value is getting corrupted due to the segmentation fault. > Try to set the break-point before the *a = 0 statement, and try to get > the register info and local variable info. > > Regards, > Rohit > > > On Feb 4, 2008 12:09 PM, Neeraj kushwaha wrote: > > > > Hi Rohit, > > > > thanks for the reply. > > > > segmentation occurs due to unreferencing null pointer. (this was done > > intensionally) > > I am running gdb on core dump. > > > > My main intention to get the value of the local variable stored in register. > > From the dwarf dump information i can say it was stored in DW_OP_reg2. > > > > Also if for the arithmetic operations, data is moved to register from > > memory, but when the printf function returns all the saved register > > value should be restored. > > > > this is the dwarf information extracted from a.out > > > > <1>< 276> DW_TAG_subprogram > > DW_AT_sibling <341> > > DW_AT_external yes(1) > > DW_AT_name main > > DW_AT_decl_file 1 > > /home/neeraj/SSG/Release2/gdblocal/2.c > > DW_AT_decl_line 5 > > DW_AT_type <199> > > DW_AT_low_pc 0x80483a4 > > DW_AT_high_pc 0x80483f5 > > DW_AT_frame_base [ > > 0]DW_OP_breg4+4 > > [ 1]DW_OP_reg1 > > [ 2]DW_OP_breg4+4 > > [ 3]DW_OP_breg4+8 > > [ > > 4]DW_OP_breg5+8 > > <2>< 305> DW_TAG_variable > > DW_AT_name a > > DW_AT_decl_file 1 > > /home/neeraj/SSG/Release2/gdblocal/2.c > > DW_AT_decl_line 6 > > DW_AT_type <341> > > DW_AT_location DW_OP_fbreg -16 > > <2>< 317> DW_TAG_variable > > DW_AT_name b > > DW_AT_decl_file 1 > > /home/neeraj/SSG/Release2/gdblocal/2.c > > DW_AT_decl_line 7 > > DW_AT_type <347> > > DW_AT_location DW_OP_fbreg -20 > > <2>< 329> DW_TAG_variable > > DW_AT_name c > > DW_AT_decl_file 1 > > /home/neeraj/SSG/Release2/gdblocal/2.c > > DW_AT_decl_line 8 > > DW_AT_type <199> > > DW_AT_location DW_OP_reg2 > > <1>< 341> DW_TAG_pointer_type > > DW_AT_byte_size 4 > > DW_AT_type <199> > > <1>< 347> DW_TAG_volatile_type > > DW_AT_type <199> > > > > Regards > > Neeraj > > > > On Feb 4, 2008 10:58 AM, Rohit Arul Raj wrote: > > > > > 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 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 > > > > > > > > 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 > > > > 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 > > > > > > > > > >