Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFC: don't let CHECK_TYPEDEF yield a value
@ 2009-03-25 19:56 Tom Tromey
  2009-03-25 20:01 ` Daniel Jacobowitz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey @ 2009-03-25 19:56 UTC (permalink / raw)
  To: gdb-patches

While reading stack.c I noticed this code:

  type = CHECK_TYPEDEF (SYMBOL_TYPE (sym));
  while (TYPE_CODE (type) == TYPE_CODE_REF)
    type = CHECK_TYPEDEF (TYPE_TARGET_TYPE (type));

Because CHECK_TYPEDEF side-effects its argument, this can change the
type of a symbol.  That seems like a bug to me.

I thought perhaps CHECK_TYPEDEF would be safer if it were explicitly a
statement, that is, if it could not yield a value.  This does not make
it completely safe, but it does help emphasize the difference between
CHECK_TYPEDEF and check_typedef.

All the other CHECK_TYPEDEF calls appear to be safe.

Built and regtested on x86-64 (compile farm).

Let me know what you think.

Tom

2009-03-25  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.h (CHECK_TYPEDEF): Don't yield a value.
	* stack.c (print_this_frame_argument_p): Use check_typedef.

diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 816a208..3c4e948 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1185,7 +1185,10 @@ extern struct type *lookup_signed_typename (char *);
 
 extern struct type *check_typedef (struct type *);
 
-#define CHECK_TYPEDEF(TYPE) (TYPE) = check_typedef (TYPE)
+#define CHECK_TYPEDEF(TYPE)			\
+  do {						\
+    (TYPE) = check_typedef (TYPE);		\
+  } while (0)
 
 extern void check_stub_method_group (struct type *, int);
 
diff --git a/gdb/stack.c b/gdb/stack.c
index f185841..c780348 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -181,9 +181,9 @@ print_this_frame_argument_p (struct symbol *sym)
   /* The user asked to print only the scalar arguments, so do not
      print the non-scalar ones.  */
 
-  type = CHECK_TYPEDEF (SYMBOL_TYPE (sym));
+  type = check_typedef (SYMBOL_TYPE (sym));
   while (TYPE_CODE (type) == TYPE_CODE_REF)
-    type = CHECK_TYPEDEF (TYPE_TARGET_TYPE (type));
+    type = check_typedef (TYPE_TARGET_TYPE (type));
   switch (TYPE_CODE (type))
     {
       case TYPE_CODE_ARRAY:


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: don't let CHECK_TYPEDEF yield a value
  2009-03-25 19:56 RFC: don't let CHECK_TYPEDEF yield a value Tom Tromey
@ 2009-03-25 20:01 ` Daniel Jacobowitz
  2009-03-25 20:10 ` Pedro Alves
  2009-03-26  2:28 ` Tom Tromey
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2009-03-25 20:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Wed, Mar 25, 2009 at 01:43:27PM -0600, Tom Tromey wrote:
> Let me know what you think.

Makes sense to me.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: don't let CHECK_TYPEDEF yield a value
  2009-03-25 19:56 RFC: don't let CHECK_TYPEDEF yield a value Tom Tromey
  2009-03-25 20:01 ` Daniel Jacobowitz
@ 2009-03-25 20:10 ` Pedro Alves
  2009-03-26  2:28 ` Tom Tromey
  2 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2009-03-25 20:10 UTC (permalink / raw)
  To: gdb-patches, tromey

Pm Wednesday 25 March 2009 19:43:27, Tom Tromey wrote:
> Let me know what you think.

Makes sense to me.

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: don't let CHECK_TYPEDEF yield a value
  2009-03-25 19:56 RFC: don't let CHECK_TYPEDEF yield a value Tom Tromey
  2009-03-25 20:01 ` Daniel Jacobowitz
  2009-03-25 20:10 ` Pedro Alves
@ 2009-03-26  2:28 ` Tom Tromey
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2009-03-26  2:28 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> 2009-03-25  Tom Tromey  <tromey@redhat.com>
Tom> 	* gdbtypes.h (CHECK_TYPEDEF): Don't yield a value.
Tom> 	* stack.c (print_this_frame_argument_p): Use check_typedef.

Daniel, Pedro, thanks for responding.
I'm checking this in.

Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-03-26  1:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-25 19:56 RFC: don't let CHECK_TYPEDEF yield a value Tom Tromey
2009-03-25 20:01 ` Daniel Jacobowitz
2009-03-25 20:10 ` Pedro Alves
2009-03-26  2:28 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox