From: Fred Fish <fnf@diveadx.com>
To: Daniel Jacobowitz <drow@false.org>
Cc: Jim Blandy <jimb@red-bean.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix ptype problem printing typedefs defined differently in different compilation units
Date: Fri, 17 Feb 2006 00:17:00 -0000 [thread overview]
Message-ID: <200602161916.00761.fnf@diveadx.com> (raw)
In-Reply-To: <20060214141056.GB21812@nevyn.them.org>
On Tuesday 14 February 2006 09:10, Daniel Jacobowitz wrote:
> This patch seems OK to me; but we really ought to fix up the comment
> directly above this code that you're changing.
I've think it would be best to split work on this issue up into two parts
(1) Make ptype and whatis handle the same arguments. Currently ptype
will work on typedefs, but whatis does not. This is the change that
makes them both use whatis_exp and eliminates ptype_eval.
(2) Make ptype and whatis handle printing types specified in a given
context using 'file'::type. I have a fix that involves a fairly
minor change to the parser and makes the patch you are commenting on
obsolete.
Here is the patch for (1). I believe we previously reached on consensus
that this change was OK, so I'd like to get it checked in. I added some
testsuite support for testing how whatis behaves with typedef names.
Gdb ChangeLog entry:
2006-02-16 Fred Fish <fnf@specifix.com>
* eval.c (evaluate_subexp_standard): For OP_TYPE, return
a non lval value zero, of the appropriate type, when avoiding
side effects.
* typeprint.c (ptype_eval): Remove function and declaration.
(ptype_command): Simplify to just a call to whatis_exp.
Testsuite ChangeLog entry:
2006-02-16 Fred Fish <fnf@specifix.com>
* gdb.base/whatis.c: Define variables using typedefs char_addr,
ushort_addr, and slong_addr, so the typedefs are not optimized
away.
* gdb.base/whatis.exp: Add tests using type name for struct type,
union type, enum type, and typedef.
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.60
diff -c -p -r1.60 eval.c
*** eval.c 17 Dec 2005 22:33:59 -0000 1.60
--- eval.c 16 Feb 2006 23:16:27 -0000
*************** evaluate_subexp_standard (struct type *e
*** 2086,2092 ****
return value_of_local ("self", 1);
case OP_TYPE:
! error (_("Attempt to use a type name as an expression"));
default:
/* Removing this case and compiling with gcc -Wall reveals that
--- 2086,2100 ----
return value_of_local ("self", 1);
case OP_TYPE:
! /* The value is not supposed to be used. This is here to make it
! easier to accommodate expressions that contain types. */
! (*pos) += 2;
! if (noside == EVAL_SKIP)
! goto nosideret;
! else if (noside == EVAL_AVOID_SIDE_EFFECTS)
! return allocate_value (exp->elts[pc + 1].type);
! else
! error (_("Attempt to use a type name as an expression"));
default:
/* Removing this case and compiling with gcc -Wall reveals that
Index: typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/typeprint.c,v
retrieving revision 1.25
diff -c -p -r1.25 typeprint.c
*** typeprint.c 17 Dec 2005 22:34:03 -0000 1.25
--- typeprint.c 16 Feb 2006 23:16:58 -0000
*************** extern void _initialize_typeprint (void)
*** 45,52 ****
static void ptype_command (char *, int);
- static struct type *ptype_eval (struct expression *);
-
static void whatis_command (char *, int);
static void whatis_exp (char *, int);
--- 45,50 ----
*************** whatis_command (char *exp, int from_tty)
*** 182,236 ****
whatis_exp (exp, -1);
}
- /* Simple subroutine for ptype_command. */
-
- static struct type *
- ptype_eval (struct expression *exp)
- {
- if (exp->elts[0].opcode == OP_TYPE)
- {
- return (exp->elts[1].type);
- }
- else
- {
- return (NULL);
- }
- }
-
/* TYPENAME is either the name of a type, or an expression. */
static void
ptype_command (char *typename, int from_tty)
{
! struct type *type;
! struct expression *expr;
! struct cleanup *old_chain;
!
! if (typename == NULL)
! {
! /* Print type of last thing in value history. */
! whatis_exp (typename, 1);
! }
! else
! {
! expr = parse_expression (typename);
! old_chain = make_cleanup (free_current_contents, &expr);
! type = ptype_eval (expr);
! if (type != NULL)
! {
! /* User did "ptype <typename>" */
! printf_filtered ("type = ");
! type_print (type, "", gdb_stdout, 1);
! printf_filtered ("\n");
! do_cleanups (old_chain);
! }
! else
! {
! /* User did "ptype <symbolname>" */
! do_cleanups (old_chain);
! whatis_exp (typename, 1);
! }
! }
}
/* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
--- 180,191 ----
whatis_exp (exp, -1);
}
/* TYPENAME is either the name of a type, or an expression. */
static void
ptype_command (char *typename, int from_tty)
{
! whatis_exp (typename, 1);
}
/* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
Index: testsuite/gdb.base/whatis.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/whatis.c,v
retrieving revision 1.3
diff -c -p -r1.3 whatis.c
*** testsuite/gdb.base/whatis.c 23 Aug 2004 13:04:03 -0000 1.3
--- testsuite/gdb.base/whatis.c 16 Feb 2006 23:22:33 -0000
*************** double v_double_array[2];
*** 79,86 ****
--- 79,89 ----
a special case kludge in GDB (Unix system include files like to define
caddr_t), but for a variety of types. */
typedef char *char_addr;
+ static char_addr a_char_addr;
typedef unsigned short *ushort_addr;
+ static ushort_addr a_ushort_addr;
typedef signed long *slong_addr;
+ static slong_addr a_slong_addr;
char *v_char_pointer;
signed char *v_signed_char_pointer;
Index: testsuite/gdb.base/whatis.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/whatis.exp,v
retrieving revision 1.6
diff -c -p -r1.6 whatis.exp
*** testsuite/gdb.base/whatis.exp 23 Aug 2004 13:04:03 -0000 1.6
--- testsuite/gdb.base/whatis.exp 16 Feb 2006 23:22:36 -0000
*************** gdb_test "whatis v_struct1" \
*** 273,278 ****
--- 273,282 ----
"type = struct t_struct" \
"whatis named structure"
+ gdb_test "whatis struct t_struct" \
+ "type = struct t_struct" \
+ "whatis named structure using type name"
+
gdb_test "whatis v_struct2" \
"type = struct \{$unstruct\}" \
"whatis unnamed structure"
*************** gdb_test "whatis v_union" \
*** 283,288 ****
--- 287,296 ----
"type = union t_union" \
"whatis named union"
+ gdb_test "whatis union t_union" \
+ "type = union t_union" \
+ "whatis named union using type name"
+
gdb_test "whatis v_union2" \
"type = union \{$ununion\}" \
"whatis unnamed union"
*************** gdb_test "whatis clunker" \
*** 371,376 ****
--- 379,388 ----
"type = enum cars" \
"whatis enumeration"
+ gdb_test "whatis enum cars" \
+ "type = enum cars" \
+ "whatis enumeration using type name"
+
# test whatis command with nested struct and union
gdb_test "whatis nested_su" \
*************** gdb_test "whatis nested_su.inner_union_i
*** 402,404 ****
--- 414,426 ----
gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
"type = int" \
"whatis inner union member"
+
+ # test whatis command with typedefs
+
+ gdb_test "whatis char_addr" \
+ "type = char \\*" \
+ "whatis using typedef type name"
+
+ gdb_test "whatis a_char_addr" \
+ "type = char_addr" \
+ "whatis applied to variable defined by typedef"
next prev parent reply other threads:[~2006-02-17 0:17 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-03 20:17 Fred Fish
2006-01-03 23:15 ` Jim Blandy
2006-01-04 2:46 ` Fred Fish
2006-01-04 3:45 ` Jim Blandy
2006-01-04 11:15 ` Fred Fish
2006-01-04 21:04 ` Fred Fish
2006-01-05 0:21 ` Jim Blandy
2006-01-05 0:26 ` Jim Blandy
2006-01-05 0:54 ` Daniel Jacobowitz
2006-01-05 4:47 ` Jim Blandy
2006-01-15 18:48 ` Daniel Jacobowitz
2006-01-16 4:22 ` Jim Blandy
2006-01-23 15:27 ` Fred Fish
2006-01-23 16:12 ` Daniel Jacobowitz
2006-01-23 16:43 ` Fred Fish
2006-01-23 19:17 ` Jim Blandy
2006-01-23 19:35 ` Fred Fish
2006-01-23 20:45 ` Jim Blandy
2006-02-11 0:39 ` Fred Fish
2006-02-11 18:35 ` Daniel Jacobowitz
2006-02-11 19:08 ` Eli Zaretskii
2006-02-11 20:13 ` Daniel Jacobowitz
2006-02-11 20:01 ` Fred Fish
2006-02-11 20:21 ` Daniel Jacobowitz
2006-02-12 18:49 ` Fred Fish
2006-02-14 14:11 ` Daniel Jacobowitz
2006-02-14 18:47 ` Fred Fish
2006-02-17 0:17 ` Fred Fish [this message]
2006-02-17 9:15 ` Eli Zaretskii
2006-02-17 13:36 ` Fred Fish
2006-02-17 20:32 ` Fred Fish
2006-02-18 9:27 ` Eli Zaretskii
2006-02-18 22:19 ` Daniel Jacobowitz
2006-02-20 15:47 ` Fred Fish
2006-02-20 16:23 ` Daniel Jacobowitz
2006-05-17 19:04 ` Fred Fish
2006-02-11 0:39 ` Fred Fish
2006-01-24 15:23 ` [commit] " Fred Fish
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200602161916.00761.fnf@diveadx.com \
--to=fnf@diveadx.com \
--cc=drow@false.org \
--cc=gdb-patches@sourceware.org \
--cc=jimb@red-bean.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox