This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Effect of 'register' keyword on debug info


Hello All,

I came across this issue while working with PowerPC GCC tool chain
v4.5.2 for e500mc(64bit)/e5500.
Test case compiled with '-O0 -g'.

/************************** Test Case ************************/
 1: int main()
 2: {
 3:	int i=0;
 4:
 5:	register float f1 = 55.77f;
 6:	register double d1 = 22.99f;
 7:
 8:	while (i <= 100)  -----------------------------------(A)
 9:	{
10:		i++;
11:		f1 = (float)i / 177 + (float)d1;
12:		d1 = (double)i / 155677 + f1;
13:		i += (int)d1;
14:	}
15: }

/**************** Debug Info *************************************/
 <2><5d>: Abbrev Number: 3 (DW_TAG_variable)
    <5e>   DW_AT_name        : f1	
    <61>   DW_AT_decl_file   : 1	
    <62>   DW_AT_decl_line   : 5	
    <63>   DW_AT_type        : <0x7f>	
    <67>   DW_AT_location    : 2 byte block: 90 3f 	(DW_OP_regx: 63)
 <2><6a>: Abbrev Number: 3 (DW_TAG_variable)
    <6b>   DW_AT_name        : d1	
    <6e>   DW_AT_decl_file   : 1	
    <6f>   DW_AT_decl_line   : 6	
    <70>   DW_AT_type        : <0x86>	
    <74>   DW_AT_location    : 2 byte block: 90 3f 	(DW_OP_regx: 63)


/**************** Generated Assembly *************************/
...
.LCFI1:
	.cfi_def_cfa_register 31
	 # main.c:3
	.loc 1 3 0
	li 0,0	 # tmp129,
	stw 0,48(31)	 # i, tmp129
	 # main.c:5
	.loc 1 5 0
	lfs 31,.LC0@toc(2)	 #, f1 --------------------- > (variable F1)
	 # main.c:6
	.loc 1 6 0
	lfd 31,.LC1@toc(2)	 #, d1 --------------------> (variable D1)
	 # main.c:8
	.loc 1 8 0
	b .L2	 #
.....

Looking at the debug info and the generated assembly, the values of
variables 'f1' and 'd1' are stored in the same register.
Due to this, while debugging, after setting the break point at (A)
[line no 8], if we print the value of 'f1' i get the wrong value.

/**************** Debugger Output *********************/
(gdb) n
5               register float f1 = 55.77f;
(gdb) n
6               register double d1 = 22.99f;
(gdb) n
8               while (i <= 100)
(gdb) p f1
$1 = 22.9899998
(gdb) p d1
$2 = 22.989999771118164
/************************************************************/

Q: Is this the side effect of using 'register' keyword? If 'f1' is
getting optimized out, shouldn't we get that info while debugging?

Also, using -fvar-tracking, i get this output while debugging the same code.

/**************** Debugger Output *********************/
5               register float f1 = 55.77f;
(gdb) n
6               register double d1 = 22.99f;
(gdb) n
8               while (i <= 100)
(gdb) p f1
$5 = <optimized out>
(gdb) p d1
$6 = 22.989999771118164
/************************************************************/

Regards,
Rohit


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]