- fmt.count = 1;
-
- if (exp && *exp == '/')
- {
- exp++;
- fmt = decode_format (&exp, last_format, last_size);
- last_size = fmt.size;
- last_format = fmt.format;
- }
-
- /* If we have an expression, evaluate it and use it as the address. */
-
- if (exp != 0 && *exp != 0)
- {
- expr = parse_c_expression (exp);
- /* Cause expression not to be there any more
- if this command is repeated with Newline.
- But don't clobber a user-defined command's definition. */
- if (from_tty)
- *exp = 0;
- old_chain = make_cleanup (free_current_contents, &expr);
- val = evaluate_expression (expr);
- /* In rvalue contexts, such as this, functions are coerced into
- pointers to functions. This makes "x/i main" work. */
- if (/* last_format == 'i'
- && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
- && VALUE_LVAL (val) == lval_memory)
- next_address = VALUE_ADDRESS (val);
- else
- next_address = (CORE_ADDR) value_as_long (val);
- do_cleanups (old_chain);
- }
-
- do_examine (fmt, next_address);
-
- /* Set a couple of internal variables if appropriate. */
- if (last_examine_value)
- {
- /* Make last address examined available to the user as $_. */
- set_internalvar (lookup_internalvar ("_"),
- value_from_long (builtin_type_int,
- (LONGEST) last_examine_address));
-
- /* Make contents of last address examined available to the user as $__.*/
- set_internalvar (lookup_internalvar ("__"), last_examine_value);
- }
-}
-\f
-/* Commands for printing types of things. */
-
-/* Print type of EXP, or last thing in value history if EXP == NULL.
- show is passed to type_print. */
-static void
-whatis_exp (exp, show)
- char *exp;
- int show;
-{
- struct expression *expr;
- register value val;
- register struct cleanup *old_chain;
-
- if (exp)
- {
- expr = parse_c_expression (exp);
- old_chain = make_cleanup (free_current_contents, &expr);
- val = evaluate_type (expr);
- }
- else
- val = access_value_history (0);
-
- printf_filtered ("type = ");
- type_print (VALUE_TYPE (val), "", stdout, show);
- printf_filtered ("\n");
-
- if (exp)
- do_cleanups (old_chain);
-}
-
-static void
-whatis_command (exp, from_tty)
- char *exp;
- int from_tty;
-{
- /* Most of the time users do not want to see all the fields
- in a structure. If they do they can use the "ptype" command.
- Hence the "-1" below. */
- whatis_exp (exp, -1);
-}
-
-/* TYPENAME is either the name of a type, or an expression. */
-static void
-ptype_command (typename, from_tty)
- char *typename;
- int from_tty;
-{
- register char *p = typename;
- register int len;
- register struct block *b
- = target_has_stack ? get_current_block () : 0;
- register struct type *type;
-
- if (typename == 0)
- {
- whatis_exp (typename, 1);
- return;
- }
-
- while (*p && *p != ' ' && *p != '\t') p++;
- len = p - typename;
- while (*p == ' ' || *p == '\t') p++;
-
- if (len == 6 && !strncmp (typename, "struct", 6))
- type = lookup_struct (p, b);
- else if (len == 5 && !strncmp (typename, "union", 5))
- type = lookup_union (p, b);
- else if (len == 4 && !strncmp (typename, "enum", 4))
- type = lookup_enum (p, b);
- else
- {
- type = lookup_typename (typename, b, 1);
- if (type == 0)
- {
- register struct symbol *sym
- = lookup_symbol (typename, b, STRUCT_NAMESPACE, 0,
- (struct symtab **)NULL);
- if (sym == 0)
- {
- whatis_exp (typename, 1 /* FIXME: right? */);
- return;
- }
- printf_filtered ("No type named %s, but there is a ",
- typename);
- switch (TYPE_CODE (SYMBOL_TYPE (sym)))
- {
- case TYPE_CODE_STRUCT:
- printf_filtered ("struct");
- break;
-
- case TYPE_CODE_UNION:
- printf_filtered ("union");
- break;
-
- case TYPE_CODE_ENUM:
- printf_filtered ("enum");
- break;