http://sourceware.org/gdb/wiki/ProjectArcher http://sourceware.org/gdb/wiki/ArcherBranchManagement GIT snapshot: commit 42fbc89fd3a797da9880ecbc467c32f282acf31f branch `archer' - the merge of branches: archer-jankratochvil-vla archer-jankratochvil-watchpoint3 archer-tromey-python archer-sergiodj-stap-fedora15jk Index: gdb-7.2.90.20110525/bfd/elf-bfd.h =================================================================== --- gdb-7.2.90.20110525.orig/bfd/elf-bfd.h 2011-03-14 16:54:57.000000000 +0100 +++ gdb-7.2.90.20110525/bfd/elf-bfd.h 2011-05-25 17:05:21.000000000 +0200 @@ -1476,6 +1476,15 @@ enum Tag_compatibility = 32 }; +/* The following struct stores information about every SystemTap section + found in the object file. */ +struct sdt_note +{ + struct sdt_note *next; + bfd_size_type size; + bfd_byte data[1]; +}; + /* Some private data is stashed away for future use using the tdata pointer in the bfd structure. */ @@ -1633,6 +1642,11 @@ struct elf_obj_tdata bfd_size_type build_id_size; bfd_byte *build_id; + /* Linked-list containing information about every Systemtap section + found in the object file. Each section corresponds to one entry + in the list. */ + struct sdt_note *sdt_note_head; + /* True if the bfd contains symbols that have the STT_GNU_IFUNC symbol type. Used to set the osabi field in the ELF header structure. */ Index: gdb-7.2.90.20110525/bfd/elf.c =================================================================== --- gdb-7.2.90.20110525.orig/bfd/elf.c 2011-03-14 16:54:58.000000000 +0100 +++ gdb-7.2.90.20110525/bfd/elf.c 2011-05-25 17:05:21.000000000 +0200 @@ -8416,6 +8416,37 @@ elfobj_grok_gnu_note (bfd *abfd, Elf_Int } } +#define SDT_NOTE_TYPE 3 + +static bfd_boolean +elfobj_grok_stapsdt_note_1 (bfd *abfd, Elf_Internal_Note *note) +{ + struct sdt_note *cur = + (struct sdt_note *) bfd_alloc (abfd, sizeof (struct sdt_note) + + note->descsz); + + cur->next = (struct sdt_note *) (elf_tdata (abfd))->sdt_note_head; + cur->size = (bfd_size_type) note->descsz; + memcpy (cur->data, note->descdata, note->descsz); + + elf_tdata (abfd)->sdt_note_head = cur; + + return TRUE; +} + +static bfd_boolean +elfobj_grok_stapsdt_note (bfd *abfd, Elf_Internal_Note *note) +{ + switch (note->type) + { + case SDT_NOTE_TYPE: + return elfobj_grok_stapsdt_note_1 (abfd, note); + + default: + return TRUE; + } +} + static bfd_boolean elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp) { @@ -9189,6 +9220,12 @@ elf_parse_notes (bfd *abfd, char *buf, s if (! elfobj_grok_gnu_note (abfd, &in)) return FALSE; } + else if (in.namesz == sizeof "stapsdt" + && strcmp (in.namedata, "stapsdt") == 0) + { + if (! elfobj_grok_stapsdt_note (abfd, &in)) + return FALSE; + } break; } Index: gdb-7.2.90.20110525/gdb/Makefile.in =================================================================== --- gdb-7.2.90.20110525.orig/gdb/Makefile.in 2011-03-30 08:55:39.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/Makefile.in 2011-05-25 17:05:21.000000000 +0200 @@ -721,8 +721,8 @@ SFILES = ada-exp.y ada-lang.c ada-typepr sentinel-frame.c \ serial.c ser-base.c ser-unix.c \ solib.c solib-target.c source.c \ - stabsread.c stack.c std-regs.c symfile.c symfile-mem.c symmisc.c \ - symtab.c \ + stabsread.c stack.c stap-probe.c std-regs.c \ + symfile.c symfile-mem.c symmisc.c symtab.c \ target.c target-descriptions.c target-memory.c \ thread.c top.c tracepoint.c \ trad-frame.c \ @@ -814,7 +814,7 @@ osdata.h procfs.h python/py-event.h pyth python/python-internal.h python/python.h ravenscar-thread.h record.h \ solib-darwin.h solib-ia64-hpux.h solib-spu.h windows-nat.h xcoffread.h \ gnulib/extra/arg-nonnull.h gnulib/extra/c++defs.h gnulib/extra/warn-on-use.h \ -gnulib/stddef.in.h inline-frame.h +gnulib/stddef.in.h inline-frame.h stap-probe.h # Header files that already have srcdir in them, or which are in objdir. @@ -899,7 +899,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $ prologue-value.o memory-map.o memrange.o xml-support.o xml-syscall.o \ target-descriptions.o target-memory.o xml-tdesc.o xml-builtin.o \ inferior.o osdata.o gdb_usleep.o record.o gcore.o \ - jit.o progspace.o + jit.o progspace.o stap-probe.o TSOBS = inflow.o @@ -1320,6 +1320,12 @@ stamp-h: $(srcdir)/config.in config.stat CONFIG_LINKS= \ $(SHELL) config.status +.gdbinit: $(srcdir)/gdbinit.in config.status + CONFIG_FILES=".gdbinit:gdbinit.in" \ + CONFIG_COMMANDS= \ + CONFIG_HEADERS= \ + $(SHELL) config.status + config.status: $(srcdir)/configure configure.tgt configure.host $(SHELL) config.status --recheck Index: gdb-7.2.90.20110525/gdb/NEWS =================================================================== --- gdb-7.2.90.20110525.orig/gdb/NEWS 2011-03-31 16:32:48.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/NEWS 2011-05-25 17:05:21.000000000 +0200 @@ -36,6 +36,10 @@ Initial support for the OpenCL C language (http://www.khronos.org/opencl) has been integrated into GDB. +* GDB now has support for SystemTap probes. You can set a + breakpoint using the new "probe:" linespec and inspect the probe + arguments using the new $_probe_arg family of convenience variables. + * Python scripting ** The function gdb.Write now accepts an optional keyword 'stream'. Index: gdb-7.2.90.20110525/gdb/ada-lang.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/ada-lang.c 2011-05-17 23:26:08.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/ada-lang.c 2011-05-25 17:05:21.000000000 +0200 @@ -11421,6 +11421,7 @@ ada_operator_length (const struct expres static int ada_operator_check (struct expression *exp, int pos, + int (*type_func) (struct type *type, void *data), int (*objfile_func) (struct objfile *objfile, void *data), void *data) { @@ -11435,12 +11436,15 @@ ada_operator_check (struct expression *e break; default: - return operator_check_standard (exp, pos, objfile_func, data); + return operator_check_standard (exp, pos, type_func, objfile_func, + data); } /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */ - if (type && TYPE_OBJFILE (type) + if (type && type_func && (*type_func) (type, data)) + return 1; + if (type && TYPE_OBJFILE (type) && objfile_func && (*objfile_func) (TYPE_OBJFILE (type), data)) return 1; Index: gdb-7.2.90.20110525/gdb/amd64-linux-nat.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/amd64-linux-nat.c 2011-01-07 20:36:15.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/amd64-linux-nat.c 2011-05-25 17:05:21.000000000 +0200 @@ -265,18 +265,11 @@ amd64_linux_store_inferior_registers (st /* Support for debug registers. */ -static unsigned long amd64_linux_dr[DR_CONTROL + 1]; - static unsigned long -amd64_linux_dr_get (ptid_t ptid, int regnum) +amd64_linux_dr_get (int tid, int regnum) { - int tid; unsigned long value; - tid = TIDGET (ptid); - if (tid == 0) - tid = PIDGET (ptid); - /* FIXME: kettenis/2001-03-27: Calling perror_with_name if the ptrace call fails breaks debugging remote targets. The correct way to fix this is to add the hardware breakpoint and watchpoint @@ -298,14 +291,8 @@ amd64_linux_dr_get (ptid_t ptid, int reg /* Set debug register REGNUM to VALUE in only the one LWP of PTID. */ static void -amd64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) +amd64_linux_dr_set (int tid, int regnum, unsigned long value) { - int tid; - - tid = TIDGET (ptid); - if (tid == 0) - tid = PIDGET (ptid); - errno = 0; ptrace (PTRACE_POKEUSER, tid, offsetof (struct user, u_debugreg[regnum]), value); @@ -313,35 +300,96 @@ amd64_linux_dr_set (ptid_t ptid, int reg perror_with_name (_("Couldn't write debug register")); } -/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST. */ +/* Helper for amd64_linux_dr_set_control. */ + +static void +amd64_linux_dr_set_control_callback (int tid, void *control_voidp) +{ + unsigned long control = *(unsigned long *) control_voidp; + + amd64_linux_dr_set (tid, DR_CONTROL, control); +} + +static void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr); + +/* Set DR_CONTROL to ADDR in all LWPs of CURRENT_INFERIOR. */ static void amd64_linux_dr_set_control (unsigned long control) { - struct lwp_info *lp; - ptid_t ptid; + int inferior_pid = ptid_get_pid (inferior_ptid); + struct inferior *inf = current_inferior (); + + /* Are we detaching breakpoints from a fork-ed child? + See linux_nat_iterate_watchpoint_lwps for the fork-ed child description. + The i386 counterpart is i386_linux_dr_set_control. */ + if (inf->pid != inferior_pid) + { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); + int i; + + /* There were two changes in Linux kernel 2.6.33 by the commit: + 72f674d203cd230426437cdcf7dd6f681dad8b0d + + (1) After fork/vfork/clone the new task no longer inherits the debug + registers. It has them zeroed instead. Either case is OK for GDB as + GDB already registers a fix up by linux_nat_set_new_thread. + + (2) If you enable a breakpoint by the CONTROL bits you have already + written its ADDRESS. Otherwise Linux kernel will report EINVAL. + For this case the workaround here ensures that during resetting + (detaching) watchpoints for a fork-ed child we can set CONTROL + arbitrarily as the addresses get pre-set here just to be sure. + + The second issue is hopefully going to be fixed in Linux kernel: + https://bugzilla.redhat.com/show_bug.cgi?id=660204 */ + + if (!dr_mirror->addr_preset) + { + dr_mirror->addr_preset = 1; + + for (i = 0; i < DR_LASTADDR - DR_FIRSTADDR; i++) + amd64_linux_dr_set_addr (i, dr_mirror->addr[i]); + } + } + + linux_nat_iterate_watchpoint_lwps (amd64_linux_dr_set_control_callback, + &control); +} + +/* Helper for amd64_linux_dr_set_addr. */ + +struct amd64_linux_dr_set_addr_data + { + int regnum; + CORE_ADDR addr; + }; + +static void +amd64_linux_dr_set_addr_callback (int tid, void *datap_voidp) +{ + const struct amd64_linux_dr_set_addr_data *datap = datap_voidp; - amd64_linux_dr[DR_CONTROL] = control; - ALL_LWPS (lp, ptid) - amd64_linux_dr_set (ptid, DR_CONTROL, control); + amd64_linux_dr_set (tid, DR_FIRSTADDR + datap->regnum, datap->addr); } -/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST. */ +/* Set address REGNUM (zero based) to ADDR in all LWPs of CURRENT_INFERIOR. + */ static void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr) { - struct lwp_info *lp; - ptid_t ptid; + struct amd64_linux_dr_set_addr_data data; gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR); - amd64_linux_dr[DR_FIRSTADDR + regnum] = addr; - ALL_LWPS (lp, ptid) - amd64_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr); + data.regnum = regnum; + data.addr = addr; + linux_nat_iterate_watchpoint_lwps (amd64_linux_dr_set_addr_callback, &data); } -/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST. */ +/* Set address REGNUM (zero based) to zero in all LWPs of CURRENT_INFERIOR. + */ static void amd64_linux_dr_reset_addr (int regnum) @@ -354,37 +402,54 @@ amd64_linux_dr_reset_addr (int regnum) static unsigned long amd64_linux_dr_get_status (void) { - return amd64_linux_dr_get (inferior_ptid, DR_STATUS); + int tid; + + tid = TIDGET (inferior_ptid); + if (tid == 0) + tid = PIDGET (inferior_ptid); + + return amd64_linux_dr_get (tid, DR_STATUS); } -/* Unset MASK bits in DR_STATUS in all LWPs of LWP_LIST. */ +/* Helper for amd64_linux_dr_unset_status. */ static void -amd64_linux_dr_unset_status (unsigned long mask) +amd64_linux_dr_unset_status_callback (int tid, void *mask_voidp) { - struct lwp_info *lp; - ptid_t ptid; - - ALL_LWPS (lp, ptid) - { - unsigned long value; + unsigned long mask = *(unsigned long *) mask_voidp; + unsigned long value; - value = amd64_linux_dr_get (ptid, DR_STATUS); - value &= ~mask; - amd64_linux_dr_set (ptid, DR_STATUS, value); - } + value = amd64_linux_dr_get (tid, DR_STATUS); + value &= ~mask; + amd64_linux_dr_set (tid, DR_STATUS, value); } +/* Unset MASK bits in DR_STATUS in all LWPs of CURRENT_INFERIOR. */ + +static void +amd64_linux_dr_unset_status (unsigned long mask) +{ + linux_nat_iterate_watchpoint_lwps (amd64_linux_dr_unset_status_callback, + &mask); +} static void amd64_linux_new_thread (ptid_t ptid) { - int i; + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); + int i, tid; + + /* Verify DR_MIRROR is valid. */ + gdb_assert (PIDGET (ptid) == PIDGET (inferior_ptid)); + + tid = TIDGET (ptid); + if (tid == 0) + tid = PIDGET (ptid); - for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++) - amd64_linux_dr_set (ptid, i, amd64_linux_dr[i]); + for (i = 0; i < DR_LASTADDR - DR_FIRSTADDR; i++) + amd64_linux_dr_set (tid, DR_FIRSTADDR + i, dr_mirror->addr[i]); - amd64_linux_dr_set (ptid, DR_CONTROL, amd64_linux_dr[DR_CONTROL]); + amd64_linux_dr_set (tid, DR_CONTROL, dr_mirror->control); } Index: gdb-7.2.90.20110525/gdb/ax-gdb.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/ax-gdb.c 2011-02-24 08:39:47.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/ax-gdb.c 2011-05-25 17:05:21.000000000 +0200 @@ -2001,7 +2001,8 @@ gen_expr (struct expression *exp, union case OP_INTERNALVAR: { - const char *name = internalvar_name ((*pc)[1].internalvar); + struct internalvar *var = (*pc)[1].internalvar; + const char *name = internalvar_name (var); struct trace_state_variable *tsv; (*pc) += 3; @@ -2015,7 +2016,7 @@ gen_expr (struct expression *exp, union value->kind = axs_rvalue; value->type = builtin_type (exp->gdbarch)->builtin_long_long; } - else + else if (! compile_internalvar_to_ax (var, ax, value)) error (_("$%s is not a trace state variable; GDB agent " "expressions cannot use convenience variables."), name); } Index: gdb-7.2.90.20110525/gdb/block.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/block.c 2011-01-01 16:32:57.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/block.c 2011-05-25 17:05:21.000000000 +0200 @@ -322,3 +322,21 @@ allocate_block (struct obstack *obstack) return bl; } + +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for + whatever reason. */ + +struct objfile * +block_objfile (const struct block *block) +{ + struct symbol *func; + + if (block == NULL) + return NULL; + + func = block_linkage_function (block); + if (func == NULL) + return NULL; + + return SYMBOL_SYMTAB (func)->objfile; +} Index: gdb-7.2.90.20110525/gdb/block.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/block.h 2011-01-01 16:32:57.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/block.h 2011-05-25 17:05:21.000000000 +0200 @@ -167,4 +167,6 @@ extern const struct block *block_global_ extern struct block *allocate_block (struct obstack *obstack); +extern struct objfile *block_objfile (const struct block *block); + #endif /* BLOCK_H */ Index: gdb-7.2.90.20110525/gdb/breakpoint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/breakpoint.c 2011-05-17 23:25:56.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/breakpoint.c 2011-05-25 17:05:21.000000000 +0200 @@ -63,6 +63,8 @@ #include "jit.h" #include "xml-syscall.h" #include "parser-defs.h" +#include "gdb_regex.h" +#include "stap-probe.h" #include "cli/cli-utils.h" /* readline include files */ @@ -107,6 +109,9 @@ static void break_command_1 (char *, int static void mention (struct breakpoint *); +static struct bp_location *add_location_to_breakpoint (struct breakpoint *b, + const struct symtab_and_line *sal); + /* This function is used in gdbtk sources and thus can not be made static. */ struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, @@ -1249,6 +1254,9 @@ update_watchpoint (struct breakpoint *b, if (!watchpoint_in_thread_scope (b)) return; + if (b->pspace != current_program_space) + return; + if (b->disposition == disp_del_at_next_stop) return; @@ -1520,6 +1528,40 @@ should_be_inserted (struct bp_location * return 1; } +/* See the comment in breakpoint.h. */ + +void +modify_semaphore (struct bp_location *loc, int set) +{ + struct gdbarch *arch = loc->gdbarch; + gdb_byte bytes[sizeof (LONGEST)]; + /* The ABI specifies "unsigned short". */ + struct type *type = builtin_type (arch)->builtin_unsigned_short; + CORE_ADDR address = loc->semaphore; + ULONGEST value; + + if (address == 0) + return; + + /* Swallow errors. */ + if (target_read_memory (address, bytes, TYPE_LENGTH (type)) != 0) + return; + + value = extract_unsigned_integer (bytes, TYPE_LENGTH (type), + gdbarch_byte_order (arch)); + /* Note that we explicitly don't worry about overflow or + underflow. */ + if (set) + ++value; + else + --value; + + store_unsigned_integer (bytes, TYPE_LENGTH (type), + gdbarch_byte_order (arch), value); + + target_write_memory (address, bytes, TYPE_LENGTH (type)); +} + /* Insert a low-level "breakpoint" of some type. BL is the breakpoint location. Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. @@ -1616,6 +1658,8 @@ insert_bp_location (struct bp_location * else val = target_insert_breakpoint (bl->gdbarch, &bl->target_info); + + modify_semaphore (bl, 1); } else { @@ -1870,6 +1914,7 @@ insert_breakpoint_locations (void) int val = 0; int disabled_breaks = 0; int hw_breakpoint_error = 0; + struct program_space *saved_current_program_space = current_program_space; struct ui_file *tmp_error_stream = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); @@ -1897,9 +1942,13 @@ insert_breakpoint_locations (void) /* For targets that support global breakpoints, there's no need to select an inferior to insert breakpoint to. In fact, even if we aren't attached to any process yet, we should still - insert breakpoints. */ + insert breakpoints. + + Also inserting breakpoints into inappropriate inferior must be + prevented. */ if (!gdbarch_has_global_breakpoints (target_gdbarch) - && ptid_equal (inferior_ptid, null_ptid)) + && (ptid_equal (inferior_ptid, null_ptid) + || bl->pspace != saved_current_program_space)) continue; val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, @@ -1923,13 +1972,19 @@ insert_breakpoint_locations (void) if (bpt->disposition == disp_del_at_next_stop) continue; - + for (loc = bpt->loc; loc; loc = loc->next) - if (!loc->inserted && should_be_inserted (loc)) - { - some_failed = 1; - break; - } + { + /* Verify the first loop above really tried to insert this LOC. */ + if (!loc->inserted && should_be_inserted (loc) + && (gdbarch_has_global_breakpoints (target_gdbarch) + || (!ptid_equal (inferior_ptid, null_ptid) + && loc->pspace == saved_current_program_space))) + { + some_failed = 1; + break; + } + } if (some_failed) { for (loc = bpt->loc; loc; loc = loc->next) @@ -2111,15 +2166,24 @@ struct breakpoint_objfile_data /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; + /* SystemTap probe point for longjmp (if any). */ + const struct stap_probe *longjmp_probe; + /* Minimal symbol for "std::terminate()" (if any). */ struct minimal_symbol *terminate_msym; /* Minimal symbol for "_Unwind_DebugHook" (if any). */ struct minimal_symbol *exception_msym; + + /* SystemTap probe point for unwinding (if any). */ + const struct stap_probe *exception_probe; }; static const struct objfile_data *breakpoint_objfile_key; +/* SystemTap probe not found sentinel. */ +static const struct stap_probe probe_not_found; + /* Minimal symbol not found sentinel. */ static struct minimal_symbol msym_not_found; @@ -2227,6 +2291,29 @@ create_longjmp_master_breakpoint (void) bp_objfile_data = get_breakpoint_objfile_data (objfile); + if (bp_objfile_data->longjmp_probe != &probe_not_found) + { + if (bp_objfile_data->longjmp_probe == NULL) + bp_objfile_data->longjmp_probe + = find_probe_in_objfile (objfile, "libc", "longjmp"); + + if (bp_objfile_data->longjmp_probe) + { + struct breakpoint *b; + struct gdbarch *gdbarch = get_objfile_arch (objfile); + + b = create_internal_breakpoint (gdbarch, + bp_objfile_data->longjmp_probe->address, + bp_longjmp_master); + b->addr_string = xstrdup ("probe:libc:longjmp"); + b->enable_state = bp_disabled; + + continue; + } + else + bp_objfile_data->longjmp_probe = &probe_not_found; + } + for (i = 0; i < NUM_LONGJMP_NAMES; i++) { struct breakpoint *b; @@ -2335,6 +2422,31 @@ create_exception_master_breakpoint (void bp_objfile_data = get_breakpoint_objfile_data (objfile); + /* We prefer the SystemTap probe point if it exists. */ + if (bp_objfile_data->exception_probe != &probe_not_found) + { + if (bp_objfile_data->exception_probe == NULL) + bp_objfile_data->exception_probe + = find_probe_in_objfile (objfile, "libgcc", "unwind"); + + if (bp_objfile_data->exception_probe) + { + struct breakpoint *b; + struct gdbarch *gdbarch = get_objfile_arch (objfile); + + b = create_internal_breakpoint (gdbarch, + bp_objfile_data->exception_probe->address, + bp_exception_master); + b->addr_string = xstrdup ("probe:libgcc:unwind"); + b->enable_state = bp_disabled; + continue; + } + else + bp_objfile_data->exception_probe = &probe_not_found; + } + + /* Otherwise, try the hook function. */ + if (msym_not_found_p (bp_objfile_data->exception_msym)) continue; @@ -2553,6 +2665,8 @@ remove_breakpoint_1 (struct bp_location val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); else val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); + + modify_semaphore (bl, 0); } else { @@ -5902,6 +6016,7 @@ set_raw_breakpoint (struct gdbarch *gdba b->loc->requested_address = sal.pc; b->loc->address = adjusted_address; b->loc->pspace = sal.pspace; + b->loc->semaphore = sal.semaphore; /* Store the program space that was used to set the breakpoint, for breakpoint resetting. */ @@ -7057,6 +7172,7 @@ clone_momentary_breakpoint (struct break copy->loc->address = orig->loc->address; copy->loc->section = orig->loc->section; copy->loc->pspace = orig->loc->pspace; + copy->loc->semaphore = orig->loc->semaphore; if (orig->source_file == NULL) copy->source_file = NULL; @@ -7280,6 +7396,7 @@ add_location_to_breakpoint (struct break loc->address = adjust_breakpoint_address (loc->gdbarch, loc->requested_address, b->type); loc->pspace = sal->pspace; + loc->semaphore = sal->semaphore; gdb_assert (loc->pspace != NULL); loc->section = sal->section; @@ -7629,6 +7746,16 @@ create_breakpoints_sal (struct gdbarch * { int i; + if (canonical->pre_expanded) + { + create_breakpoint_sal (gdbarch, sals, canonical->canonical[0], + cond_string, type, disposition, + thread, task, ignore_count, ops, + from_tty, enabled, internal, + canonical->special_display); + return; + } + for (i = 0; i < sals.nelts; ++i) { struct symtabs_and_lines expanded = @@ -8154,7 +8281,7 @@ create_breakpoint (struct gdbarch *gdbar mention (b); } - if (sals.nelts > 1) + if (sals.nelts > 1 && !canonical.pre_expanded) { warning (_("Multiple breakpoints were set.\nUse the " "\"delete\" command to delete unwanted breakpoints.")); @@ -9026,6 +9153,7 @@ watch_command_1 (char *arg, int accessfl b = set_raw_breakpoint_without_location (NULL, bp_type); set_breakpoint_number (internal, b); b->thread = thread; + b->pspace = current_program_space; b->disposition = disp_donttouch; b->exp = exp; b->exp_valid_block = exp_valid_block; @@ -10188,6 +10316,9 @@ update_global_location_list (int should_ int keep_in_target = 0; int removed = 0; + if (old_loc->pspace != current_program_space) + continue; + /* Skip LOCP entries which will definitely never be needed. Stop either at or being the one matching OLD_LOC. */ while (locp < bp_location + bp_location_count @@ -10952,12 +11083,14 @@ update_breakpoint_locations (struct brea On return, FOUND will be 1 if any SaL was found, zero otherwise. */ static struct symtabs_and_lines -addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) +addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found, + int *pre_expanded) { char *s; int marker_spec, not_found; struct symtabs_and_lines sals = {0}; struct gdb_exception e; + int my_pre_expanded = 0; s = addr_string; marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); @@ -10976,8 +11109,27 @@ addr_string_to_sals (struct breakpoint * error (_("marker %s not found"), b->static_trace_marker_id); } else - sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, - NULL, ¬_found); + { + struct linespec_result canonical; + + init_linespec_result (&canonical); + sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, + &canonical, ¬_found); + + /* We don't need the contents. */ + if (canonical.canonical) + { + int i; + + for (i = 0; i < sals.nelts; ++i) + xfree (canonical.canonical[i]); + xfree (canonical.canonical); + } + + my_pre_expanded = canonical.pre_expanded; + if (pre_expanded) + *pre_expanded = my_pre_expanded; + } } if (e.reason < 0) { @@ -11010,7 +11162,7 @@ addr_string_to_sals (struct breakpoint * if (!not_found) { - gdb_assert (sals.nelts == 1); + gdb_assert (my_pre_expanded || sals.nelts == 1); resolve_sal_pc (&sals.sals[0]); if (b->condition_not_parsed && s && s[0]) @@ -11049,22 +11201,27 @@ re_set_breakpoint (struct breakpoint *b) struct symtabs_and_lines expanded = {0}; struct symtabs_and_lines expanded_end = {0}; struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); + int pre_expanded = 0; input_radix = b->input_radix; save_current_space_and_thread (); switch_to_program_space_and_thread (b->pspace); set_language (b->language); - sals = addr_string_to_sals (b, b->addr_string, &found); + sals = addr_string_to_sals (b, b->addr_string, &found, &pre_expanded); if (found) { make_cleanup (xfree, sals.sals); - expanded = expand_line_sal_maybe (sals.sals[0]); + if (pre_expanded) + expanded = sals; + else + expanded = expand_line_sal_maybe (sals.sals[0]); } if (b->addr_string_range_end) { - sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); + sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found, + NULL); if (found) { make_cleanup (xfree, sals_end.sals); @@ -12501,6 +12658,24 @@ all_tracepoints (void) return tp_vec; } +#if 0 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */ + +static void +breakpoint_types_mark_used (void) +{ + struct breakpoint *b; + + ALL_BREAKPOINTS (b) + { + if (b->exp) + exp_types_mark_used (b->exp); + if (b->val) + type_mark_used (value_type (b->val)); + } +} +#endif + /* This help string is used for the break, hbreak, tbreak and thbreak commands. It is defined as a macro to prevent duplication. @@ -13136,4 +13311,7 @@ range (including START-LOCATION and END- automatic_hardware_breakpoints = 1; observer_attach_about_to_proceed (breakpoint_about_to_proceed); +#if 0 + observer_attach_mark_used (breakpoint_types_mark_used); +#endif } Index: gdb-7.2.90.20110525/gdb/breakpoint.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/breakpoint.h 2011-05-17 23:25:56.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/breakpoint.h 2011-05-25 17:05:21.000000000 +0200 @@ -363,6 +363,11 @@ struct bp_location processor's architectual constraints. */ CORE_ADDR requested_address; + /* If the location comes from a SystemTap probe point, and the probe + has an associated semaphore variable, then this is the address of + the semaphore. Otherwise, this is zero. */ + CORE_ADDR semaphore; + char *function_name; /* Details of the placed breakpoint, when inserted. */ @@ -1237,4 +1242,11 @@ extern struct breakpoint *iterate_over_b extern int user_breakpoint_p (struct breakpoint *); +/* Set or clear a SystemTap semaphore. LOC is the location which may + hold a semaphore. SET is non-zero if the semaphore should be set, + or zero if the semaphore should be cleared. Semaphores act as + reference counters, so calls to this function must be paired. */ + +extern void modify_semaphore (struct bp_location *location, int set); + #endif /* !defined (BREAKPOINT_H) */ Index: gdb-7.2.90.20110525/gdb/c-typeprint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/c-typeprint.c 2011-03-22 18:35:22.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/c-typeprint.c 2011-05-25 17:05:21.000000000 +0200 @@ -625,9 +625,14 @@ c_type_print_varspec_suffix (struct type fprintf_filtered (stream, ")"); fprintf_filtered (stream, "["); - if (get_array_bounds (type, &low_bound, &high_bound)) - fprintf_filtered (stream, "%d", - (int) (high_bound - low_bound + 1)); + if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind + != RANGE_BOUND_KIND_CONSTANT) + { + /* No _() - printed sources should not be locale dependent. */ + fprintf_filtered (stream, "variable"); + } + else if (get_array_bounds (type, &low_bound, &high_bound)) + fprintf_filtered (stream, "%d", (int) (high_bound - low_bound + 1)); fprintf_filtered (stream, "]"); c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, Index: gdb-7.2.90.20110525/gdb/cli/cli-utils.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/cli/cli-utils.c 2011-03-16 22:12:12.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/cli/cli-utils.c 2011-05-25 17:05:21.000000000 +0200 @@ -245,3 +245,32 @@ remove_trailing_whitespace (const char * return s; } + +/* See documentation in cli-utils.h. */ + +char * +extract_arg (char **arg) +{ + char *result, *copy; + + if (!*arg) + return NULL; + + /* Find the start of the argument. */ + *arg = skip_spaces (*arg); + if (! **arg) + return NULL; + result = *arg; + + /* Find the end of the argument. */ + *arg = skip_to_space (*arg + 1); + + if (result == *arg) + return NULL; + + copy = xmalloc (*arg - result + 1); + memcpy (copy, result, *arg - result); + copy[*arg - result] = '\0'; + + return copy; +} Index: gdb-7.2.90.20110525/gdb/cli/cli-utils.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/cli/cli-utils.h 2011-03-16 22:12:12.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/cli/cli-utils.h 2011-05-25 17:05:21.000000000 +0200 @@ -103,4 +103,11 @@ extern char *skip_to_space (char *inp); START. */ extern char *remove_trailing_whitespace (const char *start, char *s); + +/* A helper function to extract an argument from *ARG. An argument is + delimited by whitespace. The return value is either NULL if no + argument was found, or an xmalloc'd string. */ + +extern char *extract_arg (char **arg); + #endif /* CLI_UTILS_H */ Index: gdb-7.2.90.20110525/gdb/coffread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/coffread.c 2011-03-17 14:19:23.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/coffread.c 2011-05-25 17:05:21.000000000 +0200 @@ -2193,6 +2193,7 @@ static const struct sym_fns coff_sym_fns default_symfile_relocate, /* sym_relocate: Relocate a debug section. */ + NULL, /* sym_probe_fns */ &psym_functions }; Index: gdb-7.2.90.20110525/gdb/data-directory/Makefile.in =================================================================== --- gdb-7.2.90.20110525.orig/gdb/data-directory/Makefile.in 2011-02-04 19:34:41.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/data-directory/Makefile.in 2011-05-25 17:05:21.000000000 +0200 @@ -52,11 +52,23 @@ SYSCALLS_FILES = \ PYTHON_DIR = python PYTHON_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(PYTHON_DIR) PYTHON_FILES = \ + gdb/FrameIterator.py \ + gdb/FrameWrapper.py \ gdb/__init__.py \ - gdb/types.py \ - gdb/printing.py \ + gdb/backtrace.py \ gdb/command/__init__.py \ - gdb/command/pretty_printers.py + gdb/command/alias.py \ + gdb/command/backtrace.py \ + gdb/command/ignore_errors.py \ + gdb/command/pahole.py \ + gdb/command/pretty_printers.py \ + gdb/command/require.py \ + gdb/command/upto.py \ + gdb/function/__init__.py \ + gdb/function/caller_is.py \ + gdb/function/in_scope.py \ + gdb/printing.py \ + gdb/types.py FLAGS_TO_PASS = \ "prefix=$(prefix)" \ Index: gdb-7.2.90.20110525/gdb/dbxread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/dbxread.c 2011-03-23 19:23:54.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/dbxread.c 2011-05-25 17:05:21.000000000 +0200 @@ -1,6 +1,6 @@ /* Read dbx symbol tables and convert to internal format, for GDB. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, - 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2008, 2009, 2010. + 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2008, 2009, 2010, 2011. Free Software Foundation, Inc. This file is part of GDB. @@ -3587,6 +3587,7 @@ static const struct sym_fns aout_sym_fns default_symfile_segments, /* Get segment information from a file. */ NULL, default_symfile_relocate, /* Relocate a debug section. */ + NULL, /* sym_probe_fns */ &psym_functions }; Index: gdb-7.2.90.20110525/gdb/defs.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/defs.h 2011-03-31 16:32:48.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/defs.h 2011-05-25 17:05:21.000000000 +0200 @@ -398,6 +398,8 @@ extern struct cleanup *make_cleanup_rest extern struct cleanup * set_batch_flag_and_make_cleanup_restore_page_info (void); +extern struct cleanup *make_cleanup_restore_selected_frame (void); + extern char *gdb_realpath (const char *); extern char *xfullpath (const char *); Index: gdb-7.2.90.20110525/gdb/doc/gdb.texinfo =================================================================== --- gdb-7.2.90.20110525.orig/gdb/doc/gdb.texinfo 2011-05-17 23:27:48.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/doc/gdb.texinfo 2011-05-25 17:05:21.000000000 +0200 @@ -1177,6 +1177,16 @@ for remote debugging. Run using @var{device} for your program's standard input and output. @c FIXME: kingdon thinks there is more to -tty. Investigate. +@item -P +@cindex @code{-P} +@itemx --python +@cindex @code{--python} +Change interpretation of command line so that the argument immediately +following this switch is taken to be the name of a Python script file. +This option stops option processing; subsequent options are passed to +Python as @code{sys.argv}. This option is only available if Python +scripting support was enabled when @value{GDBN} was configured. + @c resolve the situation of these eventually @item -tui @cindex @code{--tui} @@ -3286,6 +3296,7 @@ all breakpoints in that range are operat * Conditions:: Break conditions * Break Commands:: Breakpoint command lists * Save Breakpoints:: How to save breakpoints in a file +* Static Probe Points:: Listing static probe points * Error in Breakpoints:: ``Cannot insert breakpoints'' * Breakpoint-related Warnings:: ``Breakpoint address adjusted...'' @end menu @@ -4499,6 +4510,50 @@ and remove the breakpoint definitions yo that can no longer be recreated. @end table +@node Static Probe Points +@subsection Static Probe Points + +@cindex SystemTap static probe point +@cindex sdt-probe +The @sc{gnu}/Linux tool @code{SystemTap} provides a way for +applications to embed static probes, using @file{sys/sdt.h}. @value{GDBN} +can list the available probes, and you can put breakpoints at the +probe points (@pxref{Specify Location}). + +You can examine the available @code{SystemTap} static probes using +@code{info probes}: + +@table @code +@kindex info probes +@item info probes [@var{provider} [@var{name} [@var{objfile}]]] +List the available @code{SystemTap} static probes. + +If given, @var{provider} is a regular expression used to select which +providers to list. If omitted, all providers are listed. + +If given, @var{name} is a regular expression used to select which +probes to list. If omitted, all probes are listed. + +If given, @var{objfile} is a regular expression used to select which +object files (executable or shared libraries) to examine. If not +given, all object files are considered. +@end table + +@vindex $_probe_arg@r{, convenience variable} +A probe may specify up to ten arguments. These are available at the +point at which the probe is defined---that is, when the current PC is +at the probe's location. The arguments are available using the +convenience variables (@pxref{Convenience Vars}) +@code{$_probe_arg0}@dots{}@code{$_probe_arg9}. Each probe argument is +an integer of the appropriate size; types are not preserved. The +convenience variable @code{$_probe_argc} holds the number of arguments +at the current probe point. + +These variables are always available, but attempts to access them at +any location other than a probe point will cause @value{GDBN} to give +an error. + + @c @ifclear BARETARGET @node Error in Breakpoints @subsection ``Cannot insert breakpoints'' @@ -6414,6 +6469,29 @@ specify the function unambiguously, e.g. functions with identical names in different source files. @end table +@cindex SystemTap static probe point +@item probe:@r{[}@var{objfile}:@r{]}@r{[}@var{provider}:@r{]}@var{name} +The @sc{gnu}/Linux tool @code{SystemTap} provides a way for +applications to embed static probes. This form of linespec specifies +the location of such a static probe. See +@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps} +for more information on static probes. + +If @var{objfile} is given, only probes coming from that shared library +or executable are considered. If @var{provider} is given, then only +probes from that provider are considered. + +@xref{Static Probe Points}, for more information on finding and using +static probes. + +Some probes have an associated semaphore variable; for instance, this +happens automatically if you defined your probe using a DTrace-style +@file{.d} file. If your probe has a semaphore, @value{GDBN} will +automatically enable it when you specify a breakpoint using the +@samp{probe:} notation. But, if you put a breakpoint at a probe's +location by some other method (e.g., @code{break file:line}), then +@value{GDBN} will not automatically set the semaphore. + @end table @@ -8500,6 +8578,10 @@ to match the format in which the data wa The variable @code{$_exitcode} is automatically set to the exit code when the program being debugged terminates. +@item $_probe_argc +@itemx $_probe_arg0@dots{}$_probe_arg9 +Arguments to a SystemTap static probe. @xref{Static Probe Points}. + @item $_sdata @vindex $_sdata@r{, inspect, convenience variable} The variable @code{$_sdata} contains extra collected static tracepoint @@ -10219,6 +10301,16 @@ Collect all function arguments. @item $locals Collect all local variables. +@item $_probe_argc +Collects the number of arguments from the @code{SystemTap} probe at +which the tracepoint is located. +@xref{Static Probe Points,,Static Probe Points} + +@item $_probe_arg@var{N} +Where @var{N} varies from 0 to 9. Collects the @var{N}th argument +from the @code{SystemTap} probe at which the tracepoint is located. +@xref{Static Probe Points,,Static Probe Points} + @item $_sdata @vindex $_sdata@r{, collect} Collect static tracepoint marker specific data. Only available for @@ -20710,8 +20802,6 @@ containing @code{end}. For example: @smallexample (@value{GDBP}) python -Type python script -End with a line saying just "end". >print 23 >end 23 @@ -20724,6 +20814,14 @@ in a Python script. This can be control python print-stack}: if @code{on}, the default, then Python stack printing is enabled; if @code{off}, then Python stack printing is disabled. + +@kindex maint set python auto-load +@item maint set python auto-load +By default, @value{GDBN} will attempt to automatically load Python +code when an object file is opened. This can be controlled using +@code{maint set python auto-load}: if @code{on}, the default, then +Python auto-loading is enabled; if @code{off}, then Python +auto-loading is disabled. @end table It is also possible to execute a Python script from the @value{GDBN} @@ -20745,6 +20843,14 @@ and thus is always available. @cindex python api @cindex programming in python +You can get quick online help for @value{GDBN}'s Python API by issuing +the command @w{@kbd{python help (gdb)}}. + +Functions and methods which have two or more optional arguments allow +them to be specified using keyword syntax. This allows passing some +optional arguments while skipping others. Example: +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}. + @cindex python stdout @cindex python pagination At startup, @value{GDBN} overrides Python's @code{sys.stdout} and Index: gdb-7.2.90.20110525/gdb/doc/gdbint.texinfo =================================================================== --- gdb-7.2.90.20110525.orig/gdb/doc/gdbint.texinfo 2011-02-04 20:10:12.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/doc/gdbint.texinfo 2011-05-25 17:05:21.000000000 +0200 @@ -2104,6 +2104,18 @@ time, and so we attempt to handle symbol we create @dfn{partial symbol tables} consisting of only selected symbols, and only expand them to full symbol tables when necessary. +@menu +* Symbol Reading:: +* Partial Symbol Tables:: +* Types:: +* Object File Formats:: +* Debugging File Formats:: +* Adding a New Symbol Reader to GDB:: +* Memory Management for Symbol Files:: +* Memory Management for Types:: +@end menu + +@node Symbol Reading @section Symbol Reading @cindex symbol reading @@ -2196,6 +2208,7 @@ symtab. Upon return, @code{pst->readin} zero if there were no symbols in that part of the symbol file. @end table +@node Partial Symbol Tables @section Partial Symbol Tables @value{GDBN} has three types of symbol tables: @@ -2297,6 +2310,7 @@ and partial symbol tables behind a set o the @dfn{quick symbol functions}. These are documented in @file{symfile.h}. +@node Types @section Types @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}). @@ -2319,6 +2333,7 @@ types map to one @code{TYPE_CODE_*} type other members of the type struct, such as whether the type is signed or unsigned, and how many bits it uses. +@anchor{Builtin Types} @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}). These are instances of type structs that roughly correspond to @@ -2333,6 +2348,7 @@ only one instance exists, while @file{c- @code{TYPE_CODE_INT} types as needed, with each one associated with some particular objfile. +@node Object File Formats @section Object File Formats @cindex object file formats @@ -2418,6 +2434,7 @@ SOM, which is a cross-language ABI). The SOM reader is in @file{somread.c}. +@node Debugging File Formats @section Debugging File Formats This section describes characteristics of debugging information that @@ -2489,6 +2506,7 @@ DWARF 3 is an improved version of DWARF @cindex SOM debugging info Like COFF, the SOM definition includes debugging information. +@node Adding a New Symbol Reader to GDB @section Adding a New Symbol Reader to @value{GDBN} @cindex adding debugging info reader @@ -2511,6 +2529,7 @@ will only ever be implemented by one obj directly. This interface should be described in a file @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}. +@node Memory Management for Symbol Files @section Memory Management for Symbol Files Most memory associated with a loaded symbol file is stored on @@ -2522,10 +2541,45 @@ released when the objfile is unloaded or objfile must not reference symbol or type data from another objfile; they could be unloaded at different times. -User convenience variables, et cetera, have associated types. Normally -these types live in the associated objfile. However, when the objfile -is unloaded, those types are deep copied to global memory, so that -the values of the user variables and history items are not lost. +@node Memory Management for Types +@section Memory Management for Types +@cindex memory management for types + +@findex TYPE_OBJFILE +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type. +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its +obstack) and in such case the type remains valid till the objfile is unloaded +or reloaded. For such types with an associated objfile no reference counting +is being made. + +User convenience variables, et cetera, have associated types. Normally these +types live in the associated objfile. However, when the objfile is unloaded, +those types are deep copied to global memory, so that the values of the user +variables and history items are not lost. During the copy they will get their +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable} +types. + +Types with null @code{TYPE_OBJFILE} can be either permanent types +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the +first idle @value{GDBN} moment if the last object referencing them is removed. +Permanent types are allocated by the function @code{alloc_type} (and its +derivations like @code{init_type}) specifying objfile as @code{NULL}. The +reclaimable types are created the same way but moreover they need to have +@code{type_init_group} called to start their tracking as being possibly +deallocatable. + +@findex free_all_types +When @value{GDBN} gets idle it always calls the @code{free_all_types} function +which deallocates any unused types. All types currently not owned by an +objfile must be marked as used on each @code{free_all_types} call as they would +get deallocated as unused otherwise. + +@code{free_all_types} automatically checks for any cross-type references such +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and +prevents early deallocation for any such existing references. Reclaimable +types may reference any other reclaimable types or even permanent types. But +permanent types must not reference reclaimable types (nor an objfile associated +type). @node Language Support Index: gdb-7.2.90.20110525/gdb/doc/observer.texi =================================================================== --- gdb-7.2.90.20110525.orig/gdb/doc/observer.texi 2011-01-05 06:09:54.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/doc/observer.texi 2011-05-25 17:05:21.000000000 +0200 @@ -223,6 +223,11 @@ Bytes from @var{data} to @var{data} + @v to the current inferior at @var{addr}. @end deftypefun +@c @deftypefun void mark_used (void) +@c Mark any possibly reclaimable objects as used during a mark-and-sweep garbage +@c collector pass. Currently only @code{type_mark_used} marker is supported. +@c @end deftypefun + @deftypefun void test_notification (int @var{somearg}) This observer is used for internal testing. Do not use. See testsuite/gdb.gdb/observer.exp. Index: gdb-7.2.90.20110525/gdb/dwarf2expr.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/dwarf2expr.c 2011-05-13 20:54:47.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/dwarf2expr.c 2011-05-25 17:05:21.000000000 +0200 @@ -912,6 +912,13 @@ execute_stack_op (struct dwarf_expr_cont ctx->num_pieces = 0; goto abort_expression; + case DW_OP_push_object_address: + if (ctx->get_object_address == NULL) + error (_("DWARF-2 expression error: DW_OP_push_object_address must " + "have a value to push.")); + result = (ctx->get_object_address) (ctx->baton); + break; + default: error (_("Unhandled dwarf expression opcode 0x%x"), op); } Index: gdb-7.2.90.20110525/gdb/dwarf2expr.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/dwarf2expr.h 2011-02-27 17:25:37.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/dwarf2expr.h 2011-05-25 17:05:21.000000000 +0200 @@ -114,9 +114,15 @@ struct dwarf_expr_context #if 0 /* Not yet implemented. */ + /* Return the location expression for the dwarf expression + subroutine in the die at OFFSET in the current compilation unit. + The result must be live until the current expression evaluation + is complete. */ + unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length); +#endif + /* Return the `object address' for DW_OP_push_object_address. */ CORE_ADDR (*get_object_address) (void *baton); -#endif /* The current depth of dwarf expression recursion, via DW_OP_call*, DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum Index: gdb-7.2.90.20110525/gdb/dwarf2loc.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/dwarf2loc.c 2011-03-22 22:06:33.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/dwarf2loc.c 2011-05-25 17:05:21.000000000 +0200 @@ -134,6 +134,9 @@ struct dwarf_expr_baton { struct frame_info *frame; struct dwarf2_per_cu_data *per_cu; + /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's + DW_AT_data_location) for DW_OP_push_object_address. */ + CORE_ADDR object_address; }; /* Helper functions for dwarf2_evaluate_loc_desc. */ @@ -202,23 +205,33 @@ dwarf_expr_frame_base_1 (struct symbol * symbaton = SYMBOL_LOCATION_BATON (framefunc); *start = dwarf2_find_location_expression (symbaton, length, pc); } - else + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs) { struct dwarf2_locexpr_baton *symbaton; symbaton = SYMBOL_LOCATION_BATON (framefunc); - if (symbaton != NULL) - { - *length = symbaton->size; - *start = symbaton->data; - } - else - *start = NULL; + gdb_assert (symbaton != NULL); + *start = symbaton->data; + *length = symbaton->size; + } + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs) + { + struct dwarf2_locexpr_baton *symbaton; + + symbaton = SYMBOL_LOCATION_BATON (framefunc); + gdb_assert (symbaton == NULL); + *start = NULL; + *length = 0; /* unused */ } + else + internal_error (__FILE__, __LINE__, + _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""), + SYMBOL_COMPUTED_OPS (framefunc), + SYMBOL_PRINT_NAME (framefunc)); if (*start == NULL) error (_("Could not find the frame base for \"%s\"."), - SYMBOL_NATURAL_NAME (framefunc)); + SYMBOL_PRINT_NAME (framefunc)); } /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for @@ -286,6 +299,172 @@ dwarf_expr_dwarf_call (struct dwarf_expr ctx->get_frame_pc, ctx->baton); } +static CORE_ADDR +dwarf_expr_object_address (void *baton) +{ + struct dwarf_expr_baton *debaton = baton; + + /* The message is suppressed in DWARF_BLOCK_EXEC. */ + if (debaton->object_address == 0) + error (_("Cannot resolve DW_OP_push_object_address for a missing object")); + + return debaton->object_address; +} + +/* Address of the variable we are currently referring to. It is set from + DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for + DW_OP_push_object_address. */ + +static CORE_ADDR object_address; + +/* Callers use object_address_set while their callers use the result set so we + cannot run the cleanup at the local block of our direct caller. Still we + should reset OBJECT_ADDRESS at least for the next GDB command. */ + +static void +object_address_cleanup (void *prev_save_voidp) +{ + CORE_ADDR *prev_save = prev_save_voidp; + + object_address = *prev_save; + xfree (prev_save); +} + +/* Set the base address - DW_AT_location - of a variable. It is being later + used to derive other object addresses by DW_OP_push_object_address. + + It would be useful to sanity check ADDRESS - such as for some objects with + unset value_raw_address - but some valid addresses may be zero (such as first + objects in relocatable .o files). */ + +void +object_address_set (CORE_ADDR address) +{ + CORE_ADDR *prev_save; + + prev_save = xmalloc (sizeof *prev_save); + *prev_save = object_address; + make_cleanup (object_address_cleanup, prev_save); + + object_address = address; +} + +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable + by dwarf_expr_fetch (RETVAL, 0). FRAME parameter can be NULL to call + get_selected_frame to find it. Returned dwarf_expr_context freeing is + pushed on the cleanup chain. */ + +static struct dwarf_expr_context * +dwarf_expr_prep_ctx (struct frame_info *frame, const gdb_byte *data, + size_t size, struct dwarf2_per_cu_data *per_cu) +{ + struct dwarf_expr_context *ctx; + struct dwarf_expr_baton baton; + struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); + volatile struct gdb_exception ex; + + baton.frame = frame; + baton.per_cu = per_cu; + baton.object_address = object_address; + + ctx = new_dwarf_expr_context (); + make_cleanup_free_dwarf_expr_context (ctx); + + ctx->gdbarch = get_objfile_arch (objfile); + ctx->addr_size = dwarf2_per_cu_addr_size (per_cu); + ctx->offset = dwarf2_per_cu_text_offset (per_cu); + ctx->baton = &baton; + ctx->read_reg = dwarf_expr_read_reg; + ctx->read_mem = dwarf_expr_read_mem; + ctx->get_frame_base = dwarf_expr_frame_base; + ctx->get_frame_cfa = dwarf_expr_frame_cfa; + ctx->get_frame_pc = dwarf_expr_frame_pc; + ctx->get_tls_address = dwarf_expr_tls_address; + ctx->dwarf_call = dwarf_expr_dwarf_call; + ctx->get_object_address = dwarf_expr_object_address; + + TRY_CATCH (ex, RETURN_MASK_ERROR) + { + dwarf_expr_eval (ctx, data, size); + } + if (ex.reason < 0) + { + if (ex.error == NOT_AVAILABLE_ERROR) + return NULL; + else + throw_exception (ex); + } + + /* It was used only during dwarf_expr_eval. */ + ctx->baton = NULL; + + return ctx; +} + +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one + CORE_ADDR result on the DWARF stack stack. */ + +CORE_ADDR +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton) +{ + struct dwarf_expr_context *ctx; + CORE_ADDR retval; + struct cleanup *back_to = make_cleanup (null_cleanup, 0); + + ctx = dwarf_expr_prep_ctx (get_selected_frame (NULL), dlbaton->data, + dlbaton->size, dlbaton->per_cu); + if (ctx == NULL) + throw_error (NOT_AVAILABLE_ERROR, _("Value not available")); + if (ctx->num_pieces > 0) + error (_("DW_OP_*piece is unsupported for DW_FORM_block")); + + retval = dwarf_expr_fetch (ctx, 0); + + if (ctx->location == DWARF_VALUE_REGISTER) + { + /* Inlined dwarf_expr_read_reg as we no longer have the baton. */ + + int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval); + struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr; + struct frame_info *frame = get_selected_frame (NULL); + + retval = address_from_register (type, gdb_regnum, frame); + } + + do_cleanups (back_to); + + return retval; +} + +/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one + CORE_ADDR result stored to *ADDRP on the DWARF stack stack. If the result + could not be found return zero and keep *ADDRP unchanged. */ + +int +dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton, + struct type *type, CORE_ADDR *addrp) +{ + struct frame_info *frame = get_selected_frame (NULL); + const gdb_byte *data; + size_t size; + struct value *val; + + if (!dllbaton) + return 0; + + data = dwarf2_find_location_expression (dllbaton, &size, + get_frame_address_in_block (frame)); + if (data == NULL) + return 0; + + val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu); + if (value_optimized_out (val)) + return 0; + + *addrp = value_as_address (val); + return 1; +} + struct piece_closure { /* Reference count. */ @@ -1072,11 +1251,8 @@ dwarf2_evaluate_loc_desc_full (struct ty LONGEST byte_offset) { struct value *retval; - struct dwarf_expr_baton baton; struct dwarf_expr_context *ctx; struct cleanup *old_chain; - struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); - volatile struct gdb_exception ex; if (byte_offset < 0) invalid_synthetic_pointer (); @@ -1089,38 +1265,14 @@ dwarf2_evaluate_loc_desc_full (struct ty return retval; } - baton.frame = frame; - baton.per_cu = per_cu; - - ctx = new_dwarf_expr_context (); - old_chain = make_cleanup_free_dwarf_expr_context (ctx); - - ctx->gdbarch = get_objfile_arch (objfile); - ctx->addr_size = dwarf2_per_cu_addr_size (per_cu); - ctx->offset = dwarf2_per_cu_text_offset (per_cu); - ctx->baton = &baton; - ctx->read_reg = dwarf_expr_read_reg; - ctx->read_mem = dwarf_expr_read_mem; - ctx->get_frame_base = dwarf_expr_frame_base; - ctx->get_frame_cfa = dwarf_expr_frame_cfa; - ctx->get_frame_pc = dwarf_expr_frame_pc; - ctx->get_tls_address = dwarf_expr_tls_address; - ctx->dwarf_call = dwarf_expr_dwarf_call; + old_chain = make_cleanup (null_cleanup, 0); - TRY_CATCH (ex, RETURN_MASK_ERROR) - { - dwarf_expr_eval (ctx, data, size); - } - if (ex.reason < 0) + ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu); + if (ctx == NULL) { - if (ex.error == NOT_AVAILABLE_ERROR) - { - retval = allocate_value (type); - mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type)); - return retval; - } - else - throw_exception (ex); + retval = allocate_value (type); + mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type)); + return retval; } if (ctx->num_pieces > 0) @@ -1166,6 +1318,15 @@ dwarf2_evaluate_loc_desc_full (struct ty CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0); int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0); + /* Frame may be needed for check_typedef of TYPE_DYNAMIC. */ + make_cleanup_restore_selected_frame (); + select_frame (frame); + + /* object_address_set called here is required in ALLOCATE_VALUE's + CHECK_TYPEDEF for the object's possible + DW_OP_push_object_address. */ + object_address_set (address); + retval = allocate_value_lazy (type); VALUE_LVAL (retval) = lval_memory; if (in_stack_memory) @@ -2855,11 +3016,51 @@ loclist_tracepoint_var_ref (struct symbo dlbaton->per_cu); } -/* The set of location functions used with the DWARF-2 expression - evaluator and location lists. */ +/* The set of location functions used with the DWARF-2 location lists. */ const struct symbol_computed_ops dwarf2_loclist_funcs = { loclist_read_variable, loclist_read_needs_frame, loclist_describe_location, loclist_tracepoint_var_ref }; + +static struct value * +missing_read_variable (struct symbol *symbol, struct frame_info *frame) +{ + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol); + + gdb_assert (dlbaton == NULL); + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol)); +} + +static int +missing_read_needs_frame (struct symbol *symbol) +{ + return 0; +} + +static void +missing_describe_location (struct symbol *symbol, CORE_ADDR addr, + struct ui_file *stream) +{ + fprintf_filtered (stream, _("a variable we are unable to resolve")); +} + +static void +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch, + struct agent_expr *ax, struct axs_value *value) +{ + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol); + + gdb_assert (dlbaton == NULL); + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol)); +} + +/* The set of location functions used with the DWARF-2 evaluator when we are + unable to resolve the symbols. */ +const struct symbol_computed_ops dwarf2_missing_funcs = { + missing_read_variable, + missing_read_needs_frame, + missing_describe_location, + missing_tracepoint_var_ref +}; Index: gdb-7.2.90.20110525/gdb/dwarf2loc.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/dwarf2loc.h 2011-02-17 17:20:44.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/dwarf2loc.h 2011-05-25 17:05:21.000000000 +0200 @@ -107,6 +107,15 @@ struct dwarf2_loclist_baton extern const struct symbol_computed_ops dwarf2_locexpr_funcs; extern const struct symbol_computed_ops dwarf2_loclist_funcs; +extern const struct symbol_computed_ops dwarf2_missing_funcs; + +extern void object_address_set (CORE_ADDR address); + +extern CORE_ADDR dwarf_locexpr_baton_eval + (struct dwarf2_locexpr_baton *dlbaton); + +extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton, + struct type *type, CORE_ADDR *addrp); /* Compile a DWARF location expression to an agent expression. Index: gdb-7.2.90.20110525/gdb/dwarf2read.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/dwarf2read.c 2011-05-17 23:26:39.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/dwarf2read.c 2011-05-25 17:06:06.000000000 +0200 @@ -1219,6 +1219,9 @@ static void fill_in_loclist_baton (struc struct dwarf2_loclist_baton *baton, struct attribute *attr); +static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton + (struct attribute *attr, struct dwarf2_cu *cu); + static void dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, struct dwarf2_cu *cu); @@ -1253,6 +1256,9 @@ static void age_cached_comp_units (void) static void free_one_cached_comp_unit (void *); +static void fetch_die_type_attrs (struct die_info *die, struct type *type, + struct dwarf2_cu *cu); + static struct type *set_die_type (struct die_info *, struct type *, struct dwarf2_cu *); @@ -1277,6 +1283,9 @@ static struct type *get_die_type_at_offs static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton + (struct attribute *attr, struct dwarf2_cu *cu); + static void dwarf2_release_queue (void *dummy); static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, @@ -7455,6 +7464,29 @@ process_enumeration_scope (struct die_in new_symbol (die, this_type, cu); } +/* Create a new array dimension referencing its target type TYPE. + + Multidimensional arrays are internally represented as a stack of + singledimensional arrays being referenced by their TYPE_TARGET_TYPE. */ + +static struct type * +create_single_array_dimension (struct type *type, struct type *range_type, + struct die_info *die, struct dwarf2_cu *cu) +{ + type = create_array_type (NULL, type, range_type); + + /* These generic type attributes need to be fetched by + evaluate_subexp_standard 's call of + value_subscripted_rvalue only for the innermost array type. */ + fetch_die_type_attrs (die, type, cu); + + /* These generic type attributes are checked for allocated/associated + validity while accessing FIELD_LOC_KIND_DWARF_BLOCK. */ + fetch_die_type_attrs (die, range_type, cu); + + return type; +} + /* Extract all information from a DW_TAG_array_type DIE and put it in the DIE's type field. For now, this only handles one dimensional arrays. */ @@ -7468,7 +7500,7 @@ read_array_type (struct die_info *die, s struct type *element_type, *range_type, *index_type; struct type **range_types = NULL; struct attribute *attr; - int ndim = 0; + int ndim = 0, i; struct cleanup *back_to; char *name; @@ -7521,17 +7553,19 @@ read_array_type (struct die_info *die, s type = element_type; if (read_array_order (die, cu) == DW_ORD_col_major) - { - int i = 0; - - while (i < ndim) - type = create_array_type (NULL, type, range_types[i++]); - } - else - { - while (ndim-- > 0) - type = create_array_type (NULL, type, range_types[ndim]); - } + for (i = 0; i < ndim; i++) + type = create_single_array_dimension (type, range_types[i], die, cu); + else /* (read_array_order (die, cu) == DW_ORD_row_major) */ + for (i = ndim - 1; i >= 0; i--) + type = create_single_array_dimension (type, range_types[i], die, cu); + + /* Data locations should be set only for the outermost dimension as they + would be confusing for the dereferenced offset on the inner ones. */ + attr = dwarf2_attr (die, DW_AT_data_location, cu); + if (attr_form_is_block (attr)) + TYPE_DATA_LOCATION_DWARF_BLOCK (type) + = dwarf2_attr_to_locexpr_baton (attr, cu); + gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type)); /* Understand Dwarf2 support for vector types (like they occur on the PowerPC w/ AltiVec). Gcc just adds another attribute to the @@ -8015,29 +8049,114 @@ read_tag_string_type (struct die_info *d struct gdbarch *gdbarch = get_objfile_arch (objfile); struct type *type, *range_type, *index_type, *char_type; struct attribute *attr; - unsigned int length; + int length; + + index_type = objfile_type (objfile)->builtin_int; + /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type. */ + range_type = alloc_type (objfile); + /* LOW_BOUND and HIGH_BOUND are set for real below. */ + range_type = create_range_type (range_type, index_type, 0, -1); + + /* C/C++ should probably have the low bound 0 but C/C++ does not use + DW_TAG_string_type. */ + TYPE_LOW_BOUND (range_type) = 1; attr = dwarf2_attr (die, DW_AT_string_length, cu); - if (attr) + if (attr && attr_form_is_block (attr)) { - length = DW_UNSND (attr); + /* Security check for a size overflow. */ + if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size) + TYPE_HIGH_BOUND (range_type) = 1; + /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size + instruction as DW_AT_string_length specifies the length location, not + its value. */ + else + { + struct dwarf2_locexpr_baton *length_baton = NULL; + struct dwarf_block *blk = DW_BLOCK (attr); + + /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing + DW_OP_deref* in such case. */ + + if (blk->size == 1 && blk->data[0] >= DW_OP_reg0 + && blk->data[0] <= DW_OP_reg31) + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu); + else if (blk->size > 1 && blk->data[0] == DW_OP_regx) + { + ULONGEST ulongest; + const gdb_byte *end; + + end = read_uleb128 (&blk->data[1], &blk->data[blk->size], + &ulongest); + if (end == &blk->data[blk->size]) + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu); + } + + if (length_baton == NULL) + { + struct attribute *size_attr; + gdb_byte *data; + + length_baton = obstack_alloc (&cu->comp_unit_obstack, + sizeof (*length_baton)); + length_baton->per_cu = cu->per_cu; + length_baton->size = DW_BLOCK (attr)->size + 2; + data = obstack_alloc (&cu->comp_unit_obstack, + length_baton->size); + length_baton->data = data; + memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size); + + /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH + specifies the size of an integer to fetch. */ + size_attr = dwarf2_attr (die, DW_AT_byte_size, cu); + if (size_attr) + { + data[DW_BLOCK (attr)->size] = DW_OP_deref_size; + data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr); + if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr)) + complaint (&symfile_complaints, + _("DW_AT_string_length's DW_AT_byte_size " + "integer exceeds the byte size storage")); + } + else + { + data[DW_BLOCK (attr)->size] = DW_OP_deref; + data[DW_BLOCK (attr)->size + 1] = DW_OP_nop; + } + } + + TYPE_RANGE_DATA (range_type)->high.kind + = RANGE_BOUND_KIND_DWARF_BLOCK; + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton; + TYPE_DYNAMIC (range_type) = 1; + } } else { - /* Check for the DW_AT_byte_size attribute. */ + if (attr && attr_form_is_constant (attr)) + { + /* We currently do not support a constant address where the location + should be read from - attr_form_is_block is expected instead. See + DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference. + */ + /* PASSTHRU */ + } + attr = dwarf2_attr (die, DW_AT_byte_size, cu); - if (attr) - { - length = DW_UNSND (attr); - } + if (attr && attr_form_is_block (attr)) + { + TYPE_RANGE_DATA (range_type)->high.kind + = RANGE_BOUND_KIND_DWARF_BLOCK; + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = + dwarf2_attr_to_locexpr_baton (attr, cu); + TYPE_DYNAMIC (range_type) = 1; + } + else if (attr && attr_form_is_constant (attr)) + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0); else - { - length = 1; - } + TYPE_HIGH_BOUND (range_type) = 1; } - index_type = objfile_type (objfile)->builtin_int; - range_type = create_range_type (NULL, index_type, 1, length); char_type = language_string_char_type (cu->language_defn, gdbarch); type = create_string_type (NULL, char_type, range_type); @@ -8322,8 +8441,7 @@ read_subrange_type (struct die_info *die struct type *base_type; struct type *range_type; struct attribute *attr; - LONGEST low = 0; - LONGEST high = -1; + LONGEST low; char *name; LONGEST negative_mask; @@ -8336,53 +8454,126 @@ read_subrange_type (struct die_info *die if (range_type) return range_type; - if (cu->language == language_fortran) - { - /* FORTRAN implies a lower bound of 1, if not given. */ - low = 1; - } + /* LOW_BOUND and HIGH_BOUND are set for real below. */ + range_type = create_range_type (NULL, base_type, 0, -1); + TYPE_UNSIGNED (range_type) = 0; - /* FIXME: For variable sized arrays either of these could be - a variable rather than a constant value. We'll allow it, - but we don't know how to handle it. */ - attr = dwarf2_attr (die, DW_AT_lower_bound, cu); - if (attr) - low = dwarf2_get_attr_constant_value (attr, 0); + negative_mask = + (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); - attr = dwarf2_attr (die, DW_AT_upper_bound, cu); - if (attr) + /* Exclude language_ada from any TYPE_DYNAMIC constructs below. GDB Ada + supports implements the dynamic bounds in a non-DWARF way and the + existing DWARF dynamic bounds are invalid, leading to memory access + errors. */ + + attr = dwarf2_attr (die, DW_AT_lower_bound, cu); + if (attr && attr_form_is_block (attr) && cu->language != language_ada) { - if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) - { - /* GCC encodes arrays with unspecified or dynamic length - with a DW_FORM_block1 attribute or a reference attribute. - FIXME: GDB does not yet know how to handle dynamic - arrays properly, treat them as arrays with unspecified - length for now. - - FIXME: jimb/2003-09-22: GDB does not really know - how to handle arrays of unspecified length - either; we just represent them as zero-length - arrays. Choose an appropriate upper bound given - the lower bound we've computed above. */ - high = low - 1; - } - else - high = dwarf2_get_attr_constant_value (attr, 1); + TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK; + TYPE_RANGE_DATA (range_type)->low.u.dwarf_block = + dwarf2_attr_to_locexpr_baton (attr, cu); + TYPE_DYNAMIC (range_type) = 1; + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */ + low = 0; + } + else if (attr && is_ref_attr (attr) && cu->language != language_ada) + { + struct die_info *target_die; + struct dwarf2_cu *target_cu = cu; + struct attribute *target_loc_attr; + + target_die = follow_die_ref_or_sig (die, attr, &target_cu); + gdb_assert (target_cu->objfile == cu->objfile); + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu); + + TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST; + TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu); + TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type + = die_type (target_die, target_cu); + TYPE_DYNAMIC (range_type) = 1; + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */ + low = 0; } else { - attr = dwarf2_attr (die, DW_AT_count, cu); - if (attr) + if (attr && attr_form_is_constant (attr)) + low = dwarf2_get_attr_constant_value (attr, 0); + else { - int count = dwarf2_get_attr_constant_value (attr, 1); - high = low + count - 1; + if (cu->language == language_fortran) + { + /* FORTRAN implies a lower bound of 1, if not given. */ + low = 1; + } + else + { + /* According to DWARF we should assume the value 0 only for + LANGUAGE_C and LANGUAGE_CPLUS. */ + low = 0; + } } + if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) + low |= negative_mask; + TYPE_LOW_BOUND (range_type) = low; + if (low >= 0) + TYPE_UNSIGNED (range_type) = 1; + } + + attr = dwarf2_attr (die, DW_AT_upper_bound, cu); + if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr) + && !is_ref_attr (attr))) + { + attr = dwarf2_attr (die, DW_AT_count, cu); + /* It does not hurt but it is needlessly ineffective in check_typedef. */ + if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr))) + { + TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1; + TYPE_DYNAMIC (range_type) = 1; + } + /* Pass it now as the regular DW_AT_upper_bound. */ + } + + if (attr && attr_form_is_block (attr) && cu->language != language_ada) + { + TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK; + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = + dwarf2_attr_to_locexpr_baton (attr, cu); + TYPE_DYNAMIC (range_type) = 1; + } + else if (attr && is_ref_attr (attr) && cu->language != language_ada) + { + struct die_info *target_die; + struct dwarf2_cu *target_cu = cu; + struct attribute *target_loc_attr; + + target_die = follow_die_ref_or_sig (die, attr, &target_cu); + gdb_assert (target_cu->objfile == cu->objfile); + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu); + + TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST; + TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu); + TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type + = die_type (target_die, target_cu); + TYPE_DYNAMIC (range_type) = 1; + } + else + { + LONGEST high; + + if (attr && attr_form_is_constant (attr)) + high = dwarf2_get_attr_constant_value (attr, 0); else { - /* Unspecified array length. */ + /* Ada expects an empty array on no boundary attributes. */ + if (cu->language != language_ada) + TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; high = low - 1; } + if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) + high |= negative_mask; + TYPE_HIGH_BOUND (range_type) = high; } /* Dwarf-2 specifications explicitly allows to create subrange types @@ -8423,24 +8614,41 @@ read_subrange_type (struct die_info *die } } - negative_mask = - (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); - if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) - low |= negative_mask; - if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) - high |= negative_mask; - - range_type = create_range_type (NULL, base_type, low, high); - - /* Mark arrays with dynamic length at least as an array of unspecified - length. GDB could check the boundary but before it gets implemented at - least allow accessing the array elements. */ - if (attr && attr->form == DW_FORM_block1) - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; - - /* Ada expects an empty array on no boundary attributes. */ - if (attr == NULL && cu->language != language_ada) - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; + /* DW_AT_bit_stride is currently unsupported as we count in bytes. */ + attr = dwarf2_attr (die, DW_AT_byte_stride, cu); + if (attr && attr_form_is_block (attr) && cu->language != language_ada) + { + TYPE_RANGE_DATA (range_type)->byte_stride.kind + = RANGE_BOUND_KIND_DWARF_BLOCK; + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block = + dwarf2_attr_to_locexpr_baton (attr, cu); + TYPE_DYNAMIC (range_type) = 1; + } + else if (attr && is_ref_attr (attr) && cu->language != language_ada) + { + struct die_info *target_die; + struct dwarf2_cu *target_cu = cu; + struct attribute *target_loc_attr; + + target_die = follow_die_ref_or_sig (die, attr, &target_cu); + gdb_assert (target_cu->objfile == cu->objfile); + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu); + + TYPE_RANGE_DATA (range_type)->byte_stride.kind + = RANGE_BOUND_KIND_DWARF_LOCLIST; + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu); + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type + = die_type (target_die, target_cu); + TYPE_DYNAMIC (range_type) = 1; + } + else if (attr && attr_form_is_constant (attr)) + { + TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0); + if (TYPE_BYTE_STRIDE (range_type) == 0) + complaint (&symfile_complaints, + _("Found DW_AT_byte_stride with unsupported value 0")); + } name = dwarf2_name (die, cu); if (name) @@ -10985,10 +11193,12 @@ var_decode_location (struct attribute *a (i.e. when the value of a register or memory location is referenced, or a thread-local block, etc.). Then again, it might not be worthwhile. I'm assuming that it isn't unless performance - or memory numbers show me otherwise. */ + or memory numbers show me otherwise. + + SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed. */ - dwarf2_symbol_mark_computed (attr, sym, cu); SYMBOL_CLASS (sym) = LOC_COMPUTED; + dwarf2_symbol_mark_computed (attr, sym, cu); if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) cu->has_loclist = 1; @@ -11029,6 +11239,8 @@ new_symbol_full (struct die_info *die, s else sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); OBJSTAT (objfile, n_syms++); + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */ + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs; /* Cache this symbol's name and the name's demangled form (if any). */ SYMBOL_SET_LANGUAGE (sym, cu->language); @@ -11801,6 +12013,9 @@ read_type_die_1 (struct die_info *die, s break; } + if (this_type) + finalize_type (this_type); + return this_type; } @@ -14655,61 +14870,99 @@ fill_in_loclist_baton (struct dwarf2_cu baton->base_address = cu->base_address; } -static void -dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, - struct dwarf2_cu *cu) +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton. ATTR must be a DW_BLOCK + attribute type. */ + +static struct dwarf2_locexpr_baton * +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu) { - if (attr_form_is_section_offset (attr) - /* ".debug_loc" may not exist at all, or the offset may be outside - the section. If so, fall through to the complaint in the - other branch. */ - && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile, - &dwarf2_per_objfile->loc)) - { - struct dwarf2_loclist_baton *baton; + struct dwarf2_locexpr_baton *baton; - baton = obstack_alloc (&cu->objfile->objfile_obstack, - sizeof (struct dwarf2_loclist_baton)); + gdb_assert (attr_form_is_block (attr)); - fill_in_loclist_baton (cu, baton, attr); + baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton)); + baton->per_cu = cu->per_cu; + gdb_assert (baton->per_cu); - if (cu->base_known == 0) - complaint (&symfile_complaints, - _("Location list used without " - "specifying the CU base address.")); + /* Note that we're just copying the block's data pointer + here, not the actual data. We're still pointing into the + info_buffer for SYM's objfile; right now we never release + that buffer, but when we do clean up properly this may + need to change. */ + baton->size = DW_BLOCK (attr)->size; + baton->data = DW_BLOCK (attr)->data; + gdb_assert (baton->size == 0 || baton->data != NULL); + + return baton; +} + +static struct dwarf2_loclist_baton * +dwarf2_attr_to_loclist_baton (struct attribute *attr, struct dwarf2_cu *cu) +{ + struct dwarf2_loclist_baton *baton; + + /* DW_AT_location of the referenced DIE may be missing if the referenced + variable has been optimized out. */ + if (!attr) + return NULL; + + dwarf2_read_section (dwarf2_per_objfile->objfile, + &dwarf2_per_objfile->loc); + if (!(attr_form_is_section_offset (attr) + /* ".debug_loc" may not exist at all, or the offset may be outside + the section. If so, fall through to the complaint in the + other branch. */ + && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile, + &dwarf2_per_objfile->loc))) + return NULL; + + baton = obstack_alloc (&cu->objfile->objfile_obstack, + sizeof (struct dwarf2_loclist_baton)); + + fill_in_loclist_baton (cu, baton, attr); + + if (cu->base_known == 0) + complaint (&symfile_complaints, + _("Location list used without " + "specifying the CU base address.")); + + return baton; +} + +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content. */ + +static void +dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, + struct dwarf2_cu *cu) +{ + struct dwarf2_loclist_baton *loclist_baton; + + loclist_baton = dwarf2_attr_to_loclist_baton (attr, cu); + if (loclist_baton) + { SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; - SYMBOL_LOCATION_BATON (sym) = baton; + SYMBOL_LOCATION_BATON (sym) = loclist_baton; + } + else if (attr_form_is_block (attr)) + { + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; + SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu); } else { - struct dwarf2_locexpr_baton *baton; + dwarf2_invalid_attrib_class_complaint ("location description", + SYMBOL_NATURAL_NAME (sym)); - baton = obstack_alloc (&cu->objfile->objfile_obstack, - sizeof (struct dwarf2_locexpr_baton)); - baton->per_cu = cu->per_cu; - gdb_assert (baton->per_cu); + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */ - if (attr_form_is_block (attr)) - { - /* Note that we're just copying the block's data pointer - here, not the actual data. We're still pointing into the - info_buffer for SYM's objfile; right now we never release - that buffer, but when we do clean up properly this may - need to change. */ - baton->size = DW_BLOCK (attr)->size; - baton->data = DW_BLOCK (attr)->data; - } - else - { - dwarf2_invalid_attrib_class_complaint ("location description", - SYMBOL_NATURAL_NAME (sym)); - baton->size = 0; - baton->data = NULL; - } + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs; + SYMBOL_LOCATION_BATON (sym) = NULL; - SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; - SYMBOL_LOCATION_BATON (sym) = baton; + /* For functions a missing DW_AT_frame_base does not optimize out the + whole function definition, only its frame base resolving. */ + if (attr->name == DW_AT_location) + SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; } } @@ -15058,6 +15311,25 @@ offset_and_type_eq (const void *item_lhs return ofs_lhs->offset == ofs_rhs->offset; } +/* Fill in generic attributes applicable for type DIEs. */ + +static void +fetch_die_type_attrs (struct die_info *die, struct type *type, + struct dwarf2_cu *cu) +{ + struct attribute *attr; + + attr = dwarf2_attr (die, DW_AT_allocated, cu); + if (attr_form_is_block (attr)) + TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu); + gdb_assert (!TYPE_NOT_ALLOCATED (type)); + + attr = dwarf2_attr (die, DW_AT_associated, cu); + if (attr_form_is_block (attr)) + TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu); + gdb_assert (!TYPE_NOT_ASSOCIATED (type)); +} + /* Set the type associated with DIE to TYPE. Save it in CU's hash table if necessary. For convenience, return TYPE. @@ -15083,6 +15355,8 @@ set_die_type (struct die_info *die, stru struct objfile *objfile = cu->objfile; htab_t *type_hash_ptr; + fetch_die_type_attrs (die, type, cu); + /* For Ada types, make sure that the gnat-specific data is always initialized (if not already set). There are a few types where we should not be doing so, because the type-specific area is Index: gdb-7.2.90.20110525/gdb/elfread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/elfread.c 2011-05-03 18:25:20.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/elfread.c 2011-05-25 17:05:21.000000000 +0200 @@ -43,6 +43,12 @@ #include "infcall.h" #include "gdbthread.h" #include "regcache.h" +#include "stap-probe.h" +#include "arch-utils.h" +#include "value.h" +#include "infcall.h" +#include "gdbthread.h" +#include "regcache.h" extern void _initialize_elfread (void); @@ -61,6 +67,21 @@ struct elfinfo asection *mdebugsect; /* Section pointer for .mdebug section */ }; +/* Per-objfile data for SystemTap probe info. */ + +static const struct objfile_data *stap_probe_key = NULL; + +/* Per-objfile data about SystemTap probes. */ + +struct stap_probe_per_objfile + { + /* The number of probes in this objfile. */ + int stap_num_probes; + + /* The probes themselves. */ + struct stap_probe *probes; + }; + static void free_elfinfo (void *); /* Minimal symbols located at the GOT entries for .plt - that is the real @@ -1553,7 +1574,266 @@ elfstab_offset_sections (struct objfile complaint (&symfile_complaints, _("elf/stab section information missing for %s"), filename); } + +/* Helper function that parses the information contained in a + SystemTap's probe. Basically, the information consists in: + + - Probe's PC address; + - Link-time section address of `.stapsdt.base' section; + - Link-time address of the semaphore variable, or ZERO if the + probe doesn't have an associated semaphore; + - Probe's provider name; + - Probe's name; + - Probe's argument format. */ + +static void +handle_probe (struct objfile *objfile, struct sdt_note *el, + struct stap_probe *ret, CORE_ADDR base) +{ + bfd *abfd = objfile->obfd; + int size = bfd_get_arch_size (abfd) / 8; + struct gdbarch *gdbarch = get_objfile_arch (objfile); + struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; + CORE_ADDR base_ref; + + /* Provider and the name of the probe. */ + ret->provider = (const char *) &el->data[3 * size]; + ret->name = memchr (ret->provider, '\0', + (unsigned long *) el->data + + el->size - (unsigned long *) ret->provider); + /* Making sure there is a name. */ + if (!ret->name) + complaint (&symfile_complaints, _("corrupt probe when reading `%s'"), + objfile->name); + else + ++ret->name; + + /* Retrieving the probe's address. */ + ret->address = extract_typed_address ((const gdb_byte *) &el->data[0], + ptr_type); + /* Link-time sh_addr of `.stapsdt.base' section. */ + base_ref = extract_typed_address ((const gdb_byte *) &el->data[size], + ptr_type); + /* Semaphore address. */ + ret->sem_addr = extract_typed_address ((const gdb_byte *) &el->data[2 * size], + ptr_type); + + ret->address += (ANOFFSET (objfile->section_offsets, + SECT_OFF_TEXT (objfile)) + + base - base_ref); + if (ret->sem_addr) + ret->sem_addr += (ANOFFSET (objfile->section_offsets, + SECT_OFF_DATA (objfile)) + + base - base_ref); + + /* Arguments. We can only extract the argument format if there is a valid + name for this probe. */ + if (ret->name) + { + ret->args = memchr (ret->name, '\0', + (unsigned long *) el->data + + el->size - (unsigned long *) ret->name); + + if (ret->args++ != NULL + || memchr (ret->args, '\0', (unsigned long *) el->data + + el->size - (unsigned long *) ret->name) + != el->data + el->size - 1) + complaint (&symfile_complaints, _("corrupt probe when reading `%s'"), + objfile->name); + } + else + ret->args = NULL; +} + +/* The name of the SystemTap section where we will find information about + the probes. */ + +#define STAP_BASE_SECTION_NAME ".stapsdt.base" + +/* Helper function which tries to find the base address of the SystemTap + base section named STAP_BASE_SECTION_NAME. */ + +static void +get_base_address_1 (bfd *abfd, asection *sect, void *obj) +{ + bfd_vma *base = (bfd_vma *) obj; + + if (*base == (bfd_vma) -1 + && (sect->flags & (SEC_DATA | SEC_ALLOC | SEC_HAS_CONTENTS)) + && sect->name && !strcmp (sect->name, STAP_BASE_SECTION_NAME)) + *base = sect->vma; +} + +/* Helper function which iterates over every section in the BFD file, + trying to find the base address of the SystemTap base section. + Returns the section address if found, or -1 otherwise. */ + +static bfd_vma +get_base_address (bfd *obfd) +{ + bfd_vma base = (bfd_vma) -1; + + bfd_map_over_sections (obfd, get_base_address_1, (void *) &base); + + return base; +} + +/* Implementation of `sym_get_probes', as documented in symfile.h. */ + +static const struct stap_probe * +elf_get_probes (struct objfile *objfile, int *num_probes) +{ + struct stap_probe *ret = NULL; + struct stap_probe_per_objfile *probes_per_objfile; + + /* Initially, no probes. */ + *num_probes = 0; + + /* Have we parsed this objfile's probes already? */ + probes_per_objfile + = (struct stap_probe_per_objfile *) objfile_data (objfile, + stap_probe_key); + + if (!probes_per_objfile) + { + /* If we are here, then this is the first time we are parsing the + probe's information. We basically have to count how many probes + the objfile has, and then fill in the necessary information + for each one. */ + + bfd *obfd = objfile->obfd; + bfd_vma base = get_base_address (obfd); + struct sdt_note *iter; + int i; + int n = 0; + + if (! elf_tdata (obfd)->sdt_note_head) + /* There isn't any probe here. */ + return NULL; + + /* Allocating space for probe info. */ + for (iter = elf_tdata (obfd)->sdt_note_head; + iter; + iter = iter->next, ++n); + + ret = xcalloc (n, sizeof (struct stap_probe)); + + /* Parsing each probe's information. */ + for (iter = elf_tdata (obfd)->sdt_note_head, i = 0; + iter; + iter = iter->next, i++) + /* We first have to handle all the information about the + probe which is present in the section. */ + handle_probe (objfile, iter, &ret[i], base); + + /* Creating a cache for these probes in the objfile's registry. */ + probes_per_objfile = xmalloc (sizeof (struct stap_probe_per_objfile)); + + probes_per_objfile->stap_num_probes = n; + probes_per_objfile->probes = ret; + + set_objfile_data (objfile, stap_probe_key, probes_per_objfile); + } + else + ret = probes_per_objfile->probes; + + *num_probes = probes_per_objfile->stap_num_probes; + + return ret; +} + +/* Implementation of `sym_get_probe_argument_count', as documented in + symfile.h. */ + +static int +elf_get_probe_argument_count (struct objfile *objfile, + const struct stap_probe *probe) +{ + const char *pargs = probe->args; + + if (!pargs || !*pargs || *pargs == ':') + /* No arguments. */ + return 0; + + return stap_get_probe_argument_count (probe); +} + +/* Implementation of `sym_evaluate_probe_argument', as documented in + symfile.h. */ + +static struct value * +elf_evaluate_probe_argument (struct objfile *objfile, + const struct stap_probe *probe, + struct frame_info *frame, + int n) +{ + return stap_evaluate_probe_argument (objfile, probe, frame, n); +} + +/* Implementation of `sym_compile_to_ax', as documented in symfile.h. */ + +static void +elf_compile_to_ax (struct objfile *objfile, + const struct stap_probe *probe, + struct agent_expr *expr, + struct axs_value *value, + int n) +{ + stap_compile_to_ax (objfile, probe, expr, value, n); +} + +/* Implementation of `sym_relocate_probe', as documented in symfile.h. */ + +static void +elf_symfile_relocate_probe (struct objfile *objfile, + struct section_offsets *new_offsets, + struct section_offsets *delta) +{ + int i; + struct stap_probe_per_objfile *p + = (struct stap_probe_per_objfile *) objfile_data (objfile, + stap_probe_key); + + if (!p) + /* No probe to relocate. */ + return; + + for (i = 0; i < p->stap_num_probes; i++) + { + p->probes[i].address += ANOFFSET (delta, SECT_OFF_TEXT (objfile)); + if (p->probes[i].sem_addr) + p->probes[i].sem_addr += ANOFFSET (delta, SECT_OFF_DATA (objfile)); + } +} + +/* Helper function used to free the space allocated for storing SystemTap + probe information. */ + +static void +stap_probe_key_free (struct objfile *objfile, void *d) +{ + int i; + struct stap_probe_per_objfile *data = (struct stap_probe_per_objfile *) d; + + for (i = 0; i < data->stap_num_probes; i++) + stap_free_parsed_args (data->probes[i].parsed_args); + xfree (data->probes); + xfree (data); +} + + +/* Implementation `sym_probe_fns', as documented in symfile.h. */ + +static const struct sym_probe_fns elf_probe_fns = +{ + elf_get_probes, /* sym_get_probes */ + elf_get_probe_argument_count, /* sym_get_probe_argument_count */ + elf_evaluate_probe_argument, /* sym_evaluate_probe_argument */ + elf_compile_to_ax, /* sym_compile_to_ax */ + elf_symfile_relocate_probe, /* sym_relocate_probe */ +}; + /* Register that we are able to handle ELF object file formats. */ static const struct sym_fns elf_sym_fns = @@ -1568,6 +1848,7 @@ static const struct sym_fns elf_sym_fns elf_symfile_segments, /* Get segment information from a file. */ NULL, default_symfile_relocate, /* Relocate a debug section. */ + &elf_probe_fns, /* sym_probe_fns */ &psym_functions }; @@ -1586,6 +1867,7 @@ static const struct sym_fns elf_sym_fns_ elf_symfile_segments, /* Get segment information from a file. */ NULL, default_symfile_relocate, /* Relocate a debug section. */ + &elf_probe_fns, /* sym_probe_fns */ &psym_functions }; @@ -1603,6 +1885,7 @@ static const struct sym_fns elf_sym_fns_ elf_symfile_segments, /* Get segment information from a file. */ NULL, default_symfile_relocate, /* Relocate a debug section. */ + &elf_probe_fns, /* sym_probe_fns */ &dwarf2_gdb_index_functions }; @@ -1619,6 +1902,8 @@ static const struct gnu_ifunc_fns elf_gn void _initialize_elfread (void) { + stap_probe_key + = register_objfile_data_with_cleanup (NULL, stap_probe_key_free); add_symtab_fns (&elf_sym_fns); elf_objfile_gnu_ifunc_cache_data = register_objfile_data (); Index: gdb-7.2.90.20110525/gdb/eval.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/eval.c 2011-03-28 22:21:03.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/eval.c 2011-05-25 17:05:21.000000000 +0200 @@ -44,6 +44,7 @@ #include "objfiles.h" #include "python/python.h" #include "wrapper.h" +#include "dwarf2loc.h" #include "gdb_assert.h" @@ -489,27 +490,217 @@ init_array_element (struct value *array, } static struct value * -value_f90_subarray (struct value *array, - struct expression *exp, int *pos, enum noside noside) +value_f90_subarray (struct value *array, struct expression *exp, int *pos, + int nargs, enum noside noside) { - int pc = (*pos) + 1; - LONGEST low_bound, high_bound; - struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array))); - enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst); - - *pos += 3; + /* Type to use for the newly allocated value ARRAY. */ + struct type *new_array_type; - if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT) - low_bound = TYPE_LOW_BOUND (range); + /* Type being iterated for each dimension. */ + struct type *type, *type_last_target; + + /* Pointer in the last holder to the type of current dimension. */ + struct type **typep = &new_array_type; + + struct subscript_index + { + enum { SUBSCRIPT_RANGE, SUBSCRIPT_NUMBER } kind; + union + { + struct subscript_range + { + enum f90_range_type f90_range_type; + LONGEST low_bound, high_bound; + } + range; + LONGEST number; + }; + } + *subscript_array; + struct type **type_array; + int i; + struct cleanup *old_chain; + CORE_ADDR value_byte_address, value_byte_offset = 0; + htab_t copied_types; + struct value *saved_array; + + old_chain = make_cleanup (null_cleanup, 0); + object_address_set (value_raw_address (array)); + + if (value_optimized_out (array) + || (VALUE_LVAL (array) != not_lval + && VALUE_LVAL (array) != lval_memory + && VALUE_LVAL (array) != lval_internalvar_component + && VALUE_LVAL (array) != lval_internalvar)) + error (_("value being subranged must be in memory")); + type = check_typedef (value_type (array)); + f_object_address_data_valid_or_error (type); + + copied_types = create_copied_types_hash (NULL); + type = copy_type_recursive (type, copied_types); + htab_delete (copied_types); + + if (nargs != calc_f77_array_dims (type)) + error (_("Wrong number of subscripts")); + + if (TYPE_DATA_LOCATION_IS_ADDR (type)) + { + value_byte_address = (TYPE_DATA_LOCATION_ADDR (type) + + value_offset (array)); + TYPE_DATA_LOCATION_IS_ADDR (type) = 0; + TYPE_DATA_LOCATION_DWARF_BLOCK (type) = NULL; + } else - low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); + { + gdb_assert (TYPE_DATA_LOCATION_DWARF_BLOCK (type) == NULL); + value_byte_address = value_address (array); + } + + new_array_type = type; + + subscript_array = alloca (sizeof (*subscript_array) * nargs); + + gdb_assert (nargs > 0); + + /* Now that we know we have a legal array subscript expression + let us actually find out where this element exists in the array. */ + + /* Take array indices left to right. */ + for (i = 0; i < nargs; i++) + { + struct subscript_index *index = &subscript_array[i]; + + if (exp->elts[*pos].opcode == OP_F90_RANGE) + { + int pc = (*pos) + 1; + struct subscript_range *range; + + index->kind = SUBSCRIPT_RANGE; + range = &index->range; + + *pos += 3; + range->f90_range_type = longest_to_int (exp->elts[pc].longconst); + + if (range->f90_range_type == HIGH_BOUND_DEFAULT + || range->f90_range_type == NONE_BOUND_DEFAULT) + range->low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, + pos, noside)); + + if (range->f90_range_type == LOW_BOUND_DEFAULT + || range->f90_range_type == NONE_BOUND_DEFAULT) + range->high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, + pos, noside)); + } + else + { + struct value *val; + + index->kind = SUBSCRIPT_NUMBER; - if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT) - high_bound = TYPE_HIGH_BOUND (range); + /* Evaluate each subscript; it must be a legal integer in F77. */ + val = evaluate_subexp_with_coercion (exp, pos, noside); + index->number = value_as_long (val); + } + } + + /* Internal type of array is arranged right to left. */ + for (i = nargs - 1; i >= 0; i--) + { + struct subscript_index *index = &subscript_array[i]; + struct type *range_type = TYPE_INDEX_TYPE (type); + + switch (index->kind) + { + case SUBSCRIPT_RANGE: + { + struct subscript_range *range = &index->range; + CORE_ADDR byte_offset; + + if (range->f90_range_type == LOW_BOUND_DEFAULT + || range->f90_range_type == BOTH_BOUND_DEFAULT) + range->low_bound = TYPE_LOW_BOUND (range_type); + + if (range->f90_range_type == HIGH_BOUND_DEFAULT + || range->f90_range_type == BOTH_BOUND_DEFAULT) + range->high_bound = TYPE_HIGH_BOUND (range_type); + + if (range->low_bound < TYPE_LOW_BOUND (range_type) + || (!TYPE_HIGH_BOUND_UNDEFINED (range_type) + && range->high_bound > TYPE_HIGH_BOUND (range_type))) + error (_("slice out of range")); + + byte_offset = ((range->low_bound - TYPE_LOW_BOUND (range_type)) + * TYPE_ARRAY_BYTE_STRIDE_VALUE (type)); + TYPE_LOW_BOUND (range_type) = range->low_bound; + TYPE_HIGH_BOUND (range_type) = range->high_bound; + if (range->f90_range_type == LOW_BOUND_DEFAULT + || range->f90_range_type == NONE_BOUND_DEFAULT) + TYPE_HIGH_BOUND_UNDEFINED (range_type) = 0; + + typep = &TYPE_TARGET_TYPE (type); + value_byte_offset += byte_offset; + type = TYPE_TARGET_TYPE (type); + } + break; + + case SUBSCRIPT_NUMBER: + { + CORE_ADDR byte_offset; + + if (index->number < TYPE_LOW_BOUND (range_type) + || (!TYPE_HIGH_BOUND_UNDEFINED (range_type) + && index->number > TYPE_HIGH_BOUND (range_type))) + error (_("no such vector element")); + + byte_offset = ((index->number - TYPE_LOW_BOUND (range_type)) + * TYPE_ARRAY_BYTE_STRIDE_VALUE (type)); + + type = TYPE_TARGET_TYPE (type); + *typep = type; + value_byte_offset += byte_offset; + } + break; + } + } + + type_last_target = type; + type_array = alloca (sizeof (*type_array) * nargs); + i = 0; + for (type = new_array_type; type != type_last_target; + type = TYPE_TARGET_TYPE (type)) + type_array[i++] = type; + while (i > 0) + { + struct type *type = type_array[--i]; + + /* Force TYPE_LENGTH (type) recalculation. */ + TYPE_TARGET_STUB (type) = 1; + check_typedef (type); + } + + saved_array = array; + array = allocate_value_lazy (new_array_type); + VALUE_LVAL (array) = VALUE_LVAL (saved_array); + if (VALUE_LVAL (saved_array) == lval_internalvar_component) + VALUE_LVAL (array) = lval_internalvar; else - high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); + VALUE_LVAL (array) = VALUE_LVAL (saved_array); + VALUE_FRAME_ID (array) = VALUE_FRAME_ID (saved_array); + if (VALUE_LVAL (array) != lval_internalvar) + set_value_address (array, value_byte_address + value_byte_offset); - return value_slice (array, low_bound, high_bound - low_bound + 1); + if (!value_lazy (saved_array)) + { + allocate_value_contents (array); + set_value_lazy (array, 0); + + memcpy (value_contents_writeable (array), + value_contents (saved_array) + value_byte_offset, + TYPE_LENGTH (new_array_type)); + } + + do_cleanups (old_chain); + return array; } @@ -790,6 +981,7 @@ evaluate_subexp_standard (struct type *e int save_pos1; struct symbol *function = NULL; char *function_name = NULL; + struct cleanup *old_chain; pc = (*pos)++; op = exp->elts[pc].opcode; @@ -1862,6 +2054,8 @@ evaluate_subexp_standard (struct type *e /* First determine the type code we are dealing with. */ arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); + old_chain = make_cleanup (null_cleanup, 0); + object_address_set (value_raw_address (arg1)); type = check_typedef (value_type (arg1)); code = TYPE_CODE (type); @@ -1882,23 +2076,13 @@ evaluate_subexp_standard (struct type *e code = TYPE_CODE (type); } } + do_cleanups (old_chain); switch (code) { case TYPE_CODE_ARRAY: - if (exp->elts[*pos].opcode == OP_F90_RANGE) - return value_f90_subarray (arg1, exp, pos, noside); - else - goto multi_f77_subscript; - case TYPE_CODE_STRING: - if (exp->elts[*pos].opcode == OP_F90_RANGE) - return value_f90_subarray (arg1, exp, pos, noside); - else - { - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); - return value_subscript (arg1, value_as_long (arg2)); - } + return value_f90_subarray (arg1, exp, pos, nargs, noside); case TYPE_CODE_PTR: case TYPE_CODE_FUNC: @@ -2337,49 +2521,6 @@ evaluate_subexp_standard (struct type *e } return (arg1); - multi_f77_subscript: - { - LONGEST subscript_array[MAX_FORTRAN_DIMS]; - int ndimensions = 1, i; - struct value *array = arg1; - - if (nargs > MAX_FORTRAN_DIMS) - error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS); - - ndimensions = calc_f77_array_dims (type); - - if (nargs != ndimensions) - error (_("Wrong number of subscripts")); - - gdb_assert (nargs > 0); - - /* Now that we know we have a legal array subscript expression - let us actually find out where this element exists in the array. */ - - /* Take array indices left to right. */ - for (i = 0; i < nargs; i++) - { - /* Evaluate each subscript; it must be a legal integer in F77. */ - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); - - /* Fill in the subscript array. */ - - subscript_array[i] = value_as_long (arg2); - } - - /* Internal type of array is arranged right to left. */ - for (i = nargs; i > 0; i--) - { - struct type *array_type = check_typedef (value_type (array)); - LONGEST index = subscript_array[i - 1]; - - lower = f77_get_lowerbound (array_type); - array = value_subscripted_rvalue (array, index, lower); - } - - return array; - } - case BINOP_LOGICAL_AND: arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); if (noside == EVAL_SKIP) @@ -2611,15 +2752,23 @@ evaluate_subexp_standard (struct type *e if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type)); arg1 = evaluate_subexp (expect_type, exp, pos, noside); + old_chain = make_cleanup (null_cleanup, 0); + object_address_set (value_raw_address (arg1)); type = check_typedef (value_type (arg1)); if (TYPE_CODE (type) == TYPE_CODE_METHODPTR || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR) error (_("Attempt to dereference pointer " "to member without an object")); if (noside == EVAL_SKIP) - goto nosideret; + { + do_cleanups (old_chain); + goto nosideret; + } if (unop_user_defined_p (op, arg1)) - return value_x_unop (arg1, op, noside); + { + do_cleanups (old_chain); + return value_x_unop (arg1, op, noside); + } else if (noside == EVAL_AVOID_SIDE_EFFECTS) { type = check_typedef (value_type (arg1)); @@ -2628,12 +2777,18 @@ evaluate_subexp_standard (struct type *e /* In C you can dereference an array to get the 1st elt. */ || TYPE_CODE (type) == TYPE_CODE_ARRAY ) - return value_zero (TYPE_TARGET_TYPE (type), - lval_memory); + { + do_cleanups (old_chain); + return value_zero (TYPE_TARGET_TYPE (type), + lval_memory); + } else if (TYPE_CODE (type) == TYPE_CODE_INT) - /* GDB allows dereferencing an int. */ - return value_zero (builtin_type (exp->gdbarch)->builtin_int, - lval_memory); + { + do_cleanups (old_chain); + /* GDB allows dereferencing an int. */ + return value_zero (builtin_type (exp->gdbarch)->builtin_int, + lval_memory); + } else error (_("Attempt to take contents of a non-pointer value.")); } @@ -2643,9 +2798,14 @@ evaluate_subexp_standard (struct type *e do. "long long" variables are rare enough that BUILTIN_TYPE_LONGEST would seem to be a mistake. */ if (TYPE_CODE (type) == TYPE_CODE_INT) - return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int, - (CORE_ADDR) value_as_address (arg1)); - return value_ind (arg1); + { + do_cleanups (old_chain); + return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int, + (CORE_ADDR) value_as_address (arg1)); + } + arg1 = value_ind (arg1); + do_cleanups (old_chain); + return arg1; case UNOP_ADDR: /* C++: check for and handle pointer to members. */ @@ -2991,7 +3151,7 @@ evaluate_subexp_with_coercion (struct ex { enum exp_opcode op; int pc; - struct value *val; + struct value *val = NULL; struct symbol *var; struct type *type; @@ -3002,13 +3162,18 @@ evaluate_subexp_with_coercion (struct ex { case OP_VAR_VALUE: var = exp->elts[pc + 2].symbol; + /* address_of_variable will call object_address_set for check_typedef. + Call it only if required as it can error-out on VAR in register. */ + if (TYPE_DYNAMIC (SYMBOL_TYPE (var))) + val = address_of_variable (var, exp->elts[pc + 1].block); type = check_typedef (SYMBOL_TYPE (var)); if (TYPE_CODE (type) == TYPE_CODE_ARRAY && !TYPE_VECTOR (type) && CAST_IS_CONVERSION (exp->language_defn)) { (*pos) += 4; - val = address_of_variable (var, exp->elts[pc + 1].block); + if (!val) + val = address_of_variable (var, exp->elts[pc + 1].block); return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), val); } @@ -3060,9 +3225,13 @@ evaluate_subexp_for_sizeof (struct expre case OP_VAR_VALUE: (*pos) += 4; - type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol)); - return - value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); + /* We do not need to call read_var_value but the object evaluation may + need to have executed object_address_set which needs valid + SYMBOL_VALUE_ADDRESS of the symbol. Still VALUE returned by + read_var_value we left as lazy. */ + type = value_type (read_var_value (exp->elts[pc + 2].symbol, + deprecated_safe_get_selected_frame ())); + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); default: val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); @@ -3093,18 +3262,25 @@ parse_and_eval_type (char *p, int length int calc_f77_array_dims (struct type *array_type) { - int ndimen = 1; - struct type *tmp_type; + switch (TYPE_CODE (array_type)) + { + case TYPE_CODE_STRING: + return 1; - if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY)) - error (_("Can't get dimensions for a non-array type")); + case TYPE_CODE_ARRAY: + { + int ndimen = 1; - tmp_type = array_type; + while ((array_type = TYPE_TARGET_TYPE (array_type))) + { + if (TYPE_CODE (array_type) == TYPE_CODE_ARRAY) + ++ndimen; + } + return ndimen; + } - while ((tmp_type = TYPE_TARGET_TYPE (tmp_type))) - { - if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY) - ++ndimen; + default: + error (_("Can't get dimensions for a non-array/non-string type")); } - return ndimen; + } Index: gdb-7.2.90.20110525/gdb/f-exp.y =================================================================== --- gdb-7.2.90.20110525.orig/gdb/f-exp.y 2011-03-18 14:51:41.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/f-exp.y 2011-05-25 17:05:21.000000000 +0200 @@ -293,7 +293,9 @@ arglist : subrange { arglist_len = 1; } ; -arglist : arglist ',' exp %prec ABOVE_COMMA +arglist : arglist ',' exp %prec ABOVE_COMMA + { arglist_len++; } + | arglist ',' subrange %prec ABOVE_COMMA { arglist_len++; } ; Index: gdb-7.2.90.20110525/gdb/f-lang.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/f-lang.h 2011-01-07 20:36:16.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/f-lang.h 2011-05-25 17:05:21.000000000 +0200 @@ -28,6 +28,10 @@ extern void f_error (char *); /* Defined extern void f_print_type (struct type *, const char *, struct ui_file *, int, int); +extern const char *f_object_address_data_valid_print_to_stream + (struct type *type, struct ui_file *stream); +extern void f_object_address_data_valid_or_error (struct type *type); + extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, struct ui_file *, int, const struct value *, Index: gdb-7.2.90.20110525/gdb/f-typeprint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/f-typeprint.c 2011-01-07 20:36:16.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/f-typeprint.c 2011-05-25 17:05:21.000000000 +0200 @@ -32,7 +32,7 @@ #include "gdbcore.h" #include "target.h" #include "f-lang.h" - +#include "dwarf2loc.h" #include "gdb_string.h" #include @@ -49,6 +49,34 @@ void f_type_print_varspec_prefix (struct void f_type_print_base (struct type *, struct ui_file *, int, int); +const char * +f_object_address_data_valid_print_to_stream (struct type *type, + struct ui_file *stream) +{ + const char *msg; + + msg = object_address_data_not_valid (type); + if (msg != NULL) + { + /* Assuming the content printed to STREAM should not be localized. */ + fprintf_filtered (stream, "<%s>", msg); + } + + return msg; +} + +void +f_object_address_data_valid_or_error (struct type *type) +{ + const char *msg; + + msg = object_address_data_not_valid (type); + if (msg != NULL) + { + error (_("Cannot access it because the %s."), _(msg)); + } +} + /* LEVEL is the depth to indent lines by. */ void @@ -58,6 +86,9 @@ f_print_type (struct type *type, const c enum type_code code; int demangled_args; + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL) + return; + f_type_print_base (type, stream, show, level); code = TYPE_CODE (type); if ((varstring != NULL && *varstring != '\0') @@ -165,6 +196,9 @@ f_type_print_varspec_suffix (struct type QUIT; + if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) + CHECK_TYPEDEF (type); + switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: Index: gdb-7.2.90.20110525/gdb/f-valprint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/f-valprint.c 2011-02-07 18:49:32.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/f-valprint.c 2011-05-25 17:05:21.000000000 +0200 @@ -54,15 +54,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIM /* The following macro gives us the size of the nth dimension, Where n is 1 based. */ -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1]) +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1]) -/* The following gives us the offset for row n where n is 1-based. */ +/* The following gives us the element size for row n where n is 1-based. */ -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0]) +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0]) int f77_get_lowerbound (struct type *type) { + f_object_address_data_valid_or_error (type); + if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type)) error (_("Lower bound may not be '*' in F77")); @@ -72,14 +74,17 @@ f77_get_lowerbound (struct type *type) int f77_get_upperbound (struct type *type) { + f_object_address_data_valid_or_error (type); + if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) { - /* We have an assumed size array on our hands. Assume that - upper_bound == lower_bound so that we show at least 1 element. - If the user wants to see more elements, let him manually ask for 'em - and we'll subscript the array and show him. */ + /* We have an assumed size array on our hands. As type_length_get + already assumes a length zero of arrays with underfined bounds VALADDR + passed to the Fortran functions does not contained the real inferior + memory content. User should request printing of specific array + elements instead. */ - return f77_get_lowerbound (type); + return f77_get_lowerbound (type) - 1; } return TYPE_ARRAY_UPPER_BOUND_VALUE (type); @@ -135,24 +140,29 @@ f77_create_arrayprint_offset_tbl (struct upper = f77_get_upperbound (tmp_type); lower = f77_get_lowerbound (tmp_type); - F77_DIM_SIZE (ndimen) = upper - lower + 1; + F77_DIM_COUNT (ndimen) = upper - lower + 1; + + F77_DIM_BYTE_STRIDE (ndimen) = + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type); tmp_type = TYPE_TARGET_TYPE (tmp_type); ndimen++; } - /* Now we multiply eltlen by all the offsets, so that later we + /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we can print out array elements correctly. Up till now we - know an offset to apply to get the item but we also + know an eltlen to apply to get the item but we also have to know how much to add to get to the next item. */ ndimen--; eltlen = TYPE_LENGTH (tmp_type); - F77_DIM_OFFSET (ndimen) = eltlen; + if (F77_DIM_BYTE_STRIDE (ndimen) == 0) + F77_DIM_BYTE_STRIDE (ndimen) = eltlen; while (--ndimen > 0) { - eltlen *= F77_DIM_SIZE (ndimen + 1); - F77_DIM_OFFSET (ndimen) = eltlen; + eltlen *= F77_DIM_COUNT (ndimen + 1); + if (F77_DIM_BYTE_STRIDE (ndimen) == 0) + F77_DIM_BYTE_STRIDE (ndimen) = eltlen; } } @@ -174,37 +184,35 @@ f77_print_array_1 (int nss, int ndimensi if (nss != ndimensions) { - for (i = 0; - (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); - i++) + for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++) { fprintf_filtered (stream, "( "); f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type), valaddr, - embedded_offset + i * F77_DIM_OFFSET (nss), + embedded_offset + i * F77_DIM_BYTE_STRIDE (nss), address, stream, recurse, val, options, elts); fprintf_filtered (stream, ") "); } - if (*elts >= options->print_max && i < F77_DIM_SIZE (nss)) + if (*elts >= options->print_max && i < F77_DIM_COUNT (nss)) fprintf_filtered (stream, "..."); } else { - for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max; + for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max; i++, (*elts)++) { val_print (TYPE_TARGET_TYPE (type), valaddr, - embedded_offset + i * F77_DIM_OFFSET (ndimensions), + embedded_offset + i * F77_DIM_BYTE_STRIDE (ndimensions), address, stream, recurse, val, options, current_language); - if (i != (F77_DIM_SIZE (nss) - 1)) + if (i != (F77_DIM_COUNT (nss) - 1)) fprintf_filtered (stream, ", "); if ((*elts == options->print_max - 1) - && (i != (F77_DIM_SIZE (nss) - 1))) + && (i != (F77_DIM_COUNT (nss) - 1))) fprintf_filtered (stream, "..."); } } @@ -260,6 +268,9 @@ f_val_print (struct type *type, const gd CORE_ADDR addr; int index; + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL) + return 0; + CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { Index: gdb-7.2.90.20110525/gdb/findvar.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/findvar.c 2011-03-18 19:42:41.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/findvar.c 2011-05-25 17:05:21.000000000 +0200 @@ -35,6 +35,7 @@ #include "user-regs.h" #include "block.h" #include "objfiles.h" +#include "dwarf2loc.h" /* Basic byte-swapping routines. All 'extract' functions return a host-format integer from a target-format integer at ADDR which is @@ -408,8 +409,11 @@ symbol_read_needs_frame (struct symbol * /* Given a struct symbol for a variable, and a stack frame id, read the value of the variable - and return a (pointer to a) struct value containing the value. - If the variable cannot be found, return a zero pointer. */ + and return a (pointer to a) struct value containing the value. + If the variable cannot be found, return a zero pointer. + We have to first find the address of the variable before allocating struct + value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly + used by its type. */ struct value * read_var_value (struct symbol *var, struct frame_info *frame) @@ -417,16 +421,6 @@ read_var_value (struct symbol *var, stru struct value *v; struct type *type = SYMBOL_TYPE (var); CORE_ADDR addr; - int len; - - /* Call check_typedef on our type to make sure that, if TYPE is - a TYPE_CODE_TYPEDEF, its length is set to the length of the target type - instead of zero. However, we do not replace the typedef type by the - target type, because we want to keep the typedef in order to be able to - set the returned value type description correctly. */ - check_typedef (type); - - len = TYPE_LENGTH (type); if (symbol_read_needs_frame (var)) gdb_assert (frame); @@ -436,7 +430,7 @@ read_var_value (struct symbol *var, stru case LOC_CONST: /* Put the constant back in target format. */ v = allocate_value (type); - store_signed_integer (value_contents_raw (v), len, + store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type), gdbarch_byte_order (get_type_arch (type)), (LONGEST) SYMBOL_VALUE (var)); VALUE_LVAL (v) = not_lval; @@ -461,12 +455,12 @@ read_var_value (struct symbol *var, stru case LOC_CONST_BYTES: v = allocate_value (type); - memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len); + memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), + TYPE_LENGTH (type)); VALUE_LVAL (v) = not_lval; return v; case LOC_STATIC: - v = allocate_value_lazy (type); if (overlay_debugging) addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var), SYMBOL_OBJ_SECTION (var)); @@ -479,7 +473,6 @@ read_var_value (struct symbol *var, stru if (!addr) return 0; addr += SYMBOL_VALUE (var); - v = allocate_value_lazy (type); break; case LOC_REF_ARG: @@ -493,14 +486,12 @@ read_var_value (struct symbol *var, stru argref += SYMBOL_VALUE (var); ref = value_at (lookup_pointer_type (type), argref); addr = value_as_address (ref); - v = allocate_value_lazy (type); break; } case LOC_LOCAL: addr = get_frame_locals_address (frame); addr += SYMBOL_VALUE (var); - v = allocate_value_lazy (type); break; case LOC_TYPEDEF: @@ -508,7 +499,6 @@ read_var_value (struct symbol *var, stru break; case LOC_BLOCK: - v = allocate_value_lazy (type); if (overlay_debugging) addr = symbol_overlayed_address (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)); @@ -533,7 +523,6 @@ read_var_value (struct symbol *var, stru error (_("Value of register variable not available.")); addr = value_as_address (regval); - v = allocate_value_lazy (type); } else { @@ -572,7 +561,6 @@ read_var_value (struct symbol *var, stru if (obj_section && (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0) addr = target_translate_tls_address (obj_section->objfile, addr); - v = allocate_value_lazy (type); } break; @@ -587,6 +575,10 @@ read_var_value (struct symbol *var, stru break; } + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for + DW_OP_PUSH_OBJECT_ADDRESS. */ + object_address_set (addr); + v = allocate_value_lazy (type); VALUE_LVAL (v) = lval_memory; set_value_address (v, addr); return v; @@ -626,11 +618,12 @@ struct value * value_from_register (struct type *type, int regnum, struct frame_info *frame) { struct gdbarch *gdbarch = get_frame_arch (frame); - struct type *type1 = check_typedef (type); struct value *v; int optim, unavail, ok; - if (gdbarch_convert_register_p (gdbarch, regnum, type1)) + type = check_typedef (type); + + if (gdbarch_convert_register_p (gdbarch, regnum, type)) { /* The ISA/ABI need to something weird when obtaining the specified value from this register. It might need to @@ -643,7 +636,7 @@ value_from_register (struct type *type, VALUE_LVAL (v) = lval_register; VALUE_FRAME_ID (v) = get_frame_id (frame); VALUE_REGNUM (v) = regnum; - ok = gdbarch_register_to_value (gdbarch, frame, regnum, type1, + ok = gdbarch_register_to_value (gdbarch, frame, regnum, type, value_contents_raw (v), &optim, &unavail); } Index: gdb-7.2.90.20110525/gdb/gdbinit.in =================================================================== --- gdb-7.2.90.20110525.orig/gdb/gdbinit.in 2009-10-05 15:46:52.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/gdbinit.in 2011-05-25 17:05:21.000000000 +0200 @@ -1,5 +1,15 @@ echo Setting up the environment for debugging gdb.\n +# Set up the Python library and "require" command. +python +from os.path import abspath +gdb.datadir = abspath ('@srcdir@/python/lib') +gdb.pythonlibdir = gdb.datadir +gdb.__path__ = [gdb.datadir + '/gdb'] +sys.path.insert(0, gdb.datadir) +end +source @srcdir@/python/lib/gdb/__init__.py + set complaints 1 b internal_error Index: gdb-7.2.90.20110525/gdb/gdbtypes.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/gdbtypes.c 2011-03-28 22:21:03.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/gdbtypes.c 2011-05-25 17:05:21.000000000 +0200 @@ -39,6 +39,9 @@ #include "cp-abi.h" #include "gdb_assert.h" #include "hashtab.h" +#include "observer.h" +#include "dwarf2expr.h" +#include "dwarf2loc.h" /* Initialize BADNESS constants. */ @@ -144,7 +147,16 @@ static void print_bit_vector (B_TYPE *, static void print_arg_types (struct field *, int, int); static void dump_fn_fieldlists (struct type *, int); static void print_cplus_stuff (struct type *, int); +static LONGEST type_length_get (struct type *type, struct type *target_type, + int full_span); +#if 0 +/* The hash table holding all discardable `struct type *' references. */ +static htab_t type_discardable_table; + +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE. */ +static int type_discardable_age_current; +#endif /* Allocate a new OBJFILE-associated type structure and fill it with some defaults. Space for the type structure is allocated @@ -175,6 +187,43 @@ alloc_type (struct objfile *objfile) return type; } +#if 0 +/* Declare TYPE as discardable on next garbage collection by free_all_types. + You must call type_mark_used during each free_all_types to protect TYPE from + being deallocated. */ + +static void +set_type_as_discardable (struct type *type) +{ + void **slot; + + gdb_assert (!TYPE_DISCARDABLE (type)); + + TYPE_DISCARDABLE (type) = 1; + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current; + + slot = htab_find_slot (type_discardable_table, type, INSERT); + gdb_assert (!*slot); + *slot = type; +} +#endif + +/* Allocate a new type like alloc_type but preserve for it the discardability + state of PARENT_TYPE. */ + +static struct type * +alloc_type_as_parent (struct type *parent_type) +{ + struct type *new_type = alloc_type_copy (parent_type); + +#if 0 + if (TYPE_DISCARDABLE (parent_type)) + set_type_as_discardable (new_type); +#endif + + return new_type; +} + /* Allocate a new GDBARCH-associated type structure and fill it with some defaults. Space for the type structure is allocated on the heap. */ @@ -300,7 +349,7 @@ make_pointer_type (struct type *type, st if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - ntype = alloc_type_copy (type); + ntype = alloc_type_as_parent (type); if (typeptr) *typeptr = ntype; } @@ -377,7 +426,7 @@ make_reference_type (struct type *type, if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - ntype = alloc_type_copy (type); + ntype = alloc_type_as_parent (type); if (typeptr) *typeptr = ntype; } @@ -748,6 +797,7 @@ create_range_type (struct type *result_t TYPE_ZALLOC (result_type, sizeof (struct range_bounds)); TYPE_LOW_BOUND (result_type) = low_bound; TYPE_HIGH_BOUND (result_type) = high_bound; + TYPE_BYTE_STRIDE (result_type) = 0; if (low_bound >= 0) TYPE_UNSIGNED (result_type) = 1; @@ -891,26 +941,31 @@ create_array_type (struct type *result_t TYPE_CODE (result_type) = TYPE_CODE_ARRAY; TYPE_TARGET_TYPE (result_type) = element_type; - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) - low_bound = high_bound = 0; - CHECK_TYPEDEF (element_type); - /* Be careful when setting the array length. Ada arrays can be - empty arrays with the high_bound being smaller than the low_bound. - In such cases, the array length should be zero. */ - if (high_bound < low_bound) - TYPE_LENGTH (result_type) = 0; - else - TYPE_LENGTH (result_type) = - TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); TYPE_NFIELDS (result_type) = 1; TYPE_FIELDS (result_type) = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)); TYPE_INDEX_TYPE (result_type) = range_type; TYPE_VPTR_FIELDNO (result_type) = -1; - /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */ + /* DWARF blocks may depend on runtime information like + DW_OP_PUSH_OBJECT_ADDRESS not being available during the + CREATE_ARRAY_TYPE time. */ + if (TYPE_RANGE_DATA (range_type)->low.kind != RANGE_BOUND_KIND_CONSTANT + || TYPE_RANGE_DATA (range_type)->high.kind != RANGE_BOUND_KIND_CONSTANT + || TYPE_DYNAMIC (element_type)) + TYPE_LENGTH (result_type) = 0; + else + { + CHECK_TYPEDEF (element_type); + TYPE_LENGTH (result_type) = type_length_get (result_type, element_type, + 0); + } if (TYPE_LENGTH (result_type) == 0) - TYPE_TARGET_STUB (result_type) = 1; + { + /* The real size will be computed for specific instances by + CHECK_TYPEDEF. */ + TYPE_TARGET_STUB (result_type) = 1; + } return result_type; } @@ -1413,6 +1468,105 @@ stub_noname_complaint (void) complaint (&symfile_complaints, _("stub type has NULL name")); } +/* Calculate the memory length of array TYPE. + + TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as + a performance hint. Feel free to pass NULL. Set FULL_SPAN to return the + size incl. the possible padding of the last element - it may differ from the + cleared FULL_SPAN return value (the expected SIZEOF) for non-zero + TYPE_BYTE_STRIDE values. */ + +static LONGEST +type_length_get (struct type *type, struct type *target_type, int full_span) +{ + struct type *range_type; + LONGEST byte_stride = 0; /* `= 0' for a false GCC warning. */ + LONGEST count, element_size, retval; + + if (TYPE_CODE (type) != TYPE_CODE_ARRAY + && TYPE_CODE (type) != TYPE_CODE_STRING) + return TYPE_LENGTH (type); + + /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated) + Fortran arrays. The allocated data will never be used so they can be + zero-length. */ + if (object_address_data_not_valid (type)) + return 0; + + range_type = TYPE_INDEX_TYPE (type); + if (TYPE_LOW_BOUND_UNDEFINED (range_type) + || TYPE_HIGH_BOUND_UNDEFINED (range_type)) + return 0; + count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1; + /* It may happen for wrong DWARF annotations returning garbage data. */ + if (count < 0) + warning (_("Range for type %s has invalid bounds %s..%s"), + TYPE_NAME (type), plongest (TYPE_LOW_BOUND (range_type)), + plongest (TYPE_HIGH_BOUND (range_type))); + /* The code below does not handle count == 0 right. */ + if (count <= 0) + return 0; + if (full_span || count > 1) + { + /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to + force FULL_SPAN to 1. */ + byte_stride = TYPE_BYTE_STRIDE (range_type); + if (byte_stride == 0) + { + if (target_type == NULL) + target_type = check_typedef (TYPE_TARGET_TYPE (type)); + byte_stride = type_length_get (target_type, NULL, 1); + } + } + + /* For now, we conservatively take the array length to be 0 if its length + exceeds UINT_MAX. The code below assumes that for x < 0, + (ULONGEST) x == -x + ULONGEST_MAX + 1, which is technically not guaranteed + by C, but is usually true (because it would be true if x were unsigned + with its high-order bit on). It uses the fact that high_bound-low_bound is + always representable in ULONGEST and that if high_bound-low_bound+1 + overflows, it overflows to 0. We must change these tests if we decide to + increase the representation of TYPE_LENGTH from unsigned int to ULONGEST. + */ + + if (full_span) + { + retval = count * byte_stride; + if (count == 0 || retval / count != byte_stride || retval > UINT_MAX) + retval = 0; + return retval; + } + if (target_type == NULL) + target_type = check_typedef (TYPE_TARGET_TYPE (type)); + element_size = type_length_get (target_type, NULL, 1); + retval = (count - 1) * byte_stride + element_size; + if (retval < element_size + || (byte_stride != 0 + && (retval - element_size) / byte_stride != count - 1) + || retval > UINT_MAX) + retval = 0; + return retval; +} + +/* Prepare TYPE after being read in by the backend. Currently this function + only propagates the TYPE_DYNAMIC flag. */ + +void +finalize_type (struct type *type) +{ + int i; + + for (i = 0; i < TYPE_NFIELDS (type); ++i) + if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i))) + break; + + /* FIXME: cplus_stuff is ignored here. */ + if (i < TYPE_NFIELDS (type) + || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type))) + || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type)))) + TYPE_DYNAMIC (type) = 1; +} + /* Find the real type of TYPE. This function returns the real type, after removing all layers of typedefs, and completing opaque or stub types. Completion changes the TYPE argument, but stripping of @@ -1575,52 +1729,37 @@ check_typedef (struct type *type) } } - if (TYPE_TARGET_STUB (type)) + /* copy_type_recursive automatically makes the resulting type containing only + constant values expected by the callers of this function. */ + if (TYPE_DYNAMIC (type)) + { + htab_t copied_types; + + copied_types = create_copied_types_hash (NULL); + type = copy_type_recursive (type, copied_types); + htab_delete (copied_types); + + gdb_assert (TYPE_DYNAMIC (type) == 0); + /* Force TYPE_LENGTH (type) recalculation. */ + TYPE_DYNAMIC (type) = 1; + } + + if (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type)) { - struct type *range_type; struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); + if (TYPE_DYNAMIC (type)) + TYPE_TARGET_TYPE (type) = target_type; if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) { /* Nothing we can do. */ } else if (TYPE_CODE (type) == TYPE_CODE_ARRAY - && TYPE_NFIELDS (type) == 1 - && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type)) - == TYPE_CODE_RANGE)) + || TYPE_CODE (type) == TYPE_CODE_STRING) { /* Now recompute the length of the array type, based on its - number of elements and the target type's length. - Watch out for Ada null Ada arrays where the high bound - is smaller than the low bound. */ - const LONGEST low_bound = TYPE_LOW_BOUND (range_type); - const LONGEST high_bound = TYPE_HIGH_BOUND (range_type); - ULONGEST len; - - if (high_bound < low_bound) - len = 0; - else - { - /* For now, we conservatively take the array length to be 0 - if its length exceeds UINT_MAX. The code below assumes - that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1, - which is technically not guaranteed by C, but is usually true - (because it would be true if x were unsigned with its - high-order bit on). It uses the fact that - high_bound-low_bound is always representable in - ULONGEST and that if high_bound-low_bound+1 overflows, - it overflows to 0. We must change these tests if we - decide to increase the representation of TYPE_LENGTH - from unsigned int to ULONGEST. */ - ULONGEST ulow = low_bound, uhigh = high_bound; - ULONGEST tlen = TYPE_LENGTH (target_type); - - len = tlen * (uhigh - ulow + 1); - if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh - || len > UINT_MAX) - len = 0; - } - TYPE_LENGTH (type) = len; + number of elements and the target type's length. */ + TYPE_LENGTH (type) = type_length_get (type, target_type, 0); TYPE_TARGET_STUB (type) = 0; } else if (TYPE_CODE (type) == TYPE_CODE_RANGE) @@ -1628,6 +1767,7 @@ check_typedef (struct type *type) TYPE_LENGTH (type) = TYPE_LENGTH (target_type); TYPE_TARGET_STUB (type) = 0; } + TYPE_DYNAMIC (type) = 0; } type = make_qualified_type (type, instance_flags, NULL); @@ -3266,33 +3406,42 @@ type_pair_eq (const void *item_lhs, cons } /* Allocate the hash table used by copy_type_recursive to walk - types without duplicates. We use OBJFILE's obstack, because - OBJFILE is about to be deleted. */ + types without duplicates. */ htab_t create_copied_types_hash (struct objfile *objfile) { - return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, - NULL, &objfile->objfile_obstack, - hashtab_obstack_allocate, - dummy_obstack_deallocate); + if (objfile == NULL) + { + /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in + OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN. Table + element entries get allocated by xmalloc - so use xfree. */ + return htab_create (1, type_pair_hash, type_pair_eq, xfree); + } + else + { + /* Use OBJFILE's obstack, because OBJFILE is about to be deleted. Table + element entries get allocated by xmalloc - so use xfree. */ + return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, + xfree, &objfile->objfile_obstack, + hashtab_obstack_allocate, + dummy_obstack_deallocate); + } } -/* Recursively copy (deep copy) TYPE, if it is associated with - OBJFILE. Return a new type allocated using malloc, a saved type if - we have already visited TYPE (using COPIED_TYPES), or TYPE if it is - not associated with OBJFILE. */ +/* A helper for copy_type_recursive. This does all the work. OBJFILE is used + only for an assertion checking. */ -struct type * -copy_type_recursive (struct objfile *objfile, - struct type *type, - htab_t copied_types) +static struct type * +copy_type_recursive_1 (struct objfile *objfile, + struct type *type, + htab_t copied_types) { struct type_pair *stored, pair; void **slot; struct type *new_type; - if (! TYPE_OBJFILE_OWNED (type)) + if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type)) return type; /* This type shouldn't be pointing to any types in other objfiles; @@ -3307,9 +3456,10 @@ copy_type_recursive (struct objfile *obj new_type = alloc_type_arch (get_type_arch (type)); /* We must add the new type to the hash table immediately, in case - we encounter this type again during a recursive call below. */ - stored - = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair)); + we encounter this type again during a recursive call below. Memory could + be allocated from OBJFILE in the case we will be removing OBJFILE, this + optimization is missed and xfree is called for it from COPIED_TYPES. */ + stored = xmalloc (sizeof (*stored)); stored->old = type; stored->new = new_type; *slot = stored; @@ -3320,6 +3470,21 @@ copy_type_recursive (struct objfile *obj TYPE_OBJFILE_OWNED (new_type) = 0; TYPE_OWNER (new_type).gdbarch = get_type_arch (type); +#if 0 + /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we + need to initialize it again. And even if TYPE was already discardable + NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE. */ + TYPE_DISCARDABLE (new_type) = 0; + set_type_as_discardable (new_type); +#endif + + /* Pre-clear the fields processed by delete_main_type. If DWARF block + evaluations below call error we would leave an unfreeable TYPE. */ + TYPE_TARGET_TYPE (new_type) = NULL; + TYPE_VPTR_BASETYPE (new_type) = NULL; + TYPE_NFIELDS (new_type) = 0; + TYPE_FIELDS (new_type) = NULL; + if (TYPE_NAME (type)) TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type)); if (TYPE_TAG_NAME (type)) @@ -3328,12 +3493,48 @@ copy_type_recursive (struct objfile *obj TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); TYPE_LENGTH (new_type) = TYPE_LENGTH (type); + if (TYPE_ALLOCATED (new_type)) + { + gdb_assert (!TYPE_NOT_ALLOCATED (new_type)); + + if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type))) + TYPE_NOT_ALLOCATED (new_type) = 1; + TYPE_ALLOCATED (new_type) = NULL; + } + + if (TYPE_ASSOCIATED (new_type)) + { + gdb_assert (!TYPE_NOT_ASSOCIATED (new_type)); + + if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type))) + TYPE_NOT_ASSOCIATED (new_type) = 1; + TYPE_ASSOCIATED (new_type) = NULL; + } + + if (!TYPE_DATA_LOCATION_IS_ADDR (new_type) + && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type)) + { + if (TYPE_NOT_ALLOCATED (new_type) + || TYPE_NOT_ASSOCIATED (new_type)) + TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL; + else + { + TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1; + TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval + (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type)); + } + } + /* Copy the fields. */ if (TYPE_NFIELDS (type)) { int i, nfields; + /* TYPE_CODE_RANGE uses TYPE_RANGE_DATA of the union with TYPE_FIELDS. */ + gdb_assert (TYPE_CODE (type) != TYPE_CODE_RANGE); + nfields = TYPE_NFIELDS (type); + TYPE_NFIELDS (new_type) = nfields; TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field); for (i = 0; i < nfields; i++) { @@ -3342,8 +3543,8 @@ copy_type_recursive (struct objfile *obj TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i); if (TYPE_FIELD_TYPE (type, i)) TYPE_FIELD_TYPE (new_type, i) - = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i), - copied_types); + = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i), + copied_types); if (TYPE_FIELD_NAME (type, i)) TYPE_FIELD_NAME (new_type, i) = xstrdup (TYPE_FIELD_NAME (type, i)); @@ -3370,24 +3571,184 @@ copy_type_recursive (struct objfile *obj } } + /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were + possibly converted. */ + TYPE_DYNAMIC (new_type) = 0; + /* For range types, copy the bounds information. */ - if (TYPE_CODE (type) == TYPE_CODE_RANGE) + if (TYPE_CODE (new_type) == TYPE_CODE_RANGE) { TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds)); *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type); + + switch (TYPE_RANGE_DATA (new_type)->low.kind) + { + case RANGE_BOUND_KIND_CONSTANT: + break; + case RANGE_BOUND_KIND_DWARF_BLOCK: + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so + it is expected to be made constant by CHECK_TYPEDEF. + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE. + */ + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type) + || ! has_stack_frames ()) + { + /* We should set 1 for Fortran but how to find the language? */ + TYPE_LOW_BOUND (new_type) = 0; + TYPE_LOW_BOUND_UNDEFINED (new_type) = 1; + } + else + { + TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval + (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block); + if (TYPE_LOW_BOUND (new_type) >= 0) + TYPE_UNSIGNED (new_type) = 1; + } + TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT; + break; + case RANGE_BOUND_KIND_DWARF_LOCLIST: + { + CORE_ADDR addr; + + /* `struct dwarf2_loclist_baton' is too bound to its objfile so + it is expected to be made constant by CHECK_TYPEDEF. + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE. + */ + if (! TYPE_NOT_ALLOCATED (new_type) + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames () + && dwarf_loclist_baton_eval + (TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.loclist, + TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.type, &addr)) + { + TYPE_LOW_BOUND (new_type) = addr; + if (TYPE_LOW_BOUND (new_type) >= 0) + TYPE_UNSIGNED (new_type) = 1; + } + else + { + /* We should set 1 for Fortran but how to find the language? */ + TYPE_LOW_BOUND (new_type) = 0; + TYPE_LOW_BOUND_UNDEFINED (new_type) = 1; + } + TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT; + } + break; + } + + switch (TYPE_RANGE_DATA (new_type)->high.kind) + { + case RANGE_BOUND_KIND_CONSTANT: + break; + case RANGE_BOUND_KIND_DWARF_BLOCK: + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so + it is expected to be made constant by CHECK_TYPEDEF. + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE. + */ + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type) + || ! has_stack_frames ()) + { + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1; + TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1; + } + else + TYPE_HIGH_BOUND (new_type) = dwarf_locexpr_baton_eval + (TYPE_RANGE_DATA (new_type)->high.u.dwarf_block); + TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT; + break; + case RANGE_BOUND_KIND_DWARF_LOCLIST: + { + CORE_ADDR addr; + + /* `struct dwarf2_loclist_baton' is too bound to its objfile so + it is expected to be made constant by CHECK_TYPEDEF. + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE. + */ + if (! TYPE_NOT_ALLOCATED (new_type) + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames () + && dwarf_loclist_baton_eval + (TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.loclist, + TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.type, + &addr)) + TYPE_HIGH_BOUND (new_type) = addr; + else + { + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1; + TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1; + } + TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT; + } + break; + } + + switch (TYPE_RANGE_DATA (new_type)->byte_stride.kind) + { + case RANGE_BOUND_KIND_CONSTANT: + break; + case RANGE_BOUND_KIND_DWARF_BLOCK: + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so + it is expected to be made constant by CHECK_TYPEDEF. + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE. + */ + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type) + || ! has_stack_frames ()) + TYPE_BYTE_STRIDE (new_type) = 0; + else + TYPE_BYTE_STRIDE (new_type) = dwarf_locexpr_baton_eval + (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_block); + TYPE_RANGE_DATA (new_type)->byte_stride.kind + = RANGE_BOUND_KIND_CONSTANT; + break; + case RANGE_BOUND_KIND_DWARF_LOCLIST: + { + CORE_ADDR addr = 0; + + /* `struct dwarf2_loclist_baton' is too bound to its objfile so + it is expected to be made constant by CHECK_TYPEDEF. + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE. + */ + if (! TYPE_NOT_ALLOCATED (new_type) + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()) + dwarf_loclist_baton_eval + (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.loclist, + TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.type, + &addr); + TYPE_BYTE_STRIDE (new_type) = addr; + TYPE_RANGE_DATA (new_type)->byte_stride.kind + = RANGE_BOUND_KIND_CONSTANT; + } + break; + } + + /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound. */ + if (TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type)) + { + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) + + TYPE_HIGH_BOUND (new_type) - 1; + TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0; + } } /* Copy pointers to other types. */ if (TYPE_TARGET_TYPE (type)) TYPE_TARGET_TYPE (new_type) = - copy_type_recursive (objfile, - TYPE_TARGET_TYPE (type), - copied_types); + copy_type_recursive_1 (objfile, + TYPE_TARGET_TYPE (type), + copied_types); if (TYPE_VPTR_BASETYPE (type)) TYPE_VPTR_BASETYPE (new_type) = - copy_type_recursive (objfile, - TYPE_VPTR_BASETYPE (type), - copied_types); + copy_type_recursive_1 (objfile, + TYPE_VPTR_BASETYPE (type), + copied_types); + + if (TYPE_CODE (new_type) == TYPE_CODE_ARRAY) + { + struct type *new_index_type = TYPE_INDEX_TYPE (new_type); + + if (TYPE_BYTE_STRIDE (new_index_type) == 0) + TYPE_BYTE_STRIDE (new_index_type) + = TYPE_LENGTH (TYPE_TARGET_TYPE (new_type)); + } + /* Maybe copy the type_specific bits. NOTE drow/2005-12-09: We do not copy the C++-specific bits like @@ -3404,6 +3765,17 @@ copy_type_recursive (struct objfile *obj return new_type; } +/* Recursively copy (deep copy) TYPE. Return a new type allocated using + malloc, a saved type if we have already visited TYPE (using COPIED_TYPES), + or TYPE if it is not associated with OBJFILE. */ + +struct type * +copy_type_recursive (struct type *type, + htab_t copied_types) +{ + return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types); +} + /* Make a copy of the given TYPE, except that the pointer & reference types are not preserved. @@ -3426,6 +3798,201 @@ copy_type (const struct type *type) return new_type; } +#if 0 +/* Callback type for main_type_crawl. */ +typedef int (*main_type_crawl_iter) (struct type *type, void *data); + +/* Iterate all main_type structures reachable through any `struct type *' from + TYPE. ITER will be called only for one type of each main_type, use + TYPE_CHAIN traversal to find all the type instances. ITER is being called + for each main_type found. ITER returns non-zero if main_type_crawl should + depth-first enter the specific type. ITER must provide some detection for + reentering the same main_type as this function would otherwise endlessly + loop. */ + +static void +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data) +{ + struct type *type_iter; + int i; + + if (!type) + return; + + gdb_assert (TYPE_OBJFILE (type) == NULL); + + /* `struct cplus_struct_type' handling is unsupported by this function. */ + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT + && TYPE_CODE (type) != TYPE_CODE_UNION) + || !HAVE_CPLUS_STRUCT (type)); + + if (!(*iter) (type, data)) + return; + + /* Iterate all the type instances of this main_type. */ + type_iter = type; + do + { + gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type)); + + main_type_crawl (TYPE_POINTER_TYPE (type), iter, data); + main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data); + + type_iter = TYPE_CHAIN (type_iter); + } + while (type_iter != type); + + for (i = 0; i < TYPE_NFIELDS (type); i++) + main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data); + + main_type_crawl (TYPE_TARGET_TYPE (type), iter, data); + main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data); +} + +/* A helper for delete_type which deletes a main_type and the things to which + it refers. TYPE is a type whose main_type we wish to destroy. */ + +static void +delete_main_type (struct type *type) +{ + int i; + + gdb_assert (TYPE_DISCARDABLE (type)); + gdb_assert (TYPE_OBJFILE (type) == NULL); + + xfree (TYPE_NAME (type)); + xfree (TYPE_TAG_NAME (type)); + + for (i = 0; i < TYPE_NFIELDS (type); ++i) + { + xfree (TYPE_FIELD_NAME (type, i)); + + if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME) + xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i)); + } + xfree (TYPE_FIELDS (type)); + + gdb_assert (!HAVE_CPLUS_STRUCT (type)); + + xfree (TYPE_MAIN_TYPE (type)); +} + +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced + main_type. TYPE must be a reclaimable type - neither permanent nor objfile + associated. */ + +static void +delete_type_chain (struct type *type) +{ + struct type *type_iter, *type_iter_to_free; + + gdb_assert (TYPE_DISCARDABLE (type)); + gdb_assert (TYPE_OBJFILE (type) == NULL); + + delete_main_type (type); + + type_iter = type; + do + { + type_iter_to_free = type_iter; + type_iter = TYPE_CHAIN (type_iter); + xfree (type_iter_to_free); + } + while (type_iter != type); +} + +/* Hash function for type_discardable_table. */ + +static hashval_t +type_discardable_hash (const void *p) +{ + const struct type *type = p; + + return htab_hash_pointer (TYPE_MAIN_TYPE (type)); +} + +/* Equality function for type_discardable_table. */ + +static int +type_discardable_equal (const void *a, const void *b) +{ + const struct type *left = a; + const struct type *right = b; + + return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right); +} + +/* A helper for type_mark_used. */ + +static int +type_mark_used_crawl (struct type *type, void *unused) +{ + if (!TYPE_DISCARDABLE (type)) + return 0; + + if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current) + return 0; + + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current; + + /* Continue the traversal. */ + return 1; +} + +/* Mark TYPE and its connected types as used in this free_all_types pass. */ + +void +type_mark_used (struct type *type) +{ + if (type == NULL) + return; + + if (!TYPE_DISCARDABLE (type)) + return; + + main_type_crawl (type, type_mark_used_crawl, NULL); +} + +/* A traverse callback for type_discardable_table which removes any + type_discardable whose reference count is now zero (unused link). */ + +static int +type_discardable_remove (void **slot, void *unused) +{ + struct type *type = *slot; + + gdb_assert (TYPE_DISCARDABLE (type)); + + if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current) + { + delete_type_chain (type); + + htab_clear_slot (type_discardable_table, slot); + } + + return 1; +} + +/* Free all the reclaimable types that have been allocated and that have + currently zero reference counter. + + This function is called after each command, successful or not. Use this + cleanup only in the GDB idle state as GDB only marks those types used by + globally tracked objects (with no autovariable references tracking). */ + +void +free_all_types (void) +{ + /* Mark a new pass. As GDB checks all the entries were visited after each + pass there cannot be any stale entries already containing the changed + value. */ + type_discardable_age_current ^= 1; + + observer_notify_mark_used (); + + htab_traverse (type_discardable_table, type_discardable_remove, NULL); +} +#endif /* Helper functions to initialize architecture-specific types. */ @@ -3955,6 +4522,13 @@ void _initialize_gdbtypes (void) { gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init); + +#if 0 + type_discardable_table = htab_create_alloc (20, type_discardable_hash, + type_discardable_equal, NULL, + xcalloc, xfree); +#endif + objfile_type_data = register_objfile_data (); add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, Index: gdb-7.2.90.20110525/gdb/gdbtypes.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/gdbtypes.h 2011-03-28 22:21:03.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/gdbtypes.h 2011-05-25 17:05:21.000000000 +0200 @@ -215,6 +215,11 @@ enum type_instance_flag_value #define TYPE_TARGET_STUB(t) (TYPE_MAIN_TYPE (t)->flag_target_stub) +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be + sticky. */ + +#define TYPE_DYNAMIC(t) (TYPE_MAIN_TYPE (t)->flag_dynamic) + /* Static type. If this is set, the corresponding type had a static modifier. Note: This may be unnecessary, since static data members @@ -292,6 +297,50 @@ enum type_instance_flag_value #define TYPE_DECLARED_CLASS(t) (TYPE_MAIN_TYPE (t)->flag_declared_class) +#if 0 +/* Define this type as being reclaimable during free_all_types. Type is + required to be have TYPE_OBJFILE set to NULL. Setting this flag requires + initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable. */ + +#define TYPE_DISCARDABLE(t) (TYPE_MAIN_TYPE (t)->flag_discardable) + +/* Marker this type has been visited by the type_mark_used by this + mark-and-sweep types garbage collecting pass. Current pass is represented + by TYPE_DISCARDABLE_AGE_CURRENT. */ + +#define TYPE_DISCARDABLE_AGE(t) (TYPE_MAIN_TYPE (t)->flag_discardable_age) +#endif + +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)? */ + +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \ + (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count) + +/* Not allocated. TYPE_ALLOCATED(t) must be NULL in such case. If this flag + is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated. If this + flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block + determines the actual allocation state. */ + +#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated) + +/* Not associated. TYPE_ASSOCIATED(t) must be NULL in such case. If this flag + is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated. If + this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block + determines the actual association state. */ + +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated) + +/* Address of the actual data as for DW_AT_data_location. Its dwarf block must + not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are + false. If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value + is the actual data address value. If unset and + TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal + value_raw_address. If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL + then its DWARF block determines the actual data address. */ + +#define TYPE_DATA_LOCATION_IS_ADDR(t) \ + (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr) + /* Constant type. If this is set, the corresponding type has a const modifier. */ @@ -400,6 +449,15 @@ struct main_type /* True if this type was declared with "class" rather than "struct". */ unsigned int flag_declared_class : 1; +#if 0 + unsigned int flag_discardable : 1; + unsigned int flag_discardable_age : 1; +#endif + unsigned int flag_dynamic : 1; + unsigned int flag_range_high_bound_is_count : 1; + unsigned int flag_not_allocated : 1; + unsigned int flag_not_associated : 1; + unsigned int flag_data_location_is_addr : 1; /* A discriminant telling us which field of the type_specific union is being used for this type, if any. */ @@ -473,6 +531,20 @@ struct main_type struct type *target_type; + /* For DW_AT_data_location. */ + union + { + struct dwarf2_locexpr_baton *dwarf_block; + CORE_ADDR addr; + } + data_location; + + /* For DW_AT_allocated. */ + struct dwarf2_locexpr_baton *allocated; + + /* For DW_AT_associated. */ + struct dwarf2_locexpr_baton *associated; + /* For structure and union types, a description of each field. For set and pascal array types, there is one "field", whose type is the domain type of the set or array. @@ -547,13 +619,34 @@ struct main_type struct range_bounds { + struct + { + union + { + LONGEST constant; + struct dwarf2_locexpr_baton *dwarf_block; + struct + { + struct dwarf2_loclist_baton *loclist; + struct type *type; + } + dwarf_loclist; + } + u; + enum range_bound_kind + { + RANGE_BOUND_KIND_CONSTANT, + RANGE_BOUND_KIND_DWARF_BLOCK, + RANGE_BOUND_KIND_DWARF_LOCLIST + } + kind; + } /* Low bound of range. */ - - LONGEST low; - + low, /* High bound of range. */ - - LONGEST high; + high, + /* Byte stride of range. */ + byte_stride; /* Flags indicating whether the values of low and high are valid. When true, the respective range value is @@ -926,9 +1019,9 @@ extern void allocate_gnat_aux_type (stru #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type #define TYPE_CHAIN(thistype) (thistype)->chain -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef. - But check_typedef does set the TYPE_LENGTH of the TYPEDEF type, - so you only have to call check_typedef once. Since allocate_value +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call + check_typedef. But check_typedef does set the TYPE_LENGTH of the TYPEDEF + type, so you only have to call check_typedef once. Since allocate_value calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */ #define TYPE_LENGTH(thistype) (thistype)->length /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real @@ -936,11 +1029,16 @@ extern void allocate_gnat_aux_type (stru #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0) #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds -#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low -#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high +#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low.u.constant +#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high.u.constant +#define TYPE_BYTE_STRIDE(range_type) TYPE_RANGE_DATA(range_type)->byte_stride.u.constant #define TYPE_LOW_BOUND_UNDEFINED(range_type) \ TYPE_RANGE_DATA(range_type)->low_undefined #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \ @@ -957,7 +1055,14 @@ extern void allocate_gnat_aux_type (stru (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype)))) #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \ - (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype)))) + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype)) + +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the + element size if no specific stride value is known. */ +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype) \ + (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \ + ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype)) \ + : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype))) /* C++ */ @@ -1379,6 +1484,18 @@ extern struct type *create_array_type (s struct type *); extern struct type *lookup_array_range_type (struct type *, int, int); +extern CORE_ADDR type_range_any_field_internal (struct type *range_type, + int fieldno); + +extern int type_range_high_bound_internal (struct type *range_type); + +extern int type_range_count_bound_internal (struct type *range_type); + +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type, + struct type *element_type); + +extern void finalize_type (struct type *type); + extern struct type *create_string_type (struct type *, struct type *, struct type *); extern struct type *lookup_string_range_type (struct type *, int, int); @@ -1424,6 +1541,10 @@ extern int is_public_ancestor (struct ty extern int is_unique_ancestor (struct type *, struct value *); +#if 0 +extern void type_mark_used (struct type *type); +#endif + /* Overload resolution */ #define LENGTH_MATCH(bv) ((bv)->rank[0]) @@ -1496,10 +1617,13 @@ extern void maintenance_print_type (char extern htab_t create_copied_types_hash (struct objfile *objfile); -extern struct type *copy_type_recursive (struct objfile *objfile, - struct type *type, +extern struct type *copy_type_recursive (struct type *type, htab_t copied_types); extern struct type *copy_type (const struct type *type); +#if 0 +extern void free_all_types (void); +#endif + #endif /* GDBTYPES_H */ Index: gdb-7.2.90.20110525/gdb/i386-linux-nat.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/i386-linux-nat.c 2011-02-27 17:25:37.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/i386-linux-nat.c 2011-05-25 17:05:21.000000000 +0200 @@ -649,22 +649,13 @@ i386_linux_store_inferior_registers (str } -/* Support for debug registers. */ - -static unsigned long i386_linux_dr[DR_CONTROL + 1]; - /* Get debug register REGNUM value from only the one LWP of PTID. */ static unsigned long -i386_linux_dr_get (ptid_t ptid, int regnum) +i386_linux_dr_get (int tid, int regnum) { - int tid; unsigned long value; - tid = TIDGET (ptid); - if (tid == 0) - tid = PIDGET (ptid); - /* FIXME: kettenis/2001-03-27: Calling perror_with_name if the ptrace call fails breaks debugging remote targets. The correct way to fix this is to add the hardware breakpoint and watchpoint @@ -686,14 +677,8 @@ i386_linux_dr_get (ptid_t ptid, int regn /* Set debug register REGNUM to VALUE in only the one LWP of PTID. */ static void -i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) +i386_linux_dr_set (int tid, int regnum, unsigned long value) { - int tid; - - tid = TIDGET (ptid); - if (tid == 0) - tid = PIDGET (ptid); - errno = 0; ptrace (PTRACE_POKEUSER, tid, offsetof (struct user, u_debugreg[regnum]), value); @@ -701,35 +686,78 @@ i386_linux_dr_set (ptid_t ptid, int regn perror_with_name (_("Couldn't write debug register")); } -/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST. */ +/* Helper for i386_linux_dr_set_control. */ + +static void +i386_linux_dr_set_control_callback (int tid, void *control_voidp) +{ + unsigned long control = *(unsigned long *) control_voidp; + + i386_linux_dr_set (tid, DR_CONTROL, control); +} + +static void i386_linux_dr_set_addr (int regnum, CORE_ADDR addr); + +/* Set DR_CONTROL to ADDR in all LWPs of CURRENT_INFERIOR. */ static void i386_linux_dr_set_control (unsigned long control) { - struct lwp_info *lp; - ptid_t ptid; + int inferior_pid = ptid_get_pid (inferior_ptid); + struct inferior *inf = current_inferior (); + + /* The amd64 counterpart and description is amd64_linux_dr_set_control. */ + if (inf->pid != inferior_pid) + { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); + int i; + + if (!dr_mirror->addr_preset) + { + dr_mirror->addr_preset = 1; - i386_linux_dr[DR_CONTROL] = control; - ALL_LWPS (lp, ptid) - i386_linux_dr_set (ptid, DR_CONTROL, control); + for (i = 0; i < DR_LASTADDR - DR_FIRSTADDR; i++) + i386_linux_dr_set_addr (i, dr_mirror->addr[i]); + } + } + + linux_nat_iterate_watchpoint_lwps (i386_linux_dr_set_control_callback, + &control); } -/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST. */ +/* Helper for i386_linux_dr_set_addr. */ + +struct i386_linux_dr_set_addr_data + { + int regnum; + CORE_ADDR addr; + }; + +static void +i386_linux_dr_set_addr_callback (int tid, void *datap_voidp) +{ + const struct i386_linux_dr_set_addr_data *datap = datap_voidp; + + i386_linux_dr_set (tid, DR_FIRSTADDR + datap->regnum, datap->addr); +} + +/* Set address REGNUM (zero based) to ADDR in all LWPs of CURRENT_INFERIOR. + */ static void i386_linux_dr_set_addr (int regnum, CORE_ADDR addr) { - struct lwp_info *lp; - ptid_t ptid; + struct i386_linux_dr_set_addr_data data; gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR); - i386_linux_dr[DR_FIRSTADDR + regnum] = addr; - ALL_LWPS (lp, ptid) - i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr); + data.regnum = regnum; + data.addr = addr; + linux_nat_iterate_watchpoint_lwps (i386_linux_dr_set_addr_callback, &data); } -/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST. */ +/* Set address REGNUM (zero based) to zero in all LWPs of CURRENT_INFERIOR. + */ static void i386_linux_dr_reset_addr (int regnum) @@ -742,36 +770,54 @@ i386_linux_dr_reset_addr (int regnum) static unsigned long i386_linux_dr_get_status (void) { - return i386_linux_dr_get (inferior_ptid, DR_STATUS); + int tid; + + tid = TIDGET (inferior_ptid); + if (tid == 0) + tid = PIDGET (inferior_ptid); + + return i386_linux_dr_get (tid, DR_STATUS); } -/* Unset MASK bits in DR_STATUS in all LWPs of LWP_LIST. */ +/* Helper for i386_linux_dr_unset_status. */ static void -i386_linux_dr_unset_status (unsigned long mask) +i386_linux_dr_unset_status_callback (int tid, void *mask_voidp) { - struct lwp_info *lp; - ptid_t ptid; - - ALL_LWPS (lp, ptid) - { - unsigned long value; + unsigned long mask = *(unsigned long *) mask_voidp; + unsigned long value; - value = i386_linux_dr_get (ptid, DR_STATUS); - value &= ~mask; - i386_linux_dr_set (ptid, DR_STATUS, value); - } + value = i386_linux_dr_get (tid, DR_STATUS); + value &= ~mask; + i386_linux_dr_set (tid, DR_STATUS, value); +} + +/* Unset MASK bits in DR_STATUS in all LWPs of CURRENT_INFERIOR. */ + +static void +i386_linux_dr_unset_status (unsigned long mask) +{ + linux_nat_iterate_watchpoint_lwps (i386_linux_dr_unset_status_callback, + &mask); } static void i386_linux_new_thread (ptid_t ptid) { - int i; + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); + int i, tid; + + /* Verify DR_MIRROR is valid. */ + gdb_assert (PIDGET (ptid) == PIDGET (inferior_ptid)); + + tid = TIDGET (ptid); + if (tid == 0) + tid = PIDGET (ptid); - for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++) - i386_linux_dr_set (ptid, i, i386_linux_dr[i]); + for (i = 0; i < DR_LASTADDR - DR_FIRSTADDR; i++) + i386_linux_dr_set (tid, DR_FIRSTADDR + i, dr_mirror->addr[i]); - i386_linux_dr_set (ptid, DR_CONTROL, i386_linux_dr[DR_CONTROL]); + i386_linux_dr_set (tid, DR_CONTROL, dr_mirror->control); } Index: gdb-7.2.90.20110525/gdb/i386-nat.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/i386-nat.c 2011-02-26 23:04:51.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/i386-nat.c 2011-05-25 17:05:21.000000000 +0200 @@ -25,6 +25,7 @@ #include "gdbcmd.h" #include "target.h" #include "gdb_assert.h" +#include "inferior.h" /* Support for hardware watchpoints and breakpoints using the i386 debug registers. @@ -44,7 +45,6 @@ struct i386_dr_low_type i386_dr_low; #define TARGET_HAS_DR_LEN_8 (i386_dr_low.debug_register_length == 8) /* Debug registers' indices. */ -#define DR_NADDR 4 /* The number of debug address registers. */ #define DR_STATUS 6 /* Index of debug status register (DR6). */ #define DR_CONTROL 7 /* Index of debug control register (DR7). */ @@ -111,49 +111,60 @@ struct i386_dr_low_type i386_dr_low; /* The I'th debug register is vacant if its Local and Global Enable bits are reset in the Debug Control register. */ -#define I386_DR_VACANT(i) \ - ((dr_control_mirror & (3 << (DR_ENABLE_SIZE * (i)))) == 0) + +static inline int +i386_dr_vacant (struct i386_dr_mirror *dr_mirror, int i) +{ + return (dr_mirror->control & (3 << (DR_ENABLE_SIZE * i))) == 0; +} /* Locally enable the break/watchpoint in the I'th debug register. */ -#define I386_DR_LOCAL_ENABLE(i) \ - dr_control_mirror |= (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))) -/* Globally enable the break/watchpoint in the I'th debug register. */ -#define I386_DR_GLOBAL_ENABLE(i) \ - dr_control_mirror |= (1 << (DR_GLOBAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))) +static inline void +i386_dr_local_enable (struct i386_dr_mirror *dr_mirror, int i) +{ + dr_mirror->control |= 1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * i); +} /* Disable the break/watchpoint in the I'th debug register. */ -#define I386_DR_DISABLE(i) \ - dr_control_mirror &= ~(3 << (DR_ENABLE_SIZE * (i))) + +static inline void +i386_dr_disable (struct i386_dr_mirror *dr_mirror, int i) +{ + dr_mirror->control &= ~(3 << (DR_ENABLE_SIZE * i)); +} /* Set in DR7 the RW and LEN fields for the I'th debug register. */ -#define I386_DR_SET_RW_LEN(i,rwlen) \ - do { \ - dr_control_mirror &= ~(0x0f << (DR_CONTROL_SHIFT+DR_CONTROL_SIZE*(i))); \ - dr_control_mirror |= ((rwlen) << (DR_CONTROL_SHIFT+DR_CONTROL_SIZE*(i))); \ - } while (0) + +static inline void +i386_dr_set_rw_len (struct i386_dr_mirror *dr_mirror, int i, unsigned rwlen) +{ + dr_mirror->control &= ~(0x0f << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * i)); + dr_mirror->control |= rwlen << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * i); +} /* Get from DR7 the RW and LEN fields for the I'th debug register. */ -#define I386_DR_GET_RW_LEN(i) \ - ((dr_control_mirror >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f) + +static inline unsigned +i386_dr_get_rw_len (struct i386_dr_mirror *dr_mirror, int i) +{ + return ((dr_mirror->control >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * i)) + & 0x0f); +} /* Mask that this I'th watchpoint has triggered. */ #define I386_DR_WATCH_MASK(i) (1 << (i)) /* Did the watchpoint whose address is in the I'th register break? */ -#define I386_DR_WATCH_HIT(i) (dr_status_mirror & I386_DR_WATCH_MASK (i)) +static inline int +i386_dr_watch_hit (struct i386_dr_mirror *dr_mirror, int i) +{ + return (dr_mirror->status & I386_DR_WATCH_MASK (i)) != 0; +} /* A macro to loop over all debug registers. */ #define ALL_DEBUG_REGISTERS(i) for (i = 0; i < DR_NADDR; i++) -/* Mirror the inferior's DRi registers. We keep the status and - control registers separated because they don't hold addresses. */ -static CORE_ADDR dr_mirror[DR_NADDR]; -static unsigned long dr_status_mirror, dr_control_mirror; - -/* Reference counts for each debug register. */ -static int dr_ref_count[DR_NADDR]; - /* Whether or not to print the mirrored debug registers. */ static int maint_show_dr; @@ -195,21 +206,80 @@ static int i386_handle_nonaligned_watchp /* Implementation. */ +/* Per-inferior data key. */ +static const struct inferior_data *i386_inferior_data; + +struct i386_inferior_data + { + /* Copy of i386 hardware debug registers for performance reasons. */ + struct i386_dr_mirror dr_mirror; + }; + +static void +i386_inferior_data_cleanup (struct inferior *inf, void *arg) +{ + struct i386_inferior_data *inf_data = arg; + + xfree (inf_data); +} + +static struct i386_inferior_data * +i386_inferior_data_get (void) +{ + struct inferior *inf = current_inferior (); + struct i386_inferior_data *inf_data; + + inf_data = inferior_data (inf, i386_inferior_data); + if (inf_data == NULL) + { + inf_data = xzalloc (sizeof (*inf_data)); + set_inferior_data (current_inferior (), i386_inferior_data, inf_data); + } + + if (inf->pid != ptid_get_pid (inferior_ptid)) + { + static struct i386_inferior_data detached_inf_data_local; + static int detached_inf_pid = -1; + + if (detached_inf_pid != ptid_get_pid (inferior_ptid)) + { + detached_inf_pid = ptid_get_pid (inferior_ptid); + + /* Forked processes get a copy of the debug registers. */ + memcpy (&detached_inf_data_local, inf_data, + sizeof (detached_inf_data_local)); + detached_inf_data_local.dr_mirror.addr_preset = 0; + } + + return &detached_inf_data_local; + } + + return inf_data; +} + /* Clear the reference counts and forget everything we knew about the debug registers. */ +struct i386_dr_mirror * +i386_dr_mirror_get (void) +{ + return &i386_inferior_data_get ()->dr_mirror; +} + void i386_cleanup_dregs (void) { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); int i; ALL_DEBUG_REGISTERS(i) { - dr_mirror[i] = 0; - dr_ref_count[i] = 0; + dr_mirror->addr[i] = 0; + dr_mirror->ref_count[i] = 0; } - dr_control_mirror = 0; - dr_status_mirror = 0; + dr_mirror->addr_preset = 0; + dr_mirror->control = 0; + dr_mirror->status = 0; } /* Print the values of the mirrored debug registers. This is called @@ -220,6 +290,7 @@ static void i386_show_dr (const char *func, CORE_ADDR addr, int len, enum target_hw_bp_type type) { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); int addr_size = gdbarch_addr_bit (target_gdbarch) / 8; int i; @@ -239,13 +310,16 @@ i386_show_dr (const char *func, CORE_ADD : "??unknown??")))); puts_unfiltered (":\n"); printf_unfiltered ("\tCONTROL (DR7): %s STATUS (DR6): %s\n", - phex (dr_control_mirror, 8), phex (dr_status_mirror, 8)); + phex (dr_mirror->control, 8), + phex (dr_mirror->status, 8)); ALL_DEBUG_REGISTERS(i) { printf_unfiltered ("\ \tDR%d: addr=0x%s, ref.count=%d DR%d: addr=0x%s, ref.count=%d\n", - i, phex (dr_mirror[i], addr_size), dr_ref_count[i], - i+1, phex (dr_mirror[i+1], addr_size), dr_ref_count[i+1]); + i, phex (dr_mirror->addr[i], addr_size), + dr_mirror->ref_count[i], i + 1, + phex (dr_mirror->addr[i + 1], addr_size), + dr_mirror->ref_count[i + 1]); i++; } } @@ -313,6 +387,7 @@ Invalid hardware breakpoint length %d in static int i386_insert_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits) { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); int i; if (!i386_dr_low.set_addr || !i386_dr_low.set_control) @@ -323,11 +398,10 @@ i386_insert_aligned_watchpoint (CORE_ADD reuse it for this watchpoint as well (and save a register). */ ALL_DEBUG_REGISTERS(i) { - if (!I386_DR_VACANT (i) - && dr_mirror[i] == addr - && I386_DR_GET_RW_LEN (i) == len_rw_bits) + if (!i386_dr_vacant (dr_mirror, i) && dr_mirror->addr[i] == addr + && i386_dr_get_rw_len (dr_mirror, i) == len_rw_bits) { - dr_ref_count[i]++; + dr_mirror->ref_count[i]++; return 0; } } @@ -335,7 +409,7 @@ i386_insert_aligned_watchpoint (CORE_ADD /* Next, look for a vacant debug register. */ ALL_DEBUG_REGISTERS(i) { - if (I386_DR_VACANT (i)) + if (i386_dr_vacant (dr_mirror, i)) break; } @@ -346,9 +420,9 @@ i386_insert_aligned_watchpoint (CORE_ADD /* Now set up the register I to watch our region. */ /* Record the info in our local mirrored array. */ - dr_mirror[i] = addr; - dr_ref_count[i] = 1; - I386_DR_SET_RW_LEN (i, len_rw_bits); + dr_mirror->addr[i] = addr; + dr_mirror->ref_count[i] = 1; + i386_dr_set_rw_len (dr_mirror, i, len_rw_bits); /* Note: we only enable the watchpoint locally, i.e. in the current task. Currently, no i386 target allows or supports global watchpoints; however, if any target would want that in the @@ -356,13 +430,13 @@ i386_insert_aligned_watchpoint (CORE_ADD to enable watchpoints globally or locally, and the code below should use global or local enable and slow-down flags as appropriate. */ - I386_DR_LOCAL_ENABLE (i); - dr_control_mirror |= DR_LOCAL_SLOWDOWN; - dr_control_mirror &= I386_DR_CONTROL_MASK; + i386_dr_local_enable (dr_mirror, i); + dr_mirror->control |= DR_LOCAL_SLOWDOWN; + dr_mirror->control &= I386_DR_CONTROL_MASK; /* Finally, actually pass the info to the inferior. */ i386_dr_low.set_addr (i, addr); - i386_dr_low.set_control (dr_control_mirror); + i386_dr_low.set_control (dr_mirror->control); /* Only a sanity check for leftover bits (set possibly only by inferior). */ if (i386_dr_low.unset_status) @@ -380,21 +454,21 @@ i386_insert_aligned_watchpoint (CORE_ADD static int i386_remove_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits) { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); int i, retval = -1; ALL_DEBUG_REGISTERS(i) { - if (!I386_DR_VACANT (i) - && dr_mirror[i] == addr - && I386_DR_GET_RW_LEN (i) == len_rw_bits) + if (!i386_dr_vacant (dr_mirror, i) && dr_mirror->addr[i] == addr + && i386_dr_get_rw_len (dr_mirror, i) == len_rw_bits) { - if (--dr_ref_count[i] == 0) /* no longer in use? */ + if (--dr_mirror->ref_count[i] == 0) /* no longer in use? */ { /* Reset our mirror. */ - dr_mirror[i] = 0; - I386_DR_DISABLE (i); + dr_mirror->addr[i] = 0; + i386_dr_disable (dr_mirror, i); /* Reset it in the inferior. */ - i386_dr_low.set_control (dr_control_mirror); + i386_dr_low.set_control (dr_mirror->control); if (i386_dr_low.reset_addr) i386_dr_low.reset_addr (i); } @@ -556,26 +630,27 @@ i386_region_ok_for_watchpoint (CORE_ADDR static int i386_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p) { + struct i386_dr_mirror *dr_mirror = i386_dr_mirror_get (); CORE_ADDR addr = 0; int i; int rc = 0; - dr_status_mirror = i386_dr_low.get_status (); + dr_mirror->status = i386_dr_low.get_status (); ALL_DEBUG_REGISTERS(i) { - if (I386_DR_WATCH_HIT (i) + if (i386_dr_watch_hit (dr_mirror, i) /* This second condition makes sure DRi is set up for a data watchpoint, not a hardware breakpoint. The reason is that GDB doesn't call the target_stopped_data_address method except for data watchpoints. In other words, I'm being paranoiac. */ - && I386_DR_GET_RW_LEN (i) != 0 + && i386_dr_get_rw_len (dr_mirror, i) != 0 /* This third condition makes sure DRi is not vacant, this avoids false positives in windows-nat.c. */ - && !I386_DR_VACANT (i)) + && !i386_dr_vacant (dr_mirror, i)) { - addr = dr_mirror[i]; + addr = dr_mirror->addr[i]; rc = 1; if (maint_show_dr) i386_show_dr ("watchpoint_hit", addr, -1, hw_write); @@ -689,6 +764,10 @@ i386_use_watchpoints (struct target_ops t->to_remove_watchpoint = i386_remove_watchpoint; t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint; t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint; + + if (i386_inferior_data == NULL) + i386_inferior_data + = register_inferior_data_with_cleanup (i386_inferior_data_cleanup); } void Index: gdb-7.2.90.20110525/gdb/i386-nat.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/i386-nat.h 2011-01-09 04:08:56.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/i386-nat.h 2011-05-25 17:05:21.000000000 +0200 @@ -78,6 +78,28 @@ struct i386_dr_low_type extern struct i386_dr_low_type i386_dr_low; +/* The number of debug address registers. */ +#define DR_NADDR 4 + +/* Copy of hardware debug registers for performance reasons. */ + +struct i386_dr_mirror + { + /* Mirror the inferior's DRi registers. We keep the status and + control registers separated because they don't hold addresses. */ + CORE_ADDR addr[DR_NADDR]; + + /* All the ADDR hardware registers have been written at least once. */ + unsigned addr_preset : 1; + + /* Reference counts for each debug register. */ + int ref_count[DR_NADDR]; + + unsigned long status, control; + }; + +extern struct i386_dr_mirror *i386_dr_mirror_get (void); + /* Use this function to set i386_dr_low debug_register_length field rather than setting it directly to check that the length is only set once. It also enables the 'maint set/show show-debug-regs' Index: gdb-7.2.90.20110525/gdb/infrun.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/infrun.c 2011-04-20 19:04:32.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/infrun.c 2011-05-25 17:05:21.000000000 +0200 @@ -54,6 +54,8 @@ #include "inline-frame.h" #include "jit.h" #include "tracepoint.h" +#include "stap-probe.h" +#include "objfiles.h" /* Prototypes for local functions */ @@ -2247,7 +2249,7 @@ static void insert_step_resume_breakpoin struct frame_id); static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR); static void check_exception_resume (struct execution_control_state *, - struct frame_info *, struct symbol *); + struct frame_info *); static void stop_stepping (struct execution_control_state *ecs); static void prepare_to_wait (struct execution_control_state *ecs); @@ -4164,9 +4166,17 @@ process_event_stop_test: if (what.is_longjmp) { - if (!gdbarch_get_longjmp_target_p (gdbarch) - || !gdbarch_get_longjmp_target (gdbarch, - frame, &jmp_buf_pc)) + struct value *arg_value; + + /* If we set the longjmp breakpoint via a SystemTap probe, + then use it to extract the arguments. The destination + PC is the third argument to the probe. */ + arg_value = stap_safe_evaluate_at_pc (frame, 2); + if (arg_value) + jmp_buf_pc = value_as_address (arg_value); + else if (!gdbarch_get_longjmp_target_p (gdbarch) + || !gdbarch_get_longjmp_target (gdbarch, + frame, &jmp_buf_pc)) { if (debug_infrun) fprintf_unfiltered (gdb_stdlog, @@ -4184,12 +4194,7 @@ process_event_stop_test: insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc); } else - { - struct symbol *func = get_frame_function (frame); - - if (func) - check_exception_resume (ecs, frame, func); - } + check_exception_resume (ecs, frame); keep_going (ecs); return; @@ -5263,15 +5268,65 @@ insert_exception_resume_breakpoint (stru } } +/* A helper for check_exception_resume that sets an + exception-breakpoint based on a SystemTap probe. */ + +static void +insert_exception_resume_from_probe (struct thread_info *tp, + const struct stap_probe *probe, + struct objfile *objfile, + struct frame_info *frame) +{ + struct value *arg_value; + CORE_ADDR handler; + struct breakpoint *bp; + + arg_value = stap_safe_evaluate_at_pc (frame, 1); + if (!arg_value) + return; + + handler = value_as_address (arg_value); + + if (debug_infrun) + fprintf_unfiltered (gdb_stdlog, + "infrun: exception resume at %s\n", + paddress (get_objfile_arch (objfile), + handler)); + + bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), + handler, bp_exception_resume); + bp->thread = tp->num; + inferior_thread ()->control.exception_resume_breakpoint = bp; +} + /* This is called when an exception has been intercepted. Check to see whether the exception's destination is of interest, and if so, set an exception resume breakpoint there. */ static void check_exception_resume (struct execution_control_state *ecs, - struct frame_info *frame, struct symbol *func) + struct frame_info *frame) { struct gdb_exception e; + struct objfile *objfile; + const struct stap_probe *probe; + struct symbol *func; + + /* First see if this exception unwinding breakpoint was set via a + SystemTap probe point. If so, the probe has two arguments: the + CFA and the HANDLER. We ignore the CFA, extract the handler, and + set a breakpoint there. */ + probe = find_probe_by_pc (get_frame_pc (frame), &objfile); + if (probe) + { + insert_exception_resume_from_probe (ecs->event_thread, probe, + objfile, frame); + return; + } + + func = get_frame_function (frame); + if (!func) + return; TRY_CATCH (e, RETURN_MASK_ERROR) { @@ -6253,7 +6308,8 @@ static struct lval_funcs siginfo_value_f if there's no object available. */ static struct value * -siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var) +siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var, + void *ignore) { if (target_has_stack && !ptid_equal (inferior_ptid, null_ptid) @@ -6821,6 +6877,15 @@ show_schedule_multiple (struct ui_file * "of all processes is %s.\n"), value); } +/* Implementation of `siginfo' variable. */ + +static const struct internalvar_funcs siginfo_funcs = +{ + siginfo_make_value, + NULL, + NULL +}; + void _initialize_infrun (void) { @@ -7093,7 +7158,7 @@ Tells gdb whether to detach the child of value with a void typed value, and when we get here, gdbarch isn't initialized yet. At this point, we're quite sure there isn't another convenience variable of the same name. */ - create_internalvar_type_lazy ("_siginfo", siginfo_make_value); + create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL); add_setshow_boolean_cmd ("observer", no_class, &observer_mode_1, _("\ Index: gdb-7.2.90.20110525/gdb/linespec.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/linespec.c 2011-03-25 18:13:12.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/linespec.c 2011-05-25 17:05:21.000000000 +0200 @@ -43,6 +43,7 @@ #include "arch-utils.h" #include #include "cli/cli-utils.h" +#include "stap-probe.h" /* We share this one with symtab.c, but it is not exported widely. */ @@ -762,6 +763,7 @@ keep_name_info (char *ptr) PC returned is 0. FILE:FUNCTION -- likewise, but prefer functions in that file. *EXPR -- line in which address EXPR appears. + probe:[OBJFILE:][PROVIDER:]NAME -- a systemtap static probe This may all be followed by an "if EXPR", which we ignore. @@ -837,6 +839,9 @@ decode_line_1 (char **argptr, int funfir if (**argptr == '*') return decode_indirect (argptr); + if (strncmp (*argptr, "probe:", 6) == 0) + return parse_stap_probe (argptr, canonical); + is_quoted = (strchr (get_gdb_completer_quote_characters (), **argptr) != NULL); Index: gdb-7.2.90.20110525/gdb/linespec.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/linespec.h 2011-03-24 20:47:17.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/linespec.h 2011-05-25 17:05:21.000000000 +0200 @@ -30,6 +30,10 @@ struct linespec_result display mechanism would do the wrong thing. */ int special_display; + /* If non-zero, the linespec result should be considered to be a + "pre-expanded" multi-location linespec. */ + int pre_expanded; + /* If non-NULL, an array of canonical names for returned symtab_and_line objects. The array has as many elements as the `nelts' field in the symtabs_and_line returned by decode_line_1. Index: gdb-7.2.90.20110525/gdb/linux-nat.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/linux-nat.c 2011-04-29 18:02:10.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/linux-nat.c 2011-05-25 17:05:21.000000000 +0200 @@ -1272,6 +1272,64 @@ iterate_over_lwps (ptid_t filter, return NULL; } +/* Helper for linux_nat_iterate_watchpoint_lwps. */ + +struct iterate_watchpoint_lwps_data + { + linux_nat_iterate_watchpoint_lwps_ftype callback; + void *callback_data; + }; + +static int +iterate_watchpoint_lwps_callback (struct lwp_info *lp, void *datap_voidp) +{ + struct iterate_watchpoint_lwps_data *datap = datap_voidp; + int tid; + + tid = TIDGET (lp->ptid); + if (tid == 0) + tid = PIDGET (lp->ptid); + + datap->callback (tid, datap->callback_data); + + /* Continue the traversal. */ + return 0; +} + +/* Iterate like iterate_over_lwps does except when forking-off a child call + CALLBACK with CALLBACK_DATA specifically only for that new child PID. + + During `set follow-fork-mode child' the call is also made for the new child + PID; parent watchpoints get detached elsewhere (during target_detach). */ + +void +linux_nat_iterate_watchpoint_lwps + (linux_nat_iterate_watchpoint_lwps_ftype callback, void *callback_data) +{ + struct iterate_watchpoint_lwps_data data; + int inferior_pid = ptid_get_pid (inferior_ptid); + struct inferior *inf = current_inferior (); + + data.callback = callback; + data.callback_data = callback_data; + + if (inf->pid == inferior_pid) + { + /* Standard mode. Iterate all the threads of the current inferior. + Without specifying INFERIOR_PID it would iterate all the threads of + all the inferiors, which is inappropriate for watchpoints. */ + + iterate_over_lwps (pid_to_ptid (inferior_pid), + iterate_watchpoint_lwps_callback, &data); + } + else + { + /* Detaching a new child PID temporarily present in INFERIOR_PID. */ + + callback (inferior_pid, callback_data); + } +} + /* Update our internal state when changing from one checkpoint to another indicated by NEW_PTID. We can only switch single-threaded applications, so we only create one new LWP, and the previous list Index: gdb-7.2.90.20110525/gdb/linux-nat.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/linux-nat.h 2011-01-05 23:22:49.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/linux-nat.h 2011-05-25 17:05:21.000000000 +0200 @@ -140,6 +140,11 @@ struct lwp_info *iterate_over_lwps (ptid void *), void *data); +typedef void (*linux_nat_iterate_watchpoint_lwps_ftype) (int tid, void *data); + +extern void linux_nat_iterate_watchpoint_lwps + (linux_nat_iterate_watchpoint_lwps_ftype callback, void *callback_data); + /* Create a prototype generic GNU/Linux target. The client can override it with local methods. */ struct target_ops * linux_target (void); Index: gdb-7.2.90.20110525/gdb/machoread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/machoread.c 2011-03-07 17:17:29.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/machoread.c 2011-05-25 17:05:21.000000000 +0200 @@ -849,6 +849,7 @@ static const struct sym_fns macho_sym_fn default_symfile_segments, /* Get segment information from a file. */ NULL, macho_symfile_relocate, /* Relocate a debug section. */ + NULL, /* sym_get_probes */ &psym_functions }; Index: gdb-7.2.90.20110525/gdb/main.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/main.c 2011-03-07 19:34:31.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/main.c 2011-05-25 17:05:21.000000000 +0200 @@ -39,6 +39,7 @@ #include "interps.h" #include "main.h" +#include "python/python.h" #include "source.h" #include "cli/cli-cmds.h" #include "python/python.h" @@ -260,6 +261,8 @@ captured_main (void *data) char *cdarg = NULL; char *ttyarg = NULL; + int python_script = 0; + /* These are static so that we can take their address in an initializer. */ static int print_help; @@ -451,10 +454,14 @@ captured_main (void *data) {"args", no_argument, &set_args, 1}, {"l", required_argument, 0, 'l'}, {"return-child-result", no_argument, &return_child_result, 1}, +#if HAVE_PYTHON + {"python", no_argument, 0, 'P'}, + {"P", no_argument, 0, 'P'}, +#endif {0, no_argument, 0, 0} }; - while (1) + while (!python_script) { int option_index; @@ -472,6 +479,9 @@ captured_main (void *data) case 0: /* Long option that just sets a flag. */ break; + case 'P': + python_script = 1; + break; case OPT_SE: symarg = optarg; execarg = optarg; @@ -667,7 +677,31 @@ captured_main (void *data) /* Now that gdb_init has created the initial inferior, we're in position to set args for that inferior. */ - if (set_args) + if (python_script) + { + /* The first argument is a python script to evaluate, and + subsequent arguments are passed to the script for + processing there. */ + if (optind >= argc) + { + fprintf_unfiltered (gdb_stderr, + _("%s: Python script file name required\n"), + argv[0]); + exit (1); + } + + /* FIXME: should handle inferior I/O intelligently here. + E.g., should be possible to run gdb in pipeline and have + Python (and gdb) output go to stderr or file; and if a + prompt is needed, open the tty. */ + quiet = 1; + /* FIXME: should read .gdbinit if, and only if, a prompt is + requested by the script. Though... maybe this is not + ideal? */ + /* FIXME: likewise, reading in history. */ + inhibit_gdbinit = 1; + } + else if (set_args) { /* The remaining options are the command-line options for the inferior. The first one is the sym/exec file, and the rest @@ -916,7 +950,8 @@ captured_main (void *data) /* Read in the old history after all the command files have been read. */ - init_history (); + if (!python_script) + init_history (); if (batch_flag) { @@ -927,13 +962,25 @@ captured_main (void *data) /* Show time and/or space usage. */ do_cleanups (pre_stat_chain); - /* NOTE: cagney/1999-11-07: There is probably no reason for not - moving this loop and the code found in captured_command_loop() - into the command_loop() proper. The main thing holding back that - change - SET_TOP_LEVEL() - has been eliminated. */ - while (1) +#if HAVE_PYTHON + if (python_script) { - catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL); + extern int pagination_enabled; + pagination_enabled = 0; + run_python_script (argc - optind, &argv[optind]); + return 1; + } + else +#endif + { + /* NOTE: cagney/1999-11-07: There is probably no reason for not + moving this loop and the code found in captured_command_loop() + into the command_loop() proper. The main thing holding back that + change - SET_TOP_LEVEL() - has been eliminated. */ + while (1) + { + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL); + } } /* No exit -- exit is through quit_command. */ } @@ -965,7 +1012,12 @@ print_gdb_help (struct ui_file *stream) fputs_unfiltered (_("\ This is the GNU debugger. Usage:\n\n\ gdb [options] [executable-file [core-file or process-id]]\n\ - gdb [options] --args executable-file [inferior-arguments ...]\n\n\ + gdb [options] --args executable-file [inferior-arguments ...]\n"), stream); +#if HAVE_PYTHON + fputs_unfiltered (_("\ + gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream); +#endif + fputs_unfiltered (_("\n\ Options:\n\n\ "), stream); fputs_unfiltered (_("\ @@ -1003,7 +1055,13 @@ Options:\n\n\ --nw Do not use a window interface.\n\ --nx Do not read "), stream); fputs_unfiltered (gdbinit, stream); - fputs_unfiltered (_(" file.\n\ + fputs_unfiltered (_(" file.\n"), stream); +#if HAVE_PYTHON + fputs_unfiltered (_("\ + --python, -P Following argument is Python script file; remaining\n\ + arguments are passed to script.\n"), stream); +#endif + fputs_unfiltered (_("\ --quiet Do not print version number on startup.\n\ --readnow Fully read symbol files on first access.\n\ "), stream); Index: gdb-7.2.90.20110525/gdb/mi/mi-cmd-var.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/mi/mi-cmd-var.c 2011-01-12 22:09:39.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/mi/mi-cmd-var.c 2011-05-25 17:05:21.000000000 +0200 @@ -707,7 +707,6 @@ mi_cmd_var_update (char *command, char * } else { - /* Get varobj handle, if a valid var obj name was specified */ struct varobj *var = varobj_get_handle (name); varobj_update_one (var, print_values, 1 /* explicit */); Index: gdb-7.2.90.20110525/gdb/mipsread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/mipsread.c 2011-03-07 17:17:29.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/mipsread.c 2011-05-25 17:05:21.000000000 +0200 @@ -402,6 +402,7 @@ static const struct sym_fns ecoff_sym_fn default_symfile_segments, /* Get segment information from a file. */ NULL, default_symfile_relocate, /* Relocate a debug section. */ + NULL, /* sym_probe_fns */ &psym_functions }; Index: gdb-7.2.90.20110525/gdb/objfiles.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/objfiles.c 2011-04-25 23:25:18.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/objfiles.c 2011-05-25 17:05:21.000000000 +0200 @@ -846,6 +846,11 @@ objfile_relocate1 (struct objfile *objfi obj_section_addr (s)); } + /* Relocating SystemTap probes. */ + if (objfile->sf && objfile->sf->sym_probe_fns) + objfile->sf->sym_probe_fns->sym_relocate_probe (objfile, + new_offsets, delta); + /* Data changed. */ return 1; } Index: gdb-7.2.90.20110525/gdb/p-valprint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/p-valprint.c 2011-03-15 17:00:56.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/p-valprint.c 2011-05-25 17:05:21.000000000 +0200 @@ -39,6 +39,7 @@ #include "cp-abi.h" #include "cp-support.h" #include "exceptions.h" +#include "dwarf2loc.h" /* See val_print for a description of the various parameters of this @@ -63,8 +64,31 @@ pascal_val_print (struct type *type, con struct type *char_type; LONGEST val; CORE_ADDR addr; + struct cleanup *back_to; + struct type *saved_type = type; + CORE_ADDR saved_address = address; + + back_to = make_cleanup (null_cleanup, 0); + address += embedded_offset; + type = object_address_get_data (type, &address); + if (type == NULL) + { + fputs_filtered (object_address_data_not_valid (saved_type), stream); + gdb_flush (stream); + do_cleanups (back_to); + return 0; + } + if (address != saved_address + embedded_offset) + { + size_t length = TYPE_LENGTH (type); - CHECK_TYPEDEF (type); + valaddr = xmalloc (length); + make_cleanup (xfree, (gdb_byte *) valaddr); + read_memory (address, (gdb_byte *) valaddr, length); + embedded_offset = 0; + } + else + address -= embedded_offset; switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: @@ -120,8 +144,8 @@ pascal_val_print (struct type *type, con { i = 0; } - val_print_array_elements (type, valaddr, embedded_offset, - address, stream, recurse, + val_print_array_elements (saved_type, valaddr, embedded_offset, + saved_address, stream, recurse, original_value, options, i); fprintf_filtered (stream, "}"); } @@ -160,6 +184,7 @@ pascal_val_print (struct type *type, con /* Try to print what function it points to. */ print_address_demangle (gdbarch, addr, stream, demangle); /* Return value is irrelevant except for string pointers. */ + do_cleanups (back_to); return (0); } @@ -251,6 +276,7 @@ pascal_val_print (struct type *type, con /* Return number of characters printed, including the terminating '\0' if we reached the end. val_print_string takes care including the terminating '\0' if necessary. */ + do_cleanups (back_to); return i; break; @@ -567,6 +593,7 @@ pascal_val_print (struct type *type, con TYPE_CODE (type)); } gdb_flush (stream); + do_cleanups (back_to); return (0); } Index: gdb-7.2.90.20110525/gdb/parse.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/parse.c 2011-03-28 22:21:03.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/parse.c 2011-05-25 17:05:21.000000000 +0200 @@ -1502,6 +1502,7 @@ parser_fprintf (FILE *x, const char *y, int operator_check_standard (struct expression *exp, int pos, + int (*type_func) (struct type *type, void *data), int (*objfile_func) (struct objfile *objfile, void *data), void *data) @@ -1543,7 +1544,7 @@ operator_check_standard (struct expressi struct type *type = elts[pos + 2 + arg].type; struct objfile *objfile = TYPE_OBJFILE (type); - if (objfile && (*objfile_func) (objfile, data)) + if (objfile && objfile_func && (*objfile_func) (objfile, data)) return 1; } } @@ -1561,7 +1562,8 @@ operator_check_standard (struct expressi /* Check objfile where the variable itself is placed. SYMBOL_OBJ_SECTION (symbol) may be NULL. */ - if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data)) + if (objfile_func + && (*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data)) return 1; /* Check objfile where is placed the code touching the variable. */ @@ -1574,24 +1576,27 @@ operator_check_standard (struct expressi /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */ - if (type && TYPE_OBJFILE (type) + if (type && type_func && (*type_func) (type, data)) + return 1; + if (type && TYPE_OBJFILE (type) && objfile_func && (*objfile_func) (TYPE_OBJFILE (type), data)) return 1; - if (objfile && (*objfile_func) (objfile, data)) + if (objfile && objfile_func && (*objfile_func) (objfile, data)) return 1; return 0; } -/* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP. - The functions are never called with NULL OBJFILE. Functions get passed an - arbitrary caller supplied DATA pointer. If any of the functions returns - non-zero value then (any other) non-zero value is immediately returned to - the caller. Otherwise zero is returned after iterating through whole EXP. - */ +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being + referenced by EXP. The functions are never called with NULL TYPE or NULL + OBJFILE. Functions get passed an arbitrary caller supplied DATA pointer. + If any of the functions returns non-zero value then (any other) non-zero + value is immediately returned to the caller. Otherwise zero is returned + after iterating through whole EXP. */ static int exp_iterate (struct expression *exp, + int (*type_func) (struct type *type, void *data), int (*objfile_func) (struct objfile *objfile, void *data), void *data) { @@ -1606,7 +1611,9 @@ exp_iterate (struct expression *exp, pos = endpos - oplen; if (exp->language_defn->la_exp_desc->operator_check (exp, pos, - objfile_func, data)) + type_func, + objfile_func, + data)) return 1; endpos = pos; @@ -1637,8 +1644,29 @@ exp_uses_objfile (struct expression *exp { gdb_assert (objfile->separate_debug_objfile_backlink == NULL); - return exp_iterate (exp, exp_uses_objfile_iter, objfile); + return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile); +} + +/* Helper for exp_types_mark_used. */ + +#if 0 +static int +exp_types_mark_used_iter (struct type *type, void *unused) +{ + type_mark_used (type); + + /* Continue the traversal. */ + return 0; +} + +/* Call type_mark_used for any type contained in EXP. */ + +void +exp_types_mark_used (struct expression *exp) +{ + exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL); } +#endif void _initialize_parse (void) Index: gdb-7.2.90.20110525/gdb/parser-defs.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/parser-defs.h 2011-01-10 21:38:49.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/parser-defs.h 2011-05-25 17:05:21.000000000 +0200 @@ -194,6 +194,8 @@ extern void operator_length_standard (co int *); extern int operator_check_standard (struct expression *exp, int pos, + int (*type_func) (struct type *type, + void *data), int (*objfile_func) (struct objfile *objfile, void *data), void *data); @@ -291,6 +293,7 @@ struct exp_descriptor value should be immediately returned to the caller. Otherwise zero should be returned. */ int (*operator_check) (struct expression *exp, int pos, + int (*type_func) (struct type *type, void *data), int (*objfile_func) (struct objfile *objfile, void *data), void *data); @@ -329,4 +332,10 @@ extern void parser_fprintf (FILE *, cons extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile); +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile); + +#if 0 +extern void exp_types_mark_used (struct expression *exp); +#endif + #endif /* PARSER_DEFS_H */ Index: gdb-7.2.90.20110525/gdb/ppc-linux-nat.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/ppc-linux-nat.c 2011-04-18 23:29:18.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/ppc-linux-nat.c 2011-05-25 17:05:21.000000000 +0200 @@ -1637,6 +1637,14 @@ booke_remove_point (struct ppc_hw_breakp hw_breaks[i].hw_break = NULL; } +static void +booke_insert_point_callback (int tid, void *pp_voidp) +{ + struct ppc_hw_breakpoint *pp = pp_voidp; + + booke_insert_point (pp, tid); +} + /* Return the number of registers needed for a ranged breakpoint. */ static int @@ -1654,8 +1662,6 @@ static int ppc_linux_insert_hw_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt) { - ptid_t ptid; - struct lwp_info *lp; struct ppc_hw_breakpoint p; if (!have_ptrace_booke_interface ()) @@ -1681,18 +1687,23 @@ ppc_linux_insert_hw_breakpoint (struct g p.addr2 = 0; } - ALL_LWPS (lp, ptid) - booke_insert_point (&p, TIDGET (ptid)); + linux_nat_iterate_watchpoint_lwps (booke_insert_point_callback, &p); return 0; } +static void +booke_remove_point_callback (int tid, void *pp_voidp) +{ + struct ppc_hw_breakpoint *pp = pp_voidp; + + booke_remove_point (pp, tid); +} + static int ppc_linux_remove_hw_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt) { - ptid_t ptid; - struct lwp_info *lp; struct ppc_hw_breakpoint p; if (!have_ptrace_booke_interface ()) @@ -1718,8 +1729,7 @@ ppc_linux_remove_hw_breakpoint (struct g p.addr2 = 0; } - ALL_LWPS (lp, ptid) - booke_remove_point (&p, TIDGET (ptid)); + linux_nat_iterate_watchpoint_lwps (booke_remove_point_callback, &p); return 0; } @@ -1946,6 +1956,15 @@ ppc_linux_can_accel_watchpoint_condition && check_condition (addr, cond, &data_value, &len)); } +static void +set_saved_dabr_value_callback (int tid, void *retp_voidp) +{ + int *retp = retp_voidp; + + if (ptrace (PTRACE_SET_DEBUGREG, tid, 0, saved_dabr_value) < 0) + *retp = -1; +} + /* Set up P with the parameters necessary to request a watchpoint covering LEN bytes starting at ADDR and if possible with condition expression COND evaluated by hardware. INSERT tells if we are creating a request for @@ -2000,8 +2019,6 @@ static int ppc_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw, struct expression *cond) { - struct lwp_info *lp; - ptid_t ptid; int ret = -1; if (have_ptrace_booke_interface ()) @@ -2010,8 +2027,7 @@ ppc_linux_insert_watchpoint (CORE_ADDR a create_watchpoint_request (&p, addr, len, rw, cond, 1); - ALL_LWPS (lp, ptid) - booke_insert_point (&p, TIDGET (ptid)); + linux_nat_iterate_watchpoint_lwps (booke_insert_point_callback, &p); ret = 0; } @@ -2054,12 +2070,8 @@ ppc_linux_insert_watchpoint (CORE_ADDR a saved_dabr_value = dabr_value; - ALL_LWPS (lp, ptid) - if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, - saved_dabr_value) < 0) - return -1; - ret = 0; + linux_nat_iterate_watchpoint_lwps (set_saved_dabr_value_callback, &ret); } return ret; @@ -2069,8 +2081,6 @@ static int ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw, struct expression *cond) { - struct lwp_info *lp; - ptid_t ptid; int ret = -1; if (have_ptrace_booke_interface ()) @@ -2079,20 +2089,16 @@ ppc_linux_remove_watchpoint (CORE_ADDR a create_watchpoint_request (&p, addr, len, rw, cond, 0); - ALL_LWPS (lp, ptid) - booke_remove_point (&p, TIDGET (ptid)); + linux_nat_iterate_watchpoint_lwps (booke_remove_point_callback, &p); ret = 0; } else { saved_dabr_value = 0; - ALL_LWPS (lp, ptid) - if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, - saved_dabr_value) < 0) - return -1; ret = 0; + linux_nat_iterate_watchpoint_lwps (set_saved_dabr_value_callback, &ret); } return ret; Index: gdb-7.2.90.20110525/gdb/printcmd.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/printcmd.c 2011-03-22 15:39:40.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/printcmd.c 2011-05-25 17:05:21.000000000 +0200 @@ -975,6 +975,11 @@ print_command_1 (char *exp, int inspect, else val = access_value_history (0); + /* Do not try to OBJECT_ADDRESS_SET here anything. We are interested in the + source variable base addresses as found by READ_VAR_VALUE. The value here + can be already a calculated expression address inappropriate for + DW_OP_push_object_address. */ + if (voidprint || (val && value_type (val) && TYPE_CODE (value_type (val)) != TYPE_CODE_VOID)) { @@ -1476,6 +1481,24 @@ x_command (char *exp, int from_tty) set_internalvar (lookup_internalvar ("__"), last_examine_value); } } + +#if 0 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */ + +static void +print_types_mark_used (void) +{ + struct display *d; + + if (last_examine_value) + type_mark_used (value_type (last_examine_value)); + + for (d = display_chain; d; d = d->next) + if (d->exp) + exp_types_mark_used (d->exp); +} +#endif + /* Add an expression to the auto-display chain. @@ -2870,4 +2893,8 @@ Show printing of source filename and lin add_com ("eval", no_class, eval_command, _("\ Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\ a command line, and call it.")); + +#if 0 + observer_attach_mark_used (print_types_mark_used); +#endif } Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/FrameIterator.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/FrameIterator.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,33 @@ +# Iterator over frames. + +# Copyright (C) 2008, 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +class FrameIterator: + """An iterator that iterates over frames.""" + + def __init__ (self, frame): + "Initialize a FrameIterator. FRAME is the starting frame." + self.frame = frame + + def __iter__ (self): + return self + + def next (self): + result = self.frame + if result is None: + raise StopIteration + self.frame = result.older () + return result Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/FrameWrapper.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/FrameWrapper.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,112 @@ +# Wrapper API for frames. + +# Copyright (C) 2008, 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb + +# FIXME: arguably all this should be on Frame somehow. +class FrameWrapper: + def __init__ (self, frame): + self.frame = frame; + + def write_symbol (self, stream, sym, block): + if len (sym.linkage_name): + nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block) + if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER: + sym = nsym + + stream.write (sym.print_name + "=") + try: + val = self.read_var (sym) + if val != None: + val = str (val) + # FIXME: would be nice to have a more precise exception here. + except RuntimeError, text: + val = text + if val == None: + stream.write ("???") + else: + stream.write (str (val)) + + def print_frame_locals (self, stream, func): + if not func: + return + + first = True + block = func.value + + for sym in block: + if sym.is_argument: + continue; + + self.write_symbol (stream, sym, block) + stream.write ('\n') + + def print_frame_args (self, stream, func): + if not func: + return + + first = True + block = func.value + + for sym in block: + if not sym.is_argument: + continue; + + if not first: + stream.write (", ") + + self.write_symbol (stream, sym, block) + first = False + + # FIXME: this should probably just be a method on gdb.Frame. + # But then we need stream wrappers. + def describe (self, stream, full): + if self.type () == gdb.DUMMY_FRAME: + stream.write (" \n") + elif self.type () == gdb.SIGTRAMP_FRAME: + stream.write (" \n") + else: + sal = self.find_sal () + pc = self.pc () + name = self.name () + if not name: + name = "??" + if pc != sal.pc or not sal.symtab: + stream.write (" 0x%08x in" % pc) + stream.write (" " + name + " (") + + func = self.function () + self.print_frame_args (stream, func) + + stream.write (")") + + if sal.symtab and sal.symtab.filename: + stream.write (" at " + sal.symtab.filename) + stream.write (":" + str (sal.line)) + + if not self.name () or (not sal.symtab or not sal.symtab.filename): + lib = gdb.solib_address (pc) + if lib: + stream.write (" from " + lib) + + stream.write ("\n") + + if full: + self.print_frame_locals (stream, func) + + def __getattr__ (self, name): + return getattr (self.frame, name) Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/backtrace.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/backtrace.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,42 @@ +# Filtering backtrace. + +# Copyright (C) 2008, 2011 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb +import itertools + +# Our only exports. +__all__ = ['push_frame_filter', 'create_frame_filter'] + +frame_filter = None + +def push_frame_filter (constructor): + """Register a new backtrace filter class with the 'backtrace' command. +The filter will be passed an iterator as an argument. The iterator +will return gdb.Frame-like objects. The filter should in turn act as +an iterator returning such objects.""" + global frame_filter + if frame_filter == None: + frame_filter = constructor + else: + frame_filter = lambda iterator, filter = frame_filter: constructor (filter (iterator)) + +def create_frame_filter (iter): + global frame_filter + if frame_filter is None: + return iter + return frame_filter (iter) + Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/command/alias.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/command/alias.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,59 @@ +# Alias command. + +# Copyright (C) 2008 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb + +class AliasImplementation (gdb.Command): + def __init__ (self, name, real, doc): + # Have to set __doc__ before the super init call. + # It would be nice if gdb's help looked up __doc__ dynamically. + self.__doc__ = doc + # Note: no good way to complete :( + super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE) + self.real = real + + def invoke(self, arg, from_tty): + gdb.execute (self.real + ' ' + arg, from_tty) + +class AliasCommand (gdb.Command): + """Alias one command to another. +In the simplest form, the first word is the name of the alias, and +the remaining words are the the expansion. +An '=' by itself can be used to define a multi-word alias; words +before the '=' are the name of the new command.""" + + def __init__ (self): + # Completion is not quite right here. + super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE, + gdb.COMPLETE_COMMAND) + + def invoke (self, arg, from_tty): + self.dont_repeat () + # Without some form of quoting we can't alias a multi-word + # command to another command. + args = arg.split() + try: + start = args.index ('=') + end = start + 1 + except ValueError: + start = 1 + end = 1 + target = " ".join(args[end:]) + AliasImplementation (" ".join (args[0:start]), target, + "This command is an alias for '%s'." % target) + +AliasCommand() Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/command/backtrace.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/command/backtrace.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,106 @@ +# New backtrace command. + +# Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb +import gdb.backtrace +import itertools +from gdb.FrameIterator import FrameIterator +from gdb.FrameWrapper import FrameWrapper +import sys + +class ReverseBacktraceParameter (gdb.Parameter): + """The new-backtrace command can show backtraces in 'reverse' order. +This means that the innermost frame will be printed last. +Note that reverse backtraces are more expensive to compute.""" + + set_doc = "Enable or disable reverse backtraces." + show_doc = "Show whether backtraces will be printed in reverse order." + + def __init__(self): + gdb.Parameter.__init__ (self, "reverse-backtrace", + gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN) + # Default to compatibility with gdb. + self.value = False + +class FilteringBacktrace (gdb.Command): + """Print backtrace of all stack frames, or innermost COUNT frames. +With a negative argument, print outermost -COUNT frames. +Use of the 'full' qualifier also prints the values of the local variables. +Use of the 'raw' qualifier avoids any filtering by loadable modules. +""" + + def __init__ (self): + # FIXME: this is not working quite well enough to replace + # "backtrace" yet. + gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK) + self.reverse = ReverseBacktraceParameter() + + def reverse_iter (self, iter): + result = [] + for item in iter: + result.append (item) + result.reverse() + return result + + def final_n (self, iter, x): + result = [] + for item in iter: + result.append (item) + return result[x:] + + def invoke (self, arg, from_tty): + i = 0 + count = 0 + filter = True + full = False + + for word in arg.split (" "): + if word == '': + continue + elif word == 'raw': + filter = False + elif word == 'full': + full = True + else: + count = int (word) + + # FIXME: provide option to start at selected frame + # However, should still number as if starting from newest + newest_frame = gdb.newest_frame() + iter = itertools.imap (FrameWrapper, + FrameIterator (newest_frame)) + if filter: + iter = gdb.backtrace.create_frame_filter (iter) + + # Now wrap in an iterator that numbers the frames. + iter = itertools.izip (itertools.count (0), iter) + + # Reverse if the user wanted that. + if self.reverse.value: + iter = self.reverse_iter (iter) + + # Extract sub-range user wants. + if count < 0: + iter = self.final_n (iter, count) + elif count > 0: + iter = itertools.islice (iter, 0, count) + + for pair in iter: + sys.stdout.write ("#%-2d" % pair[0]) + pair[1].describe (sys.stdout, full) + +FilteringBacktrace() Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/command/ignore_errors.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/command/ignore_errors.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,37 @@ +# Ignore errors in user commands. + +# Copyright (C) 2008 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb + +class IgnoreErrorsCommand (gdb.Command): + """Execute a single command, ignoring all errors. +Only one-line commands are supported. +This is primarily useful in scripts.""" + + def __init__ (self): + super (IgnoreErrorsCommand, self).__init__ ("ignore-errors", + gdb.COMMAND_OBSCURE, + # FIXME... + gdb.COMPLETE_COMMAND) + + def invoke (self, arg, from_tty): + try: + gdb.execute (arg, from_tty) + except: + pass + +IgnoreErrorsCommand () Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/command/pahole.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/command/pahole.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,75 @@ +# pahole command for gdb + +# Copyright (C) 2008, 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb + +class Pahole (gdb.Command): + """Show the holes in a structure. +This command takes a single argument, a type name. +It prints the type and displays comments showing where holes are.""" + + def __init__ (self): + super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE, + gdb.COMPLETE_SYMBOL) + + def pahole (self, type, level, name): + if name is None: + name = '' + tag = type.tag + if tag is None: + tag = '' + print '%sstruct %s {' % (' ' * (2 * level), tag) + bitpos = 0 + for field in type.fields (): + # Skip static fields. + if not hasattr (field, ('bitpos')): + continue + + ftype = field.type.strip_typedefs() + + if bitpos != field.bitpos: + hole = field.bitpos - bitpos + print ' /* XXX %d bit hole, try to pack */' % hole + bitpos = field.bitpos + if field.bitsize > 0: + fieldsize = field.bitsize + else: + # TARGET_CHAR_BIT here... + fieldsize = 8 * ftype.sizeof + + # TARGET_CHAR_BIT + print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)), + bitpos = bitpos + fieldsize + + if ftype.code == gdb.TYPE_CODE_STRUCT: + self.pahole (ftype, level + 1, field.name) + else: + print ' ' * (2 + 2 * level), + print '%s %s' % (str (ftype), field.name) + + print ' ' * (14 + 2 * level), + print '} %s' % name + + def invoke (self, arg, from_tty): + type = gdb.lookup_type (arg) + type = type.strip_typedefs () + if type.code != gdb.TYPE_CODE_STRUCT: + raise TypeError, '%s is not a struct type' % arg + print ' ' * 14, + self.pahole (type, 0, '') + +Pahole() Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/command/require.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/command/require.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,57 @@ +# Demand-loading commands. + +# Copyright (C) 2008, 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb +import os + +class RequireCommand (gdb.Command): + """Prefix command for requiring features.""" + + def __init__ (self): + super (RequireCommand, self).__init__ ("require", + gdb.COMMAND_SUPPORT, + gdb.COMPLETE_NONE, + True) + +class RequireSubcommand (gdb.Command): + """Demand-load a command by name.""" + + def __init__ (self, name): + self.__doc__ = "Demand-load a %s by name." % name + super (RequireSubcommand, self).__init__ ("require %s" % name, + gdb.COMMAND_SUPPORT) + self.name = name + + def invoke (self, arg, from_tty): + for cmd in arg.split(): + exec ('import gdb.' + self.name + '.' + cmd, globals ()) + + def complete (self, text, word): + dir = gdb.pythondir + '/gdb/' + self.name + result = [] + for file in os.listdir(dir): + if not file.startswith (word) or not file.endswith ('.py'): + continue + feature = file[0:-3] + if feature == 'require' or feature == '__init__': + continue + result.append (feature) + return result + +RequireCommand() +RequireSubcommand("command") +RequireSubcommand("function") Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/command/upto.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/command/upto.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,129 @@ +# upto command. + +# Copyright (C) 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb +import re +from gdb.FrameIterator import FrameIterator +from gdb.FrameWrapper import FrameWrapper + +class UptoPrefix (gdb.Command): + def __init__ (self): + super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK, + prefix = True) + +class UptoImplementation (gdb.Command): + def __init__ (self, subcommand): + super (UptoImplementation, self).__init__ ("upto " + subcommand, + gdb.COMMAND_STACK) + + def search (self): + saved = gdb.selected_frame () + iter = FrameIterator (saved) + found = False + try: + for frame in iter: + frame.select () + try: + if self.filter (frame): + wrapper = FrameWrapper (frame) + wrapper.describe (sys.stdout, False) + return + except: + pass + except: + pass + saved.select () + raise RuntimeError, 'Could not find a matching frame' + + def invoke (self, arg, from_tty): + self.rx = re.compile (arg) + self.search () + +class UptoSymbolCommand (UptoImplementation): + """Select and print some calling stack frame, based on symbol. +The argument is a regular expression. This command moves up the +stack, stopping at the first frame whose symbol matches the regular +expression.""" + + def __init__ (self): + super (UptoSymbolCommand, self).__init__ ("symbol") + + def filter (self, frame): + name = frame.name () + if name is not None: + if self.rx.search (name) is not None: + return True + return False + +class UptoSourceCommand (UptoImplementation): + """Select and print some calling stack frame, based on source file. +The argument is a regular expression. This command moves up the +stack, stopping at the first frame whose source file name matches the +regular expression.""" + + def __init__ (self): + super (UptoSourceCommand, self).__init__ ("source") + + def filter (self, frame): + name = frame.find_sal ().symtab.filename + if name is not None: + if self.rx.search (name) is not None: + return True + return False + +class UptoObjectCommand (UptoImplementation): + """Select and print some calling stack frame, based on object file. +The argument is a regular expression. This command moves up the +stack, stopping at the first frame whose object file name matches the +regular expression.""" + + def __init__ (self): + super (UptoObjectCommand, self).__init__ ("object") + + def filter (self, frame): + name = frame.find_sal ().symtab.objfile.filename + if name is not None: + if self.rx.search (name) is not None: + return True + return False + +class UptoWhereCommand (UptoImplementation): + """Select and print some calling stack frame, based on expression. +The argument is an expression. This command moves up the stack, +parsing and evaluating the expression in each frame. This stops when +the expression evaluates to a non-zero (true) value.""" + + def __init__ (self): + super (UptoWhereCommand, self).__init__ ("where") + + def filter (self, frame): + try: + if gdb.parse_and_eval (self.expression): + return True + except: + pass + return False + + def invoke (self, arg, from_tty): + self.expression = arg + self.search () + +UptoPrefix () +UptoSymbolCommand () +UptoSourceCommand () +UptoObjectCommand () +UptoWhereCommand () Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/function/__init__.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/function/__init__.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1 @@ + Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/function/caller_is.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/function/caller_is.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,58 @@ +# Caller-is functions. + +# Copyright (C) 2008 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb +import re + +class CallerIs (gdb.Function): + """Return True if the calling function's name is equal to a string. +This function takes one or two arguments. +The first argument is the name of a function; if the calling function's +name is equal to this argument, this function returns True. +The optional second argument tells this function how many stack frames +to traverse to find the calling function. The default is 1.""" + + def __init__ (self): + super (CallerIs, self).__init__ ("caller_is") + + def invoke (self, name, nframes = 1): + frame = gdb.selected_frame () + while nframes > 0: + frame = frame.older () + nframes = nframes - 1 + return frame.name () == name.string () + +class CallerMatches (gdb.Function): + """Return True if the calling function's name matches a string. +This function takes one or two arguments. +The first argument is a regular expression; if the calling function's +name is matched by this argument, this function returns True. +The optional second argument tells this function how many stack frames +to traverse to find the calling function. The default is 1.""" + + def __init__ (self): + super (CallerMatches, self).__init__ ("caller_matches") + + def invoke (self, name, nframes = 1): + frame = gdb.selected_frame () + while nframes > 0: + frame = frame.older () + nframes = nframes - 1 + return re.match (name.string (), frame.name ()) is not None + +CallerIs() +CallerMatches() Index: gdb-7.2.90.20110525/gdb/python/lib/gdb/function/in_scope.py =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/python/lib/gdb/function/in_scope.py 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,47 @@ +# In-scope function. + +# Copyright (C) 2008 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +import gdb + +class InScope (gdb.Function): + """Return True if all the given variables or macros are in scope. +Takes one argument for each variable name to be checked.""" + + def __init__ (self): + super (InScope, self).__init__ ("in_scope") + + def invoke (self, *vars): + if len (vars) == 0: + raise TypeError, "in_scope takes at least one argument" + + # gdb.Value isn't hashable so it can't be put in a map. + # Convert to string first. + wanted = set (map (lambda x: x.string (), vars)) + found = set () + block = gdb.selected_frame ().block () + while block: + for sym in block: + if (sym.is_argument or sym.is_constant + or sym.is_function or sym.is_variable): + if sym.name in wanted: + found.add (sym.name) + + block = block.superblock + + return wanted == found + +InScope () Index: gdb-7.2.90.20110525/gdb/python/py-type.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/python/py-type.c 2011-01-26 21:53:45.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/python/py-type.c 2011-05-25 17:05:21.000000000 +0200 @@ -29,6 +29,8 @@ #include "language.h" #include "vec.h" #include "bcache.h" +#include "observer.h" +#include "gdb_assert.h" typedef struct pyty_type_object { @@ -37,11 +39,19 @@ typedef struct pyty_type_object /* If a Type object is associated with an objfile, it is kept on a doubly-linked list, rooted in the objfile. This lets us copy the - underlying struct type when the objfile is deleted. */ + underlying struct type when the objfile is deleted. + + With NULL objfile Type still can be doubly-linked in the list + PYTY_OBJECTS_DISCARDABLE. */ struct pyty_type_object *prev; struct pyty_type_object *next; } type_object; +#if 0 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types. */ +static type_object *pyty_objects_discardable; +#endif + static PyTypeObject type_object_type; /* A Field object. */ @@ -919,8 +929,63 @@ typy_richcompare (PyObject *self, PyObje +/* Key associated with each objfile pointing to the first element of + a doubly-linked list of Types associated with this objfile. */ static const struct objfile_data *typy_objfile_data_key; +/* Link TYPE_OBJ to its appropriate list. Either to its objfile associated one + or at least to the global list for TYPE_DISCARDABLE Types. Permanent types + do not get linked anywhere. */ +static void +typy_link (type_object *type_obj) +{ + type_obj->prev = NULL; + + if (type_obj->type && TYPE_OBJFILE (type_obj->type)) + { + struct objfile *objfile = TYPE_OBJFILE (type_obj->type); + + type_obj->next = objfile_data (objfile, typy_objfile_data_key); + if (type_obj->next) + type_obj->next->prev = type_obj; + set_objfile_data (objfile, typy_objfile_data_key, type_obj); + } +#if 0 + else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type)) + { + type_obj->next = pyty_objects_discardable; + if (type_obj->next) + type_obj->next->prev = type_obj; + pyty_objects_discardable = type_obj; + } +#endif + else + type_obj->next = NULL; +} + +/* Unlink TYPE_OBJ from its current list. Permanent types are not linked + anywhere and this function has no effect on them. */ +static void +typy_unlink (type_object *type_obj) +{ + if (type_obj->prev) + type_obj->prev->next = type_obj->next; + else if (type_obj->type && TYPE_OBJFILE (type_obj->type)) + { + /* Must reset head of list. */ + struct objfile *objfile = TYPE_OBJFILE (type_obj->type); + + set_objfile_data (objfile, typy_objfile_data_key, type_obj->next); + } +#if 0 + else if (pyty_objects_discardable == type_obj) + pyty_objects_discardable = type_obj->next; +#endif + + if (type_obj->next) + type_obj->next->prev = type_obj->prev; +} + static void save_objfile_types (struct objfile *objfile, void *datum) { @@ -938,12 +1003,13 @@ save_objfile_types (struct objfile *objf { type_object *next = obj->next; - htab_empty (copied_types); + gdb_assert (TYPE_OBJFILE (obj->type) == objfile); + typy_unlink (obj); - obj->type = copy_type_recursive (objfile, obj->type, copied_types); + obj->type = copy_type_recursive (obj->type, copied_types); - obj->next = NULL; - obj->prev = NULL; + gdb_assert (TYPE_OBJFILE (obj->type) == NULL); + typy_link (obj); obj = next; } @@ -954,43 +1020,28 @@ save_objfile_types (struct objfile *objf } static void -set_type (type_object *obj, struct type *type) +typy_dealloc (PyObject *obj) { - obj->type = type; - obj->prev = NULL; - if (type && TYPE_OBJFILE (type)) - { - struct objfile *objfile = TYPE_OBJFILE (type); - - obj->next = objfile_data (objfile, typy_objfile_data_key); - if (obj->next) - obj->next->prev = obj; - set_objfile_data (objfile, typy_objfile_data_key, obj); - } - else - obj->next = NULL; + type_object *type_obj = (type_object *) obj; + + typy_unlink (type_obj); + + type_obj->ob_type->tp_free (obj); } +#if 0 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */ static void -typy_dealloc (PyObject *obj) +typy_types_mark_used (void) { - type_object *type = (type_object *) obj; - - if (type->prev) - type->prev->next = type->next; - else if (type->type && TYPE_OBJFILE (type->type)) - { - /* Must reset head of list. */ - struct objfile *objfile = TYPE_OBJFILE (type->type); - - if (objfile) - set_objfile_data (objfile, typy_objfile_data_key, type->next); - } - if (type->next) - type->next->prev = type->prev; + type_object *type_obj; - type->ob_type->tp_free (type); + for (type_obj = pyty_objects_discardable; + type_obj != NULL; + type_obj = type_obj->next) + type_mark_used (type_obj->type); } +#endif /* Create a new Type referring to TYPE. */ PyObject * @@ -1000,7 +1051,10 @@ type_to_type_object (struct type *type) type_obj = PyObject_New (type_object, &type_object_type); if (type_obj) - set_type (type_obj, type); + { + type_obj->type = type; + typy_link (type_obj); + } return (PyObject *) type_obj; } @@ -1074,6 +1128,10 @@ gdbpy_initialize_types (void) Py_INCREF (&field_object_type); PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type); + +#if 0 + observer_attach_mark_used (typy_types_mark_used); +#endif } Index: gdb-7.2.90.20110525/gdb/python/py-value.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/python/py-value.c 2011-03-18 17:09:57.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/python/py-value.c 2011-05-25 17:05:21.000000000 +0200 @@ -28,6 +28,7 @@ #include "infcall.h" #include "expression.h" #include "cp-abi.h" +#include "observer.h" #ifdef HAVE_PYTHON @@ -1210,6 +1211,19 @@ gdbpy_is_value_object (PyObject *obj) return PyObject_TypeCheck (obj, &value_object_type); } +#if 0 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */ + +static void +python_types_mark_used (void) +{ + value_object *iter; + + for (iter = values_in_python; iter; iter = iter->next) + type_mark_used (value_type (iter->value)); +} +#endif + void gdbpy_initialize_values (void) { @@ -1220,6 +1234,10 @@ gdbpy_initialize_values (void) PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type); values_in_python = NULL; + +#if 0 + observer_attach_mark_used (python_types_mark_used); +#endif } Index: gdb-7.2.90.20110525/gdb/python/python.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/python/python.c 2011-03-18 09:44:47.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/python/python.c 2011-05-25 17:05:21.000000000 +0200 @@ -49,8 +49,11 @@ static int gdbpy_should_print_stack = 1; #include "linespec.h" #include "source.h" #include "version.h" +#include "inferior.h" +#include "gdbthread.h" #include "target.h" #include "gdbthread.h" +#include "event-top.h" static PyMethodDef GdbMethods[]; @@ -769,6 +772,53 @@ gdbpy_print_stack (void) /* Return the current Progspace. There always is one. */ +/* True if 'gdb -P' was used, false otherwise. */ +static int running_python_script; + +/* True if we are currently in a call to 'gdb.cli', false otherwise. */ +static int in_cli; + +/* Enter the command loop. */ + +static PyObject * +gdbpy_cli (PyObject *unused1, PyObject *unused2) +{ + if (! running_python_script || in_cli) + return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively"); + + in_cli = 1; + cli_command_loop (); + in_cli = 0; + + Py_RETURN_NONE; +} + +/* Set up the Python argument vector and evaluate a script. This is + used to implement 'gdb -P'. */ + +void +run_python_script (int argc, char **argv) +{ + FILE *input; + + /* We never free this, since we plan to exit at the end. */ + ensure_python_env (get_current_arch (), current_language); + + running_python_script = 1; + PySys_SetArgv (argc - 1, argv + 1); + input = fopen (argv[0], "r"); + if (! input) + { + fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno)); + exit (1); + } + PyRun_SimpleFile (input, argv[0]); + fclose (input); + exit (0); +} + + + static PyObject * gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2) @@ -1194,6 +1244,8 @@ static PyMethodDef GdbMethods[] = "Get a value from history" }, { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS, "Execute a gdb command" }, + { "cli", gdbpy_cli, METH_NOARGS, + "Enter the gdb CLI" }, { "parameter", gdbpy_parameter, METH_VARARGS, "Return a gdb parameter's value" }, Index: gdb-7.2.90.20110525/gdb/python/python.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/python/python.h 2011-03-14 17:09:54.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/python/python.h 2011-05-25 17:05:21.000000000 +0200 @@ -32,6 +32,8 @@ void eval_python_from_control_command (s void source_python_script (FILE *stream, const char *file); +void run_python_script (int argc, char **argv); + int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, Index: gdb-7.2.90.20110525/gdb/somread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/somread.c 2011-03-07 17:17:29.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/somread.c 2011-05-25 17:05:21.000000000 +0200 @@ -439,6 +439,7 @@ static const struct sym_fns som_sym_fns default_symfile_segments, /* Get segment information from a file. */ NULL, default_symfile_relocate, /* Relocate a debug section. */ + NULL, /* sym_get_probes */ &psym_functions }; Index: gdb-7.2.90.20110525/gdb/stack.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/stack.c 2011-03-18 19:48:56.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/stack.c 2011-05-25 17:05:21.000000000 +0200 @@ -366,6 +366,7 @@ print_frame_args (struct symbol *func, s { const struct language_defn *language; struct value_print_options opts; + struct cleanup *old_chain; /* Use the appropriate language to display our symbol, unless the user forced the language to a specific @@ -378,7 +379,13 @@ print_frame_args (struct symbol *func, s get_raw_print_options (&opts); opts.deref_ref = 0; opts.summary = summary; + + /* Frame may be needed for check_typedef of TYPE_DYNAMIC. */ + old_chain = make_cleanup_restore_selected_frame (); + select_frame (frame); common_val_print (val, stb->stream, 2, &opts, language); + do_cleanups (old_chain); + ui_out_field_stream (uiout, "value", stb); } else Index: gdb-7.2.90.20110525/gdb/stap-probe.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/stap-probe.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,2041 @@ +/* SystemTap probe support for GDB. + + Copyright (C) 2011 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#include "defs.h" +#include "stap-probe.h" +#include "vec.h" +#include "ui-out.h" +#include "gdb_regex.h" +#include "objfiles.h" +#include "arch-utils.h" +#include "command.h" +#include "filenames.h" +#include "value.h" +#include "exceptions.h" +#include "ax.h" +#include "ax-gdb.h" +#include "user-regs.h" +#include "complaints.h" +#include "cli/cli-utils.h" +#include "linespec.h" + +#include + +/* This define is used to inform whether we are compiling an agent + expression or not. */ + +#define STAP_COMPILING_AGENT_EXPR_P(eval_info) \ + (eval_info->aexpr != NULL) + +/* The various possibilities of bitness defined for a probe's argument. + + The relationship is: + + - STAP_ARG_BITNESS_UNDEFINED: The user hasn't specified the bitness. + - STAP_ARG_BITNESS_32BIT_UNSIGNED: argument string starts with `4@'. + - STAP_ARG_BITNESS_32BIT_SIGNED: argument string starts with `-4@'. + - STAP_ARG_BITNESS_64BIT_UNSIGNED: argument string starts with `8@'. + - STAP_ARG_BITNESS_64BIT_SIGNED: argument string starts with `-8@'. */ + +enum stap_arg_bitness +{ + STAP_ARG_BITNESS_UNDEFINED, + STAP_ARG_BITNESS_32BIT_UNSIGNED, + STAP_ARG_BITNESS_32BIT_SIGNED, + STAP_ARG_BITNESS_64BIT_UNSIGNED, + STAP_ARG_BITNESS_64BIT_SIGNED, +}; + +/* The following structure represents a single argument for the probe. */ + +struct stap_probe_arg +{ + /* The bitness of this argument. */ + enum stap_arg_bitness bitness; + + /* The string representing this argument. */ + char *arg_str; +}; + +/* The maximum number of arguments that a probe can have, + as defined in . */ + +#define STAP_MAX_ARGS 10 + +/* Structure that holds information about all arguments of a probe. */ + +struct stap_args_info +{ + /* The number of valid parsed arguments. */ + int n_args; + + /* The probe to which these arguments belong. */ + struct stap_probe *probe; + + /* Information about each argument. */ + struct stap_probe_arg *arg; +}; + +/* Structure that contains all the necessary information to evaluate + an expression. */ + +struct stap_evaluation_info +{ + /* The constant pointer which holds the expression. This is primarily + used for printing error messages. Evaluation functions should + not modify this pointer directly; instead, they should use the + EXP_BUFFER pointer below. */ + const char *saved_expr; + + /* Modifiable version of the above pointer. */ + char *exp_buf; + + /* The pointer to the current gdbarch. */ + struct gdbarch *gdbarch; + + /* The pointer to the current frame, used when accessing registers' + contents. */ + struct frame_info *frame; + + /* The bitness specified for this argument. */ + enum stap_arg_bitness bitness; + + /* If the above flag is true (one), this field will contain the + pointer to the agent expression. */ + struct agent_expr *aexpr; + + /* The value we are modifying (for agent expression). */ + struct axs_value *avalue; +}; + +/* This dummy variable is used when parsing a probe's argument fails. + In this case, the number of arguments for this probe is zero, so that's + why this variable is useful. */ + +static struct stap_args_info dummy_stap_args_info = + { 0, NULL, NULL }; + +static struct value *stap_evaluate_probe_argument_2 + (struct stap_evaluation_info *eval_info, + struct value *lhs, int prec); + +static struct value *stap_evaluate_conditionally + (struct stap_evaluation_info *eval_info); + +/* Helper function which decides to skip whitespaces or not in a probe's + argument string. Basically, if we are inside a parenthesis expression + (i.e., inside a subexpression), we can skip whitespaces; otherwise we + cannot. */ + +static void +stap_skip_whitespace_cond (char **s, int inside_paren) +{ + if (inside_paren) + *s = skip_spaces (*s); +} + +/* Helper function which parses a single argument in a probe's argument + string, based on various rules (which can be learned from the `gas' + manual). It returns 1 on success, or 0 otherwise. */ + +static int +stap_parse_arg (const char **p) +{ + char *cur = (char *) *p; + int done = 0; + int paren_open = 0; + + while (!done) + { + switch (*cur) + { + case ' ': case 0: + /* If we're here, then we have already parsed everything + from this argument. */ + if (paren_open) + return 0; + done = 1; + break; + + case '(': + ++paren_open; + ++cur; + stap_skip_whitespace_cond (&cur, paren_open); + break; + + case ')': + if (!paren_open) + return 0; + + --paren_open; + ++cur; + if (paren_open) + cur = skip_spaces (cur); + break; + + case '+': case '-': + case '*': case '/': + case '>': case '<': case '|': case '&': + case '^': case '!': + { + char c = *cur; + + ++cur; + switch (*cur) + { + case '>': + if (c != '<' && c != '>') + return 0; + + ++cur; + break; + + case '<': + if (c != '<') + return 0; + + ++cur; + break; + + case '=': + if (c != '=' && c != '<' && c != '>' && c != '!') + return 0; + + ++cur; + break; + + case '|': + if (c != '|') + return 0; + + ++cur; + break; + + case '&': + if (c != '&') + return 0; + + ++cur; + break; + + default: + break; + } + /* Infix operators take two arguments, one on either + side. Skipping the whitespaces that may happen on the + right side. */ + stap_skip_whitespace_cond (&cur, paren_open); + } + break; + + case '%': + { + ++cur; + stap_skip_whitespace_cond (&cur, paren_open); + if (*cur >= 'a' && *cur <= 'z') + { + /* We're dealing with a register name. */ + while (isalnum (*cur)) + ++cur; + + stap_skip_whitespace_cond (&cur, paren_open); + + /* Some registers (e.g. floating-point register stack + registers on Intel i386) have the following syntax: + + `%st(0)', `%st(1)', and so on. + + So it's ok to expect parenthesis here. */ + if (*cur == '(') + { + ++cur; + stap_skip_whitespace_cond (&cur, paren_open); + if (!isdigit (*cur)) + /* This is an error, since we only expect numbers + inside this parenthesis. */ + return 0; + ++cur; + stap_skip_whitespace_cond (&cur, paren_open); + if (*cur != ')') + /* We only expect one number. */ + return 0; + ++cur; + stap_skip_whitespace_cond (&cur, paren_open); + } + } + } + break; + + case '$': + { + /* This is an integer constant. */ + ++cur; + stap_skip_whitespace_cond (&cur, paren_open); + + while (isdigit (*cur)) + ++cur; + + stap_skip_whitespace_cond (&cur, paren_open); + } + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + char *old = cur; + + /* Number. */ + while (isdigit (*cur)) + ++cur; + + /* We have to do a lookahead here, because the user may + input `2 + 2' (with spaces), and this is not an error. */ + cur = skip_spaces (cur); + + switch (*cur) + { + case '+': case '-': + /* We may find the `@' sign, and it means that the + argument has finished, so we shouldn't advance the + pointer. */ + if (cur[1] && (cur[1] == '4' || cur[1] == '8') + && cur[2] && cur[2] == '@') + { + cur = old; + goto fin; + } + break; + + case '*': case '/': case '>': case '<': + case '|': case '&': case '^': case '!': + /* This is a binary operation, which means we'll + have to find another number after the operator. */ + break; + + case '(': + /* We may also have sentences in the form: + + `4 (%rax)' */ + break; + } + } +fin: + break; + } + } + + *p = cur; + + return 1; +} + +/* Helper function which is responsible for freeing the space allocated to + hold information about a probe's arguments. */ + +static void +stap_free_args_info (void *args_info_ptr) +{ + struct stap_args_info *a = (struct stap_args_info *) args_info_ptr; + int i; + + for (i = 0; i < a->n_args; i++) + { + xfree (a->arg[i].arg_str); + } + + xfree (a->arg); + xfree (a); +} + +/* Function which parses an argument string from PROBE, correctly splitting + the arguments and storing their information in properly ways. This function + only separates the arguments, but does not evaluate them. + + Consider the following argument string: + + `4@%eax 4@$10' + + We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness. + This function basically handles them, properly filling some structures with + this information. */ + +static void +stap_parse_probe_arguments (struct stap_probe *probe) +{ + struct stap_args_info *args_info; + struct cleanup *back_to; + const char *cur = probe->args; + int current_arg = -1; + /* This is a state-machine parser, which means we will always be + in a known state when parsing an argument. The state could be + either `NEW_ARG' if we are parsing a new argument, `BITNESS' if + we are parsing the bitness-definition part (i.e., `4@'), or + `PARSE_ARG' if we are actually parsing the argument part. */ + enum + { + NEW_ARG, + BITNESS, + PARSE_ARG, + } current_state; + + /* For now, we assume everything is not going to work. */ + probe->parsed_args = &dummy_stap_args_info; + + if (!cur || !*cur || *cur == ':') + return; + + args_info = xmalloc (sizeof (struct stap_args_info)); + back_to = make_cleanup (stap_free_args_info, args_info); + args_info->arg = xcalloc (STAP_MAX_ARGS, sizeof (struct stap_probe_arg)); + + /* Ok, let's start. */ + current_state = NEW_ARG; + + while (*cur) + { + switch (current_state) + { + case NEW_ARG: + ++current_arg; + + if (current_arg >= STAP_MAX_ARGS) + { + complaint (&symfile_complaints, + _("probe `%s' has more arguments than the maximum " + "allowed"), probe->name); + do_cleanups (back_to); + return; + } + + current_state = BITNESS; + break; + + case BITNESS: + { + enum stap_arg_bitness b; + int got_minus = 0; + + /* We expect to find something like: + + N@OP + + Where `N' can be [+,-][4,8]. This is not mandatory, so + we check it here. If we don't find it, go to the next + state. */ + if ((*cur == '-' && cur[1] && cur[2] != '@') + && cur[1] != '@') + { + current_state = PARSE_ARG; + args_info->arg[current_arg].bitness + = STAP_ARG_BITNESS_UNDEFINED; + break; + } + + if (*cur == '-') + { + /* Discard the `-'. */ + ++cur; + got_minus = 1; + } + + if (*cur == '4') + b = got_minus ? STAP_ARG_BITNESS_32BIT_SIGNED + : STAP_ARG_BITNESS_32BIT_UNSIGNED; + else if (*cur == '8') + b = got_minus ? STAP_ARG_BITNESS_64BIT_SIGNED + : STAP_ARG_BITNESS_64BIT_UNSIGNED; + else + { + /* We have an error, because we don't expect anything + except 4 and 8. */ + complaint (&symfile_complaints, + _("unrecognized bitness `%c' for probe `%s'"), + *cur, probe->name); + do_cleanups (back_to); + return; + } + + args_info->arg[current_arg].bitness = b; + /* Discard the number and the `@' sign. */ + cur += 2; + /* Move on. */ + current_state = PARSE_ARG; + } + break; + + case PARSE_ARG: + { + const char *start = cur; + + if (!stap_parse_arg (&cur)) + { + /* We have tried to parse this argument, but it's + malformed. This is an error. */ + do_cleanups (back_to); + return; + } + + args_info->arg[current_arg].arg_str + = savestring (start, cur - start); + /* Start it over again. */ + cur = skip_spaces ((char *) cur); + current_state = NEW_ARG; + } + break; + } + + if (!*cur && current_state != NEW_ARG) + { + /* We reached the end of the argument string, but we're + still in the middle of the process of parsing an argument. + It means the argument string is malformed. */ + complaint (&symfile_complaints, + _("malformed argument for probe `%s'"), + probe->name); + do_cleanups (back_to); + return; + } + } + + args_info->n_args = current_arg + 1; + args_info->arg = xrealloc (args_info->arg, + args_info->n_args + * sizeof (struct stap_probe_arg)); + args_info->probe = probe; + + probe->parsed_args = args_info; + + discard_cleanups (back_to); +} + +/* See definition in stap-probe.h. */ + +int +stap_get_probe_argument_count (const struct stap_probe *probe) +{ + if (!probe->parsed_args) + stap_parse_probe_arguments ((struct stap_probe *) probe); + + return probe->parsed_args->n_args; +} + +/* Returns the operator precedence level of OP, or zero if the operator + code was not recognized. + The levels were taken from the gas manual. */ + +static int +stap_get_operator_prec (enum exp_opcode op) +{ + switch (op) + { + case BINOP_LOGICAL_OR: + return 1; + + case BINOP_LOGICAL_AND: + return 2; + + case BINOP_ADD: case BINOP_SUB: + case BINOP_EQUAL: case BINOP_NOTEQUAL: + case BINOP_LESS: case BINOP_LEQ: + case BINOP_GTR: case BINOP_GEQ: + return 3; + + case BINOP_BITWISE_IOR: case BINOP_BITWISE_AND: + case BINOP_BITWISE_XOR: case UNOP_LOGICAL_NOT: + return 4; + + case BINOP_MUL: case BINOP_DIV: case BINOP_REM: + case BINOP_LSH: case BINOP_RSH: + return 5; + + default: + return 0; + } +} + +/* Given S, this function reads the operator in it and fills the OP + pointer with its code. Returns 1 on success, zero if the operator + was not recognized. */ + +static int +stap_get_opcode (char **s, enum exp_opcode *op) +{ + char c = **s; + int ret = 1; + + *s += 1; + + switch (c) + { + case '*': + *op = BINOP_MUL; + break; + + case '/': + *op = BINOP_DIV; + break; + + case '%': + { + if (isalpha (**s)) + { + /* Dealing with a register name. */ + ret = 0; + break; + } + + *op = BINOP_REM; + } + break; + + case '<': + *op = BINOP_LESS; + if (**s == '<') + { + *s += 1; + *op = BINOP_LSH; + } + else if (**s == '=') + { + *s += 1; + *op = BINOP_LEQ; + } + else if (**s == '>') + { + *s += 1; + *op = BINOP_NOTEQUAL; + } + break; + + case '>': + *op = BINOP_GTR; + if (**s == '>') + { + *s += 1; + *op = BINOP_RSH; + } + else if (**s == '=') + { + *s += 1; + *op = BINOP_GEQ; + } + break; + + case '|': + *op = BINOP_BITWISE_IOR; + if (**s == '|') + { + *s += 1; + *op = BINOP_LOGICAL_OR; + } + break; + + case '&': + *op = BINOP_BITWISE_AND; + if (**s == '&') + { + *s += 1; + *op = BINOP_LOGICAL_AND; + } + break; + + case '^': + *op = BINOP_BITWISE_XOR; + break; + + case '!': + *op = UNOP_LOGICAL_NOT; + break; + + case '+': + *op = BINOP_ADD; + break; + + case '-': + *op = BINOP_SUB; + break; + + case '=': + if (**s != '=') + { + ret = 0; + break; + } + *op = BINOP_EQUAL; + break; + + default: + /* We didn't find any operator. */ + *s -= 1; + return 0; + } + + return ret; +} + +/* Given the operator OPCODE, this function generates agent bytecode + for it. */ + +static void +stap_opcode_to_ax (struct stap_evaluation_info *eval_info, + enum exp_opcode opcode) +{ + struct agent_expr *expr = eval_info->aexpr; + + switch (opcode) + { + case BINOP_MUL: + ax_simple (expr, aop_mul); + break; + + case BINOP_DIV: + ax_simple (expr, aop_div_signed); + break; + + case BINOP_REM: + ax_simple (expr, aop_rem_unsigned); + break; + + case BINOP_LESS: + ax_simple (expr, aop_less_signed); + break; + + case BINOP_LEQ: + /* A <= B is !(B < A) */ + ax_simple (expr, aop_swap); + ax_simple (expr, aop_less_signed); + ax_simple (expr, aop_log_not); + break; + + case BINOP_GTR: + /* A > B is B < A */ + ax_simple (expr, aop_swap); + ax_simple (expr, aop_less_signed); + break; + + case BINOP_GEQ: + /* A >= B is !(A < B) */ + ax_simple (expr, aop_less_signed); + ax_simple (expr, aop_log_not); + break; + + case BINOP_NOTEQUAL: + ax_simple (expr, aop_equal); + ax_simple (expr, aop_log_not); + break; + + case BINOP_LSH: + ax_simple (expr, aop_lsh); + break; + + case BINOP_RSH: + ax_simple (expr, aop_rsh_unsigned); + break; + + case BINOP_BITWISE_IOR: + ax_simple (expr, aop_bit_or); + break; + + case BINOP_LOGICAL_OR: + error (_("Operator logical-or (`||') not supported yet.")); + break; + + case BINOP_BITWISE_AND: + ax_simple (expr, aop_bit_and); + break; + + case BINOP_LOGICAL_AND: + error (_("Operator logical-and (`&&') not supported yet.")); + break; + + case BINOP_BITWISE_XOR: + ax_simple (expr, aop_bit_xor); + break; + + case UNOP_LOGICAL_NOT: + ax_simple (expr, aop_log_not); + break; + + case BINOP_ADD: + ax_simple (expr, aop_add); + break; + + case BINOP_SUB: + ax_simple (expr, aop_sub); + break; + + case BINOP_EQUAL: + ax_simple (expr, aop_equal); + break; + + default: + error (_("Invalid operator.")); + } +} + +/* Returns 1 if *S is an operator, zero otherwise. */ + +static int +stap_is_operator (char *s) +{ + char op; + + if (!s || !*s) + return 0; + + op = *s; + + if (*s == '%' && isalpha (s[1])) + /* Register name. */ + return 0; + + return (op == '+' || op == '-' || op == '*' || op == '/' + || op == '>' || op == '<' || op == '!' || op == '^' + || op == '|' || op == '&' || op == '%' || op == '='); +} + +/* This function fetches the value of the register whose + name starts in the expression buffer. It also applies any register + displacements (e.g., `-4(%eax)'), and indirects the contents of the + register (e.g., `(%eax)'). It returns RET if the operation has succeeded, + or calls `error' otherwise. */ + +static struct value * +stap_fetch_reg_value (struct stap_evaluation_info *eval_info, + struct value *displacement) +{ + const char *start; + char *s = eval_info->exp_buf; + struct gdbarch *gdbarch = eval_info->gdbarch; + struct frame_info *frame = eval_info->frame; + enum stap_arg_bitness bitness = eval_info->bitness; + char *regname; + int len, regnum, indirect_p = 0; + struct value *ret = NULL; + + /* The function which called us did not check if the expression + buffer was empty. */ + gdb_assert (s && *s); + + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + /* If we are compiling, we cannot return NULL because that would + lead to errors in future evaluations. That's why we just make + this dummy value, representing that the return value of this + function is not NULL. */ + ret = value_from_longest (builtin_type (gdbarch)->builtin_int, 0); + + /* Valid register name on x86 platforms are: + + [paren]%{a-z0-9}[paren] + + Let's check for that here. */ + if (*s == '(') + { + ++s; + if (!*s || *s != '%' + || (*s == '%' && !isalpha (s[1]))) + error (_("Invalid register name on expression `%s'."), + eval_info->saved_expr); + ++s; + /* The presence of parenthesis means that we want to indirect + the register. */ + indirect_p = 1; + } + else if (*s == '%') + { + ++s; + if (!*s || !isalpha (*s)) + error (_("Invalid register name on expression `%s'."), + eval_info->saved_expr); + } + else + error (_("Invalid register name on expression `%s'."), + eval_info->saved_expr); + + if (displacement && !indirect_p) + /* We cannot apply displacement to non-indirect register access. */ + error (_("Trying to apply displacement without indirecting register " + "on expression `%s'."), eval_info->saved_expr); + + /* Ok, let's calculate the size of the register name. */ + start = s; + while (isalnum (*s)) + ++s; + + len = s - start; + + if (indirect_p && *s == ')') + ++s; + + regname = alloca (len + 1); + strncpy (regname, start, len); + regname[len] = '\0'; + + /* Translating the register name into the corresponding number. */ + regnum = user_reg_map_name_to_regnum (gdbarch, regname, len); + + if (regnum == -1) + error (_("Invalid register name `%s' on expression `%s'."), + regname, eval_info->saved_expr); + + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + ax_reg (eval_info->aexpr, regnum); + else + ret = value_of_register (regnum, frame); + + if (indirect_p) + { + struct type *t = NULL; + enum agent_op aop = aop_ref32; + + /* If the user has specified that the register must be indirected, + we should know what's the correct type to cast it before making + the indirection. This type corresponds to the bitness specified + before the `@' sign on the argument string, or it defaults to + `unsigned long' if the `@' were not present. */ + + switch (bitness) + { + case STAP_ARG_BITNESS_UNDEFINED: + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + { + if (gdbarch_addr_bit (gdbarch) == 32) + aop = aop_ref32; + else + aop = aop_ref64; + } + else + { + if (gdbarch_addr_bit (gdbarch) == 32) + t = lookup_pointer_type + (builtin_type (gdbarch)->builtin_uint32); + else + t = lookup_pointer_type + (builtin_type (gdbarch)->builtin_uint64); + } + break; + + case STAP_ARG_BITNESS_32BIT_SIGNED: + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + aop = aop_ref32; + else + t = lookup_pointer_type + (builtin_type (gdbarch)->builtin_int32); + break; + + case STAP_ARG_BITNESS_32BIT_UNSIGNED: + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + aop = aop_ref32; + else + t = lookup_pointer_type + (builtin_type (gdbarch)->builtin_uint32); + break; + + case STAP_ARG_BITNESS_64BIT_SIGNED: + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + aop = aop_ref64; + else + t = lookup_pointer_type + (builtin_type (gdbarch)->builtin_int64); + break; + + case STAP_ARG_BITNESS_64BIT_UNSIGNED: + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + aop = aop_ref64; + else + t = lookup_pointer_type + (builtin_type (gdbarch)->builtin_uint64); + break; + + default: + internal_error (__FILE__, __LINE__, + _("Undefined bitness for probe.")); + break; + } + + if (displacement) + { + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + { + ax_const_l (eval_info->aexpr, value_as_long (displacement)); + ax_simple (eval_info->aexpr, aop_add); + } + else + ret = value_ptradd (ret, value_as_long (displacement)); + } + + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + { + if (trace_kludge) + { + gdb_assert (aop == aop_ref32 || aop == aop_ref64); + ax_trace_quick (eval_info->aexpr, aop == aop_ref32 ? 4 : 8); + } + ax_simple (eval_info->aexpr, aop); + } + else + { + ret = value_cast (t, ret); + ret = value_ind (ret); + } + } + + /* Updating the expression buffer pointer, because we have made + some modifications to it before. */ + eval_info->exp_buf = s; + + return ret; +} + +/* This function tries to evaluate a single operand of the expression. + + Single operands can be: + + - unary operators `-' and `~'; + - integer constants (beginning with `$'); + - register access, with/out displacement and indirection. */ + +static struct value * +stap_evaluate_single_operand (struct stap_evaluation_info *eval_info) +{ + struct gdbarch *gdbarch = eval_info->gdbarch; + struct frame_info *frame = eval_info->frame; + enum stap_arg_bitness bitness = eval_info->bitness; + struct value *res = NULL; + + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + /* If we are compiling, we cannot return NULL because that would + lead to errors in future evaluations. That's why we just make + this dummy value, representing that the return value of this + function is not NULL. */ + res = value_from_longest (builtin_type (gdbarch)->builtin_int, 0); + + switch (*eval_info->exp_buf) + { + case '-': case '~': + { + char c = *eval_info->exp_buf; + + /* This is an unary operator (either `-' or `~'). + + If it is followed by a parenthesis, and this parenthesis + is NOT followed by a `%', then we are dealing with an expression + like `-(2 + 3)' or `~(2 + 3)'. We just have to treat separately + and return the result after applying the operation (`-' or `~'). + + If it is followed by a digit, then we have only one choice: it + is a displacement argument for a register access, like + `-4(%eax)'. It also means that the operator can *only* be `-', + and the characters immediately after the number *must* be `(%'. + + If it is followed by a `$', then it is an integer constant, and + we should apply the correct operation to it. */ + + ++eval_info->exp_buf; + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + if (*eval_info->exp_buf + && *eval_info->exp_buf == '(' + && eval_info->exp_buf[1] != '%') + { + struct value *tmp_res; + + /* We're not dealing with a register name, but with an + expression like `-(2 + 3)' or `~(2 + 3)'. We first have + to evaluate the right side of the expression (i.e., the + parenthesis), and then apply the specified operation + (either `-' or `~') to it. */ + tmp_res = stap_evaluate_conditionally (eval_info); + + if (c == '-') + { + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + { + /* We have to add `-1' to the stack, and multiply + the two values. */ + ax_const_l (eval_info->aexpr, -1); + ax_simple (eval_info->aexpr, aop_mul); + } + else + res = value_neg (tmp_res); + } + else + { + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + ax_simple (eval_info->aexpr, aop_bit_not); + else + res = value_complement (tmp_res); + } + } + else if (isdigit (*eval_info->exp_buf)) + { + int number; + + /* This is a number, so it MUST be a register displacement. + The only operator allowed here is `-', it MUST be + followed by a number, and the number MUST be followed by + `(%'. */ + if (c != '-') + error (_("Invalid operator `%c' for register displacement " + "on expression `%s'."), c, eval_info->saved_expr); + + number = strtol (eval_info->exp_buf, + &eval_info->exp_buf, 0) * -1; + + if (!*eval_info->exp_buf + || *eval_info->exp_buf != '(' + || (*eval_info->exp_buf == '(' + && eval_info->exp_buf[1] != '%')) + error (_("Invalid method of indirecting a register on " + "expression `%s'."), eval_info->saved_expr); + + res + = value_from_longest (builtin_type (gdbarch)->builtin_int, + number); + + res = stap_fetch_reg_value (eval_info, res); + } + else if (*eval_info->exp_buf == '$') + { + int number; + + /* Last case. We are dealing with an integer constant, so + we must read it and then apply the necessary operation, + either `-' or `~'. */ + ++eval_info->exp_buf; + number = strtol (eval_info->exp_buf, + &eval_info->exp_buf, 0); + + if (!STAP_COMPILING_AGENT_EXPR_P (eval_info)) + res + = value_from_longest (builtin_type (gdbarch)->builtin_int, + number); + else + ax_const_l (eval_info->aexpr, number); + + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + + if (c == '-') + { + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + ax_simple (eval_info->aexpr, aop_log_not); + else + res = value_neg (res); + } + else + { + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + ax_simple (eval_info->aexpr, aop_bit_not); + else + res = value_complement (res); + } + } + else + error (_("Invalid operand to unary operator `%c' on " + "expression `%s'."), c, eval_info->saved_expr); + } + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + int number = strtol (eval_info->exp_buf, &eval_info->exp_buf, 0); + + /* This is a register displacement with a positive value. We read + the number, and then check for the mandatory `(%' part. */ + if (!*eval_info->exp_buf + || !(*eval_info->exp_buf == '(' + && eval_info->exp_buf[1] == '%')) + error (_("Invalid register access on expression `%s'."), + eval_info->saved_expr); + + res = value_from_longest (builtin_type (gdbarch)->builtin_int, + number); + + res = stap_fetch_reg_value (eval_info, res); + } + break; + + case '$': + { + int number; + + /* This is an integer constant. We just have to read the number + and return it. */ + ++eval_info->exp_buf; + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + + number = strtol (eval_info->exp_buf, &eval_info->exp_buf, 0); + + if (STAP_COMPILING_AGENT_EXPR_P (eval_info)) + ax_const_l (eval_info->aexpr, number); + else + res = value_from_longest (builtin_type (gdbarch)->builtin_int, + number); + + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + } + break; + + case '(': case '%': + { + /* Register access, with or without indirection. */ + res = stap_fetch_reg_value (eval_info, /*displacement=*/NULL); + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + } + break; + + default: + { + error (_("Operator `%c' not recognized on expression `%s'."), + *eval_info->exp_buf, eval_info->saved_expr); + } + } + + return res; +} + +/* This function is responsible for checking the necessary type of evaluation + depending on what is the next "thing" in the buffer. Valid values are: + + - Unary operators; + - Integer constants; + - Register displacement, indirection, and direct access; + - Parenthesized operand. */ + +static struct value * +stap_evaluate_conditionally (struct stap_evaluation_info *eval_info) +{ + char *s = eval_info->exp_buf; + struct value *ret = NULL; + + if (*s == '-' || *s == '~' /* Unary operators. */ + || *s == '$' /* Number (integer constant). */ + || (isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement. */ + || (*s == '(' && s[1] == '%') /* Register indirection. */ + || (*s == '%' && isalpha (s[1]))) /* Register value. */ + /* This is a single operand, so just evaluate it and return. */ + ret = stap_evaluate_single_operand (eval_info); + else if (*s == '(') + { + /* We are dealing with a parenthesized operand. It means we + have to evaluate it as it was a separate expression, without + left-side or precedence. */ + ++eval_info->exp_buf; + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + + ret = stap_evaluate_probe_argument_2 (eval_info, + /*lhs=*/NULL, /*prec=*/0); + + if (*eval_info->exp_buf != ')') + error (_("Missign close-paren on expression `%s'."), + eval_info->saved_expr); + + ++eval_info->exp_buf; + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + } + else + error (_("Cannot evaluate expression `%s'."), + eval_info->saved_expr); + + return ret; +} + +/* Evaluation function for probe's argument expressions. LHS represents + the left side of the expression, and PREC is the precedence of the + last operator identified before calling the function. */ + +static struct value * +stap_evaluate_probe_argument_2 (struct stap_evaluation_info *eval_info, + struct value *lhs, int prec) +{ + struct value *rhs = NULL; + int compiling_p = STAP_COMPILING_AGENT_EXPR_P (eval_info); + + /* This is an operator-precedence parser and evaluator. + + We work with left- and right-sides of expressions, and + evaluate them depending on the precedence of the operators + we find. */ + + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + + if (!lhs) + /* We were called without a left-side, either because this is the + first call, or because we were called to evaluate a parenthesized + expression. It doesn't really matter; we have to evaluate the + left-side in order to continue the process. */ + lhs = stap_evaluate_conditionally (eval_info); + + /* Start to evaluate the right-side, and to "join" left and right sides + depending on the operation specified. + + This loop shall continue until we run out of characters in the input, + or until we find a close-parenthesis, which means that we've reached + the end of a sub-expression. */ + while (eval_info->exp_buf + && *eval_info->exp_buf + && *eval_info->exp_buf != ')') + { + char *tmp_exp_buf; + enum exp_opcode opcode; + int cur_prec; + + if (!stap_is_operator (eval_info->exp_buf)) + error (_("Invalid operator `%c' on expression `%s'."), + *eval_info->exp_buf, eval_info->saved_expr); + + /* We have to save the current value of the expression buffer because + the `stap_get_opcode' modifies it in order to get the current + operator. If this operator's precedence is lower than PREC, we + should return and not advance the expression buffer pointer. */ + tmp_exp_buf = eval_info->exp_buf; + stap_get_opcode (&tmp_exp_buf, &opcode); + + cur_prec = stap_get_operator_prec (opcode); + if (cur_prec < prec) + /* If the precedence of the operator that we are seeing now is + lower than the precedence of the first operator seen before + this evaluation process began, it means we should stop evaluating + and return. */ + break; + + eval_info->exp_buf = tmp_exp_buf; + eval_info->exp_buf = skip_spaces (eval_info->exp_buf); + + /* Evaluate the right-side of the expression. */ + rhs = stap_evaluate_conditionally (eval_info); + + /* While we still have operators, try to evaluate another + right-side, but using the current right-side as a left-side. */ + while (*eval_info->exp_buf + && stap_is_operator (eval_info->exp_buf)) + { + enum exp_opcode lookahead_opcode; + int lookahead_prec; + + /* Saving the current expression buffer position. The explanation + is the same as above. */ + tmp_exp_buf = eval_info->exp_buf; + stap_get_opcode (&tmp_exp_buf, &lookahead_opcode); + lookahead_prec = stap_get_operator_prec (lookahead_opcode); + + if (lookahead_prec <= prec) + /* If we are dealing with an operator whose precedence is lower + than the first one, just abandon the attempt. */ + break; + + rhs = stap_evaluate_probe_argument_2 (eval_info, + rhs, lookahead_prec); + } + + /* Now, "join" both left and right sides into one left-side, using + the specified operator. */ + if (compiling_p) + stap_opcode_to_ax (eval_info, opcode); + else + lhs = value_binop (lhs, rhs, opcode); + } + + return lhs; +} + +/* This function fills the necessary arguments for the evaluation function + to work. */ + +static struct value * +stap_evaluate_probe_argument_1 (struct objfile *objfile, + const struct stap_probe *probe, + struct frame_info *frame, + int n) +{ + struct stap_evaluation_info eval_info; + char *s = (char *) probe->parsed_args->arg[n].arg_str; + struct value *res, *vs[4]; + + /* Filling necessary information for evaluation function. */ + eval_info.saved_expr = s; + eval_info.exp_buf = s; + eval_info.gdbarch = get_objfile_arch (objfile); + eval_info.frame = frame; + eval_info.bitness = probe->parsed_args->arg[n].bitness; + /* We are not compiling to an agent expression. */ + eval_info.aexpr = NULL; + eval_info.avalue = NULL; + + res = stap_evaluate_probe_argument_2 (&eval_info, + /*lhs=*/NULL, /*prec=*/0); + + if (!res) + error (_("Could not evaluate expression `%s'."), + eval_info.saved_expr); + + return res; +} + +/* See definition in stap-probe.h. */ + +struct value * +stap_evaluate_probe_argument (struct objfile *objfile, + const struct stap_probe *probe, + struct frame_info *frame, + int n) +{ + if (!probe->parsed_args) + stap_parse_probe_arguments ((struct stap_probe *) probe); + + if (!probe->parsed_args->arg + || n >= probe->parsed_args->n_args) + return NULL; + + return stap_evaluate_probe_argument_1 (objfile, probe, frame, n); +} + +/* Helper function which compiles the probe's argument N into an + agent expression, suitable for using with tracepoints. */ + +static void +stap_compile_to_ax_1 (struct objfile *objfile, + const struct stap_probe *probe, + struct agent_expr *expr, + struct axs_value *value, + int n) +{ + struct stap_evaluation_info eval_info; + struct gdbarch *gdbarch = expr->gdbarch; + char *s = (char *) probe->parsed_args->arg[n].arg_str; + + /* Filling necessary information for evaluation function. */ + eval_info.saved_expr = s; + eval_info.exp_buf = s; + eval_info.gdbarch = expr->gdbarch; + eval_info.frame = NULL; + eval_info.bitness = probe->parsed_args->arg[n].bitness; + /* We are compiling to an agent expression. */ + eval_info.aexpr = expr; + eval_info.avalue = value; + + /* We can always use this kind. */ + value->kind = axs_rvalue; + + /* Figuring out the correct type for this axs_value. */ + switch (eval_info.bitness) + { + case STAP_ARG_BITNESS_UNDEFINED: + if (gdbarch_addr_bit (gdbarch) == 32) + value->type = builtin_type (gdbarch)->builtin_uint32; + else + value->type = builtin_type (gdbarch)->builtin_uint64; + break; + + case STAP_ARG_BITNESS_32BIT_SIGNED: + value->type = builtin_type (gdbarch)->builtin_int32; + break; + + case STAP_ARG_BITNESS_32BIT_UNSIGNED: + value->type = builtin_type (gdbarch)->builtin_uint32; + break; + + case STAP_ARG_BITNESS_64BIT_SIGNED: + value->type = builtin_type (gdbarch)->builtin_int64; + break; + + case STAP_ARG_BITNESS_64BIT_UNSIGNED: + value->type = builtin_type (gdbarch)->builtin_uint64; + break; + + default: + internal_error (__FILE__, __LINE__, + _("Undefined bitness for probe.")); + break; + } + + stap_evaluate_probe_argument_2 (&eval_info, + /*lhs=*/NULL, /*prec=*/0); +} + +/* See definition in stap-probe.h. */ + +void +stap_compile_to_ax (struct objfile *objfile, + const struct stap_probe *probe, + struct agent_expr *expr, + struct axs_value *value, + int n) +{ + if (!probe->parsed_args) + stap_parse_probe_arguments ((struct stap_probe *) probe); + + if (!probe->parsed_args->arg + || n >= probe->parsed_args->n_args) + return; + + stap_compile_to_ax_1 (objfile, probe, expr, value, n); +} + +struct value * +stap_safe_evaluate_at_pc (struct frame_info *frame, int n) +{ + const struct stap_probe *probe; + struct objfile *objfile; + int n_probes; + + probe = find_probe_by_pc (get_frame_pc (frame), &objfile); + if (!probe) + return NULL; + gdb_assert (objfile->sf && objfile->sf->sym_probe_fns); + + n_probes + = objfile->sf->sym_probe_fns->sym_get_probe_argument_count (objfile, + probe); + if (n >= n_probes) + return NULL; + + return objfile->sf->sym_probe_fns->sym_evaluate_probe_argument (objfile, + probe, + frame, + n); +} + +/* This function frees the space allocated to hold information about + the probe's parsed arguments. */ + +void +stap_free_parsed_args (struct stap_args_info *parsed_args) +{ + int i; + + if (!parsed_args + || parsed_args == &dummy_stap_args_info + || parsed_args->n_args == 0) + return; + + for (i = 0; i < parsed_args->n_args; i++) + xfree (parsed_args->arg); + + xfree (parsed_args); +} + +/* A utility structure. A VEC of these is built when handling "info + probes". */ + +struct stap_probe_and_objfile +{ + /* The probe. */ + const struct stap_probe *probe; + /* The probe's objfile. */ + struct objfile *objfile; +}; + +typedef struct stap_probe_and_objfile stap_entry; +DEF_VEC_O (stap_entry); + +/* A helper function for collect_probes that compiles a regexp and + throws an exception on error. This installs a cleanup to free the + resulting pattern on success. If RX is NULL, this does nothing. */ + +static void +compile_rx_or_error (regex_t *pattern, const char *rx, const char *message) +{ + int code; + + if (!rx) + return; + + code = regcomp (pattern, rx, REG_NOSUB); + if (code == 0) + make_regfree_cleanup (pattern); + else + { + char *err = get_regcomp_error (code, pattern); + + make_cleanup (xfree, err); + error (_("%s: %s"), message, err); + } +} + +/* Make a vector of probes matching OBJNAME, PROVIDER, and PROBE. + Each argument is a regexp, or NULL, which matches anything. */ + +static VEC (stap_entry) * +collect_probes (char *objname, char *provider, char *probe) +{ + struct objfile *objfile; + VEC (stap_entry) *result = NULL; + struct cleanup *cleanup; + regex_t obj_pat, prov_pat, probe_pat; + + cleanup = make_cleanup (VEC_cleanup (stap_entry), &result); + + compile_rx_or_error (&prov_pat, provider, _("Invalid provider regexp")); + compile_rx_or_error (&probe_pat, probe, _("Invalid probe regexp")); + compile_rx_or_error (&obj_pat, objname, _("Invalid object file regexp")); + + ALL_OBJFILES (objfile) + { + const struct stap_probe *probes; + int i, num_probes; + + if (! objfile->sf || ! objfile->sf->sym_probe_fns) + continue; + + if (objname) + { + if (regexec (&obj_pat, objfile->name, 0, NULL, 0) != 0) + continue; + } + + probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile, &num_probes); + for (i = 0; i < num_probes; ++i) + { + stap_entry entry; + + if (provider) + { + if (regexec (&prov_pat, probes[i].provider, 0, NULL, 0) != 0) + continue; + } + + if (probe) + { + if (regexec (&probe_pat, probes[i].name, 0, NULL, 0) != 0) + continue; + } + + entry.probe = &probes[i]; + entry.objfile = objfile; + VEC_safe_push (stap_entry, result, &entry); + } + } + + discard_cleanups (cleanup); + return result; +} + +/* A qsort comparison function for stap_entry objects. */ + +static int +compare_entries (const void *a, const void *b) +{ + const stap_entry *ea = a; + const stap_entry *eb = b; + int v; + + v = strcmp (ea->probe->provider, eb->probe->provider); + if (v) + return v; + + v = strcmp (ea->probe->name, eb->probe->name); + if (v) + return v; + + if (ea->probe->address < eb->probe->address) + return -1; + if (ea->probe->address > eb->probe->address) + return 1; + + return strcmp (ea->objfile->name, eb->objfile->name); +} + +/* Implementation of the "info probes" command. */ + +static void +info_probes_command (char *arg, int from_tty) +{ + char *provider, *probe = NULL, *objname = NULL; + struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); + VEC (stap_entry) *items; + int i, addr_width, any_found; + stap_entry *entry; + + provider = extract_arg (&arg); + if (provider) + { + make_cleanup (xfree, provider); + + probe = extract_arg (&arg); + if (probe) + { + make_cleanup (xfree, probe); + + objname = extract_arg (&arg); + if (objname) + make_cleanup (xfree, objname); + } + } + + items = collect_probes (objname, provider, probe); + make_cleanup (VEC_cleanup (stap_entry), &items); + make_cleanup_ui_out_table_begin_end (uiout, 5, + VEC_length (stap_entry, items), + "SystemTapProbes"); + + if (! VEC_empty (stap_entry, items)) + qsort (VEC_address (stap_entry, items), + VEC_length (stap_entry, items), + sizeof (stap_entry), + compare_entries); + + addr_width = 4 + (gdbarch_ptr_bit (get_current_arch ()) / 4); + + ui_out_table_header (uiout, 10, ui_left, "provider", _("Provider")); + ui_out_table_header (uiout, 10, ui_left, "name", _("Name")); + ui_out_table_header (uiout, addr_width - 1, ui_left, "addr", _("Where")); + ui_out_table_header (uiout, addr_width - 1, ui_left, "semaphore", + _("Semaphore")); + ui_out_table_header (uiout, 30, ui_left, "object", _("Object")); + ui_out_table_body (uiout); + + for (i = 0; VEC_iterate (stap_entry, items, i, entry); ++i) + { + struct cleanup *inner; + + inner = make_cleanup_ui_out_tuple_begin_end (uiout, "probe"); + + ui_out_field_string (uiout, "provider", entry->probe->provider); + ui_out_field_string (uiout, "name", entry->probe->name); + ui_out_field_core_addr (uiout, "addr", get_current_arch (), + entry->probe->address); + if (entry->probe->sem_addr == 0) + ui_out_field_skip (uiout, "semaphore"); + else + ui_out_field_core_addr (uiout, "semaphore", get_current_arch (), + entry->probe->sem_addr); + ui_out_field_string (uiout, "object", entry->objfile->name); + ui_out_text (uiout, "\n"); + + do_cleanups (inner); + } + + any_found = ! VEC_empty (stap_entry, items); + do_cleanups (cleanup); + + if (! any_found) + ui_out_message (uiout, 0, _("No probes matched.\n")); +} + + + +/* See definition in stap-probe.h. */ + +const struct stap_probe * +find_probe_in_objfile (struct objfile *objfile, + const char *provider, + const char *name) +{ + const struct stap_probe *probes; + int i, num_probes; + + if (! objfile->sf || ! objfile->sf->sym_probe_fns) + return NULL; + + probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile, &num_probes); + for (i = 0; i < num_probes; ++i) + { + if (strcmp (probes[i].provider, provider) != 0) + continue; + + if (strcmp (probes[i].name, name) != 0) + continue; + + return &probes[i]; + } + + return NULL; +} + +/* See definition in stap-probe.h. */ + +struct symtabs_and_lines +parse_stap_probe (char **argptr, struct linespec_result *canonical) +{ + char *full_arg = extract_arg (argptr); + char *arg = xstrdup (full_arg); + char *objfile_name = NULL, *provider = NULL, *name, *p; + struct cleanup *cleanup; + struct symtabs_and_lines result; + struct objfile *objfile; + + result.sals = NULL; + result.nelts = 0; + + /* The caller ensured that this starts with 'probe:'. */ + gdb_assert (arg && strncmp (arg, "probe:", 6) == 0); + cleanup = make_cleanup (xfree, arg); + make_cleanup (xfree, full_arg); + arg += 6; + + /* Extract each word from the argument, separated by ":"s. */ + p = strchr (arg, ':'); + if (p == NULL) + { + /* This is `probe:name'. */ + name = arg; + } + else + { + char *hold = p + 1; + + *p = '\0'; + p = strchr (hold, ':'); + if (p == NULL) + { + /* This is `probe:provider:name'. */ + provider = arg; + name = hold; + } + else + { + /* This is `probe:objfile:provider:name'. */ + *p = '\0'; + objfile_name = arg; + provider = hold; + name = p + 1; + } + } + + if (*name == '\0') + error (_("no probe name specified")); + if (provider && *provider == '\0') + error (_("invalid provider name")); + if (objfile_name && *objfile_name == '\0') + error (_("invalid objfile name")); + + if (canonical) + canonical->canonical = NULL; + + ALL_OBJFILES (objfile) + { + const struct stap_probe *probes; + int i, num_probes; + + if (! objfile->sf || ! objfile->sf->sym_probe_fns) + continue; + + if (objfile_name + && FILENAME_CMP (objfile->name, objfile_name) != 0 + && FILENAME_CMP (lbasename (objfile->name), objfile_name) != 0) + continue; + + probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile, &num_probes); + for (i = 0; i < num_probes; ++i) + { + struct symtab_and_line *sal; + + if (provider && strcmp (probes[i].provider, provider) != 0) + continue; + + if (strcmp (probes[i].name, name) != 0) + continue; + + ++result.nelts; + result.sals = xrealloc (result.sals, + result.nelts * sizeof (struct symtab_and_line)); + sal = &result.sals[result.nelts - 1]; + + init_sal (sal); + + sal->pc = probes[i].address; + sal->explicit_pc = 1; + sal->section = find_pc_overlay (sal->pc); + sal->pspace = current_program_space; + sal->semaphore = probes[i].sem_addr; + + if (canonical) + { + canonical->canonical = xrealloc (canonical->canonical, + result.nelts * sizeof (char **)); + canonical->canonical[result.nelts - 1] = xstrdup (full_arg); + } + } + } + + if (result.nelts == 0) + { + throw_error (NOT_FOUND_ERROR, + _("No probe matching objfile=`%s', provider=`%s', name=`%s'"), + objfile_name ? objfile_name : _(""), + provider ? provider : _(""), + name); + } + + if (canonical) + { + canonical->special_display = 1; + canonical->pre_expanded = 1; + } + + do_cleanups (cleanup); + + return result; +} + + + +/* See definition in stap-probe.h. */ + +const struct stap_probe * +find_probe_by_pc (CORE_ADDR pc, struct objfile **objfile_out) +{ + struct objfile *objfile; + + ALL_OBJFILES (objfile) + { + const struct stap_probe *probes; + int i, num_probes; + stap_entry entry; + + if (! objfile->sf || ! objfile->sf->sym_probe_fns) + continue; + + /* If this proves too inefficient, we can replace with a hash. */ + probes = objfile->sf->sym_probe_fns->sym_get_probes (objfile, &num_probes); + for (i = 0; i < num_probes; ++i) + { + if (probes[i].address == pc) + { + *objfile_out = objfile; + return &probes[i]; + } + } + } + + return NULL; +} + +/* This is called to compute the value of one of the $_probe_arg* + convenience variables. */ + +static struct value * +compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar, + void *data) +{ + struct frame_info *frame = get_selected_frame (_("No frame selected")); + CORE_ADDR pc = get_frame_pc (frame); + int sel = (int) (uintptr_t) data; + struct objfile *objfile; + const struct stap_probe *pc_probe; + int n_probes; + + /* SEL==10 means "_probe_argc". */ + gdb_assert (sel >= 0 && sel <= STAP_MAX_ARGS); + + pc_probe = find_probe_by_pc (pc, &objfile); + if (pc_probe == NULL) + error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc)); + + n_probes + = objfile->sf->sym_probe_fns->sym_get_probe_argument_count (objfile, + pc_probe); + if (sel == 10) + return value_from_longest (builtin_type (arch)->builtin_int, n_probes); + + if (sel >= n_probes) + error (_("Invalid probe argument %d -- probe has %d arguments available"), + sel, n_probes); + + return objfile->sf->sym_probe_fns->sym_evaluate_probe_argument (objfile, + pc_probe, + frame, sel); +} + +/* This is called to compile one of the $_probe_arg* convenience + variables into an agent expression. */ + +static void +compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr, + struct axs_value *value, void *data) +{ + CORE_ADDR pc = expr->scope; + int sel = (int) (uintptr_t) data; + struct objfile *objfile; + const struct stap_probe *pc_probe; + int n_probes; + + /* SEL==10 means "_probe_argc". */ + gdb_assert (sel >= 0 && sel <= 10); + + pc_probe = find_probe_by_pc (pc, &objfile); + if (pc_probe == NULL) + error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc)); + + n_probes + = objfile->sf->sym_probe_fns->sym_get_probe_argument_count (objfile, + pc_probe); + if (sel == 10) + { + value->kind = axs_rvalue; + value->type = builtin_type (expr->gdbarch)->builtin_int; + ax_const_l (expr, n_probes); + return; + } + + gdb_assert (sel >= 0); + if (sel >= n_probes) + error (_("Invalid probe argument %d -- probe has %d arguments available"), + sel, n_probes); + + objfile->sf->sym_probe_fns->sym_compile_to_ax (objfile, pc_probe, + expr, value, sel); +} + + + +/* Implementation of `$_probe_arg*' set of variables. */ + +static const struct internalvar_funcs probe_funcs = +{ + compute_probe_arg, + compile_probe_arg, + NULL +}; + +void +_initialize_stap_probe (void) +{ + add_info ("probes", info_probes_command, _("\ +Show available static probes.\n\ +Usage: info probes [PROVIDER [NAME [OBJECT]]]\n\ +Each argument is a regular expression, used to select probes.\n\ +PROVIDER matches probe provider names.\n\ +NAME matches the probe names.\n\ +OBJECT match the executable or shared library name.")); + + create_internalvar_type_lazy ("_probe_argc", &probe_funcs, + (void *) (uintptr_t) 10); + create_internalvar_type_lazy ("_probe_arg0", &probe_funcs, + (void *) (uintptr_t) 0); + create_internalvar_type_lazy ("_probe_arg1", &probe_funcs, + (void *) (uintptr_t) 1); + create_internalvar_type_lazy ("_probe_arg2", &probe_funcs, + (void *) (uintptr_t) 2); + create_internalvar_type_lazy ("_probe_arg3", &probe_funcs, + (void *) (uintptr_t) 3); + create_internalvar_type_lazy ("_probe_arg4", &probe_funcs, + (void *) (uintptr_t) 4); + create_internalvar_type_lazy ("_probe_arg5", &probe_funcs, + (void *) (uintptr_t) 5); + create_internalvar_type_lazy ("_probe_arg6", &probe_funcs, + (void *) (uintptr_t) 6); + create_internalvar_type_lazy ("_probe_arg7", &probe_funcs, + (void *) (uintptr_t) 7); + create_internalvar_type_lazy ("_probe_arg8", &probe_funcs, + (void *) (uintptr_t) 8); + create_internalvar_type_lazy ("_probe_arg9", &probe_funcs, + (void *) (uintptr_t) 9); +} Index: gdb-7.2.90.20110525/gdb/stap-probe.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/stap-probe.h 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,109 @@ +/* SystemTap probe support for GDB. + + Copyright (C) 2011 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#if !defined (STAP_PROBE_H) +#define STAP_PROBE_H 1 + +struct stap_args_info; +struct axs_value; +struct linespec_result; + +/* Main structure which holds information about a SystemTap probe. */ + +struct stap_probe +{ + /* The provider of this probe. */ + const char *provider; + + /* The name of the probe. */ + const char *name; + + /* The address where the probe is inserted. */ + CORE_ADDR address; + + /* The address of the probe's semaphore, or 0 if this probe does not + have an associated semaphore. */ + CORE_ADDR sem_addr; + + /* Probe's arguments. Users should generally not examine this, but + should instead extract information about the arguments using the + methods provided in sym_probe_fns. */ + const char *args; + + /* Probe's arguments after parsing. This is an opaque structure that + will hold information about the arguments pointed by ARGS. */ + struct stap_args_info *parsed_args; +}; + + +/* A helper for linespec that decodes a stap probe specification. It + returns a symtabs_and_lines object and updates *ARGPTR or throws an + error. */ + +extern struct symtabs_and_lines parse_stap_probe (char **argptr, + struct linespec_result *canon); + +/* Search OBJFILE for a probe with the given PROVIDER and NAME. If a + probe is found, return it. If no probe is found, return NULL. */ + +extern const struct stap_probe *find_probe_in_objfile (struct objfile *objfile, + const char *provider, + const char *name); + +/* Given a PC, find an associated SystemTap probe. If a probe is + found, set *OBJFILE_OUT to the probe's objfile, and return the + probe. If no probe is found, return NULL. */ + +extern const struct stap_probe *find_probe_by_pc (CORE_ADDR pc, + struct objfile **objfile_out); + +/* Given PROBE, returns the number of arguments present in that probe's + argument string. */ + +extern int stap_get_probe_argument_count (const struct stap_probe *probe); + +/* Given PARSED_ARGS, frees the space allocated to hold information about + the probe's parsed arguments. */ + +extern void stap_free_parsed_args (struct stap_args_info *parsed_args); + +/* Evaluates the probe's argument N, returning a value corresponding + to it. */ + +extern struct value *stap_evaluate_probe_argument (struct objfile *objfile, + const struct stap_probe *probe, + struct frame_info *frame, + int n); + +/* Compile the probe's argument N to agent expression. */ + +extern void stap_compile_to_ax (struct objfile *objfile, + const struct stap_probe *probe, + struct agent_expr *expr, + struct axs_value *value, + int n); + +/* A convenience function that finds a probe at the PC in FRAME and + evaluates argument N. If there is no probe at that location, or if + the probe does not have enough arguments, this returns NULL. */ + +extern struct value *stap_safe_evaluate_at_pc (struct frame_info *frame, + int n); + +#endif /* !defined (STAP_PROBE_H) */ Index: gdb-7.2.90.20110525/gdb/symfile.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/symfile.h 2011-04-25 23:25:18.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/symfile.h 2011-05-25 17:05:21.000000000 +0200 @@ -31,6 +31,11 @@ struct objfile; struct obj_section; struct obstack; struct block; +struct stap_probe; +struct value; +struct frame_info; +struct agent_expr; +struct axs_value; /* Comparison function for symbol look ups. */ @@ -290,6 +295,52 @@ struct quick_symbol_functions void *data); }; +/* Structure of functions used for SystemTap probe support. If one of + these functions is provided, all must be. */ + +struct sym_probe_fns +{ + /* If non-NULL, return an array of SystemTap probe objects. The + number of objects is returned in *NUM_PROBES. */ + const struct stap_probe *(*sym_get_probes) (struct objfile *, + int *num_probes); + + /* Return the number of arguments available to PROBE. PROBE will + have come from a call to this objfile's sym_get_probes method. + If you provide an implementation of sym_get_probes, you must + implement this method as well. */ + int (*sym_get_probe_argument_count) (struct objfile *objfile, + const struct stap_probe *probe); + + /* Evaluate the Nth argument available to PROBE. PROBE will have + come from a call to this objfile's sym_get_probes method. N will + be between 0 and the number of arguments available to this probe. + FRAME is the frame in which the evaluation is done; the frame's + PC will match the address of the probe. If you provide an + implementation of sym_get_probes, you must implement this method + as well. */ + struct value *(*sym_evaluate_probe_argument) (struct objfile *objfile, + const struct stap_probe *probe, + struct frame_info *frame, + int n); + + /* Compile the Nth probe argument to an agent expression. PROBE + will have come from a call to this objfile's sym_get_probes + method. N will be between 0 and the number of arguments + available to this probe. EXPR and VALUE are the agent expression + that is being updated. */ + void (*sym_compile_to_ax) (struct objfile *objfile, + const struct stap_probe *probe, + struct agent_expr *expr, + struct axs_value *value, + int n); + + /* Relocate the probe section of OBJFILE. */ + void (*sym_relocate_probe) (struct objfile *objfile, + struct section_offsets *new_offsets, + struct section_offsets *delta); +}; + /* Structure to keep track of symbol reading functions for various object file types. */ @@ -360,6 +411,10 @@ struct sym_fns bfd_byte *(*sym_relocate) (struct objfile *, asection *sectp, bfd_byte *buf); + /* If non-NULL, this objfile has probe support, and all the probe + functions referred to here will be non-NULL. */ + const struct sym_probe_fns *sym_probe_fns; + /* The "quick" (aka partial) symbol functions for this symbol reader. */ const struct quick_symbol_functions *qf; Index: gdb-7.2.90.20110525/gdb/symtab.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/symtab.c 2011-05-06 17:13:37.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/symtab.c 2011-05-25 17:05:21.000000000 +0200 @@ -770,6 +770,7 @@ init_sal (struct symtab_and_line *sal) sal->end = 0; sal->explicit_pc = 0; sal->explicit_line = 0; + sal->semaphore = 0; } Index: gdb-7.2.90.20110525/gdb/symtab.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/symtab.h 2011-05-06 17:13:37.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/symtab.h 2011-05-25 17:05:21.000000000 +0200 @@ -1118,6 +1118,10 @@ struct symtab_and_line CORE_ADDR end; int explicit_pc; int explicit_line; + + /* If non-zero, the semaphore location associated with a SystemTap + probe. */ + CORE_ADDR semaphore; }; extern void init_sal (struct symtab_and_line *sal); Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,457 @@ + .file "x86_64-vla-pointer.c" + .section .debug_abbrev,"",@progbits +.Ldebug_abbrev0: + .section .debug_info,"",@progbits +.Ldebug_info0: + .section .debug_line,"",@progbits +.Ldebug_line0: + .text +.Ltext0: +.globl foo + .type foo, @function +foo: +.LFB2: + .file 1 "x86_64-vla-pointer.c" + .loc 1 22 0 + pushq %rbp +.LCFI0: + movq %rsp, %rbp +.LCFI1: + subq $64, %rsp +.LCFI2: + movl %edi, -36(%rbp) + .loc 1 22 0 + movq %rsp, %rax + movq %rax, -48(%rbp) + .loc 1 23 0 + movl -36(%rbp), %edx + movslq %edx,%rax + subq $1, %rax + movq %rax, -24(%rbp) + .loc 1 24 0 + movslq %edx,%rax + addq $15, %rax + addq $15, %rax + shrq $4, %rax + salq $4, %rax + subq %rax, %rsp + movq %rsp, -56(%rbp) + movq -56(%rbp), %rax + addq $15, %rax + shrq $4, %rax + salq $4, %rax + movq %rax, -56(%rbp) + movq -56(%rbp), %rax + movq %rax, -16(%rbp) + .loc 1 27 0 + movl $0, -4(%rbp) + jmp .L2 +.L3: + .loc 1 28 0 + movl -4(%rbp), %esi + movl -4(%rbp), %eax + movl %eax, %ecx + movq -16(%rbp), %rdx + movslq %esi,%rax + movb %cl, (%rdx,%rax) + .loc 1 27 0 + addl $1, -4(%rbp) +.L2: + movl -4(%rbp), %eax + cmpl -36(%rbp), %eax + jl .L3 + .loc 1 30 0 + .globl break_here +break_here: + movq -16(%rbp), %rax + movb $0, (%rax) + movq -48(%rbp), %rsp + .loc 1 31 0 + leave + ret +.LFE2: + .size foo, .-foo + .section .debug_frame,"",@progbits +.Lframe0: + .long .LECIE0-.LSCIE0 +.LSCIE0: + .long 0xffffffff + .byte 0x1 + .string "" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE0: +.LSFDE0: + .long .LEFDE0-.LASFDE0 +.LASFDE0: + .long .Lframe0 + .quad .LFB2 + .quad .LFE2-.LFB2 + .byte 0x4 + .long .LCFI0-.LFB2 + .byte 0xe + .uleb128 0x10 + .byte 0x86 + .uleb128 0x2 + .byte 0x4 + .long .LCFI1-.LCFI0 + .byte 0xd + .uleb128 0x6 + .align 8 +.LEFDE0: + .section .eh_frame,"a",@progbits +.Lframe1: + .long .LECIE1-.LSCIE1 +.LSCIE1: + .long 0x0 + .byte 0x1 + .string "zR" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .uleb128 0x1 + .byte 0x3 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE1: +.LSFDE1: + .long .LEFDE1-.LASFDE1 +.LASFDE1: + .long .LASFDE1-.Lframe1 + .long .LFB2 + .long .LFE2-.LFB2 + .uleb128 0x0 + .byte 0x4 + .long .LCFI0-.LFB2 + .byte 0xe + .uleb128 0x10 + .byte 0x86 + .uleb128 0x2 + .byte 0x4 + .long .LCFI1-.LCFI0 + .byte 0xd + .uleb128 0x6 + .align 8 +.LEFDE1: + .text +.Letext0: + .section .debug_loc,"",@progbits +.Ldebug_loc0: +.LLST0: + .quad .LFB2-.Ltext0 + .quad .LCFI0-.Ltext0 + .value 0x2 + .byte 0x77 + .sleb128 8 + .quad .LCFI0-.Ltext0 + .quad .LCFI1-.Ltext0 + .value 0x2 + .byte 0x77 + .sleb128 16 + .quad .LCFI1-.Ltext0 + .quad .LFE2-.Ltext0 + .value 0x2 + .byte 0x76 + .sleb128 16 + .quad 0x0 + .quad 0x0 + .section .debug_info +.Ldebug_relative: + .long .Ldebug_end - .Ldebug_start +.Ldebug_start: + .value 0x2 + .long .Ldebug_abbrev0 + .byte 0x8 + .uleb128 0x1 + .long .LASF2 + .byte 0x1 + .long .LASF3 + .long .LASF4 + .quad .Ltext0 + .quad .Letext0 + .long .Ldebug_line0 + .uleb128 0x2 + .byte 0x1 + .string "foo" + .byte 0x1 + .byte 0x16 + .byte 0x1 + .quad .LFB2 + .quad .LFE2 + .long .LLST0 + .long .Ltype_int - .Ldebug_relative + .uleb128 0x3 + .long .LASF5 + .byte 0x1 + .byte 0x15 + .long .Ltype_int - .Ldebug_relative + .byte 0x2 + .byte 0x91 + .sleb128 -52 +.Ltag_pointer: + .uleb128 0x4 + .byte 0x8 /* DW_AT_byte_size */ + .long .Ltag_array_type - .debug_info /* DW_AT_type */ + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */ + .long .LASF0 + .byte 0x1 + .byte 0x18 +#if 1 + .long .Ltag_pointer - .debug_info +#else + /* Debugging only: Skip the typedef indirection. */ + .long .Ltag_array_type - .debug_info +#endif + /* DW_AT_location: DW_FORM_block1: start */ + .byte 0x3 + .byte 0x91 + .sleb128 -32 +#if 0 + .byte 0x6 /* DW_OP_deref */ +#else + .byte 0x96 /* DW_OP_nop */ +#endif + /* DW_AT_location: DW_FORM_block1: end */ + .uleb128 0x6 + .string "i" + .byte 0x1 + .byte 0x19 + .long .Ltype_int - .Ldebug_relative + .byte 0x2 + .byte 0x91 + .sleb128 -20 + .byte 0x0 +.Ltype_int: + .uleb128 0x7 + .byte 0x4 + .byte 0x5 + .string "int" +.Ltag_array_type: + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */ + .long .Ltype_char - .Ldebug_relative + .long .Ltype_ulong - .Ldebug_relative /* DW_AT_sibling: DW_FORM_ref4 */ +1: /* DW_AT_data_location: DW_FORM_block1: start */ + .byte 2f - 3f /* length */ +3: + .byte 0x97 /* DW_OP_push_object_address */ +#if 1 + .byte 0x6 /* DW_OP_deref */ +#else + .byte 0x96 /* DW_OP_nop */ +#endif +2: /* DW_AT_data_location: DW_FORM_block1: end */ + .uleb128 0x9 + .long .Ltype_char - .Ldebug_relative /* DW_AT_type: DW_FORM_ref4 */ + .byte 0x3 + .byte 0x91 + .sleb128 -40 + .byte 0x6 + .byte 0x0 +.Ltype_ulong: + .uleb128 0xa + .byte 0x8 + .byte 0x7 +.Ltype_char: + .uleb128 0xb + .byte 0x1 + .byte 0x6 + .long .LASF1 + .byte 0x0 +.Ldebug_end: + .section .debug_abbrev + .uleb128 0x1 + .uleb128 0x11 + .byte 0x1 + .uleb128 0x25 + .uleb128 0xe + .uleb128 0x13 + .uleb128 0xb + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x1b + .uleb128 0xe + .uleb128 0x11 + .uleb128 0x1 + .uleb128 0x12 + .uleb128 0x1 + .uleb128 0x10 + .uleb128 0x6 + .byte 0x0 + .byte 0x0 + .uleb128 0x2 + .uleb128 0x2e + .byte 0x1 + .uleb128 0x3f + .uleb128 0xc + .uleb128 0x3 + .uleb128 0x8 + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x27 + .uleb128 0xc + .uleb128 0x11 + .uleb128 0x1 + .uleb128 0x12 + .uleb128 0x1 + .uleb128 0x40 + .uleb128 0x6 + .uleb128 0x1 + .uleb128 0x13 + .byte 0x0 + .byte 0x0 + .uleb128 0x3 + .uleb128 0x5 + .byte 0x0 + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .uleb128 0x2 + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0x4 /* .Ltag_pointer abbrev */ + .uleb128 0x0f /* DW_TAG_pointer_type */ + .byte 0x0 + .uleb128 0x0b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .byte 0x0 + .byte 0x0 + .uleb128 0x5 + .uleb128 0x34 + .byte 0x0 + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .uleb128 0x2 + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0x6 + .uleb128 0x34 + .byte 0x0 + .uleb128 0x3 + .uleb128 0x8 + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .uleb128 0x2 + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0x7 + .uleb128 0x24 + .byte 0x0 + .uleb128 0xb + .uleb128 0xb + .uleb128 0x3e + .uleb128 0xb + .uleb128 0x3 + .uleb128 0x8 + .byte 0x0 + .byte 0x0 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */ + .uleb128 0x1 + .byte 0x1 + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x1 /* DW_AT_sibling */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x50 /* DW_AT_data_location */ + .uleb128 0xa /* DW_FORM_block1 */ + .byte 0x0 + .byte 0x0 + .uleb128 0x9 + .uleb128 0x21 + .byte 0x0 + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x2f + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0xa + .uleb128 0x24 + .byte 0x0 + .uleb128 0xb + .uleb128 0xb + .uleb128 0x3e + .uleb128 0xb + .byte 0x0 + .byte 0x0 + .uleb128 0xb + .uleb128 0x24 + .byte 0x0 + .uleb128 0xb + .uleb128 0xb + .uleb128 0x3e + .uleb128 0xb + .uleb128 0x3 + .uleb128 0xe + .byte 0x0 + .byte 0x0 + .byte 0x0 + .section .debug_pubnames,"",@progbits + .long 0x16 + .value 0x2 + .long .Ldebug_info0 + .long 0xa8 + .long 0x2d + .string "foo" + .long 0x0 + .section .debug_aranges,"",@progbits + .long 0x2c + .value 0x2 + .long .Ldebug_info0 + .byte 0x8 + .byte 0x0 + .value 0x0 + .value 0x0 + .quad .Ltext0 + .quad .Letext0-.Ltext0 + .quad 0x0 + .quad 0x0 + .section .debug_str,"MS",@progbits,1 +.LASF0: + .string "array" +.LASF5: + .string "size" +.LASF3: + .string "x86_64-vla-pointer.c" +.LASF6: + .string "array_t" +.LASF1: + .string "char" +.LASF4: + .string "gdb.arch" +.LASF2: + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)" + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)" + .section .note.GNU-stack,"",@progbits Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,43 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2009 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#if 0 + +void +foo (int size) +{ + typedef char array_t[size]; + array_t array; + int i; + + for (i = 0; i < size; i++) + array[i] = i; + + array[0] = 0; /* break-here */ +} + +#else + +int +main (void) +{ + foo (26); + foo (78); + return 0; +} + +#endif Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,66 @@ +# Copyright 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +if ![istarget "x86_64-*-*"] then { + verbose "Skipping over gdb.arch/x86_64-vla-pointer.exp test made only for x86_64." + return +} + +set testfile x86_64-vla-pointer +set srcasmfile ${testfile}-foo.S +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } { + untested "Couldn't compile test program" + return -1 +} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] { + untested x86_64-vla-pointer + return -1 +} + +gdb_breakpoint "break_here" + +gdb_continue_to_breakpoint "break_here" + +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array" +gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array" + +gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array" +gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array" + +gdb_test "p (*array)\[1\]" "\\$\[0-9\] = 1 '\\\\001'" +gdb_test "p (*array)\[2\]" "\\$\[0-9\] = 2 '\\\\002'" +gdb_test "p (*array)\[3\]" "\\$\[0-9\] = 3 '\\\\003'" +gdb_test "p (*array)\[4\]" "\\$\[0-9\] = 4 '\\\\004'" + +gdb_continue_to_breakpoint "break_here" + +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array" +gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array" + +gdb_test "whatis *array" "type = char \\\[78\\\]" "second: whatis *array" +gdb_test "ptype *array" "type = char \\\[78\\\]" "second: ptype *array" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,455 @@ + .file "x86_64-vla-typedef.c" + .section .debug_abbrev,"",@progbits +.Ldebug_abbrev0: + .section .debug_info,"",@progbits +.Ldebug_info0: + .section .debug_line,"",@progbits +.Ldebug_line0: + .text +.Ltext0: +.globl foo + .type foo, @function +foo: +.LFB2: + .file 1 "x86_64-vla-typedef.c" + .loc 1 22 0 + pushq %rbp +.LCFI0: + movq %rsp, %rbp +.LCFI1: + subq $64, %rsp +.LCFI2: + movl %edi, -36(%rbp) + .loc 1 22 0 + movq %rsp, %rax + movq %rax, -48(%rbp) + .loc 1 23 0 + movl -36(%rbp), %edx + movslq %edx,%rax + subq $1, %rax + movq %rax, -24(%rbp) + .loc 1 24 0 + movslq %edx,%rax + addq $15, %rax + addq $15, %rax + shrq $4, %rax + salq $4, %rax + subq %rax, %rsp + movq %rsp, -56(%rbp) + movq -56(%rbp), %rax + addq $15, %rax + shrq $4, %rax + salq $4, %rax + movq %rax, -56(%rbp) + movq -56(%rbp), %rax + movq %rax, -16(%rbp) + .loc 1 27 0 + movl $0, -4(%rbp) + jmp .L2 +.L3: + .loc 1 28 0 + movl -4(%rbp), %esi + movl -4(%rbp), %eax + movl %eax, %ecx + movq -16(%rbp), %rdx + movslq %esi,%rax + movb %cl, (%rdx,%rax) + .loc 1 27 0 + addl $1, -4(%rbp) +.L2: + movl -4(%rbp), %eax + cmpl -36(%rbp), %eax + jl .L3 + .loc 1 30 0 + .globl break_here +break_here: + movq -16(%rbp), %rax + movb $0, (%rax) + movq -48(%rbp), %rsp + .loc 1 31 0 + leave + ret +.LFE2: + .size foo, .-foo + .section .debug_frame,"",@progbits +.Lframe0: + .long .LECIE0-.LSCIE0 +.LSCIE0: + .long 0xffffffff + .byte 0x1 + .string "" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE0: +.LSFDE0: + .long .LEFDE0-.LASFDE0 +.LASFDE0: + .long .Lframe0 + .quad .LFB2 + .quad .LFE2-.LFB2 + .byte 0x4 + .long .LCFI0-.LFB2 + .byte 0xe + .uleb128 0x10 + .byte 0x86 + .uleb128 0x2 + .byte 0x4 + .long .LCFI1-.LCFI0 + .byte 0xd + .uleb128 0x6 + .align 8 +.LEFDE0: + .section .eh_frame,"a",@progbits +.Lframe1: + .long .LECIE1-.LSCIE1 +.LSCIE1: + .long 0x0 + .byte 0x1 + .string "zR" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .uleb128 0x1 + .byte 0x3 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE1: +.LSFDE1: + .long .LEFDE1-.LASFDE1 +.LASFDE1: + .long .LASFDE1-.Lframe1 + .long .LFB2 + .long .LFE2-.LFB2 + .uleb128 0x0 + .byte 0x4 + .long .LCFI0-.LFB2 + .byte 0xe + .uleb128 0x10 + .byte 0x86 + .uleb128 0x2 + .byte 0x4 + .long .LCFI1-.LCFI0 + .byte 0xd + .uleb128 0x6 + .align 8 +.LEFDE1: + .text +.Letext0: + .section .debug_loc,"",@progbits +.Ldebug_loc0: +.LLST0: + .quad .LFB2-.Ltext0 + .quad .LCFI0-.Ltext0 + .value 0x2 + .byte 0x77 + .sleb128 8 + .quad .LCFI0-.Ltext0 + .quad .LCFI1-.Ltext0 + .value 0x2 + .byte 0x77 + .sleb128 16 + .quad .LCFI1-.Ltext0 + .quad .LFE2-.Ltext0 + .value 0x2 + .byte 0x76 + .sleb128 16 + .quad 0x0 + .quad 0x0 + .section .debug_info + .long .Ldebug_end - .Ldebug_start +.Ldebug_start: + .value 0x2 + .long .Ldebug_abbrev0 + .byte 0x8 + .uleb128 0x1 + .long .LASF2 + .byte 0x1 + .long .LASF3 + .long .LASF4 + .quad .Ltext0 + .quad .Letext0 + .long .Ldebug_line0 + .uleb128 0x2 + .byte 0x1 + .string "foo" + .byte 0x1 + .byte 0x16 + .byte 0x1 + .quad .LFB2 + .quad .LFE2 + .long .LLST0 + .long 0x83 + .uleb128 0x3 + .long .LASF5 + .byte 0x1 + .byte 0x15 + .long 0x83 + .byte 0x2 + .byte 0x91 + .sleb128 -52 +.Ltag_typedef: + .uleb128 0x4 + .long .LASF6 + .byte 0x1 + .byte 0x17 + .long .Ltag_array_type - .debug_info + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */ + .long .LASF0 + .byte 0x1 + .byte 0x18 +#if 1 + .long .Ltag_typedef - .debug_info +#else + /* Debugging only: Skip the typedef indirection. */ + .long .Ltag_array_type - .debug_info +#endif + /* DW_AT_location: DW_FORM_block1: start */ + .byte 0x3 + .byte 0x91 + .sleb128 -32 +#if 0 + .byte 0x6 /* DW_OP_deref */ +#else + .byte 0x96 /* DW_OP_nop */ +#endif + /* DW_AT_location: DW_FORM_block1: end */ + .uleb128 0x6 + .string "i" + .byte 0x1 + .byte 0x19 + .long 0x83 + .byte 0x2 + .byte 0x91 + .sleb128 -20 + .byte 0x0 + .uleb128 0x7 + .byte 0x4 + .byte 0x5 + .string "int" +.Ltag_array_type: + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */ + .long 0xa0 + (2f - 1f) /* DW_AT_type: DW_FORM_ref4 */ + .long 0x9d + (2f - 1f) /* DW_AT_sibling: DW_FORM_ref4 */ +1: /* DW_AT_data_location: DW_FORM_block1: start */ + .byte 2f - 3f /* length */ +3: + .byte 0x97 /* DW_OP_push_object_address */ + .byte 0x6 /* DW_OP_deref */ +2: /* DW_AT_data_location: DW_FORM_block1: end */ + .uleb128 0x9 + .long 0x9d + (2b - 1b) /* DW_AT_type: DW_FORM_ref4 */ + .byte 0x3 + .byte 0x91 + .sleb128 -40 + .byte 0x6 + .byte 0x0 + .uleb128 0xa + .byte 0x8 + .byte 0x7 + .uleb128 0xb + .byte 0x1 + .byte 0x6 + .long .LASF1 + .byte 0x0 +.Ldebug_end: + .section .debug_abbrev + .uleb128 0x1 + .uleb128 0x11 + .byte 0x1 + .uleb128 0x25 + .uleb128 0xe + .uleb128 0x13 + .uleb128 0xb + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x1b + .uleb128 0xe + .uleb128 0x11 + .uleb128 0x1 + .uleb128 0x12 + .uleb128 0x1 + .uleb128 0x10 + .uleb128 0x6 + .byte 0x0 + .byte 0x0 + .uleb128 0x2 + .uleb128 0x2e + .byte 0x1 + .uleb128 0x3f + .uleb128 0xc + .uleb128 0x3 + .uleb128 0x8 + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x27 + .uleb128 0xc + .uleb128 0x11 + .uleb128 0x1 + .uleb128 0x12 + .uleb128 0x1 + .uleb128 0x40 + .uleb128 0x6 + .uleb128 0x1 + .uleb128 0x13 + .byte 0x0 + .byte 0x0 + .uleb128 0x3 + .uleb128 0x5 + .byte 0x0 + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .uleb128 0x2 + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0x4 + .uleb128 0x16 + .byte 0x0 + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .byte 0x0 + .byte 0x0 + .uleb128 0x5 + .uleb128 0x34 + .byte 0x0 + .uleb128 0x3 + .uleb128 0xe + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .uleb128 0x2 + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0x6 + .uleb128 0x34 + .byte 0x0 + .uleb128 0x3 + .uleb128 0x8 + .uleb128 0x3a + .uleb128 0xb + .uleb128 0x3b + .uleb128 0xb + .uleb128 0x49 + .uleb128 0x13 + .uleb128 0x2 + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0x7 + .uleb128 0x24 + .byte 0x0 + .uleb128 0xb + .uleb128 0xb + .uleb128 0x3e + .uleb128 0xb + .uleb128 0x3 + .uleb128 0x8 + .byte 0x0 + .byte 0x0 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */ + .uleb128 0x1 + .byte 0x1 + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x1 /* DW_AT_sibling */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x50 /* DW_AT_data_location */ + .uleb128 0xa /* DW_FORM_block1 */ + .byte 0x0 + .byte 0x0 + .uleb128 0x9 + .uleb128 0x21 + .byte 0x0 + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x2f + .uleb128 0xa + .byte 0x0 + .byte 0x0 + .uleb128 0xa + .uleb128 0x24 + .byte 0x0 + .uleb128 0xb + .uleb128 0xb + .uleb128 0x3e + .uleb128 0xb + .byte 0x0 + .byte 0x0 + .uleb128 0xb + .uleb128 0x24 + .byte 0x0 + .uleb128 0xb + .uleb128 0xb + .uleb128 0x3e + .uleb128 0xb + .uleb128 0x3 + .uleb128 0xe + .byte 0x0 + .byte 0x0 + .byte 0x0 + .section .debug_pubnames,"",@progbits + .long 0x16 + .value 0x2 + .long .Ldebug_info0 + .long 0xa8 + .long 0x2d + .string "foo" + .long 0x0 + .section .debug_aranges,"",@progbits + .long 0x2c + .value 0x2 + .long .Ldebug_info0 + .byte 0x8 + .byte 0x0 + .value 0x0 + .value 0x0 + .quad .Ltext0 + .quad .Letext0-.Ltext0 + .quad 0x0 + .quad 0x0 + .section .debug_str,"MS",@progbits,1 +.LASF0: + .string "array" +.LASF5: + .string "size" +.LASF3: + .string "x86_64-vla-typedef.c" +.LASF6: + .string "array_t" +.LASF1: + .string "char" +.LASF4: + .string "gdb.arch" +.LASF2: + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)" + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)" + .section .note.GNU-stack,"",@progbits Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,43 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#if 0 + +void +foo (int size) +{ + typedef char array_t[size]; + array_t array; + int i; + + for (i = 0; i < size; i++) + array[i] = i; + + array[0] = 0; /* break-here */ +} + +#else + +int +main (void) +{ + foo (26); + foo (78); + return 0; +} + +#endif Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,64 @@ +# Copyright 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate. + +if ![istarget "x86_64-*-*"] then { + verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64." + return +} + +set testfile x86_64-vla-typedef +set srcasmfile ${testfile}-foo.S +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } { + untested "Couldn't compile test program" + return -1 +} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] { + untested x86_64-vla-typedef + return -1 +} + +gdb_breakpoint "break_here" + +gdb_continue_to_breakpoint "break_here" + +gdb_test "whatis array" "type = array_t" "first: whatis array" + +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array" + +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'" +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'" +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'" +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'" + +gdb_continue_to_breakpoint "break_here" + +gdb_test "whatis array" "type = array_t" "second: whatis array" + +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/arrayidx.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.base/arrayidx.c 2011-01-01 16:33:40.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/arrayidx.c 2011-05-25 17:05:21.000000000 +0200 @@ -17,6 +17,13 @@ int array[] = {1, 2, 3, 4}; +#ifdef __GNUC__ +struct + { + int a[0]; + } unbound; +#endif + int main (void) { Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/arrayidx.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.base/arrayidx.exp 2011-01-01 16:33:40.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/arrayidx.exp 2011-05-25 17:05:21.000000000 +0200 @@ -57,4 +57,12 @@ gdb_test "print array" \ "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \ "Print array with array-indexes on" - +set test "p unbound.a == &unbound.a\[0\]" +gdb_test_multiple $test $test { + -re " = 1\r\n$gdb_prompt $" { + pass $test + } + -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" { + unsupported "$test (no GCC)" + } +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/default.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.base/default.exp 2011-02-15 22:17:52.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/default.exp 2011-05-25 17:05:21.000000000 +0200 @@ -607,6 +607,17 @@ gdb_test_list_exact "show convenience" " {$_sdata = void} \ {$_siginfo = void} \ {$_thread = 0} \ + {$_probe_argc = } \ + {$_probe_arg0 = } \ + {$_probe_arg1 = } \ + {$_probe_arg2 = } \ + {$_probe_arg3 = } \ + {$_probe_arg4 = } \ + {$_probe_arg5 = } \ + {$_probe_arg6 = } \ + {$_probe_arg7 = } \ + {$_probe_arg8 = } \ + {$_probe_arg9 = } \ } #test show directories Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/internal-var-field-address.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/internal-var-field-address.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,20 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2009 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +struct { + int field; +} staticstruct = { 1 }; Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/internal-var-field-address.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/internal-var-field-address.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,26 @@ +# Copyright 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +set test internal-var-field-address +set binfile ${test}.x +if { [gdb_compile "${srcdir}/${subdir}/${test}.c" "${objdir}/${subdir}/${binfile}" object {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +clean_restart $binfile + +gdb_test {set $varstruct = staticstruct} +gdb_test {p $varstruct.field} " = 1" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/stap-probe.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/stap-probe.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,69 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#if USE_PROBES + +#define _SDT_HAS_SEMAPHORES +__extension__ unsigned short teste_user_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes"))); +#define TEST teste_user_semaphore + +__extension__ unsigned short teste_two_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes"))); +#define TEST2 teste_two_semaphore + +#else + +#define TEST 1 +#define TEST2 1 + +#endif + +#include + +/* We only support SystemTap and only the v3 form. */ +#if _SDT_NOTE_TYPE != 3 +#error "not using SystemTap v3 probes" +#endif + +void +m1 (void) +{ + if (TEST2) + STAP_PROBE (teste, two); +} + +void +m2 (void) +{ + if (TEST2) + STAP_PROBE (teste, two); +} + +int +f (int x) +{ + if (TEST) + STAP_PROBE1(teste, user, x); + return x+5; +} + +int +main() +{ + f(f(23)); + m1(); + m2(); +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/stap-probe.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/stap-probe.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,72 @@ +# Copyright (C) 2011 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +set testfile stap-probe + +# Run the tests. We run the tests two different ways: once with a +# plain probe, and once with a probe that has an associated semaphore. +# This returns -1 on failure to compile or start, 0 otherwise. +proc stap_test {{arg ""}} { + global testfile hex + + if {$arg != ""} { + set arg "additional_flags=$arg" + set addendum ", with semaphore" + } else { + set addendum ", no semaphore" + } + + if {[prepare_for_testing ${testfile}.exp ${testfile} ${testfile}.c \ + [concat $arg debug]]} { + return -1 + } + + if ![runto_main] { + return -1 + } + + gdb_test "print \$_probe_argc" "No SystemTap probe at PC $hex" \ + "check argument not at probe point$addendum" + + gdb_test "info probes" \ + "teste *user *$hex .*" \ + "info probes$addendum" + + if {[runto "probe:teste:user"]} { + pass "run to probe:teste:user$addendum" + } else { + fail "run to probe:teste:user$addendum" + } + + # Test probe arguments. + gdb_test "print \$_probe_argc" " = 1" "print \$_probe_argc$addendum" + gdb_test "print \$_probe_arg0 == x" " = 1" "check \$_probe_arg0$addendum" + gdb_test "print \$_probe_arg1" \ + "Invalid probe argument 1 -- probe has 1 arguments available" \ + "check \$_probe_arg1$addendum" + + # Set a breakpoint with multiple probe locations. + gdb_test "break probe:teste:two" \ + "Breakpoint .* at $hex.*2 locations.*" \ + "set multi-location probe breakpoint$addendum" + + return 0 +} + +if {[stap_test] == -1} { + untested stap-probe.exp + return -1 +} +stap_test "-DUSE_PROBES" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla-overflow.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla-overflow.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,30 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#include + +int +main (int argc, char **argv) +{ + int array[argc]; + + array[0] = array[0]; + + abort (); + + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla-overflow.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla-overflow.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,109 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +# We could crash in: +# #0 block_linkage_function (bl=0x0) at ../../gdb/block.c:69 +# #1 in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97 +# 97 framefunc = block_linkage_function (get_frame_block (frame, NULL)); +# #2 in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496 +# #3 in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156 +# #4 dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206 +# #5 in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430 +# #6 in create_array_type (...) at ../../gdb/gdbtypes.c:840 +# ... +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292 +# ... +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273 + +set testfile vla-overflow +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +set f [open "|getconf PAGESIZE" "r"] +gets $f pagesize +close $f + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +set pid_of_gdb [exp_pid -i [board_info host fileid]] + +if { [runto_main] < 0 } { + untested vla-overflow + return -1 +} + +# Get the GDB memory size when we stay at main. + +proc memory_v_pages_get {} { + global pid_of_gdb pagesize + set fd [open "/proc/$pid_of_gdb/statm"] + gets $fd line + close $fd + # number of pages of virtual memory + scan $line "%d" drs + return $drs +} + +set pages_found [memory_v_pages_get] + +# s390x with glibc-debuginfo.s390x installed used approx. 16MB. +set mb_reserve 40 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve" +set kb_found [expr $pages_found * $pagesize / 1024] +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024] +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit" + +# Create the ulimit wrapper. +set f [open $shfile "w"] +puts $f "#! /bin/sh" +puts $f "ulimit -v $kb_permit" +puts $f "exec $GDB \"\$@\"" +close $f +remote_exec host "chmod +x $shfile" + +gdb_exit +set GDBold $GDB +set GDB "$shfile" +gdb_start +set GDB $GDBold + +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +set pid_of_gdb [exp_pid -i [board_info host fileid]] + +# Check the size again after the second run. +# We must not stop in main as it would cache `array' and never crash later. + +gdb_run_cmd + +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]" + +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()" + +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]" + +# `abort' can get expressed as `*__GI_abort'. +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()" + +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,55 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#include + +void +marker (void) +{ +} + +void +bar (char *a, char *b, char *c, int size) +{ + memset (a, '1', size); + memset (b, '2', size); + memset (c, '3', 48); +} + +void +foo (int size) +{ + char temp1[size]; + char temp3[48]; + + temp1[size - 1] = '\0'; + { + char temp2[size]; + + bar (temp1, temp2, temp3, size); + + marker (); /* break-here */ + } +} + +int +main (void) +{ + foo (26); + foo (78); + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.base/vla.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,62 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +set testfile vla +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] { + untested vla + return -1 +} + +gdb_breakpoint [gdb_get_line_number "break-here"] + +gdb_continue_to_breakpoint "break-here" + +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1" +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2" +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3" + +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1" +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2" +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3" + +gdb_test "p temp1" " = '1' " "first: print temp1" +gdb_test "p temp2" " = '2' " "first: print temp2" +gdb_test "p temp3" " = '3' " "first: print temp3" + +gdb_continue_to_breakpoint "break-here" + +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1" +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2" +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3" + +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1" +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2" +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3" + +gdb_test "p temp1" " = '1' " "second: print temp1" +gdb_test "p temp2" " = '2' " "second: print temp2" +gdb_test "p temp3" " = '3' " "second: print temp3" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.cp/nextoverthrow.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.cp/nextoverthrow.exp 2011-01-01 16:33:44.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.cp/nextoverthrow.exp 2011-05-25 17:05:21.000000000 +0200 @@ -53,6 +53,17 @@ gdb_test_multiple "print _Unwind_DebugHo } } if {!$ok} { + gdb_test_multiple "info probe" "check for stap probe in unwinder" { + -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" { + pass "check for stap probe in unwinder" + set ok 1 + } + -re "\r\n$gdb_prompt $" { + } + } +} + +if {!$ok} { unsupported "nextoverthrow.exp could not find _Unwind_DebugHook" return -1 } Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,246 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +/* Debug information */ + +/* We will `break *main' at the very first instruction. */ +#define main_length 1 + + .section .data +vardata: + /* See DW_OP_lit3 + 1 (0-based). */ + .string "seennotseen" + + .section .debug_info +.Lcu1_begin: + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */ +.Lcu1_start: + .2byte 2 /* DWARF version number */ + .4byte .Ldebug_abbrev0 /* Offset Into Abbrev. Section */ + .byte 4 /* Pointer Size (in bytes) */ + + /* CU die */ + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */ + .4byte .Lproducer /* DW_AT_producer */ + /* Use C++ to exploit a bug in parsing DW_AT_name "". */ + .byte 4 /* DW_AT_language (C++) - */ + .4byte main /* DW_AT_low_pc */ + .byte main_length /* DW_AT_high_pc */ + +.Larray_type: + .uleb128 2 /* Abbrev: DW_TAG_array_type */ + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */ + + .uleb128 3 /* Abbrev: DW_TAG_subrange_type */ + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */ + .byte 0 /* DW_AT_lower_bound */ + .4byte .Llen_var-.Lcu1_begin /* DW_AT_upper_bound */ + .byte 0 /* End of children of die */ + + /* DW_AT_upper_bound is referencing an optimized-out variable. */ +.Larrayb_type: + .uleb128 2 /* Abbrev: DW_TAG_array_type */ + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */ + + .uleb128 3 /* Abbrev: DW_TAG_subrange_type */ + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */ + .byte 0 /* DW_AT_lower_bound */ + .4byte .Llenb_var-.Lcu1_begin /* DW_AT_upper_bound */ + .byte 0 /* End of children of die */ + + /* DW_AT_upper_bound is referencing register. */ +.Larrayreg_type: + .uleb128 2 /* Abbrev: DW_TAG_array_type */ + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */ + + .uleb128 8 /* Abbrev: DW_TAG_subrange_type with block */ + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */ + .byte 0 /* DW_AT_lower_bound */ + .byte 2f - 1f /* DW_AT_upper_bound */ +1: .byte 0x50 /* DW_OP_reg0 */ +2: + .byte 0 /* End of children of die */ + +.Luint_type: + .uleb128 4 /* Abbrev: DW_TAG_base_type */ + .4byte .Luint_str /* DW_AT_name */ + .byte 4 /* DW_AT_byte_size */ + .byte 7 /* DW_AT_encoding */ + +.Lchar_type: + .uleb128 4 /* Abbrev: DW_TAG_base_type */ + .4byte .Lchar_str /* DW_AT_name */ + .byte 1 /* DW_AT_byte_size */ + .byte 6 /* DW_AT_encoding */ + +.Llen_var: + .uleb128 5 /* Abbrev: DW_TAG_variable artificial */ + .byte 1 /* DW_AT_artificial */ + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */ + .4byte .Llen_loclist-.Lloclist /* DW_AT_location */ + + /* optimized-out variable for b_string. */ +.Llenb_var: + .uleb128 7 /* Abbrev: DW_TAG_variable artificial no DW_AT_location */ + .byte 1 /* DW_AT_artificial */ + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */ + + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */ + .string "a_string" /* DW_AT_name */ + .4byte .Larray_type-.Lcu1_begin /* DW_AT_type */ + .byte 2f - 1f /* DW_AT_location */ +1: .byte 3 /* DW_OP_addr */ + .4byte vardata /* */ +2: + + /* DW_AT_upper_bound is referencing an optimized-out variable. */ + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */ + .string "b_string" /* DW_AT_name */ + .4byte .Larrayb_type-.Lcu1_begin /* DW_AT_type */ + .byte 2f - 1f /* DW_AT_location */ +1: .byte 3 /* DW_OP_addr */ + .4byte vardata /* */ +2: + + /* DW_AT_upper_bound is referencing register. */ + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */ + .string "reg_string" /* DW_AT_name */ + .4byte .Larrayreg_type-.Lcu1_begin /* DW_AT_type */ + .byte 2f - 1f /* DW_AT_location */ +1: .byte 3 /* DW_OP_addr */ + .4byte vardata /* */ +2: + + .byte 0 /* End of children of CU */ +.Lcu1_end: + + .section .debug_loc +.Lloclist: +.Llen_loclist: + .4byte 0 # Location list begin address + .4byte main_length # Location list end address + .value 2f-1f # Location expression size +1: .byte 0x33 # DW_OP_lit3 + .byte 0x9f # DW_OP_stack_value +2: + .quad 0x0 # Location list terminator begin (*.LLST2) + .quad 0x0 # Location list terminator end (*.LLST2) + + .section .debug_abbrev +.Ldebug_abbrev0: + .uleb128 1 /* Abbrev code */ + .uleb128 0x11 /* DW_TAG_compile_unit */ + .byte 0x1 /* has_children */ + .uleb128 0x25 /* DW_AT_producer */ + .uleb128 0xe /* DW_FORM_strp */ + .uleb128 0x13 /* DW_AT_language */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x11 /* DW_AT_low_pc */ + .uleb128 0x1 /* DW_FORM_addr */ + .uleb128 0x12 /* DW_AT_high_pc */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 2 /* Abbrev code */ + .uleb128 0x1 /* TAG: DW_TAG_array_type */ + .byte 0x1 /* DW_children_yes */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 3 /* Abbrev code */ + .uleb128 0x21 /* DW_TAG_subrange_type */ + .byte 0x0 /* no children */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x22 /* DW_AT_lower_bound */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x2f /* DW_AT_upper_bound */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 4 /* Abbrev code */ + .uleb128 0x24 /* DW_TAG_base_type */ + .byte 0x0 /* no_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0xe /* DW_FORM_strp */ + .uleb128 0xb /* DW_AT_byte_size */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x3e /* DW_AT_encoding */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 5 /* Abbrev code */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0x0 /* no_children */ + .uleb128 0x34 /* DW_AT_artificial */ + .uleb128 0x0c /* DW_FORM_flag */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x02 /* DW_AT_location */ + .uleb128 0x06 /* DW_FORM_data4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 6 /* Abbrev code */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0x0 /* no_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x2 /* DW_AT_location */ + .uleb128 0xa /* DW_FORM_block1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 7 /* Abbrev code */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0x0 /* no_children */ + .uleb128 0x34 /* DW_AT_artificial */ + .uleb128 0x0c /* DW_FORM_flag */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 8 /* Abbrev code */ + .uleb128 0x21 /* DW_TAG_subrange_type with block */ + .byte 0x0 /* no children */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .uleb128 0x22 /* DW_AT_lower_bound */ + .uleb128 0xb /* DW_FORM_data1 */ + .uleb128 0x2f /* DW_AT_upper_bound */ + .uleb128 0xa /* DW_FORM_block1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .byte 0x0 /* Terminator */ + +/* String table */ + .section .debug_str +.Lproducer: + .string "GNU C 3.3.3" +.Lchar_str: + .string "char" +.Luint_str: + .string "unsigned int" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,54 @@ +# Copyright 2010 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +# Test printing variable with dynamic bounds which reference a different +# (artificial in the GCC case) variable containing loclist as its location. +# This testcase uses value (not address) of the referenced variable: +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762 + +# This test can only be run on targets which support DWARF-2 and use gas. +# For now pick a sampling of likely targets. +if {![istarget *-*-linux*] + && ![istarget *-*-gnu*] + && ![istarget *-*-elf*] + && ![istarget *-*-openbsd*] + && ![istarget arm-*-eabi*] + && ![istarget powerpc-*-eabi*]} { + return 0 +} + +set testfile dw2-bound-loclist +if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } { + return -1 +} + +# Verify it behaves at least as an unbound array without inferior. + +gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"} +gdb_test "ptype a_string" {type = char \[\]} + +# Not runto_main as dw2-bound-loclist.S handles only the first byte of main. +if ![runto "*main"] { + return -1 +} + +gdb_test "p a_string" { = "seen"} +gdb_test "ptype a_string" {type = char \[4\]} + +gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"} +gdb_test "ptype b_string" {type = char \[\]} + +# The register contains unpredictable value - the array size. +gdb_test "ptype reg_string" {type = char \[-?[0-9]+\]} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-stripped.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-stripped.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,42 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2004 Free Software Foundation, Inc. + + 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 2 of the License, or + (at your option) any later version. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + + +/* The function `func1' traced into must have debug info on offset > 0; + (DW_UNSND (attr)). This is the reason of `func0' existence. */ + +void +func0(int a, int b) +{ +} + +/* `func1' being traced into must have some arguments to dump. */ + +void +func1(int a, int b) +{ + func0 (a,b); +} + +int +main(void) +{ + func1 (1, 2); + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,79 @@ +# Copyright 2006 Free Software Foundation, Inc. + +# 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 2 of the License, or +# (at your option) any later version. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Minimal DWARF-2 unit test + +# This test can only be run on targets which support DWARF-2. +# For now pick a sampling of likely targets. +if {![istarget *-*-linux*] + && ![istarget *-*-gnu*] + && ![istarget *-*-elf*] + && ![istarget *-*-openbsd*] + && ![istarget arm-*-eabi*] + && ![istarget powerpc-*-eabi*]} { + return 0 +} + +set testfile "dw2-stripped" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile}.x + +remote_exec build "rm -f ${binfile}" + +# get the value of gcc_compiled +if [get_compiler_info ${binfile}] { + return -1 +} + +# This test can only be run on gcc as we use additional_flags=FIXME +if {$gcc_compiled == 0} { + return 0 +} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } { + return -1 +} + +remote_exec build "objcopy -R .debug_loc ${binfile}" +set strip_output [remote_exec build "objdump -h ${binfile}"] + +set test "stripping test file preservation" +if [ regexp ".debug_info " $strip_output] { + pass "$test (.debug_info preserved)" +} else { + fail "$test (.debug_info got also stripped)" +} + +set test "stripping test file functionality" +if [ regexp ".debug_loc " $strip_output] { + fail "$test (.debug_loc still present)" +} else { + pass "$test (.debug_loc stripped)" +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# For C programs, "start" should stop in main(). + +gdb_test "start" \ + ".*main \\(\\) at .*" \ + "start" +gdb_test "step" \ + "func.* \\(.*\\) at .*" \ + "step" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,83 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2009 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +/* Debug information */ + + .section .debug_info +.Lcu1_begin: + /* CU header */ + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */ +.Lcu1_start: + .2byte 2 /* DWARF Version */ + .4byte .Labbrev1_begin /* Offset into abbrev section */ + .byte 4 /* Pointer size */ + + /* CU die */ + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */ + .ascii "dw2-struct-member-data-location.c\0" /* DW_AT_name */ + .ascii "GNU C 4.3.2\0" /* DW_AT_producer */ + .byte 1 /* DW_AT_language (C) */ + +.Ltype_uchar: + .uleb128 2 /* Abbrev: DW_TAG_structure_type */ + .ascii "some_struct\0" /* DW_AT_name */ + + .uleb128 3 /* Abbrev: DW_TAG_member */ + .ascii "field\0" /* DW_AT_name */ + .byte 0 /* DW_AT_data_member_location */ + + .byte 0 /* End of children of some_struct */ + + .byte 0 /* End of children of CU */ + +.Lcu1_end: + +/* Abbrev table */ + .section .debug_abbrev +.Labbrev1_begin: + .uleb128 1 /* Abbrev code */ + .uleb128 0x11 /* DW_TAG_compile_unit */ + .byte 1 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x25 /* DW_AT_producer */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x13 /* DW_AT_language */ + .uleb128 0xb /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 2 /* Abbrev code */ + .uleb128 0x13 /* DW_TAG_structure_type */ + .byte 1 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .uleb128 3 /* Abbrev code */ + .uleb128 0x0d /* DW_TAG_member */ + .byte 0 /* has_children */ + .uleb128 0x3 /* DW_AT_name */ + .uleb128 0x8 /* DW_FORM_string */ + .uleb128 0x38 /* DW_AT_data_member_location */ + .uleb128 0x0b /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,37 @@ +# Copyright 2009 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +# This test can only be run on targets which support DWARF-2 and use gas. +# For now pick a sampling of likely targets. +if {![istarget *-*-linux*] + && ![istarget *-*-gnu*] + && ![istarget *-*-elf*] + && ![istarget *-*-openbsd*] + && ![istarget arm-*-eabi*] + && ![istarget powerpc-*-eabi*]} { + return 0 +} + +set testfile "dw2-struct-member-data-location" +set srcfile ${testfile}.S +set binfile ${testfile}.x + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } { + return -1 +} + +clean_restart $binfile + +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dwarf-stride.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dwarf-stride.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,42 @@ +# Copyright 2009 Free Software Foundation, Inc. + +# 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 2 of the License, or +# (at your option) any later version. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# This file was written by Jan Kratochvil . + +# This file is part of the gdb testsuite. Array element stride must not be +# specified in the number of elements but in a number of bytes instead. +# Original problem: +# (gdb) p c40pt(1) +# $1 = '0-hello', ' ' +# (gdb) p c40pt(2) +# warning: Fortran array stride not divisible by the element size + +set testfile dwarf-stride +set srcfile ${testfile}.f90 + +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } { + return -1 +} + +if ![runto MAIN__] then { + perror "couldn't run to breakpoint MAIN__" + continue +} + +gdb_breakpoint [gdb_get_line_number "break-here"] +gdb_continue_to_breakpoint "break-here" ".*break-here.*" +gdb_test "p c40pt(1)" " = '0-hello.*" +gdb_test "p c40pt(2)" " = '1-hello.*" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dwarf-stride.f90 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dwarf-stride.f90 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,40 @@ +! Copyright 2009 Free Software Foundation, Inc. +! +! 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 2 of the License, or +! (at your option) any later version. +! +! 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 this program; if not, write to the Free Software +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +! +! File written by Alan Matsuoka. + +program repro + + type small_stride + character*40 long_string + integer small_pad + end type small_stride + + type(small_stride), dimension (20), target :: unpleasant + character*40, pointer, dimension(:):: c40pt + + integer i + + do i = 0,19 + unpleasant(i+1)%small_pad = i+1 + unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello' + end do + + c40pt => unpleasant%long_string + + print *, c40pt ! break-here + +end program repro Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,24 @@ +! Copyright 2010 Free Software Foundation, Inc. +! +! 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 2 of the License, or +! (at your option) any later version. +! +! 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 this program; if not, write to the Free Software +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +! +! Ihis file is the Fortran source file for dynamic.exp. +! Original file written by Jakub Jelinek . +! Modified for the GDB testcase by Jan Kratochvil . + +subroutine bar + real :: dummy + dummy = 1 +end subroutine bar Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,37 @@ +# Copyright 2010 Free Software Foundation, Inc. + +# 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 2 of the License, or +# (at your option) any later version. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +set testfile "dynamic-other-frame" +set srcfile1 ${testfile}.f90 +set srcfile2 ${testfile}-stub.f90 +set objfile2 ${objdir}/${subdir}/${testfile}-stub.o +set executable ${testfile} +set binfile ${objdir}/${subdir}/${executable} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${objfile2}" object {f77}] != "" + || [gdb_compile "${srcdir}/${subdir}/${srcfile1} ${objfile2}" "${binfile}" executable {debug f77}] != "" } { + untested "Couldn't compile ${srcfile1} or ${srcfile2}" + return -1 +} + +clean_restart ${executable} + +if ![runto bar_] then { + perror "couldn't run to bar_" + continue +} + +gdb_test "bt" {foo \(string='hello'.*} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,36 @@ +! Copyright 2010 Free Software Foundation, Inc. +! +! 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 2 of the License, or +! (at your option) any later version. +! +! 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 this program; if not, write to the Free Software +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +! +! Ihis file is the Fortran source file for dynamic.exp. +! Original file written by Jakub Jelinek . +! Modified for the GDB testcase by Jan Kratochvil . + +subroutine foo (string) + interface + subroutine bar + end subroutine + end interface + character string*(*) + call bar ! stop-here +end subroutine foo +program test + interface + subroutine foo (string) + character string*(*) + end subroutine + end interface + call foo ('hello') +end Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,145 @@ +# Copyright 2007 Free Software Foundation, Inc. + +# 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 2 of the License, or +# (at your option) any later version. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# This file was written by Jan Kratochvil . + +# This file is part of the gdb testsuite. It contains tests for dynamically +# allocated Fortran arrays. +# It depends on the GCC dynamic Fortran arrays DWARF support: +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244 + +set testfile "dynamic" +set srcfile ${testfile}.f90 +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } { + untested "Couldn't compile ${srcfile}" + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto MAIN__] then { + perror "couldn't run to breakpoint MAIN__" + continue +} + +gdb_breakpoint [gdb_get_line_number "varx-init"] +gdb_continue_to_breakpoint "varx-init" +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated" +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated" +gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) unallocated" +gdb_test "p varx(1,5,17)=1" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17)=1 unallocated" +gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) unallocated" + +gdb_breakpoint [gdb_get_line_number "varx-allocated"] +gdb_continue_to_breakpoint "varx-allocated" +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...) +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated" +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1. +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated" + +gdb_breakpoint [gdb_get_line_number "varx-filled"] +gdb_continue_to_breakpoint "varx-filled" +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6" +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7" +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8" +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9" +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type. +gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv unassociated" +gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv unassociated" + +gdb_breakpoint [gdb_get_line_number "varv-associated"] +gdb_continue_to_breakpoint "varv-associated" +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated" +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated" +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1. +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated" +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated" +# Intel Fortran Compiler 10.1.008 uses the pointer type. +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated" + +gdb_breakpoint [gdb_get_line_number "varv-filled"] +gdb_continue_to_breakpoint "varv-filled" +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled" +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled" + +gdb_breakpoint [gdb_get_line_number "varv-deassociated"] +gdb_continue_to_breakpoint "varv-deassociated" +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type. +gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv deassociated" +gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv deassociated" +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated" +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\." +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\." + +gdb_breakpoint [gdb_get_line_number "varx-deallocated"] +gdb_continue_to_breakpoint "varx-deallocated" +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated" +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated" +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated" +gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) deallocated" +gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) deallocated" + +gdb_breakpoint [gdb_get_line_number "vary-passed"] +gdb_continue_to_breakpoint "vary-passed" +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...) +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)" + +gdb_breakpoint [gdb_get_line_number "vary-filled"] +gdb_continue_to_breakpoint "vary-filled" +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)" +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8" +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9" +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10" +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...) +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)" + +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"] +gdb_continue_to_breakpoint "varw-almostfilled" +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)" +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1" +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...) +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled" +# "up" works with GCC but other Fortran compilers may copy the values into the +# outer function only on the exit of the inner function. +# We need both variants as depending on the arch we optionally may still be +# executing the caller line or not after `finish'. +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))" +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3" +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6" +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5" +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1" + +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"] +gdb_continue_to_breakpoint "varz-almostfilled" +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not. +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?" +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7) +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7. +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?" +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)" +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)" +gdb_test "p varz(3)" "\\$\[0-9\]* = 4" +# maps to foo::vary(1,1) +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8" +# maps to foo::vary(2,2) +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9" +# maps to foo::vary(1,3) +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic.f90 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/dynamic.f90 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,98 @@ +! Copyright 2007 Free Software Foundation, Inc. +! +! 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 2 of the License, or +! (at your option) any later version. +! +! 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 this program; if not, write to the Free Software +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +! +! Ihis file is the Fortran source file for dynamic.exp. +! Original file written by Jakub Jelinek . +! Modified for the GDB testcase by Jan Kratochvil . + +subroutine baz + real, target, allocatable :: varx (:, :, :) + real, pointer :: varv (:, :, :) + real, target :: varu (1, 2, 3) + logical :: l + allocate (varx (1:6, 5:15, 17:28)) ! varx-init + l = allocated (varx) + varx(:, :, :) = 6 ! varx-allocated + varx(1, 5, 17) = 7 + varx(2, 6, 18) = 8 + varx(6, 15, 28) = 9 + varv => varx ! varx-filled + l = associated (varv) + varv(3, 7, 19) = 10 ! varv-associated + varv => null () ! varv-filled + l = associated (varv) + deallocate (varx) ! varv-deassociated + l = allocated (varx) + varu(:, :, :) = 10 ! varx-deallocated + allocate (varv (1:6, 5:15, 17:28)) + l = associated (varv) + varv(:, :, :) = 6 + varv(1, 5, 17) = 7 + varv(2, 6, 18) = 8 + varv(6, 15, 28) = 9 + deallocate (varv) + l = associated (varv) + varv => varu + varv(1, 1, 1) = 6 + varv(1, 2, 3) = 7 + l = associated (varv) +end subroutine baz +subroutine foo (vary, varw) + real :: vary (:, :) + real :: varw (:, :, :) + vary(:, :) = 4 ! vary-passed + vary(1, 1) = 8 + vary(2, 2) = 9 + vary(1, 3) = 10 + varw(:, :, :) = 5 ! vary-filled + varw(1, 1, 1) = 6 + varw(2, 2, 2) = 7 ! varw-almostfilled +end subroutine foo +subroutine bar (varz, vart) + real :: varz (*) + real :: vart (2:11, 7:*) + varz(1:3) = 4 + varz(2) = 5 ! varz-almostfilled + vart(2,7) = vart(2,7) +end subroutine bar +program test + interface + subroutine foo (vary, varw) + real :: vary (:, :) + real :: varw (:, :, :) + end subroutine + end interface + interface + subroutine bar (varz, vart) + real :: varz (*) + real :: vart (2:11, 7:*) + end subroutine + end interface + real :: x (10, 10), y (5), z(8, 8, 8) + x(:,:) = 1 + y(:) = 2 + z(:,:,:) = 3 + call baz + call foo (x, z(2:6, 4:7, 6:8)) + call bar (y, x) + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort + if (x (1, 3) .ne. 10) call abort + if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort + if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort + call foo (transpose (x), z) + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort + if (x (3, 1) .ne. 10) call abort +end Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/string.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/string.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,59 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# 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 2 of the License, or +# (at your option) any later version. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# This file was written by Jan Kratochvil . + +# This file is part of the gdb testsuite. It contains tests for Fortran +# strings with dynamic length. + +set testfile "string" +set srcfile ${testfile}.f90 +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } { + untested "Couldn't compile ${srcfile}" + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto MAIN__] then { + perror "couldn't run to breakpoint MAIN__" + continue +} + +gdb_breakpoint [gdb_get_line_number "var-init"] +gdb_continue_to_breakpoint "var-init" +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)" +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)" +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)" +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)" +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value." +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)" +gdb_test "p c" "\\$\[0-9\]* = 'c'" +gdb_test "p d" "\\$\[0-9\]* = 'd '" +gdb_test "p e" "\\$\[0-9\]* = 'g '" +gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'h ', 'h ', 'h ', 'h ', 'h ', 'h ', 'h '\\) \\( 'h ', 'h ', 'h ', 'h ', 'h ', 'h ', 'h '\\) \\( 'h ', 'h ', 'h ', 'h ', 'h ', 'h ', 'h '\\) \\)" +gdb_test "p *e" "Attempt to take contents of a non-pointer value." +gdb_test "p *f" "Attempt to take contents of a non-pointer value." + +gdb_breakpoint [gdb_get_line_number "var-finish"] +gdb_continue_to_breakpoint "var-finish" +gdb_test "p e" "\\$\[0-9\]* = 'e '" "p e re-set" +gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'f ', 'f ', 'f ', 'f ', 'f ', 'f ', 'f '\\) \\( 'f2 ', 'f ', 'f ', 'f ', 'f ', 'f ', 'f '\\) \\( 'f ', 'f ', 'f ', 'f ', 'f ', 'f ', 'f '\\) \\)" "p *f re-set" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/string.f90 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/string.f90 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,37 @@ +! Copyright 2008 Free Software Foundation, Inc. +! +! 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 2 of the License, or +! (at your option) any later version. +! +! 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 this program; if not, write to the Free Software +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +! +! Ihis file is the Fortran source file for dynamic.exp. +! Original file written by Jakub Jelinek . +! Modified for the GDB testcase by Jan Kratochvil . + +subroutine foo (e, f) + character (len=1) :: c + character (len=8) :: d + character (len=*) :: e + character (len=*) :: f (1:7, 8:10) + c = 'c' + d = 'd' + e = 'e' ! var-init + f = 'f' + f(1,9) = 'f2' + c = 'c' ! var-finish +end subroutine foo + character (len=4) :: g, h (1:7, 8:10) + g = 'g' + h = 'h' + call foo (g, h) +end Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/subrange.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/subrange.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,60 @@ +# Copyright 2011 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +if { [skip_fortran_tests] } { return -1 } + +set testfile "subrange" +set srcfile ${testfile}.f90 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } { + return -1 +} + +if ![runto MAIN__] { + perror "Couldn't run to MAIN__" + continue +} + +# Depending on the compiler version being used, the name of the 4-byte integer +# and real types can be printed differently. For instance, gfortran-4.1 uses +# "int4" whereas gfortran-4.3 uses "int(kind=4)". +set int4 "(int4|integer\\(kind=4\\))" + +gdb_breakpoint [gdb_get_line_number "break-static"] +gdb_continue_to_breakpoint "break-static" ".*break-static.*" + +foreach var {a alloc ptr} { + global pf_prefix + set old_prefix $pf_prefix + lappend pf_prefix "$var:" + + gdb_test "p $var (2, 2:3)" { = \(22, 32\)} + gdb_test "p $var (2:3, 3)" { = \(32, 33\)} + gdb_test "p $var (1, 2:)" { = \(21, 31\)} + gdb_test "p $var (2, :2)" { = \(12, 22\)} + gdb_test "p $var (3, 2:2)" { = \(23\)} + gdb_test "ptype $var (3, 2:2)" " = $int4 \\(2:2\\)" + gdb_test "p $var (4, :)" { = \(14, 24, 34\)} + gdb_test "p $var (:, :)" { = \(\( *11, 12, 13, 14\) \( *21, 22, 23, 24\) \( *31, 32, 33, 34\) *\)} + gdb_test "ptype $var (:, :)" " = $int4 \\(4,3\\)" + gdb_test "p $var (:)" "Wrong number of subscripts" + gdb_test "p $var (:, :, :)" "Wrong number of subscripts" + + set pf_prefix $old_prefix +} + +gdb_test_no_output {set $a=a} +delete_breakpoints +gdb_unload +gdb_test {p $a (3, 2:2)} { = \(23\)} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/subrange.f90 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.fortran/subrange.f90 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,28 @@ +! Copyright 2011 Free Software Foundation, Inc. +! +! 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 3 of the License, or +! (at your option) any later version. +! +! 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 this program. If not, see . + +program test + integer, target :: a (4, 3) + integer, allocatable :: alloc (:, :) + integer, pointer :: ptr (:, :) + do 1 i = 1, 4 + do 1 j = 1, 3 + a (i, j) = j * 10 + i +1 continue + allocate (alloc (4, 3)) + alloc = a + ptr => a + write (*,*) a ! break-static +end Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.gdb/selftest.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.gdb/selftest.exp 2011-05-25 17:04:21.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.gdb/selftest.exp 2011-05-25 17:05:21.000000000 +0200 @@ -92,6 +92,10 @@ proc do_steps_and_nexts {} { set description "step over ttyarg initialization" set command "step" } + -re ".*python_script = 0.*$gdb_prompt $" { + set description "step over python_script initialization" + set command "step" + } -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" { set description "next over make_command_stats_cleanup and everything it calls" set command "next" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.mi/mi2-var-stale-type.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.mi/mi2-var-stale-type.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,26 @@ +/* Copyright 2011 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +int +main (int argc, char **argv) +{ + char vla[argc]; + + vla[0] = 0; /* break-here */ + + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,57 @@ +# Copyright 2011 Free Software Foundation, Inc. +# +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +load_lib mi-support.exp +set MIFLAGS "-i=mi2" + +gdb_exit +if [mi_gdb_start] { + continue +} + +set testfile "mi2-var-stale-type" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { + return -1 +} + +mi_delete_breakpoints +mi_gdb_reinitialize_dir $srcdir/$subdir +mi_gdb_load ${binfile} + +mi_gdb_test {-interpreter-exec console "maintenance set internal-error quit yes"} \ + {\^done} \ + "maintenance set internal-error quit yes" + +mi_gdb_test {-interpreter-exec console "maintenance set internal-error corefile yes"} \ + {\^done} \ + "maintenance set internal-error corefile yes" + +set line [gdb_get_line_number "break-here"] +set func "main" + +mi_gdb_test "-break-insert -t $srcfile:$line" \ + "\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"$func\(\\\(.*\\\)\)?\",file=\".*\",line=\"$line\",times=\"0\",original-location=\".*\"\}" \ + "breakpoint at $func" + +if { [mi_run_cmd] < 0 } { + return -1 +} +mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "stop after initializing vla" + +mi_create_varobj "vla" "vla" "create local variable vla" + +mi_gdb_test "-var-update *" "\\^done,changelist=.*" "-var-update *" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.multi/watchpoint-multi.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.multi/watchpoint-multi.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,59 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#include +#include + +static volatile int a, b, c; + +static void +marker_exit1 (void) +{ + a = 1; +} + +/* Workaround PR breakpoints/12272 by two different breakpoint locations. */ +static void +marker_exit2 (void) +{ + a = 1; +} + +static void * +start (void *arg) +{ + b = 2; + c = 3; + + return NULL; +} + +int +main (void) +{ + pthread_t thread; + int i; + + i = pthread_create (&thread, NULL, start, NULL); + assert (i == 0); + i = pthread_join (thread, NULL); + assert (i == 0); + + marker_exit1 (); + marker_exit2 (); + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.multi/watchpoint-multi.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.multi/watchpoint-multi.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,113 @@ +# Copyright 2010 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +if { [is_remote target] || ![isnative] } then { + continue +} + +set testfile "watchpoint-multi" + +set executable ${testfile} +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${executable} + +if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested ${testfile}.exp + return -1 +} + +clean_restart $executable + +if ![runto_main] { + return +} +# Never keep/use any non-hw breakpoints to workaround a multi-inferior bug. +delete_breakpoints + +gdb_test "add-inferior" "Added inferior 2" +gdb_test "inferior 2" "witching to inferior 2 .*" +gdb_load $binfile + +if ![runto_main] { + return +} +delete_breakpoints + +# Simulate non-stop+target-async which also uses breakpoint always-inserted. +gdb_test_no_output "set breakpoint always-inserted on" +# displaced-stepping is also needed as other GDB sometimes still removes the +# breakpoints, even with always-inserted on. +gdb_test_no_output "set displaced-stepping on" + +# Debugging of this testcase: +#gdb_test_no_output "maintenance set show-debug-regs on" +#gdb_test_no_output "set debug infrun 1" + +# Do not use simple hardware watchpoint ("watch") as its false hit may be +# unnoticed by GDB if it reads it still has the same value. +gdb_test "awatch c" "Hardware access \\(read/write\\) watchpoint \[0-9\]+: c" +# Never keep/use any non-hw breakpoints to workaround a multi-inferior bug. +# Use `*' to workaround a multi-inferior bug. +set test "hbreak *marker_exit2" +gdb_test_multiple $test $test { + -re "Hardware assisted breakpoint \[0-9\]+ at .*\r\n$gdb_prompt $" { + pass $test + } + -re "(No hardware breakpoint support in the target\\.|Hardware breakpoints used exceeds limit\\.)\r\n$gdb_prompt $" { + pass $test + untested ${testfile}.exp + return + } +} + +gdb_test "inferior 1" "witching to inferior 1 .*" + +gdb_test "awatch b" "Hardware access \\(read/write\\) watchpoint \[0-9\]+: b" +gdb_test "hbreak *marker_exit1" {Hardware assisted breakpoint [0-9]+ at .*} + +gdb_test "inferior 2" "witching to inferior 2 .*" + +# FAIL would be a hit on watchpoint for `b' - that one is for the other +# inferior. +gdb_test "continue" "Hardware access \\(read/write\\) watchpoint \[0-9\]+: c\r\n\r\nOld value = 0\r\nNew value = 3\r\n.*" "catch c" + +set test "catch marker_exit2" +gdb_test_multiple "continue" $test { + -re "Breakpoint \[0-9\]+, marker_exit2 .*\r\n$gdb_prompt $" { + setup_kfail breakpoints/12312 *-*-* + pass $test + } + -re "Hardware access \\(read/write\\) watchpoint \[0-9\]+: c\r\n\r\nValue = 3\r\n(.* in )?__nptl_death_event .*\r\n$gdb_prompt $" { + setup_kfail breakpoints/12312 *-*-* + fail $test + } +} + +gdb_test "inferior 1" "witching to inferior 1 .*" + +gdb_test "continue" "Hardware access \\(read/write\\) watchpoint \[0-9\]+: b\r\n\r\nOld value = 0\r\nNew value = 2\r\n.*" "catch b" + +set test "catch marker_exit1" +gdb_test_multiple "continue" $test { + -re "Breakpoint \[0-9\]+, marker_exit1 .*\r\n$gdb_prompt $" { + setup_kfail breakpoints/12312 *-*-* + pass $test + } + -re "Hardware access \\(read/write\\) watchpoint \[0-9\]+: b\r\n\r\nValue = 2\r\n(.* in )?__nptl_death_event .*\r\n$gdb_prompt $" { + setup_kfail breakpoints/12312 *-*-* + fail $test + } +} + Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.opt/array-from-register-func.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.opt/array-from-register-func.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,22 @@ +/* This file is part of GDB, the GNU debugger. + + Copyright 2009 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +int +func (int *arr) +{ + return arr[0]; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.opt/array-from-register.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.opt/array-from-register.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,28 @@ +/* This file is part of GDB, the GNU debugger. + + Copyright 2009 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +extern int func (int *arr); + +int +main (void) +{ + int arr[] = { 42 }; + + func (arr); + + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.opt/array-from-register.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.opt/array-from-register.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,33 @@ +# Copyright 2009 Free Software Foundation, Inc. +# +# 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 2 of the License, or +# (at your option) any later version. +# +# 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# This file is part of the gdb testsuite. + +if { [prepare_for_testing array-from-register.exp "array-from-register" \ + {array-from-register.c array-from-register-func.c} \ + {debug optimize=-O2}] } { + return -1 +} + +if ![runto func] then { + return -1 +} + +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+" + +# Seen regression: +# Address requested for identifier "arr" which is in register $rdi +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.pascal/arrays.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.pascal/arrays.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,104 @@ +# Copyright 2008, 2009 Free Software Foundation, Inc. +# +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +if $tracelevel then { + strace $tracelevel +} + +load_lib "pascal.exp" + +set testfile "arrays" +set srcfile ${testfile}.pas +set binfile ${objdir}/${subdir}/${testfile}$EXEEXT + +# These tests only work with fpc, using the -gw3 compile-option +pascal_init +if { $pascal_compiler_is_fpc != 1 } { + return -1 +} + +# Detect if the fpc version is below 2.3.0 +set fpc_generates_dwarf_for_dynamic_arrays 1 +if { ($fpcversion_major < 2) || ( ($fpcversion_major == 2) && ($fpcversion_minor < 3))} { + set fpc_generates_dwarf_for_dynamic_arrays 0 +} + + +if {[gdb_compile_pascal "-gw3 ${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} +set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] +set bp_location2 [gdb_get_line_number "set breakpoint 2 here"] + + +if { [gdb_breakpoint ${srcfile}:${bp_location1}] } { + pass "setting breakpoint 1" +} +if { [gdb_breakpoint ${srcfile}:${bp_location2}] } { + pass "setting breakpoint 2" +} + +# Verify that "start" lands inside the right procedure. +if { [gdb_start_cmd] < 0 } { + untested start + return -1 +} + +gdb_test "" ".* at .*${srcfile}.*" "start" + +gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint" + +gdb_test "print StatArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer type" +gdb_test "print StatArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer" + +gdb_test "cont" "Breakpoint .*:${bp_location2}.*" "Going to second breakpoint" + +gdb_test "print StatArrChar" ".* = 'abcdefghijkl'" "Print static array of char" +gdb_test "print Stat2dArrInt" ".* = \\{\\{0, 1, 2, 3, 4\\}, \\{1, 2, 3, 4, 5\\}, \\{2, 3, 4, 5, 6\\}, \\{3, 4, 5, 6, 7\\}, \\{4, 5, 6, 7, 8\\}, \\{5, 6, 7, 8, 9\\}, \\{6, 7, 8, 9, 10\\}, \\{7, 8, 9, 10, 11\\}, \\{8, 9, 10, 11, 12\\}, \\{9, 10, 11, 12, 13\\}, \\{10, 11, 12, 13, 14\\}, \\{11, 12, 13, 14, 15\\}\\}" "Print static 2-dimensional array of integer" + +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} { + setup_xfail "*-*-*" +} +gdb_test "print DynArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer type" +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} { + setup_xfail "*-*-*" +} +gdb_test "print DynArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer" + +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} { + setup_xfail "*-*-*" +} +gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char" + +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} { + setup_xfail "*-*-*" +} +gdb_test "print DynArrStr" ".* = \\{'dstr0', 'dstr1', 'dstr2', 'dstr3', 'dstr4', 'dstr5', 'dstr6', 'dstr7', 'dstr8', 'dstr9', 'dstr10', 'dstr11', 'dstr12'\\}" "Print dynamic array of string" + +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} { + setup_xfail "*-*-*" +} +gdb_test "print StatArrStr" ".* = \\{'str0', 'str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9', 'str10', 'str11', 'str12'\\}" "Print static array of string" + +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} { + setup_xfail "*-*-*" +} +gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char" + Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.pascal/arrays.pas =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.pascal/arrays.pas 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,82 @@ +{ + Copyright 2008, 2009 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . +} + +program arrays; + +{$mode objfpc}{$h+} + +uses sysutils; + +type TStatArrInt= array[0..11] of integer; + TDynArrInt= array of integer; + TStatArrStr= array[0..12] of string; + TDynArrStr= array of string; + TDynArrChar = array of char; + TStatArrChar = array [0..11] of char; + + TStat2dArrInt = array[0..11,0..4] of integer; + +var StatArrInt: TStatArrInt; + StatArrInt_: Array[0..11] of integer; + DynArrInt: TDynArrInt; + DynArrInt_: Array of integer; + StatArrStr: TStatArrStr; + DynArrStr: TDynArrStr; + StatArrChar: TStatArrChar; + DynArrChar: TDynArrChar; + + Stat2dArrInt: TStat2dArrInt; + + s: string; + + i,j : integer; + +begin + for i := 0 to 11 do + begin + StatArrInt[i]:= i+50; + StatArrInt_[i]:= i+50; + StatArrChar[i]:= chr(ord('a')+i); + for j := 0 to 4 do + Stat2dArrInt[i,j]:=i+j; + end; + writeln(StatArrInt_[0]); + writeln(StatArrInt[0]); { set breakpoint 1 here } + writeln(StatArrChar[0]); + writeln(Stat2dArrInt[0,0]); + + setlength(DynArrInt,13); + setlength(DynArrInt_,13); + setlength(DynArrStr,13); + setlength(DynArrChar,13); + for i := 0 to 12 do + begin + DynArrInt[i]:= i+50; + DynArrInt_[i]:= i+50; + DynArrChar[i]:= chr(ord('a')+i); + StatArrStr[i]:='str'+inttostr(i); + DynArrStr[i]:='dstr'+inttostr(i); + end; + writeln(DynArrInt_[1]); + writeln(DynArrInt[1]); + writeln(DynArrStr[1]); + writeln(StatArrStr[1]); + writeln(DynArrChar[1]); + + s := 'test'#0'string'; + writeln(s); { set breakpoint 2 here } +end. Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.python/py-frame.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.python/py-frame.exp 2011-02-26 15:06:28.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.python/py-frame.exp 2011-05-25 17:05:21.000000000 +0200 @@ -78,8 +78,6 @@ gdb_test "python print bframe == gdb.new gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)" gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)" -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)" -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)" gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid" gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name" gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type" @@ -94,3 +92,5 @@ gdb_test "python print 'result =', f0.re gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success" gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame" + +gdb_test "python print 'result =', f0.block ()" "" "test Frame.block" Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.python/py-value.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/gdb.python/py-value.exp 2011-01-01 16:33:49.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.python/py-value.exp 2011-05-25 17:05:21.000000000 +0200 @@ -318,6 +318,15 @@ proc test_value_after_death {} { "print value's type" } +# Regression test for a cast failure. The bug was that if we cast a +# value to its own type, gdb could crash. This happened because we +# could end up double-freeing a struct value. +proc test_cast_regression {} { + gdb_test "python v = gdb.Value(5)" "" "create value for cast test" + gdb_test "python v = v.cast(v.type)" "" "cast value for cast test" + gdb_test "python print v" "5" "print value for cast test" +} + # Regression test for invalid subscript operations. The bug was that # the type of the value was not being checked before allowing a # subscript operation to proceed. @@ -455,6 +464,7 @@ test_value_in_inferior test_inferior_function_call test_lazy_strings test_value_after_death +test_cast_regression # The following test recompiles the binary to test either C or C++ # values. Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-child.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-child.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,127 @@ +/* Test case for forgotten hw-watchpoints after fork()-off of a process. + + Copyright 2008, 2009, 2010 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 2 of the License, or + (at your option) any later version. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include +#include +#include + +#include "watchpoint-fork.h" + +static volatile int usr1_got; + +static void +handler_usr1 (int signo) +{ + usr1_got++; +} + +void +forkoff (int nr) +{ + pid_t child, save_parent = getpid (); + int i; + struct sigaction act, oldact; +#ifdef THREAD + void *thread_result; +#endif + + memset (&act, 0, sizeof act); + act.sa_flags = SA_RESTART; + act.sa_handler = handler_usr1; + sigemptyset (&act.sa_mask); + i = sigaction (SIGUSR1, &act, &oldact); + assert (i == 0); + + child = fork (); + switch (child) + { + case -1: + assert (0); + default: + printf ("parent%d: %d\n", nr, (int) child); + + /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB + tracing the child fork with no longer valid thread/lwp entries of the + parent. */ + + i = sleep (2); + assert (i == 0); + + /* We must not get caught here (against a forgotten breakpoint). */ + + var++; + marker (); + +#ifdef THREAD + /* And neither got caught our thread. */ + + step = 99; + i = pthread_join (thread, &thread_result); + assert (i == 0); + assert (thread_result == (void *) 99UL); +#endif + + /* Be sure our child knows we did not get caught above. */ + + i = kill (child, SIGUSR1); + assert (i == 0); + + /* Sleep for a while to check GDB's `info threads' no longer tracks us in + the child fork. */ + + i = sleep (2); + assert (i == 0); + + _exit (0); + case 0: + printf ("child%d: %d\n", nr, (int) getpid ()); + + /* Let the parent signal us about its success. Be careful of races. */ + + for (;;) + { + /* Parent either died (and USR1_GOT is zero) or it succeeded. */ + if (getppid () != save_parent) + break; + if (kill (getppid (), 0) != 0) + break; + /* Parent succeeded? */ + if (usr1_got) + break; + +#ifdef THREAD + i = pthread_yield (); + assert (i == 0); +#endif + } + assert (usr1_got); + + /* We must get caught here (against a false watchpoint removal). */ + + marker (); + } + + i = sigaction (SIGUSR1, &oldact, NULL); + assert (i == 0); +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,174 @@ +/* Test case for forgotten hw-watchpoints after fork()-off of a process. + + Copyright 2008, 2009, 2010 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 2 of the License, or + (at your option) any later version. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#define gettid() syscall (__NR_gettid) + +#include "watchpoint-fork.h" + +/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP + variable. Hit-comments need to be duplicite there to catch both at-stops + and behind-stops, depending on the target. */ + +volatile int var; + +void +marker (void) +{ +} + +static void +empty (void) +{ +} + +static void +mark_exit (void) +{ +} + +pthread_t thread; +volatile int step; + +static void * +start (void *arg) +{ + int i; + + if (step >= 3) + goto step_3; + + while (step != 1) + { + i = pthread_yield (); + assert (i == 0); + } + + var++; /* validity-thread-B */ + empty (); /* validity-thread-B */ + step = 2; + while (step != 3) + { + if (step == 99) + goto step_99; + + i = pthread_yield (); + assert (i == 0); + } + +step_3: + if (step >= 5) + goto step_5; + + var++; /* after-fork1-B */ + empty (); /* after-fork1-B */ + step = 4; + while (step != 5) + { + if (step == 99) + goto step_99; + + i = pthread_yield (); + assert (i == 0); + } + +step_5: + var++; /* after-fork2-B */ + empty (); /* after-fork2-B */ + return (void *) 5UL; + +step_99: + /* We must not get caught here (against a forgotten breakpoint). */ + var++; + marker (); + return (void *) 99UL; +} + +int +main (void) +{ + int i; + void *thread_result; + + setbuf (stdout, NULL); + printf ("main: %d\n", (int) gettid ()); + + /* General hardware breakpoints and watchpoints validity. */ + marker (); + var++; /* validity-first */ + empty (); /* validity-first */ + + i = pthread_create (&thread, NULL, start, NULL); + assert (i == 0); + + var++; /* validity-thread-A */ + empty (); /* validity-thread-A */ + step = 1; + while (step != 2) + { + i = pthread_yield (); + assert (i == 0); + } + + /* Hardware watchpoints got disarmed here. */ + forkoff (1); + + var++; /* after-fork1-A */ + empty (); /* after-fork1-A */ + step = 3; +#ifdef FOLLOW_CHILD + /* Spawn new thread as it was deleted in the child of FORK. */ + i = pthread_create (&thread, NULL, start, NULL); + assert (i == 0); +#endif + while (step != 4) + { + i = pthread_yield (); + assert (i == 0); + } + + /* A sanity check for double hardware watchpoints removal. */ + forkoff (2); + + var++; /* after-fork2-A */ + empty (); /* after-fork2-A */ + step = 5; +#ifdef FOLLOW_CHILD + /* Spawn new thread as it was deleted in the child of FORK. */ + i = pthread_create (&thread, NULL, start, NULL); + assert (i == 0); +#endif + + i = pthread_join (thread, &thread_result); + assert (i == 0); + assert (thread_result == (void *) 5UL); + + mark_exit (); + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-parent.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-parent.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,74 @@ +/* Test case for forgotten hw-watchpoints after fork()-off of a process. + + Copyright 2008, 2009, 2010 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 2 of the License, or + (at your option) any later version. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include +#include +#include +#include + +#include "watchpoint-fork.h" + +void +forkoff (int nr) +{ + pid_t child, pid_got; + int exit_code = 42 + nr; + int status, i; + + child = fork (); + switch (child) + { + case -1: + assert (0); + case 0: + printf ("child%d: %d\n", nr, (int) getpid ()); + /* Delay to get both the "child%d" and "parent%d" message printed without + a race breaking expect by its endless wait on `$gdb_prompt$': + Breakpoint 3, marker () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33 + 33 } + (gdb) parent2: 14223 */ + i = sleep (1); + assert (i == 0); + + /* We must not get caught here (against a forgotten breakpoint). */ + var++; + marker (); + + _exit (exit_code); + default: + printf ("parent%d: %d\n", nr, (int) child); + /* Delay to get both the "child%d" and "parent%d" message printed, see + above. */ + i = sleep (1); + assert (i == 0); + + pid_got = wait (&status); + assert (pid_got == child); + assert (WIFEXITED (status)); + assert (WEXITSTATUS (status) == exit_code); + + /* We must get caught here (against a false watchpoint removal). */ + marker (); + } +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-st.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork-st.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,61 @@ +/* Test case for forgotten hw-watchpoints after fork()-off of a process. + + Copyright 2008, 2009, 2010 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 2 of the License, or + (at your option) any later version. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include +#include + +#include "watchpoint-fork.h" + +volatile int var; + +void +marker (void) +{ +} + +static void +mark_exit (void) +{ +} + +int +main (void) +{ + setbuf (stdout, NULL); + printf ("main: %d\n", (int) getpid ()); + + /* General hardware breakpoints and watchpoints validity. */ + marker (); + var++; + /* Hardware watchpoints got disarmed here. */ + forkoff (1); + /* This watchpoint got lost before. */ + var++; + /* A sanity check for double hardware watchpoints removal. */ + forkoff (2); + var++; + + mark_exit (); + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,149 @@ +# Copyright 2008, 2009, 2010 Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +# Test case for forgotten hw-watchpoints after fork()-off of a process. + +proc test {type symbol} { + global objdir subdir srcdir gdb_prompt + + set testfile watchpoint-fork + + global pf_prefix + set prefix_test $pf_prefix + lappend pf_prefix "$type:" + set prefix_mt $pf_prefix + + set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c + + + # no threads + + set pf_prefix $prefix_mt + lappend pf_prefix "singlethreaded:" + + set executable ${testfile}-${type}-st + set srcfile_main ${srcdir}/${subdir}/${testfile}-st.c + if { [gdb_compile "${srcfile_main} ${srcfile_type}" ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } { + untested ${testfile}.exp + return + } + clean_restart $executable + + gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on\\." + gdb_test_no_output "set follow-fork-mode $type" + gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"\\." + # Testcase uses it for the `follow-fork-mode child' type. + gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*" + + if ![runto_main] { + return + } + + gdb_test "watch var" "atchpoint \[0-9\]+: var" "Set the watchpoint" + + # It is never hit but it should not be left over in the fork()ed-off child. + set hbreak "hbreak" + set test "hbreak marker" + gdb_test_multiple $test $test { + -re "Hardware assisted breakpoint \[0-9\]+ at .*\r\n$gdb_prompt $" { + pass $test + } + -re "(No hardware breakpoint support in the target\\.|Hardware breakpoints used exceeds limit\\.)\r\n$gdb_prompt $" { + pass $test + set hbreak "break" + gdb_test "break marker" + } + } + + gdb_breakpoint "mark_exit" + + gdb_test "continue" \ + "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work" + gdb_test "continue" \ + "reakpoint \[0-9\]+, marker.*" "breakpoint after the first fork" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork" + gdb_test "continue" \ + "reakpoint \[0-9\]+, marker.*" "breakpoint after the second fork" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*mark_exit \\(\\);" "watchpoint after the second fork" + gdb_test "continue" "Continuing\\..*\r\nBreakpoint \[0-9\]+, mark_exit .*" "finish" + + + # threads + + set pf_prefix $prefix_mt + lappend pf_prefix "multithreaded:" + + set executable ${testfile}-${type}-mt + set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c + if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" ${objdir}/${subdir}/${executable} executable [list debug "additional_flags=-D$symbol -DTHREAD"]] != "" } { + untested ${testfile}.exp + return + } + clean_restart $executable + + gdb_test_no_output "set follow-fork-mode $type" + # Testcase uses it for the `follow-fork-mode child' type. + gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*" + + if ![runto_main] { + return + } + + gdb_test "watch var" "atchpoint \[0-9\]+: var" "Set the watchpoint" + + # It should not be left over in the fork()ed-off child. + gdb_test "$hbreak marker" {reakpoint [0-9]+.*} + + gdb_breakpoint "mark_exit" + + gdb_test "continue" \ + "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B" + gdb_test "continue" \ + "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the first fork" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork" + gdb_test "continue" \ + "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the second fork" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork" + gdb_test "continue" \ + "atchpoint \[0-9\]+: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork" + gdb_test "continue" "Continuing\\..*\r\nBreakpoint \[0-9\]+, mark_exit .*" "finish" + + + # cleanup + set pf_prefix $prefix_test +} + +test parent FOLLOW_PARENT + +# Only GNU/Linux is known to support `set follow-fork-mode child'. +if {[istarget "*-*-linux*"] && ![is_remote target]} { + test child FOLLOW_CHILD +} else { + untested "child" +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.threads/watchpoint-fork.h 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,32 @@ +/* Test case for forgotten hw-watchpoints after fork()-off of a process. + + Copyright 2008, 2009, 2010 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 2 of the License, or + (at your option) any later version. + + 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifdef THREAD +#include + +extern volatile int step; +extern pthread_t thread; +#endif /* THREAD */ + +extern volatile int var; + +extern void marker (void); +extern void forkoff (int nr); Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.trace/stap-trace.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.trace/stap-trace.c 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,71 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 Free Software Foundation, Inc. + + 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 3 of the License, or + (at your option) any later version. + + 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 this program. If not, see . */ + +#if USE_PROBES + +#define _SDT_HAS_SEMAPHORES +__extension__ unsigned short teste_user_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes"))); +#define TEST teste_user_semaphore + +__extension__ unsigned short teste_two_semaphore __attribute__ ((unused)) __attribute__ ((section (".probes"))); +#define TEST2 teste_two_semaphore + +#else + +#define TEST 1 +#define TEST2 1 + +#endif /* USE_PROBES */ + +#include + +/* We only support SystemTap and only the v3 form. */ +#if _SDT_NOTE_TYPE != 3 +#error "not using SystemTap v3 probes" +#endif + +void +m1 (int x) +{ + if (TEST2) + STAP_PROBE1 (teste, two, x); +} + +int +f (int x) +{ + if (TEST) + STAP_PROBE1(teste, user, x); + return x+5; +} + +void +nothing (void) +{ + int a = 1 + 1; + return; +} + +int +main() +{ + f (f (23)); + m1 (46); + nothing (); /* end-here */ + + return 0; +} Index: gdb-7.2.90.20110525/gdb/testsuite/gdb.trace/stap-trace.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb-7.2.90.20110525/gdb/testsuite/gdb.trace/stap-trace.exp 2011-05-25 17:05:21.000000000 +0200 @@ -0,0 +1,129 @@ +# Copyright 2011 +# Free Software Foundation, Inc. + +# 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 3 of the License, or +# (at your option) any later version. +# +# 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 this program. If not, see . + +load_lib "trace-support.exp" + +if $tracelevel then { + strace $tracelevel +} + +set testfile "stap-trace" +set srcfile ${testfile}.c +set executable $testfile +set binfile $objdir/$subdir/$executable + +set ws "\[\r\n\t \]+" +set cr "\[\r\n\]+" + +# Only x86 and x86_64 targets are supported for now. + +if { ![istarget "x86_64-*"] && ![istarget "i?86-*"] } { + continue +} + +proc compile_stap_bin {{ arg "" }} { + global srcfile + global binfile + global srcdir + global subdir + + if { $arg != "" } { + set arg "additional_flags=$arg" + } + + if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ + executable [concat $arg debug nowarnings]] != "" } { + untested "Could not compile ${srcfile}" + return -1 + } +} + +proc prepare_for_trace_test {} { + global executable + + clean_restart $executable + + if { ![runto_main] } { + perror "Could not run to `main'." + continue + } + + gdb_breakpoint [gdb_get_line_number "end-here"] +} + +proc run_trace_experiment { test_probe msg } { + global gdb_prompt + + set test "collect $msg: start trace experiment" + gdb_test_multiple "tstart" "$test" { + -re "^tstart\r\n$gdb_prompt $" { + pass "$test" + } + } + + gdb_test "continue" \ + "Continuing.*Breakpoint \[0-9\]+.*" \ + "collect $msg: run trace experiment" + gdb_test "tstop" \ + "\[\r\n\]+" \ + "collect $msg: stop trace experiment" + gdb_test "tfind start" \ + "#0 .*" \ + "collect $msg: tfind test frame" +} + +proc gdb_collect_probe_arg { msg probe val_arg0 } { + global gdb_prompt + global cr + + prepare_for_trace_test + + gdb_test "trace $probe" \ + "Tracepoint \[0-9\]+ at .*" \ + "collect $msg: set tracepoint" + gdb_trace_setactions "collect $msg: define actions" \ + "" \ + "collect \$_probe_arg0" "^$" + + # Begin the test. + run_trace_experiment $msg $probe + + gdb_test "print \$_probe_arg0" \ + "\\$\[0-9\]+ = $val_arg0$cr" \ + "collect $msg: collected probe arg0" +} + +compile_stap_bin "" + +clean_restart $executable +if { ![runto_main] } { + perror "Could not run to `main'." + continue +} + +if { ![gdb_target_supports_trace] } { + # Test cannot run on this target. + return 1; +} + +gdb_collect_probe_arg "probe args without semaphore" "probe:user" "23" +gdb_exit + +compile_stap_bin "-DUSE_PROBES" +gdb_collect_probe_arg "probe args with semaphore" "probe:two" "46" + +# Finished! +gdb_test "tfind none" ".*" "" Index: gdb-7.2.90.20110525/gdb/testsuite/lib/gdb.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/lib/gdb.exp 2011-03-25 14:08:11.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/lib/gdb.exp 2011-05-25 17:05:21.000000000 +0200 @@ -141,6 +141,11 @@ proc gdb_unload {} { send_gdb "y\n" exp_continue } + -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $"\ + { send_gdb "y\n" + verbose "\t\tUnloading symbols for program being debugged" + exp_continue + } -re "Discard symbol table from .*y or n.*$" { send_gdb "y\n" exp_continue Index: gdb-7.2.90.20110525/gdb/testsuite/lib/pascal.exp =================================================================== --- gdb-7.2.90.20110525.orig/gdb/testsuite/lib/pascal.exp 2011-01-01 16:33:52.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/testsuite/lib/pascal.exp 2011-05-25 17:05:21.000000000 +0200 @@ -37,6 +37,9 @@ proc pascal_init {} { global pascal_compiler_is_fpc global gpc_compiler global fpc_compiler + global fpcversion_major + global fpcversion_minor + global fpcversion_release global env if { $pascal_init_done == 1 } { @@ -64,6 +67,20 @@ proc pascal_init {} { set pascal_compiler_is_fpc 1 verbose -log "Free Pascal compiler found" } + + # Detect the fpc-version + if { $pascal_compiler_is_fpc == 1 } { + set fpcversion_major 1 + set fpcversion_minor 0 + set fpcversion_release 0 + set fpcversion [ remote_exec host $fpc_compiler "-iV" ] + if [regexp {.*([0-9]+)\.([0-9]+)\.([0-9]+).?} $fpcversion] { + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\1} fpcversion_major + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\2} fpcversion_minor + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\3} fpcversion_release + } + verbose -log "Freepascal version: $fpcversion_major.$fpcversion_minor.$fpcversion_release" + } } set pascal_init_done 1 } Index: gdb-7.2.90.20110525/gdb/thread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/thread.c 2011-04-19 17:24:49.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/thread.c 2011-05-25 17:05:21.000000000 +0200 @@ -1438,7 +1438,8 @@ update_thread_list (void) no thread is selected, or no threads exist. */ static struct value * -thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var) +thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var, + void *ignore) { struct thread_info *tp = find_thread_ptid (inferior_ptid); @@ -1449,6 +1450,15 @@ thread_id_make_value (struct gdbarch *gd /* Commands with a prefix of `thread'. */ struct cmd_list_element *thread_cmd_list = NULL; +/* Implementation of `thread' variable. */ + +static struct internalvar_funcs thread_funcs = +{ + thread_id_make_value, + NULL, + NULL +}; + void _initialize_thread (void) { @@ -1494,5 +1504,5 @@ Show printing of thread events (such as show_print_thread_events, &setprintlist, &showprintlist); - create_internalvar_type_lazy ("_thread", thread_id_make_value); + create_internalvar_type_lazy ("_thread", &thread_funcs, NULL); } Index: gdb-7.2.90.20110525/gdb/top.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/top.c 2011-03-12 23:59:24.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/top.c 2011-05-25 17:05:21.000000000 +0200 @@ -343,6 +343,9 @@ void prepare_execute_command (void) { free_all_values (); +#if 0 + free_all_types (); +#endif /* With multiple threads running while the one we're examining is stopped, the dcache can get stale without us being able to detect Index: gdb-7.2.90.20110525/gdb/tracepoint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/tracepoint.c 2011-05-20 16:37:42.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/tracepoint.c 2011-05-25 17:05:21.000000000 +0200 @@ -1603,6 +1603,8 @@ start_tracing (void) for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) { + struct bp_location *loc; + if ((t->type == bp_fast_tracepoint ? !may_insert_fast_tracepoints : !may_insert_tracepoints)) @@ -1611,6 +1613,9 @@ start_tracing (void) t->number_on_target = 0; target_download_tracepoint (t); t->number_on_target = t->number; + + for (loc = t->loc; loc; loc = loc->next) + modify_semaphore (loc, 1); } VEC_free (breakpoint_p, tp_vec); @@ -1672,7 +1677,28 @@ trace_stop_command (char *args, int from void stop_tracing (void) { + VEC(breakpoint_p) *tp_vec = NULL; + int ix; + struct breakpoint *t; + target_trace_stop (); + + tp_vec = all_tracepoints (); + for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) + { + struct bp_location *loc; + + if ((t->type == bp_fast_tracepoint + ? !may_insert_fast_tracepoints + : !may_insert_tracepoints)) + continue; + + for (loc = t->loc; loc; loc = loc->next) + modify_semaphore (loc, 0); + } + + VEC_free (breakpoint_p, tp_vec); + /* Should change in response to reply? */ current_trace_status ()->running = 0; } @@ -4515,7 +4541,8 @@ info_static_tracepoint_markers_command ( available. */ static struct value * -sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var) +sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var, + void *ignore) { LONGEST size; gdb_byte *buf; @@ -4694,6 +4721,15 @@ traceframe_available_memory (VEC(mem_ran return 0; } +/* Implementation of `sdata' variable. */ + +static const struct internalvar_funcs sdata_funcs = +{ + sdata_make_value, + NULL, + NULL +}; + /* module initialization */ void _initialize_tracepoint (void) @@ -4704,7 +4740,7 @@ _initialize_tracepoint (void) value with a void typed value, and when we get here, gdbarch isn't initialized yet. At this point, we're quite sure there isn't another convenience variable of the same name. */ - create_internalvar_type_lazy ("_sdata", sdata_make_value); + create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL); traceframe_number = -1; tracepoint_number = -1; Index: gdb-7.2.90.20110525/gdb/typeprint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/typeprint.c 2011-01-11 22:53:25.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/typeprint.c 2011-05-25 17:05:21.000000000 +0200 @@ -36,6 +36,7 @@ #include "gdb_string.h" #include "exceptions.h" #include "valprint.h" +#include "dwarf2loc.h" #include extern void _initialize_typeprint (void); @@ -77,6 +78,9 @@ void type_print (struct type *type, char *varstring, struct ui_file *stream, int show) { + if (show >= 0) + type = check_typedef (type); + LA_PRINT_TYPE (type, varstring, stream, show, 0); } @@ -115,7 +119,8 @@ whatis_exp (char *exp, int show) { struct expression *expr; struct value *val; - struct cleanup *old_chain = NULL; + /* Required at least for the object_address_set call. */ + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); struct type *real_type = NULL; struct type *type; int full = 0; @@ -126,12 +131,13 @@ whatis_exp (char *exp, int show) if (exp) { expr = parse_expression (exp); - old_chain = make_cleanup (free_current_contents, &expr); + make_cleanup (free_current_contents, &expr); val = evaluate_type (expr); } else val = access_value_history (0); + object_address_set (value_raw_address (val)); type = value_type (val); get_user_print_options (&opts); @@ -168,8 +174,7 @@ whatis_exp (char *exp, int show) type_print (type, "", gdb_stdout, show); printf_filtered ("\n"); - if (exp) - do_cleanups (old_chain); + do_cleanups (old_chain); } static void Index: gdb-7.2.90.20110525/gdb/utils.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/utils.c 2011-05-17 23:26:28.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/utils.c 2011-05-25 17:05:21.000000000 +0200 @@ -2243,6 +2243,36 @@ set_batch_flag_and_make_cleanup_restore_ return back_to; } +/* Helper for make_cleanup_restore_page_info. */ + +static void +do_restore_selected_frame_cleanup (void *arg) +{ + struct frame_id *frame_idp = arg; + + select_frame (frame_find_by_id (*frame_idp)); + + xfree (frame_idp); +} + +/* Provide cleanup for restoring currently selected frame. Use frame_id for + the case the current frame becomes stale in the meantime. */ + +struct cleanup * +make_cleanup_restore_selected_frame (void) +{ + struct frame_id *frame_idp; + + /* get_selected_frame->get_current_frame would error otherwise. */ + if (!has_stack_frames ()) + return make_cleanup (null_cleanup, NULL); + + frame_idp = xmalloc (sizeof (*frame_idp)); + *frame_idp = get_frame_id (get_selected_frame (NULL)); + + return make_cleanup (do_restore_selected_frame_cleanup, frame_idp); +} + /* Set the screen size based on LINES_PER_PAGE and CHARS_PER_LINE. */ static void Index: gdb-7.2.90.20110525/gdb/valarith.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/valarith.c 2011-02-18 20:10:46.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/valarith.c 2011-05-25 17:05:21.000000000 +0200 @@ -198,7 +198,10 @@ value_subscripted_rvalue (struct value * struct type *array_type = check_typedef (value_type (array)); struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type)); unsigned int elt_size = TYPE_LENGTH (elt_type); - unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound); + unsigned int elt_stride + = (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type)) == 0 + ? elt_size : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type))); + unsigned int elt_offs = elt_stride * longest_to_int (index - lowerbound); struct value *v; if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type) @@ -298,6 +301,10 @@ int binop_user_defined_p (enum exp_opcode op, struct value *arg1, struct value *arg2) { + /* FIXME: We should support user defined ops for dynamic types. */ + if (TYPE_DYNAMIC (value_type (arg1)) || TYPE_DYNAMIC (value_type (arg2))) + return 0; + return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2)); } Index: gdb-7.2.90.20110525/gdb/valops.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/valops.c 2011-03-29 19:04:30.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/valops.c 2011-05-25 17:05:21.000000000 +0200 @@ -47,6 +47,7 @@ #include "objfiles.h" #include "symtab.h" #include "exceptions.h" +#include "dwarf2loc.h" extern int overload_debug; /* Local functions. */ @@ -915,6 +916,65 @@ value_one (struct type *type, enum lval_ return val; } +/* object_address_set must be already called before this function. */ + +const char * +object_address_data_not_valid (struct type *type) +{ + /* Attributes are present only at the target type of a typedef. Make the + call conditional as it would otherwise loop through type_length_get. */ + if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) + CHECK_TYPEDEF (type); + + /* DW_AT_associated has a preference over DW_AT_allocated. */ + if (TYPE_NOT_ASSOCIATED (type) + || (TYPE_ASSOCIATED (type) != NULL + && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type)))) + return N_("object is not associated"); + + if (TYPE_NOT_ALLOCATED (type) + || (TYPE_ALLOCATED (type) != NULL + && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type)))) + return N_("object is not allocated"); + + return NULL; +} + +/* Return non-NULL check_typedef result on TYPE if the variable is valid. If + it is valid the function may store the data address (DW_AT_DATA_LOCATION) of + TYPE at *ADDRESS_RETURN. You must set *ADDRESS_RETURN from + value_raw_address (VAL) before calling this function. If no + DW_AT_DATA_LOCATION is present for TYPE the address at *ADDRESS_RETURN is + left unchanged. ADDRESS_RETURN must not be NULL, use + object_address_data_not_valid () for just the data validity check. */ + +struct type * +object_address_get_data (struct type *type, CORE_ADDR *address_return) +{ + gdb_assert (address_return != NULL); + + object_address_set (*address_return); + + /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only + at the target type of a typedef. */ + CHECK_TYPEDEF (type); + + if (object_address_data_not_valid (type) != NULL) + { + /* Do not try to evaluate DW_AT_data_location as it may even crash + (it would just return the value zero in the gfortran case). */ + return NULL; + } + + if (TYPE_DATA_LOCATION_IS_ADDR (type)) + *address_return = TYPE_DATA_LOCATION_ADDR (type); + else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL) + *address_return + = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type)); + + return type; +} + /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */ static struct value * @@ -1011,12 +1071,20 @@ value_fetch_lazy (struct value *val) } else if (VALUE_LVAL (val) == lval_memory) { - CORE_ADDR addr = value_address (val); - int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val))); + CORE_ADDR addr = value_raw_address (val); - if (length) - read_value_memory (val, 0, value_stack (val), - addr, value_contents_all_raw (val), length); + if (object_address_get_data (value_type (val), &addr)) + { + struct type *type = value_enclosing_type (val); + int length = TYPE_LENGTH (check_typedef (type)); + + if (length) + { + addr += value_offset (val); + read_value_memory (val, 0, value_stack (val), + addr, value_contents_all_raw (val), length); + } + } } else if (VALUE_LVAL (val) == lval_register) { @@ -1528,7 +1596,18 @@ address_of_variable (struct symbol *var, if ((VALUE_LVAL (val) == lval_memory && value_lazy (val)) || TYPE_CODE (type) == TYPE_CODE_FUNC) { - CORE_ADDR addr = value_address (val); + CORE_ADDR addr; + + if (VALUE_LVAL (val) == lval_memory) + { + addr = value_raw_address (val); + if (!object_address_get_data (type, &addr)) + error (_("Can't take address of memory lvalue \"%s\"."), + SYMBOL_PRINT_NAME (var)); + set_value_address (val, addr); + } + + addr = value_address (val); return value_from_pointer (lookup_pointer_type (type), addr); } @@ -1635,6 +1714,7 @@ struct value * value_coerce_array (struct value *arg1) { struct type *type = check_typedef (value_type (arg1)); + CORE_ADDR address; /* If the user tries to do something requiring a pointer with an array that has not yet been pushed to the target, then this would @@ -1644,8 +1724,12 @@ value_coerce_array (struct value *arg1) if (VALUE_LVAL (arg1) != lval_memory) error (_("Attempt to take address of value not located in memory.")); + address = value_raw_address (arg1); + if (!object_address_get_data (type, &address)) + error (_("Attempt to take address of non-valid value.")); + return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)), - value_address (arg1)); + address + value_offset (arg1)); } /* Given a value which is a function, return a value which is a pointer @@ -3695,6 +3779,8 @@ value_slice (struct value *array, int lo TYPE_TARGET_TYPE (range_type), lowbound, lowbound + length - 1); + TYPE_BYTE_STRIDE (slice_range_type) = TYPE_BYTE_STRIDE (range_type); + if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING) { int i; Index: gdb-7.2.90.20110525/gdb/valprint.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/valprint.c 2011-04-29 21:23:05.000000000 +0200 +++ gdb-7.2.90.20110525/gdb/valprint.c 2011-05-25 17:05:21.000000000 +0200 @@ -36,6 +36,7 @@ #include "dfp.h" #include "python/python.h" #include "ada-lang.h" +#include "dwarf2loc.h" #include @@ -239,7 +240,6 @@ scalar_type_p (struct type *type) case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: case TYPE_CODE_SET: - case TYPE_CODE_STRING: case TYPE_CODE_BITSTRING: return 0; default: @@ -1193,6 +1193,7 @@ val_print_array_elements (struct type *t { unsigned int things_printed = 0; unsigned len; + struct type *saved_type = type; struct type *elttype, *index_type; unsigned eltlen; /* Position of the array element we are examining to see @@ -1201,9 +1202,33 @@ val_print_array_elements (struct type *t /* Number of repetitions we have detected so far. */ unsigned int reps; LONGEST low_bound, high_bound; + struct cleanup *back_to; + CORE_ADDR saved_address = address; + + back_to = make_cleanup (null_cleanup, 0); + type = object_address_get_data (type, &address); + if (!type) + { + fputs_filtered (object_address_data_not_valid (type), stream); + do_cleanups (back_to); + return; + } + if (address != saved_address) + { + size_t length = TYPE_LENGTH (type); - elttype = TYPE_TARGET_TYPE (type); - eltlen = TYPE_LENGTH (check_typedef (elttype)); + valaddr = xmalloc (length); + make_cleanup (xfree, (gdb_byte *) valaddr); + read_memory (address, (gdb_byte *) valaddr, length); + } + + /* Skip typedefs but do not resolve TYPE_DYNAMIC. */ + elttype = saved_type; + while (TYPE_CODE (elttype) == TYPE_CODE_TYPEDEF) + elttype = TYPE_TARGET_TYPE (elttype); + elttype = TYPE_TARGET_TYPE (elttype); + + eltlen = TYPE_ARRAY_BYTE_STRIDE_VALUE (type); index_type = TYPE_INDEX_TYPE (type); if (get_array_bounds (type, &low_bound, &high_bound)) @@ -1290,6 +1315,8 @@ val_print_array_elements (struct type *t { fprintf_filtered (stream, "..."); } + + do_cleanups (back_to); } /* Read LEN bytes of target memory at address MEMADDR, placing the Index: gdb-7.2.90.20110525/gdb/value.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/value.c 2011-02-27 21:57:15.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/value.c 2011-05-25 17:05:21.000000000 +0200 @@ -43,6 +43,7 @@ #include "python/python.h" #include #include "tracepoint.h" +#include "observer.h" /* Prototypes for exported functions. */ @@ -1339,12 +1340,15 @@ void set_value_component_location (struct value *component, const struct value *whole) { + CORE_ADDR addr; + if (whole->lval == lval_internalvar) VALUE_LVAL (component) = lval_internalvar_component; else VALUE_LVAL (component) = whole->lval; component->location = whole->location; + if (whole->lval == lval_computed) { struct lval_funcs *funcs = whole->location.computed.funcs; @@ -1352,6 +1356,12 @@ set_value_component_location (struct val if (funcs->copy_closure) component->location.computed.closure = funcs->copy_closure (whole); } + + addr = value_raw_address (component); + object_address_get_data (value_type (whole), &addr); + if (component->lval != lval_internalvar + && component->lval != lval_internalvar_component) + set_value_address (component, addr); } @@ -1485,6 +1495,31 @@ show_values (char *num_exp, int from_tty num_exp[1] = '\0'; } } + +/* Sanity check for memory leaks and proper types reference counting. */ + +static void +value_history_cleanup (void *unused) +{ + while (value_history_chain) + { + struct value_history_chunk *chunk = value_history_chain; + int i; + + for (i = 0; i < ARRAY_SIZE (chunk->values); i++) + value_free (chunk->values[i]); + + value_history_chain = chunk->next; + xfree (chunk); + } + value_history_count = 0; + + /* Free the unreferenced types above. */ + free_all_values (); +#if 0 + free_all_types (); +#endif +} /* Internal variables. These are variables within the debugger that hold values assigned by debugger commands. @@ -1530,7 +1565,14 @@ struct internalvar struct value *value; /* The call-back routine used with INTERNALVAR_MAKE_VALUE. */ - internalvar_make_value make_value; + struct + { + /* The functions to call. */ + const struct internalvar_funcs *functions; + + /* The function's user-data. */ + void *data; + } make_value; /* The internal function used with INTERNALVAR_FUNCTION. */ struct @@ -1629,18 +1671,39 @@ create_internalvar (const char *name) /* Create an internal variable with name NAME and register FUN as the function that value_of_internalvar uses to create a value whenever this variable is referenced. NAME should not normally include a - dollar sign. */ + dollar sign. DATA is passed uninterpreted to FUN when it is + called. CLEANUP, if not NULL, is called when the internal variable + is destroyed. It is passed DATA as its only argument. */ struct internalvar * -create_internalvar_type_lazy (char *name, internalvar_make_value fun) +create_internalvar_type_lazy (const char *name, + const struct internalvar_funcs *funcs, + void *data) { struct internalvar *var = create_internalvar (name); var->kind = INTERNALVAR_MAKE_VALUE; - var->u.make_value = fun; + var->u.make_value.functions = funcs; + var->u.make_value.data = data; return var; } +/* See documentation in value.h. */ + +int +compile_internalvar_to_ax (struct internalvar *var, + struct agent_expr *expr, + struct axs_value *value) +{ + if (var->kind != INTERNALVAR_MAKE_VALUE + || var->u.make_value.functions->compile_to_ax == NULL) + return 0; + + var->u.make_value.functions->compile_to_ax (var, expr, value, + var->u.make_value.data); + return 1; +} + /* Look up an internal variable with name NAME. NAME should not normally include a dollar sign. @@ -1713,7 +1776,8 @@ value_of_internalvar (struct gdbarch *gd break; case INTERNALVAR_MAKE_VALUE: - val = (*var->u.make_value) (gdbarch, var); + val = (*var->u.make_value.functions->make_value) (gdbarch, var, + var->u.make_value.data); break; default: @@ -1909,6 +1973,11 @@ clear_internalvar (struct internalvar *v xfree (var->u.string); break; + case INTERNALVAR_MAKE_VALUE: + if (var->u.make_value.functions->destroy != NULL) + var->u.make_value.functions->destroy (var->u.make_value.data); + break; + default: break; } @@ -1963,6 +2032,38 @@ call_internal_function (struct gdbarch * return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv); } +#if 0 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */ + +static void +value_types_mark_used (void) +{ + struct internalvar *var; + struct value_history_chunk *chunk; + + for (var = internalvars; var != NULL; var = var->next) + switch (var->kind) + { + case INTERNALVAR_VALUE: + type_mark_used (value_type (var->u.value)); + break; + + case INTERNALVAR_INTEGER: + type_mark_used (var->u.integer.type); + break; + } + + for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next) + { + int i; + + for (i = 0; i < ARRAY_SIZE (chunk->values); i++) + if (chunk->values[i]) + type_mark_used (value_type (chunk->values[i])); + } +} +#endif + /* The 'function' command. This does nothing -- it is just a placeholder to let "help function NAME" work. This is also used as the implementation of the sub-command that is created when @@ -2010,11 +2111,10 @@ preserve_one_value (struct value *value, htab_t copied_types) { if (TYPE_OBJFILE (value->type) == objfile) - value->type = copy_type_recursive (objfile, value->type, copied_types); + value->type = copy_type_recursive (value->type, copied_types); if (TYPE_OBJFILE (value->enclosing_type) == objfile) - value->enclosing_type = copy_type_recursive (objfile, - value->enclosing_type, + value->enclosing_type = copy_type_recursive (value->enclosing_type, copied_types); } @@ -2029,7 +2129,7 @@ preserve_one_internalvar (struct interna case INTERNALVAR_INTEGER: if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile) var->u.integer.type - = copy_type_recursive (objfile, var->u.integer.type, copied_types); + = copy_type_recursive (var->u.integer.type, copied_types); break; case INTERNALVAR_VALUE: @@ -2080,14 +2180,22 @@ show_convenience (char *ignore, int from get_user_print_options (&opts); for (var = internalvars; var; var = var->next) { + volatile struct gdb_exception e; + if (!varseen) { varseen = 1; } printf_filtered (("$%s = "), var->name); - value_print (value_of_internalvar (gdbarch, var), gdb_stdout, - &opts); - printf_filtered (("\n")); + + TRY_CATCH (e, RETURN_MASK_ERROR) + { + value_print (value_of_internalvar (gdbarch, var), gdb_stdout, + &opts); + printf_filtered (("\n")); + } + if (e.reason < 0) + printf_filtered (_("\n"), e.message); } if (!varseen) printf_unfiltered (_("No debugger convenience variables now defined.\n" @@ -3047,7 +3155,24 @@ value_from_history_ref (char *h, char ** struct value * coerce_ref (struct value *arg) { - struct type *value_type_arg_tmp = check_typedef (value_type (arg)); + struct type *value_type_arg_tmp; + + if (TYPE_DYNAMIC (value_type (arg))) + { + struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); + CORE_ADDR address; + + value_type_arg_tmp = value_type (arg); + address = value_raw_address (arg); + value_type_arg_tmp = object_address_get_data (value_type_arg_tmp, + &address); + if (! value_type_arg_tmp) + error (_("Attempt to coerce non-valid value.")); + arg = value_at_lazy (value_type_arg_tmp, address); + do_cleanups (cleanups); + } + else + value_type_arg_tmp = check_typedef (value_type (arg)); if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF) arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp), @@ -3145,4 +3270,10 @@ VARIABLE is already initialized.")); add_prefix_cmd ("function", no_class, function_command, _("\ Placeholder command for showing help on convenience functions."), &functionlist, "function ", 0, &cmdlist); + + make_final_cleanup (value_history_cleanup, NULL); + +#if 0 + observer_attach_mark_used (value_types_mark_used); +#endif } Index: gdb-7.2.90.20110525/gdb/value.h =================================================================== --- gdb-7.2.90.20110525.orig/gdb/value.h 2011-03-04 21:07:22.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/value.h 2011-05-25 17:05:21.000000000 +0200 @@ -473,6 +473,10 @@ extern struct value *value_from_decfloat const gdb_byte *decbytes); extern struct value *value_from_history_ref (char *, char **); +extern const char *object_address_data_not_valid (struct type *type); +extern struct type *object_address_get_data (struct type *type, + CORE_ADDR *address_return); + extern struct value *value_at (struct type *type, CORE_ADDR addr); extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr); @@ -697,10 +701,52 @@ extern struct internalvar *lookup_only_i extern struct internalvar *create_internalvar (const char *name); -typedef struct value * (*internalvar_make_value) (struct gdbarch *, - struct internalvar *); +/* An internalvar can be dynamically computed by supplying a vector of + function pointers to perform various operations. */ + +struct internalvar_funcs +{ + /* Compute the value of the variable. The DATA argument passed to + the function is the same argument that was passed to + `create_internalvar_type_lazy'. */ + + struct value *(*make_value) (struct gdbarch *arch, + struct internalvar *var, + void *data); + + /* Update the agent expression EXPR with bytecode to compute the + value. VALUE is the agent value we are updating. The DATA + argument passed to this function is the same argument that was + passed to `create_internalvar_type_lazy'. If this pointer is + NULL, then the internalvar cannot be compiled to an agent + expression. */ + + void (*compile_to_ax) (struct internalvar *var, + struct agent_expr *expr, + struct axs_value *value, + void *data); + + /* If non-NULL, this is called to destroy DATA. The DATA argument + passed to this function is the same argument that was passed to + `create_internalvar_type_lazy'. */ + + void (*destroy) (void *data); +}; + extern struct internalvar * - create_internalvar_type_lazy (char *name, internalvar_make_value fun); +create_internalvar_type_lazy (const char *name, + const struct internalvar_funcs *funcs, + void *data); + +/* Compile an internal variable to an agent expression. VAR is the + variable to compile; EXPR and VALUE are the agent expression we are + updating. This will return 0 if there is no known way to compile + VAR, and 1 if VAR was successfully compiled. It may also throw an + exception on error. */ + +extern int compile_internalvar_to_ax (struct internalvar *var, + struct agent_expr *expr, + struct axs_value *value); extern struct internalvar *lookup_internalvar (const char *name); Index: gdb-7.2.90.20110525/gdb/windows-tdep.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/windows-tdep.c 2011-01-12 02:23:29.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/windows-tdep.c 2011-05-25 17:05:21.000000000 +0200 @@ -268,7 +268,7 @@ static struct lval_funcs tlb_value_funcs if there's no object available. */ static struct value * -tlb_make_value (struct gdbarch *gdbarch, struct internalvar *var) +tlb_make_value (struct gdbarch *gdbarch, struct internalvar *var, void *ignore) { if (target_has_stack && !ptid_equal (inferior_ptid, null_ptid)) { @@ -425,6 +425,15 @@ init_w32_command_list (void) } } +/* Implementation of `tlb' variable. */ + +static const struct internalvar_funcs tlb_funcs = +{ + tlb_make_value, + NULL, + NULL +}; + void _initialize_windows_tdep (void) { @@ -451,5 +460,5 @@ even if their meaning is unknown."), value with a void typed value, and when we get here, gdbarch isn't initialized yet. At this point, we're quite sure there isn't another convenience variable of the same name. */ - create_internalvar_type_lazy ("_tlb", tlb_make_value); + create_internalvar_type_lazy ("_tlb", &tlb_funcs, NULL); } Index: gdb-7.2.90.20110525/gdb/xcoffread.c =================================================================== --- gdb-7.2.90.20110525.orig/gdb/xcoffread.c 2011-03-07 17:17:29.000000000 +0100 +++ gdb-7.2.90.20110525/gdb/xcoffread.c 2011-05-25 17:05:21.000000000 +0200 @@ -3090,6 +3090,7 @@ static const struct sym_fns xcoff_sym_fn default_symfile_segments, /* Get segment information from a file. */ aix_process_linenos, default_symfile_relocate, /* Relocate a debug section. */ + NULL, /* sym_probe_fns */ &psym_functions };