This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch] Don't refer to current architecture when allocating a new one
- To: gdb-patches at sources dot redhat dot com
- Subject: [patch] Don't refer to current architecture when allocating a new one
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Tue, 25 Sep 2001 23:42:57 -0400
Hello,
The attached fixes a potentially nasty but some what theoretical bug.
The code in gdbarch_alloc() was refering to macros such as
``TARGET_LONG_BIT'' when initializing various fields vis:
gdbarch->target_long_long_bit = 2*TARGET_LONG_BIT;
Unfortunatly such macros refer to the global ``current_gdbarch'' and
hence the code picks up the value of TARGET_LONG_BIT from the previous
and not this new architecture :-( The obvious fix would be to just not
use the macros. Unfortunatly due to the way a non-multi-arch
configuration works, that isn't possible.
The attached addresses the problem by naming local variable designating
the new architecture ``curent_gdbarch''. That way all macros refer to
that local variable and not the global.
As an asside, people multi-arching targets should be aware of this
potential problem in their code. I've a follow on patch to ensure it
doesn't happen but it is some what prutal.
Andrew
2001-09-25 Andrew Cagney <ac131313@redhat.com>
* gdbarch.sh (gdbarch_alloc): Name the new architecture
``current_gdbarch'' so that it, and not the identically named
global is refered to by macros.
* gdbarch.c: Regenerate.
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.77
diff -p -r1.77 gdbarch.sh
*** gdbarch.sh 2001/09/05 23:44:43 1.77
--- gdbarch.sh 2001/09/26 03:28:22
*************** struct gdbarch *
*** 1289,1307 ****
gdbarch_alloc (const struct gdbarch_info *info,
struct gdbarch_tdep *tdep)
{
! struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
! memset (gdbarch, 0, sizeof (*gdbarch));
! alloc_gdbarch_data (gdbarch);
! gdbarch->tdep = tdep;
EOF
printf "\n"
function_list | while do_read
do
if class_is_info_p
then
! printf " gdbarch->${function} = info->${function};\n"
fi
done
printf "\n"
--- 1289,1313 ----
gdbarch_alloc (const struct gdbarch_info *info,
struct gdbarch_tdep *tdep)
{
! /* NOTE: The new architecture variable is named \`\`current_gdbarch''
! so that macros such as TARGET_DOUBLE_BIT, when expanded, refer to
! the current local architecture and not the previous global
! architecture. This ensures that the new architectures initial
! values are not influenced by the previous architecture. Once
! everything is parameterised with gdbarch, this will go away. */
! struct gdbarch *current_gdbarch = XMALLOC (struct gdbarch);
! memset (current_gdbarch, 0, sizeof (*current_gdbarch));
! alloc_gdbarch_data (current_gdbarch);
! current_gdbarch->tdep = tdep;
EOF
printf "\n"
function_list | while do_read
do
if class_is_info_p
then
! printf " current_gdbarch->${function} = info->${function};\n"
fi
done
printf "\n"
*************** do
*** 1312,1325 ****
then
if [ -n "${predefault}" -a "x${predefault}" != "x0" ]
then
! printf " gdbarch->${function} = ${predefault};\n"
fi
fi
done
cat <<EOF
/* gdbarch_alloc() */
! return gdbarch;
}
EOF
--- 1318,1331 ----
then
if [ -n "${predefault}" -a "x${predefault}" != "x0" ]
then
! printf " current_gdbarch->${function} = ${predefault};\n"
fi
fi
done
cat <<EOF
/* gdbarch_alloc() */
! return current_gdbarch;
}
EOF