* Patch for bug 567 (sparc-sun-solaris2.8)
@ 2002-11-14 20:37 Duncan Roe
2002-11-15 16:35 ` Andrew Cagney
0 siblings, 1 reply; 4+ messages in thread
From: Duncan Roe @ 2002-11-14 20:37 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]
Hi,
Bug 567 complains that when you build gdb for sparc-sun-solaris2.8 as a 64-bit
program, then when you use it to debug a 32-bit program things happen like:
(gdb) p d1
Cannot access memory at address 0xffbef7a0
(gdb) x/fg &d1
0xffbef7a0: 3.2999999999999998
(Actually 567 shows the wrong value being printed to x/fg, but this seems to be
fixed at gcc-3.2 / gdb 5.2.1).
It turns out that you can't "p" any kind of variable: the problem isn't limited
to double.
The problem seemed to me that 32-bit negative stack offsets became +ve 64-bit
quantities. This would give a 33-bit address (the wanted address with an extra
"1" on the left).
Ideally, I think gdb should just mask off the extra bit when debugging 32-bit
code. But I couldn't figure out how to do that, so the attached patch
sign-extends symbol values as they are read in.
GCC 3.2 configuration:
/tmp/gcc-3.2/configure --prefix=/usr/local/gcc-3.2
GDB 5.2.1 configuration
PATH=/usr/local/gcc-3.2/bin:$PATH
export PATH
CC="gcc -m64"
export CC
CFLAGS="-g -O2"
export CFLAGS
./configure --prefix=/usr/local/solaris2.8_64
You need to put "-m64" in CC rather than CFLAGS else "make install" fails when
trying to build "chew". This has the unfortunate side-effect that "make check"
also uses "gcc -m64", i.e. it never exercises "gcc" which would build a 32-bit
program.
Cheers ... Duncan.
[-- Attachment #2: The patch --]
[-- Type: text/plain, Size: 1491 bytes --]
diff -r -u gdb-5.2.1.bu/gdb/dbxread.c gdb-5.2.1/gdb/dbxread.c
--- gdb-5.2.1.bu/gdb/dbxread.c Fri Apr 5 08:33:49 2002
+++ gdb-5.2.1/gdb/dbxread.c Thu Nov 14 16:23:40 2002
@@ -2591,6 +2591,27 @@
fill_symbuf (abfd);
bufp = &symbuf[symbuf_idx++];
INTERNALIZE_SYMBOL (nlist, bufp, abfd);
+
+ /* ----------------------------------------------- */
+ /* Horrible fix for when gdb is built with "-m64" */
+ /* (sparc-sun-solaris2.8): */
+ /* sign-extend the 32-bit result in nlist.n_value. */
+ /* */
+ /* This fixes the testcase in bug 567, */
+ /* in that you can "p d1" successfully. */
+ /* Actually you can "p" *anything* */
+ /* (previously, you couldn't). */
+ /* */
+ /* I expect this will break something else, */
+ /* we'll just have to wait to see what. */
+ /* */
+ /* The proper fix is for gdb to know that it's */
+ /* working on a 32-bit program and */
+ /* truncate addresses to 32 bits before using them */
+ /* ----------------------------------------------- */
+
+ nlist.n_value = (long)(int)nlist.n_value;
+
OBJSTAT (objfile, n_stabs++);
type = bfd_h_get_8 (abfd, bufp->e_type);
[-- Attachment #3: (simplified) test program from bug 567 --]
[-- Type: text/plain, Size: 333 bytes --]
/*
* From GDB bug report 567
gcc -g -m64 -o double double.c
gcc -g -o double double.c
*
* The report says to breakpoint on the printf line
* & print the value of d1
*/
extern int printf(const char *, ...);
int
main()
{
double d1;
d1 = 3.3;
printf("d1 = %f\n", d1);
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Patch for bug 567 (sparc-sun-solaris2.8) 2002-11-14 20:37 Patch for bug 567 (sparc-sun-solaris2.8) Duncan Roe @ 2002-11-15 16:35 ` Andrew Cagney 2002-11-15 17:43 ` Duncan Roe 2002-11-20 14:32 ` Duncan Roe 0 siblings, 2 replies; 4+ messages in thread From: Andrew Cagney @ 2002-11-15 16:35 UTC (permalink / raw) To: Duncan Roe; +Cc: gdb-patches > Hi, > > Bug 567 complains that when you build gdb for sparc-sun-solaris2.8 as a 64-bit > program, then when you use it to debug a 32-bit program things happen like: > > (gdb) p d1 > Cannot access memory at address 0xffbef7a0 > (gdb) x/fg &d1 > 0xffbef7a0: 3.2999999999999998 > > (Actually 567 shows the wrong value being printed to x/fg, but this seems to be > fixed at gcc-3.2 / gdb 5.2.1). > > It turns out that you can't "p" any kind of variable: the problem isn't limited > to double. > > The problem seemed to me that 32-bit negative stack offsets became +ve 64-bit > quantities. This would give a 33-bit address (the wanted address with an extra > "1" on the left). > > Ideally, I think gdb should just mask off the extra bit when debugging 32-bit > code. But I couldn't figure out how to do that, so the attached patch > sign-extends symbol values as they are read in. From the point of view of GDB's core, the patch below may be closer to correct than you think (don't know how well it fits into the definition of the debug info - debug maintainer problem :-). GDB converts all external (debug info, et.al.) addresses into a canonical form. That form won't involve masking but can, on ocasions, involve sign extension. This is so that GDB can correctly debug a 32 bit ABI on a 64 bit target. In such a situtation, while a pointer might be 32 bits, registers and the address space would be the full 64 bits, gdb extending everything out to the size of CORE_ADDR. This is what makes it possible for GDB to debug an o32 ABI on a MIPS 64 platform (eg IRIX 6.5). BTW, can you post the corresponding debug info? Andrew > GCC 3.2 configuration: > > /tmp/gcc-3.2/configure --prefix=/usr/local/gcc-3.2 > > GDB 5.2.1 configuration > > PATH=/usr/local/gcc-3.2/bin:$PATH > export PATH > CC="gcc -m64" > export CC > CFLAGS="-g -O2" > export CFLAGS > ./configure --prefix=/usr/local/solaris2.8_64 > > You need to put "-m64" in CC rather than CFLAGS else "make install" fails when > trying to build "chew". This has the unfortunate side-effect that "make check" > also uses "gcc -m64", i.e. it never exercises "gcc" which would build a 32-bit > program. > > Cheers ... Duncan. > > > > diff -r -u gdb-5.2.1.bu/gdb/dbxread.c gdb-5.2.1/gdb/dbxread.c > --- gdb-5.2.1.bu/gdb/dbxread.c Fri Apr 5 08:33:49 2002 > +++ gdb-5.2.1/gdb/dbxread.c Thu Nov 14 16:23:40 2002 > @@ -2591,6 +2591,27 @@ > fill_symbuf (abfd); > bufp = &symbuf[symbuf_idx++]; > INTERNALIZE_SYMBOL (nlist, bufp, abfd); > + > + /* ----------------------------------------------- */ > + /* Horrible fix for when gdb is built with "-m64" */ > + /* (sparc-sun-solaris2.8): */ > + /* sign-extend the 32-bit result in nlist.n_value. */ > + /* */ > + /* This fixes the testcase in bug 567, */ > + /* in that you can "p d1" successfully. */ > + /* Actually you can "p" *anything* */ > + /* (previously, you couldn't). */ > + /* */ > + /* I expect this will break something else, */ > + /* we'll just have to wait to see what. */ > + /* */ > + /* The proper fix is for gdb to know that it's */ > + /* working on a 32-bit program and */ > + /* truncate addresses to 32 bits before using them */ > + /* ----------------------------------------------- */ > + > + nlist.n_value = (long)(int)nlist.n_value; > + > OBJSTAT (objfile, n_stabs++); > > type = bfd_h_get_8 (abfd, bufp->e_type); > > > > /* > * From GDB bug report 567 > gcc -g -m64 -o double double.c > gcc -g -o double double.c > * > * The report says to breakpoint on the printf line > * & print the value of d1 > */ > extern int printf(const char *, ...); > > int > main() > { > double d1; > > d1 = 3.3; > printf("d1 = %f\n", d1); > > return 0; > } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Patch for bug 567 (sparc-sun-solaris2.8) 2002-11-15 16:35 ` Andrew Cagney @ 2002-11-15 17:43 ` Duncan Roe 2002-11-20 14:32 ` Duncan Roe 1 sibling, 0 replies; 4+ messages in thread From: Duncan Roe @ 2002-11-15 17:43 UTC (permalink / raw) To: Andrew Cagney; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 219 bytes --] On Fri, Nov 15, 2002 at 07:34:58PM -0500, Andrew Cagney wrote: [snip] > > BTW, can you post the corresponding debug info? > > Andrew > [snip] Attached. The entry for "d1" indeed contains "-24". Cheers ... Duncan. [-- Attachment #2: double.s --] [-- Type: text/plain, Size: 2719 bytes --] .file "double.c" .stabs "/work/home/duncanr/tests/",100,0,0,.LLtext0 .stabs "double.c",100,0,0,.LLtext0 .section ".text" .LLtext0: .stabs "gcc2_compiled.",60,0,0,0 .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0 .stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0 .stabs "long int:t(0,3)=r(0,3);-2147483648;2147483647;",128,0,0,0 .stabs "unsigned int:t(0,4)=r(0,4);000000000000000000000000;000000000000037777777777;",128,0,0,0 .stabs "long unsigned int:t(0,5)=r(0,5);000000000000000000000000;000000000000037777777777;",128,0,0,0 .stabs "long long int:t(0,6)=@s64;r(0,6);001000000000000000000000;000777777777777777777777;",128,0,0,0 .stabs "long long unsigned int:t(0,7)=@s64;r(0,7);000000000000000000000000;001777777777777777777777;",128,0,0,0 .stabs "short int:t(0,8)=@s16;r(0,8);-32768;32767;",128,0,0,0 .stabs "short unsigned int:t(0,9)=@s16;r(0,9);0;65535;",128,0,0,0 .stabs "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,0,0 .stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,0,0 .stabs "__int128_t:t(0,12)=@s128;r(0,12);000000000000000000000000;0377777777777777777777777777777777;",128,0,0,0 .stabs "__uint128_t:t(0,13)=@s128;r(0,13);000000000000000000000000;0377777777777777777777777777777777;",128,0,0,0 .stabs "float:t(0,14)=r(0,1);4;0;",128,0,0,0 .stabs "double:t(0,15)=r(0,1);8;0;",128,0,0,0 .stabs "long double:t(0,16)=r(0,1);16;0;",128,0,0,0 .stabs "complex int:t(0,17)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0 .stabs "complex float:t(0,18)=r(0,18);8;0;",128,0,0,0 .stabs "complex double:t(0,19)=r(0,19);16;0;",128,0,0,0 .stabs "complex long double:t(0,20)=r(0,20);32;0;",128,0,0,0 .stabs "__builtin_va_list:t(0,21)=*(0,22)=(0,22)",128,0,0,0 .stabs "_Bool:t(0,23)=@s8;-16;",128,0,0,0 .stabs "double.c",130,0,0,0 .section ".rodata" .align 8 .LLC1: .asciz "d1 = %f\n" .align 8 .LLC0: .long 1074423398 .long 1717986918 .section ".text" .align 4 .stabs "main:F(0,1)",36,0,14,main .global main .type main,#function .proc 04 main: .stabn 68,0,14,.LLM1-main .LLM1: !#PROLOGUE# 0 save %sp, -120, %sp !#PROLOGUE# 1 .LLBB2: .stabn 68,0,17,.LLM2-main .LLM2: sethi %hi(.LLC0), %o0 or %o0, %lo(.LLC0), %o0 ld [%o0], %f2 ld [%o0+4], %f3 std %f2, [%fp-24] .stabn 68,0,18,.LLM3-main .LLM3: sethi %hi(.LLC1), %o0 or %o0, %lo(.LLC1), %o0 ld [%fp-24], %o1 ld [%fp-20], %o2 call printf, 0 nop .stabn 68,0,20,.LLM4-main .LLM4: mov 0, %o0 .LLBE2: .stabn 68,0,21,.LLM5-main .LLM5: mov %o0, %i0 nop ret restore .LLfe1: .size main,.LLfe1-main .stabs "d1:(0,15)",128,0,15,-24 .stabn 192,0,0,.LLBB2-main .stabn 224,0,0,.LLBE2-main .LLscope0: .stabs "",36,0,0,.LLscope0-main .text .stabs "",100,0,0,.Letext .Letext: .ident "GCC: (GNU) 3.2" ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Patch for bug 567 (sparc-sun-solaris2.8) 2002-11-15 16:35 ` Andrew Cagney 2002-11-15 17:43 ` Duncan Roe @ 2002-11-20 14:32 ` Duncan Roe 1 sibling, 0 replies; 4+ messages in thread From: Duncan Roe @ 2002-11-20 14:32 UTC (permalink / raw) To: Andrew Cagney; +Cc: Duncan Roe, gdb-patches Hi Andrew, I posted the debug info the other day, as you requested. What happens now? Cheers ... Duncan. On Fri, Nov 15, 2002 at 07:34:58PM -0500, Andrew Cagney wrote: > > Hi, > > > > Bug 567 complains that when you build gdb for sparc-sun-solaris2.8 as a 64-bit > > program, then when you use it to debug a 32-bit program things happen like: > > > > (gdb) p d1 > > Cannot access memory at address 0xffbef7a0 > > (gdb) x/fg &d1 > > 0xffbef7a0: 3.2999999999999998 > > > > (Actually 567 shows the wrong value being printed to x/fg, but this seems to be > > fixed at gcc-3.2 / gdb 5.2.1). > > > > It turns out that you can't "p" any kind of variable: the problem isn't limited > > to double. > > > > The problem seemed to me that 32-bit negative stack offsets became +ve 64-bit > > quantities. This would give a 33-bit address (the wanted address with an extra > > "1" on the left). > > > > Ideally, I think gdb should just mask off the extra bit when debugging 32-bit > > code. But I couldn't figure out how to do that, so the attached patch > > sign-extends symbol values as they are read in. > > From the point of view of GDB's core, the patch below may be closer to > correct than you think (don't know how well it fits into the definition > of the debug info - debug maintainer problem :-). > > GDB converts all external (debug info, et.al.) addresses into a > canonical form. That form won't involve masking but can, on ocasions, > involve sign extension. This is so that GDB can correctly debug a 32 > bit ABI on a 64 bit target. In such a situtation, while a pointer might > be 32 bits, registers and the address space would be the full 64 bits, > gdb extending everything out to the size of CORE_ADDR. > > This is what makes it possible for GDB to debug an o32 ABI on a MIPS 64 > platform (eg IRIX 6.5). > > BTW, can you post the corresponding debug info? > > Andrew > > > > GCC 3.2 configuration: > > > > /tmp/gcc-3.2/configure --prefix=/usr/local/gcc-3.2 > > > > GDB 5.2.1 configuration > > > > PATH=/usr/local/gcc-3.2/bin:$PATH > > export PATH > > CC="gcc -m64" > > export CC > > CFLAGS="-g -O2" > > export CFLAGS > > ./configure --prefix=/usr/local/solaris2.8_64 > > > > You need to put "-m64" in CC rather than CFLAGS else "make install" fails when > > trying to build "chew". This has the unfortunate side-effect that "make check" > > also uses "gcc -m64", i.e. it never exercises "gcc" which would build a 32-bit > > program. > > > > Cheers ... Duncan. > > > > > > > > diff -r -u gdb-5.2.1.bu/gdb/dbxread.c gdb-5.2.1/gdb/dbxread.c > > --- gdb-5.2.1.bu/gdb/dbxread.c Fri Apr 5 08:33:49 2002 > > +++ gdb-5.2.1/gdb/dbxread.c Thu Nov 14 16:23:40 2002 > > @@ -2591,6 +2591,27 @@ > > fill_symbuf (abfd); > > bufp = &symbuf[symbuf_idx++]; > > INTERNALIZE_SYMBOL (nlist, bufp, abfd); > > + > > + /* ----------------------------------------------- */ > > + /* Horrible fix for when gdb is built with "-m64" */ > > + /* (sparc-sun-solaris2.8): */ > > + /* sign-extend the 32-bit result in nlist.n_value. */ > > + /* */ > > + /* This fixes the testcase in bug 567, */ > > + /* in that you can "p d1" successfully. */ > > + /* Actually you can "p" *anything* */ > > + /* (previously, you couldn't). */ > > + /* */ > > + /* I expect this will break something else, */ > > + /* we'll just have to wait to see what. */ > > + /* */ > > + /* The proper fix is for gdb to know that it's */ > > + /* working on a 32-bit program and */ > > + /* truncate addresses to 32 bits before using them */ > > + /* ----------------------------------------------- */ > > + > > + nlist.n_value = (long)(int)nlist.n_value; > > + > > OBJSTAT (objfile, n_stabs++); > > > > type = bfd_h_get_8 (abfd, bufp->e_type); > > > > > > > > /* > > * From GDB bug report 567 > > gcc -g -m64 -o double double.c > > gcc -g -o double double.c > > * > > * The report says to breakpoint on the printf line > > * & print the value of d1 > > */ > > extern int printf(const char *, ...); > > > > int > > main() > > { > > double d1; > > > > d1 = 3.3; > > printf("d1 = %f\n", d1); > > > > return 0; > > } > > > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-11-20 22:32 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-11-14 20:37 Patch for bug 567 (sparc-sun-solaris2.8) Duncan Roe 2002-11-15 16:35 ` Andrew Cagney 2002-11-15 17:43 ` Duncan Roe 2002-11-20 14:32 ` Duncan Roe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox