From 36b9d39cf464e3511c08399cbce1da7e098fde69 Mon Sep 17 00:00:00 2001 From: John Gilmore Date: Sun, 14 Jul 1991 07:48:06 +0000 Subject: [PATCH] * findvar.c (find_var_value): Handle &function better. * TODO: Document work needed on &fn and &array. * printcmd.c (print_address_symbolic): New arg is the prefix to print if a name is printed. (print_address_demangle): Honor "set print address" now. Use new arg above to improve spacing of output. * valprint.c (val_print): When printing function pointers, print symbolic form too. * breakpoint.c (breakpoint_1): Use new print_address_symbolic. --- gdb/ChangeLog | 12 ++++++++++++ gdb/TODO | 9 ++++++++- gdb/findvar.c | 32 +++++++++++++++++++------------- gdb/printcmd.c | 39 +++++++++++++++++++++++++-------------- gdb/valprint.c | 23 +++++++++++++++-------- 5 files changed, 79 insertions(+), 36 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1024177f8cb..07cbc3fbfc1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +Sun Jul 14 00:42:53 1991 John Gilmore (gnu at cygint.cygnus.com) + + * findvar.c (find_var_value): Handle &function better. + * TODO: Document work needed on &fn and &array. + * printcmd.c (print_address_symbolic): New arg is the prefix + to print if a name is printed. + (print_address_demangle): Honor "set print address" now. + Use new arg above to improve spacing of output. + * valprint.c (val_print): When printing function pointers, + print symbolic form too. + * breakpoint.c (breakpoint_1): Use new print_address_symbolic. + Mon Jul 8 19:02:46 1991 John Gilmore (gnu at cygint.cygnus.com) * core.c (memory_error): Reword error msg to mislead less. diff --git a/gdb/TODO b/gdb/TODO index 93dce626fe0..45b780f39f5 100644 --- a/gdb/TODO +++ b/gdb/TODO @@ -316,9 +316,16 @@ struct with a field name that matches the superclass name. This can happen when the struct was defined before the superclass (before the name became a typedef). -For "float point[15];": +Handling of "&" address-of operator needs some serious overhaul +for ANSI C and consistency on arrays and functions. + For "float point[15];": ptype &point[4] ==> Attempt to take address of non-lvalue. p &point[4] ==> Dereferences point[4] rather than giving you point+4. + For "char *malloc();": +ptype malloc ==> "char *()"; should be same as +ptype &malloc ==> "char *(*)()" +call printf ("%x\n", malloc) ==> wierd value, should be same as +call printf ("%x\n", &malloc) ==> correct value Fix symbol reading in the presence of interrupts. It currently leaves a cleanup to blow away the entire symbol table when a QUIT occurs. diff --git a/gdb/findvar.c b/gdb/findvar.c index 106fadf2c06..58da6b6a3fb 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -3,19 +3,19 @@ This file is part of GDB. -GDB is free software; you can redistribute it and/or modify +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. -GDB is distributed in the hope that it will be useful, +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include "defs.h" @@ -390,10 +390,13 @@ read_var_value (var, frame) return v; case LOC_CONST_BYTES: - addr = SYMBOL_VALUE_ADDRESS (var); - bcopy (addr, VALUE_CONTENTS_RAW (v), len); - VALUE_LVAL (v) = not_lval; - return v; + { + char *bytes_addr; + bytes_addr = SYMBOL_VALUE_BYTES (var); + bcopy (bytes_addr, VALUE_CONTENTS_RAW (v), len); + VALUE_LVAL (v) = not_lval; + return v; + } case LOC_STATIC: case LOC_EXTERNAL: @@ -631,9 +634,10 @@ value_from_register (type, regnum, frame) return v; } -/* Given a struct symbol for a variable, +/* Given a struct symbol for a variable or function, and a stack frame id, - return a (pointer to a) struct value containing the variable's address. */ + return a (pointer to a) struct value containing the properly typed + address. */ value locate_var_value (var, frame) @@ -652,7 +656,8 @@ locate_var_value (var, frame) if (lazy_value == 0) error ("Address of \"%s\" is unknown.", SYMBOL_NAME (var)); - if (VALUE_LAZY (lazy_value)) + if (VALUE_LAZY (lazy_value) + || TYPE_CODE (type) == TYPE_CODE_FUNC) { addr = VALUE_ADDRESS (lazy_value); @@ -668,6 +673,7 @@ locate_var_value (var, frame) } /* Address of an array is of the type of address of it's elements. */ + /* FIXME, this is probably wrong now for ANSI C. */ result_type = lookup_pointer_type (TYPE_CODE (type) == TYPE_CODE_ARRAY ? TYPE_TARGET_TYPE (type) : type); diff --git a/gdb/printcmd.c b/gdb/printcmd.c index a5251eb0fd7..760825404e6 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -3,19 +3,19 @@ This file is part of GDB. -GDB is free software; you can redistribute it and/or modify +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. -GDB is distributed in the hope that it will be useful, +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include @@ -30,6 +30,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "target.h" extern int asm_demangle; /* Whether to demangle syms in asm printouts */ +extern int addressprint; /* Whether to print hex addresses in HLL " */ extern struct block *get_current_block (); @@ -446,16 +447,18 @@ set_next_address (addr) value_from_long (builtin_type_int, (LONGEST) addr)); } -/* Optionally print address ADDR symbolically as on STREAM. +/* Optionally print address ADDR symbolically as on STREAM, + after LEADIN. Print nothing if no symbolic name is found nearby. DO_DEMANGLE controls whether to print a symbol in its native "raw" form, or to interpret it as a possible C++ name and convert it back to source form. */ void -print_address_symbolic (addr, stream, do_demangle) +print_address_symbolic (addr, stream, do_demangle, leadin) CORE_ADDR addr; FILE *stream; int do_demangle; + char *leadin; { int name_location; register int i = find_pc_misc_function (addr); @@ -465,7 +468,8 @@ print_address_symbolic (addr, stream, do_demangle) if (i < 0) return; - fputs_filtered (" <", stream); + fputs_filtered (leadin, stream); + fputs_filtered ("<", stream); if (do_demangle) fputs_demangled (misc_function_vector[i].name, stream, 1); else @@ -487,11 +491,13 @@ print_address (addr, stream) FILE *stream; { fprintf_filtered (stream, "0x%x", addr); - print_address_symbolic (addr, stream, asm_demangle); + print_address_symbolic (addr, stream, asm_demangle, " "); } /* Print address ADDR symbolically on STREAM. Parameter DEMANGLE - controls whether to print the symbolic name "raw" or demangled. */ + controls whether to print the symbolic name "raw" or demangled. + Global setting "addressprint" controls whether to print hex address + or not. */ void print_address_demangle (addr, stream, do_demangle) @@ -499,10 +505,15 @@ print_address_demangle (addr, stream, do_demangle) FILE *stream; int do_demangle; { - fprintf_filtered (stream, "0x%x", addr); - print_address_symbolic (addr, stream, do_demangle); + if (addr == 0) { + fprintf_filtered (stream, "0"); + } else if (addressprint) { + fprintf_filtered (stream, "0x%x", addr); + print_address_symbolic (addr, stream, do_demangle, " "); + } else { + print_address_symbolic (addr, stream, do_demangle, ""); + } } - /* Examine data at address ADDR in format FMT. diff --git a/gdb/valprint.c b/gdb/valprint.c index d91bada3565..ed2d7b67dc9 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -3,19 +3,19 @@ This file is part of GDB. -GDB is free software; you can redistribute it and/or modify +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. -GDB is distributed in the hope that it will be useful, +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include @@ -1087,11 +1087,13 @@ val_print (type, valaddr, address, stream, format, print_scalar_formatted (valaddr, type, format, 0, stream); break; } + /* FIXME, we should consider, at least for ANSI C language, eliminating + the distinction made between FUNCs and POINTERs to FUNCs. */ fprintf_filtered (stream, "{"); type_print (type, "", stream, -1); fprintf_filtered (stream, "} "); - if (addressprint) - fprintf_filtered (stream, "0x%x", address); + /* Try to print what function it points to, and its address. */ + print_address_demangle (address, stream, demangle); break; case TYPE_CODE_INT: @@ -1884,9 +1886,14 @@ _initialize_valprint () add_prefix_cmd ("print", no_class, set_print, "Generic command for setting how things print.", &setprintlist, "set print ", 0, &setlist); + add_alias_cmd ("p", "print", no_class, 1, &setlist); + add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print + to set prompt */ add_prefix_cmd ("print", no_class, show_print, "Generic command for showing print settings.", &showprintlist, "show print ", 0, &showlist); + add_alias_cmd ("p", "print", no_class, 1, &showlist); + add_alias_cmd ("pr", "print", no_class, 1, &showlist); add_show_from_set (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max, -- 2.30.2