Re: Avoid gcc warning on sparc solaris 9

Pedro Alves
2007-10-24T13:03:38Z

[-- Attachment #1: Type: text/plain, Size: 871 bytes --]

Ulrich Weigand wrote:
> Pedro Alves wrote:
>
> > Building HEAD on a native gdb on sparc solaris 9 with gcc 3.4.6 stops due to:
> >
> > ../../src/gdb/sol-thread.c: In function `sol_thread_fetch_registers':
> > ../../src/gdb/sol-thread.c:533: warning: dereferencing type-punned
> > pointer will break strict-aliasing rules
>
> We've seen this on other platforms with gcc 3.4 as well. I think
> the best fix would be replace the problematic construct
> supply_gregset (regcache, (const gdb_gregset_t *) &gregset);
> with
>
> gdb_gregset_t *gregset_p = &gregset;
>
> supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
>
> That seemed to fix the problems e.g. in i386-linux-nat.c (fetch_regs).
>

Indeed it does fix it here too. Much nicer. Thanks for the pointer.

Testsuite shows the same results as the previous version.

OK now?

--
Cheers,
Pedro Alves

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: solaris.diff --]
[-- Type: text/x-patch; name=solaris.diff, Size: 1244 bytes --]

2007-10-24 Pedro Alves <pedro_alves@portugalmail.pt>

* sol-thread.c (sol_thread_fetch_registers): Work around gcc 3.4
alias warning bug.

---
gdb/sol-thread.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

Index: src/gdb/sol-thread.c
===================================================================
--- src.orig/gdb/sol-thread.c 2007-10-23 17:07:07.604730000 +0100
+++ src/gdb/sol-thread.c 2007-10-24 13:35:37.380474000 +0100
@@ -484,6 +484,9 @@ sol_thread_fetch_registers (struct regca
td_err_e val;
prgregset_t gregset;
prfpregset_t fpregset;
+ gdb_gregset_t *gregset_p = &gregset;
+ gdb_fpregset_t *fpregset_p = &fpregset;
+
#if 0
int xregsize;
caddr_t xregset;
@@ -530,8 +533,8 @@ sol_thread_fetch_registers (struct regca
calling the td routines because the td routines call ps_lget*
which affect the values stored in the registers array. */

- supply_gregset (regcache, (const gdb_gregset_t *) &gregset);
- supply_fpregset (regcache, (const gdb_fpregset_t *) &fpregset);
+ supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
+ supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset_p);

#if 0
/* FIXME: libthread_db doesn't seem to handle this right. */