aboutsummaryrefslogtreecommitdiff
path: root/gdb/printcmd.c
diff options
context:
space:
mode:
authorJohn Gilmore <gnu@cygnus>1991-11-09 07:45:36 +0000
committerJohn Gilmore <gnu@cygnus>1991-11-09 07:45:36 +0000
commitc466820795c1eccb540b676f32c42ff71d592610 (patch)
tree08fc66ce2376c69f11bb591dbc62ac54901cfdf7 /gdb/printcmd.c
parentbb5ae298fcd30ddac9689777f22a02d82f04fedd (diff)
downloadgdb-c466820795c1eccb540b676f32c42ff71d592610.zip
gdb-c466820795c1eccb540b676f32c42ff71d592610.tar.gz
gdb-c466820795c1eccb540b676f32c42ff71d592610.tar.bz2
Lint and some rs/6000 port.
Diffstat (limited to 'gdb/printcmd.c')
-rw-r--r--gdb/printcmd.c256
1 files changed, 101 insertions, 155 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 7608254..ec96d49 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -24,6 +24,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "frame.h"
#include "symtab.h"
#include "value.h"
+#include "language.h"
#include "expression.h"
#include "gdbcore.h"
#include "gdbcmd.h"
@@ -207,6 +208,7 @@ print_formatted (val, format, size)
break;
case 'i':
+ wrap_here (""); /* Force output out, print_insn not using _filtered */
next_address = VALUE_ADDRESS (val)
+ print_insn (VALUE_ADDRESS (val), stdout);
break;
@@ -247,22 +249,26 @@ print_scalar_formatted (valaddr, type, format, size, stream)
{
/* ok, we're going to have to get fancy here. Assumption: a
long is four bytes. FIXME. */
- unsigned long v1, v2, tmp;
+ unsigned long v1, v2;
v1 = unpack_long (builtin_type_long, valaddr);
v2 = unpack_long (builtin_type_long, valaddr + 4);
#if TARGET_BYTE_ORDER == LITTLE_ENDIAN
/* Swap the two for printing */
- tmp = v1;
- v1 = v2;
- v2 = tmp;
+ {
+ unsigned long tmp;
+
+ tmp = v1;
+ v1 = v2;
+ v2 = tmp;
+ }
#endif
switch (format)
{
case 'x':
- fprintf_filtered (stream, "0x%08x%08x", v1, v2);
+ fprintf_filtered (stream, local_hex_format_custom("08x%08"), v1, v2);
break;
default:
error ("Output size \"g\" unimplemented for format \"%c\".",
@@ -291,9 +297,9 @@ print_scalar_formatted (valaddr, type, format, size, stream)
{
/* no size specified, like in print. Print varying # of digits. */
#if defined (LONG_LONG)
- fprintf_filtered (stream, "0x%llx", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("ll"), val_long);
#else /* not LONG_LONG. */
- fprintf_filtered (stream, "0x%lx", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("l"), val_long);
#endif /* not LONG_LONG. */
}
else
@@ -301,16 +307,16 @@ print_scalar_formatted (valaddr, type, format, size, stream)
switch (size)
{
case 'b':
- fprintf_filtered (stream, "0x%02llx", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("02ll"), val_long);
break;
case 'h':
- fprintf_filtered (stream, "0x%04llx", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("04ll"), val_long);
break;
case 'w':
- fprintf_filtered (stream, "0x%08llx", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("08ll"), val_long);
break;
case 'g':
- fprintf_filtered (stream, "0x%016llx", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("016ll"), val_long);
break;
default:
error ("Undefined output size \"%c\".", size);
@@ -319,16 +325,16 @@ print_scalar_formatted (valaddr, type, format, size, stream)
switch (size)
{
case 'b':
- fprintf_filtered (stream, "0x%02x", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("02"), val_long);
break;
case 'h':
- fprintf_filtered (stream, "0x%04x", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("04"), val_long);
break;
case 'w':
- fprintf_filtered (stream, "0x%08x", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("08"), val_long);
break;
case 'g':
- fprintf_filtered (stream, "0x%016x", val_long);
+ fprintf_filtered (stream, local_hex_format_custom("016"), val_long);
break;
default:
error ("Undefined output size \"%c\".", size);
@@ -355,9 +361,9 @@ print_scalar_formatted (valaddr, type, format, size, stream)
case 'o':
if (val_long)
#ifdef LONG_LONG
- fprintf_filtered (stream, "0%llo", val_long);
+ fprintf_filtered (stream, local_octal_format_custom("ll"), val_long);
#else
- fprintf_filtered (stream, "0%o", val_long);
+ fprintf_filtered (stream, local_octal_format(), val_long);
#endif
else
fprintf_filtered (stream, "0");
@@ -368,7 +374,7 @@ print_scalar_formatted (valaddr, type, format, size, stream)
break;
case 'c':
- value_print (value_from_long (builtin_type_char, val_long), stream, 0,
+ value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
Val_pretty_default);
break;
@@ -444,7 +450,8 @@ set_next_address (addr)
/* Make address available to the user as $_. */
set_internalvar (lookup_internalvar ("_"),
- value_from_long (builtin_type_int, (LONGEST) addr));
+ value_from_longest (lookup_pointer_type (builtin_type_void),
+ (LONGEST) addr));
}
/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
@@ -490,7 +497,7 @@ print_address (addr, stream)
CORE_ADDR addr;
FILE *stream;
{
- fprintf_filtered (stream, "0x%x", addr);
+ fprintf_filtered (stream, local_hex_format(), addr);
print_address_symbolic (addr, stream, asm_demangle, " ");
}
@@ -508,7 +515,7 @@ print_address_demangle (addr, stream, do_demangle)
if (addr == 0) {
fprintf_filtered (stream, "0");
} else if (addressprint) {
- fprintf_filtered (stream, "0x%x", addr);
+ fprintf_filtered (stream, local_hex_format(), addr);
print_address_symbolic (addr, stream, do_demangle, " ");
} else {
print_address_symbolic (addr, stream, do_demangle, "");
@@ -634,7 +641,7 @@ print_command_1 (exp, inspect, voidprint)
{
extern int objectprint;
struct type *type;
- expr = parse_c_expression (exp);
+ expr = parse_expression (exp);
old_chain = make_cleanup (free_current_contents, &expr);
cleanup = 1;
val = evaluate_expression (expr);
@@ -732,7 +739,7 @@ output_command (exp, from_tty)
format = fmt.format;
}
- expr = parse_c_expression (exp);
+ expr = parse_expression (exp);
old_chain = make_cleanup (free_current_contents, &expr);
val = evaluate_expression (expr);
@@ -748,7 +755,7 @@ set_command (exp, from_tty)
char *exp;
int from_tty;
{
- struct expression *expr = parse_c_expression (exp);
+ struct expression *expr = parse_expression (exp);
register struct cleanup *old_chain
= make_cleanup (free_current_contents, &expr);
evaluate_expression (expr);
@@ -786,8 +793,8 @@ address_info (exp, from_tty)
break;
if (i < misc_function_count)
- printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n",
- exp, misc_function_vector[i].address);
+ printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
+ exp, local_hex_string(misc_function_vector[i].address));
else
error ("No symbol \"%s\" in current context.", exp);
return;
@@ -804,7 +811,7 @@ address_info (exp, from_tty)
break;
case LOC_LABEL:
- printf ("a label at address 0x%x", SYMBOL_VALUE_ADDRESS (sym));
+ printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
break;
case LOC_REGISTER:
@@ -812,7 +819,7 @@ address_info (exp, from_tty)
break;
case LOC_STATIC:
- printf ("static at address 0x%x", SYMBOL_VALUE_ADDRESS (sym));
+ printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
break;
case LOC_REGPARM:
@@ -840,13 +847,8 @@ address_info (exp, from_tty)
break;
case LOC_BLOCK:
- printf ("a function at address 0x%x",
- BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
- break;
-
- case LOC_EXTERNAL:
- printf ("an external symbol at address 0x%x",
- SYMBOL_VALUE_ADDRESS (sym));
+ printf ("a function at address %s",
+ local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
break;
default:
@@ -882,7 +884,7 @@ x_command (exp, from_tty)
if (exp != 0 && *exp != 0)
{
- expr = parse_c_expression (exp);
+ expr = parse_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. */
@@ -908,10 +910,12 @@ x_command (exp, from_tty)
/* Set a couple of internal variables if appropriate. */
if (last_examine_value)
{
- /* Make last address examined available to the user as $_. */
+ /* Make last address examined available to the user as $_. Use
+ the correct pointer type. */
set_internalvar (lookup_internalvar ("_"),
- value_from_long (builtin_type_int,
- (LONGEST) last_examine_address));
+ value_from_longest (
+ lookup_pointer_type (VALUE_TYPE (last_examine_value)),
+ (LONGEST) last_examine_address));
/* Make contents of last address examined available to the user as $__.*/
set_internalvar (lookup_internalvar ("__"), last_examine_value);
@@ -933,7 +937,7 @@ whatis_exp (exp, show)
if (exp)
{
- expr = parse_c_expression (exp);
+ expr = parse_expression (exp);
old_chain = make_cleanup (free_current_contents, &expr);
val = evaluate_type (expr);
}
@@ -960,6 +964,18 @@ whatis_command (exp, from_tty)
whatis_exp (exp, -1);
}
+/* Simple subroutine for ptype_command. */
+static
+struct type *
+ptype_eval(exp)
+ struct expression *exp;
+{
+ if(exp->elts[0].opcode==OP_TYPE)
+ return exp->elts[1].type;
+ else
+ return 0;
+}
+
/* TYPENAME is either the name of a type, or an expression. */
/* ARGSUSED */
static void
@@ -967,105 +983,32 @@ 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;
+ struct expression *expr;
+ register struct cleanup *old_chain;
- 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)
- {
- /* It's not the name of a type, either VAR_NAMESPACE
- or STRUCT_NAMESPACE, so it must be an expression. */
- whatis_exp (typename, 1);
- return;
- }
- printf_filtered ("No type named %s, ", typename);
- wrap_here ("");
- printf_filtered ("but there is ");
- switch (TYPE_CODE (SYMBOL_TYPE (sym)))
- {
- case TYPE_CODE_STRUCT:
- printf_filtered ("a struct");
- break;
-
- case TYPE_CODE_UNION:
- printf_filtered ("a union");
- break;
-
- case TYPE_CODE_ENUM:
- printf_filtered ("an enum");
- break;
-
- default:
- printf_filtered ("(Internal error in gdb)");
- break;
- }
- printf_filtered (" %s. ", typename);
- wrap_here ("");
- printf_filtered ("(Type \"help ptype\".)\n");
- type = SYMBOL_TYPE (sym);
- }
- }
-
- type_print (type, "", stdout, 1);
- printf_filtered ("\n");
-}
-
-#if 0
-/* This is not necessary. Instead, decode_line_1 takes any variable,
- so "info line foo" is a close equivalent to "whereis foo". */
-static void
-whereis_command (var, from_tty)
- char *var;
- int from_tty;
-{
- struct symtab *s;
- struct symbol *sym;
-
- if (var == NULL)
- error_no_arg ("Variable name.");
-
- sym = lookup_symbol (var, get_selected_block (), VAR_NAMESPACE,
- NULL, &s);
-
- if (sym != NULL && s != NULL)
- printf_filtered ("Symbol \"%s\" is at line %d of file %s\n",
- var, sym->line, s->filename);
+ if (typename)
+ {
+ expr = parse_expression (typename);
+ old_chain = make_cleanup (free_current_contents, &expr);
+ type = ptype_eval (expr);
+
+ if(type)
+ {
+ printf_filtered ("type = ");
+ type_print (type, "", stdout, 1);
+ printf_filtered ("\n");
+ do_cleanups (old_chain);
+ }
+ else
+ {
+ do_cleanups (old_chain);
+ whatis_exp (typename, 1);
+ }
+ }
else
- {
- if (lookup_misc_func (var) >= 0)
- printf_filtered ("Symbol \"%s\" is in a file compiled without -g.",
- var);
- else
- error ("No symbol \"%s\" in current context.", var);
- }
+ whatis_exp (typename, 1);
}
-#endif /* 0 */
enum display_status {disabled, enabled};
@@ -1127,7 +1070,7 @@ display_command (exp, from_tty)
}
innermost_block = 0;
- expr = parse_c_expression (exp);
+ expr = parse_expression (exp);
new = (struct display *) xmalloc (sizeof (struct display));
@@ -1493,22 +1436,10 @@ print_frame_args (func, fi, num, stream)
QUIT;
sym = BLOCK_SYM (b, i);
- if (SYMBOL_CLASS (sym) != LOC_REGPARM
- && SYMBOL_CLASS (sym) != LOC_ARG
- && SYMBOL_CLASS (sym) != LOC_LOCAL_ARG
- && SYMBOL_CLASS (sym) != LOC_REF_ARG)
- continue;
-
- /* We have to re-look-up the symbol because arguments often have
- two entries (one a parameter, one a register or local), and the one
- we want is the non-parm, which lookup_symbol will find for
- us. After this, sym could be any SYMBOL_CLASS... */
- sym = lookup_symbol (SYMBOL_NAME (sym),
- b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
+ /* Keep track of the highest stack argument offset seen, and
+ skip over any kinds of symbols we don't care about. */
switch (SYMBOL_CLASS (sym)) {
-
- /* Keep track of the highest stack argument offset seen */
case LOC_ARG:
case LOC_REF_ARG:
{
@@ -1531,11 +1462,24 @@ print_frame_args (func, fi, num, stream)
args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
}
- /* Other types of symbols don't need to be kept track of. */
- default:
+ /* We care about types of symbols, but don't need to keep track of
+ stack offsets in them. */
+ case LOC_REGPARM:
+ case LOC_LOCAL_ARG:
break;
+
+ /* Other types of symbols we just skip over. */
+ default:
+ continue;
}
+ /* We have to re-look-up the symbol because arguments often have
+ two entries (one a parameter, one a register or local), and the one
+ we want is the non-parm, which lookup_symbol will find for
+ us. After this, sym could be any SYMBOL_CLASS... */
+ sym = lookup_symbol (SYMBOL_NAME (sym),
+ b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
+
/* Print the current arg. */
if (! first)
fprintf_filtered (stream, ", ");
@@ -1900,7 +1844,8 @@ disassemble_command (arg, from_tty)
printf_filtered ("for function %s:\n", name);
}
else
- printf_filtered ("from 0x%x to 0x%x:\n", low, high);
+ printf_filtered ("from %s ", local_hex_string(low));
+ printf_filtered ("to %s:\n", local_hex_string(high));
/* Dump the specified range. */
for (pc = low; pc < high; )
@@ -2016,8 +1961,9 @@ You can see these environment settings with the \"show\" command.",
/* "call" is the same as "set", but handy for dbx users to call fns. */
add_com ("call", class_vars, call_command,
"Call a function in the inferior process.\n\
-The argument is the function name and arguments, in standard C notation.\n\
-The result is printed and saved in the value history, if it is not void.");
+The argument is the function name and arguments, in the notation of the\n\
+current working language. The result is printed and saved in the value\n\
+history, if it is not void.");
add_cmd ("variable", class_vars, set_command,
"Perform an assignment VAR = EXP.\n\