From e3ecf7c8474926a46815f21edb56270b594fe7e6 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Wed, 26 Mar 2003 20:33:47 +0000 Subject: 2003-03-26 Andrew Cagney Add frame debug info addresses: * frame-base.c: New file. * frame-base.h: New file. * frame.h (struct frame_base): Add opaque declaration. (get_frame_base): Update comment. (get_frame_base_address): Declare. (get_frame_locals_address): Declare. (get_frame_args_address): Declare. (struct frame_info): Add "base" and "base_cache". Update comments on the unwinder. * frame.c: Include "frame-base.h". (get_frame_locals_address): New function. (get_frame_base_address): New function. (get_frame_args_address): New function. * findvar.c (read_var_value): Use get_frame_locals_address. * stack.c (frame_info): Use get_frame_locals_address and get_frame_args_address. (FRAME_ARGS_ADDRESS_CORRECT): Delete conditionally defined macro, moved to "frame-base.c". * Makefile.in (frame_base_h): Define. (frame.o): Update dependencies. (d10v-tdep.o): Update dependencies. (frame-base.o): Add dependencies. (SFILES): Add frame-base.c. (COMMON_OBS): Add frame-base.o. * printcmd.c (print_frame_nameless_args): Ditto. * symtab.h (address_class): Update comments. * dwarf2loc.c (dwarf_expr_frame_base): Add note about get_frame_base_address. * dwarf2expr.c (execute_stack_op): Ditto. * d10v-tdep.c: Include "frame-base.h". (d10v_frame_unwind): Make constant. (d10v_frame_base_address): New function. (d10v_frame_base): New variable. (d10v_gdbarch_init): Set frame_base default. --- gdb/ChangeLog | 38 +++++++++++++++++++++++ gdb/Makefile.in | 20 +++++++----- gdb/d10v-tdep.c | 20 ++++++++++-- gdb/dwarf2expr.c | 3 ++ gdb/dwarf2loc.c | 3 ++ gdb/findvar.c | 2 +- gdb/frame.c | 53 +++++++++++++++++++++++++++++++ gdb/frame.h | 95 +++++++++++++++++++++++++++++--------------------------- gdb/printcmd.c | 2 +- gdb/stack.c | 14 ++------- gdb/symtab.h | 10 +++--- 11 files changed, 186 insertions(+), 74 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 24f5b8a0752..a0f277072b1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,41 @@ +2003-03-26 Andrew Cagney + + Add frame debug info addresses: + * frame-base.c: New file. + * frame-base.h: New file. + * frame.h (struct frame_base): Add opaque declaration. + (get_frame_base): Update comment. + (get_frame_base_address): Declare. + (get_frame_locals_address): Declare. + (get_frame_args_address): Declare. + (struct frame_info): Add "base" and "base_cache". Update + comments on the unwinder. + * frame.c: Include "frame-base.h". + (get_frame_locals_address): New function. + (get_frame_base_address): New function. + (get_frame_args_address): New function. + * findvar.c (read_var_value): Use get_frame_locals_address. + * stack.c (frame_info): Use get_frame_locals_address and + get_frame_args_address. + (FRAME_ARGS_ADDRESS_CORRECT): Delete conditionally defined macro, + moved to "frame-base.c". + * Makefile.in (frame_base_h): Define. + (frame.o): Update dependencies. + (d10v-tdep.o): Update dependencies. + (frame-base.o): Add dependencies. + (SFILES): Add frame-base.c. + (COMMON_OBS): Add frame-base.o. + * printcmd.c (print_frame_nameless_args): Ditto. + * symtab.h (address_class): Update comments. + * dwarf2loc.c (dwarf_expr_frame_base): Add note about + get_frame_base_address. + * dwarf2expr.c (execute_stack_op): Ditto. + * d10v-tdep.c: Include "frame-base.h". + (d10v_frame_unwind): Make constant. + (d10v_frame_base_address): New function. + (d10v_frame_base): New variable. + (d10v_gdbarch_init): Set frame_base default. + 2003-03-26 Daniel Jacobowitz * breakpoint.c (handle_gnu_4_16_catch_command, get_catch_sals) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index d7666e48216..5449392c4d9 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -517,6 +517,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \ dummy-frame.c dwarfread.c dwarf2expr.c dwarf2loc.c dwarf2read.c \ elfread.c environ.c eval.c event-loop.c event-top.c expprint.c \ f-exp.y f-lang.c f-typeprint.c f-valprint.c findvar.c frame.c \ + frame-base.c \ frame-unwind.c \ gdbarch.c arch-utils.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \ hpacc-abi.c \ @@ -641,6 +642,7 @@ expression_h = expression.h $(symtab_h) $(doublest_h) f_lang_h = f-lang.h frame_h = frame.h frame_unwind_h = frame-unwind.h +frame_base_h = frame-base.h gdb_events_h = gdb-events.h gdb_stabs_h = gdb-stabs.h gdb_h = gdb.h @@ -858,6 +860,7 @@ COMMON_OBS = version.o blockframe.o breakpoint.o findvar.o regcache.o \ nlmread.o serial.o mdebugread.o top.o utils.o \ ui-file.o \ frame.o frame-unwind.o doublest.o \ + frame-base.o \ gnu-v2-abi.o gnu-v3-abi.o hpacc-abi.o cp-abi.o cp-support.o \ reggroups.o @@ -1618,11 +1621,11 @@ cris-tdep.o: cris-tdep.c $(defs_h) $(frame_h) $(symtab_h) $(inferior_h) \ $(gdbtypes_h) $(gdbcore_h) $(gdbcmd_h) $(target_h) $(value_h) \ $(opcode_cris_h) $(arch_utils_h) $(regcache_h) $(symfile_h) \ $(solib_h) $(solib_svr4_h) $(gdb_string_h) -d10v-tdep.o: d10v-tdep.c $(defs_h) $(frame_h) $(symtab_h) $(gdbtypes_h) \ - $(gdbcmd_h) $(gdbcore_h) $(gdb_string_h) $(value_h) $(inferior_h) \ - $(dis_asm_h) $(symfile_h) $(objfiles_h) $(language_h) $(arch_utils_h) \ - $(regcache_h) $(floatformat_h) $(gdb_sim_d10v_h) $(sim_regno_h) \ - $(gdb_assert_h) +d10v-tdep.o: d10v-tdep.c $(defs_h) $(frame_h) $(frame_unwind_h) \ + $(frame_base_h) $(symtab_h) $(gdbtypes_h) $(gdbcmd_h) $(gdbcore_h) \ + $(gdb_string_h) $(value_h) $(inferior_h) $(dis_asm_h) $(symfile_h) \ + $(objfiles_h) $(language_h) $(arch_utils_h) $(regcache_h) \ + $(floatformat_h) $(gdb_sim_d10v_h) $(sim_regno_h) $(gdb_assert_h) dbug-rom.o: dbug-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \ $(serial_h) $(regcache_h) $(m68k_tdep_h) dbxread.o: dbxread.c $(defs_h) $(gdb_string_h) $(gdb_obstack_h) \ @@ -1702,9 +1705,10 @@ fork-child.o: fork-child.c $(defs_h) $(gdb_string_h) $(frame_h) \ $(terminal_h) $(gdbthread_h) $(command_h) frame.o: frame.c $(defs_h) $(frame_h) $(target_h) $(value_h) $(inferior_h) \ $(regcache_h) $(gdb_assert_h) $(gdb_string_h) $(builtin_regs_h) \ - $(gdb_obstack_h) $(dummy_frame_h) $(gdbcore_h) $(annotate_h) \ - $(language_h) $(frame_unwind_h) $(command_h) $(gdbcmd_h) \ - $(sentinel_frame_h) + $(gdb_obstack_h) $(dummy_frame_h) $(sentinel_frame_h) $(gdbcore_h) \ + $(annotate_h) $(language_h) $(frame_unwind_h) $(frame_base_h) \ + $(command_h) $(gdbcmd_h) +frame-base.o: frame-base.c $(defs_h) $(frame_base_h) frame-unwind.o: frame-unwind.c $(defs_h) $(frame_h) $(frame_unwind_h) \ $(gdb_assert_h) $(dummy_frame_h) $(legacy_frame_h) frv-tdep.o: frv-tdep.c $(defs_h) $(inferior_h) $(symfile_h) $(gdbcore_h) \ diff --git a/gdb/d10v-tdep.c b/gdb/d10v-tdep.c index d9c95c78d31..31b49899e96 100644 --- a/gdb/d10v-tdep.c +++ b/gdb/d10v-tdep.c @@ -25,6 +25,7 @@ #include "defs.h" #include "frame.h" #include "frame-unwind.h" +#include "frame-base.h" #include "symtab.h" #include "gdbtypes.h" #include "gdbcmd.h" @@ -1558,8 +1559,7 @@ d10v_frame_prev_register (struct frame_info *next_frame, } } - -static struct frame_unwind d10v_frame_unwind = { +static const struct frame_unwind d10v_frame_unwind = { d10v_frame_this_id, d10v_frame_prev_register }; @@ -1570,6 +1570,21 @@ d10v_frame_p (CORE_ADDR pc) return &d10v_frame_unwind; } +static CORE_ADDR +d10v_frame_base_address (struct frame_info *next_frame, void **this_cache) +{ + struct d10v_unwind_cache *info + = d10v_frame_unwind_cache (next_frame, this_cache); + return info->base; +} + +static const struct frame_base d10v_frame_base = { + &d10v_frame_unwind, + d10v_frame_base_address, + d10v_frame_base_address, + d10v_frame_base_address +}; + /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that dummy frame. The frame ID's base needs to match the TOS value saved by save_dummy_frame_tos(), and the PC match the dummy frame's @@ -1719,6 +1734,7 @@ d10v_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_print_registers_info (gdbarch, d10v_print_registers_info); frame_unwind_append_predicate (gdbarch, d10v_frame_p); + frame_base_set_default (gdbarch, &d10v_frame_base); /* Methods for saving / extracting a dummy frame's ID. */ set_gdbarch_unwind_dummy_id (gdbarch, d10v_unwind_dummy_id); diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c index 7456979b91f..be965abd528 100644 --- a/gdb/dwarf2expr.c +++ b/gdb/dwarf2expr.c @@ -454,6 +454,9 @@ execute_stack_op (struct dwarf_expr_context *ctx, unsigned char *op_ptr, afterwards, effectively erasing whatever the recursive call put there. */ before_stack_len = ctx->stack_len; + /* FIXME: cagney/2003-03-26: This code should be using + get_frame_base_address(), and then implement a dwarf2 + specific this_base method. */ (ctx->get_frame_base) (ctx->baton, &datastart, &datalen); dwarf_expr_eval (ctx, datastart, datalen); result = dwarf_expr_fetch (ctx, 0); diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 9ea9941f249..7073549bf02 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -87,6 +87,9 @@ dwarf_expr_read_mem (void *baton, char *buf, CORE_ADDR addr, size_t len) static void dwarf_expr_frame_base (void *baton, unsigned char **start, size_t * length) { + /* FIXME: cagney/2003-03-26: This code should be using + get_frame_base_address(), and then implement a dwarf2 specific + this_base method. */ struct symbol *framefunc; struct dwarf2_locexpr_baton *symbaton; struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton; diff --git a/gdb/findvar.c b/gdb/findvar.c index 93c4d8a6e83..7100940897c 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -533,7 +533,7 @@ addresses have not been bound by the dynamic loader. Try again when executable i case LOC_LOCAL_ARG: if (frame == NULL) return 0; - addr = FRAME_LOCALS_ADDRESS (frame); + addr = get_frame_locals_address (frame); addr += SYMBOL_VALUE (var); break; diff --git a/gdb/frame.c b/gdb/frame.c index 8609ce194fb..969ead33ef6 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -36,6 +36,7 @@ #include "annotate.h" #include "language.h" #include "frame-unwind.h" +#include "frame-base.h" #include "command.h" #include "gdbcmd.h" @@ -1627,6 +1628,58 @@ get_frame_base (struct frame_info *fi) return fi->frame; } +/* High-level offsets into the frame. Used by the debug info. */ + +CORE_ADDR +get_frame_base_address (struct frame_info *fi) +{ + if (fi->type != NORMAL_FRAME) + return 0; + if (fi->base == NULL) + fi->base = frame_base_find_by_pc (current_gdbarch, get_frame_pc (fi)); + /* Sneaky: If the low-level unwind and high-level base code share a + common unwinder, let them share the prologue cache. */ + if (fi->base->unwind == fi->unwind) + return fi->base->this_base (fi->next, &fi->prologue_cache); + return fi->base->this_base (fi->next, &fi->base_cache); +} + +CORE_ADDR +get_frame_locals_address (struct frame_info *fi) +{ + void **cache; + if (fi->type != NORMAL_FRAME) + return 0; + /* If there isn't a frame address method, find it. */ + if (fi->base == NULL) + fi->base = frame_base_find_by_pc (current_gdbarch, get_frame_pc (fi)); + /* Sneaky: If the low-level unwind and high-level base code share a + common unwinder, let them share the prologue cache. */ + if (fi->base->unwind == fi->unwind) + cache = &fi->prologue_cache; + else + cache = &fi->base_cache; + return fi->base->this_locals (fi->next, cache); +} + +CORE_ADDR +get_frame_args_address (struct frame_info *fi) +{ + void **cache; + if (fi->type != NORMAL_FRAME) + return 0; + /* If there isn't a frame address method, find it. */ + if (fi->base == NULL) + fi->base = frame_base_find_by_pc (current_gdbarch, get_frame_pc (fi)); + /* Sneaky: If the low-level unwind and high-level base code share a + common unwinder, let them share the prologue cache. */ + if (fi->base->unwind == fi->unwind) + cache = &fi->prologue_cache; + else + cache = &fi->base_cache; + return fi->base->this_args (fi->next, cache); +} + /* Level of the selected frame: 0 for innermost, 1 for its caller, ... or -1 for a NULL frame. */ diff --git a/gdb/frame.h b/gdb/frame.h index 005960cc4f7..28426a2819d 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -25,6 +25,7 @@ struct symtab_and_line; struct frame_unwind; +struct frame_base; struct block; /* A legacy unwinder to prop up architectures using the old style @@ -169,47 +170,25 @@ extern CORE_ADDR get_frame_pc (struct frame_info *); extern void find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal); -/* Return the frame address from FI. Except in the machine-dependent - *FRAME* macros, a frame address has no defined meaning other than - as a magic cookie which identifies a frame over calls to the - inferior (um, SEE NOTE BELOW). The only known exception is - inferior.h (DEPRECATED_PC_IN_CALL_DUMMY) [ON_STACK]; see comments - there. You cannot assume that a frame address contains enough - information to reconstruct the frame; if you want more than just to - identify the frame (e.g. be able to fetch variables relative to - that frame), then save the whole struct frame_info (and the next - struct frame_info, since the latter is used for fetching variables - on some machines) (um, again SEE NOTE BELOW). - - NOTE: cagney/2002-11-18: Actually, the frame address isn't - sufficient for identifying a frame, and the counter examples are - wrong! - - Code that needs to (re)identify a frame must use get_frame_id() and - frame_find_by_id() (and in the future, a frame_compare() function - instead of INNER_THAN()). Two reasons: an architecture (e.g., - ia64) can have more than one frame address (due to multiple stack - pointers) (frame ID is going to be expanded to accomodate this); - successive frameless function calls can only be differientated by - comparing both the frame's base and the frame's enclosing function - (frame_find_by_id() is going to be modified to perform this test). - - The generic dummy frame version of DEPRECATED_PC_IN_CALL_DUMMY() is - able to identify a dummy frame using only the PC value. So the - frame address is not needed. In fact, most - DEPRECATED_PC_IN_CALL_DUMMY() calls now pass zero as the frame/sp - values as the caller knows that those values won't be used. Once - all architectures are using generic dummy frames, - DEPRECATED_PC_IN_CALL_DUMMY() can drop the sp/frame parameters. - When it comes to finding a dummy frame, the next frame's frame ID - (with out duing an unwind) can be used (ok, could if it wasn't for - the need to change the way the PPC defined frame base in a strange - way). - - Modern architectures should be using something like dwarf2's - location expression to describe where a variable lives. Such - expressions specify their own debug info centric frame address. - Consequently, a generic frame address is pretty meaningless. */ +/* Return the frame base (what ever that is) (DEPRECATED). + + Old code was trying to use this single method for two conflicting + purposes. Such code needs to be updated to use either of: + + get_frame_id: A low level frame unique identifier, that consists of + both a stack and a function address, that can be used to uniquely + identify a frame. This value is determined by the frame's + low-level unwinder, the stack part [typically] being the + top-of-stack of the previous frame, and the function part being the + function's start address. Since the correct identification of a + frameless function requires both the a stack and function address, + the old get_frame_base method was not sufficient. + + get_frame_base_address: get_frame_locals_address: + get_frame_args_address: A set of high-level debug-info dependant + addresses that fall within the frame. These addresses almost + certainly will not match the stack address part of a frame ID (as + returned by get_frame_base). */ extern CORE_ADDR get_frame_base (struct frame_info *); @@ -218,6 +197,25 @@ extern CORE_ADDR get_frame_base (struct frame_info *); FI is NULL, return the null_frame_id. */ extern struct frame_id get_frame_id (struct frame_info *fi); +/* Assuming that a frame is `normal', return its base-address, or 0 if + the information isn't available. NOTE: This address is really only + meaningful to the frame's high-level debug info. */ +extern CORE_ADDR get_frame_base_address (struct frame_info *); + +/* Assuming that a frame is `normal', return the address of the first + local variable, or 0 if the information isn't available. NOTE: + This address is really only meaningful to the frame's high-level + debug info. Typically, the argument and locals share a single + base-address. */ +extern CORE_ADDR get_frame_locals_address (struct frame_info *); + +/* Assuming that a frame is `normal', return the address of the first + parameter, or 0 if that information isn't available. NOTE: This + address is really only meaningful to the frame's high-level debug + info. Typically, the argument and locals share a single + base-address. */ +extern CORE_ADDR get_frame_args_address (struct frame_info *); + /* The frame's level: 0 for innermost, 1 for its caller, ...; or -1 for an invalid frame). */ extern int frame_relative_level (struct frame_info *fi); @@ -398,11 +396,12 @@ struct frame_info related unwind data. */ struct context *context; - /* Prologue cache shared between the unwind functions. See - "frame-unwind.h" for more information. */ + /* The frame's low-level unwinder and corresponding cache. The + low-level unwinder is responsible for unwinding register values + for the previous frame. The low-level unwind methods are + selected based on the presence, or otherwize, of register + unwind information such as CFI. */ void *prologue_cache; - - /* The frame's unwinder. */ const struct frame_unwind *unwind; /* Cached copy of the previous frame's resume address. */ @@ -413,6 +412,12 @@ struct frame_info redundant information. */ struct frame_id id; + /* The frame's high-level base methods, and corresponding cache. + The high level base methods are selected based on the frame's + debug info. */ + const struct frame_base *base; + void *base_cache; + /* Pointers to the next (down, inner, younger) and previous (up, outer, older) frame_info's in the frame cache. */ struct frame_info *next; /* down, inner, younger */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 5196ef049b6..b38968d7751 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1959,7 +1959,7 @@ print_frame_nameless_args (struct frame_info *fi, long start, int num, #ifdef NAMELESS_ARG_VALUE NAMELESS_ARG_VALUE (fi, start, &arg_value); #else - argsaddr = FRAME_ARGS_ADDRESS (fi); + argsaddr = get_frame_args_address (fi); if (!argsaddr) return; diff --git a/gdb/stack.c b/gdb/stack.c index 98b8a0f88ce..27fcaf6f6db 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -600,16 +600,6 @@ parse_frame_specification (char *frame_exp) /* NOTREACHED */ } -/* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except - that if it is unsure about the answer, it returns 0 - instead of guessing (this happens on the VAX and i960, for example). - - On most machines, we never have to guess about the args address, - so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */ -#if !defined (FRAME_ARGS_ADDRESS_CORRECT) -#define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS -#endif - /* Print verbosely the selected frame or the frame at address ADDR. This means absolutely all information in the frame is printed. */ @@ -743,7 +733,7 @@ frame_info (char *addr_exp, int from_tty) { /* Address of the argument list for this frame, or 0. */ - CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi); + CORE_ADDR arg_list = get_frame_args_address (fi); /* Number of args for this frame, or -1 if unknown. */ int numargs; @@ -770,7 +760,7 @@ frame_info (char *addr_exp, int from_tty) } { /* Address of the local variables for this frame, or 0. */ - CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi); + CORE_ADDR arg_list = get_frame_locals_address (fi); if (arg_list == 0) printf_filtered (" Locals at unknown address,"); diff --git a/gdb/symtab.h b/gdb/symtab.h index 79705fec06d..f2f2d247fc0 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -402,8 +402,8 @@ enum address_class /* Value is in register number SYMBOL_VALUE. Just like LOC_REGISTER except this is an argument. Probably the cleaner way to handle this would be to separate address_class (which would include - separate ARG and LOCAL to deal with FRAME_ARGS_ADDRESS versus - FRAME_LOCALS_ADDRESS), and an is_argument flag. + separate ARG and LOCAL to deal with get_frame_args_address() + versus get_frame_locals_address()), and an is_argument flag. For some symbol formats (stabs, for some compilers at least), the compiler generates two symbols, an argument and a register. @@ -447,9 +447,9 @@ enum address_class /* Value is arg at SYMBOL_VALUE offset in stack frame. Differs from LOC_LOCAL in that symbol is an argument; differs from LOC_ARG in - that we find it in the frame (FRAME_LOCALS_ADDRESS), not in the - arglist (FRAME_ARGS_ADDRESS). Added for i960, which passes args - in regs then copies to frame. */ + that we find it in the frame (get_frame_locals_address()), not in + the arglist (get_frame_args_address()). Added for i960, which + passes args in regs then copies to frame. */ LOC_LOCAL_ARG, -- cgit v1.2.1