1 http://sourceware.org/gdb/wiki/ProjectArcher
2 http://sourceware.org/gdb/wiki/ArcherBranchManagement
5 commit 16276c1aad1366b92e687c72cab30192280e1906
7 branch `archer' - the merge of branches:
8 archer-tromey-call-frame-cfa
9 archer-tromey-delayed-symfile
10 archer-tromey-dw-op-value
11 archer-jankratochvil-vla
12 archer-jankratochvil-misc
13 archer-keiths-expr-cumulative
15 archer-jankratochvil-fortran-module
16 archer-jankratochvil-watchpoint
17 archer-jankratochvil-bp_location-accel
18 archer-pmuldoon-next-over-throw
21 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
22 index 7d53205..319fac4 100644
25 @@ -169,6 +169,10 @@ TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
26 # Did the user give us a --with-gdb-datadir option?
27 GDB_DATADIR = @GDB_DATADIR@
29 +# The argument to --with-pythondir. If not given, this is
30 +# GDB_DATADIR_PATH/python.
31 +pythondir = @pythondir@
33 # Helper code from gnulib.
34 LIBGNU = gnulib/libgnu.a
35 INCGNU = -I$(srcdir)/gnulib -Ignulib
36 @@ -267,21 +271,37 @@ SUBDIR_TUI_CFLAGS= \
56 SUBDIR_PYTHON_SRCS = \
59 + python/py-breakpoint.c \
62 python/py-function.c \
64 + python/py-inferior.c \
65 + python/py-infthread.c \
68 python/py-prettyprint.c \
69 + python/py-symbol.c \
70 + python/py-symtab.c \
74 @@ -750,7 +770,7 @@ config/rs6000/nm-rs6000.h top.h bsd-kvm.h gdb-stabs.h reggroups.h \
75 annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h \
76 remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
77 sentinel-frame.h bcache.h symfile.h windows-tdep.h linux-tdep.h \
78 -gdb_usleep.h jit.h xml-syscall.h ada-operator.inc
79 +gdb_usleep.h jit.h xml-syscall.h ada-operator.inc python/python.h python/python-internal.h
81 # Header files that already have srcdir in them, or which are in objdir.
83 @@ -874,7 +894,7 @@ generated_files = config.h observer.h observer.inc ada-lex.c \
87 -all: gdb$(EXEEXT) $(CONFIG_ALL) xml-syscall-copy
88 +all: gdb$(EXEEXT) $(CONFIG_ALL) xml-syscall-copy .gdbinit
89 @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do
91 all-tui: $(TUI)$(EXEEXT)
92 @@ -1264,6 +1284,12 @@ stamp-h: $(srcdir)/config.in config.status
94 $(SHELL) config.status
96 +.gdbinit: $(srcdir)/gdbinit.in config.status
97 + CONFIG_FILES=".gdbinit:gdbinit.in" \
100 + $(SHELL) config.status
102 config.status: $(srcdir)/configure configure.tgt configure.host
103 $(SHELL) config.status --recheck
105 @@ -1963,6 +1989,14 @@ python.o: $(srcdir)/python/python.c
106 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/python.c
109 +py-block.o: $(srcdir)/python/py-block.c
110 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-block.c
113 +py-breakpoint.o: $(srcdir)/python/py-breakpoint.c
114 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-breakpoint.c
117 py-cmd.o: $(srcdir)/python/py-cmd.c
118 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-cmd.c
120 @@ -1975,14 +2009,38 @@ py-function.o: $(srcdir)/python/py-function.c
121 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-function.c
124 +py-hooks.o: $(srcdir)/python/py-hooks.c
125 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-hooks.c
128 +py-inferior.o: $(srcdir)/python/py-inferior.c
129 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-inferior.c
132 +py-infthread.o: $(srcdir)/python/py-infthread.c
133 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-infthread.c
136 py-objfile.o: $(srcdir)/python/py-objfile.c
137 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-objfile.c
140 +py-param.o: $(srcdir)/python/py-param.c
141 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-param.c
144 py-prettyprint.o: $(srcdir)/python/py-prettyprint.c
145 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-prettyprint.c
148 +py-symbol.o: $(srcdir)/python/py-symbol.c
149 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-symbol.c
152 +py-symtab.o: $(srcdir)/python/py-symtab.c
153 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-symtab.c
156 py-type.o: $(srcdir)/python/py-type.c
157 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-type.c
159 @@ -1995,6 +2053,36 @@ py-value.o: $(srcdir)/python/py-value.c
160 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c
163 +# All python library files, with the "python/lib" stripped off.
164 +# Note that we should only install files in the "gdb" module.
165 +PY_FILES = gdb/FrameIterator.py gdb/FrameWrapper.py gdb/command/alias.py \
166 + gdb/command/backtrace.py gdb/command/require.py \
167 + gdb/command/pahole.py gdb/command/upto.py gdb/command/__init__.py \
168 + gdb/command/ignore_errors.py gdb/command/save_breakpoints.py \
169 + gdb/function/caller_is.py gdb/function/in_scope.py \
170 + gdb/function/__init__.py gdb/backtrace.py gdb/__init__.py
172 +# Install the Python library. Python library files go under
175 + files='$(PY_FILES)'; for file in $$files; do \
176 + dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
177 + $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(pythondir)/$$dir; \
178 + $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(pythondir)/$$file; \
181 +# Other packages may have their files installed in $(pythondir).
183 + files='$(PY_FILES)'; for file in $$files; do \
184 + slashdir=`echo "/$$file" | sed 's,/[^/]*$$,,'`; \
185 + rm -f $(DESTDIR)$(pythondir)/$$file; \
186 + while test "x$$file" != "x$$slashdir"; do \
187 + rmdir 2>/dev/null "$(DESTDIR)$(pythondir)$$slashdir"; \
188 + file="$$slashdir"; \
189 + slashdir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
194 # Dependency tracking. Most of this is conditional on GNU Make being
195 # found by configure; if GNU Make is not found, we fall back to a
196 diff --git a/gdb/NEWS b/gdb/NEWS
197 index 8d32c34..f7ea21b 100644
200 @@ -476,6 +476,13 @@ x86/x86_64 Darwin i[34567]86-*-darwin*
202 x86_64 MinGW x86_64-*-mingw*
204 +* New native configurations
206 +x86/x86_64 Darwin i[34567]86-*-darwin*
209 + Show operating system information about processes.
213 Lattice Mico32 lm32-*
214 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
215 index 9b5d2c6..61676a9 100644
218 @@ -1621,7 +1621,7 @@ ada_type_of_array (struct value *arr, int bounds)
222 - struct type *range_type = alloc_type_copy (value_type (arr));
223 + struct type *range_type = alloc_type_copy (value_type (arr));
224 struct type *array_type = alloc_type_copy (value_type (arr));
225 struct value *low = desc_one_bound (descriptor, arity, 0);
226 struct value *high = desc_one_bound (descriptor, arity, 1);
227 @@ -4727,14 +4727,10 @@ ada_lookup_symbol (const char *name, const struct block *block0,
229 static struct symbol *
230 ada_lookup_symbol_nonlocal (const char *name,
231 - const char *linkage_name,
232 const struct block *block,
233 const domain_enum domain)
235 - if (linkage_name == NULL)
236 - linkage_name = name;
237 - return ada_lookup_symbol (linkage_name, block_static_block (block), domain,
239 + return ada_lookup_symbol (name, block_static_block (block), domain, NULL);
243 @@ -10839,6 +10835,40 @@ ada_operator_length (struct expression *exp, int pc, int *oplenp, int *argsp)
247 +/* Implementation of the exp_descriptor method operator_check. */
250 +ada_operator_check (struct expression *exp, int pos,
251 + int (*type_func) (struct type *type, void *data),
252 + int (*objfile_func) (struct objfile *objfile, void *data),
255 + const union exp_element *const elts = exp->elts;
256 + struct type *type = NULL;
258 + switch (elts[pos].opcode)
260 + case UNOP_IN_RANGE:
262 + type = elts[pos + 1].type;
266 + return operator_check_standard (exp, pos, type_func, objfile_func,
270 + /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
272 + if (type && type_func && (*type_func) (type, data))
274 + if (type && TYPE_OBJFILE (type) && objfile_func
275 + && (*objfile_func) (TYPE_OBJFILE (type), data))
282 ada_op_name (enum exp_opcode opcode)
284 @@ -11227,6 +11257,7 @@ parse (void)
285 static const struct exp_descriptor ada_exp_descriptor = {
288 + ada_operator_check,
290 ada_dump_subexp_body,
292 diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
293 index 7d8461c..fc4b3e0 100644
294 --- a/gdb/amd64-linux-nat.c
295 +++ b/gdb/amd64-linux-nat.c
296 @@ -270,6 +270,8 @@ amd64_linux_dr_get (ptid_t ptid, int regnum)
300 +/* Set debug register REGNUM to VALUE in only the one LWP of PTID. */
303 amd64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
305 @@ -286,6 +288,8 @@ amd64_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
306 perror_with_name (_("Couldn't write debug register"));
309 +/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST. */
312 amd64_linux_dr_set_control (unsigned long control)
314 @@ -297,6 +301,8 @@ amd64_linux_dr_set_control (unsigned long control)
315 amd64_linux_dr_set (ptid, DR_CONTROL, control);
318 +/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST. */
321 amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr)
323 @@ -310,18 +316,55 @@ amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr)
324 amd64_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
327 +/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST. */
330 amd64_linux_dr_reset_addr (int regnum)
332 amd64_linux_dr_set_addr (regnum, 0);
335 +/* Get DR_STATUS from only the one LWP of INFERIOR_PTID. */
338 amd64_linux_dr_get_status (void)
340 return amd64_linux_dr_get (inferior_ptid, DR_STATUS);
343 +/* Unset MASK bits in DR_STATUS in all LWPs of LWP_LIST. */
346 +amd64_linux_dr_unset_status (unsigned long mask)
348 + struct lwp_info *lp;
351 + ALL_LWPS (lp, ptid)
353 + unsigned long value;
355 + value = amd64_linux_dr_get (ptid, DR_STATUS);
357 + amd64_linux_dr_set (ptid, DR_STATUS, value);
361 +/* See i386_dr_low_type.detach. Do not use wrappers amd64_linux_dr_set_control
362 + or amd64_linux_dr_reset_addr as they would modify the register cache
363 + (amd64_linux_dr). */
366 +amd64_linux_dr_detach (void)
370 + amd64_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
371 + amd64_linux_dr_unset_status (~0UL);
372 + for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
373 + amd64_linux_dr_set (inferior_ptid, regnum, 0);
377 amd64_linux_new_thread (ptid_t ptid)
379 @@ -672,6 +715,8 @@ _initialize_amd64_linux_nat (void)
380 i386_dr_low.set_addr = amd64_linux_dr_set_addr;
381 i386_dr_low.reset_addr = amd64_linux_dr_reset_addr;
382 i386_dr_low.get_status = amd64_linux_dr_get_status;
383 + i386_dr_low.unset_status = amd64_linux_dr_unset_status;
384 + i386_dr_low.detach = amd64_linux_dr_detach;
385 i386_set_debug_register_length (8);
387 /* Override the GNU/Linux inferior startup hook. */
388 diff --git a/gdb/block.c b/gdb/block.c
389 index 97ea67a..b20beeb 100644
392 @@ -227,8 +227,9 @@ block_set_scope (struct block *block, const char *scope,
393 BLOCK_NAMESPACE (block)->scope = scope;
396 -/* This returns the using directives list associated with BLOCK, if
398 +/* This returns the first using directives associated with BLOCK, if
399 + any. Each BLOCK_NAMESPACE()->USING already contains all the namespaces
400 + imported at that code point - even those from its parent blocks. */
402 struct using_direct *
403 block_using (const struct block *block)
404 @@ -318,6 +319,25 @@ allocate_block (struct obstack *obstack)
405 BLOCK_SUPERBLOCK (bl) = NULL;
406 BLOCK_DICT (bl) = NULL;
407 BLOCK_NAMESPACE (bl) = NULL;
408 + BLOCK_FORTRAN_USE (bl) = NULL;
413 +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
414 + whatever reason. */
417 +block_objfile (const struct block *block)
419 + struct symbol *func;
424 + func = block_linkage_function (block);
428 + return SYMBOL_SYMTAB (func)->objfile;
430 diff --git a/gdb/block.h b/gdb/block.h
431 index 53e7371..d373f8a 100644
434 @@ -96,6 +96,15 @@ struct block
439 + /* FIXME: It should be in the LANGUAGE_SPECIFIC region but the
440 + BLOCK_NAMESPACE accessor is not protected by the C language check. */
444 + struct fortran_using *use;
449 #define BLOCK_START(bl) (bl)->startaddr
450 @@ -104,6 +113,7 @@ struct block
451 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock
452 #define BLOCK_DICT(bl) (bl)->dict
453 #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace
454 +#define BLOCK_FORTRAN_USE(bl) (bl)->fortran_specific.use
456 /* Macro to loop through all symbols in a block BL, in no particular
457 order. ITER helps keep track of the iteration, and should be a
458 @@ -166,4 +176,6 @@ extern const struct block *block_global_block (const struct block *block);
460 extern struct block *allocate_block (struct obstack *obstack);
462 +extern struct objfile *block_objfile (const struct block *block);
465 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
466 index 811cdfb..0f35101 100644
467 --- a/gdb/breakpoint.c
468 +++ b/gdb/breakpoint.c
470 #include "valprint.h"
472 #include "xml-syscall.h"
473 +#include "parser-defs.h"
475 /* readline include files */
476 #include "readline/readline.h"
477 @@ -112,8 +113,6 @@ struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
478 struct symtab_and_line,
481 -static void check_duplicates (struct breakpoint *);
483 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
485 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
486 @@ -337,14 +336,14 @@ static int executing_startup;
487 B ? (TMP=B->next, 1): 0; \
490 -/* Similar iterators for the low-level breakpoints. */
492 -#define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
493 +/* Similar iterator for the low-level breakpoints. SAFE variant is not
494 + provided so update_global_location_list must not be called while executing
495 + the block of ALL_BP_LOCATIONS. */
497 -#define ALL_BP_LOCATIONS_SAFE(B,TMP) \
498 - for (B = bp_location_chain; \
499 - B ? (TMP=B->global_next, 1): 0; \
501 +#define ALL_BP_LOCATIONS(B,BP_TMP) \
502 + for (BP_TMP = bp_location; \
503 + BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
506 /* Iterator for tracepoints only. */
508 @@ -356,10 +355,31 @@ static int executing_startup;
510 struct breakpoint *breakpoint_chain;
512 -struct bp_location *bp_location_chain;
513 +/* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
515 +static struct bp_location **bp_location;
517 +/* Number of elements of BP_LOCATION. */
519 +static unsigned bp_location_count;
521 +/* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
522 + for the current elements of BP_LOCATION which get a valid result from
523 + bp_location_has_shadow. You can use it for roughly limiting the subrange of
524 + BP_LOCATION to scan for shadow bytes for an address you need to read. */
526 +static CORE_ADDR bp_location_placed_address_before_address_max;
528 +/* Maximum offset plus alignment between
529 + bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
530 + the current elements of BP_LOCATION which get a valid result from
531 + bp_location_has_shadow. You can use it for roughly limiting the subrange of
532 + BP_LOCATION to scan for shadow bytes for an address you need to read. */
534 +static CORE_ADDR bp_location_shadow_len_after_address_max;
536 /* The locations that no longer correspond to any breakpoint,
537 - unlinked from bp_location_chain, but for which a hit
538 + unlinked from bp_location array, but for which a hit
539 may still be reported by a target. */
540 VEC(bp_location_p) *moribund_locations = NULL;
542 @@ -582,6 +602,53 @@ get_breakpoint (int num)
546 +/* Set break condition of breakpoint B to EXP. */
549 +set_breakpoint_condition (struct breakpoint *b, char *exp, int from_tty)
551 + struct bp_location *loc = b->loc;
553 + for (; loc; loc = loc->next)
562 + if (b->cond_string != NULL)
563 + xfree (b->cond_string);
567 + b->cond_string = NULL;
569 + printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number);
575 + /* I don't know if it matters whether this is the string the user
576 + typed in or the decompiled expression. */
577 + b->cond_string = xstrdup (arg);
578 + b->condition_not_parsed = 0;
579 + for (loc = b->loc; loc; loc = loc->next)
583 + parse_exp_1 (&arg, block_for_pc (loc->address), 0);
585 + error (_("Junk at end of expression"));
589 + breakpoints_changed ();
590 + observer_notify_breakpoint_modified (b->number);
593 /* condition N EXP -- set break condition of breakpoint N to EXP. */
596 @@ -602,42 +669,7 @@ condition_command (char *arg, int from_tty)
598 if (b->number == bnum)
600 - struct bp_location *loc = b->loc;
601 - for (; loc; loc = loc->next)
609 - if (b->cond_string != NULL)
610 - xfree (b->cond_string);
614 - b->cond_string = NULL;
616 - printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum);
621 - /* I don't know if it matters whether this is the string the user
622 - typed in or the decompiled expression. */
623 - b->cond_string = xstrdup (arg);
624 - b->condition_not_parsed = 0;
625 - for (loc = b->loc; loc; loc = loc->next)
629 - parse_exp_1 (&arg, block_for_pc (loc->address), 0);
631 - error (_("Junk at end of expression"));
634 - breakpoints_changed ();
635 - observer_notify_breakpoint_modified (b->number);
636 + set_breakpoint_condition (b, p, from_tty);
640 @@ -735,35 +767,88 @@ commands_from_control_command (char *arg, struct command_line *cmd)
642 error (_("No breakpoint number %d."), bnum);
646 +/* Return non-zero if BL->TARGET_INFO contains valid information. */
649 +bp_location_has_shadow (struct bp_location *bl)
651 + if (bl->loc_type != bp_loc_software_breakpoint)
655 + if (bl->target_info.shadow_len == 0)
656 + /* bp isn't valid, or doesn't shadow memory. */
661 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
662 - by replacing any memory breakpoints with their shadowed contents. */
663 + by replacing any memory breakpoints with their shadowed contents.
665 + The range of shadowed area by each bp_location is:
666 + b->address - bp_location_placed_address_before_address_max
667 + up to b->address + bp_location_shadow_len_after_address_max
668 + The range we were requested to resolve shadows for is:
669 + memaddr ... memaddr + le
670 + Thus the safe cutoff boundaries for performance optimization are
671 + memaddr + len <= b->address - bp_location_placed_address_before_address_max
673 + b->address + bp_location_shadow_len_after_address_max <= memaddr */
676 breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
678 - struct bp_location *b;
679 - CORE_ADDR bp_addr = 0;
682 + /* Left boundary, right boundary and media element of our binary search. */
683 + unsigned bc_l, bc_r, bc;
685 + /* Find BC_L which is a leftmost element which may affect BUF content. It is
686 + safe to report lower value but a failure to report higher one. */
688 - ALL_BP_LOCATIONS (b)
690 + bc_r = bp_location_count;
691 + while (bc_l + 1 < bc_r)
693 + struct bp_location *b;
695 + bc = (bc_l + bc_r) / 2;
696 + b = bp_location[bc];
698 + if (b->address + bp_location_shadow_len_after_address_max >= b->address
699 + && b->address + bp_location_shadow_len_after_address_max <= memaddr)
705 + /* Now do full processing of the found relevant range of elements. */
707 + for (bc = bc_l; bc < bp_location_count; bc++)
709 + struct bp_location *b = bp_location[bc];
710 + CORE_ADDR bp_addr = 0;
714 if (b->owner->type == bp_none)
715 warning (_("reading through apparently deleted breakpoint #%d?"),
718 - if (b->loc_type != bp_loc_software_breakpoint)
721 + /* Performance optimization: any futher element can no longer affect BUF
724 + if (b->address >= bp_location_placed_address_before_address_max
725 + && memaddr + len <= b->address
726 + - bp_location_placed_address_before_address_max)
729 + if (!bp_location_has_shadow (b))
732 /* Addresses and length of the part of the breakpoint that
734 bp_addr = b->target_info.placed_address;
735 bp_size = b->target_info.shadow_len;
737 - /* bp isn't valid, or doesn't shadow memory. */
740 if (bp_addr + bp_size <= memaddr)
741 /* The breakpoint is entirely before the chunk of memory we
742 @@ -912,7 +997,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
743 struct bp_location *loc;
746 - /* We don't free locations. They are stored in bp_location_chain and
747 + /* We don't free locations. They are stored in bp_location array and
748 update_global_locations will eventually delete them and remove
749 breakpoints if needed. */
751 @@ -1347,7 +1432,7 @@ static void
752 insert_breakpoint_locations (void)
754 struct breakpoint *bpt;
755 - struct bp_location *b, *temp;
756 + struct bp_location *b, **bp_tmp;
759 int disabled_breaks = 0;
760 @@ -1360,7 +1445,7 @@ insert_breakpoint_locations (void)
761 there was an error. */
762 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
764 - ALL_BP_LOCATIONS_SAFE (b, temp)
765 + ALL_BP_LOCATIONS (b, bp_tmp)
767 if (!should_be_inserted (b) || b->inserted)
769 @@ -1434,10 +1519,10 @@ You may have requested too many hardware breakpoints/watchpoints.\n");
771 remove_breakpoints (void)
773 - struct bp_location *b;
774 + struct bp_location *b, **bp_tmp;
777 - ALL_BP_LOCATIONS (b)
778 + ALL_BP_LOCATIONS (b, bp_tmp)
781 val |= remove_breakpoint (b, mark_uninserted);
782 @@ -1448,10 +1533,10 @@ remove_breakpoints (void)
784 remove_hw_watchpoints (void)
786 - struct bp_location *b;
787 + struct bp_location *b, **bp_tmp;
790 - ALL_BP_LOCATIONS (b)
791 + ALL_BP_LOCATIONS (b, bp_tmp)
793 if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
794 val |= remove_breakpoint (b, mark_uninserted);
795 @@ -1462,7 +1547,7 @@ remove_hw_watchpoints (void)
797 reattach_breakpoints (int pid)
799 - struct bp_location *b;
800 + struct bp_location *b, **bp_tmp;
802 struct cleanup *old_chain = save_inferior_ptid ();
803 struct ui_file *tmp_error_stream = mem_fileopen ();
804 @@ -1471,7 +1556,7 @@ reattach_breakpoints (int pid)
805 make_cleanup_ui_file_delete (tmp_error_stream);
807 inferior_ptid = pid_to_ptid (pid);
808 - ALL_BP_LOCATIONS (b)
809 + ALL_BP_LOCATIONS (b, bp_tmp)
813 @@ -1569,12 +1654,42 @@ create_longjmp_master_breakpoint (char *func_name)
814 update_global_location_list (1);
817 +/* Install a master breakpoint on the unwinder's debug hook. */
820 +create_exception_master_breakpoint (void)
822 + struct objfile *objfile;
824 + ALL_OBJFILES (objfile)
826 + struct minimal_symbol *debug_hook;
828 + debug_hook = lookup_minimal_symbol_text ("_Unwind_DebugHook", objfile);
829 + if (debug_hook != NULL)
832 + struct breakpoint *b;
834 + pc = find_function_start_pc (get_objfile_arch (objfile),
835 + SYMBOL_VALUE_ADDRESS (debug_hook),
836 + SYMBOL_OBJ_SECTION (debug_hook));
837 + b = create_internal_breakpoint (get_objfile_arch (objfile),
838 + pc, bp_exception_master);
839 + b->addr_string = xstrdup ("_Unwind_DebugHook");
840 + b->enable_state = bp_disabled;
844 + update_global_location_list (1);
848 update_breakpoints_after_exec (void)
850 struct breakpoint *b;
851 struct breakpoint *temp;
852 - struct bp_location *bploc;
853 + struct bp_location *bploc, **bplocp_tmp;
855 /* We're about to delete breakpoints from GDB's lists. If the
856 INSERTED flag is true, GDB will try to lift the breakpoints by
857 @@ -1584,7 +1699,7 @@ update_breakpoints_after_exec (void)
858 breakpoints out as soon as it detects an exec. We don't do that
859 here instead, because there may be other attempts to delete
860 breakpoints after detecting an exec and before reaching here. */
861 - ALL_BP_LOCATIONS (bploc)
862 + ALL_BP_LOCATIONS (bploc, bplocp_tmp)
863 gdb_assert (!bploc->inserted);
865 ALL_BREAKPOINTS_SAFE (b, temp)
866 @@ -1606,7 +1721,7 @@ update_breakpoints_after_exec (void)
867 /* Thread event breakpoints must be set anew after an exec(),
868 as must overlay event and longjmp master breakpoints. */
869 if (b->type == bp_thread_event || b->type == bp_overlay_event
870 - || b->type == bp_longjmp_master)
871 + || b->type == bp_longjmp_master || b->type == bp_exception_master)
873 delete_breakpoint (b);
875 @@ -1621,7 +1736,8 @@ update_breakpoints_after_exec (void)
877 /* Longjmp and longjmp-resume breakpoints are also meaningless
879 - if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
880 + if (b->type == bp_longjmp || b->type == bp_longjmp_resume
881 + || b->type == bp_exception || b->type == bp_exception_resume)
883 delete_breakpoint (b);
885 @@ -1682,12 +1798,13 @@ update_breakpoints_after_exec (void)
886 create_longjmp_master_breakpoint ("_longjmp");
887 create_longjmp_master_breakpoint ("siglongjmp");
888 create_longjmp_master_breakpoint ("_siglongjmp");
889 + create_exception_master_breakpoint ();
893 detach_breakpoints (int pid)
895 - struct bp_location *b;
896 + struct bp_location *b, **bp_tmp;
898 struct cleanup *old_chain = save_inferior_ptid ();
900 @@ -1696,11 +1813,12 @@ detach_breakpoints (int pid)
902 /* Set inferior_ptid; remove_breakpoint uses this global. */
903 inferior_ptid = pid_to_ptid (pid);
904 - ALL_BP_LOCATIONS (b)
905 + ALL_BP_LOCATIONS (b, bp_tmp)
908 val |= remove_breakpoint (b, mark_inserted);
910 + val |= target_detach_watchpoints ();
911 do_cleanups (old_chain);
914 @@ -1793,12 +1911,14 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
916 b->inserted = (is == mark_inserted);
918 - else if (b->loc_type == bp_loc_hardware_watchpoint)
919 + /* bp_loc_hardware_watchpoint with mark_inserted is being handled by
920 + target_detach_watchpoints. */
921 + else if (b->loc_type == bp_loc_hardware_watchpoint && is == mark_uninserted)
926 - b->inserted = (is == mark_inserted);
928 val = target_remove_watchpoint (b->address, b->length,
931 @@ -1827,9 +1947,9 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
933 mark_breakpoints_out (void)
935 - struct bp_location *bpt;
936 + struct bp_location *bpt, **bptp_tmp;
938 - ALL_BP_LOCATIONS (bpt)
939 + ALL_BP_LOCATIONS (bpt, bptp_tmp)
943 @@ -1849,7 +1969,7 @@ void
944 breakpoint_init_inferior (enum inf_context context)
946 struct breakpoint *b, *temp;
947 - struct bp_location *bpt;
948 + struct bp_location *bpt, **bptp_tmp;
951 /* If breakpoint locations are shared across processes, then there's
952 @@ -1857,7 +1977,7 @@ breakpoint_init_inferior (enum inf_context context)
953 if (gdbarch_has_global_breakpoints (target_gdbarch))
956 - ALL_BP_LOCATIONS (bpt)
957 + ALL_BP_LOCATIONS (bpt, bptp_tmp)
958 if (bpt->owner->enable_state != bp_permanent)
961 @@ -1918,10 +2038,10 @@ breakpoint_init_inferior (enum inf_context context)
963 breakpoint_here_p (CORE_ADDR pc)
965 - const struct bp_location *bpt;
966 + struct bp_location *bpt, **bptp_tmp;
967 int any_breakpoint_here = 0;
969 - ALL_BP_LOCATIONS (bpt)
970 + ALL_BP_LOCATIONS (bpt, bptp_tmp)
972 if (bpt->loc_type != bp_loc_software_breakpoint
973 && bpt->loc_type != bp_loc_hardware_breakpoint)
974 @@ -1961,16 +2081,16 @@ moribund_breakpoint_here_p (CORE_ADDR pc)
977 /* Returns non-zero if there's a breakpoint inserted at PC, which is
978 - inserted using regular breakpoint_chain/bp_location_chain mechanism.
979 + inserted using regular breakpoint_chain / bp_location array mechanism.
980 This does not check for single-step breakpoints, which are
981 inserted and removed using direct target manipulation. */
984 regular_breakpoint_inserted_here_p (CORE_ADDR pc)
986 - const struct bp_location *bpt;
987 + struct bp_location *bpt, **bptp_tmp;
989 - ALL_BP_LOCATIONS (bpt)
990 + ALL_BP_LOCATIONS (bpt, bptp_tmp)
992 if (bpt->loc_type != bp_loc_software_breakpoint
993 && bpt->loc_type != bp_loc_hardware_breakpoint)
994 @@ -2011,10 +2131,10 @@ breakpoint_inserted_here_p (CORE_ADDR pc)
996 software_breakpoint_inserted_here_p (CORE_ADDR pc)
998 - const struct bp_location *bpt;
999 + struct bp_location *bpt, **bptp_tmp;
1000 int any_breakpoint_here = 0;
1002 - ALL_BP_LOCATIONS (bpt)
1003 + ALL_BP_LOCATIONS (bpt, bptp_tmp)
1005 if (bpt->loc_type != bp_loc_software_breakpoint)
1007 @@ -2044,12 +2164,12 @@ software_breakpoint_inserted_here_p (CORE_ADDR pc)
1009 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1011 - const struct bp_location *bpt;
1012 + struct bp_location *bpt, **bptp_tmp;
1013 /* The thread and task IDs associated to PTID, computed lazily. */
1017 - ALL_BP_LOCATIONS (bpt)
1018 + ALL_BP_LOCATIONS (bpt, bptp_tmp)
1020 if (bpt->loc_type != bp_loc_software_breakpoint
1021 && bpt->loc_type != bp_loc_hardware_breakpoint)
1022 @@ -2503,6 +2623,12 @@ print_it_typical (bpstat bs)
1023 result = PRINT_NOTHING;
1026 + case bp_exception_master:
1027 + /* These should never be enabled. */
1028 + printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
1029 + result = PRINT_NOTHING;
1033 case bp_hardware_watchpoint:
1034 annotate_watchpoint (b->number);
1035 @@ -2590,6 +2716,8 @@ print_it_typical (bpstat bs)
1038 case bp_longjmp_resume:
1039 + case bp_exception:
1040 + case bp_exception_resume:
1041 case bp_step_resume:
1042 case bp_watchpoint_scope:
1044 @@ -2973,8 +3101,12 @@ bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr)
1046 /* If BS refers to a watchpoint, determine if the watched values
1047 has actually changed, and we should stop. If not, set BS->stop
1051 + Return 0 for watchpoints which could not be the cause of this trap.
1052 + In such case PRINT_IT will be print_it_noop and STOP will be 0.
1053 + Otherwise return 1 but in such case it is not guaranteed whether this
1054 + breakpoint did or did not trigger this trap. */
1056 bpstat_check_watchpoint (bpstat bs)
1058 const struct bp_location *bl = bs->breakpoint_at;
1059 @@ -3063,8 +3195,10 @@ bpstat_check_watchpoint (bpstat bs)
1060 anything for this watchpoint. */
1061 bs->print_it = print_it_noop;
1070 @@ -3157,17 +3291,19 @@ bpstat
1071 bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1073 struct breakpoint *b = NULL;
1074 - const struct bp_location *bl;
1075 + struct bp_location *bl, **blp_tmp;
1076 struct bp_location *loc;
1077 /* Root of the chain of bpstat's */
1078 struct bpstats root_bs[1];
1079 /* Pointer to the last thing in the chain currently. */
1080 bpstat bs = root_bs;
1082 - int need_remove_insert;
1083 + int need_remove_insert, update_locations = 0;
1085 - ALL_BP_LOCATIONS (bl)
1086 + ALL_BP_LOCATIONS (bl, blp_tmp)
1088 + bpstat bs_prev = bs;
1092 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent)
1093 @@ -3188,6 +3324,7 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1094 /* Come here if it's a watchpoint, or if the break address matches */
1096 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
1097 + gdb_assert (bs_prev->next == bs);
1099 /* Assume we stop. Should we find watchpoint that is not actually
1100 triggered, or if condition of breakpoint is false, we'll reset
1101 @@ -3195,12 +3332,21 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1105 - bpstat_check_watchpoint (bs);
1108 + if (!bpstat_check_watchpoint (bs))
1110 + /* Ensure bpstat_explains_signal stays false if this BL could not be
1111 + the cause of this trap. */
1113 + gdb_assert (bs->print_it == print_it_noop);
1114 + gdb_assert (!bs->stop);
1121 if (b->type == bp_thread_event || b->type == bp_overlay_event
1122 - || b->type == bp_longjmp_master)
1123 + || b->type == bp_longjmp_master || b->type == bp_exception_master)
1124 /* We do not stop for these. */
1127 @@ -3208,14 +3354,15 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1132 + if (b->enable_state != bp_disabled)
1135 /* We will stop here */
1136 if (b->disposition == disp_disable)
1138 if (b->enable_state != bp_permanent)
1139 b->enable_state = bp_disabled;
1140 - update_global_location_list (0);
1141 + update_locations = 1;
1145 @@ -3235,6 +3382,10 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
1146 bs->print_it = print_it_noop;
1149 + /* Delay this call which would break the ALL_BP_LOCATIONS iteration above. */
1150 + if (update_locations)
1151 + update_global_location_list (0);
1153 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
1155 if (loc->address == bp_addr)
1156 @@ -3412,6 +3563,7 @@ bpstat_what (bpstat bs)
1157 struct bpstat_what retval;
1159 retval.call_dummy = 0;
1160 + retval.is_longjmp = 0;
1161 for (; bs != NULL; bs = bs->next)
1163 enum class bs_class = no_effect;
1164 @@ -3458,10 +3610,15 @@ bpstat_what (bpstat bs)
1165 bs_class = no_effect;
1168 + case bp_exception:
1169 bs_class = long_jump;
1170 + retval.is_longjmp = bs->breakpoint_at->owner->type == bp_longjmp;
1172 case bp_longjmp_resume:
1173 + case bp_exception_resume:
1174 bs_class = long_resume;
1176 + = bs->breakpoint_at->owner->type == bp_longjmp_resume;
1178 case bp_step_resume:
1180 @@ -3484,6 +3641,7 @@ bpstat_what (bpstat bs)
1181 case bp_thread_event:
1182 case bp_overlay_event:
1183 case bp_longjmp_master:
1184 + case bp_exception_master:
1185 bs_class = bp_nostop;
1188 @@ -3605,6 +3763,8 @@ print_one_breakpoint_location (struct breakpoint *b,
1189 {bp_access_watchpoint, "acc watchpoint"},
1190 {bp_longjmp, "longjmp"},
1191 {bp_longjmp_resume, "longjmp resume"},
1192 + {bp_exception, "exception"},
1193 + {bp_exception_resume, "exception resume"},
1194 {bp_step_resume, "step resume"},
1195 {bp_watchpoint_scope, "watchpoint scope"},
1196 {bp_call_dummy, "call dummy"},
1197 @@ -3612,6 +3772,7 @@ print_one_breakpoint_location (struct breakpoint *b,
1198 {bp_thread_event, "thread events"},
1199 {bp_overlay_event, "overlay events"},
1200 {bp_longjmp_master, "longjmp master"},
1201 + {bp_exception_master, "exception master"},
1202 {bp_catchpoint, "catchpoint"},
1203 {bp_tracepoint, "tracepoint"},
1204 {bp_jit_event, "jit events"},
1205 @@ -3735,6 +3896,8 @@ print_one_breakpoint_location (struct breakpoint *b,
1208 case bp_longjmp_resume:
1209 + case bp_exception:
1210 + case bp_exception_resume:
1211 case bp_step_resume:
1212 case bp_watchpoint_scope:
1214 @@ -3742,6 +3905,7 @@ print_one_breakpoint_location (struct breakpoint *b,
1215 case bp_thread_event:
1216 case bp_overlay_event:
1217 case bp_longjmp_master:
1218 + case bp_exception_master:
1221 if (opts.addressprint)
1222 @@ -4197,9 +4361,8 @@ set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
1223 (or use it for any other purpose either).
1225 More specifically, each of the following breakpoint types will always
1226 - have a zero valued address and we don't want check_duplicates() to mark
1227 - breakpoints of any of these types to be a duplicate of an actual
1228 - breakpoint at address zero:
1229 + have a zero valued address and we don't want to mark breakpoints of any of
1230 + these types to be a duplicate of an actual breakpoint at address zero:
1233 bp_hardware_watchpoint
1234 @@ -4219,88 +4382,6 @@ breakpoint_address_is_meaningful (struct breakpoint *bpt)
1235 && type != bp_catchpoint);
1238 -/* Rescan breakpoints at the same address and section as BPT,
1239 - marking the first one as "first" and any others as "duplicates".
1240 - This is so that the bpt instruction is only inserted once.
1241 - If we have a permanent breakpoint at the same place as BPT, make
1242 - that one the official one, and the rest as duplicates. */
1245 -check_duplicates_for (CORE_ADDR address, struct obj_section *section)
1247 - struct bp_location *b;
1249 - struct bp_location *perm_bp = 0;
1251 - ALL_BP_LOCATIONS (b)
1252 - if (b->owner->enable_state != bp_disabled
1253 - && b->owner->enable_state != bp_call_disabled
1254 - && b->owner->enable_state != bp_startup_disabled
1256 - && !b->shlib_disabled
1257 - && b->address == address /* address / overlay match */
1258 - && (!overlay_debugging || b->section == section)
1259 - && breakpoint_address_is_meaningful (b->owner))
1261 - /* Have we found a permanent breakpoint? */
1262 - if (b->owner->enable_state == bp_permanent)
1269 - b->duplicate = count > 1;
1272 - /* If we found a permanent breakpoint at this address, go over the
1273 - list again and declare all the other breakpoints there (except
1274 - other permanent breakpoints) to be the duplicates. */
1277 - perm_bp->duplicate = 0;
1279 - /* Permanent breakpoint should always be inserted. */
1280 - if (! perm_bp->inserted)
1281 - internal_error (__FILE__, __LINE__,
1282 - _("allegedly permanent breakpoint is not "
1283 - "actually inserted"));
1285 - ALL_BP_LOCATIONS (b)
1288 - if (b->owner->enable_state != bp_permanent
1289 - && b->owner->enable_state != bp_disabled
1290 - && b->owner->enable_state != bp_call_disabled
1291 - && b->owner->enable_state != bp_startup_disabled
1292 - && b->enabled && !b->shlib_disabled
1293 - && b->address == address /* address / overlay match */
1294 - && (!overlay_debugging || b->section == section)
1295 - && breakpoint_address_is_meaningful (b->owner))
1298 - internal_error (__FILE__, __LINE__,
1299 - _("another breakpoint was inserted on top of "
1300 - "a permanent breakpoint"));
1309 -check_duplicates (struct breakpoint *bpt)
1311 - struct bp_location *bl = bpt->loc;
1313 - if (! breakpoint_address_is_meaningful (bpt))
1316 - for (; bl; bl = bl->next)
1317 - check_duplicates_for (bl->address, bl->section);
1321 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
1322 int bnum, int have_bnum)
1323 @@ -4382,6 +4463,8 @@ allocate_bp_location (struct breakpoint *bpt)
1326 case bp_longjmp_resume:
1327 + case bp_exception:
1328 + case bp_exception_resume:
1329 case bp_step_resume:
1330 case bp_watchpoint_scope:
1332 @@ -4390,6 +4473,7 @@ allocate_bp_location (struct breakpoint *bpt)
1333 case bp_overlay_event:
1335 case bp_longjmp_master:
1336 + case bp_exception_master:
1337 loc->loc_type = bp_loc_software_breakpoint;
1339 case bp_hardware_breakpoint:
1340 @@ -4568,8 +4652,7 @@ make_breakpoint_permanent (struct breakpoint *b)
1343 /* Call this routine when stepping and nexting to enable a breakpoint
1344 - if we do a longjmp() in THREAD. When we hit that breakpoint, call
1345 - set_longjmp_resume_breakpoint() to figure out where we are going. */
1346 + if we do a longjmp() or 'throw' in THREAD. */
1349 set_longjmp_breakpoint (int thread)
1350 @@ -4581,10 +4664,10 @@ set_longjmp_breakpoint (int thread)
1351 longjmp "master" breakpoints. Here, we simply create momentary
1352 clones of those and enable them for the requested thread. */
1353 ALL_BREAKPOINTS_SAFE (b, temp)
1354 - if (b->type == bp_longjmp_master)
1355 + if (b->type == bp_longjmp_master || b->type == bp_exception_master)
1357 struct breakpoint *clone = clone_momentary_breakpoint (b);
1358 - clone->type = bp_longjmp;
1359 + clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
1360 clone->thread = thread;
1363 @@ -4596,7 +4679,7 @@ delete_longjmp_breakpoint (int thread)
1364 struct breakpoint *b, *temp;
1366 ALL_BREAKPOINTS_SAFE (b, temp)
1367 - if (b->type == bp_longjmp)
1368 + if (b->type == bp_longjmp || b->type == bp_exception)
1370 if (b->thread == thread)
1371 delete_breakpoint (b);
1372 @@ -4710,9 +4793,9 @@ create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
1374 disable_breakpoints_in_shlibs (void)
1376 - struct bp_location *loc;
1377 + struct bp_location *loc, **locp_tmp;
1379 - ALL_BP_LOCATIONS (loc)
1380 + ALL_BP_LOCATIONS (loc, locp_tmp)
1382 struct breakpoint *b = loc->owner;
1383 /* We apply the check to all breakpoints, including disabled
1384 @@ -4742,7 +4825,7 @@ disable_breakpoints_in_shlibs (void)
1386 disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
1388 - struct bp_location *loc;
1389 + struct bp_location *loc, **locp_tmp;
1390 int disabled_shlib_breaks = 0;
1392 /* SunOS a.out shared libraries are always mapped, so do not
1393 @@ -4753,7 +4836,7 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
1394 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour)
1397 - ALL_BP_LOCATIONS (loc)
1398 + ALL_BP_LOCATIONS (loc, locp_tmp)
1400 struct breakpoint *b = loc->owner;
1401 if ((loc->loc_type == bp_loc_hardware_breakpoint
1402 @@ -5648,6 +5731,8 @@ mention (struct breakpoint *b)
1405 case bp_longjmp_resume:
1406 + case bp_exception:
1407 + case bp_exception_resume:
1408 case bp_step_resume:
1410 case bp_watchpoint_scope:
1411 @@ -5656,6 +5741,7 @@ mention (struct breakpoint *b)
1412 case bp_overlay_event:
1414 case bp_longjmp_master:
1415 + case bp_exception_master:
1419 @@ -6958,6 +7044,7 @@ struct until_break_command_continuation_args
1421 struct breakpoint *breakpoint;
1422 struct breakpoint *breakpoint2;
1426 /* This function is called by fetch_inferior_event via the
1427 @@ -6972,6 +7059,7 @@ until_break_command_continuation (void *arg)
1428 delete_breakpoint (a->breakpoint);
1430 delete_breakpoint (a->breakpoint2);
1431 + delete_longjmp_breakpoint (a->thread_num);
1435 @@ -6983,6 +7071,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
1436 struct breakpoint *breakpoint;
1437 struct breakpoint *breakpoint2 = NULL;
1438 struct cleanup *old_chain;
1440 + struct thread_info *tp;
1442 clear_proceed_status ();
1444 @@ -7021,6 +7111,9 @@ until_break_command (char *arg, int from_tty, int anywhere)
1446 old_chain = make_cleanup_delete_breakpoint (breakpoint);
1448 + tp = inferior_thread ();
1451 /* Keep within the current frame, or in frames called by the current
1454 @@ -7033,6 +7126,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
1455 frame_unwind_caller_id (frame),
1457 make_cleanup_delete_breakpoint (breakpoint2);
1459 + set_longjmp_breakpoint (thread);
1460 + tp->initiating_frame = frame_unwind_caller_id (frame);
1461 + make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
1464 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
1465 @@ -7049,6 +7146,7 @@ until_break_command (char *arg, int from_tty, int anywhere)
1467 args->breakpoint = breakpoint;
1468 args->breakpoint2 = breakpoint2;
1469 + args->thread_num = thread;
1471 discard_cleanups (old_chain);
1472 add_continuation (inferior_thread (),
1473 @@ -7758,6 +7856,82 @@ do_vec_free (void *p)
1474 VEC_free (bp_location_p, *vec);
1477 +/* A comparison function for bp_location A and B being interfaced to qsort.
1478 + Sort elements primarily by their ADDRESS (no matter what does
1479 + breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
1480 + first bp_permanent OWNERed elements and terciarily just ensuring the array
1481 + is sorted stable way despite qsort being an instable algorithm. */
1484 +bp_location_compare (struct bp_location *a, struct bp_location *b)
1486 + int a_perm = a->owner->enable_state == bp_permanent;
1487 + int b_perm = b->owner->enable_state == bp_permanent;
1489 + if (a->address != b->address)
1490 + return (a->address > b->address) - (a->address < b->address);
1492 + /* Sort permanent breakpoints first. */
1493 + if (a_perm != b_perm)
1494 + return (a_perm < b_perm) - (a_perm > b_perm);
1496 + /* Make the user-visible order stable across GDB runs. Locations of the same
1497 + breakpoint can be sorted in arbitrary order. */
1499 + if (a->owner->number != b->owner->number)
1500 + return (a->owner->number > b->owner->number)
1501 + - (a->owner->number < b->owner->number);
1503 + return (a > b) - (a < b);
1506 +/* Interface bp_location_compare as the COMPAR parameter of qsort function. */
1509 +bp_location_compare_for_qsort (const void *ap, const void *bp)
1511 + struct bp_location *a = *(void **) ap;
1512 + struct bp_location *b = *(void **) bp;
1514 + return bp_location_compare (a, b);
1517 +/* Set bp_location_placed_address_before_address_max and
1518 + bp_location_shadow_len_after_address_max according to the current content of
1519 + the bp_location array. */
1522 +bp_location_target_extensions_update (void)
1524 + struct bp_location *bl, **blp_tmp;
1526 + bp_location_placed_address_before_address_max = 0;
1527 + bp_location_shadow_len_after_address_max = 0;
1529 + ALL_BP_LOCATIONS (bl, blp_tmp)
1531 + CORE_ADDR start, end, addr;
1533 + if (!bp_location_has_shadow (bl))
1536 + start = bl->target_info.placed_address;
1537 + end = start + bl->target_info.shadow_len;
1539 + gdb_assert (bl->address >= start);
1540 + addr = bl->address - start;
1541 + if (addr > bp_location_placed_address_before_address_max)
1542 + bp_location_placed_address_before_address_max = addr;
1544 + /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
1546 + gdb_assert (bl->address < end);
1547 + addr = end - bl->address;
1548 + if (addr > bp_location_shadow_len_after_address_max)
1549 + bp_location_shadow_len_after_address_max = addr;
1553 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
1554 into the inferior, only remove already-inserted locations that no
1555 longer should be inserted. Functions that delete a breakpoint or
1556 @@ -7777,49 +7951,78 @@ static void
1557 update_global_location_list (int should_insert)
1559 struct breakpoint *b;
1560 - struct bp_location **next = &bp_location_chain;
1561 - struct bp_location *loc;
1562 - struct bp_location *loc2;
1563 - VEC(bp_location_p) *old_locations = NULL;
1566 + struct bp_location **locp, *loc;
1567 struct cleanup *cleanups;
1569 - cleanups = make_cleanup (do_vec_free, &old_locations);
1570 - /* Store old locations for future reference. */
1571 - for (loc = bp_location_chain; loc; loc = loc->global_next)
1572 - VEC_safe_push (bp_location_p, old_locations, loc);
1573 + /* The first bp_location being the only one non-DUPLICATE for the current run
1574 + of the same ADDRESS. */
1575 + struct bp_location *loc_first;
1577 + /* Saved former bp_location array which we compare against the newly built
1578 + bp_location from the current state of ALL_BREAKPOINTS. */
1579 + struct bp_location **old_location, **old_locp;
1580 + unsigned old_location_count;
1582 + old_location = bp_location;
1583 + old_location_count = bp_location_count;
1584 + bp_location = NULL;
1585 + bp_location_count = 0;
1586 + cleanups = make_cleanup (xfree, old_location);
1588 - bp_location_chain = NULL;
1591 - for (loc = b->loc; loc; loc = loc->next)
1594 - next = &(loc->global_next);
1598 + for (loc = b->loc; loc; loc = loc->next)
1599 + bp_location_count++;
1601 + bp_location = xmalloc (sizeof (*bp_location) * bp_location_count);
1602 + locp = bp_location;
1603 + ALL_BREAKPOINTS (b)
1604 + for (loc = b->loc; loc; loc = loc->next)
1606 + qsort (bp_location, bp_location_count, sizeof (*bp_location),
1607 + bp_location_compare_for_qsort);
1609 + bp_location_target_extensions_update ();
1611 /* Identify bp_location instances that are no longer present in the new
1612 list, and therefore should be freed. Note that it's not necessary that
1613 those locations should be removed from inferior -- if there's another
1614 location at the same address (previously marked as duplicate),
1615 - we don't need to remove/insert the location. */
1616 - for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix)
1617 + we don't need to remove/insert the location.
1619 + LOCP is kept in sync with OLD_LOCP, each pointing to the current and
1620 + former bp_location array state respectively. */
1622 + locp = bp_location;
1623 + for (old_locp = old_location; old_locp < old_location + old_location_count;
1626 - /* Tells if 'loc' is found amoung the new locations. If not, we
1627 + struct bp_location *old_loc = *old_locp;
1628 + struct bp_location **loc2p;
1630 + /* Tells if 'old_loc' is found amoung the new locations. If not, we
1632 int found_object = 0;
1633 /* Tells if the location should remain inserted in the target. */
1634 int keep_in_target = 0;
1636 - for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
1643 + /* Skip LOCP entries which will definitely never be needed. Stop either
1644 + at or being the one matching OLD_LOC. */
1645 + while (locp < bp_location + bp_location_count
1646 + && (*locp)->address < old_loc->address)
1649 + for (loc2p = locp;
1650 + (loc2p < bp_location + bp_location_count
1651 + && (*loc2p)->address == old_loc->address);
1654 + if (*loc2p == old_loc)
1661 /* If this location is no longer present, and inserted, look if there's
1662 maybe a new location at the same address. If so, mark that one
1663 @@ -7827,11 +8030,11 @@ update_global_location_list (int should_insert)
1664 don't have a time window where a breakpoint at certain location is not
1667 - if (loc->inserted)
1668 + if (old_loc->inserted)
1670 /* If the location is inserted now, we might have to remove it. */
1672 - if (found_object && should_be_inserted (loc))
1673 + if (found_object && should_be_inserted (old_loc))
1675 /* The location is still present in the location list, and still
1676 should be inserted. Don't do anything. */
1677 @@ -7842,37 +8045,46 @@ update_global_location_list (int should_insert)
1678 /* The location is either no longer present, or got disabled.
1679 See if there's another location at the same address, in which
1680 case we don't need to remove this one from the target. */
1681 - if (breakpoint_address_is_meaningful (loc->owner))
1682 - for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
1684 - /* For the sake of should_insert_location. The
1685 - call to check_duplicates will fix up this later. */
1686 - loc2->duplicate = 0;
1687 - if (should_be_inserted (loc2)
1688 - && loc2 != loc && loc2->address == loc->address)
1690 - loc2->inserted = 1;
1691 - loc2->target_info = loc->target_info;
1692 - keep_in_target = 1;
1697 + if (breakpoint_address_is_meaningful (old_loc->owner))
1699 + for (loc2p = locp;
1700 + (loc2p < bp_location + bp_location_count
1701 + && (*loc2p)->address == old_loc->address);
1704 + struct bp_location *loc2 = *loc2p;
1707 + /* For the sake of should_be_inserted.
1708 + Duplicates check below will fix up this later. */
1709 + loc2->duplicate = 0;
1710 + if (loc2 != old_loc && should_be_inserted (loc2))
1712 + loc2->inserted = 1;
1713 + loc2->target_info = old_loc->target_info;
1714 + keep_in_target = 1;
1722 if (!keep_in_target)
1724 - if (remove_breakpoint (loc, mark_uninserted))
1725 + if (remove_breakpoint (old_loc, mark_uninserted))
1727 /* This is just about all we can do. We could keep this
1728 location on the global list, and try to remove it next
1729 time, but there's no particular reason why we will
1732 - Note that at this point, loc->owner is still valid,
1733 + Note that at this point, old_loc->owner is still valid,
1734 as delete_breakpoint frees the breakpoint only
1735 after calling us. */
1736 printf_filtered (_("warning: Error removing breakpoint %d\n"),
1737 - loc->owner->number);
1738 + old_loc->owner->number);
1742 @@ -7894,19 +8106,59 @@ update_global_location_list (int should_insert)
1743 longer need to keep this breakpoint. This is just a
1744 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
1745 which is usability issue, but not a correctness problem. */
1746 - loc->events_till_retirement = 3 * (thread_count () + 1);
1747 - loc->owner = NULL;
1748 + old_loc->events_till_retirement = 3 * (thread_count () + 1);
1749 + old_loc->owner = NULL;
1751 - VEC_safe_push (bp_location_p, moribund_locations, loc);
1752 + VEC_safe_push (bp_location_p, moribund_locations, old_loc);
1755 - free_bp_location (loc);
1756 + free_bp_location (old_loc);
1760 - ALL_BREAKPOINTS (b)
1761 + /* Rescan breakpoints at the same address and section,
1762 + marking the first one as "first" and any others as "duplicates".
1763 + This is so that the bpt instruction is only inserted once.
1764 + If we have a permanent breakpoint at the same place as BPT, make
1765 + that one the official one, and the rest as duplicates. Permanent
1766 + breakpoints are sorted first for the same address. */
1769 + ALL_BP_LOCATIONS (loc, locp)
1771 - check_duplicates (b);
1772 + struct breakpoint *b = loc->owner;
1774 + if (b->enable_state == bp_disabled
1775 + || b->enable_state == bp_call_disabled
1776 + || b->enable_state == bp_startup_disabled
1778 + || loc->shlib_disabled
1779 + || !breakpoint_address_is_meaningful (b))
1782 + /* Permanent breakpoint should always be inserted. */
1783 + if (b->enable_state == bp_permanent && ! loc->inserted)
1784 + internal_error (__FILE__, __LINE__,
1785 + _("allegedly permanent breakpoint is not "
1786 + "actually inserted"));
1788 + if (loc_first == NULL
1789 + /* address / overlay match */
1790 + || loc->address != loc_first->address
1791 + || (overlay_debugging && loc->section != loc_first->section))
1794 + loc->duplicate = 0;
1798 + loc->duplicate = 1;
1800 + if (loc_first->owner->enable_state == bp_permanent && loc->inserted
1801 + && b->enable_state != bp_permanent)
1802 + internal_error (__FILE__, __LINE__,
1803 + _("another breakpoint was inserted on top of "
1804 + "a permanent breakpoint"));
1807 if (breakpoints_always_inserted_mode () && should_insert
1808 @@ -8083,6 +8335,7 @@ delete_command (char *arg, int from_tty)
1809 && b->type != bp_thread_event
1810 && b->type != bp_overlay_event
1811 && b->type != bp_longjmp_master
1812 + && b->type != bp_exception_master
1815 breaks_to_delete = 1;
1816 @@ -8102,6 +8355,7 @@ delete_command (char *arg, int from_tty)
1817 && b->type != bp_jit_event
1818 && b->type != bp_overlay_event
1819 && b->type != bp_longjmp_master
1820 + && b->type != bp_exception_master
1822 delete_breakpoint (b);
1824 @@ -8404,6 +8658,7 @@ breakpoint_re_set_one (void *bint)
1825 reset later by breakpoint_re_set. */
1826 case bp_overlay_event:
1827 case bp_longjmp_master:
1828 + case bp_exception_master:
1829 delete_breakpoint (b);
1832 @@ -8427,6 +8682,8 @@ breakpoint_re_set_one (void *bint)
1834 case bp_longjmp_resume:
1836 + case bp_exception:
1837 + case bp_exception_resume:
1841 @@ -8462,6 +8719,7 @@ breakpoint_re_set (void)
1842 create_longjmp_master_breakpoint ("_longjmp");
1843 create_longjmp_master_breakpoint ("siglongjmp");
1844 create_longjmp_master_breakpoint ("_siglongjmp");
1845 + create_exception_master_breakpoint ();
1848 /* Reset the thread number of this breakpoint:
1849 @@ -9327,6 +9585,22 @@ all_tracepoints ()
1853 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
1856 +breakpoint_types_mark_used (void)
1858 + struct breakpoint *b;
1860 + ALL_BREAKPOINTS (b)
1863 + exp_types_mark_used (b->exp);
1865 + type_mark_used (value_type (b->val));
1870 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
1871 It is defined as a macro to prevent duplication.
1872 @@ -9850,4 +10124,5 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
1873 automatic_hardware_breakpoints = 1;
1875 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
1876 + observer_attach_mark_used (breakpoint_types_mark_used);
1878 diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
1879 index ba499c6..80f702f 100644
1880 --- a/gdb/breakpoint.h
1881 +++ b/gdb/breakpoint.h
1882 @@ -56,6 +56,13 @@ enum bptype
1883 bp_longjmp, /* secret breakpoint to find longjmp() */
1884 bp_longjmp_resume, /* secret breakpoint to escape longjmp() */
1886 + /* An internal breakpoint that is installed on the unwinder's
1889 + /* An internal breakpoint that is set at the point where an
1890 + exception will land. */
1891 + bp_exception_resume,
1893 /* Used by wait_for_inferior for stepping over subroutine calls, for
1894 stepping over signal handlers, and for skipping prologues. */
1896 @@ -118,6 +125,9 @@ enum bptype
1900 + /* Like bp_longjmp_master, but for exceptions. */
1901 + bp_exception_master,
1906 @@ -228,10 +238,6 @@ struct bp_location
1907 the same parent breakpoint. */
1908 struct bp_location *next;
1910 - /* Pointer to the next breakpoint location, in a global
1911 - list of all breakpoint locations. */
1912 - struct bp_location *global_next;
1914 /* Type of this breakpoint location. */
1915 enum bp_loc_type loc_type;
1917 @@ -583,6 +589,10 @@ struct bpstat_what
1918 continuing from a call dummy without popping the frame is not a
1922 + /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME. True if we are
1923 + handling a longjmp, false if we are handling an exception. */
1927 /* The possible return values for print_bpstat, print_it_normal,
1928 @@ -946,6 +956,9 @@ extern int catching_syscall_number (int syscall_number);
1929 /* Tell a breakpoint to be quiet. */
1930 extern void make_breakpoint_silent (struct breakpoint *);
1932 +/* Set break condition of breakpoint B to EXP. */
1933 +extern void set_breakpoint_condition (struct breakpoint *b, char *exp, int from_tty);
1935 /* Return a tracepoint with the given number if found. */
1936 extern struct breakpoint *get_tracepoint (int num);
1938 diff --git a/gdb/c-exp.y b/gdb/c-exp.y
1939 index f8e4f12..5b47e2e 100644
1942 @@ -117,6 +117,8 @@ static int yylex (void);
1944 void yyerror (char *);
1946 +/* Cleanup for 'nonempty_typelist' */
1947 +static struct cleanup *typelist_cleanup;
1950 /* Although the yacc "value" of an expression is not used,
1951 @@ -157,6 +159,7 @@ void yyerror (char *);
1953 /* YYSTYPE gets defined by %union */
1954 static int parse_number (char *, int, int, YYSTYPE *);
1955 +static struct stoken operator_stoken (const char *);
1958 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
1959 @@ -199,9 +202,12 @@ static int parse_number (char *, int, int, YYSTYPE *);
1961 %token <ssym> NAME_OR_INT
1964 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
1968 +%type <sval> operator
1970 /* Special type cases, put in to allow the parser to distinguish different
1972 @@ -401,6 +407,36 @@ arglist : arglist ',' exp %prec ABOVE_COMMA
1976 +exp : exp '(' nonempty_typelist ')' const_or_volatile
1978 + write_exp_elt_opcode (TYPE_INSTANCE);
1979 + write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
1980 + for (i = 0; i < $<ivec>3[0]; ++i)
1981 + write_exp_elt_type ($<tvec>3[i + 1]);
1982 + write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
1983 + write_exp_elt_opcode (TYPE_INSTANCE);
1984 + do_cleanups (typelist_cleanup);
1989 +exp : BLOCKNAME '(' nonempty_typelist ')'
1991 + write_exp_elt_opcode (TYPE_INSTANCE_LOOKUP);
1992 + write_exp_elt_sym ($1.sym);
1993 + write_exp_elt_opcode (TYPE_INSTANCE_LOOKUP);
1995 + write_exp_elt_opcode (TYPE_INSTANCE);
1996 + write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
1997 + for (i = 0; i < $<ivec>3[0]; ++i)
1998 + write_exp_elt_type ($<tvec>3[i + 1]);
1999 + write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
2000 + write_exp_elt_opcode (TYPE_INSTANCE);
2001 + do_cleanups (typelist_cleanup);
2007 { $$ = end_arglist () - 1; }
2009 @@ -703,6 +739,7 @@ variable: block COLONCOLON name
2010 qualified_name: typebase COLONCOLON name
2012 struct type *type = $1;
2013 + CHECK_TYPEDEF (type);
2014 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2015 && TYPE_CODE (type) != TYPE_CODE_UNION
2016 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2017 @@ -718,6 +755,7 @@ qualified_name: typebase COLONCOLON name
2019 struct type *type = $1;
2020 struct stoken tmp_token;
2021 + CHECK_TYPEDEF (type);
2022 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2023 && TYPE_CODE (type) != TYPE_CODE_UNION
2024 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2025 @@ -740,12 +778,13 @@ qualified_name: typebase COLONCOLON name
2028 variable: qualified_name
2029 + | COLONCOLON qualified_name
2032 char *name = copy_name ($2);
2034 struct minimal_symbol *msymbol;
2038 lookup_symbol (name, (const struct block *) NULL,
2039 VAR_DOMAIN, (int *) NULL);
2040 @@ -883,7 +922,7 @@ array_mod: '[' ']'
2043 | '(' nonempty_typelist ')'
2044 - { free ($2); $$ = 0; }
2045 + { do_cleanups (typelist_cleanup); $$ = 0; }
2048 /* We used to try to recognize pointer to member types here, but
2049 @@ -1088,12 +1127,15 @@ typename: TYPENAME
2052 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
2053 + typelist_cleanup = make_cleanup (free, $$);
2054 $<ivec>$[0] = 1; /* Number of types in vector */
2057 | nonempty_typelist ',' type
2058 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
2059 $$ = (struct type **) realloc ((char *) $1, len);
2060 + discard_cleanups (typelist_cleanup);
2061 + typelist_cleanup = make_cleanup (free, $$);
2062 $$[$<ivec>$[0]] = $3;
2065 @@ -1117,10 +1159,135 @@ const_or_volatile_noopt: const_and_volatile
2066 { push_type (tp_volatile); }
2069 +operator: OPERATOR NEW
2070 + { $$ = operator_stoken (" new"); }
2072 + { $$ = operator_stoken (" delete"); }
2073 + | OPERATOR NEW '[' ']'
2074 + { $$ = operator_stoken (" new[]"); }
2075 + | OPERATOR DELETE '[' ']'
2076 + { $$ = operator_stoken (" delete[]"); }
2078 + { $$ = operator_stoken ("+"); }
2080 + { $$ = operator_stoken ("-"); }
2082 + { $$ = operator_stoken ("*"); }
2084 + { $$ = operator_stoken ("/"); }
2086 + { $$ = operator_stoken ("%"); }
2088 + { $$ = operator_stoken ("^"); }
2090 + { $$ = operator_stoken ("&"); }
2092 + { $$ = operator_stoken ("|"); }
2094 + { $$ = operator_stoken ("~"); }
2096 + { $$ = operator_stoken ("!"); }
2098 + { $$ = operator_stoken ("="); }
2100 + { $$ = operator_stoken ("<"); }
2102 + { $$ = operator_stoken (">"); }
2103 + | OPERATOR ASSIGN_MODIFY
2104 + { const char *op = "unknown";
2128 + case BINOP_BITWISE_IOR:
2131 + case BINOP_BITWISE_AND:
2134 + case BINOP_BITWISE_XOR:
2141 + $$ = operator_stoken (op);
2144 + { $$ = operator_stoken ("<<"); }
2146 + { $$ = operator_stoken (">>"); }
2148 + { $$ = operator_stoken ("=="); }
2149 + | OPERATOR NOTEQUAL
2150 + { $$ = operator_stoken ("!="); }
2152 + { $$ = operator_stoken ("<="); }
2154 + { $$ = operator_stoken (">="); }
2156 + { $$ = operator_stoken ("&&"); }
2158 + { $$ = operator_stoken ("||"); }
2159 + | OPERATOR INCREMENT
2160 + { $$ = operator_stoken ("++"); }
2161 + | OPERATOR DECREMENT
2162 + { $$ = operator_stoken ("--"); }
2164 + { $$ = operator_stoken (","); }
2165 + | OPERATOR ARROW_STAR
2166 + { $$ = operator_stoken ("->*"); }
2168 + { $$ = operator_stoken ("->"); }
2169 + | OPERATOR '(' ')'
2170 + { $$ = operator_stoken ("()"); }
2171 + | OPERATOR '[' ']'
2172 + { $$ = operator_stoken ("[]"); }
2174 + { char *name, *canon;
2176 + struct ui_file *buf = mem_fileopen ();
2178 + c_print_type ($2, NULL, buf, -1, 0);
2179 + name = ui_file_xstrdup (buf, &length);
2180 + canon = cp_canonicalize_string (name);
2181 + if (canon != NULL)
2186 + ui_file_delete (buf);
2187 + $$ = operator_stoken (name);
2193 name : NAME { $$ = $1.stoken; }
2194 | BLOCKNAME { $$ = $1.stoken; }
2195 | TYPENAME { $$ = $1.stoken; }
2196 | NAME_OR_INT { $$ = $1.stoken; }
2197 + | operator { $$ = $1; }
2200 name_not_typename : NAME
2201 @@ -1136,6 +1303,20 @@ name_not_typename : NAME
2205 +/* Returns a stoken of the operator name given by OP (which does not
2206 + include the string "operator"). The result is xmalloc'd. */
2207 +static struct stoken
2208 +operator_stoken (const char *op)
2210 + static const char *operator_string = "operator";
2211 + struct stoken st = { NULL, 0 };
2212 + st.length = strlen (operator_string) + strlen (op);
2213 + st.ptr = xmalloc (st.length + 1);
2214 + strcpy (st.ptr, operator_string);
2215 + strcat (st.ptr, op);
2219 /* Take care of parsing a number (anything that starts with a digit).
2220 Set yylval and return the token type; update lexptr.
2221 LEN is the number of characters in it. */
2222 @@ -1714,6 +1895,9 @@ static const struct token ident_tokens[] =
2223 {"long", LONG, OP_NULL, 0},
2224 {"true", TRUEKEYWORD, OP_NULL, 1},
2225 {"int", INT_KEYWORD, OP_NULL, 0},
2226 + {"new", NEW, OP_NULL, 1},
2227 + {"delete", DELETE, OP_NULL, 1},
2228 + {"operator", OPERATOR, OP_NULL, 1},
2230 {"and", ANDAND, BINOP_END, 1},
2231 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
2232 @@ -1822,6 +2006,13 @@ static int last_was_structop;
2236 + /* name_prefix stores the full qualification of a variable that is
2237 + specified in the expression. It is used to eleminate confusion
2239 + static char *name_prefix = NULL;
2240 + static int name_prefix_len = 0;
2241 + static int terminate_prefix = 0;
2246 @@ -1830,9 +2021,19 @@ yylex (void)
2249 last_was_structop = 0;
2255 + if (terminate_prefix
2256 + || lexptr != name_prefix + name_prefix_len)
2258 + /* Some token was skipped, so clear name_prefix. */
2259 + name_prefix = NULL;
2260 + name_prefix_len = 0;
2263 + terminate_prefix = 1;
2265 /* Check if this is a macro invocation that we need to expand. */
2266 if (! scanning_macro_expansion ())
2268 @@ -1868,10 +2069,19 @@ yylex (void)
2269 && parse_language->la_language != language_cplus)
2272 + if (tokentab2[i].token == COLONCOLON)
2274 + name_prefix_len += 2;
2275 + terminate_prefix = 0;
2276 + if (name_prefix == NULL)
2277 + name_prefix = lexptr;
2281 yylval.opcode = tokentab2[i].opcode;
2282 if (in_parse_field && tokentab2[i].token == ARROW)
2283 last_was_structop = 1;
2285 return tokentab2[i].token;
2288 @@ -1900,6 +2110,8 @@ yylex (void)
2292 + name_prefix_len++;
2293 + terminate_prefix = 0;
2297 @@ -2057,11 +2269,13 @@ yylex (void)
2298 error ("Invalid character '%c' in expression.", c);
2300 /* It's a name. See how long it is. */
2303 for (c = tokstart[namelen];
2304 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2305 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2308 /* Template parameter lists are part of the name.
2309 FIXME: This mishandles `print $a<4&&$a>3'. */
2311 @@ -2125,14 +2339,29 @@ yylex (void)
2312 currently as names of types; NAME for other symbols.
2313 The caller is not constrained to care about the distinction. */
2317 int is_a_field_of_this = 0;
2320 - sym = lookup_symbol (copy, expression_context_block,
2321 + if (name_prefix != NULL)
2322 + tmp = savestring (name_prefix, name_prefix_len+namelen);
2324 + sym = lookup_symbol (tmp, expression_context_block,
2326 parse_language->la_language == language_cplus
2327 ? &is_a_field_of_this : (int *) NULL);
2329 + /* Keep this name as the prefix for the next name. */
2332 + if (name_prefix == NULL)
2333 + name_prefix = tokstart;
2335 + name_prefix_len += namelen;
2336 + terminate_prefix = 0;
2339 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
2340 no psymtabs (coff, xcoff, or some future change to blow away the
2341 psymtabs once once symbols are read). */
2342 @@ -2191,6 +2420,7 @@ yylex (void)
2343 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2344 if (in_parse_field && *lexptr == '\0')
2345 saw_name_at_eof = 1;
2350 diff --git a/gdb/c-lang.c b/gdb/c-lang.c
2351 index d01490c..bc35a3e 100644
2354 @@ -715,7 +715,7 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
2355 If length returned from read_string was > 0, return the number of
2356 characters read by dividing the number of bytes by width. */
2358 - *length = *length / width;
2359 + *length = *length / width;
2361 *charset = target_charset ();
2363 @@ -1038,6 +1038,9 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
2364 return evaluate_subexp_standard (expect_type, exp, pos, noside);
2368 +/* Preprocessing and parsing C and C++ expressions. */
2372 /* Table mapping opcodes into strings for printing operators
2373 @@ -1138,6 +1141,7 @@ static const struct exp_descriptor exp_descriptor_c =
2375 print_subexp_standard,
2376 operator_length_standard,
2377 + operator_check_standard,
2379 dump_subexp_body_standard,
2381 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
2382 index b193080..04cf3bc 100644
2383 --- a/gdb/c-typeprint.c
2384 +++ b/gdb/c-typeprint.c
2387 #include "typeprint.h"
2389 +#include "jv-lang.h"
2391 #include "gdb_string.h"
2393 @@ -40,8 +41,6 @@ static void cp_type_print_method_args (struct type *mtype, char *prefix,
2394 char *varstring, int staticp,
2395 struct ui_file *stream);
2397 -static void c_type_print_args (struct type *, struct ui_file *);
2399 static void cp_type_print_derivation_info (struct ui_file *, struct type *);
2401 static void c_type_print_varspec_prefix (struct type *, struct ui_file *, int,
2402 @@ -199,6 +198,23 @@ cp_type_print_method_args (struct type *mtype, char *prefix, char *varstring,
2403 fprintf_filtered (stream, "void");
2405 fprintf_filtered (stream, ")");
2407 + /* For non-static methods, read qualifiers from the type of
2411 + struct type *domain;
2413 + gdb_assert (nargs > 0);
2414 + gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
2415 + domain = TYPE_TARGET_TYPE (args[0].type);
2417 + if (TYPE_CONST (domain))
2418 + fprintf_filtered (stream, " const");
2420 + if (TYPE_VOLATILE (domain))
2421 + fprintf_filtered (stream, " volatile");
2426 @@ -355,10 +371,14 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
2428 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
2429 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
2430 - in non-static methods, are displayed. */
2431 + in non-static methods, are displayed if SHOW_ARTIFICIAL is
2432 + non-zero. LANGUAGE is the language in which TYPE was defined. This is
2433 + a necessary evil since this code is used by the C, C++, and Java
2437 -c_type_print_args (struct type *type, struct ui_file *stream)
2439 +c_type_print_args (struct type *type, struct ui_file *stream,
2440 + int show_artificial, enum language language)
2444 @@ -370,13 +390,19 @@ c_type_print_args (struct type *type, struct ui_file *stream)
2446 for (i = 0; i < TYPE_NFIELDS (type); i++)
2448 + if (TYPE_FIELD_ARTIFICIAL (type, i) && !show_artificial)
2453 fprintf_filtered (stream, ", ");
2457 - c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2458 + if (language == language_java)
2459 + java_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2461 + c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2465 @@ -560,7 +586,12 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2466 fprintf_filtered (stream, ")");
2468 fprintf_filtered (stream, "[");
2469 - if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
2470 + if (TYPE_ARRAY_BOUND_IS_DWARF_BLOCK (type, 1))
2472 + /* No _() - printed sources should not be locale dependent. */
2473 + fprintf_filtered (stream, "variable");
2475 + else if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
2476 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2477 fprintf_filtered (stream, "%d",
2479 @@ -593,7 +624,7 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2481 fprintf_filtered (stream, ")");
2482 if (!demangled_args)
2483 - c_type_print_args (type, stream);
2484 + c_type_print_args (type, stream, 1, language_c);
2485 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
2488 diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
2489 index ce7c2a6..6380fec 100644
2490 --- a/gdb/cli/cli-cmds.c
2491 +++ b/gdb/cli/cli-cmds.c
2493 #include "cli/cli-setshow.h"
2494 #include "cli/cli-cmds.h"
2496 +#include "python/python.h"
2499 #include "tui/tui.h" /* For tui_active et.al. */
2501 @@ -183,6 +185,7 @@ struct cmd_list_element *showchecklist;
2503 /* Command tracing state. */
2505 +static int source_python = 0;
2506 int source_verbose = 0;
2507 int trace_commands = 0;
2509 @@ -444,6 +447,7 @@ source_script (char *file, int from_tty)
2510 struct cleanup *old_cleanups;
2511 char *full_pathname = NULL;
2515 if (file == NULL || *file == 0)
2517 @@ -476,8 +480,16 @@ source_script (char *file, int from_tty)
2521 + is_python = source_python;
2522 + if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
2525 stream = fdopen (fd, FOPEN_RT);
2526 - script_from_file (stream, file);
2529 + source_python_script (stream, file);
2531 + script_from_file (stream, file);
2533 do_cleanups (old_cleanups);
2535 @@ -491,15 +503,30 @@ source_verbose_cleanup (void *old_value)
2539 +/* A helper for source_command. Look for an argument in *ARGS.
2540 + Update *ARGS by stripping leading whitespace. If an argument is
2541 + found, return it (a character). Otherwise, return 0. */
2543 +find_argument (char **args)
2546 + while (isspace ((*args)[0]))
2548 + if ((*args)[0] == '-' && isalpha ((*args)[1]))
2550 + result = (*args)[1];
2557 source_command (char *args, int from_tty)
2559 struct cleanup *old_cleanups;
2560 - char *file = args;
2561 - int *old_source_verbose = xmalloc (sizeof(int));
2563 - *old_source_verbose = source_verbose;
2564 - old_cleanups = make_cleanup (source_verbose_cleanup, old_source_verbose);
2565 + old_cleanups = make_cleanup_restore_integer (&source_verbose);
2566 + make_cleanup_restore_integer (&source_python);
2568 /* -v causes the source command to run in verbose mode.
2569 We still have to be able to handle filenames with spaces in a
2570 @@ -507,23 +534,28 @@ source_command (char *args, int from_tty)
2574 - /* Make sure leading white space does not break the comparisons. */
2575 - while (isspace(args[0]))
2578 - /* Is -v the first thing in the string? */
2579 - if (args[0] == '-' && args[1] == 'v' && isspace (args[2]))
2582 - source_verbose = 1;
2584 - /* Trim -v and whitespace from the filename. */
2586 - while (isspace (file[0]))
2588 + int arg = find_argument (&args);
2594 + source_verbose = 1;
2597 + source_python = 1;
2600 + error (_("unrecognized option -%c"), arg);
2605 - source_script (file, from_tty);
2606 + source_script (args, from_tty);
2608 + do_cleanups (old_cleanups);
2612 @@ -1307,7 +1339,9 @@ Read commands from a file named FILE.\n\
2613 Optional -v switch (before the filename) causes each command in\n\
2614 FILE to be echoed as it is executed.\n\
2615 Note that the file \"%s\" is read automatically in this way\n\
2616 -when GDB is started."), gdbinit);
2617 +when GDB is started.\n\
2618 +Optional -p switch (before the filename) causes FILE to be evaluated\n\
2619 +as Python code."), gdbinit);
2620 c = add_cmd ("source", class_support, source_command,
2621 source_help_text, &cmdlist);
2622 set_cmd_completer (c, filename_completer);
2623 diff --git a/gdb/coffread.c b/gdb/coffread.c
2624 index 888f8b4..65494b8 100644
2625 --- a/gdb/coffread.c
2626 +++ b/gdb/coffread.c
2627 @@ -346,7 +346,7 @@ coff_alloc_type (int index)
2628 We will fill it in later if we find out how. */
2631 - type = alloc_type (current_objfile);
2632 + type = alloc_type (current_objfile, NULL);
2636 @@ -2121,6 +2121,7 @@ static struct sym_fns coff_sym_fns =
2637 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2638 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2639 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2640 + NULL, /* sym_read_psymbols */
2641 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2642 default_symfile_offsets, /* sym_offsets: xlate external to internal form */
2643 default_symfile_segments, /* sym_segments: Get segment information from
2644 diff --git a/gdb/config.in b/gdb/config.in
2645 index 4716524..0745c65 100644
2649 language is requested. */
2652 -/* look for global separate data files in this path [DATADIR/gdb] */
2653 +/* Global directory for GDB data files. */
2656 -/* Define if the gdb-datadir directory should be relocated when GDB is moved.
2658 +/* Define if GDB datadir should be relocated when GDB is moved. */
2659 #undef GDB_DATADIR_RELOCATABLE
2661 /* Define to be a string naming the default host character set. */
2664 #undef PTRDIFF_T_SUFFIX
2666 +/* Define to install path for Python sources */
2669 /* Relocated directory for source files. */
2672 diff --git a/gdb/config/i386/nm-i386.h b/gdb/config/i386/nm-i386.h
2673 new file mode 100644
2674 index 0000000..5f237cc
2676 +++ b/gdb/config/i386/nm-i386.h
2678 +/* Native macro definitions for GDB on an Intel i[3456]86.
2679 + Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
2681 + This file is part of GDB.
2683 + This program is free software; you can redistribute it and/or modify
2684 + it under the terms of the GNU General Public License as published by
2685 + the Free Software Foundation; either version 3 of the License, or
2686 + (at your option) any later version.
2688 + This program is distributed in the hope that it will be useful,
2689 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2690 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2691 + GNU General Public License for more details.
2693 + You should have received a copy of the GNU General Public License
2694 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
2697 +#define NM_I386_H 1
2699 +/* Hardware-assisted breakpoints and watchpoints. */
2701 +/* Targets should define this to use the generic x86 watchpoint support. */
2702 +#ifdef I386_USE_GENERIC_WATCHPOINTS
2704 +/* Add watchpoint methods to the provided target_ops. Targets which call
2705 + this should also define I386_WATCHPOINTS_IN_TARGET_VECTOR. */
2707 +void i386_use_watchpoints (struct target_ops *);
2709 +/* Clear the reference counts and forget everything we knew about DRi. */
2710 +extern void i386_cleanup_dregs (void);
2712 +/* Insert a watchpoint to watch a memory region which starts at
2713 + address ADDR and whose length is LEN bytes. Watch memory accesses
2714 + of the type TYPE. Return 0 on success, -1 on failure. */
2715 +extern int i386_insert_watchpoint (CORE_ADDR addr, int len, int type);
2717 +/* Remove a watchpoint that watched the memory region which starts at
2718 + address ADDR, whose length is LEN bytes, and for accesses of the
2719 + type TYPE. Return 0 on success, -1 on failure. */
2720 +extern int i386_remove_watchpoint (CORE_ADDR addr, int len, int type);
2722 +/* Return non-zero if we can watch a memory region that starts at
2723 + address ADDR and whose length is LEN bytes. */
2724 +extern int i386_region_ok_for_watchpoint (CORE_ADDR addr, int len);
2726 +/* Return non-zero if the inferior has some break/watchpoint that
2728 +extern int i386_stopped_by_hwbp (void);
2730 +/* If the inferior has some break/watchpoint that triggered, set
2731 + the address associated with that break/watchpoint and return
2732 + true. Otherwise, return false. */
2733 +extern int i386_stopped_data_address (struct target_ops *, CORE_ADDR *);
2735 +/* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
2736 + Return 0 on success, EBUSY on failure. */
2737 +struct bp_target_info;
2738 +extern int i386_insert_hw_breakpoint (struct bp_target_info *bp_tgt);
2740 +/* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
2741 + Return 0 on success, -1 on failure. */
2742 +extern int i386_remove_hw_breakpoint (struct bp_target_info *bp_tgt);
2744 +extern int i386_stopped_by_watchpoint (void);
2746 +#ifndef I386_WATCHPOINTS_IN_TARGET_VECTOR
2748 +/* Returns the number of hardware watchpoints of type TYPE that we can
2749 + set. Value is positive if we can set CNT watchpoints, zero if
2750 + setting watchpoints of type TYPE is not supported, and negative if
2751 + CNT is more than the maximum number of watchpoints of type TYPE
2752 + that we can support. TYPE is one of bp_hardware_watchpoint,
2753 + bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
2754 + CNT is the number of such watchpoints used so far (including this
2755 + one). OTHERTYPE is non-zero if other types of watchpoints are
2756 + currently enabled.
2758 + We always return 1 here because we don't have enough information
2759 + about possible overlap of addresses that they want to watch. As an
2760 + extreme example, consider the case where all the watchpoints watch
2761 + the same address and the same region length: then we can handle a
2762 + virtually unlimited number of watchpoints, due to debug register
2763 + sharing implemented via reference counts in i386-nat.c. */
2765 +#define TARGET_CAN_USE_HARDWARE_WATCHPOINT(type, cnt, ot) 1
2767 +/* Returns non-zero if we can use hardware watchpoints to watch a
2768 + region whose address is ADDR and whose length is LEN. */
2770 +#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(addr, len) \
2771 + i386_region_ok_for_watchpoint (addr, len)
2773 +/* After a watchpoint trap, the PC points to the instruction after the
2774 + one that caused the trap. Therefore we don't need to step over it.
2775 + But we do need to reset the status register to avoid another trap. */
2777 +#define HAVE_CONTINUABLE_WATCHPOINT 1
2779 +#define STOPPED_BY_WATCHPOINT(W) (i386_stopped_by_watchpoint () != 0)
2781 +#define target_stopped_data_address(target, x) \
2782 + i386_stopped_data_address(target, x)
2784 +/* Use these macros for watchpoint insertion/removal. */
2786 +#define target_insert_watchpoint(addr, len, type) \
2787 + i386_insert_watchpoint (addr, len, type)
2789 +#define target_remove_watchpoint(addr, len, type) \
2790 + i386_remove_watchpoint (addr, len, type)
2792 +#define target_insert_hw_breakpoint(bp_tgt) \
2793 + i386_insert_hw_breakpoint (bp_tgt)
2795 +#define target_remove_hw_breakpoint(bp_tgt) \
2796 + i386_remove_hw_breakpoint (bp_tgt)
2798 +#endif /* I386_WATCHPOINTS_IN_TARGET_VECTOR */
2800 +#endif /* I386_USE_GENERIC_WATCHPOINTS */
2802 +#endif /* NM_I386_H */
2803 diff --git a/gdb/config/i386/nm-linux64.h b/gdb/config/i386/nm-linux64.h
2804 new file mode 100644
2805 index 0000000..19d710a
2807 +++ b/gdb/config/i386/nm-linux64.h
2809 +/* Native support for GNU/Linux x86-64.
2811 + Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
2812 + Free Software Foundation, Inc.
2814 + Contributed by Jiri Smid, SuSE Labs.
2816 + This file is part of GDB.
2818 + This program is free software; you can redistribute it and/or modify
2819 + it under the terms of the GNU General Public License as published by
2820 + the Free Software Foundation; either version 3 of the License, or
2821 + (at your option) any later version.
2823 + This program is distributed in the hope that it will be useful,
2824 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2825 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2826 + GNU General Public License for more details.
2828 + You should have received a copy of the GNU General Public License
2829 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
2831 +#ifndef NM_LINUX64_H
2832 +#define NM_LINUX64_H
2834 +/* GNU/Linux supports the i386 hardware debugging registers. */
2835 +#define I386_USE_GENERIC_WATCHPOINTS
2836 +#define I386_WATCHPOINTS_IN_TARGET_VECTOR
2838 +#include "i386/nm-i386.h"
2839 +#include "config/nm-linux.h"
2841 +/* Support for 8-byte wide hardware watchpoints. */
2842 +#define TARGET_HAS_DR_LEN_8 1
2844 +/* Provide access to the i386 hardware debugging registers. */
2846 +extern void amd64_linux_dr_set_control (unsigned long control);
2847 +#define I386_DR_LOW_SET_CONTROL(control) \
2848 + amd64_linux_dr_set_control (control)
2850 +extern void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr);
2851 +#define I386_DR_LOW_SET_ADDR(regnum, addr) \
2852 + amd64_linux_dr_set_addr (regnum, addr)
2854 +extern void amd64_linux_dr_reset_addr (int regnum);
2855 +#define I386_DR_LOW_RESET_ADDR(regnum) \
2856 + amd64_linux_dr_reset_addr (regnum)
2858 +extern unsigned long amd64_linux_dr_get_status (void);
2859 +#define I386_DR_LOW_GET_STATUS() \
2860 + amd64_linux_dr_get_status ()
2862 +#endif /* nm-linux64.h */
2863 diff --git a/gdb/config/mips/nm-irix5.h b/gdb/config/mips/nm-irix5.h
2864 new file mode 100644
2865 index 0000000..49ac420
2867 +++ b/gdb/config/mips/nm-irix5.h
2869 +/* Definitions for native support of irix5.
2871 + Copyright 1993, 1996, 1998, 1999, 2000, 2007, 2008, 2009
2872 + Free Software Foundation, Inc.
2874 + This file is part of GDB.
2876 + This program is free software; you can redistribute it and/or modify
2877 + it under the terms of the GNU General Public License as published by
2878 + the Free Software Foundation; either version 3 of the License, or
2879 + (at your option) any later version.
2881 + This program is distributed in the hope that it will be useful,
2882 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2883 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2884 + GNU General Public License for more details.
2886 + You should have received a copy of the GNU General Public License
2887 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
2889 +#define TARGET_HAS_HARDWARE_WATCHPOINTS
2891 +/* TARGET_CAN_USE_HARDWARE_WATCHPOINT is now defined to go through
2892 + the target vector. For Irix5, procfs_can_use_hw_watchpoint()
2893 + should be invoked. */
2895 +/* When a hardware watchpoint fires off the PC will be left at the
2896 + instruction which caused the watchpoint. It will be necessary for
2897 + GDB to step over the watchpoint. */
2899 +#define STOPPED_BY_WATCHPOINT(W) \
2900 + procfs_stopped_by_watchpoint(inferior_ptid)
2901 +extern int procfs_stopped_by_watchpoint (ptid_t);
2903 +/* Use these macros for watchpoint insertion/deletion. */
2904 +/* type can be 0: write watch, 1: read watch, 2: access watch (read/write) */
2905 +#define target_insert_watchpoint(ADDR, LEN, TYPE) \
2906 + procfs_set_watchpoint (inferior_ptid, ADDR, LEN, TYPE, 0)
2907 +#define target_remove_watchpoint(ADDR, LEN, TYPE) \
2908 + procfs_set_watchpoint (inferior_ptid, ADDR, 0, 0, 0)
2909 +extern int procfs_set_watchpoint (ptid_t, CORE_ADDR, int, int, int);
2911 +#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(SIZE) 1
2913 diff --git a/gdb/configure b/gdb/configure
2914 index 46e7bfe..ea667f0 100755
2917 @@ -676,6 +676,8 @@ REPORT_BUGS_TO
2926 @@ -883,6 +885,7 @@ enable_dependency_tracking
2927 with_separate_debug_dir
2929 with_relocated_sources
2934 @@ -1581,6 +1584,10 @@ Optional Packages:
2936 --with-relocated-sources=PATH
2937 automatically relocate this path for source files
2938 + --with-gdb-datadir look for global separate data files in this path
2940 + --with-pythondir install Python data files in this path
2941 + [DATADIR/gdb/python]
2942 --with-libunwind use libunwind frame unwinding support
2943 --with-curses use the curses library instead of the termcap
2945 @@ -6602,6 +6609,73 @@ _ACEOF
2949 +# GDB's datadir relocation
2951 +gdbdatadir=${datadir}/gdb
2954 +# Check whether --with-gdb-datadir was given.
2955 +if test "${with_gdb_datadir+set}" = set; then :
2956 + withval=$with_gdb_datadir; gdbdatadir="${withval}"
2961 + test "x$prefix" = xNONE && prefix="$ac_default_prefix"
2962 + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
2963 + ac_define_dir=`eval echo $gdbdatadir`
2964 + ac_define_dir=`eval echo $ac_define_dir`
2966 +cat >>confdefs.h <<_ACEOF
2967 +#define GDB_DATADIR "$ac_define_dir"
2972 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
2973 + if test "x$prefix" = xNONE; then
2974 + test_prefix=/usr/local
2976 + test_prefix=$prefix
2979 + test_prefix=$exec_prefix
2982 +case ${gdbdatadir} in
2983 + "${test_prefix}"|"${test_prefix}/"*|\
2984 + '${exec_prefix}'|'${exec_prefix}/'*)
2986 +$as_echo "#define GDB_DATADIR_RELOCATABLE 1" >>confdefs.h
2990 +GDB_DATADIR_PATH=${gdbdatadir}
2994 +# Check whether --with-pythondir was given.
2995 +if test "${with_pythondir+set}" = set; then :
2996 + withval=$with_pythondir; pythondir="${withval}"
3002 +# If the user passed in a path, define it. Otherwise, compute it at
3003 +# runtime based on the possibly-relocatable datadir.
3004 +if test "$pythondir" = "no"; then
3005 + pythondir='$(GDB_DATADIR_PATH)/python'
3008 +cat >>confdefs.h <<_ACEOF
3009 +#define PYTHONDIR "$pythondir"
3018 subdirs="$subdirs doc testsuite"
3019 @@ -9282,6 +9356,8 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
3020 CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
3021 CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
3022 CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
3023 + CONFIG_INSTALL="$CONFIG_INSTALL install-python"
3024 + CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
3025 ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
3027 # Flags needed to compile Python code (taken from python-config --cflags).
3028 diff --git a/gdb/configure.ac b/gdb/configure.ac
3029 index 0e42182..e7f97cf 100644
3030 --- a/gdb/configure.ac
3031 +++ b/gdb/configure.ac
3032 @@ -107,6 +107,51 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat
3033 [Relocated directory for source files. ])
3036 +# GDB's datadir relocation
3038 +gdbdatadir=${datadir}/gdb
3040 +AC_ARG_WITH([gdb-datadir],
3041 + [AS_HELP_STRING([--with-gdb-datadir],
3042 + [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
3044 +AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
3045 + [Global directory for GDB data files. ])
3047 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
3048 + if test "x$prefix" = xNONE; then
3049 + test_prefix=/usr/local
3051 + test_prefix=$prefix
3054 + test_prefix=$exec_prefix
3057 +case ${gdbdatadir} in
3058 + "${test_prefix}"|"${test_prefix}/"*|\
3059 + '${exec_prefix}'|'${exec_prefix}/'*)
3060 + AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
3063 +GDB_DATADIR_PATH=${gdbdatadir}
3064 +AC_SUBST(GDB_DATADIR_PATH)
3066 +AC_ARG_WITH([pythondir],
3067 + [AS_HELP_STRING([--with-pythondir],
3068 + [install Python data files in this path [DATADIR/gdb/python]])], [pythondir="${withval}"], [pythondir=no])
3070 +# If the user passed in a path, define it. Otherwise, compute it at
3071 +# runtime based on the possibly-relocatable datadir.
3072 +if test "$pythondir" = "no"; then
3073 + pythondir='$(GDB_DATADIR_PATH)/python'
3075 + AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir",
3076 + [Define to install path for Python sources])
3078 +AC_SUBST(pythondir)
3081 AC_CONFIG_SUBDIRS(doc testsuite)
3083 # Check whether to support alternative target configurations
3084 @@ -658,6 +703,8 @@ if test "${have_libpython}" = yes; then
3085 CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
3086 CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
3087 CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
3088 + CONFIG_INSTALL="$CONFIG_INSTALL install-python"
3089 + CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
3090 ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
3092 # Flags needed to compile Python code (taken from python-config --cflags).
3093 diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
3094 index 62800b8..97d587b 100644
3095 --- a/gdb/cp-name-parser.y
3096 +++ b/gdb/cp-name-parser.y
3098 /* YACC parser for C++ names, for GDB.
3100 - Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
3101 - Free Software Foundation, Inc.
3102 + Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
3104 Parts of the lexer are based on c-exp.y from GDB.
3106 @@ -389,7 +388,7 @@ function
3107 | colon_ext_only function_arglist start_opt
3108 { $$ = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, $2.comp);
3109 if ($3) $$ = fill_comp (DEMANGLE_COMPONENT_LOCAL_NAME, $$, $3); }
3112 | conversion_op_name start_opt
3114 if ($2) $$ = fill_comp (DEMANGLE_COMPONENT_LOCAL_NAME, $$, $2); }
3115 diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
3116 index d2d8f2e..db26a01 100644
3117 --- a/gdb/cp-namespace.c
3118 +++ b/gdb/cp-namespace.c
3119 @@ -36,14 +36,17 @@ static struct using_direct *cp_copy_usings (struct using_direct *using,
3120 struct obstack *obstack);
3122 static struct symbol *lookup_namespace_scope (const char *name,
3123 - const char *linkage_name,
3124 const struct block *block,
3125 const domain_enum domain,
3129 +static struct symbol *cp_lookup_symbol_in_namespace (const char *namespace,
3131 + const struct block *block,
3132 + const domain_enum domain);
3134 static struct symbol *lookup_symbol_file (const char *name,
3135 - const char *linkage_name,
3136 const struct block *block,
3137 const domain_enum domain,
3138 int anonymous_namespace);
3139 @@ -119,7 +122,7 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
3140 anonymous namespace. So add symbols in it to the
3141 namespace given by the previous component if there is
3142 one, or to the global namespace if there isn't. */
3143 - cp_add_using_directive (dest, src);
3144 + cp_add_using_directive (dest, src, "", "", 0);
3146 /* The "+ 2" is for the "::". */
3147 previous_component = next_component + 2;
3148 @@ -134,7 +137,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
3149 has already been added, don't add it twice. */
3152 -cp_add_using_directive (const char *dest, const char *src)
3153 +cp_add_using_directive (const char *dest, const char *src, const char* alias,
3154 + const char *declaration, const int line_number)
3156 struct using_direct *current;
3157 struct using_direct *new;
3158 @@ -148,7 +152,8 @@ cp_add_using_directive (const char *dest, const char *src)
3162 - using_directives = cp_add_using (dest, src, using_directives);
3163 + using_directives = cp_add_using (dest, src, alias, declaration,
3164 + line_number, using_directives);
3168 @@ -201,7 +206,10 @@ cp_is_anonymous (const char *namespace)
3171 /* Create a new struct using direct which imports the namespace SRC
3172 - into the scope DEST.
3173 + into the scope DEST. ALIAS is the name of the imported namespace
3174 + in the current scope. If ALIAS is an empty string then the
3175 + namespace is known by its original name.
3177 Set its next member in the linked list to NEXT; allocate all memory
3178 using xmalloc. It copies the strings, so NAME can be a temporary
3180 @@ -209,14 +217,21 @@ cp_is_anonymous (const char *namespace)
3181 struct using_direct *
3182 cp_add_using (const char *dest,
3184 + const char *alias,
3185 + const char *declaration,
3186 + const int line_number,
3187 struct using_direct *next)
3189 struct using_direct *retval;
3191 retval = xmalloc (sizeof (struct using_direct));
3192 - retval->import_src = savestring (src, strlen(src));
3193 - retval->import_dest = savestring (dest, strlen(dest));
3194 + retval->import_src = savestring (src, strlen (src));
3195 + retval->import_dest = savestring (dest, strlen (dest));
3196 + retval->alias = savestring (alias, strlen (alias));
3197 + retval->declaration = savestring (declaration, strlen (declaration));
3198 + retval->line_number = line_number;
3199 retval->next = next;
3200 + retval->searched = 0;
3204 @@ -241,10 +256,18 @@ cp_copy_usings (struct using_direct *using,
3206 retval->import_dest = obsavestring (using->import_dest, strlen (using->import_dest),
3208 + retval->alias = obsavestring (using->alias, strlen (using->alias),
3210 + retval->declaration = obsavestring (using->declaration, strlen (using->declaration),
3212 retval->next = cp_copy_usings (using->next, obstack);
3214 + retval->searched = using->searched;
3216 xfree (using->import_src);
3217 xfree (using->import_dest);
3218 + xfree (using->alias);
3219 + xfree (using->declaration);
3223 @@ -261,12 +284,48 @@ cp_copy_usings (struct using_direct *using,
3226 cp_lookup_symbol_nonlocal (const char *name,
3227 - const char *linkage_name,
3228 const struct block *block,
3229 const domain_enum domain)
3231 - return lookup_namespace_scope (name, linkage_name, block, domain,
3232 - block_scope (block), 0);
3233 + struct symbol *sym;
3234 + const char *scope = block_scope (block);
3236 + sym = lookup_namespace_scope (name, block, domain, scope, 0);
3240 + return cp_lookup_symbol_namespace(scope, name, block, domain);
3243 +/* Searches for NAME in the current namespace, and by applying relevant import
3244 + statements belonging to BLOCK and its parents. SCOPE is the namespace
3245 + scope of the context in which the search is being evaluated. */
3248 +cp_lookup_symbol_namespace (const char *scope,
3250 + const struct block *block,
3251 + const domain_enum domain)
3253 + struct symbol *sym;
3255 + /* First, try to find the symbol in the given namespace. */
3256 + sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
3260 + /* Search for name in namespaces imported to this and parent blocks. */
3261 + while (block != NULL)
3263 + sym = cp_lookup_symbol_imports(scope,name, block, domain,0,1);
3268 + block = BLOCK_SUPERBLOCK(block);
3274 /* Lookup NAME at namespace scope (or, in C terms, in static and
3275 @@ -284,9 +343,8 @@ cp_lookup_symbol_nonlocal (const char *name,
3276 "A::x", and if that call fails, then the first call looks for
3279 -static struct symbol *
3281 lookup_namespace_scope (const char *name,
3282 - const char *linkage_name,
3283 const struct block *block,
3284 const domain_enum domain,
3286 @@ -308,8 +366,7 @@ lookup_namespace_scope (const char *name,
3289 new_scope_len += cp_find_first_component (scope + new_scope_len);
3290 - sym = lookup_namespace_scope (name, linkage_name, block,
3291 - domain, scope, new_scope_len);
3292 + sym = lookup_namespace_scope (name, block, domain, scope, new_scope_len);
3296 @@ -320,25 +377,98 @@ lookup_namespace_scope (const char *name,
3297 namespace = alloca (scope_len + 1);
3298 strncpy (namespace, scope, scope_len);
3299 namespace[scope_len] = '\0';
3300 - return cp_lookup_symbol_namespace (namespace, name, linkage_name,
3302 + return cp_lookup_symbol_in_namespace (namespace, name,block, domain);
3305 -/* Look up NAME in the C++ namespace NAMESPACE, applying the using
3306 - directives that are active in BLOCK. Other arguments are as in
3307 +/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
3308 cp_lookup_symbol_nonlocal. */
3310 +static struct symbol *
3311 +cp_lookup_symbol_in_namespace (const char *namespace,
3313 + const struct block *block,
3314 + const domain_enum domain)
3317 + if (namespace[0] == '\0')
3319 + return lookup_symbol_file (name, block,domain, 0);
3323 + char *concatenated_name
3324 + = alloca (strlen (namespace) + 2 + strlen (name) + 1);
3325 + strcpy (concatenated_name, namespace);
3326 + strcat (concatenated_name, "::");
3327 + strcat (concatenated_name, name);
3328 + return lookup_symbol_file (concatenated_name, block, domain,
3329 + cp_is_anonymous (namespace));
3333 +/* Used for cleanups to reset the "searched" flag incase
3337 +reset_directive_searched (void *data)
3339 + struct using_direct *direct = data;
3340 + direct->searched = 0;
3343 +/* Search for NAME by applying all import statements belonging
3344 + to BLOCK which are applicable in SCOPE. If DECLARATION_ONLY the search
3345 + is restricted to using declarations.
3353 + If SEARCH_PARENTS the search will include imports which are applicable in
3354 + parents of scopes.
3358 + using namespace X;
3360 + using namespace Y;
3364 + If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X
3365 + and Y will be considered. If SEARCH_PARENTS is false only the import of Y
3369 -cp_lookup_symbol_namespace (const char *namespace,
3371 - const char *linkage_name,
3372 - const struct block *block,
3373 - const domain_enum domain)
3374 +cp_lookup_symbol_imports (const char *scope,
3376 + const struct block *block,
3377 + const domain_enum domain,
3378 + int declaration_only,
3379 + int search_parents)
3381 - const struct using_direct *current;
3382 - struct symbol *sym;
3383 + struct using_direct *current;
3384 + struct symbol *sym = NULL;
3385 + int directive_match;
3387 + struct cleanup *searched_cleanup;
3389 + if(!declaration_only)
3390 + /* First, try to find the symbol in the given namespace. */
3391 + sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
3393 - /* First, go through the using directives. If any of them add new
3397 + if (has_stack_frames ())
3398 + current_line = find_pc_line (get_frame_pc (get_selected_frame (NULL)),
3403 + /* Go through the using directives. If any of them add new
3404 names to the namespace we're searching in, see if we can find a
3405 match by applying them. */
3407 @@ -346,39 +476,78 @@ cp_lookup_symbol_namespace (const char *namespace,
3409 current = current->next)
3411 - if (strcmp (namespace, current->import_dest) == 0)
3413 + /* If the import destination is the current scope or one of its ancestors then
3414 + it is applicable. */
3415 + directive_match = search_parents ?
3416 + strncmp (scope, current->import_dest,
3417 + strlen(current->import_dest)) == 0 :
3418 + strcmp (scope, current->import_dest) == 0;
3420 + if (directive_match &&
3421 + current->line_number < current_line &&
3422 + !current->searched)
3424 - sym = cp_lookup_symbol_namespace (current->import_src,
3429 + current->searched = 1;
3430 + searched_cleanup = make_cleanup (reset_directive_searched, current);
3432 + /* If there is an import of a single declaration, compare the imported
3433 + declaration with the sought out name. If there is a match pass
3434 + current->import_src as NAMESPACE to direct the search towards the
3435 + imported namespace. */
3436 + if (strcmp ("", current->declaration) != 0)
3438 + if (strcmp (name, current->declaration) == 0)
3440 + sym = cp_lookup_symbol_in_namespace (current->import_src,
3446 + current->searched = 0;
3453 + if (declaration_only)
3455 + current->searched = 0;
3456 + discard_cleanups (searched_cleanup);
3460 + if (strcmp (name, current->alias) == 0)
3461 + /* If the import is creating an alias and the alias matches the
3462 + sought name. Pass current->inner as the NAME to direct the
3463 + search towards the aliased namespace */
3465 + sym = cp_lookup_symbol_in_namespace (scope,
3466 + current->import_src,
3469 + } else if (strcmp ("", current->alias) == 0){
3470 + /* If this import statement creates no alias, pass current->inner as
3471 + NAMESPACE to direct the search towards the imported namespace. */
3472 + sym = cp_lookup_symbol_imports (current->import_src,
3480 + current->searched = 0;
3481 + discard_cleanups (searched_cleanup);
3488 - /* We didn't find anything by applying any of the using directives
3489 - that are still applicable; so let's see if we've got a match
3490 - using the current namespace. */
3492 - if (namespace[0] == '\0')
3494 - return lookup_symbol_file (name, linkage_name, block,
3499 - char *concatenated_name
3500 - = alloca (strlen (namespace) + 2 + strlen (name) + 1);
3501 - strcpy (concatenated_name, namespace);
3502 - strcat (concatenated_name, "::");
3503 - strcat (concatenated_name, name);
3504 - sym = lookup_symbol_file (concatenated_name, linkage_name,
3506 - cp_is_anonymous (namespace));
3512 /* Look up NAME in BLOCK's static block and in global blocks. If
3513 @@ -388,17 +557,15 @@ cp_lookup_symbol_namespace (const char *namespace,
3515 static struct symbol *
3516 lookup_symbol_file (const char *name,
3517 - const char *linkage_name,
3518 const struct block *block,
3519 const domain_enum domain,
3520 int anonymous_namespace)
3522 struct symbol *sym = NULL;
3524 - sym = lookup_symbol_static (name, linkage_name, block, domain);
3525 + sym = lookup_symbol_static (name, block, domain);
3529 if (anonymous_namespace)
3531 /* Symbols defined in anonymous namespaces have external linkage
3532 @@ -408,12 +575,11 @@ lookup_symbol_file (const char *name,
3533 const struct block *global_block = block_global_block (block);
3535 if (global_block != NULL)
3536 - sym = lookup_symbol_aux_block (name, linkage_name, global_block,
3538 + sym = lookup_symbol_aux_block (name, global_block, domain);
3542 - sym = lookup_symbol_global (name, linkage_name, block, domain);
3543 + sym = lookup_symbol_global (name, block, domain);
3547 @@ -434,6 +600,7 @@ lookup_symbol_file (const char *name,
3548 sym = lookup_possible_namespace_symbol (name);
3555 @@ -461,9 +628,8 @@ cp_lookup_nested_type (struct type *parent_type,
3556 lookup_symbol_namespace works when looking them up. */
3558 const char *parent_name = TYPE_TAG_NAME (parent_type);
3559 - struct symbol *sym = cp_lookup_symbol_namespace (parent_name,
3560 + struct symbol *sym = cp_lookup_symbol_in_namespace (parent_name,
3565 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
3566 @@ -709,7 +875,7 @@ check_one_possible_namespace_symbol (const char *name, int len,
3568 memcpy (name_copy, name, len);
3569 name_copy[len] = '\0';
3570 - sym = lookup_block_symbol (block, name_copy, NULL, VAR_DOMAIN);
3571 + sym = lookup_block_symbol (block, name_copy, VAR_DOMAIN);
3575 @@ -749,7 +915,7 @@ lookup_possible_namespace_symbol (const char *name)
3578 sym = lookup_block_symbol (get_possible_namespace_block (objfile),
3579 - name, NULL, VAR_DOMAIN);
3580 + name, VAR_DOMAIN);
3584 diff --git a/gdb/cp-support.c b/gdb/cp-support.c
3585 index f12d785..23b34c1 100644
3586 --- a/gdb/cp-support.c
3587 +++ b/gdb/cp-support.c
3590 #include "complaints.h"
3591 #include "gdbtypes.h"
3592 +#include "exceptions.h"
3593 +#include "expression.h"
3596 #include "safe-ctype.h"
3598 @@ -70,6 +73,18 @@ struct cmd_list_element *maint_cplus_cmd_list = NULL;
3599 static void maint_cplus_command (char *arg, int from_tty);
3600 static void first_component_command (char *arg, int from_tty);
3602 +/* Operator validation.
3603 + NOTE: Multi-byte operators (usually the assignment variety operator)
3604 + must appear before the single byte version, i.e., "+=" before "+". */
3605 +static const char *operator_tokens[] =
3607 + "++", "+=", "+", "->*", "->", "--", "-=", "-", "*=", "*", "/=", "/",
3608 + "%=", "%", "!=", "==", "!", "&&", "<<=", "<<", ">>=", ">>",
3609 + "<=", "<", ">=", ">", "~", "&=", "&", "|=", "||", "|", "^=", "^",
3610 + "=", "()", "[]", ",", "new", "delete"
3611 + /* new[] and delete[] require special whitespace handling */
3614 /* Return 1 if STRING is clearly already in canonical form. This
3615 function is conservative; things which it does not recognize are
3616 assumed to be non-canonical, and the parser will sort them out
3617 @@ -175,7 +190,8 @@ mangled_name_to_comp (const char *mangled_name, int options,
3621 -/* Return the name of the class containing method PHYSNAME. */
3622 +/* Return the name of the class or namespace containing
3623 + function, method, or variable PHYSNAME. */
3626 cp_class_name_from_physname (const char *physname)
3627 @@ -825,9 +841,9 @@ read_in_psymtabs (const char *func_name)
3631 - if ((lookup_partial_symbol (ps, func_name, NULL, 1, VAR_DOMAIN)
3632 + if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
3634 - || (lookup_partial_symbol (ps, func_name, NULL, 0, VAR_DOMAIN)
3635 + || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
3637 psymtab_to_symtab (ps);
3639 @@ -909,6 +925,107 @@ first_component_command (char *arg, int from_tty)
3641 extern initialize_file_ftype _initialize_cp_support; /* -Wmissing-prototypes */
3643 +#define SKIP_SPACE(P) \
3646 + while (*(P) == ' ' || *(P) == '\t') \
3651 +/* Returns the length of the operator name or 0 if INPUT does not
3652 + point to a valid C++ operator. INPUT should start with "operator". */
3654 +cp_validate_operator (const char *input)
3659 + struct expression *expr;
3660 + struct value *val;
3661 + struct gdb_exception except;
3662 + struct cleanup *old_chain;
3666 + if (strncmp (p, "operator", 8) == 0)
3672 + for (i = 0; i < sizeof (operator_tokens) / sizeof (operator_tokens[0]);
3675 + int length = strlen (operator_tokens[i]);
3676 + /* By using strncmp here, we MUST have operator_tokens ordered!
3677 + See additional notes where operator_tokens is defined above. */
3678 + if (strncmp (p, operator_tokens[i], length) == 0)
3680 + const char *op = p;
3684 + if (strncmp (op, "new", 3) == 0
3685 + || strncmp (op, "delete", 6) == 0)
3688 + /* Special case: new[] and delete[]. We must be careful
3689 + to swallow whitespace before/in "[]". */
3704 + return (p - input);
3708 + /* Check input for a conversion operator. */
3710 + /* Skip past base typename */
3711 + while (*p != '*' && *p != '&' && *p != 0 && *p != ' ')
3715 + /* Add modifiers '*'/'&' */
3716 + while (*p == '*' || *p == '&')
3722 + /* Check for valid type. [Remember: input starts with
3724 + copy = savestring (input + 8, p - input - 8);
3727 + TRY_CATCH (except, RETURN_MASK_ALL)
3729 + expr = parse_expression (copy);
3730 + val = evaluate_type (expr);
3737 + if (val != NULL && value_type (val) != NULL)
3738 + return (p - input);
3745 _initialize_cp_support (void)
3747 diff --git a/gdb/cp-support.h b/gdb/cp-support.h
3748 index b5a5c5f..3f48f98 100644
3749 --- a/gdb/cp-support.h
3750 +++ b/gdb/cp-support.h
3751 @@ -38,15 +38,33 @@ struct demangle_component;
3753 /* This struct is designed to store data from using directives. It
3754 says that names from namespace IMPORT_SRC should be visible within
3755 - namespace IMPORT_DEST. IMPORT_DEST should always be a strict initial
3756 - substring of IMPORT_SRC. These form a linked list; NEXT is the next element
3758 + namespace IMPORT_DEST. IMPORT_DEST should always be a strict initial
3759 + substring of IMPORT_SRC. These form a linked list; NEXT is the next
3760 + element of the list. ALIAS is set to a non empty string if the imported
3761 + namespace has been aliased.Eg:
3764 + DECLARATION is the name of the imported declaration, if this import
3765 + statement represents one. Eg:
3767 + Where x is variable in namespace A. declaration is set to x.
3777 + char *declaration;
3781 struct using_direct *next;
3783 + /* Used during import search to temporarly mark this node as searced. */
3788 @@ -54,6 +72,7 @@ struct using_direct
3790 extern char *cp_canonicalize_string (const char *string);
3793 extern char *cp_class_name_from_physname (const char *physname);
3795 extern char *method_name_from_physname (const char *physname);
3796 @@ -72,15 +91,23 @@ extern struct symbol **make_symbol_overload_list (const char *,
3797 extern struct type *cp_lookup_rtti_type (const char *name,
3798 struct block *block);
3800 +extern int cp_validate_operator (const char *input);
3802 /* Functions/variables from cp-namespace.c. */
3804 extern int cp_is_anonymous (const char *namespace);
3806 extern void cp_add_using_directive (const char *dest,
3809 + const char *alias,
3810 + const char *declaration,
3811 + const int line_number);
3813 extern struct using_direct *cp_add_using (const char *dest,
3815 + const char *alias,
3816 + const char *declaration,
3817 + const int line_number,
3818 struct using_direct *next);
3820 extern void cp_initialize_namespace (void);
3821 @@ -97,15 +124,20 @@ extern void cp_set_block_scope (const struct symbol *symbol,
3822 extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol);
3824 extern struct symbol *cp_lookup_symbol_nonlocal (const char *name,
3825 - const char *linkage_name,
3826 const struct block *block,
3827 const domain_enum domain);
3829 +struct symbol *cp_lookup_symbol_imports (const char *scope,
3831 + const struct block *block,
3832 + const domain_enum domain,
3833 + int declaration_only,
3834 + int search_parents);
3836 extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
3838 - const char *linkage_name,
3839 - const struct block *block,
3840 - const domain_enum domain);
3842 + const struct block *block,
3843 + const domain_enum domain);
3845 extern struct type *cp_lookup_nested_type (struct type *parent_type,
3846 const char *nested_name,
3847 diff --git a/gdb/dbxread.c b/gdb/dbxread.c
3848 index 7cb016d..bb9e35a 100644
3851 @@ -3581,6 +3581,7 @@ static struct sym_fns aout_sym_fns =
3852 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
3853 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3854 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
3855 + NULL, /* sym_read_psymbols */
3856 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
3857 default_symfile_offsets, /* sym_offsets: parse user's offsets to
3859 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
3860 index 1f98fa5..9e24482 100644
3861 --- a/gdb/doc/gdb.texinfo
3862 +++ b/gdb/doc/gdb.texinfo
3863 @@ -959,8 +959,10 @@ Connect to process ID @var{number}, as with the @code{attach} command.
3864 @itemx -x @var{file}
3865 @cindex @code{--command}
3867 -Execute @value{GDBN} commands from file @var{file}. @xref{Command
3868 -Files,, Command files}.
3869 +Execute commands from file @var{file}. If @var{file} ends in
3870 +@samp{.py}, then the file is evaluated as Python code. If Python
3871 +support is not enabled in this @value{GDBN}, then an error occurs.
3872 +@xref{Command Files,, Command files}.
3874 @item -eval-command @var{command}
3875 @itemx -ex @var{command}
3876 @@ -1152,6 +1154,16 @@ for remote debugging.
3877 Run using @var{device} for your program's standard input and output.
3878 @c FIXME: kingdon thinks there is more to -tty. Investigate.
3883 +@cindex @code{--python}
3884 +Change interpretation of command line so that the argument immediately
3885 +following this switch is taken to be the name of a Python script file.
3886 +This option stops option processing; subsequent options are passed to
3887 +Python as @code{sys.argv}. This option is only available if Python
3888 +scripting support was enabled when @value{GDBN} was configured.
3890 @c resolve the situation of these eventually
3892 @cindex @code{--tui}
3893 @@ -18660,7 +18672,7 @@ command:
3896 @cindex execute commands from a file
3897 -@item source [@code{-v}] @var{filename}
3898 +@item source [@code{-v}] [@code{-p}] @var{filename}
3899 Execute the command file @var{filename}.
3902 @@ -18677,6 +18689,11 @@ If @code{-v}, for verbose mode, is given then @value{GDBN} displays
3903 each command as it is executed. The option must be given before
3904 @var{filename}, and is interpreted as part of the filename anywhere else.
3906 +If @var{filename} ends in @samp{.py}, or if @code{-p}, for Python, is
3907 +given then @value{GDBN} evaluates the contents of the file as Python
3908 +code. If Python support is not compiled in to @value{GDBN}, then an
3911 Commands that would ask for confirmation if used interactively proceed
3912 without asking when used in a command file. Many @value{GDBN} commands that
3913 normally print messages to say what they are doing omit the messages
3914 @@ -18938,8 +18955,6 @@ containing @code{end}. For example:
3917 (@value{GDBP}) python
3919 -End with a line saying just "end".
3923 @@ -18952,6 +18967,14 @@ in a Python script. This can be controlled using @code{maint set
3924 python print-stack}: if @code{on}, the default, then Python stack
3925 printing is enabled; if @code{off}, then Python stack printing is
3928 +@kindex maint set python auto-load
3929 +@item maint set python auto-load
3930 +By default, @value{GDBN} will attempt to automatically load Python
3931 +code when an object file is opened. This can be controlled using
3932 +@code{maint set python auto-load}: if @code{on}, the default, then
3933 +Python auto-loading is enabled; if @code{off}, then Python
3934 +auto-loading is disabled.
3938 @@ -18959,6 +18982,14 @@ disabled.
3940 @cindex programming in python
3942 +You can get quick online help for @value{GDBN}'s Python API by issuing
3943 +the command @w{@kbd{python help (gdb)}}.
3945 +Functions and methods which have two or more optional arguments allow
3946 +them to be specified using keyword syntax. This allows passing some
3947 +optional arguments while skipping others. Example:
3948 +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
3950 @cindex python stdout
3951 @cindex python pagination
3952 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
3953 @@ -18971,13 +19002,17 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
3954 * Basic Python:: Basic Python Functions.
3955 * Exception Handling::
3956 * Auto-loading:: Automatically loading Python code.
3957 -* Values From Inferior::
3958 +* Values From Inferior:: Python representation of values.
3959 * Types In Python:: Python representation of types.
3960 * Pretty Printing:: Pretty-printing values.
3961 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
3962 +* Inferiors In Python:: Python representation of inferiors (processes)
3963 +* Threads In Python:: Accessing inferior threads from Python.
3964 * Commands In Python:: Implementing new commands in Python.
3965 +* Parameters In Python:: Adding new @value{GDBN} parameters.
3966 * Functions In Python:: Writing new convenience functions.
3967 * Objfiles In Python:: Object files.
3968 +* Breakpoints In Python:: Manipulating breakpoints using Python.
3969 * Frames In Python:: Acessing inferior stack frames from Python.
3972 @@ -19004,6 +19039,12 @@ command as having originated from the user invoking it interactively.
3973 It must be a boolean value. If omitted, it defaults to @code{False}.
3976 +@findex gdb.breakpoints
3978 +Return a sequence holding all of @value{GDBN}'s breakpoints.
3979 +@xref{Breakpoints In Python}, for more information.
3982 @findex gdb.parameter
3983 @defun parameter parameter
3984 Return the value of a @value{GDBN} parameter. @var{parameter} is a
3985 @@ -19020,6 +19061,7 @@ a Python value of the appropriate type, and returned.
3986 @defun history number
3987 Return a value from @value{GDBN}'s value history (@pxref{Value
3988 History}). @var{number} indicates which history element to return.
3990 If @var{number} is negative, then @value{GDBN} will take its absolute value
3991 and count backward from the last element (i.e., the most recent element) to
3992 find the value to return. If @var{number} is zero, then @value{GDBN} will
3993 @@ -19031,6 +19073,28 @@ If no exception is raised, the return value is always an instance of
3994 @code{gdb.Value} (@pxref{Values From Inferior}).
3997 +@findex gdb.parse_and_eval
3998 +@defun parse_and_eval expression
3999 +Parse @var{expression} as an expression in the current language,
4000 +evaluate it, and return the result as a @code{gdb.Value}.
4001 +@var{expression} must be a string.
4004 +@findex gdb.post_event
4005 +@defun post_event event
4006 +Put @var{event}, a callable object taking no arguments, into
4007 +@value{GDBN}'s internal event queue. This callable will be invoked at
4008 +some later point, during @value{GDBN}'s event processing. Events
4009 +posted using @code{post_event} will be run in the order in which they
4010 +were posted; however, there is no way to know when they will be
4011 +processed relative to other events inside @value{GDBN}.
4013 +@value{GDBN} is not thread-safe. If your Python program uses multiple
4014 +threads, you must be careful to only call @value{GDBN}-specific
4015 +functions in the main @value{GDBN} thread. @code{post_event} ensures
4021 Print a string to @value{GDBN}'s paginated standard output stream.
4022 @@ -19045,6 +19109,11 @@ Flush @value{GDBN}'s paginated standard output stream. Flushing
4026 +@findex gdb.solib_address
4027 +@defun solib_address @var{address}
4028 +Return the name of the shared library holding the given address, or None.
4031 @node Exception Handling
4032 @subsubsection Exception Handling
4033 @cindex python exceptions
4034 @@ -19181,6 +19250,13 @@ The type of this @code{gdb.Value}. The value of this attribute is a
4035 The following methods are provided:
4038 +@defmethod Value cast type
4039 +Cast the @code{gdb.Value} to the type represented by @var{type}, and
4040 +return a new @code{gdb.Value}. @var{type} must be a @code{gdb.Type}
4041 +object. If the cast cannot be performed for some reason, an exception
4045 @defmethod Value dereference
4046 For pointer data types, this method returns a new @code{gdb.Value} object
4047 whose contents is the object pointed to by the pointer. For example, if
4048 @@ -19252,6 +19328,9 @@ module:
4049 This function looks up a type by name. @var{name} is the name of the
4050 type to look up. It must be a string.
4052 +If @var{block} is given, then @var{name} is looked up in that scope.
4053 +Otherwise, it is searched for globally.
4055 Ordinarily, this function will return an instance of @code{gdb.Type}.
4056 If the named type cannot be found, it will throw an exception.
4058 @@ -19304,6 +19383,12 @@ This is @code{True} if the field is artificial, usually meaning that
4059 it was provided by the compiler and not the user. This attribute is
4060 always provided, and is @code{False} if the field is not artificial.
4062 +@item is_base_class
4063 +This is @code{True} if the field represents a base class of a C@t{++}
4064 +structure. This attribute is always provided, and is @code{False}
4065 +if the field is not a base class of the type on which @code{fields} was
4066 +called, or if that type was not a C@t{++} class.
4069 If the field is packed, or is a bitfield, then this will have a
4070 non-zero value, which is the size of the field in bits. Otherwise,
4071 @@ -19356,7 +19441,7 @@ If the type does not have a target, this method will throw an
4075 -@defmethod Type template_argument n
4076 +@defmethod Type template_argument n [block]
4077 If this @code{gdb.Type} is an instantiation of a template, this will
4078 return a new @code{gdb.Type} which represents the type of the
4079 @var{n}th template argument.
4080 @@ -19364,7 +19449,8 @@ return a new @code{gdb.Type} which represents the type of the
4081 If this @code{gdb.Type} is not a template type, this will throw an
4082 exception. Ordinarily, only C@t{++} code will have template types.
4084 -@var{name} is searched for globally.
4085 +If @var{block} is given, then @var{name} is looked up in that scope.
4086 +Otherwise, it is searched for globally.
4090 @@ -19718,6 +19804,121 @@ import gdb.libstdcxx.v6
4091 gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
4094 +@node Inferiors In Python
4095 +@subsubsection Inferiors In Python
4097 +Programs which are being run under @value{GDBN} are called inferiors
4098 +(@pxref{Inferiors}). Python scripts can access information about and
4099 +manipulate inferiors controlled by @value{GDBN} via objects of the
4100 +@code{gdb.Inferior} class.
4102 +The following inferior-related functions are available in the @code{gdb}
4106 +Return a tuple containing all inferior objects.
4109 +A @code{gdb.Inferior} object has the following attributes:
4112 +@defivar Inferior num
4113 +ID of inferior, as assigned by GDB.
4116 +@defivar Inferior pid
4117 +Process ID of the inferior, assigned by the underlying OS.
4120 +@defivar Inferior was_attached
4121 +Boolean signaling whether the inferior was created using `attach', or
4122 +started by @value{GDBN} itself.
4126 +A @code{gdb.Inferior} object has the following methods:
4129 +@defmethod Inferior threads
4130 +This method returns a tuple holding all the threads which are valid
4131 +when it is called. If there are no valid threads, the method will
4132 +return an empty list.
4135 +@findex gdb.read_memory
4136 +@defmethod Inferior read_memory @var{address} @var{length}
4137 +Read @var{length} bytes of memory from the inferior, starting at
4138 +@var{address}. Returns a buffer object, which behaves much like an array
4139 +or a string. It can be modified and given to the @code{gdb.write_memory}
4143 +@findex gdb.write_memory
4144 +@defmethod Inferior write_memory @var{address} @var{buffer} @r{[}@var{length}@r{]}
4145 +Write the contents of @var{buffer} (a Python object which supports the
4146 +buffer protocol, i.e., a string, an array or the object returned from
4147 +@code{gdb.read_memory}) to the inferior, starting at @var{address}.
4148 +If given, @var{length} determines the number of bytes from @var{buffer} to
4152 +@findex gdb.search_memory
4153 +@defmethod Inferior search_memory @var{address} @var{length} @var{pattern} @r{[}@var{size}@r{]} @r{[}@var{max_count}@r{]}
4154 +Search a region of the inferior memory starting at @var{address} with the
4155 +given @var{length}. @var{pattern} can be a string, a byte array, a buffer
4156 +object, a number, a @code{gdb.Value} object (@pxref{Values From Inferior})
4157 +or a list or tuple with elements in any combination of those types. If
4158 +@var{size} is given and is non-zero, it specifies the size in bytes of a
4159 +Python scalar or @code{gdb.Value} in the search pattern. If @var{size} is
4160 +zero or not specified, it is taken from the value's type in the current
4161 +language. This is useful when one wants to specify the search pattern as
4162 +a mixture of types. Note that this means, for example, that in the case of
4163 +C-like languages a search for an untyped 0x42 will search for
4164 +@samp{(int) 0x42} which is typically four bytes. @var{max_count} is the
4165 +highest number of matches to search for.
4169 +@node Threads In Python
4170 +@subsubsection Threads In Python
4172 +Python scripts can access information about and manipulate inferior threads
4173 +controlled by @value{GDBN} via objects of the @code{gdb.InferiorThread} class.
4175 +The following inferior-related functions are available in the @code{gdb}
4178 +@findex gdb.selected_thread
4179 +@defun selected_thread
4180 +This function returns the thread object for the selected thread. If there
4181 +is no selected thread, this will return @code{None}.
4184 +A @code{gdb.InferiorThread} object has the following attributes:
4187 +@defivar InferiorThread num
4188 +ID of the thread, as assigned by GDB.
4192 +A @code{gdb.InferiorThread} object has the following methods:
4195 +@defmethod InferiorThread frames
4196 +Return a tuple containing all frames in the thread.
4199 +@defmethod InferiorThread newest_frame
4200 +Return the newest frame thread's stack.
4203 +@defmethod InferiorThread switch_to_thread
4204 +This changes @value{GDBN}'s currently selected thread to the one represented
4209 @node Commands In Python
4210 @subsubsection Commands In Python
4212 @@ -19970,6 +20171,135 @@ registration of the command with @value{GDBN}. Depending on how the
4213 Python code is read into @value{GDBN}, you may need to import the
4214 @code{gdb} module explicitly.
4216 +@node Parameters In Python
4217 +@subsubsection Parameters In Python
4219 +@cindex parameters in python
4220 +@cindex python parameters
4221 +@tindex gdb.Parameter
4223 +You can implement new @value{GDBN} parameters using Python. A new
4224 +parameter is implemented as an instance of the @code{gdb.Parameter}
4225 +class. Parameters are exposed to the user via the @code{set} and
4226 +@code{show} commands.
4228 +@defmethod Parameter __init__ name @var{command-class} @var{parameter-class} @r{[}@var{enum-sequence}@r{]}
4229 +The object initializer for @code{Parameter} registers the new
4230 +parameter with @value{GDBN}. This initializer is normally invoked
4231 +from the subclass' own @code{__init__} method.
4233 +@var{name} is the name of the new parameter. If @var{name} consists
4234 +of multiple words, then the initial words are looked for as prefix
4235 +commands. In this case, if one of the prefix commands does not exist,
4236 +an exception is raised.
4238 +@var{command-class} should be one of the @samp{COMMAND_} constants
4239 +(@pxref{Commands In Python}). This argument tells @value{GDBN} how to
4240 +categorize the new parameter in the help system.
4242 +@var{parameter-class} should be one of the @samp{PARAM_} constants
4243 +defined below. This argument tells @value{GDBN} the type of the new
4244 +parameter; this information is used for input validation and
4247 +If @var{parameter-class} is @code{PARAM_ENUM}, then
4248 +@var{enum-sequence} must be a sequence of strings. These strings
4249 +represent the possible values for the parameter.
4251 +If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
4252 +of a fourth argument will cause an exception to be thrown.
4254 +The help text for the new parameter is taken from the Python
4255 +documentation string for the parameter's class, if there is one. If
4256 +there is no documentation string, a default value is used.
4259 +@defivar Parameter set_doc
4260 +If this attribute exists, and is a string, then its value is used as
4261 +the help text for this parameter's @code{set} command. The value is
4262 +examined when @code{Parameter.__init__} is invoked; subsequent changes
4266 +@defivar Parameter show_doc
4267 +If this attribute exists, and is a string, then its value is used as
4268 +the help text for this parameter's @code{show} command. The value is
4269 +examined when @code{Parameter.__init__} is invoked; subsequent changes
4273 +@defivar Parameter value
4274 +The @code{value} attribute holds the underlying value of the
4275 +parameter. It can be read and assigned to just as any other
4276 +attribute. @value{GDBN} does validation when assignments are made.
4280 +When a new parameter is defined, its type must be specified. The
4281 +available types are represented by constants defined in the @code{gdb}
4285 +@findex PARAM_BOOLEAN
4286 +@findex gdb.PARAM_BOOLEAN
4287 +@item PARAM_BOOLEAN
4288 +The value is a plain boolean. The Python boolean values, @code{True}
4289 +and @code{False} are the only valid values.
4291 +@findex PARAM_AUTO_BOOLEAN
4292 +@findex gdb.PARAM_AUTO_BOOLEAN
4293 +@item PARAM_AUTO_BOOLEAN
4294 +The value has three possible states: true, false, and @samp{auto}. In
4295 +Python, true and false are represented using boolean constants, and
4296 +@samp{auto} is represented using @code{None}.
4298 +@findex PARAM_UINTEGER
4299 +@findex gdb.PARAM_UINTEGER
4300 +@item PARAM_UINTEGER
4301 +The value is an unsigned integer. The value of 0 should be
4302 +interpreted to mean ``unlimited''.
4304 +@findex PARAM_INTEGER
4305 +@findex gdb.PARAM_INTEGER
4306 +@item PARAM_INTEGER
4307 +The value is a signed integer. The value of 0 should be interpreted
4308 +to mean ``unlimited''.
4310 +@findex PARAM_STRING
4311 +@findex gdb.PARAM_STRING
4313 +The value is a string. When the user modifies the string, escapes are
4316 +@findex PARAM_STRING_NOESCAPE
4317 +@findex gdb.PARAM_STRING_NOESCAPE
4318 +@item PARAM_STRING_NOESCAPE
4319 +The value is a string. When the user modifies the string, escapes are
4320 +passed through untranslated.
4322 +@findex PARAM_OPTIONAL_FILENAME
4323 +@findex gdb.PARAM_OPTIONAL_FILENAME
4324 +@item PARAM_OPTIONAL_FILENAME
4325 +The value is a either a filename (a string), or @code{None}.
4327 +@findex PARAM_FILENAME
4328 +@findex gdb.PARAM_FILENAME
4329 +@item PARAM_FILENAME
4330 +The value is a filename (a string).
4332 +@findex PARAM_ZINTEGER
4333 +@findex gdb.PARAM_ZINTEGER
4334 +@item PARAM_ZINTEGER
4335 +The value is an integer. This is like @code{PARAM_INTEGER}, except 0
4336 +is interpreted as itself.
4339 +@findex gdb.PARAM_ENUM
4341 +The value is a string, which must be one of a collection string
4342 +constants provided when the parameter is created.
4345 @node Functions In Python
4346 @subsubsection Writing new convenience functions
4348 @@ -20074,6 +20404,82 @@ which is used to format the value. @xref{Pretty Printing}, for more
4352 +@node Breakpoints In Python
4353 +@subsubsection Manipulating breakpoints using Python
4355 +@cindex breakpoints in python
4356 +@cindex python breakpoints
4357 +@tindex gdb.Breakpoint
4359 +Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
4362 +@defmethod Breakpoint __init__ location
4363 +Create a new breakpoint. @var{location} is a string naming the
4364 +location of the breakpoint. The contents can be any location
4365 +recognized by the @code{break} command.
4368 +@defmethod Breakpoint is_valid
4369 +Return @code{True} if this @code{Breakpoint} object is valid,
4370 +@code{False} otherwise. A @code{Breakpoint} object can become invalid
4371 +if the user deletes the breakpoint. In this case, the object still
4372 +exists, but the underlying breakpoint does not.
4375 +@defivar Breakpoint enabled
4376 +This attribute is @code{True} if the breakpoint is enabled, and
4377 +@code{False} otherwise. This attribute is writable.
4380 +@defivar Breakpoint silent
4381 +This attribute is @code{True} if the breakpoint is silent, and
4382 +@code{False} otherwise. This attribute is writable.
4384 +Note that a breakpoint can also be silent if it has commands and the
4385 +first command is @code{silent}. This is not reported by the
4386 +@code{silent} attribute.
4389 +@defivar Breakpoint thread
4390 +If the breakpoint is thread-specific, this attribute holds the thread
4391 +id. If the breakpoint is not thread-specific, this attribute is
4392 +@code{None}. This attribute is writable.
4395 +@defivar Breakpoint ignore_count
4396 +This attribute holds the ignore count for the breakpoint, an integer.
4397 +This attribute is writable.
4400 +@defivar Breakpoint number
4401 +This attribute holds the breakpoint's number -- the identifier used by
4402 +the user to manipulate the breakpoint. This attribute is not writable.
4405 +@defivar Breakpoint hit_count
4406 +This attribute holds the hit count for the breakpoint, an integer.
4407 +This attribute is writable, but currently it can only be set to zero.
4410 +@defivar Breakpoint location
4411 +This attribute holds the location of the breakpoint, as specified by
4412 +the user. It is a string. This attribute is not writable.
4415 +@defivar Breakpoint condition
4416 +This attribute holds the condition of the breakpoint, as specified by
4417 +the user. It is a string. If there is no condition, this attribute's
4418 +value is @code{None}. This attribute is writable.
4421 +@defivar Breakpoint commands
4422 +This attribute holds the commands attached to the breakpoint. If
4423 +there are commands, this returns a string holding all the commands,
4424 +separated by newlines. If there are no commands, this attribute is
4425 +@code{None}. This attribute is not writable.
4428 @node Frames In Python
4429 @subsubsection Acessing inferior stack frames from Python.
4431 @@ -20138,6 +20544,14 @@ function to a string.
4432 Returns the frame's resume address.
4435 +@defmethod Frame block
4436 +Returns the frame's code block. @c (@pxref{Block,,Code Blocks and Scopes}).
4439 +@defmethod Frame function
4440 +Returns the symbol for the function corresponding to this frame. @c (@pxref{Symbols In Python}).
4443 @defmethod Frame older
4444 Return the frame that called this frame.
4446 @@ -20146,10 +20560,18 @@ Return the frame that called this frame.
4447 Return the frame called by this frame.
4450 +@defmethod Frame find_sal
4451 +Return the frame's symtab and line object. @c (@pxref{Symtab_and_line,, Symtab and line}).
4454 @defmethod Frame read_var variable
4455 Return the value of the given variable in this frame. @var{variable} must
4459 +@defmethod Frame select
4460 +Set this frame to be the user's selected frame.
4465 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
4466 index c2be3f7..a7811ab 100644
4467 --- a/gdb/doc/gdbint.texinfo
4468 +++ b/gdb/doc/gdbint.texinfo
4469 @@ -2114,6 +2114,18 @@ time, and so we attempt to handle symbols incrementally. For instance,
4470 we create @dfn{partial symbol tables} consisting of only selected
4471 symbols, and only expand them to full symbol tables when necessary.
4475 +* Partial Symbol Tables::
4477 +* Object File Formats::
4478 +* Debugging File Formats::
4479 +* Adding a New Symbol Reader to GDB::
4480 +* Memory Management for Symbol Files::
4481 +* Memory Management for Types::
4484 +@node Symbol Reading
4485 @section Symbol Reading
4487 @cindex symbol reading
4488 @@ -2206,6 +2218,7 @@ symtab. Upon return, @code{pst->readin} should have been set to 1, and
4489 zero if there were no symbols in that part of the symbol file.
4492 +@node Partial Symbol Tables
4493 @section Partial Symbol Tables
4495 @value{GDBN} has three types of symbol tables:
4496 @@ -2301,6 +2314,7 @@ and all the psymbols themselves are allocated in a pair of large arrays
4497 on an obstack, so there is little to be gained by trying to free them
4498 unless you want to do a lot more work.
4503 @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
4504 @@ -2323,6 +2337,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
4505 other members of the type struct, such as whether the type is signed
4506 or unsigned, and how many bits it uses.
4508 +@anchor{Builtin Types}
4509 @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
4511 These are instances of type structs that roughly correspond to
4512 @@ -2337,6 +2352,7 @@ only one instance exists, while @file{c-lang.c} builds as many
4513 @code{TYPE_CODE_INT} types as needed, with each one associated with
4514 some particular objfile.
4516 +@node Object File Formats
4517 @section Object File Formats
4518 @cindex object file formats
4520 @@ -2422,6 +2438,7 @@ SOM, which is a cross-language ABI).
4522 The SOM reader is in @file{somread.c}.
4524 +@node Debugging File Formats
4525 @section Debugging File Formats
4527 This section describes characteristics of debugging information that
4528 @@ -2493,6 +2510,7 @@ DWARF 3 is an improved version of DWARF 2.
4529 @cindex SOM debugging info
4530 Like COFF, the SOM definition includes debugging information.
4532 +@node Adding a New Symbol Reader to GDB
4533 @section Adding a New Symbol Reader to @value{GDBN}
4535 @cindex adding debugging info reader
4536 @@ -2515,6 +2533,7 @@ will only ever be implemented by one object file format may be called
4537 directly. This interface should be described in a file
4538 @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
4540 +@node Memory Management for Symbol Files
4541 @section Memory Management for Symbol Files
4543 Most memory associated with a loaded symbol file is stored on
4544 @@ -2526,10 +2545,45 @@ released when the objfile is unloaded or reloaded. Therefore one
4545 objfile must not reference symbol or type data from another objfile;
4546 they could be unloaded at different times.
4548 -User convenience variables, et cetera, have associated types. Normally
4549 -these types live in the associated objfile. However, when the objfile
4550 -is unloaded, those types are deep copied to global memory, so that
4551 -the values of the user variables and history items are not lost.
4552 +@node Memory Management for Types
4553 +@section Memory Management for Types
4554 +@cindex memory management for types
4556 +@findex TYPE_OBJFILE
4557 +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
4558 +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
4559 +obstack) and in such case the type remains valid till the objfile is unloaded
4560 +or reloaded. For such types with an associated objfile no reference counting
4563 +User convenience variables, et cetera, have associated types. Normally these
4564 +types live in the associated objfile. However, when the objfile is unloaded,
4565 +those types are deep copied to global memory, so that the values of the user
4566 +variables and history items are not lost. During the copy they will get their
4567 +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
4570 +Types with null @code{TYPE_OBJFILE} can be either permanent types
4571 +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
4572 +first idle @value{GDBN} moment if the last object referencing them is removed.
4573 +Permanent types are allocated by the function @code{alloc_type} (and its
4574 +derivations like @code{init_type}) specifying objfile as @code{NULL}. The
4575 +reclaimable types are created the same way but moreover they need to have
4576 +@code{type_init_group} called to start their tracking as being possibly
4579 +@findex free_all_types
4580 +When @value{GDBN} gets idle it always calls the @code{free_all_types} function
4581 +which deallocates any unused types. All types currently not owned by an
4582 +objfile must be marked as used on each @code{free_all_types} call as they would
4583 +get deallocated as unused otherwise.
4585 +@code{free_all_types} automatically checks for any cross-type references such
4586 +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
4587 +prevents early deallocation for any such existing references. Reclaimable
4588 +types may reference any other reclaimable types or even permanent types. But
4589 +permanent types must not reference reclaimable types (nor an objfile associated
4593 @node Language Support
4594 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
4595 index 4984f31..fcf1b5d 100644
4596 --- a/gdb/doc/observer.texi
4597 +++ b/gdb/doc/observer.texi
4598 @@ -206,6 +206,11 @@ Either @value{GDBN} detached from the inferior, or the inferior
4599 exited. The argument @var{pid} identifies the inferior.
4602 +@deftypefun void mark_used (void)
4603 +Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
4604 +collector pass. Currently only @code{type_mark_used} marker is supported.
4607 @deftypefun void test_notification (int @var{somearg})
4608 This observer is used for internal testing. Do not use.
4609 See testsuite/gdb.gdb/observer.exp.
4610 diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
4611 index 668c434..c29c3a5 100644
4612 --- a/gdb/dwarf2-frame.c
4613 +++ b/gdb/dwarf2-frame.c
4616 #include "complaints.h"
4617 #include "dwarf2-frame.h"
4618 +#include "addrmap.h"
4622 @@ -1574,6 +1575,14 @@ dwarf2_frame_find_fde (CORE_ADDR *pc)
4626 + if (objfile->quick_addrmap)
4628 + if (!addrmap_find (objfile->quick_addrmap, *pc))
4631 + /* FIXME: Read-in only .debug_frame/.eh_frame without .debug_info? */
4632 + require_partial_symbols (objfile);
4634 fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
4635 if (fde_table == NULL)
4637 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
4638 index 46bc9d7..e675575 100644
4639 --- a/gdb/dwarf2expr.c
4640 +++ b/gdb/dwarf2expr.c
4641 @@ -848,6 +848,13 @@ execute_stack_op (struct dwarf_expr_context *ctx,
4642 ctx->initialized = 0;
4645 + case DW_OP_push_object_address:
4646 + if (ctx->get_object_address == NULL)
4647 + error (_("DWARF-2 expression error: DW_OP_push_object_address must "
4648 + "have a value to push."));
4649 + result = (ctx->get_object_address) (ctx->baton);
4653 error (_("Unhandled dwarf expression opcode 0x%x"), op);
4655 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
4656 index a9a8a05..d449012 100644
4657 --- a/gdb/dwarf2expr.h
4658 +++ b/gdb/dwarf2expr.h
4659 @@ -102,10 +102,10 @@ struct dwarf_expr_context
4660 The result must be live until the current expression evaluation
4662 unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length);
4665 /* Return the `object address' for DW_OP_push_object_address. */
4666 CORE_ADDR (*get_object_address) (void *baton);
4669 /* The current depth of dwarf expression recursion, via DW_OP_call*,
4670 DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
4671 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
4672 index 3a81202..85f4487 100644
4673 --- a/gdb/dwarf2loc.c
4674 +++ b/gdb/dwarf2loc.c
4675 @@ -116,6 +116,9 @@ struct dwarf_expr_baton
4677 struct frame_info *frame;
4678 struct objfile *objfile;
4679 + /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
4680 + DW_AT_data_location) for DW_OP_push_object_address. */
4681 + CORE_ADDR object_address;
4684 /* Helper functions for dwarf2_evaluate_loc_desc. */
4685 @@ -177,22 +180,33 @@ dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
4686 *start = find_location_expression (symbaton, length,
4687 get_frame_address_in_block (frame));
4690 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
4692 struct dwarf2_locexpr_baton *symbaton;
4694 symbaton = SYMBOL_LOCATION_BATON (framefunc);
4695 - if (symbaton != NULL)
4697 - *length = symbaton->size;
4698 - *start = symbaton->data;
4702 + gdb_assert (symbaton != NULL);
4703 + *start = symbaton->data;
4704 + *length = symbaton->size;
4706 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
4708 + struct dwarf2_locexpr_baton *symbaton;
4710 + symbaton = SYMBOL_LOCATION_BATON (framefunc);
4711 + gdb_assert (symbaton == NULL);
4713 + *length = 0; /* unused */
4716 + internal_error (__FILE__, __LINE__,
4717 + _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
4718 + SYMBOL_COMPUTED_OPS (framefunc),
4719 + SYMBOL_PRINT_NAME (framefunc));
4722 error (_("Could not find the frame base for \"%s\"."),
4723 - SYMBOL_NATURAL_NAME (framefunc));
4724 + SYMBOL_PRINT_NAME (framefunc));
4727 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
4728 @@ -215,6 +229,129 @@ dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
4729 return target_translate_tls_address (debaton->objfile, offset);
4733 +dwarf_expr_object_address (void *baton)
4735 + struct dwarf_expr_baton *debaton = baton;
4737 + /* The message is suppressed in DWARF_BLOCK_EXEC. */
4738 + if (debaton->object_address == 0)
4739 + error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
4741 + return debaton->object_address;
4744 +/* Address of the variable we are currently referring to. It is set from
4745 + DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
4746 + DW_OP_push_object_address. */
4748 +static CORE_ADDR object_address;
4750 +/* Callers use object_address_set while their callers use the result set so we
4751 + cannot run the cleanup at the local block of our direct caller. Still we
4752 + should reset OBJECT_ADDRESS at least for the next GDB command. */
4755 +object_address_cleanup (void *prev_save_voidp)
4757 + CORE_ADDR *prev_save = prev_save_voidp;
4759 + object_address = *prev_save;
4760 + xfree (prev_save);
4763 +/* Set the base address - DW_AT_location - of a variable. It is being later
4764 + used to derive other object addresses by DW_OP_push_object_address.
4766 + It would be useful to sanity check ADDRESS - such as for some objects with
4767 + unset value_raw_address - but some valid addresses may be zero (such as first
4768 + objects in relocatable .o files). */
4771 +object_address_set (CORE_ADDR address)
4773 + CORE_ADDR *prev_save;
4775 + prev_save = xmalloc (sizeof *prev_save);
4776 + *prev_save = object_address;
4777 + make_cleanup (object_address_cleanup, prev_save);
4779 + object_address = address;
4782 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
4783 + by dwarf_expr_fetch (RETVAL, 0). FRAME parameter can be NULL to call
4784 + get_selected_frame to find it. Returned dwarf_expr_context freeing is
4785 + pushed on the cleanup chain. */
4787 +static struct dwarf_expr_context *
4788 +dwarf_expr_prep_ctx (struct frame_info *frame, gdb_byte *data,
4789 + unsigned short size, struct dwarf2_per_cu_data *per_cu)
4791 + struct dwarf_expr_context *ctx;
4792 + struct dwarf_expr_baton baton;
4795 + frame = get_selected_frame (NULL);
4797 + baton.frame = frame;
4798 + baton.objfile = dwarf2_per_cu_objfile (per_cu);
4799 + baton.object_address = object_address;
4801 + ctx = new_dwarf_expr_context ();
4802 + make_cleanup_free_dwarf_expr_context (ctx);
4804 + ctx->gdbarch = get_objfile_arch (baton.objfile);
4805 + ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4806 + ctx->baton = &baton;
4807 + ctx->read_reg = dwarf_expr_read_reg;
4808 + ctx->read_mem = dwarf_expr_read_mem;
4809 + ctx->get_frame_base = dwarf_expr_frame_base;
4810 + ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4811 + ctx->get_tls_address = dwarf_expr_tls_address;
4812 + ctx->get_object_address = dwarf_expr_object_address;
4814 + dwarf_expr_eval (ctx, data, size);
4816 + /* It was used only during dwarf_expr_eval. */
4817 + ctx->baton = NULL;
4822 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
4823 + CORE_ADDR result on the DWARF stack stack. */
4826 +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
4828 + struct dwarf_expr_context *ctx;
4830 + struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4832 + ctx = dwarf_expr_prep_ctx (NULL, dlbaton->data, dlbaton->size,
4834 + if (ctx->num_pieces > 0)
4835 + error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
4837 + retval = dwarf_expr_fetch (ctx, 0);
4839 + if (ctx->location == DWARF_VALUE_REGISTER)
4841 + /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
4843 + int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
4844 + struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
4845 + struct frame_info *frame = get_selected_frame (NULL);
4847 + retval = address_from_register (type, gdb_regnum, frame);
4850 + do_cleanups (back_to);
4855 struct piece_closure
4857 /* The number of pieces used to describe this variable. */
4858 @@ -382,9 +519,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4859 struct dwarf2_per_cu_data *per_cu)
4861 struct value *retval;
4862 - struct dwarf_expr_baton baton;
4863 struct dwarf_expr_context *ctx;
4864 - struct cleanup *old_chain;
4865 + struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
4869 @@ -394,22 +530,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4873 - baton.frame = frame;
4874 - baton.objfile = dwarf2_per_cu_objfile (per_cu);
4875 + ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu);
4877 - ctx = new_dwarf_expr_context ();
4878 - old_chain = make_cleanup_free_dwarf_expr_context (ctx);
4880 - ctx->gdbarch = get_objfile_arch (baton.objfile);
4881 - ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4882 - ctx->baton = &baton;
4883 - ctx->read_reg = dwarf_expr_read_reg;
4884 - ctx->read_mem = dwarf_expr_read_mem;
4885 - ctx->get_frame_base = dwarf_expr_frame_base;
4886 - ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4887 - ctx->get_tls_address = dwarf_expr_tls_address;
4889 - dwarf_expr_eval (ctx, data, size);
4890 if (ctx->num_pieces > 0)
4892 struct piece_closure *c;
4893 @@ -439,6 +561,11 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4894 CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
4895 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
4897 + /* object_address_set called here is required in ALLOCATE_VALUE's
4898 + CHECK_TYPEDEF for the object's possible
4899 + DW_OP_push_object_address. */
4900 + object_address_set (address);
4902 retval = allocate_value (SYMBOL_TYPE (var));
4903 VALUE_LVAL (retval) = lval_memory;
4904 set_value_lazy (retval, 1);
4905 @@ -815,7 +942,7 @@ static int
4906 loclist_describe_location (struct symbol *symbol, struct ui_file *stream)
4908 /* FIXME: Could print the entire list of locations. */
4909 - fprintf_filtered (stream, "a variable with multiple locations");
4910 + fprintf_filtered (stream, _("a variable with multiple locations"));
4914 @@ -831,16 +958,56 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4916 data = find_location_expression (dlbaton, &size, ax->scope);
4918 - error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol));
4919 + error (_("Variable \"%s\" is not available."), SYMBOL_PRINT_NAME (symbol));
4921 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
4924 -/* The set of location functions used with the DWARF-2 expression
4925 - evaluator and location lists. */
4926 +/* The set of location functions used with the DWARF-2 location lists. */
4927 const struct symbol_computed_ops dwarf2_loclist_funcs = {
4928 loclist_read_variable,
4929 loclist_read_needs_frame,
4930 loclist_describe_location,
4931 loclist_tracepoint_var_ref
4934 +static struct value *
4935 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
4937 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4939 + gdb_assert (dlbaton == NULL);
4940 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
4944 +missing_read_needs_frame (struct symbol *symbol)
4950 +missing_describe_location (struct symbol *symbol, struct ui_file *stream)
4952 + fprintf_filtered (stream, _("a variable we are unable to resolve"));
4957 +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4958 + struct agent_expr *ax, struct axs_value *value)
4960 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4962 + gdb_assert (dlbaton == NULL);
4963 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
4966 +/* The set of location functions used with the DWARF-2 evaluator when we are
4967 + unable to resolve the symbols. */
4968 +const struct symbol_computed_ops dwarf2_missing_funcs = {
4969 + missing_read_variable,
4970 + missing_read_needs_frame,
4971 + missing_describe_location,
4972 + missing_tracepoint_var_ref
4974 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
4975 index 0bfcfca..01018d6 100644
4976 --- a/gdb/dwarf2loc.h
4977 +++ b/gdb/dwarf2loc.h
4978 @@ -71,5 +71,11 @@ struct dwarf2_loclist_baton
4980 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
4981 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
4982 +extern const struct symbol_computed_ops dwarf2_missing_funcs;
4984 +extern void object_address_set (CORE_ADDR address);
4986 +extern CORE_ADDR dwarf_locexpr_baton_eval
4987 + (struct dwarf2_locexpr_baton *dlbaton);
4989 #endif /* dwarf2loc.h */
4990 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
4991 index 4cce36b..fb0a693 100644
4992 --- a/gdb/dwarf2read.c
4993 +++ b/gdb/dwarf2read.c
4997 #include "addrmap.h"
4998 +#include "f-lang.h"
4999 +#include "c-lang.h"
5000 +#include "typeprint.h"
5001 +#include "jv-lang.h"
5006 #include "gdb_string.h"
5007 @@ -93,7 +99,7 @@ typedef struct pubnames_header
5009 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
5011 -/* .debug_pubnames header
5012 +/* .debug_aranges header
5013 Because of alignment constraints, this structure has padding and cannot
5014 be mapped directly onto the beginning of the .debug_info section. */
5015 typedef struct aranges_header
5016 @@ -150,7 +156,10 @@ struct dwarf2_section_info
5021 + /* A function to call to deallocate BUFFER. If NULL, no
5022 + deallocation is needed. A pointer to this structure is passed as
5023 + the only argument. */
5024 + void (*destructor) (struct dwarf2_section_info *);
5027 struct dwarf2_per_objfile
5028 @@ -336,6 +345,19 @@ struct dwarf2_cu
5030 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
5031 unsigned int has_ranges_offset : 1;
5033 + /* Fields are valid according to the LANGUAGE field. */
5036 + /* language_fortran */
5039 + /* Module names imported to the block being currently read in. */
5040 + struct fortran_using *use;
5044 + language_specific;
5047 /* Persistent data held for a compilation unit, even when not
5048 @@ -495,8 +517,7 @@ struct partial_die_info
5049 unsigned int has_byte_size : 1;
5051 /* The name of this DIE. Normally the value of DW_AT_name, but
5052 - sometimes DW_TAG_MIPS_linkage_name or a string computed in some
5054 + sometimes a default name for unnamed DIEs. */
5058 @@ -689,6 +710,11 @@ struct field_info
5062 +/* A vector used during linkage name generation. */
5063 +typedef struct die_info *die_info_p;
5064 +DEF_VEC_P (die_info_p);
5065 +static VEC(die_info_p) *die_list;
5067 /* One item on the queue of compilation units to read in full symbols
5069 struct dwarf2_queue_item
5070 @@ -800,7 +826,10 @@ static void scan_partial_symbols (struct partial_die_info *,
5071 static void add_partial_symbol (struct partial_die_info *,
5072 struct dwarf2_cu *);
5074 -static int pdi_needs_namespace (enum dwarf_tag tag);
5075 +static gdb_byte *read_comp_unit_head (struct comp_unit_head *, gdb_byte *,
5078 +static int die_needs_namespace (struct die_info *, struct dwarf2_cu *);
5080 static void add_partial_namespace (struct partial_die_info *pdi,
5081 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5082 @@ -825,6 +854,10 @@ static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
5084 static void psymtab_to_symtab_1 (struct partial_symtab *);
5086 +static void dwarf2_read_section_1 (struct objfile *objfile,
5087 + struct obstack *obstack,
5088 + struct dwarf2_section_info *info);
5090 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
5092 static void dwarf2_free_abbrev_table (void *);
5093 @@ -945,6 +978,11 @@ static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
5095 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
5097 +static char *physname_prefix (struct die_info *die, struct dwarf2_cu *);
5099 +static void physname_prefix_1 (struct ui_file *, struct die_info *,
5100 + struct dwarf2_cu *);
5102 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
5104 static char *typename_concat (struct obstack *,
5105 @@ -964,7 +1002,8 @@ static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
5106 struct dwarf2_cu *, struct partial_symtab *);
5108 static int dwarf2_get_pc_bounds (struct die_info *,
5109 - CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
5110 + CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
5111 + struct partial_symtab *pst);
5113 static void get_scope_pc_bounds (struct die_info *,
5114 CORE_ADDR *, CORE_ADDR *,
5115 @@ -988,17 +1027,25 @@ static void dwarf2_attach_fn_fields_to_type (struct field_info *,
5117 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
5119 -static const char *determine_class_name (struct die_info *die,
5120 - struct dwarf2_cu *cu);
5122 static void read_common_block (struct die_info *, struct dwarf2_cu *);
5124 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
5126 +static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
5128 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
5130 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
5132 +static struct type *read_module_type (struct die_info *die,
5133 + struct dwarf2_cu *cu);
5135 +static void read_fortran_imported_module (struct die_info *die,
5136 + struct dwarf2_cu *cu);
5138 +static void read_fortran_imported_declaration (struct die_info *die,
5139 + struct dwarf2_cu *cu);
5141 static const char *namespace_name (struct die_info *die,
5142 int *is_anonymous, struct dwarf2_cu *);
5144 @@ -1032,7 +1079,10 @@ static gdb_byte *read_full_die (const struct die_reader_specs *reader,
5146 static void process_die (struct die_info *, struct dwarf2_cu *);
5148 -static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
5149 +static char *dwarf2_physname (struct die_info *, struct dwarf2_cu *);
5151 +static char *fortran_module_linkage_name (struct die_info *die,
5152 + struct dwarf2_cu *cu);
5154 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
5156 @@ -1076,7 +1126,7 @@ static int is_ref_attr (struct attribute *);
5158 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
5160 -static int dwarf2_get_attr_constant_value (struct attribute *, int);
5161 +static CORE_ADDR dwarf2_get_attr_constant_value (struct attribute *, CORE_ADDR);
5163 static struct die_info *follow_die_ref_or_sig (struct die_info *,
5165 @@ -1148,6 +1198,9 @@ static void age_cached_comp_units (void);
5167 static void free_one_cached_comp_unit (void *);
5169 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
5170 + struct dwarf2_cu *cu);
5172 static struct type *set_die_type (struct die_info *, struct type *,
5173 struct dwarf2_cu *);
5175 @@ -1167,22 +1220,31 @@ static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
5177 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
5179 +static void destroy_section (struct dwarf2_section_info *info);
5181 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
5182 + (struct attribute *attr, struct dwarf2_cu *cu);
5184 /* Try to locate the sections we need for DWARF 2 debugging
5185 information and return true if we have enough to do something. */
5188 dwarf2_has_info (struct objfile *objfile)
5190 - struct dwarf2_per_objfile *data;
5192 - /* Initialize per-objfile state. */
5193 - data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
5194 - memset (data, 0, sizeof (*data));
5195 - set_objfile_data (objfile, dwarf2_objfile_data_key, data);
5196 - dwarf2_per_objfile = data;
5197 + dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
5198 + if (!dwarf2_per_objfile)
5200 + /* Initialize per-objfile state. */
5201 + struct dwarf2_per_objfile *data
5202 + = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
5203 + memset (data, 0, sizeof (*data));
5204 + set_objfile_data (objfile, dwarf2_objfile_data_key, data);
5205 + dwarf2_per_objfile = data;
5207 - bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
5208 - return (data->info.asection != NULL && data->abbrev.asection != NULL);
5209 + bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
5211 + return (dwarf2_per_objfile->info.asection != NULL
5212 + && dwarf2_per_objfile->abbrev.asection != NULL);
5215 /* When loading sections, we can either look for ".<name>", or for
5216 @@ -1275,10 +1337,13 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
5219 /* Decompress a section that was compressed using zlib. Store the
5220 - decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5221 + decompressed buffer, and its size, in OUTBUF and OUTSIZE. The
5222 + result is allocated on OBSTACK; if OBSTACK is NULL, xmalloc is
5226 -zlib_decompress_section (struct objfile *objfile, asection *sectp,
5227 +zlib_decompress_section (struct objfile *objfile, struct obstack *obstack,
5229 gdb_byte **outbuf, bfd_size_type *outsize)
5231 bfd *abfd = objfile->obfd;
5232 @@ -1295,6 +1360,7 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5235 int header_size = 12;
5236 + struct cleanup *old = NULL;
5238 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5239 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
5240 @@ -1324,8 +1390,13 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5241 strm.avail_in = compressed_size - header_size;
5242 strm.next_in = (Bytef*) compressed_buffer + header_size;
5243 strm.avail_out = uncompressed_size;
5244 - uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
5245 - uncompressed_size);
5247 + uncompressed_buffer = obstack_alloc (obstack, uncompressed_size);
5250 + uncompressed_buffer = xmalloc (uncompressed_size);
5251 + old = make_cleanup (xfree, uncompressed_buffer);
5253 rc = inflateInit (&strm);
5254 while (strm.avail_in > 0)
5256 @@ -1346,26 +1417,176 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5257 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5258 bfd_get_filename (abfd), rc);
5261 + discard_cleanups (old);
5262 do_cleanups (cleanup);
5263 *outbuf = uncompressed_buffer;
5264 *outsize = uncompressed_size;
5268 -/* Read the contents of the section SECTP from object file specified by
5269 - OBJFILE, store info about the section into INFO.
5270 - If the section is compressed, uncompress it before returning. */
5271 +/* A cleanup that calls destroy_section. */
5274 -dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5275 +destroy_section_cleanup (void *arg)
5277 + destroy_section (arg);
5280 +/* Read the .debug_aranges section and construct an address map. */
5283 +dwarf2_create_quick_addrmap (struct objfile *objfile)
5285 + char *aranges_buffer, *aranges_ptr;
5286 + bfd *abfd = objfile->obfd;
5287 + CORE_ADDR baseaddr;
5288 + struct cleanup *old;
5289 + struct obstack temp_obstack;
5290 + struct addrmap *mutable_map;
5292 + if (!dwarf2_per_objfile->aranges.asection)
5295 + baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5297 + dwarf2_read_section_1 (objfile, NULL, &dwarf2_per_objfile->aranges);
5298 + aranges_buffer = dwarf2_per_objfile->aranges.buffer;
5299 + aranges_ptr = aranges_buffer;
5300 + old = make_cleanup (destroy_section_cleanup, &dwarf2_per_objfile->aranges);
5302 + obstack_init (&temp_obstack);
5303 + make_cleanup_obstack_free (&temp_obstack);
5304 + mutable_map = addrmap_create_mutable (&temp_obstack);
5306 + while ((aranges_ptr - aranges_buffer) < dwarf2_per_objfile->aranges.size)
5308 + struct comp_unit_head cu_header;
5309 + unsigned int bytes_read, segment_size, delta;
5310 + LONGEST info_offset;
5311 + struct dwarf2_cu cu;
5314 + cu_header.initial_length_size = 0;
5315 + end_ptr = aranges_ptr;
5316 + aranges_ptr = read_comp_unit_head (&cu_header, aranges_ptr, abfd);
5317 + end_ptr += cu_header.initial_length_size + cu_header.length;
5319 + /* Sanity check. */
5320 + if (end_ptr - aranges_ptr >= dwarf2_per_objfile->aranges.size)
5322 + do_cleanups (old);
5323 + complaint (&symfile_complaints,
5324 + _("aranges entry runs off end of `.debug_aranges' section, ignored"));
5327 + if (cu_header.addr_size == 0)
5329 + do_cleanups (old);
5330 + complaint (&symfile_complaints,
5331 + _("aranges entry has zero addr_size, ignored"));
5335 + segment_size = read_1_byte (abfd, aranges_ptr);
5338 + /* Align the pointer to twice the pointer size. I didn't see
5339 + this in the spec but it appears to be required. */
5340 + delta = (aranges_ptr - aranges_buffer) % (2 * cu_header.addr_size);
5341 + delta = (2 * cu_header.addr_size - delta) % (2 * cu_header.addr_size);
5342 + aranges_ptr += delta;
5344 + memset (&cu, 0, sizeof (cu));
5345 + cu.header.addr_size = cu_header.addr_size;
5349 + CORE_ADDR address, length;
5351 + address = read_address (abfd, aranges_ptr, &cu, &bytes_read);
5352 + aranges_ptr += bytes_read;
5354 + length = read_address (abfd, aranges_ptr, &cu, &bytes_read);
5355 + aranges_ptr += bytes_read;
5357 + if (address == 0 && length == 0)
5362 + do_cleanups (old);
5363 + complaint (&symfile_complaints,
5364 + _("aranges entry has zero length, ignored"));
5368 + address += baseaddr;
5370 + addrmap_set_empty (mutable_map, address, address + length - 1,
5374 + /* Some older versions of GCC incorrectly started the arange
5375 + with a (0,0) pair. If we encounter any oddity while reading
5376 + the section, just abandon the attempt; falling back to the
5377 + slower code is always safe. */
5378 + if (aranges_ptr != end_ptr)
5380 + do_cleanups (old);
5381 + complaint (&symfile_complaints,
5382 + _("aranges entry ends early, ignored"));
5387 + objfile->quick_addrmap = addrmap_create_fixed (mutable_map,
5388 + &objfile->objfile_obstack);
5389 + do_cleanups (old);
5392 +/* Free a section buffer allocated with xmalloc. */
5395 +xfree_section_buffer (struct dwarf2_section_info *info)
5397 + xfree (info->buffer);
5400 +/* If section described by INFO was mmapped, munmap it now. */
5403 +munmap_section_buffer (struct dwarf2_section_info *info)
5406 + intptr_t begin = (intptr_t) info->buffer;
5407 + intptr_t map_begin = begin & ~(pagesize - 1);
5408 + size_t map_length = info->size + begin - map_begin;
5409 + gdb_assert (munmap ((void *) map_begin, map_length) == 0);
5411 + /* Without HAVE_MMAP, we should never be here to begin with. */
5416 +/* Read the contents of the section at OFFSET and of size SIZE from
5417 + the object file specified by OBJFILE into OBSTACK and store it into
5418 + INFO. If OBSTACK is NULL, xmalloc is used instead. If the section
5419 + is compressed, uncompress it before returning. */
5422 +dwarf2_read_section_1 (struct objfile *objfile,
5423 + struct obstack *obstack,
5424 + struct dwarf2_section_info *info)
5426 bfd *abfd = objfile->obfd;
5427 asection *sectp = info->asection;
5428 gdb_byte *buf, *retbuf;
5429 unsigned char header[4];
5430 + struct cleanup *old = NULL;
5432 info->buffer = NULL;
5433 - info->was_mmapped = 0;
5434 + info->destructor = 0;
5436 if (info->asection == NULL || info->size == 0)
5438 @@ -1378,7 +1599,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5439 /* Upon decompression, update the buffer and its size. */
5440 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
5442 - zlib_decompress_section (objfile, sectp, &info->buffer,
5443 + zlib_decompress_section (objfile, obstack, sectp, &info->buffer,
5447 @@ -1401,7 +1622,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5449 if (retbuf != MAP_FAILED)
5451 - info->was_mmapped = 1;
5452 + info->destructor = munmap_section_buffer;
5453 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
5456 @@ -1409,8 +1630,15 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5459 /* If we get here, we are a normal, not-compressed section. */
5460 - info->buffer = buf
5461 - = obstack_alloc (&objfile->objfile_obstack, info->size);
5463 + buf = obstack_alloc (obstack, info->size);
5466 + buf = xmalloc (info->size);
5467 + old = make_cleanup (xfree, buf);
5468 + info->destructor = xfree_section_buffer;
5470 + info->buffer = buf;
5472 /* When debugging .o files, we may need to apply relocations; see
5473 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5474 @@ -1419,6 +1647,8 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5475 retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
5479 + discard_cleanups (old);
5480 info->buffer = retbuf;
5483 @@ -1427,6 +1657,19 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5484 || bfd_bread (buf, info->size, abfd) != info->size)
5485 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5486 bfd_get_filename (abfd));
5489 + discard_cleanups (old);
5492 +/* Read the contents of the section SECTP from object file specified by
5493 + OBJFILE, store info about the section into INFO.
5494 + If the section is compressed, uncompress it before returning. */
5497 +dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5499 + dwarf2_read_section_1 (objfile, &objfile->objfile_obstack, info);
5502 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
5503 @@ -1810,6 +2053,37 @@ lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
5507 +/* Find the base address of the compilation unit for range lists and
5508 + location lists. It will normally be specified by DW_AT_low_pc.
5509 + In DWARF-3 draft 4, the base address could be overridden by
5510 + DW_AT_entry_pc. It's been removed, but GCC still uses this for
5511 + compilation units with discontinuous ranges. */
5514 +dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
5516 + struct attribute *attr;
5518 + cu->base_known = 0;
5519 + cu->base_address = 0;
5521 + attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
5524 + cu->base_address = DW_ADDR (attr);
5525 + cu->base_known = 1;
5529 + attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5532 + cu->base_address = DW_ADDR (attr);
5533 + cu->base_known = 1;
5538 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
5539 to combine the common parts.
5540 Process a compilation unit for a psymtab.
5541 @@ -2359,7 +2633,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
5543 complaint (&symfile_complaints,
5544 _("unhandled containing DIE tag %d for DIE at %d"),
5545 - parent->tag, pdi->offset);
5546 + parent->tag, real_pdi->offset);
5547 parent->scope = grandparent_scope;
5550 @@ -2374,12 +2648,22 @@ partial_die_full_name (struct partial_die_info *pdi,
5551 struct dwarf2_cu *cu)
5554 + struct partial_die_info *real_pdi;
5556 - parent_scope = partial_die_parent_scope (pdi, cu);
5557 - if (parent_scope == NULL)
5560 + /* We need to look at our parent DIE; if we have a DW_AT_specification,
5561 + then this means the parent of the specification DIE.
5562 + partial_die_parent_scope does this loop also, but we do it here
5563 + since we need to examine real_pdi->parent ourselves. */
5566 + while (real_pdi->has_specification)
5567 + real_pdi = find_partial_die (real_pdi->spec_offset, cu);
5569 + parent_scope = partial_die_parent_scope (real_pdi, cu);
5570 + if (parent_scope != NULL)
5571 return typename_concat (NULL, parent_scope, pdi->name, cu);
5577 @@ -2395,12 +2679,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5579 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5581 - if (pdi_needs_namespace (pdi->tag))
5583 - actual_name = partial_die_full_name (pdi, cu);
5585 - built_actual_name = 1;
5587 + actual_name = partial_die_full_name (pdi, cu);
5589 + built_actual_name = 1;
5591 if (actual_name == NULL)
5592 actual_name = pdi->name;
5593 @@ -2491,6 +2772,12 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5594 &objfile->global_psymbols,
5595 0, (CORE_ADDR) 0, cu->language, objfile);
5597 + case DW_TAG_module:
5598 + add_psymbol_to_list (actual_name, strlen (actual_name),
5599 + MODULE_DOMAIN, LOC_STATIC,
5600 + &objfile->global_psymbols,
5601 + 0, (CORE_ADDR) 0, cu->language, objfile);
5603 case DW_TAG_class_type:
5604 case DW_TAG_interface_type:
5605 case DW_TAG_structure_type:
5606 @@ -2532,34 +2819,17 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5610 - /* Check to see if we should scan the name for possible namespace
5611 - info. Only do this if this is C++, if we don't have namespace
5612 - debugging info in the file, if the psym is of an appropriate type
5613 - (otherwise we'll have psym == NULL), and if we actually had a
5614 - mangled name to begin with. */
5616 - /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
5617 - cases which do not set PSYM above? */
5619 - if (cu->language == language_cplus
5620 - && cu->has_namespace_info == 0
5622 - && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
5623 - cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
5626 if (built_actual_name)
5627 xfree (actual_name);
5630 -/* Determine whether a die of type TAG living in a C++ class or
5631 - namespace needs to have the name of the scope prepended to the
5632 - name listed in the die. */
5633 +/* Determine whether DIE needs to have the name of the scope prepended
5634 + to the name listed in the die. */
5637 -pdi_needs_namespace (enum dwarf_tag tag)
5638 +die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
5643 case DW_TAG_namespace:
5644 case DW_TAG_typedef:
5645 @@ -2569,7 +2839,23 @@ pdi_needs_namespace (enum dwarf_tag tag)
5646 case DW_TAG_union_type:
5647 case DW_TAG_enumeration_type:
5648 case DW_TAG_enumerator:
5649 + case DW_TAG_subprogram:
5650 + case DW_TAG_member:
5653 + case DW_TAG_variable:
5655 + struct attribute *attr;
5656 + attr = dwarf2_attr (die, DW_AT_specification, cu);
5659 + attr = dwarf2_attr (die, DW_AT_external, cu);
5660 + if (attr == NULL && die->parent->tag != DW_TAG_namespace)
5669 @@ -2602,12 +2888,12 @@ static void
5670 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
5671 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
5673 - /* Now scan partial symbols in that module.
5674 + /* Add a symbol for the module. */
5676 - FIXME: Support the separate Fortran module namespaces. */
5677 + add_partial_symbol (pdi, cu);
5679 - if (pdi->has_children)
5680 - scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
5681 + /* Partial symbols in that module are not scanned as they are never globally
5682 + visible. They get imported to the specific scopes on the full read. */
5685 /* Read a partial die corresponding to a subprogram and create a partial
5686 @@ -2698,27 +2984,6 @@ guess_structure_name (struct partial_die_info *struct_pdi,
5688 if (real_pdi->die_parent != NULL)
5691 - while (child_pdi != NULL)
5693 - if (child_pdi->tag == DW_TAG_subprogram)
5695 - char *actual_class_name
5696 - = language_class_name_from_physname (cu->language_defn,
5698 - if (actual_class_name != NULL)
5701 - = obsavestring (actual_class_name,
5702 - strlen (actual_class_name),
5703 - &cu->comp_unit_obstack);
5704 - xfree (actual_class_name);
5709 - child_pdi = child_pdi->die_sibling;
5714 @@ -3295,6 +3560,14 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
5715 case DW_TAG_imported_declaration:
5716 case DW_TAG_imported_module:
5717 processing_has_namespace_info = 1;
5718 + if (cu->language == language_fortran)
5720 + if (die->tag == DW_TAG_imported_declaration)
5721 + read_fortran_imported_declaration (die, cu);
5723 + read_fortran_imported_module (die, cu);
5726 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
5727 || cu->language != language_fortran))
5728 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
5729 @@ -3310,41 +3583,71 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
5730 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5731 If scope qualifiers are appropriate they will be added. The result
5732 will be allocated on the objfile_obstack, or NULL if the DIE does
5733 - not have a name. */
5736 + The output string will be canonicalized (if C++/Java). */
5739 dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu)
5741 - struct attribute *attr;
5742 - char *prefix, *name;
5743 - struct ui_file *buf = NULL;
5746 name = dwarf2_name (die, cu);
5750 /* These are the only languages we know how to qualify names in. */
5751 - if (cu->language != language_cplus
5752 - && cu->language != language_java)
5755 + && (cu->language == language_cplus || cu->language == language_java))
5757 + if (die_needs_namespace (die, cu))
5761 + struct ui_file *buf;
5763 - /* If no prefix is necessary for this type of DIE, return the
5764 - unqualified name. The other three tags listed could be handled
5765 - in pdi_needs_namespace, but that requires broader changes. */
5766 - if (!pdi_needs_namespace (die->tag)
5767 - && die->tag != DW_TAG_subprogram
5768 - && die->tag != DW_TAG_variable
5769 - && die->tag != DW_TAG_member)
5771 + buf = mem_fileopen ();
5772 + prefix = determine_prefix (die, cu);
5773 + if (*prefix != '\0')
5775 + char *prefixed_name = typename_concat (NULL, prefix, name, cu);
5776 + fputs_unfiltered (prefixed_name, buf);
5777 + xfree (prefixed_name);
5780 + fputs_unfiltered (name, buf);
5782 - prefix = determine_prefix (die, cu);
5783 - if (*prefix != '\0')
5784 - name = typename_concat (&cu->objfile->objfile_obstack, prefix,
5786 + name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5788 + ui_file_delete (buf);
5790 + if (cu->language == language_cplus)
5793 + = dwarf2_canonicalize_name (name, cu,
5794 + &cu->objfile->objfile_obstack);
5795 + if (cname != NULL)
5804 +/* Read the given DIE's DW_AT_decl_line number. Return -1 if in case of an
5808 +dwarf2_read_decl_line (struct die_info *die, struct dwarf2_cu *cu)
5810 + struct attribute *line_attr;
5812 + line_attr = dwarf2_attr (die, DW_AT_decl_line, cu);
5814 + return DW_UNSND (line_attr);
5819 /* Read the import statement specified by the given die and record it. */
5822 @@ -3354,9 +3657,15 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5823 struct die_info *imported_die;
5824 const char *imported_name;
5825 const char *imported_name_prefix;
5826 - const char *import_prefix;
5827 char *canonical_name;
5829 + const char *import_alias;
5830 + const char *imported_declaration = "";
5831 + const char *import_prefix;
5833 + int line_number = -1;
5835 + int is_anonymous = 0;
5837 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5838 if (import_attr == NULL)
5840 @@ -3404,17 +3713,27 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5844 - /* FIXME: dwarf2_name (die); for the local name after import. */
5846 - /* Figure out where the statement is being imported to. */
5847 + /* Figure out the local name after import. */
5848 + import_alias = dwarf2_name(die, cu);
5849 + if(import_alias == NULL){
5850 + import_alias = "";
5853 + /* Determine the line number at which the import was made */
5854 + line_number = dwarf2_read_decl_line(die, cu);
5856 + /* Figure out where the statement is being imported to */
5857 import_prefix = determine_prefix (die, cu);
5859 /* Figure out what the scope of the imported die is and prepend it
5860 to the name of the imported die. */
5861 imported_name_prefix = determine_prefix (imported_die, cu);
5863 - if (strlen (imported_name_prefix) > 0)
5866 + if(imported_die->tag != DW_TAG_namespace){
5867 + imported_declaration = imported_name;
5868 + canonical_name = (char*)imported_name_prefix;
5870 + if(strlen (imported_name_prefix) > 0){
5871 canonical_name = alloca (strlen (imported_name_prefix) + 2 + strlen (imported_name) + 1);
5872 strcpy (canonical_name, imported_name_prefix);
5873 strcat (canonical_name, "::");
5874 @@ -3425,8 +3744,14 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5875 canonical_name = alloca (strlen (imported_name) + 1);
5876 strcpy (canonical_name, imported_name);
5879 - using_directives = cp_add_using (import_prefix,canonical_name, using_directives);
5882 + using_directives = cp_add_using (import_prefix,
5885 + imported_declaration,
5887 + using_directives);
5891 @@ -3695,6 +4020,14 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5892 struct attribute *attr;
5894 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5896 + /* GCC 4.3 incorrectly uses DW_AT_specification to indicate die inheritence
5897 + in the case of import statements. The following is to accommodate
5900 + attr = dwarf2_attr (die, DW_AT_specification, cu);
5906 @@ -3793,6 +4126,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5909 struct block *block;
5910 + unsigned die_children = 0;
5911 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5914 @@ -3811,13 +4145,23 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5916 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5918 - name = dwarf2_linkage_name (die, cu);
5919 + name = dwarf2_name (die, cu);
5921 /* Ignore functions with missing or empty names and functions with
5922 missing or invalid low and high pc attributes. */
5923 - if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
5924 + if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)){
5925 + /* explore abstract origins if present. They might contain useful information
5926 + such as import statements. */
5927 + child_die = die->child;
5928 + while (child_die && child_die->tag)
5930 + child_die = sibling_die (child_die);
5933 + inherit_abstract_dies(die, cu);
5941 @@ -3844,14 +4188,19 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5943 cu->list_in_scope = &local_symbols;
5945 - if (die->child != NULL)
5946 + switch (cu->language)
5948 - child_die = die->child;
5949 - while (child_die && child_die->tag)
5951 - process_die (child_die, cu);
5952 - child_die = sibling_die (child_die);
5954 + case language_fortran:
5955 + cu->language_specific.fortran.use = NULL;
5959 + child_die = die->child;
5960 + while (child_die && child_die->tag)
5962 + process_die (child_die, cu);
5963 + child_die = sibling_die (child_die);
5967 inherit_abstract_dies (die, cu);
5968 @@ -3867,6 +4216,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5969 determine_prefix (die, cu),
5970 processing_has_namespace_info);
5972 + switch (cu->language)
5974 + case language_fortran:
5975 + BLOCK_FORTRAN_USE (block) = cu->language_specific.fortran.use;
5979 /* If we have address ranges, record them. */
5980 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5982 @@ -3903,7 +4259,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5983 as multiple lexical blocks? Handling children in a sane way would
5984 be nasty. Might be easier to properly extend generic blocks to
5986 - if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
5987 + if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5991 @@ -3920,7 +4276,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5993 new = pop_context ();
5995 - if (local_symbols != NULL)
5996 + if (local_symbols != NULL || using_directives != NULL)
5999 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6000 @@ -4075,7 +4431,8 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6001 discontinuous, i.e. derived from DW_AT_ranges information. */
6003 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6004 - CORE_ADDR *highpc, struct dwarf2_cu *cu)
6005 + CORE_ADDR *highpc, struct dwarf2_cu *cu,
6006 + struct partial_symtab *pst)
6008 struct attribute *attr;
6010 @@ -4103,7 +4460,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6012 /* Value of the DW_AT_ranges attribute is the offset in the
6013 .debug_ranges section. */
6014 - if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL))
6015 + if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6017 /* Found discontinuous range of addresses. */
6019 @@ -4142,7 +4499,7 @@ dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6020 CORE_ADDR low, high;
6021 struct die_info *child = die->child;
6023 - if (dwarf2_get_pc_bounds (die, &low, &high, cu))
6024 + if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6026 *lowpc = min (*lowpc, low);
6027 *highpc = max (*highpc, high);
6028 @@ -4179,7 +4536,7 @@ get_scope_pc_bounds (struct die_info *die,
6029 CORE_ADDR best_high = (CORE_ADDR) 0;
6030 CORE_ADDR current_low, current_high;
6032 - if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
6033 + if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6035 best_low = current_low;
6036 best_high = current_high;
6037 @@ -4474,7 +4831,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
6040 /* Get physical name. */
6041 - physname = dwarf2_linkage_name (die, cu);
6042 + physname = dwarf2_physname (die, cu);
6044 /* The name is already allocated along with this objfile, so we don't
6045 need to duplicate it for the type. */
6046 @@ -4617,7 +4974,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6049 /* Get the mangled name. */
6050 - physname = dwarf2_linkage_name (die, cu);
6051 + physname = dwarf2_physname (die, cu);
6053 /* Look up member function name in fieldlist. */
6054 for (i = 0; i < fip->nfnfields; i++)
6055 @@ -4661,7 +5018,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6056 /* The name is already allocated along with this objfile, so we don't
6057 need to duplicate it for the type. */
6058 fnp->physname = physname ? physname : "";
6059 - fnp->type = alloc_type (objfile);
6060 + fnp->type = alloc_type (objfile, NULL);
6061 this_type = read_type_die (die, cu);
6062 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6064 @@ -4721,18 +5078,18 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6066 /* Support the .debug_loc offsets */
6067 if (attr_form_is_block (attr))
6069 - fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6072 + fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6074 else if (attr_form_is_section_offset (attr))
6077 dwarf2_complex_location_expr_complaint ();
6083 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6090 @@ -4845,7 +5202,7 @@ quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
6093 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6094 - type = alloc_type (objfile);
6095 + type = alloc_type (objfile, NULL);
6096 smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6097 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6098 TYPE_VARARGS (pfn_type));
6099 @@ -4898,7 +5255,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6100 return set_die_type (die, type, cu);
6103 - type = alloc_type (objfile);
6104 + type = alloc_type (objfile, NULL);
6105 INIT_CPLUS_SPECIFIC (type);
6107 name = dwarf2_name (die, cu);
6108 @@ -4907,14 +5264,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6109 if (cu->language == language_cplus
6110 || cu->language == language_java)
6112 - const char *new_prefix = determine_class_name (die, cu);
6113 - TYPE_TAG_NAME (type) = (char *) new_prefix;
6114 + TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (die, cu);
6115 + if (die->tag == DW_TAG_structure_type
6116 + || die->tag == DW_TAG_class_type)
6117 + TYPE_NAME (type) = TYPE_TAG_NAME (type);
6121 /* The name is already allocated along with this objfile, so
6122 we don't need to duplicate it for the type. */
6123 - TYPE_TAG_NAME (type) = name;
6124 + TYPE_TAG_NAME (type) = (char *) name;
6125 + if (die->tag == DW_TAG_class_type)
6126 + TYPE_NAME (type) = TYPE_TAG_NAME (type);
6130 @@ -5124,7 +5485,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6131 return set_die_type (die, type, cu);
6134 - type = alloc_type (objfile);
6135 + type = alloc_type (objfile, NULL);
6137 TYPE_CODE (type) = TYPE_CODE_ENUM;
6138 name = dwarf2_full_name (die, cu);
6139 @@ -5152,51 +5513,6 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6140 return set_die_type (die, type, cu);
6143 -/* Determine the name of the type represented by DIE, which should be
6144 - a named C++ or Java compound type. Return the name in question,
6145 - allocated on the objfile obstack. */
6147 -static const char *
6148 -determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
6150 - const char *new_prefix = NULL;
6152 - /* If we don't have namespace debug info, guess the name by trying
6153 - to demangle the names of members, just like we did in
6154 - guess_structure_name. */
6155 - if (!processing_has_namespace_info)
6157 - struct die_info *child;
6159 - for (child = die->child;
6160 - child != NULL && child->tag != 0;
6161 - child = sibling_die (child))
6163 - if (child->tag == DW_TAG_subprogram)
6166 - = language_class_name_from_physname (cu->language_defn,
6167 - dwarf2_linkage_name
6170 - if (phys_prefix != NULL)
6173 - = obsavestring (phys_prefix, strlen (phys_prefix),
6174 - &cu->objfile->objfile_obstack);
6175 - xfree (phys_prefix);
6182 - if (new_prefix == NULL)
6183 - new_prefix = dwarf2_full_name (die, cu);
6185 - return new_prefix;
6188 /* Given a pointer to a die which begins an enumeration, process all
6189 the dies that define the members of the enumeration, and create the
6190 symbol for the enumeration type.
6191 @@ -5274,6 +5590,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
6192 new_symbol (die, this_type, cu);
6195 +/* Create a new array dimension referencing its target type TYPE.
6197 + Multidimensional arrays are internally represented as a stack of
6198 + singledimensional arrays being referenced by their TYPE_TARGET_TYPE. */
6200 +static struct type *
6201 +create_single_array_dimension (struct type *type, struct type *range_type,
6202 + struct die_info *die, struct dwarf2_cu *cu)
6204 + type = create_array_type (NULL, type, range_type);
6206 + /* These generic type attributes need to be fetched by
6207 + evaluate_subexp_standard <multi_f77_subscript>'s call of
6208 + value_subscripted_rvalue only for the innermost array type. */
6209 + fetch_die_type_attrs (die, type, cu);
6211 + /* These generic type attributes are checked for allocated/associated
6212 + validity while accessing FIELD_LOC_KIND_DWARF_BLOCK. */
6213 + fetch_die_type_attrs (die, range_type, cu);
6218 /* Extract all information from a DW_TAG_array_type DIE and put it in
6219 the DIE's type field. For now, this only handles one dimensional
6221 @@ -5287,7 +5626,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6222 struct type *element_type, *range_type, *index_type;
6223 struct type **range_types = NULL;
6224 struct attribute *attr;
6227 struct cleanup *back_to;
6230 @@ -5334,16 +5673,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6231 type = element_type;
6233 if (read_array_order (die, cu) == DW_ORD_col_major)
6237 - type = create_array_type (NULL, type, range_types[i++]);
6241 - while (ndim-- > 0)
6242 - type = create_array_type (NULL, type, range_types[ndim]);
6244 + for (i = 0; i < ndim; i++)
6245 + type = create_single_array_dimension (type, range_types[i], die, cu);
6246 + else /* (read_array_order (die, cu) == DW_ORD_row_major) */
6247 + for (i = ndim - 1; i >= 0; i--)
6248 + type = create_single_array_dimension (type, range_types[i], die, cu);
6250 /* Understand Dwarf2 support for vector types (like they occur on
6251 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6252 @@ -5410,12 +5744,14 @@ read_set_type (struct die_info *die, struct dwarf2_cu *cu)
6253 return set_die_type (die, set_type, cu);
6256 -/* First cut: install each common block member as a global variable. */
6257 +/* Create appropriate locally-scoped variables for all the DW_TAG_common_block
6258 + entries. Create also TYPE_CODE_STRUCT listing all such variables to be
6259 + available for `info common'. COMMON_BLOCK_DOMAIN is used to sepate the
6260 + common blocks name namespace from regular variable names. */
6263 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6265 - struct die_info *child_die;
6266 struct attribute *attr;
6268 CORE_ADDR base = (CORE_ADDR) 0;
6269 @@ -5425,25 +5761,55 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6271 /* Support the .debug_loc offsets */
6272 if (attr_form_is_block (attr))
6274 - base = decode_locdesc (DW_BLOCK (attr), cu);
6277 + base = decode_locdesc (DW_BLOCK (attr), cu);
6279 else if (attr_form_is_section_offset (attr))
6282 dwarf2_complex_location_expr_complaint ();
6288 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6289 "common block member");
6293 if (die->child != NULL)
6295 + struct objfile *objfile = cu->objfile;
6296 + struct die_info *child_die;
6297 + struct type *type;
6298 + struct field *field;
6300 + struct symbol *sym;
6302 + type = alloc_type (objfile, NULL);
6303 + TYPE_CODE (type) = TYPE_CODE_STRUCT;
6304 + /* Artificial type to be used only by `info common'. */
6305 + TYPE_NAME (type) = "<common>";
6307 child_die = die->child;
6308 while (child_die && child_die->tag)
6310 + TYPE_NFIELDS (type)++;
6311 + child_die = sibling_die (child_die);
6314 + TYPE_FIELDS (type) = obstack_alloc (&objfile->objfile_obstack,
6315 + sizeof (*TYPE_FIELDS (type))
6316 + * TYPE_NFIELDS (type));
6317 + memset (TYPE_FIELDS (type), 0, sizeof (*TYPE_FIELDS (type))
6318 + * TYPE_NFIELDS (type));
6320 + field = TYPE_FIELDS (type);
6321 + child_die = die->child;
6322 + while (child_die && child_die->tag)
6324 + /* Create the symbol in the DW_TAG_common_block block in the current
6326 sym = new_symbol (child_die, NULL, cu);
6328 + /* Undocumented in DWARF3, when it can be present? */
6329 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
6332 @@ -5461,8 +5827,25 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6333 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
6334 add_symbol_to_list (sym, &global_symbols);
6337 + if (SYMBOL_CLASS (sym) == LOC_STATIC)
6338 + SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym));
6340 + SET_FIELD_PHYSNAME (*field, SYMBOL_LINKAGE_NAME (sym));
6341 + FIELD_TYPE (*field) = SYMBOL_TYPE (sym);
6342 + FIELD_NAME (*field) = SYMBOL_NATURAL_NAME (sym);
6344 child_die = sibling_die (child_die);
6347 + /* TYPE_LENGTH (type) is left 0 - it is only a virtual structure even
6348 + with no consecutive address space. */
6350 + sym = new_symbol (die, type, cu);
6351 + /* SYMBOL_VALUE_ADDRESS never gets used as all its fields are static. */
6352 + SYMBOL_VALUE_ADDRESS (sym) = base;
6354 + set_die_type (die, type, cu);
6358 @@ -5530,7 +5913,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6361 const char *previous_prefix = determine_prefix (die, cu);
6362 - cp_add_using_directive (previous_prefix, TYPE_NAME (type));
6363 + cp_add_using_directive (previous_prefix, TYPE_NAME (type), "", "", dwarf2_read_decl_line(die, cu));
6367 @@ -5546,20 +5929,155 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6371 -/* Read a Fortran module. */
6372 +/* Read a Fortran module as global symbol which can be later looked up by
6373 + f_lookup_symbol_nonlocal. */
6376 read_module (struct die_info *die, struct dwarf2_cu *cu)
6378 - struct die_info *child_die = die->child;
6379 + struct type *type;
6381 + type = read_module_type (die, cu);
6384 + new_symbol (die, type, cu);
6387 +/* Read a Fortran module as type.
6389 + Modules present only as declarations - being used only for DW_AT_import of
6390 + DW_TAG_imported_module - are ignored here. They are read in only in form of
6391 + the module name by read_fortran_imported_module. */
6393 +static struct type *
6394 +read_module_type (struct die_info *die, struct dwarf2_cu *cu)
6396 + struct objfile *objfile = cu->objfile;
6397 + struct die_info *child_die;
6398 + struct type *type;
6399 + char *module_name;
6400 + struct context_stack *new;
6401 + struct pending *save_file_symbols;
6402 + struct pending *save_global_symbols;
6403 + struct pending **save_list_in_scope;
6405 + if (die_is_declaration (die, cu))
6408 + module_name = dwarf2_name (die, cu);
6410 + complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
6412 + type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
6414 + /* Create a context for reading the module variables. */
6416 - /* FIXME: Support the separate Fortran module namespaces. */
6417 + new = push_context (0, 0);
6419 + save_file_symbols = file_symbols;
6420 + file_symbols = NULL;
6421 + save_global_symbols = global_symbols;
6422 + global_symbols = NULL;
6423 + save_list_in_scope = cu->list_in_scope;
6425 + /* Process the child DIEs. */
6427 + child_die = die->child;
6428 while (child_die && child_die->tag)
6430 + /* Any DW_TAG_subprogram will reset LIST_IN_SCOPE to LOCAL_SYMBOLS. */
6431 + cu->list_in_scope = &global_symbols;
6433 process_die (child_die, cu);
6434 child_die = sibling_die (child_die);
6437 + /* Finish this module and restore the context. */
6439 + TYPE_MODULE_BLOCK (type) = finish_block (NULL, &global_symbols,
6440 + new->old_blocks, 0, 0, objfile);
6443 + complaint (&symfile_complaints, _("DW_TAG_module contains static symbols"));
6444 + if (local_symbols)
6445 + complaint (&symfile_complaints, _("DW_TAG_module contains local symbols"));
6446 + if (param_symbols)
6447 + complaint (&symfile_complaints, _("DW_TAG_module contains function "
6450 + file_symbols = save_file_symbols;
6451 + global_symbols = save_global_symbols;
6452 + cu->list_in_scope = save_list_in_scope;
6456 + set_die_type (die, type, cu);
6461 +/* Import a Fortran module. Only store the module name for its later lookup by
6462 + f_lookup_symbol_nonlocal. */
6465 +read_fortran_imported_module (struct die_info *die, struct dwarf2_cu *cu)
6467 + struct objfile *objfile = cu->objfile;
6468 + struct attribute *attr;
6469 + struct die_info *module_die;
6470 + char *module_name;
6471 + struct fortran_using *use;
6473 + attr = dwarf2_attr (die, DW_AT_import, cu);
6477 + module_die = follow_die_ref (die, attr, &cu);
6478 + module_name = dwarf2_name (module_die, cu);
6479 + if (module_name == NULL)
6481 + complaint (&symfile_complaints,
6482 + _("Imported DIE at offset 0x%x has no name"), die->offset);
6486 + /* Fortran does not allow any duplicity between local and any of the imported
6487 + symbols. Therefore the order of the USE statements is not portant.
6489 + Error: Name 'X' at (1) is an ambiguous reference to 'X' from module 'Y' */
6491 + use = obstack_alloc (&objfile->objfile_obstack, sizeof (*use)
6492 + + strlen (module_name));
6493 + strcpy (use->module_name, module_name);
6494 + gdb_assert (cu->language == language_fortran);
6495 + use->next = cu->language_specific.fortran.use;
6496 + cu->language_specific.fortran.use = use;
6499 +/* Import a single Fortran declaration and possibly rename it. */
6502 +read_fortran_imported_declaration (struct die_info *die, struct dwarf2_cu *cu)
6504 + struct attribute *attr;
6505 + struct die_info *imported_die;
6506 + struct symbol *sym;
6507 + char *rename = dwarf2_name (die, cu);
6509 + attr = dwarf2_attr (die, DW_AT_import, cu);
6512 + complaint (&symfile_complaints,
6513 + _("Fortran DW_TAG_imported_declaration is missing "
6514 + "DW_AT_import at offset 0x%x"), die->offset);
6517 + imported_die = follow_die_ref (die, attr, &cu);
6519 + sym = new_symbol (imported_die, NULL, cu);
6521 + if (sym && rename)
6522 + (sym)->ginfo.language_specific.cplus_specific.demangled_name = rename;
6525 /* Return the name of the namespace represented by DIE. Set
6526 @@ -5724,29 +6242,113 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
6527 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6528 struct type *type, *range_type, *index_type, *char_type;
6529 struct attribute *attr;
6530 - unsigned int length;
6533 + index_type = objfile_type (objfile)->builtin_int;
6534 + /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type. */
6535 + range_type = alloc_type (objfile, NULL);
6536 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
6537 + range_type = create_range_type (range_type, index_type, 0, -1);
6539 + /* C/C++ should probably have the low bound 0 but C/C++ does not use
6540 + DW_TAG_string_type. */
6541 + TYPE_LOW_BOUND (range_type) = 1;
6543 attr = dwarf2_attr (die, DW_AT_string_length, cu);
6546 - length = DW_UNSND (attr);
6547 + if (attr && attr_form_is_block (attr))
6549 + /* Security check for a size overflow. */
6550 + if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
6551 + TYPE_HIGH_BOUND (range_type) = 1;
6552 + /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
6553 + instruction as DW_AT_string_length specifies the length location, not
6557 + struct dwarf2_locexpr_baton *length_baton = NULL;
6558 + struct dwarf_block *blk = DW_BLOCK (attr);
6560 + /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
6561 + DW_OP_deref* in such case. */
6563 + if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
6564 + && blk->data[0] <= DW_OP_reg31)
6565 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
6566 + else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
6568 + ULONGEST ulongest;
6571 + end = read_uleb128 (&blk->data[1], &blk->data[blk->size],
6573 + if (end == &blk->data[blk->size])
6574 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
6577 + if (length_baton == NULL)
6579 + struct attribute *size_attr;
6581 + length_baton = obstack_alloc (&cu->comp_unit_obstack,
6582 + sizeof (*length_baton));
6583 + length_baton->per_cu = cu->per_cu;
6584 + length_baton->size = DW_BLOCK (attr)->size + 2;
6585 + length_baton->data = obstack_alloc (&cu->comp_unit_obstack,
6586 + length_baton->size);
6587 + memcpy (length_baton->data, DW_BLOCK (attr)->data,
6588 + DW_BLOCK (attr)->size);
6590 + /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
6591 + specifies the size of an integer to fetch. */
6592 + size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6595 + length_baton->data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
6596 + length_baton->data[DW_BLOCK (attr)->size + 1] =
6597 + DW_UNSND (size_attr);
6598 + if (length_baton->data[DW_BLOCK (attr)->size + 1]
6599 + != DW_UNSND (size_attr))
6600 + complaint (&symfile_complaints,
6601 + _("DW_AT_string_length's DW_AT_byte_size "
6602 + "integer exceeds the byte size storage"));
6606 + length_baton->data[DW_BLOCK (attr)->size] = DW_OP_deref;
6607 + length_baton->data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
6611 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6612 + TYPE_FIELD_DWARF_BLOCK (range_type, 1) = length_baton;
6613 + TYPE_DYNAMIC (range_type) = 1;
6618 - /* check for the DW_AT_byte_size attribute */
6619 + if (attr && attr_form_is_constant (attr))
6621 + /* We currently do not support a constant address where the location
6622 + should be read from - attr_form_is_block is expected instead. See
6623 + DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
6628 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6631 - length = DW_UNSND (attr);
6633 + if (attr && attr_form_is_block (attr))
6635 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6636 + TYPE_FIELD_DWARF_BLOCK (range_type, 1) =
6637 + dwarf2_attr_to_locexpr_baton (attr, cu);
6638 + TYPE_DYNAMIC (range_type) = 1;
6640 + else if (attr && attr_form_is_constant (attr))
6641 + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6646 + TYPE_HIGH_BOUND (range_type) = 1;
6649 - index_type = objfile_type (objfile)->builtin_int;
6650 - range_type = create_range_type (NULL, index_type, 1, length);
6651 char_type = language_string_char_type (cu->language_defn, gdbarch);
6652 type = create_string_type (NULL, char_type, range_type);
6654 @@ -5841,7 +6443,6 @@ static struct type *
6655 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
6657 struct objfile *objfile = cu->objfile;
6658 - struct attribute *attr;
6659 const char *name = NULL;
6660 struct type *this_type;
6662 @@ -5949,8 +6550,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6663 struct type *base_type;
6664 struct type *range_type;
6665 struct attribute *attr;
6671 base_type = die_type (die, cu);
6672 @@ -5963,42 +6563,89 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6673 0, NULL, cu->objfile);
6676 - if (cu->language == language_fortran)
6678 - /* FORTRAN implies a lower bound of 1, if not given. */
6681 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
6682 + range_type = create_range_type (NULL, base_type, 0, -1);
6684 - /* FIXME: For variable sized arrays either of these could be
6685 - a variable rather than a constant value. We'll allow it,
6686 - but we don't know how to handle it. */
6687 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
6689 - low = dwarf2_get_attr_constant_value (attr, 0);
6690 + if (attr && attr_form_is_block (attr))
6692 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 0);
6693 + TYPE_FIELD_DWARF_BLOCK (range_type, 0) = dwarf2_attr_to_locexpr_baton
6695 + TYPE_DYNAMIC (range_type) = 1;
6696 + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */
6701 + if (attr && attr_form_is_constant (attr))
6702 + low = dwarf2_get_attr_constant_value (attr, 0);
6705 + if (cu->language == language_fortran)
6707 + /* FORTRAN implies a lower bound of 1, if not given. */
6712 + /* According to DWARF we should assume the value 0 only for
6713 + LANGUAGE_C and LANGUAGE_CPLUS. */
6717 + TYPE_LOW_BOUND (range_type) = low;
6719 + TYPE_UNSIGNED (range_type) = 1;
6722 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
6725 - if (attr->form == DW_FORM_block1)
6727 - /* GCC encodes arrays with unspecified or dynamic length
6728 - with a DW_FORM_block1 attribute.
6729 - FIXME: GDB does not yet know how to handle dynamic
6730 - arrays properly, treat them as arrays with unspecified
6733 - FIXME: jimb/2003-09-22: GDB does not really know
6734 - how to handle arrays of unspecified length
6735 - either; we just represent them as zero-length
6736 - arrays. Choose an appropriate upper bound given
6737 - the lower bound we've computed above. */
6740 + if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)))
6742 + attr = dwarf2_attr (die, DW_AT_count, cu);
6743 + /* It does not hurt but it is needlessly ineffective in check_typedef. */
6744 + if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
6746 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
6747 + TYPE_DYNAMIC (range_type) = 1;
6749 + /* Pass it now as the regular DW_AT_upper_bound. */
6752 + if (attr && attr_form_is_block (attr))
6754 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6755 + TYPE_FIELD_DWARF_BLOCK (range_type, 1) = dwarf2_attr_to_locexpr_baton
6757 + TYPE_DYNAMIC (range_type) = 1;
6761 + if (attr && attr_form_is_constant (attr))
6762 + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6764 - high = dwarf2_get_attr_constant_value (attr, 1);
6766 + TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type) = 1;
6767 + TYPE_HIGH_BOUND (range_type) = low - 1;
6771 - range_type = create_range_type (NULL, base_type, low, high);
6772 + /* DW_AT_bit_stride is currently unsupported as we count in bytes. */
6773 + attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
6774 + if (attr && attr_form_is_block (attr))
6776 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 2);
6777 + TYPE_FIELD_DWARF_BLOCK (range_type, 2) = dwarf2_attr_to_locexpr_baton
6779 + TYPE_DYNAMIC (range_type) = 1;
6781 + else if (attr && attr_form_is_constant (attr))
6783 + TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6784 + if (TYPE_BYTE_STRIDE (range_type) == 0)
6785 + complaint (&symfile_complaints,
6786 + _("Found DW_AT_byte_stride with unsupported value 0"));
6789 name = dwarf2_name (die, cu);
6791 @@ -6469,6 +7116,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
6792 && abbrev->tag != DW_TAG_lexical_block
6793 && abbrev->tag != DW_TAG_variable
6794 && abbrev->tag != DW_TAG_namespace
6795 + && abbrev->tag != DW_TAG_module
6796 && abbrev->tag != DW_TAG_member)
6798 /* Otherwise we skip to the next sibling, if any. */
6799 @@ -6689,9 +7337,6 @@ read_partial_die (struct partial_die_info *part_die,
6800 if (part_die->dirname == NULL)
6801 part_die->dirname = DW_STRING (&attr);
6803 - case DW_AT_MIPS_linkage_name:
6804 - part_die->name = DW_STRING (&attr);
6807 has_low_pc_attr = 1;
6808 part_die->lowpc = DW_ADDR (&attr);
6809 @@ -6923,7 +7568,8 @@ fixup_partial_die (struct partial_die_info *part_die,
6810 /* If we found a reference attribute and the DIE has no name, try
6811 to find a name in the referred to DIE. */
6813 - if (part_die->name == NULL && part_die->has_specification)
6814 + if (part_die->has_specification
6815 + && (part_die->name == NULL || !part_die->is_external))
6817 struct partial_die_info *spec_die;
6819 @@ -8265,10 +8911,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
6820 (i.e. when the value of a register or memory location is
6821 referenced, or a thread-local block, etc.). Then again, it might
6822 not be worthwhile. I'm assuming that it isn't unless performance
6823 - or memory numbers show me otherwise. */
6824 + or memory numbers show me otherwise.
6826 + SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed. */
6828 - dwarf2_symbol_mark_computed (attr, sym, cu);
6829 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6830 + dwarf2_symbol_mark_computed (attr, sym, cu);
6833 /* Given a pointer to a DWARF information entry, figure out if we need
6834 @@ -8290,21 +8938,30 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6836 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6838 - if (die->tag != DW_TAG_namespace)
6839 - name = dwarf2_linkage_name (die, cu);
6841 - name = TYPE_NAME (type);
6843 + name = dwarf2_name (die, cu);
6846 + const char *linkagename;
6848 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6849 sizeof (struct symbol));
6850 OBJSTAT (objfile, n_syms++);
6851 memset (sym, 0, sizeof (struct symbol));
6852 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
6853 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
6855 - /* Cache this symbol's name and the name's demangled form (if any). */
6856 SYMBOL_LANGUAGE (sym) = cu->language;
6857 - SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6859 + /* Cache this symbol's name and the name's demangled form (if any). */
6861 + linkagename = dwarf2_physname (die, cu);
6862 + SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), objfile);
6863 + if (cu->language == language_fortran)
6865 + (sym)->ginfo.language_specific.cplus_specific.demangled_name =
6866 + SYMBOL_LINKAGE_NAME (sym);
6867 + SYMBOL_LINKAGE_NAME (sym) = fortran_module_linkage_name (die, cu);
6870 /* Default assumptions.
6871 Use the passed type or decode it from the die. */
6872 @@ -8402,9 +9059,28 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6875 var_decode_location (attr, sym, cu);
6877 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6879 + /* Fortran explicitely imports any global symbols to the local
6880 + scope by DW_TAG_common_block. */
6881 + if (cu->language == language_fortran && die->parent
6882 + && die->parent->tag == DW_TAG_common_block)
6885 if (attr2 && (DW_UNSND (attr2) != 0))
6886 - add_symbol_to_list (sym, &global_symbols);
6888 + /* Workaround gfortran PR debug/40040 - it uses
6889 + DW_AT_location for variables in -fPIC libraries which may
6890 + get overriden by other libraries/executable and get
6891 + a different address. Resolve it by .dynsym instead. */
6893 + if (cu->language == language_fortran && die->parent
6894 + && die->parent->tag == DW_TAG_module)
6895 + SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6897 + add_symbol_to_list (sym, &global_symbols);
6900 add_symbol_to_list (sym, cu->list_in_scope);
6902 @@ -8534,7 +9210,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6903 add_symbol_to_list (sym, cu->list_in_scope);
6905 case DW_TAG_enumerator:
6906 - SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
6907 + SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_name (die, cu);
6908 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6911 @@ -8558,6 +9234,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6912 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6913 add_symbol_to_list (sym, &global_symbols);
6915 + case DW_TAG_common_block:
6916 + SYMBOL_CLASS (sym) = LOC_STATIC;
6917 + SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
6918 + add_symbol_to_list (sym, cu->list_in_scope);
6920 + case DW_TAG_module:
6921 + SYMBOL_CLASS (sym) = LOC_STATIC;
6922 + SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
6923 + add_symbol_to_list (sym, &global_symbols);
6926 /* Not a tag we recognize. Hopefully we aren't processing
6927 trash data, but since we must specifically ignore things
6928 @@ -8571,8 +9257,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6929 /* For the benefit of old versions of GCC, check for anonymous
6930 namespaces based on the demangled name. */
6931 if (!processing_has_namespace_info
6932 - && cu->language == language_cplus
6933 - && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
6934 + && cu->language == language_cplus)
6935 cp_scan_for_anonymous_namespaces (sym);
6938 @@ -8823,12 +9508,18 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6939 case DW_TAG_namespace:
6940 this_type = read_namespace_type (die, cu);
6942 + case DW_TAG_module:
6943 + this_type = read_module_type (die, cu);
6946 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
6947 dwarf_tag_name (die->tag));
6952 + finalize_type (this_type);
6957 @@ -8910,10 +9601,100 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6958 So it does not need a prefix. */
6961 - return determine_prefix (parent, cu);
6962 + return determine_prefix (parent, cu);
6966 +/* Determines the prefix for a symbol's physname. Unlike determine_prefix,
6967 + this method does not simply look at the DIE's immediate parent.
6968 + It will compute the symbol's physname by scanning through all parent
6969 + DIEs until it gets to the compilation unit's DIE. */
6972 +physname_prefix (struct die_info *die, struct dwarf2_cu *cu)
6975 + struct ui_file *buf;
6976 + struct die_info *d, *spec_die;
6977 + struct dwarf2_cu *spec_cu;
6980 + /* Construct a stack containing all of the DIE's parents. Caution
6981 + must be observed for dealing with DW_AT_specification. */
6983 + spec_die = die_specification (die, &spec_cu);
6984 + if (spec_die != NULL)
6985 + d = spec_die->parent;
6988 + while (d != NULL && d->tag != DW_TAG_compile_unit)
6990 + struct attribute *attr;
6992 + spec_die = die_specification (d, &spec_cu);
6993 + if (spec_die != NULL)
6996 + VEC_quick_push (die_info_p, die_list, d);
7000 + /* Now pop all the elements, printing their names as we go. */
7001 + buf = mem_fileopen ();
7002 + while (!VEC_empty (die_info_p, die_list))
7004 + d = VEC_pop (die_info_p, die_list);
7005 + physname_prefix_1 (buf, d, cu);
7007 + if (!VEC_empty (die_info_p, die_list))
7009 + if (cu->language == language_cplus)
7010 + fputs_unfiltered ("::", buf);
7012 + fputs_unfiltered (".", buf);
7016 + name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, &length);
7017 + ui_file_delete (buf);
7022 +physname_prefix_1 (struct ui_file *buf, struct die_info *die,
7023 + struct dwarf2_cu *cu)
7025 + const char *name = NULL;
7026 + gdb_assert (buf != NULL);
7032 + case DW_TAG_namespace:
7033 + name = dwarf2_name (die, cu);
7035 + name = "(anonymous namespace)";
7038 + case DW_TAG_class_type:
7039 + case DW_TAG_structure_type:
7040 + case DW_TAG_union_type:
7041 + case DW_TAG_enumeration_type:
7042 + case DW_TAG_interface_type:
7043 + case DW_TAG_subprogram:
7044 + name = dwarf2_name (die, cu);
7053 + fputs_unfiltered (name, buf);
7056 /* Return a newly-allocated string formed by concatenating PREFIX and
7057 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7058 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7059 @@ -8963,17 +9744,111 @@ sibling_die (struct die_info *die)
7060 return die->sibling;
7063 -/* Get linkage name of a die, return NULL if not found. */
7064 +/* Construct a physname for the given DIE in CU. */
7067 -dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7068 +dwarf2_physname (struct die_info *die, struct dwarf2_cu *cu)
7070 struct attribute *attr;
7073 + name = dwarf2_name (die, cu);
7075 + /* These are the only languages we know how to qualify names in. */
7076 + if (cu->language != language_cplus
7077 + && cu->language != language_java)
7080 + if (die_needs_namespace (die, cu))
7084 + struct ui_file *buf;
7086 + prefix = physname_prefix (die, cu);
7087 + buf = mem_fileopen ();
7088 + if (*prefix != '\0')
7090 + char *prefixed_name = typename_concat (NULL, prefix, name, cu);
7091 + fputs_unfiltered (prefixed_name, buf);
7092 + xfree (prefixed_name);
7095 + fputs_unfiltered (name ? name : "", buf);
7097 + /* For Java and C++ methods, append formal parameter type
7099 + if ((cu->language == language_cplus || cu->language == language_java)
7100 + && die->tag == DW_TAG_subprogram)
7102 + struct type *type = read_type_die (die, cu);
7104 + c_type_print_args (type, buf, 0, cu->language);
7106 + if (cu->language == language_java)
7108 + /* For java, we must append the return type to method names. */
7109 + if (die->tag == DW_TAG_subprogram)
7110 + java_print_type (TYPE_TARGET_TYPE (type), "", buf, 0, 0);
7112 + else if (cu->language == language_cplus)
7114 + /* c_type_print_args adds argument types, but it does
7115 + not add any necessary "const". */
7116 + if (TYPE_NFIELDS (type) > 0 && TYPE_FIELD_ARTIFICIAL (type, 0)
7117 + && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
7118 + fputs_unfiltered (" const", buf);
7122 + name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
7124 + ui_file_delete (buf);
7126 + if (cu->language == language_cplus)
7129 + = dwarf2_canonicalize_name (name, cu,
7130 + &cu->objfile->objfile_obstack);
7131 + if (cname != NULL)
7139 +/* Return the fully qualified .symtab name for symbols contained in Fortran
7140 + modules. Return DWARF2_NAME otherwise. */
7143 +fortran_module_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7147 + gdb_assert (cu->language == language_fortran);
7149 + name = dwarf2_name (die, cu);
7151 + if (name && die->parent && die->parent->tag == DW_TAG_module)
7153 + char *module_name = dwarf2_name (die->parent, cu);
7159 - attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7160 - if (attr && DW_STRING (attr))
7161 - return DW_STRING (attr);
7162 - return dwarf2_name (die, cu);
7163 + /* `__modulename_MOD_variablename0'. */
7164 + retval = obstack_alloc (&cu->objfile->objfile_obstack,
7165 + 2 + strlen (module_name) + 5 + strlen (name)
7167 + sprintf (retval, "__%s_MOD_%s", module_name, name);
7176 /* Get name of a die, return NULL if not found. */
7177 @@ -10200,11 +11075,11 @@ dwarf2_get_ref_die_offset (struct attribute *attr)
7181 -/* Return the constant value held by the given attribute. Return -1
7182 +/* Return the constant value held by the given attribute. Return DEFAULT_VALUE
7183 if the value held by the attribute is not constant. */
7186 -dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7188 +dwarf2_get_attr_constant_value (struct attribute *attr, CORE_ADDR default_value)
7190 if (attr->form == DW_FORM_sdata)
7191 return DW_SND (attr);
7192 @@ -11009,8 +11884,6 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7194 gdb_byte *mac_ptr, *mac_end;
7195 struct macro_source_file *current_file = 0;
7196 - enum dwarf_macinfo_record_type macinfo_type;
7197 - int at_commandline;
7199 if (dwarf2_per_objfile->macinfo.buffer == NULL)
7201 @@ -11018,29 +11891,19 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7205 - /* First pass: Find the name of the base filename.
7206 - This filename is needed in order to process all macros whose definition
7207 - (or undefinition) comes from the command line. These macros are defined
7208 - before the first DW_MACINFO_start_file entry, and yet still need to be
7209 - associated to the base file.
7211 - To determine the base file name, we scan the macro definitions until we
7212 - reach the first DW_MACINFO_start_file entry. We then initialize
7213 - CURRENT_FILE accordingly so that any macro definition found before the
7214 - first DW_MACINFO_start_file can still be associated to the base file. */
7216 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
7217 mac_end = dwarf2_per_objfile->macinfo.buffer
7218 + dwarf2_per_objfile->macinfo.size;
7223 + enum dwarf_macinfo_record_type macinfo_type;
7225 /* Do we at least have room for a macinfo type byte? */
7226 if (mac_ptr >= mac_end)
7228 - /* Complaint is printed during the second pass as GDB will probably
7229 - stop the first pass earlier upon finding DW_MACINFO_start_file. */
7231 + dwarf2_macros_too_long_complaint ();
7235 macinfo_type = read_1_byte (abfd, mac_ptr);
7236 @@ -11051,92 +11914,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7237 /* A zero macinfo type indicates the end of the macro
7242 - case DW_MACINFO_define:
7243 - case DW_MACINFO_undef:
7244 - /* Only skip the data by MAC_PTR. */
7246 - unsigned int bytes_read;
7248 - read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7249 - mac_ptr += bytes_read;
7250 - read_string (abfd, mac_ptr, &bytes_read);
7251 - mac_ptr += bytes_read;
7255 - case DW_MACINFO_start_file:
7257 - unsigned int bytes_read;
7260 - line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7261 - mac_ptr += bytes_read;
7262 - file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7263 - mac_ptr += bytes_read;
7265 - current_file = macro_start_file (file, line, current_file, comp_dir,
7270 - case DW_MACINFO_end_file:
7271 - /* No data to skip by MAC_PTR. */
7274 - case DW_MACINFO_vendor_ext:
7275 - /* Only skip the data by MAC_PTR. */
7277 - unsigned int bytes_read;
7279 - read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7280 - mac_ptr += bytes_read;
7281 - read_string (abfd, mac_ptr, &bytes_read);
7282 - mac_ptr += bytes_read;
7289 - } while (macinfo_type != 0 && current_file == NULL);
7291 - /* Second pass: Process all entries.
7293 - Use the AT_COMMAND_LINE flag to determine whether we are still processing
7294 - command-line macro definitions/undefinitions. This flag is unset when we
7295 - reach the first DW_MACINFO_start_file entry. */
7297 - mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
7299 - /* Determines if GDB is still before first DW_MACINFO_start_file. If true
7300 - GDB is still reading the definitions from command line. First
7301 - DW_MACINFO_start_file will need to be ignored as it was already executed
7302 - to create CURRENT_FILE for the main source holding also the command line
7303 - definitions. On first met DW_MACINFO_start_file this flag is reset to
7304 - normally execute all the remaining DW_MACINFO_start_file macinfos. */
7306 - at_commandline = 1;
7310 - /* Do we at least have room for a macinfo type byte? */
7311 - if (mac_ptr >= mac_end)
7313 - dwarf2_macros_too_long_complaint ();
7317 - macinfo_type = read_1_byte (abfd, mac_ptr);
7320 - switch (macinfo_type)
7322 - /* A zero macinfo type indicates the end of the macro
7328 case DW_MACINFO_define:
7329 case DW_MACINFO_undef:
7330 @@ -11151,31 +11929,19 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7331 mac_ptr += bytes_read;
7335 - /* DWARF violation as no main source is present. */
7336 - complaint (&symfile_complaints,
7337 - _("debug info with no main source gives macro %s "
7338 - "on line %d: %s"),
7340 - DW_MACINFO_define ? _("definition") : macinfo_type ==
7341 - DW_MACINFO_undef ? _("undefinition") :
7342 - "something-or-other", line, body);
7345 - if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
7346 complaint (&symfile_complaints,
7347 - _("debug info gives %s macro %s with %s line %d: %s"),
7348 - at_commandline ? _("command-line") : _("in-file"),
7349 + _("debug info gives macro %s outside of any file: %s"),
7351 - DW_MACINFO_define ? _("definition") : macinfo_type ==
7352 - DW_MACINFO_undef ? _("undefinition") :
7353 - "something-or-other",
7354 - line == 0 ? _("zero") : _("non-zero"), line, body);
7356 - if (macinfo_type == DW_MACINFO_define)
7357 - parse_macro_definition (current_file, line, body);
7358 - else if (macinfo_type == DW_MACINFO_undef)
7359 - macro_undef (current_file, line, body);
7360 + DW_MACINFO_define ? "definition" : macinfo_type ==
7361 + DW_MACINFO_undef ? "undefinition" :
7362 + "something-or-other", body);
7365 + if (macinfo_type == DW_MACINFO_define)
7366 + parse_macro_definition (current_file, line, body);
7367 + else if (macinfo_type == DW_MACINFO_undef)
7368 + macro_undef (current_file, line, body);
7373 @@ -11189,22 +11955,9 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7374 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7375 mac_ptr += bytes_read;
7377 - if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
7378 - complaint (&symfile_complaints,
7379 - _("debug info gives source %d included "
7380 - "from %s at %s line %d"),
7381 - file, at_commandline ? _("command-line") : _("file"),
7382 - line == 0 ? _("zero") : _("non-zero"), line);
7384 - if (at_commandline)
7386 - /* This DW_MACINFO_start_file was executed in the pass one. */
7387 - at_commandline = 0;
7390 - current_file = macro_start_file (file, line,
7391 - current_file, comp_dir,
7393 + current_file = macro_start_file (file, line,
7394 + current_file, comp_dir,
7399 @@ -11258,7 +12011,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7403 - } while (macinfo_type != 0);
7407 /* Check if the attribute's form is a DW_FORM_block*
7408 @@ -11318,6 +12071,34 @@ attr_form_is_constant (struct attribute *attr)
7412 +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton. ATTR must be a DW_BLOCK
7413 + attribute type. */
7415 +static struct dwarf2_locexpr_baton *
7416 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
7418 + struct dwarf2_locexpr_baton *baton;
7420 + gdb_assert (attr_form_is_block (attr));
7422 + baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton));
7423 + baton->per_cu = cu->per_cu;
7424 + gdb_assert (baton->per_cu);
7426 + /* Note that we're just copying the block's data pointer
7427 + here, not the actual data. We're still pointing into the
7428 + info_buffer for SYM's objfile; right now we never release
7429 + that buffer, but when we do clean up properly this may
7430 + need to change. */
7431 + baton->size = DW_BLOCK (attr)->size;
7432 + baton->data = DW_BLOCK (attr)->data;
7433 + gdb_assert (baton->size == 0 || baton->data != NULL);
7438 +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content. */
7441 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7442 struct dwarf2_cu *cu)
7443 @@ -11347,35 +12128,25 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7444 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
7445 SYMBOL_LOCATION_BATON (sym) = baton;
7447 + else if (attr_form_is_block (attr))
7449 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
7450 + SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
7454 - struct dwarf2_locexpr_baton *baton;
7455 + dwarf2_invalid_attrib_class_complaint ("location description",
7456 + SYMBOL_NATURAL_NAME (sym));
7458 - baton = obstack_alloc (&cu->objfile->objfile_obstack,
7459 - sizeof (struct dwarf2_locexpr_baton));
7460 - baton->per_cu = cu->per_cu;
7461 - gdb_assert (baton->per_cu);
7462 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
7464 - if (attr_form_is_block (attr))
7466 - /* Note that we're just copying the block's data pointer
7467 - here, not the actual data. We're still pointing into the
7468 - info_buffer for SYM's objfile; right now we never release
7469 - that buffer, but when we do clean up properly this may
7470 - need to change. */
7471 - baton->size = DW_BLOCK (attr)->size;
7472 - baton->data = DW_BLOCK (attr)->data;
7476 - dwarf2_invalid_attrib_class_complaint ("location description",
7477 - SYMBOL_NATURAL_NAME (sym));
7479 - baton->data = NULL;
7482 - SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
7483 - SYMBOL_LOCATION_BATON (sym) = baton;
7484 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
7485 + SYMBOL_LOCATION_BATON (sym) = NULL;
7487 + /* For functions a missing DW_AT_frame_base does not optimize out the
7488 + whole function definition, only its frame base resolving. */
7489 + if (attr->name == DW_AT_location)
7490 + SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7494 @@ -11663,6 +12434,31 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
7495 return ofs_lhs->offset == ofs_rhs->offset;
7498 +/* Fill in generic attributes applicable for type DIEs. */
7501 +fetch_die_type_attrs (struct die_info *die, struct type *type,
7502 + struct dwarf2_cu *cu)
7504 + struct attribute *attr;
7506 + attr = dwarf2_attr (die, DW_AT_data_location, cu);
7507 + if (attr_form_is_block (attr))
7508 + TYPE_DATA_LOCATION_DWARF_BLOCK (type) = dwarf2_attr_to_locexpr_baton (attr,
7510 + gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
7512 + attr = dwarf2_attr (die, DW_AT_allocated, cu);
7513 + if (attr_form_is_block (attr))
7514 + TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
7515 + gdb_assert (!TYPE_NOT_ALLOCATED (type));
7517 + attr = dwarf2_attr (die, DW_AT_associated, cu);
7518 + if (attr_form_is_block (attr))
7519 + TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
7520 + gdb_assert (!TYPE_NOT_ASSOCIATED (type));
7523 /* Set the type associated with DIE to TYPE. Save it in CU's hash
7524 table if necessary. For convenience, return TYPE. */
7526 @@ -11671,6 +12467,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
7528 struct dwarf2_offset_and_type **slot, ofs;
7530 + fetch_die_type_attrs (die, type, cu);
7532 if (cu->type_hash == NULL)
7534 gdb_assert (cu->per_cu != NULL);
7535 @@ -11813,23 +12611,13 @@ show_dwarf2_cmd (char *args, int from_tty)
7536 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
7539 -/* If section described by INFO was mmapped, munmap it now. */
7540 +/* A helper function to destroy a debug section. */
7543 -munmap_section_buffer (struct dwarf2_section_info *info)
7544 +destroy_section (struct dwarf2_section_info *info)
7546 - if (info->was_mmapped)
7549 - intptr_t begin = (intptr_t) info->buffer;
7550 - intptr_t map_begin = begin & ~(pagesize - 1);
7551 - size_t map_length = info->size + begin - map_begin;
7552 - gdb_assert (munmap ((void *) map_begin, map_length) == 0);
7554 - /* Without HAVE_MMAP, we should never be here to begin with. */
7558 + if (info->destructor)
7559 + (*info->destructor) (info);
7562 /* munmap debug sections for OBJFILE, if necessary. */
7563 @@ -11838,15 +12626,15 @@ static void
7564 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
7566 struct dwarf2_per_objfile *data = d;
7567 - munmap_section_buffer (&data->info);
7568 - munmap_section_buffer (&data->abbrev);
7569 - munmap_section_buffer (&data->line);
7570 - munmap_section_buffer (&data->str);
7571 - munmap_section_buffer (&data->macinfo);
7572 - munmap_section_buffer (&data->ranges);
7573 - munmap_section_buffer (&data->loc);
7574 - munmap_section_buffer (&data->frame);
7575 - munmap_section_buffer (&data->eh_frame);
7576 + destroy_section (&data->info);
7577 + destroy_section (&data->abbrev);
7578 + destroy_section (&data->line);
7579 + destroy_section (&data->str);
7580 + destroy_section (&data->macinfo);
7581 + destroy_section (&data->ranges);
7582 + destroy_section (&data->loc);
7583 + destroy_section (&data->frame);
7584 + destroy_section (&data->eh_frame);
7587 void _initialize_dwarf2_read (void);
7588 @@ -11854,6 +12642,7 @@ void _initialize_dwarf2_read (void);
7590 _initialize_dwarf2_read (void)
7592 + die_list = VEC_alloc (die_info_p, 32);
7593 dwarf2_objfile_data_key
7594 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
7596 diff --git a/gdb/elfread.c b/gdb/elfread.c
7597 index 6e79d4a..198bae3 100644
7600 @@ -728,10 +728,18 @@ elf_symfile_read (struct objfile *objfile, int mainline)
7602 bfd_section_size (abfd, str_sect));
7605 + if (dwarf2_has_info (objfile))
7606 + dwarf2_create_quick_addrmap (objfile);
7610 +read_psyms (struct objfile *objfile)
7612 if (dwarf2_has_info (objfile))
7614 /* DWARF 2 sections */
7615 - dwarf2_build_psymtabs (objfile, mainline);
7616 + dwarf2_build_psymtabs (objfile, 0);
7619 /* FIXME: kettenis/20030504: This still needs to be integrated with
7620 @@ -881,6 +889,7 @@ static struct sym_fns elf_sym_fns =
7621 elf_new_init, /* sym_new_init: init anything gbl to entire symtab */
7622 elf_symfile_init, /* sym_init: read initial info, setup for sym_read() */
7623 elf_symfile_read, /* sym_read: read a symbol file into symtab */
7624 + read_psyms, /* sym_read_psymbols */
7625 elf_symfile_finish, /* sym_finish: finished with file, cleanup */
7626 default_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
7627 elf_symfile_segments, /* sym_segments: Get segment information from
7628 diff --git a/gdb/eval.c b/gdb/eval.c
7629 index 2926465..4c6de78 100644
7633 #include "exceptions.h"
7634 #include "regcache.h"
7635 #include "user-regs.h"
7636 +#include "python/python.h"
7637 #include "valprint.h"
7638 +#include "gdb_obstack.h"
7639 +#include "objfiles.h"
7640 #include "python/python.h"
7641 +#include "dwarf2loc.h"
7643 #include "gdb_assert.h"
7645 @@ -651,6 +655,36 @@ ptrmath_type_p (struct type *type)
7649 +/* Constructs a fake method with the given parameter types. */
7651 +free_param_types (void *arg)
7653 + struct type *type = (struct type *) arg;
7654 + xfree (TYPE_FIELDS (type));
7655 + xfree (TYPE_MAIN_TYPE (type));
7659 +static struct type *
7660 +make_params (int num_types, struct type **param_types)
7662 + struct type *type = XZALLOC (struct type);
7663 + TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
7664 + TYPE_LENGTH (type) = 1;
7665 + TYPE_CODE (type) = TYPE_CODE_METHOD;
7666 + TYPE_VPTR_FIELDNO (type) = -1;
7667 + TYPE_CHAIN (type) = type;
7668 + TYPE_NFIELDS (type) = num_types;
7669 + TYPE_FIELDS (type) = (struct field *)
7670 + TYPE_ZALLOC (type, sizeof (struct field) * num_types);
7672 + while (num_types-- > 0)
7673 + TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
7675 + make_cleanup (free_param_types, type);
7680 evaluate_subexp_standard (struct type *expect_type,
7681 struct expression *exp, int *pos,
7682 @@ -671,6 +705,7 @@ evaluate_subexp_standard (struct type *expect_type,
7684 struct type **arg_types;
7686 + struct cleanup *old_chain;
7689 op = exp->elts[pc].opcode;
7690 @@ -684,7 +719,7 @@ evaluate_subexp_standard (struct type *expect_type,
7692 arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
7693 &exp->elts[pc + 3].string,
7695 + expect_type, 0, noside);
7697 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7699 @@ -1293,7 +1328,6 @@ evaluate_subexp_standard (struct type *expect_type,
7700 argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 3));
7701 if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
7704 /* First, evaluate the structure into arg2 */
7707 @@ -1317,21 +1351,40 @@ evaluate_subexp_standard (struct type *expect_type,
7709 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7711 - if (TYPE_CODE (check_typedef (value_type (arg1)))
7712 - != TYPE_CODE_METHODPTR)
7713 - error (_("Non-pointer-to-member value used in pointer-to-member "
7716 - if (noside == EVAL_AVOID_SIDE_EFFECTS)
7717 + type = check_typedef (value_type (arg1));
7718 + switch (TYPE_CODE (type))
7720 - struct type *method_type = check_typedef (value_type (arg1));
7721 - arg1 = value_zero (method_type, not_lval);
7722 + case TYPE_CODE_METHODPTR:
7723 + if (noside == EVAL_AVOID_SIDE_EFFECTS)
7724 + arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
7726 + arg1 = cplus_method_ptr_to_value (&arg2, arg1);
7728 + /* Now, say which argument to start evaluating from */
7734 + case TYPE_CODE_MEMBERPTR:
7735 + /* Now, convert these values to an address. */
7736 + arg2 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
7739 + mem_offset = value_as_long (arg1);
7741 + arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
7742 + value_as_long (arg2) + mem_offset);
7743 + arg1 = value_ind (arg1);
7748 + error (_("Non-pointer-to-member value used in pointer-to-member "
7752 - arg1 = cplus_method_ptr_to_value (&arg2, arg1);
7754 - /* Now, say which argument to start evaluating from */
7758 else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
7760 @@ -1457,8 +1510,7 @@ evaluate_subexp_standard (struct type *expect_type,
7762 else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
7766 + /* Pointer to member. argvec is already set up. */
7768 else if (op == OP_VAR_VALUE)
7770 @@ -1549,7 +1601,10 @@ evaluate_subexp_standard (struct type *expect_type,
7772 /* First determine the type code we are dealing with. */
7773 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7774 + old_chain = make_cleanup (null_cleanup, 0);
7775 + object_address_set (value_raw_address (arg1));
7776 type = check_typedef (value_type (arg1));
7777 + do_cleanups (old_chain);
7778 code = TYPE_CODE (type);
7780 if (code == TYPE_CODE_PTR)
7781 @@ -1716,6 +1771,37 @@ evaluate_subexp_standard (struct type *expect_type,
7782 error (_("non-pointer-to-member value used in pointer-to-member construct"));
7785 + case TYPE_INSTANCE:
7786 + nargs = longest_to_int (exp->elts[pc + 1].longconst);
7787 + arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
7788 + for (ix = 0; ix < nargs; ++ix)
7789 + arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
7791 + expect_type = make_params (nargs, arg_types);
7792 + *(pos) += 3 + nargs;
7793 + return evaluate_subexp_standard (expect_type, exp, pos, noside);
7795 + case TYPE_INSTANCE_LOOKUP:
7798 + struct symbol *sym;
7799 + struct type **arg_types;
7801 + printf ("TYPE_INSTANCE_LOOKUP\n");
7802 + arg_types = (struct type **) alloca (TYPE_NFIELDS (expect_type)
7803 + * sizeof (struct type *));
7804 + for (i = 0; i < TYPE_NFIELDS (expect_type); ++i)
7805 + arg_types[i] = TYPE_FIELD_TYPE (expect_type, i);
7806 + (void) find_overload_match (arg_types, TYPE_NFIELDS (expect_type),
7807 + NULL /* no need for name */,
7808 + 0 /* not method */,
7809 + 0 /* strict match */,
7810 + NULL, exp->elts[pc + 1].symbol, NULL,
7817 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
7818 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
7819 @@ -1987,13 +2073,19 @@ evaluate_subexp_standard (struct type *expect_type,
7821 int subscript_array[MAX_FORTRAN_DIMS];
7822 int array_size_array[MAX_FORTRAN_DIMS];
7823 + int byte_stride_array[MAX_FORTRAN_DIMS];
7824 int ndimensions = 1, i;
7825 struct type *tmp_type;
7826 int offset_item; /* The array offset where the item lives */
7827 + CORE_ADDR offset_byte; /* byte_stride based offset */
7828 + unsigned element_size;
7830 if (nargs > MAX_FORTRAN_DIMS)
7831 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
7833 + old_chain = make_cleanup (null_cleanup, 0);
7834 + object_address_set (value_raw_address (arg1));
7836 tmp_type = check_typedef (value_type (arg1));
7837 ndimensions = calc_f77_array_dims (type);
7839 @@ -2023,6 +2115,9 @@ evaluate_subexp_standard (struct type *expect_type,
7840 upper = f77_get_upperbound (tmp_type);
7841 lower = f77_get_lowerbound (tmp_type);
7843 + byte_stride_array[nargs - i - 1] =
7844 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
7846 array_size_array[nargs - i - 1] = upper - lower + 1;
7848 /* Zero-normalize subscripts so that offsetting will work. */
7849 @@ -2041,13 +2136,25 @@ evaluate_subexp_standard (struct type *expect_type,
7850 tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
7853 + /* Kept for the f77_get_upperbound / f77_get_lowerbound calls above. */
7854 + do_cleanups (old_chain);
7856 /* Now let us calculate the offset for this item */
7858 - offset_item = subscript_array[ndimensions - 1];
7862 + for (i = ndimensions - 1; i >= 0; --i)
7864 + offset_item *= array_size_array[i];
7865 + if (byte_stride_array[i] == 0)
7866 + offset_item += subscript_array[i];
7868 + offset_byte += subscript_array[i] * byte_stride_array[i];
7871 - for (i = ndimensions - 1; i > 0; --i)
7873 - array_size_array[i - 1] * offset_item + subscript_array[i - 1];
7874 + element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tmp_type));
7875 + offset_byte += offset_item * element_size;
7877 /* Let us now play a dirty trick: we will take arg1
7878 which is a value node pointing to the topmost level
7879 @@ -2057,7 +2164,7 @@ evaluate_subexp_standard (struct type *expect_type,
7880 returns the correct type value */
7882 deprecated_set_value_type (arg1, tmp_type);
7883 - return value_subscripted_rvalue (arg1, offset_item, 0);
7884 + return value_subscripted_rvalue (arg1, offset_byte);
7887 case BINOP_LOGICAL_AND:
7888 @@ -2598,7 +2705,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
7889 (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
7890 x = value_aggregate_elt (exp->elts[pc + 1].type,
7891 &exp->elts[pc + 3].string,
7895 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7897 @@ -2643,7 +2750,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
7901 - struct value *val;
7902 + struct value *val = NULL;
7906 @@ -2654,12 +2761,17 @@ evaluate_subexp_with_coercion (struct expression *exp,
7909 var = exp->elts[pc + 2].symbol;
7910 + /* address_of_variable will call object_address_set for check_typedef.
7911 + Call it only if required as it can error-out on VAR in register. */
7912 + if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
7913 + val = address_of_variable (var, exp->elts[pc + 1].block);
7914 type = check_typedef (SYMBOL_TYPE (var));
7915 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
7916 && CAST_IS_CONVERSION)
7919 - val = address_of_variable (var, exp->elts[pc + 1].block);
7921 + val = address_of_variable (var, exp->elts[pc + 1].block);
7922 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
7925 @@ -2711,9 +2823,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
7929 - type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
7931 - value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
7932 + /* We do not need to call read_var_value but the object evaluation may
7933 + need to have executed object_address_set which needs valid
7934 + SYMBOL_VALUE_ADDRESS of the symbol. Still VALUE returned by
7935 + read_var_value we left as lazy. */
7936 + type = value_type (read_var_value (exp->elts[pc + 2].symbol,
7937 + deprecated_safe_get_selected_frame ()));
7938 + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
7941 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
7942 diff --git a/gdb/expression.h b/gdb/expression.h
7943 index effe1f0..3e083ca 100644
7944 --- a/gdb/expression.h
7945 +++ b/gdb/expression.h
7946 @@ -88,6 +88,16 @@ enum exp_opcode
7947 when X is a pointer instead of an aggregate. */
7950 + /* TYPE_INSTANCE is used when the user specifies a specific
7951 + type instantiation for overloaded methods/functions. The format
7952 + is: TYPE_INSTANCE num_types type0 ... typeN num_types TYPE_INSTANCE*/
7955 + /* TYPE_INSTANCE_LOOKUP is used when the user specifies a specific
7956 + type instantiation of a function (not a method). In this case,
7957 + we must toss the results of the parser and manually do the lookup. */
7958 + TYPE_INSTANCE_LOOKUP,
7962 /* For Modula-2 integer division DIV */
7963 @@ -438,4 +448,5 @@ extern char *op_string (enum exp_opcode);
7964 extern void dump_raw_expression (struct expression *, struct ui_file *, char *);
7965 extern void dump_prefix_expression (struct expression *, struct ui_file *);
7968 #endif /* !defined (EXPRESSION_H) */
7969 diff --git a/gdb/f-exp.y b/gdb/f-exp.y
7970 index c04c8f4..ddcd460 100644
7973 @@ -196,6 +196,7 @@ static int parse_number (char *, int, int, YYSTYPE *);
7974 /* Special type cases, put in to allow the parser to distinguish different
7976 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
7977 +%token LOGICAL_S8_KEYWORD
7978 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
7979 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
7980 %token BOOL_AND BOOL_OR BOOL_NOT
7981 @@ -606,6 +607,8 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */
7982 { $$ = parse_f_type->builtin_integer_s2; }
7984 { $$ = parse_f_type->builtin_character; }
7985 + | LOGICAL_S8_KEYWORD
7986 + { $$ = parse_f_type->builtin_logical_s8;}
7988 { $$ = parse_f_type->builtin_logical; }
7989 | LOGICAL_S2_KEYWORD
7990 @@ -858,6 +861,7 @@ static const struct token f77_keywords[] =
7991 { "integer_2", INT_S2_KEYWORD, BINOP_END },
7992 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
7993 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
7994 + { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END },
7995 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
7996 { "integer", INT_KEYWORD, BINOP_END },
7997 { "logical", LOGICAL_KEYWORD, BINOP_END },
7998 diff --git a/gdb/f-lang.c b/gdb/f-lang.c
7999 index 19c1316..4cc2a40 100644
8004 #include "valprint.h"
8007 +#include "gdb_assert.h"
8010 /* Following is dubious stuff that had been in the xcoff reader. */
8011 @@ -55,20 +57,6 @@ typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR;
8012 /* Local functions */
8014 extern void _initialize_f_language (void);
8016 -static void clear_function_list (void);
8017 -static long get_bf_for_fcn (long);
8018 -static void clear_bf_list (void);
8019 -static void patch_all_commons_by_name (char *, CORE_ADDR, int);
8020 -static SAVED_F77_COMMON_PTR find_first_common_named (char *);
8021 -static void add_common_entry (struct symbol *);
8022 -static void add_common_block (char *, CORE_ADDR, int, char *);
8023 -static SAVED_FUNCTION *allocate_saved_function_node (void);
8024 -static SAVED_BF_PTR allocate_saved_bf_node (void);
8025 -static COMMON_ENTRY_PTR allocate_common_entry_node (void);
8026 -static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node (void);
8027 -static void patch_common_entries (SAVED_F77_COMMON_PTR, CORE_ADDR, int);
8030 static void f_printchar (int c, struct type *type, struct ui_file * stream);
8031 static void f_emit_char (int c, struct type *type,
8032 @@ -259,6 +247,7 @@ enum f_primitive_types {
8033 f_primitive_type_logical,
8034 f_primitive_type_logical_s1,
8035 f_primitive_type_logical_s2,
8036 + f_primitive_type_logical_s8,
8037 f_primitive_type_integer,
8038 f_primitive_type_integer_s2,
8039 f_primitive_type_real,
8040 @@ -289,6 +278,8 @@ f_language_arch_info (struct gdbarch *gdbarch,
8041 = builtin->builtin_logical_s1;
8042 lai->primitive_type_vector [f_primitive_type_logical_s2]
8043 = builtin->builtin_logical_s2;
8044 + lai->primitive_type_vector [f_primitive_type_logical_s8]
8045 + = builtin->builtin_logical_s8;
8046 lai->primitive_type_vector [f_primitive_type_real]
8047 = builtin->builtin_real;
8048 lai->primitive_type_vector [f_primitive_type_real_s8]
8049 @@ -306,6 +297,46 @@ f_language_arch_info (struct gdbarch *gdbarch,
8050 lai->bool_type_default = builtin->builtin_logical_s2;
8053 +/* Find if NAME is not contained in any of the Fortran modules imported by the
8054 + Fortran USE statement.
8056 + As Fortran has no nested blocks such lookup can be processed from
8057 + lookup_symbol_nonlocal - when no local blocks could satisfy the lookup. */
8059 +static struct symbol *
8060 +f_lookup_symbol_nonlocal (const char *name,
8061 + const struct block *block,
8062 + const domain_enum domain)
8064 + struct fortran_using *use;
8069 + for (use = BLOCK_FORTRAN_USE (block); use; use = use->next)
8071 + struct symbol *sym;
8072 + struct type *type;
8073 + struct symbol *retval;
8075 + sym = lookup_symbol_global (use->module_name, block, MODULE_DOMAIN);
8077 + /* Module name lookup should not fail with correct debug info. */
8081 + type = SYMBOL_TYPE (sym);
8082 + gdb_assert (TYPE_CODE (type) == TYPE_CODE_MODULE);
8083 + gdb_assert (TYPE_MODULE_BLOCK (type) != NULL);
8085 + retval = lookup_block_symbol (TYPE_MODULE_BLOCK (type), name, domain);
8093 /* This is declared in c-lang.h but it is silly to import that file for what
8094 is already just a hack. */
8095 extern int c_value_print (struct value *, struct ui_file *,
8096 @@ -333,7 +364,7 @@ const struct language_defn f_language_defn =
8097 c_value_print, /* FIXME */
8098 NULL, /* Language specific skip_trampoline */
8099 NULL, /* name_of_this */
8100 - basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8101 + f_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8102 basic_lookup_transparent_type,/* lookup_transparent_type */
8103 NULL, /* Language specific symbol demangler */
8104 NULL, /* Language specific class_name_from_physname */
8105 @@ -372,6 +403,10 @@ build_fortran_types (struct gdbarch *gdbarch)
8106 = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1,
8109 + builtin_f_type->builtin_logical_s8
8110 + = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
8113 builtin_f_type->builtin_integer
8114 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0,
8116 @@ -418,395 +453,3 @@ _initialize_f_language (void)
8118 add_language (&f_language_defn);
8122 -static SAVED_BF_PTR
8123 -allocate_saved_bf_node (void)
8127 - new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
8131 -static SAVED_FUNCTION *
8132 -allocate_saved_function_node (void)
8134 - SAVED_FUNCTION *new;
8136 - new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
8140 -static SAVED_F77_COMMON_PTR
8141 -allocate_saved_f77_common_node (void)
8143 - SAVED_F77_COMMON_PTR new;
8145 - new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
8149 -static COMMON_ENTRY_PTR
8150 -allocate_common_entry_node (void)
8152 - COMMON_ENTRY_PTR new;
8154 - new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
8159 -SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */
8160 -SAVED_F77_COMMON_PTR tail_common_list = NULL; /* Ptr to last saved COMMON */
8161 -SAVED_F77_COMMON_PTR current_common = NULL; /* Ptr to current COMMON */
8164 -static SAVED_BF_PTR saved_bf_list = NULL; /* Ptr to (.bf,function)
8166 -static SAVED_BF_PTR saved_bf_list_end = NULL; /* Ptr to above list's end */
8167 -static SAVED_BF_PTR current_head_bf_list = NULL; /* Current head of above list
8170 -static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use
8173 -/* The following function simply enters a given common block onto
8174 - the global common block chain */
8177 -add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
8179 - SAVED_F77_COMMON_PTR tmp;
8180 - char *c, *local_copy_func_stab;
8182 - /* If the COMMON block we are trying to add has a blank
8183 - name (i.e. "#BLNK_COM") then we set it to __BLANK
8184 - because the darn "#" character makes GDB's input
8185 - parser have fits. */
8188 - if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
8189 - || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
8193 - name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
8194 - strcpy (name, BLANK_COMMON_NAME_LOCAL);
8197 - tmp = allocate_saved_f77_common_node ();
8199 - local_copy_func_stab = xmalloc (strlen (func_stab) + 1);
8200 - strcpy (local_copy_func_stab, func_stab);
8202 - tmp->name = xmalloc (strlen (name) + 1);
8204 - /* local_copy_func_stab is a stabstring, let us first extract the
8205 - function name from the stab by NULLing out the ':' character. */
8209 - c = strchr (local_copy_func_stab, ':');
8214 - error (_("Malformed function STAB found in add_common_block()"));
8217 - tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1);
8219 - strcpy (tmp->owning_function, local_copy_func_stab);
8221 - strcpy (tmp->name, name);
8222 - tmp->offset = offset;
8224 - tmp->entries = NULL;
8225 - tmp->secnum = secnum;
8227 - current_common = tmp;
8229 - if (head_common_list == NULL)
8231 - head_common_list = tail_common_list = tmp;
8235 - tail_common_list->next = tmp;
8236 - tail_common_list = tmp;
8241 -/* The following function simply enters a given common entry onto
8242 - the "current_common" block that has been saved away. */
8246 -add_common_entry (struct symbol *entry_sym_ptr)
8248 - COMMON_ENTRY_PTR tmp;
8252 - /* The order of this list is important, since
8253 - we expect the entries to appear in decl.
8254 - order when we later issue "info common" calls */
8256 - tmp = allocate_common_entry_node ();
8259 - tmp->symbol = entry_sym_ptr;
8261 - if (current_common == NULL)
8262 - error (_("Attempt to add COMMON entry with no block open!"));
8265 - if (current_common->entries == NULL)
8267 - current_common->entries = tmp;
8268 - current_common->end_of_entries = tmp;
8272 - current_common->end_of_entries->next = tmp;
8273 - current_common->end_of_entries = tmp;
8279 -/* This routine finds the first encountred COMMON block named "name" */
8282 -static SAVED_F77_COMMON_PTR
8283 -find_first_common_named (char *name)
8286 - SAVED_F77_COMMON_PTR tmp;
8288 - tmp = head_common_list;
8290 - while (tmp != NULL)
8292 - if (strcmp (tmp->name, name) == 0)
8301 -/* This routine finds the first encountred COMMON block named "name"
8302 - that belongs to function funcname */
8304 -SAVED_F77_COMMON_PTR
8305 -find_common_for_function (char *name, char *funcname)
8308 - SAVED_F77_COMMON_PTR tmp;
8310 - tmp = head_common_list;
8312 - while (tmp != NULL)
8314 - if (strcmp (tmp->name, name) == 0
8315 - && strcmp (tmp->owning_function, funcname) == 0)
8326 -/* The following function is called to patch up the offsets
8327 - for the statics contained in the COMMON block named
8331 -patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
8333 - COMMON_ENTRY_PTR entry;
8335 - blk->offset = offset; /* Keep this around for future use. */
8337 - entry = blk->entries;
8339 - while (entry != NULL)
8341 - SYMBOL_VALUE (entry->symbol) += offset;
8342 - SYMBOL_SECTION (entry->symbol) = secnum;
8344 - entry = entry->next;
8346 - blk->secnum = secnum;
8349 -/* Patch all commons named "name" that need patching.Since COMMON
8350 - blocks occur with relative infrequency, we simply do a linear scan on
8351 - the name. Eventually, the best way to do this will be a
8352 - hashed-lookup. Secnum is the section number for the .bss section
8353 - (which is where common data lives). */
8356 -patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
8359 - SAVED_F77_COMMON_PTR tmp;
8361 - /* For blank common blocks, change the canonical reprsentation
8362 - of a blank name */
8364 - if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
8365 - || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
8368 - name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
8369 - strcpy (name, BLANK_COMMON_NAME_LOCAL);
8372 - tmp = head_common_list;
8374 - while (tmp != NULL)
8376 - if (COMMON_NEEDS_PATCHING (tmp))
8377 - if (strcmp (tmp->name, name) == 0)
8378 - patch_common_entries (tmp, offset, secnum);
8385 -/* This macro adds the symbol-number for the start of the function
8386 - (the symbol number of the .bf) referenced by symnum_fcn to a
8387 - list. This list, in reality should be a FIFO queue but since
8388 - #line pragmas sometimes cause line ranges to get messed up
8389 - we simply create a linear list. This list can then be searched
8390 - first by a queueing algorithm and upon failure fall back to
8394 -#define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
8396 - if (saved_bf_list == NULL) \
8398 - tmp_bf_ptr = allocate_saved_bf_node(); \
8400 - tmp_bf_ptr->symnum_bf = (bf_sym); \
8401 - tmp_bf_ptr->symnum_fcn = (fcn_sym); \
8402 - tmp_bf_ptr->next = NULL; \
8404 - current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
8405 - saved_bf_list_end = tmp_bf_ptr; \
8409 - tmp_bf_ptr = allocate_saved_bf_node(); \
8411 - tmp_bf_ptr->symnum_bf = (bf_sym); \
8412 - tmp_bf_ptr->symnum_fcn = (fcn_sym); \
8413 - tmp_bf_ptr->next = NULL; \
8415 - saved_bf_list_end->next = tmp_bf_ptr; \
8416 - saved_bf_list_end = tmp_bf_ptr; \
8420 -/* This function frees the entire (.bf,function) list */
8424 -clear_bf_list (void)
8427 - SAVED_BF_PTR tmp = saved_bf_list;
8428 - SAVED_BF_PTR next = NULL;
8430 - while (tmp != NULL)
8436 - saved_bf_list = NULL;
8440 -int global_remote_debug;
8445 -get_bf_for_fcn (long the_function)
8450 - /* First use a simple queuing algorithm (i.e. look and see if the
8451 - item at the head of the queue is the one you want) */
8453 - if (saved_bf_list == NULL)
8454 - internal_error (__FILE__, __LINE__,
8455 - _("cannot get .bf node off empty list"));
8457 - if (current_head_bf_list != NULL)
8458 - if (current_head_bf_list->symnum_fcn == the_function)
8460 - if (global_remote_debug)
8461 - fprintf_unfiltered (gdb_stderr, "*");
8463 - tmp = current_head_bf_list;
8464 - current_head_bf_list = current_head_bf_list->next;
8465 - return (tmp->symnum_bf);
8468 - /* If the above did not work (probably because #line directives were
8469 - used in the sourcefile and they messed up our internal tables) we now do
8470 - the ugly linear scan */
8472 - if (global_remote_debug)
8473 - fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
8476 - tmp = saved_bf_list;
8477 - while (tmp != NULL)
8480 - if (tmp->symnum_fcn == the_function)
8482 - if (global_remote_debug)
8483 - fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes);
8484 - current_head_bf_list = tmp->next;
8485 - return (tmp->symnum_bf);
8493 -static SAVED_FUNCTION_PTR saved_function_list = NULL;
8494 -static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
8497 -clear_function_list (void)
8499 - SAVED_FUNCTION_PTR tmp = saved_function_list;
8500 - SAVED_FUNCTION_PTR next = NULL;
8502 - while (tmp != NULL)
8509 - saved_function_list = NULL;
8512 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
8513 index 711bdba..9d7d92b 100644
8516 @@ -28,6 +28,10 @@ extern void f_error (char *); /* Defined in f-exp.y */
8517 extern void f_print_type (struct type *, char *, struct ui_file *, int,
8520 +extern const char *f_object_address_data_valid_print_to_stream
8521 + (struct type *type, struct ui_file *stream);
8522 +extern void f_object_address_data_valid_or_error (struct type *type);
8524 extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
8525 struct ui_file *, int,
8526 const struct value_print_options *);
8527 @@ -47,41 +51,8 @@ enum f90_range_type
8528 NONE_BOUND_DEFAULT /* "(low:high)" */
8531 -struct common_entry
8533 - struct symbol *symbol; /* The symbol node corresponding
8534 - to this component */
8535 - struct common_entry *next; /* The next component */
8538 -struct saved_f77_common
8540 - char *name; /* Name of COMMON */
8541 - char *owning_function; /* Name of parent function */
8542 - int secnum; /* Section # of .bss */
8543 - CORE_ADDR offset; /* Offset from .bss for
8545 - struct common_entry *entries; /* List of block's components */
8546 - struct common_entry *end_of_entries; /* ptr. to end of components */
8547 - struct saved_f77_common *next; /* Next saved COMMON block */
8550 -typedef struct saved_f77_common SAVED_F77_COMMON, *SAVED_F77_COMMON_PTR;
8552 -typedef struct common_entry COMMON_ENTRY, *COMMON_ENTRY_PTR;
8554 -extern SAVED_F77_COMMON_PTR head_common_list; /* Ptr to 1st saved COMMON */
8555 -extern SAVED_F77_COMMON_PTR tail_common_list; /* Ptr to last saved COMMON */
8556 -extern SAVED_F77_COMMON_PTR current_common; /* Ptr to current COMMON */
8558 -extern SAVED_F77_COMMON_PTR find_common_for_function (char *, char *);
8560 -#define UNINITIALIZED_SECNUM -1
8561 -#define COMMON_NEEDS_PATCHING(blk) ((blk)->secnum == UNINITIALIZED_SECNUM)
8563 #define BLANK_COMMON_NAME_ORIGINAL "#BLNK_COM" /* XLF assigned */
8564 #define BLANK_COMMON_NAME_MF77 "__BLNK__" /* MF77 assigned */
8565 -#define BLANK_COMMON_NAME_LOCAL "__BLANK" /* Local GDB */
8567 /* When reasonable array bounds cannot be fetched, such as when
8568 you ask to 'mt print symbols' and there is no stack frame and
8569 @@ -113,6 +84,7 @@ struct builtin_f_type
8570 struct type *builtin_logical;
8571 struct type *builtin_logical_s1;
8572 struct type *builtin_logical_s2;
8573 + struct type *builtin_logical_s8;
8574 struct type *builtin_real;
8575 struct type *builtin_real_s8;
8576 struct type *builtin_real_s16;
8577 @@ -125,3 +97,10 @@ struct builtin_f_type
8578 /* Return the Fortran type table for the specified architecture. */
8579 extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
8581 +/* List of module names being imported by a block though BLOCK_FORTRAN_USE. */
8583 +struct fortran_using
8585 + struct fortran_using *next;
8586 + char module_name[1];
8588 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
8589 index 6c9668f..852b9a8 100644
8590 --- a/gdb/f-typeprint.c
8591 +++ b/gdb/f-typeprint.c
8593 #include "gdbcore.h"
8597 +#include "dwarf2loc.h"
8598 #include "gdb_string.h"
8601 @@ -48,6 +48,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
8602 void f_type_print_base (struct type *, struct ui_file *, int, int);
8606 +f_object_address_data_valid_print_to_stream (struct type *type,
8607 + struct ui_file *stream)
8611 + msg = object_address_data_not_valid (type);
8614 + /* Assuming the content printed to STREAM should not be localized. */
8615 + fprintf_filtered (stream, "<%s>", msg);
8622 +f_object_address_data_valid_or_error (struct type *type)
8626 + msg = object_address_data_not_valid (type);
8629 + error (_("Cannot access it because the %s."), _(msg));
8633 /* LEVEL is the depth to indent lines by. */
8636 @@ -57,6 +85,9 @@ f_print_type (struct type *type, char *varstring, struct ui_file *stream,
8637 enum type_code code;
8640 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
8643 f_type_print_base (type, stream, show, level);
8644 code = TYPE_CODE (type);
8645 if ((varstring != NULL && *varstring != '\0')
8646 @@ -166,6 +197,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
8650 + if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
8651 + CHECK_TYPEDEF (type);
8653 switch (TYPE_CODE (type))
8655 case TYPE_CODE_ARRAY:
8656 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
8657 index 0a57404..a9ccc77 100644
8658 --- a/gdb/f-valprint.c
8659 +++ b/gdb/f-valprint.c
8661 #include "gdbcore.h"
8662 #include "command.h"
8666 -static int there_is_a_visible_common_named (char *);
8668 +#include "dictionary.h"
8669 +#include "gdb_assert.h"
8671 extern void _initialize_f_valprint (void);
8672 static void info_common_command (char *, int);
8673 @@ -54,15 +52,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
8674 /* The following macro gives us the size of the nth dimension, Where
8677 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
8678 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
8680 -/* The following gives us the offset for row n where n is 1-based. */
8681 +/* The following gives us the element size for row n where n is 1-based. */
8683 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
8684 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
8687 f77_get_lowerbound (struct type *type)
8689 + f_object_address_data_valid_or_error (type);
8691 if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
8692 error (_("Lower bound may not be '*' in F77"));
8694 @@ -72,14 +72,17 @@ f77_get_lowerbound (struct type *type)
8696 f77_get_upperbound (struct type *type)
8698 + f_object_address_data_valid_or_error (type);
8700 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
8702 - /* We have an assumed size array on our hands. Assume that
8703 - upper_bound == lower_bound so that we show at least 1 element.
8704 - If the user wants to see more elements, let him manually ask for 'em
8705 - and we'll subscript the array and show him. */
8706 + /* We have an assumed size array on our hands. As type_length_get
8707 + already assumes a length zero of arrays with underfined bounds VALADDR
8708 + passed to the Fortran functions does not contained the real inferior
8709 + memory content. User should request printing of specific array
8710 + elements instead. */
8712 - return f77_get_lowerbound (type);
8713 + return f77_get_lowerbound (type) - 1;
8716 return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
8717 @@ -135,24 +138,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
8718 upper = f77_get_upperbound (tmp_type);
8719 lower = f77_get_lowerbound (tmp_type);
8721 - F77_DIM_SIZE (ndimen) = upper - lower + 1;
8722 + F77_DIM_COUNT (ndimen) = upper - lower + 1;
8724 + F77_DIM_BYTE_STRIDE (ndimen) =
8725 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
8727 tmp_type = TYPE_TARGET_TYPE (tmp_type);
8731 - /* Now we multiply eltlen by all the offsets, so that later we
8732 + /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
8733 can print out array elements correctly. Up till now we
8734 - know an offset to apply to get the item but we also
8735 + know an eltlen to apply to get the item but we also
8736 have to know how much to add to get to the next item */
8739 eltlen = TYPE_LENGTH (tmp_type);
8740 - F77_DIM_OFFSET (ndimen) = eltlen;
8741 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
8742 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
8743 while (--ndimen > 0)
8745 - eltlen *= F77_DIM_SIZE (ndimen + 1);
8746 - F77_DIM_OFFSET (ndimen) = eltlen;
8747 + eltlen *= F77_DIM_COUNT (ndimen + 1);
8748 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
8749 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
8753 @@ -172,34 +180,34 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
8755 if (nss != ndimensions)
8757 - for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
8758 + for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
8760 fprintf_filtered (stream, "( ");
8761 f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
8762 - valaddr + i * F77_DIM_OFFSET (nss),
8763 - address + i * F77_DIM_OFFSET (nss),
8764 + valaddr + i * F77_DIM_BYTE_STRIDE (nss),
8765 + address + i * F77_DIM_BYTE_STRIDE (nss),
8766 stream, recurse, options, elts);
8767 fprintf_filtered (stream, ") ");
8769 - if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
8770 + if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
8771 fprintf_filtered (stream, "...");
8775 - for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
8776 + for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
8779 val_print (TYPE_TARGET_TYPE (type),
8780 - valaddr + i * F77_DIM_OFFSET (ndimensions),
8781 + valaddr + i * F77_DIM_BYTE_STRIDE (ndimensions),
8783 - address + i * F77_DIM_OFFSET (ndimensions),
8784 + address + i * F77_DIM_BYTE_STRIDE (ndimensions),
8785 stream, recurse, options, current_language);
8787 - if (i != (F77_DIM_SIZE (nss) - 1))
8788 + if (i != (F77_DIM_COUNT (nss) - 1))
8789 fprintf_filtered (stream, ", ");
8791 if ((*elts == options->print_max - 1)
8792 - && (i != (F77_DIM_SIZE (nss) - 1)))
8793 + && (i != (F77_DIM_COUNT (nss) - 1)))
8794 fprintf_filtered (stream, "...");
8797 @@ -253,6 +261,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
8801 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
8804 CHECK_TYPEDEF (type);
8805 switch (TYPE_CODE (type))
8807 @@ -467,22 +478,54 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
8812 -list_all_visible_commons (char *funname)
8814 +info_common_command_for_block (struct block *block, struct frame_info *frame,
8815 + const char *comname)
8817 - SAVED_F77_COMMON_PTR tmp;
8819 - tmp = head_common_list;
8821 - printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
8823 - while (tmp != NULL)
8825 - if (strcmp (tmp->owning_function, funname) == 0)
8826 - printf_filtered ("%s\n", tmp->name);
8830 + struct dict_iterator iter;
8831 + struct symbol *sym;
8832 + int values_printed = 0;
8834 + struct value_print_options opts;
8836 + get_user_print_options (&opts);
8838 + ALL_BLOCK_SYMBOLS (block, iter, sym)
8839 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
8841 + struct type *type = SYMBOL_TYPE (sym);
8844 + gdb_assert (SYMBOL_CLASS (sym) == LOC_STATIC);
8845 + gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
8847 + if (comname && (!SYMBOL_LINKAGE_NAME (sym)
8848 + || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
8851 + values_printed = 1;
8852 + if (SYMBOL_PRINT_NAME (sym))
8853 + printf_filtered (_("Contents of F77 COMMON block '%s':\n"),
8854 + SYMBOL_PRINT_NAME (sym));
8856 + printf_filtered (_("Contents of blank COMMON block:\n"));
8858 + for (index = 0; index < TYPE_NFIELDS (type); index++)
8860 + struct value *val;
8862 + gdb_assert (field_is_static (&TYPE_FIELD (type, index)));
8863 + val = value_static_field (type, index);
8865 + printf_filtered ("%s = ", TYPE_FIELD_NAME (type, index));
8866 + value_print (val, gdb_stdout, &opts);
8867 + putchar_filtered ('\n');
8870 + putchar_filtered ('\n');
8873 + return values_printed;
8876 /* This function is used to print out the values in a given COMMON
8877 @@ -492,11 +535,9 @@ list_all_visible_commons (char *funname)
8879 info_common_command (char *comname, int from_tty)
8881 - SAVED_F77_COMMON_PTR the_common;
8882 - COMMON_ENTRY_PTR entry;
8883 struct frame_info *fi;
8884 - char *funname = 0;
8885 - struct symbol *func;
8886 + struct block *block;
8887 + int values_printed = 0;
8889 /* We have been told to display the contents of F77 COMMON
8890 block supposedly visible in this function. Let us
8891 @@ -508,136 +549,32 @@ info_common_command (char *comname, int from_tty)
8892 /* The following is generally ripped off from stack.c's routine
8893 print_frame_info() */
8895 - func = find_pc_function (get_frame_pc (fi));
8898 - /* In certain pathological cases, the symtabs give the wrong
8899 - function (when we are in the first function in a file which
8900 - is compiled without debugging symbols, the previous function
8901 - is compiled with debugging symbols, and the "foo.o" symbol
8902 - that is supposed to tell us where the file with debugging symbols
8903 - ends has been truncated by ar because it is longer than 15
8906 - So look in the minimal symbol tables as well, and if it comes
8907 - up with a larger address for the function use that instead.
8908 - I don't think this can ever cause any problems; there shouldn't
8909 - be any minimal symbols in the middle of a function.
8910 - FIXME: (Not necessarily true. What about text labels) */
8912 - struct minimal_symbol *msymbol =
8913 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
8915 - if (msymbol != NULL
8916 - && (SYMBOL_VALUE_ADDRESS (msymbol)
8917 - > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
8918 - funname = SYMBOL_LINKAGE_NAME (msymbol);
8920 - funname = SYMBOL_LINKAGE_NAME (func);
8924 - struct minimal_symbol *msymbol =
8925 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
8927 - if (msymbol != NULL)
8928 - funname = SYMBOL_LINKAGE_NAME (msymbol);
8929 - else /* Got no 'funname', code below will fail. */
8930 - error (_("No function found for frame."));
8933 - /* If comname is NULL, we assume the user wishes to see the
8934 - which COMMON blocks are visible here and then return */
8937 + block = get_frame_block (fi, 0);
8938 + if (block == NULL)
8940 - list_all_visible_commons (funname);
8941 + printf_filtered (_("No symbol table info available.\n"));
8945 - the_common = find_common_for_function (comname, funname);
8950 - if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
8951 - printf_filtered (_("Contents of blank COMMON block:\n"));
8953 - printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
8955 - printf_filtered ("\n");
8956 - entry = the_common->entries;
8958 - while (entry != NULL)
8960 - print_variable_and_value (NULL, entry->symbol, fi, gdb_stdout, 0);
8961 - entry = entry->next;
8963 + if (info_common_command_for_block (block, fi, comname))
8964 + values_printed = 1;
8965 + /* After handling the function's top-level block, stop. Don't
8966 + continue to its superblock, the block of per-file symbols. */
8967 + if (BLOCK_FUNCTION (block))
8969 + block = BLOCK_SUPERBLOCK (block);
8972 - printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
8973 - comname, funname);
8976 -/* This function is used to determine whether there is a
8977 - F77 common block visible at the current scope called 'comname'. */
8981 -there_is_a_visible_common_named (char *comname)
8983 - SAVED_F77_COMMON_PTR the_common;
8984 - struct frame_info *fi;
8985 - char *funname = 0;
8986 - struct symbol *func;
8988 - if (comname == NULL)
8989 - error (_("Cannot deal with NULL common name!"));
8991 - fi = get_selected_frame (_("No frame selected"));
8993 - /* The following is generally ripped off from stack.c's routine
8994 - print_frame_info() */
8996 - func = find_pc_function (fi->pc);
8998 + if (!values_printed)
9000 - /* In certain pathological cases, the symtabs give the wrong
9001 - function (when we are in the first function in a file which
9002 - is compiled without debugging symbols, the previous function
9003 - is compiled with debugging symbols, and the "foo.o" symbol
9004 - that is supposed to tell us where the file with debugging symbols
9005 - ends has been truncated by ar because it is longer than 15
9008 - So look in the minimal symbol tables as well, and if it comes
9009 - up with a larger address for the function use that instead.
9010 - I don't think this can ever cause any problems; there shouldn't
9011 - be any minimal symbols in the middle of a function.
9012 - FIXME: (Not necessarily true. What about text labels) */
9014 - struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
9016 - if (msymbol != NULL
9017 - && (SYMBOL_VALUE_ADDRESS (msymbol)
9018 - > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
9019 - funname = SYMBOL_LINKAGE_NAME (msymbol);
9021 + printf_filtered (_("No common block '%s'.\n"), comname);
9023 - funname = SYMBOL_LINKAGE_NAME (func);
9024 + printf_filtered (_("No common blocks.\n"));
9028 - struct minimal_symbol *msymbol =
9029 - lookup_minimal_symbol_by_pc (fi->pc);
9031 - if (msymbol != NULL)
9032 - funname = SYMBOL_LINKAGE_NAME (msymbol);
9035 - the_common = find_common_for_function (comname, funname);
9037 - return (the_common ? 1 : 0);
9042 _initialize_f_valprint (void)
9043 diff --git a/gdb/findcmd.c b/gdb/findcmd.c
9044 index 1d28914..d176341 100644
9049 /* Copied from bfd_put_bits. */
9053 put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
9056 @@ -45,6 +45,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
9060 +/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
9061 + will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
9062 + place as *PATTERN_BUF, indicating that the buffer is initially empty. */
9065 +allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
9066 + ULONGEST *pattern_buf_size)
9068 +#define INITIAL_PATTERN_BUF_SIZE 100
9069 + *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
9070 + *pattern_buf = xmalloc (*pattern_buf_size);
9071 + *pattern_buf_end = *pattern_buf;
9074 +/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
9075 + VAL_BYTES more bytes or a 64-bit value, whichever is larger.
9076 + *PATTERN_BUF_END is updated as necessary. */
9079 +increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
9080 + ULONGEST *pattern_buf_size, int val_bytes)
9082 + /* Keep it simple and assume size == 'g' when watching for when we
9083 + need to grow the pattern buf. */
9084 + if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
9085 + > *pattern_buf_size)
9087 + size_t current_offset = *pattern_buf_end - *pattern_buf;
9089 + *pattern_buf_size *= 2;
9090 + *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
9091 + *pattern_buf_end = *pattern_buf + current_offset;
9095 /* Subroutine of find_command to simplify it.
9096 Parse the arguments of the "find" command. */
9098 @@ -61,8 +96,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
9100 /* Current size of search pattern buffer.
9101 We realloc space as needed. */
9102 -#define INITIAL_PATTERN_BUF_SIZE 100
9103 - ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
9104 + ULONGEST pattern_buf_size;
9105 /* Pointer to one past the last in-use part of pattern_buf. */
9106 char *pattern_buf_end;
9107 ULONGEST pattern_len;
9108 @@ -75,8 +109,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
9110 error (_("Missing search parameters."));
9112 - pattern_buf = xmalloc (pattern_buf_size);
9113 - pattern_buf_end = pattern_buf;
9114 + allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
9115 old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
9117 /* Get search granularity and/or max count if specified.
9118 @@ -173,16 +206,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
9119 v = parse_to_comma_and_eval (&s);
9120 val_bytes = TYPE_LENGTH (value_type (v));
9122 - /* Keep it simple and assume size == 'g' when watching for when we
9123 - need to grow the pattern buf. */
9124 - if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
9125 - > pattern_buf_size)
9127 - size_t current_offset = pattern_buf_end - pattern_buf;
9128 - pattern_buf_size *= 2;
9129 - pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
9130 - pattern_buf_end = pattern_buf + current_offset;
9132 + increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
9133 + &pattern_buf_size, val_bytes);
9137 @@ -237,6 +262,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
9138 discard_cleanups (old_cleanups);
9141 +/* Drives target_search_memory to sweep through the specified search space,
9142 + possibly in several iterations (with one call to this function for each
9143 + iteration). *START_ADDR is the address where the search starts, and is
9144 + updated to the next starting address to continue the search.
9145 + *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
9146 + updated for the next iteration. PATTERN_BUF holds the pattern to be searched
9147 + for, PATTERN_LEN is the size of the pattern in bytes. If a match is found,
9148 + it's address is put in *FOUND_ADDR.
9150 + Returns 1 if found, 0 if not found, and -1 if there was an error requiring
9151 + halting of the search (e.g. memory read error). */
9154 +search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
9155 + const char *pattern_buf, ULONGEST pattern_len,
9156 + CORE_ADDR *found_addr)
9158 + /* Offset from start of this iteration to the next iteration. */
9159 + ULONGEST next_iter_incr;
9162 + found = target_search_memory (*start_addr, *search_space_len,
9163 + pattern_buf, pattern_len, found_addr);
9167 + /* Begin next iteration at one byte past this match. */
9168 + next_iter_incr = (*found_addr - *start_addr) + 1;
9170 + /* For robustness, we don't let search_space_len go -ve here. */
9171 + if (*search_space_len >= next_iter_incr)
9172 + *search_space_len -= next_iter_incr;
9174 + *search_space_len = 0;
9175 + *start_addr += next_iter_incr;
9181 find_command (char *args, int from_tty)
9183 @@ -267,12 +331,11 @@ find_command (char *args, int from_tty)
9184 while (search_space_len >= pattern_len
9185 && found_count < max_count)
9187 - /* Offset from start of this iteration to the next iteration. */
9188 - ULONGEST next_iter_incr;
9189 CORE_ADDR found_addr;
9190 - int found = target_search_memory (start_addr, search_space_len,
9191 - pattern_buf, pattern_len, &found_addr);
9194 + found = search_memory (&start_addr, &search_space_len, pattern_buf,
9195 + pattern_len, &found_addr);
9199 @@ -280,16 +343,6 @@ find_command (char *args, int from_tty)
9200 printf_filtered ("\n");
9202 last_found_addr = found_addr;
9204 - /* Begin next iteration at one byte past this match. */
9205 - next_iter_incr = (found_addr - start_addr) + 1;
9207 - /* For robustness, we don't let search_space_len go -ve here. */
9208 - if (search_space_len >= next_iter_incr)
9209 - search_space_len -= next_iter_incr;
9211 - search_space_len = 0;
9212 - start_addr += next_iter_incr;
9215 /* Record and print the results. */
9216 diff --git a/gdb/findvar.c b/gdb/findvar.c
9217 index 8c027c9..d201f76 100644
9221 #include "user-regs.h"
9223 #include "objfiles.h"
9224 +#include "dwarf2loc.h"
9226 /* Basic byte-swapping routines. GDB has needed these for a long time...
9227 All extract a target-format integer at ADDR which is LEN bytes long. */
9228 @@ -394,27 +395,16 @@ symbol_read_needs_frame (struct symbol *sym)
9229 /* Given a struct symbol for a variable,
9230 and a stack frame id, read the value of the variable
9231 and return a (pointer to a) struct value containing the value.
9232 - If the variable cannot be found, return a zero pointer. */
9233 + If the variable cannot be found, return a zero pointer.
9234 + We have to first find the address of the variable before allocating struct
9235 + value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
9236 + used by its type. */
9239 read_var_value (struct symbol *var, struct frame_info *frame)
9242 struct type *type = SYMBOL_TYPE (var);
9246 - if (SYMBOL_CLASS (var) == LOC_COMPUTED
9247 - || SYMBOL_CLASS (var) == LOC_REGISTER)
9248 - /* These cases do not use V. */
9252 - v = allocate_value (type);
9253 - VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
9256 - len = TYPE_LENGTH (type);
9258 if (symbol_read_needs_frame (var))
9260 @@ -422,32 +412,40 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9261 switch (SYMBOL_CLASS (var))
9264 - /* Put the constant back in target format. */
9265 - store_signed_integer (value_contents_raw (v), len,
9266 - gdbarch_byte_order (get_type_arch (type)),
9267 - (LONGEST) SYMBOL_VALUE (var));
9268 - VALUE_LVAL (v) = not_lval;
9271 + /* Put the constant back in target format. */
9272 + struct value *v = allocate_value (type);
9273 + VALUE_LVAL (v) = not_lval;
9274 + store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
9275 + gdbarch_byte_order (get_type_arch (type)),
9276 + (LONGEST) SYMBOL_VALUE (var));
9281 - /* Put the constant back in target format. */
9282 - if (overlay_debugging)
9285 - = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
9286 - SYMBOL_OBJ_SECTION (var));
9287 - store_typed_address (value_contents_raw (v), type, addr);
9290 - store_typed_address (value_contents_raw (v), type,
9291 - SYMBOL_VALUE_ADDRESS (var));
9292 - VALUE_LVAL (v) = not_lval;
9295 + /* Put the constant back in target format. */
9296 + struct value *v = allocate_value (type);
9297 + VALUE_LVAL (v) = not_lval;
9298 + if (overlay_debugging)
9301 + = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
9302 + SYMBOL_OBJ_SECTION (var));
9303 + store_typed_address (value_contents_raw (v), type, addr);
9306 + store_typed_address (value_contents_raw (v), type,
9307 + SYMBOL_VALUE_ADDRESS (var));
9311 case LOC_CONST_BYTES:
9313 - memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
9314 + struct value *v = allocate_value (type);
9315 VALUE_LVAL (v) = not_lval;
9316 + memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
9317 + TYPE_LENGTH (type));
9321 @@ -489,12 +487,23 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9325 - if (overlay_debugging)
9326 - set_value_address (v, symbol_overlayed_address
9327 - (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)));
9329 - set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
9335 + if (overlay_debugging)
9336 + addr = symbol_overlayed_address
9337 + (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
9339 + addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
9340 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
9341 + DW_OP_push_object_address. */
9342 + object_address_set (addr);
9343 + v = allocate_value (type);
9344 + VALUE_LVAL (v) = lval_memory;
9345 + set_value_address (v, addr);
9350 case LOC_REGPARM_ADDR:
9351 @@ -513,7 +522,6 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9352 error (_("Value of register variable not available."));
9354 addr = value_as_address (regval);
9355 - VALUE_LVAL (v) = lval_memory;
9359 @@ -556,18 +564,33 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9362 case LOC_OPTIMIZED_OUT:
9363 - VALUE_LVAL (v) = not_lval;
9364 - set_value_optimized_out (v, 1);
9367 + struct value *v = allocate_value (type);
9369 + VALUE_LVAL (v) = not_lval;
9370 + set_value_optimized_out (v, 1);
9375 error (_("Cannot look up value of a botched symbol."));
9379 - set_value_address (v, addr);
9380 - set_value_lazy (v, 1);
9385 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
9386 + DW_OP_PUSH_OBJECT_ADDRESS. */
9387 + object_address_set (addr);
9388 + v = allocate_value (type);
9389 + VALUE_LVAL (v) = lval_memory;
9390 + set_value_address (v, addr);
9392 + set_value_lazy (v, 1);
9398 /* Install default attributes for register values. */
9399 @@ -604,10 +627,11 @@ struct value *
9400 value_from_register (struct type *type, int regnum, struct frame_info *frame)
9402 struct gdbarch *gdbarch = get_frame_arch (frame);
9403 - struct type *type1 = check_typedef (type);
9406 - if (gdbarch_convert_register_p (gdbarch, regnum, type1))
9407 + type = check_typedef (type);
9409 + if (gdbarch_convert_register_p (gdbarch, regnum, type))
9411 /* The ISA/ABI need to something weird when obtaining the
9412 specified value from this register. It might need to
9413 @@ -621,7 +645,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
9414 VALUE_FRAME_ID (v) = get_frame_id (frame);
9415 VALUE_REGNUM (v) = regnum;
9416 gdbarch_register_to_value (gdbarch,
9417 - frame, regnum, type1, value_contents_raw (v));
9418 + frame, regnum, type, value_contents_raw (v));
9422 diff --git a/gdb/frame.c b/gdb/frame.c
9423 index 7932b48..4e7c434 100644
9426 @@ -1171,6 +1171,14 @@ has_stack_frames (void)
9427 if (ptid_equal (inferior_ptid, null_ptid))
9430 + /* FIXME: Workaround archer-tromey-python crash in
9431 + add_inferior_object->get_current_arch on FSF GDB update:
9432 + is_thread_state would assertion check here as
9433 + remote_start_remote->add_inferior_silent->observer_notify_new_inferior is
9434 + before remote_start_remote->add_thread_silent. */
9435 + if (find_thread_ptid (inferior_ptid) == NULL)
9438 /* Don't try to read from a dead thread. */
9439 if (is_exited (inferior_ptid))
9441 diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
9442 index ffb7f53..a2e7e94 100644
9443 --- a/gdb/gdbinit.in
9444 +++ b/gdb/gdbinit.in
9446 echo Setting up the environment for debugging gdb.\n
9448 +# Set up the Python library and "require" command.
9450 +from os.path import abspath
9451 +gdb.datadir = abspath ('@srcdir@/python/lib')
9452 +gdb.pythonlibdir = gdb.datadir
9453 +gdb.__path__ = [gdb.datadir + '/gdb']
9454 +sys.path.insert(0, gdb.datadir)
9456 +source @srcdir@/python/lib/gdb/__init__.py
9461 diff --git a/gdb/gdbserver/linux-i386-low.c b/gdb/gdbserver/linux-i386-low.c
9462 new file mode 100644
9463 index 0000000..b95c1b1
9465 +++ b/gdb/gdbserver/linux-i386-low.c
9467 +/* GNU/Linux/i386 specific low level interface, for the remote server for GDB.
9468 + Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
9469 + 2007, 2008, 2009 Free Software Foundation, Inc.
9471 + This file is part of GDB.
9473 + This program is free software; you can redistribute it and/or modify
9474 + it under the terms of the GNU General Public License as published by
9475 + the Free Software Foundation; either version 3 of the License, or
9476 + (at your option) any later version.
9478 + This program is distributed in the hope that it will be useful,
9479 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9480 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9481 + GNU General Public License for more details.
9483 + You should have received a copy of the GNU General Public License
9484 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
9486 +#include "server.h"
9487 +#include "linux-low.h"
9488 +#include "i387-fp.h"
9490 +#include "gdb_proc_service.h"
9492 +#include <sys/ptrace.h>
9494 +#ifdef HAVE_SYS_REG_H
9495 +#include <sys/reg.h>
9498 +#ifndef PTRACE_GET_THREAD_AREA
9499 +#define PTRACE_GET_THREAD_AREA 25
9502 +/* Defined in auto-generated file reg-i386-linux.c. */
9503 +void init_registers_i386_linux (void);
9506 +/* This module only supports access to the general purpose registers. */
9508 +#define i386_num_regs 16
9510 +/* This stuff comes from i386-linux-nat.c. */
9512 +/* Mapping between the general-purpose registers in `struct user'
9513 + format and GDB's register array layout. */
9514 +static int i386_regmap[] =
9516 + EAX * 4, ECX * 4, EDX * 4, EBX * 4,
9517 + UESP * 4, EBP * 4, ESI * 4, EDI * 4,
9518 + EIP * 4, EFL * 4, CS * 4, SS * 4,
9519 + DS * 4, ES * 4, FS * 4, GS * 4
9522 +/* Called by libthread_db. */
9525 +ps_get_thread_area (const struct ps_prochandle *ph,
9526 + lwpid_t lwpid, int idx, void **base)
9528 + unsigned int desc[4];
9530 + if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
9531 + (void *) idx, (unsigned long) &desc) < 0)
9534 + *(int *)base = desc[1];
9539 +i386_cannot_store_register (int regno)
9541 + return (regno >= i386_num_regs);
9545 +i386_cannot_fetch_register (int regno)
9547 + return (regno >= i386_num_regs);
9551 +#ifdef HAVE_PTRACE_GETREGS
9552 +#include <sys/procfs.h>
9553 +#include <sys/ptrace.h>
9556 +i386_fill_gregset (void *buf)
9560 + for (i = 0; i < i386_num_regs; i++)
9561 + collect_register (i, ((char *) buf) + i386_regmap[i]);
9563 + collect_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
9567 +i386_store_gregset (const void *buf)
9571 + for (i = 0; i < i386_num_regs; i++)
9572 + supply_register (i, ((char *) buf) + i386_regmap[i]);
9574 + supply_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
9578 +i386_fill_fpregset (void *buf)
9580 + i387_cache_to_fsave (buf);
9584 +i386_store_fpregset (const void *buf)
9586 + i387_fsave_to_cache (buf);
9590 +i386_fill_fpxregset (void *buf)
9592 + i387_cache_to_fxsave (buf);
9596 +i386_store_fpxregset (const void *buf)
9598 + i387_fxsave_to_cache (buf);
9601 +#endif /* HAVE_PTRACE_GETREGS */
9603 +struct regset_info target_regsets[] = {
9604 +#ifdef HAVE_PTRACE_GETREGS
9605 + { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
9607 + i386_fill_gregset, i386_store_gregset },
9608 +# ifdef HAVE_PTRACE_GETFPXREGS
9609 + { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, sizeof (elf_fpxregset_t),
9611 + i386_fill_fpxregset, i386_store_fpxregset },
9613 + { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
9615 + i386_fill_fpregset, i386_store_fpregset },
9616 +#endif /* HAVE_PTRACE_GETREGS */
9617 + { 0, 0, -1, -1, NULL, NULL }
9620 +static const unsigned char i386_breakpoint[] = { 0xCC };
9621 +#define i386_breakpoint_len 1
9623 +extern int debug_threads;
9630 + collect_register_by_name ("eip", &pc);
9632 + if (debug_threads)
9633 + fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
9638 +i386_set_pc (CORE_ADDR newpc)
9640 + if (debug_threads)
9641 + fprintf (stderr, "set pc to %08lx\n", (long) newpc);
9642 + supply_register_by_name ("eip", &newpc);
9646 +i386_breakpoint_at (CORE_ADDR pc)
9650 + read_inferior_memory (pc, &c, 1);
9657 +struct linux_target_ops the_low_target = {
9658 + init_registers_i386_linux,
9661 + i386_cannot_fetch_register,
9662 + i386_cannot_store_register,
9666 + i386_breakpoint_len,
9669 + i386_breakpoint_at,
9677 diff --git a/gdb/gdbserver/linux-x86-64-low.c b/gdb/gdbserver/linux-x86-64-low.c
9678 new file mode 100644
9679 index 0000000..b8213f5
9681 +++ b/gdb/gdbserver/linux-x86-64-low.c
9683 +/* GNU/Linux/x86-64 specific low level interface, for the remote server
9685 + Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009
9686 + Free Software Foundation, Inc.
9688 + This file is part of GDB.
9690 + This program is free software; you can redistribute it and/or modify
9691 + it under the terms of the GNU General Public License as published by
9692 + the Free Software Foundation; either version 3 of the License, or
9693 + (at your option) any later version.
9695 + This program is distributed in the hope that it will be useful,
9696 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9697 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9698 + GNU General Public License for more details.
9700 + You should have received a copy of the GNU General Public License
9701 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
9703 +#include "server.h"
9704 +#include "linux-low.h"
9705 +#include "i387-fp.h"
9707 +#include "gdb_proc_service.h"
9709 +/* Defined in auto-generated file reg-x86-64-linux.c. */
9710 +void init_registers_x86_64_linux (void);
9712 +#include <sys/reg.h>
9713 +#include <sys/procfs.h>
9714 +#include <sys/ptrace.h>
9716 +/* This definition comes from prctl.h, but some kernels may not have it. */
9717 +#ifndef PTRACE_ARCH_PRCTL
9718 +#define PTRACE_ARCH_PRCTL 30
9721 +/* The following definitions come from prctl.h, but may be absent
9722 + for certain configurations. */
9723 +#ifndef ARCH_GET_FS
9724 +#define ARCH_SET_GS 0x1001
9725 +#define ARCH_SET_FS 0x1002
9726 +#define ARCH_GET_FS 0x1003
9727 +#define ARCH_GET_GS 0x1004
9730 +static int x86_64_regmap[] = {
9731 + RAX * 8, RBX * 8, RCX * 8, RDX * 8,
9732 + RSI * 8, RDI * 8, RBP * 8, RSP * 8,
9733 + R8 * 8, R9 * 8, R10 * 8, R11 * 8,
9734 + R12 * 8, R13 * 8, R14 * 8, R15 * 8,
9735 + RIP * 8, EFLAGS * 8, CS * 8, SS * 8,
9736 + DS * 8, ES * 8, FS * 8, GS * 8,
9737 + -1, -1, -1, -1, -1, -1, -1, -1,
9738 + -1, -1, -1, -1, -1, -1, -1, -1,
9739 + -1, -1, -1, -1, -1, -1, -1, -1,
9740 + -1, -1, -1, -1, -1, -1, -1, -1, -1,
9744 +#define X86_64_NUM_GREGS (sizeof(x86_64_regmap)/sizeof(int))
9746 +/* Called by libthread_db. */
9749 +ps_get_thread_area (const struct ps_prochandle *ph,
9750 + lwpid_t lwpid, int idx, void **base)
9755 + if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
9759 + if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
9763 + return PS_BADADDR;
9769 +x86_64_fill_gregset (void *buf)
9773 + for (i = 0; i < X86_64_NUM_GREGS; i++)
9774 + if (x86_64_regmap[i] != -1)
9775 + collect_register (i, ((char *) buf) + x86_64_regmap[i]);
9779 +x86_64_store_gregset (const void *buf)
9783 + for (i = 0; i < X86_64_NUM_GREGS; i++)
9784 + if (x86_64_regmap[i] != -1)
9785 + supply_register (i, ((char *) buf) + x86_64_regmap[i]);
9789 +x86_64_fill_fpregset (void *buf)
9791 + i387_cache_to_fxsave (buf);
9795 +x86_64_store_fpregset (const void *buf)
9797 + i387_fxsave_to_cache (buf);
9800 +struct regset_info target_regsets[] = {
9801 + { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
9803 + x86_64_fill_gregset, x86_64_store_gregset },
9804 + { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
9806 + x86_64_fill_fpregset, x86_64_store_fpregset },
9807 + { 0, 0, -1, -1, NULL, NULL }
9810 +static const unsigned char x86_64_breakpoint[] = { 0xCC };
9811 +#define x86_64_breakpoint_len 1
9813 +extern int debug_threads;
9820 + collect_register_by_name ("rip", &pc);
9822 + if (debug_threads)
9823 + fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
9828 +x86_64_set_pc (CORE_ADDR newpc)
9830 + if (debug_threads)
9831 + fprintf (stderr, "set pc to %08lx\n", (long) newpc);
9832 + supply_register_by_name ("rip", &newpc);
9836 +x86_64_breakpoint_at (CORE_ADDR pc)
9840 + read_inferior_memory (pc, &c, 1);
9847 +struct linux_target_ops the_low_target = {
9848 + init_registers_x86_64_linux,
9855 + x86_64_breakpoint,
9856 + x86_64_breakpoint_len,
9859 + x86_64_breakpoint_at,
9867 diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
9868 index 79d33fe..d3b4fa1 100644
9869 --- a/gdb/gdbthread.h
9870 +++ b/gdb/gdbthread.h
9871 @@ -185,6 +185,10 @@ struct thread_info
9872 /* True if this thread has been explicitly requested to stop. */
9875 + /* The initiating frame of a nexting operation, used for deciding
9876 + which exceptions to intercept. */
9877 + struct frame_id initiating_frame;
9879 /* Private data used by the target vector implementation. */
9880 struct private_thread_info *private;
9882 @@ -249,6 +253,9 @@ extern struct thread_info *any_thread_of_process (int pid);
9883 /* Change the ptid of thread OLD_PTID to NEW_PTID. */
9884 void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
9886 +/* Prune dead threads from the list of threads. */
9887 +extern void prune_threads (void);
9889 /* Iterator function to call a user-provided callback function
9890 once for each known thread. */
9891 typedef int (*thread_callback_func) (struct thread_info *, void *);
9892 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
9893 index 2f77dca..90abf2c 100644
9894 --- a/gdb/gdbtypes.c
9895 +++ b/gdb/gdbtypes.c
9898 #include "gdb_assert.h"
9899 #include "hashtab.h"
9900 +#include "observer.h"
9901 +#include "dwarf2expr.h"
9902 +#include "dwarf2loc.h"
9905 /* Floatformat pairs. */
9906 @@ -118,13 +121,31 @@ static void print_arg_types (struct field *, int, int);
9907 static void dump_fn_fieldlists (struct type *, int);
9908 static void print_cplus_stuff (struct type *, int);
9910 +/* A reference count structure for the type reference count map. Each
9911 + type in a hierarchy of types is mapped to the same reference
9913 +struct type_refc_entry
9915 + /* One type in the hierarchy. Each type in the hierarchy gets its
9917 + struct type *type;
9919 + /* A pointer to the shared reference count. */
9923 +/* The hash table holding all discardable `struct type *' references. */
9924 +static htab_t type_discardable_table;
9926 +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE. */
9927 +static int type_discardable_age_current;
9929 /* Allocate a new OBJFILE-associated type structure and fill it
9930 with some defaults. Space for the type structure is allocated
9931 on the objfile's objfile_obstack. */
9934 -alloc_type (struct objfile *objfile)
9935 +alloc_type (struct objfile *objfile, struct type *parent)
9939 @@ -148,6 +169,39 @@ alloc_type (struct objfile *objfile)
9943 +/* Declare TYPE as discardable on next garbage collection by free_all_types.
9944 + You must call type_mark_used during each free_all_types to protect TYPE from
9945 + being deallocated. */
9948 +set_type_as_discardable (struct type *type)
9952 + gdb_assert (!TYPE_DISCARDABLE (type));
9954 + TYPE_DISCARDABLE (type) = 1;
9955 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
9957 + slot = htab_find_slot (type_discardable_table, type, INSERT);
9958 + gdb_assert (!*slot);
9962 +/* Allocate a new type like alloc_type but preserve for it the discardability
9963 + state of PARENT_TYPE. */
9965 +static struct type *
9966 +alloc_type_as_parent (struct type *parent_type)
9968 + struct type *new_type = alloc_type_copy (parent_type);
9970 + if (TYPE_DISCARDABLE (parent_type))
9971 + set_type_as_discardable (new_type);
9976 /* Allocate a new GDBARCH-associated type structure and fill it
9977 with some defaults. Space for the type structure is allocated
9979 @@ -184,7 +238,7 @@ struct type *
9980 alloc_type_copy (const struct type *type)
9982 if (TYPE_OBJFILE_OWNED (type))
9983 - return alloc_type (TYPE_OWNER (type).objfile);
9984 + return alloc_type (TYPE_OWNER (type).objfile, (struct type *) type);
9986 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
9988 @@ -273,7 +327,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
9990 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
9992 - ntype = alloc_type_copy (type);
9993 + ntype = alloc_type_as_parent (type);
9997 @@ -350,7 +404,7 @@ make_reference_type (struct type *type, struct type **typeptr)
9999 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
10001 - ntype = alloc_type_copy (type);
10002 + ntype = alloc_type_as_parent (type);
10006 @@ -721,12 +775,13 @@ create_range_type (struct type *result_type, struct type *index_type,
10007 TYPE_TARGET_STUB (result_type) = 1;
10009 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
10010 - TYPE_NFIELDS (result_type) = 2;
10011 + TYPE_NFIELDS (result_type) = 3;
10012 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
10013 TYPE_NFIELDS (result_type)
10014 * sizeof (struct field));
10015 TYPE_LOW_BOUND (result_type) = low_bound;
10016 TYPE_HIGH_BOUND (result_type) = high_bound;
10017 + TYPE_BYTE_STRIDE (result_type) = 0;
10019 if (low_bound >= 0)
10020 TYPE_UNSIGNED (result_type) = 1;
10021 @@ -826,26 +881,45 @@ create_array_type (struct type *result_type,
10023 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
10024 TYPE_TARGET_TYPE (result_type) = element_type;
10025 - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
10026 - low_bound = high_bound = 0;
10027 - CHECK_TYPEDEF (element_type);
10028 - /* Be careful when setting the array length. Ada arrays can be
10029 - empty arrays with the high_bound being smaller than the low_bound.
10030 - In such cases, the array length should be zero. */
10031 - if (high_bound < low_bound)
10032 - TYPE_LENGTH (result_type) = 0;
10034 - TYPE_LENGTH (result_type) =
10035 - TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
10036 TYPE_NFIELDS (result_type) = 1;
10037 TYPE_FIELDS (result_type) =
10038 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
10039 TYPE_INDEX_TYPE (result_type) = range_type;
10040 TYPE_VPTR_FIELDNO (result_type) = -1;
10042 - /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
10043 + /* DWARF blocks may depend on runtime information like
10044 + DW_OP_PUSH_OBJECT_ADDRESS not being available during the
10045 + CREATE_ARRAY_TYPE time. */
10046 + if (TYPE_RANGE_BOUND_IS_DWARF_BLOCK (range_type, 0)
10047 + || TYPE_RANGE_BOUND_IS_DWARF_BLOCK (range_type, 1)
10048 + || TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type)
10049 + || TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (range_type)
10050 + || get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
10056 + /* Be careful when setting the array length. Ada arrays can be
10057 + empty arrays with the high_bound being smaller than the low_bound.
10058 + In such cases, the array length should be zero. TYPE_TARGET_STUB needs to
10059 + be checked as it may have dependencies on DWARF blocks depending on
10060 + runtime information not available during the CREATE_ARRAY_TYPE time. */
10061 + if (high_bound < low_bound || TYPE_TARGET_STUB (element_type))
10062 + TYPE_LENGTH (result_type) = 0;
10065 + CHECK_TYPEDEF (element_type);
10066 + TYPE_LENGTH (result_type) =
10067 + TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
10070 if (TYPE_LENGTH (result_type) == 0)
10071 - TYPE_TARGET_STUB (result_type) = 1;
10073 + /* The real size will be computed for specific instances by
10074 + CHECK_TYPEDEF. */
10075 + TYPE_TARGET_STUB (result_type) = 1;
10078 return result_type;
10080 @@ -1331,6 +1405,84 @@ stub_noname_complaint (void)
10081 complaint (&symfile_complaints, _("stub type has NULL name"));
10084 +/* Calculate the memory length of array TYPE.
10086 + TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
10087 + a performance hint. Feel free to pass NULL. Set FULL_SPAN to return the
10088 + size incl. the possible padding of the last element - it may differ from the
10089 + cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
10090 + TYPE_BYTE_STRIDE values. */
10093 +type_length_get (struct type *type, struct type *target_type, int full_span)
10095 + struct type *range_type;
10097 + CORE_ADDR byte_stride = 0; /* `= 0' for a false GCC warning. */
10098 + CORE_ADDR element_size;
10100 + if (TYPE_CODE (type) != TYPE_CODE_ARRAY
10101 + && TYPE_CODE (type) != TYPE_CODE_STRING)
10102 + return TYPE_LENGTH (type);
10104 + /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
10105 + Fortran arrays. The allocated data will never be used so they can be
10107 + if (object_address_data_not_valid (type))
10110 + range_type = TYPE_INDEX_TYPE (type);
10111 + if (TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (range_type)
10112 + || TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type))
10114 + count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
10115 + /* It may happen for wrong DWARF annotations returning garbage data. */
10117 + warning (_("Range for type %s has invalid bounds %d..%d"),
10118 + TYPE_NAME (type), TYPE_LOW_BOUND (range_type),
10119 + TYPE_HIGH_BOUND (range_type));
10120 + /* The code below does not handle count == 0 right. */
10123 + if (full_span || count > 1)
10125 + /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
10126 + force FULL_SPAN to 1. */
10127 + byte_stride = TYPE_BYTE_STRIDE (range_type);
10128 + if (byte_stride == 0)
10130 + if (target_type == NULL)
10131 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
10132 + byte_stride = type_length_get (target_type, NULL, 1);
10136 + return count * byte_stride;
10137 + if (target_type == NULL)
10138 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
10139 + element_size = type_length_get (target_type, NULL, 1);
10140 + return (count - 1) * byte_stride + element_size;
10143 +/* Prepare TYPE after being read in by the backend. Currently this function
10144 + only propagates the TYPE_DYNAMIC flag. */
10147 +finalize_type (struct type *type)
10151 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
10152 + if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
10155 + /* FIXME: cplus_stuff is ignored here. */
10156 + if (i < TYPE_NFIELDS (type)
10157 + || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
10158 + || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
10159 + TYPE_DYNAMIC (type) = 1;
10162 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
10164 If this is a stubbed struct (i.e. declared as struct foo *), see if
10165 @@ -1347,7 +1499,8 @@ stub_noname_complaint (void)
10166 /* Find the real type of TYPE. This function returns the real type,
10167 after removing all layers of typedefs and completing opaque or stub
10168 types. Completion changes the TYPE argument, but stripping of
10169 - typedefs does not. */
10170 + typedefs does not. Still original passed TYPE will have TYPE_LENGTH
10171 + updated. FIXME: Remove this dependency (only ada_to_fixed_type?). */
10174 check_typedef (struct type *type)
10175 @@ -1457,34 +1610,37 @@ check_typedef (struct type *type)
10179 - if (TYPE_TARGET_STUB (type))
10180 + /* copy_type_recursive automatically makes the resulting type containing only
10181 + constant values expected by the callers of this function. */
10182 + if (TYPE_DYNAMIC (type))
10184 + htab_t copied_types;
10185 + struct type *type_old = type;
10187 + copied_types = create_copied_types_hash (NULL);
10188 + type = copy_type_recursive (type, copied_types);
10189 + htab_delete (copied_types);
10191 + gdb_assert (TYPE_DYNAMIC (type) == 0);
10194 + if (!currently_reading_symtab
10195 + && (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type)))
10197 - struct type *range_type;
10198 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
10200 + if (TYPE_DYNAMIC (type))
10201 + TYPE_TARGET_TYPE (type) = target_type;
10202 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
10206 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
10207 - && TYPE_NFIELDS (type) == 1
10208 - && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
10209 - == TYPE_CODE_RANGE))
10210 + || TYPE_CODE (type) == TYPE_CODE_STRING)
10212 /* Now recompute the length of the array type, based on its
10213 - number of elements and the target type's length.
10214 - Watch out for Ada null Ada arrays where the high bound
10215 - is smaller than the low bound. */
10216 - const int low_bound = TYPE_LOW_BOUND (range_type);
10217 - const int high_bound = TYPE_HIGH_BOUND (range_type);
10220 - if (high_bound < low_bound)
10223 - nb_elements = high_bound - low_bound + 1;
10225 - TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
10226 + number of elements and the target type's length. */
10227 + TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
10228 TYPE_TARGET_STUB (type) = 0;
10230 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
10231 @@ -1492,9 +1648,12 @@ check_typedef (struct type *type)
10232 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
10233 TYPE_TARGET_STUB (type) = 0;
10235 + TYPE_DYNAMIC (type) = 0;
10238 /* Cache TYPE_LENGTH for future use. */
10239 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
10244 @@ -1716,7 +1875,7 @@ init_type (enum type_code code, int length, int flags,
10248 - type = alloc_type (objfile);
10249 + type = alloc_type (objfile, NULL);
10250 TYPE_CODE (type) = code;
10251 TYPE_LENGTH (type) = length;
10253 @@ -1760,6 +1919,10 @@ init_type (enum type_code code, int length, int flags,
10255 INIT_CPLUS_SPECIFIC (type);
10259 + type_incref (type);
10264 @@ -2004,7 +2167,8 @@ rank_one_type (struct type *parm, struct type *arg)
10265 switch (TYPE_CODE (arg))
10267 case TYPE_CODE_PTR:
10268 - if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
10269 + if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID
10270 + && TYPE_CODE (TYPE_TARGET_TYPE (arg)) != TYPE_CODE_VOID)
10271 return VOID_PTR_CONVERSION_BADNESS;
10273 return rank_one_type (TYPE_TARGET_TYPE (parm),
10274 @@ -2820,33 +2984,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
10277 /* Allocate the hash table used by copy_type_recursive to walk
10278 - types without duplicates. We use OBJFILE's obstack, because
10279 - OBJFILE is about to be deleted. */
10280 + types without duplicates. */
10283 create_copied_types_hash (struct objfile *objfile)
10285 - return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
10286 - NULL, &objfile->objfile_obstack,
10287 - hashtab_obstack_allocate,
10288 - dummy_obstack_deallocate);
10289 + if (objfile == NULL)
10291 + /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
10292 + OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN. Table
10293 + element entries get allocated by xmalloc - so use xfree. */
10294 + return htab_create (1, type_pair_hash, type_pair_eq, xfree);
10298 + /* Use OBJFILE's obstack, because OBJFILE is about to be deleted. Table
10299 + element entries get allocated by xmalloc - so use xfree. */
10300 + return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
10301 + xfree, &objfile->objfile_obstack,
10302 + hashtab_obstack_allocate,
10303 + dummy_obstack_deallocate);
10307 -/* Recursively copy (deep copy) TYPE, if it is associated with
10308 - OBJFILE. Return a new type allocated using malloc, a saved type if
10309 - we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
10310 - not associated with OBJFILE. */
10311 +/* A helper for copy_type_recursive. This does all the work. OBJFILE is used
10312 + only for an assertion checking. */
10315 -copy_type_recursive (struct objfile *objfile,
10316 - struct type *type,
10317 - htab_t copied_types)
10318 +static struct type *
10319 +copy_type_recursive_1 (struct objfile *objfile,
10320 + struct type *type,
10321 + htab_t copied_types)
10323 struct type_pair *stored, pair;
10325 struct type *new_type;
10327 - if (! TYPE_OBJFILE_OWNED (type))
10328 + if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
10331 /* This type shouldn't be pointing to any types in other objfiles;
10332 @@ -2861,8 +3034,10 @@ copy_type_recursive (struct objfile *objfile,
10333 new_type = alloc_type_arch (get_type_arch (type));
10335 /* We must add the new type to the hash table immediately, in case
10336 - we encounter this type again during a recursive call below. */
10337 - stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
10338 + we encounter this type again during a recursive call below. Memory could
10339 + be allocated from OBJFILE in the case we will be removing OBJFILE, this
10340 + optimization is missed and xfree is called for it from COPIED_TYPES. */
10341 + stored = xmalloc (sizeof (*stored));
10342 stored->old = type;
10343 stored->new = new_type;
10345 @@ -2873,6 +3048,19 @@ copy_type_recursive (struct objfile *objfile,
10346 TYPE_OBJFILE_OWNED (new_type) = 0;
10347 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
10349 + /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
10350 + need to initialize it again. And even if TYPE was already discardable
10351 + NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE. */
10352 + TYPE_DISCARDABLE (new_type) = 0;
10353 + set_type_as_discardable (new_type);
10355 + /* Pre-clear the fields processed by delete_main_type. If DWARF block
10356 + evaluations below call error we would leave an unfreeable TYPE. */
10357 + TYPE_TARGET_TYPE (new_type) = NULL;
10358 + TYPE_VPTR_BASETYPE (new_type) = NULL;
10359 + TYPE_NFIELDS (new_type) = 0;
10360 + TYPE_FIELDS (new_type) = NULL;
10362 if (TYPE_NAME (type))
10363 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
10364 if (TYPE_TAG_NAME (type))
10365 @@ -2881,12 +3069,45 @@ copy_type_recursive (struct objfile *objfile,
10366 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
10367 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
10369 + if (TYPE_ALLOCATED (new_type))
10371 + gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
10373 + if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
10374 + TYPE_NOT_ALLOCATED (new_type) = 1;
10375 + TYPE_ALLOCATED (new_type) = NULL;
10378 + if (TYPE_ASSOCIATED (new_type))
10380 + gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
10382 + if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
10383 + TYPE_NOT_ASSOCIATED (new_type) = 1;
10384 + TYPE_ASSOCIATED (new_type) = NULL;
10387 + if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
10388 + && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
10390 + if (TYPE_NOT_ALLOCATED (new_type)
10391 + || TYPE_NOT_ASSOCIATED (new_type))
10392 + TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
10395 + TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
10396 + TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
10397 + (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
10401 /* Copy the fields. */
10402 if (TYPE_NFIELDS (type))
10406 nfields = TYPE_NFIELDS (type);
10407 + TYPE_NFIELDS (new_type) = nfields;
10408 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
10409 for (i = 0; i < nfields; i++)
10411 @@ -2895,8 +3116,8 @@ copy_type_recursive (struct objfile *objfile,
10412 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
10413 if (TYPE_FIELD_TYPE (type, i))
10414 TYPE_FIELD_TYPE (new_type, i)
10415 - = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
10417 + = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
10419 if (TYPE_FIELD_NAME (type, i))
10420 TYPE_FIELD_NAME (new_type, i) =
10421 xstrdup (TYPE_FIELD_NAME (type, i));
10422 @@ -2915,6 +3136,16 @@ copy_type_recursive (struct objfile *objfile,
10423 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
10426 + case FIELD_LOC_KIND_DWARF_BLOCK:
10427 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
10428 + it is expected to be made constant by CHECK_TYPEDEF. */
10429 + if (TYPE_NOT_ALLOCATED (new_type)
10430 + || TYPE_NOT_ASSOCIATED (new_type))
10431 + SET_FIELD_DWARF_BLOCK (TYPE_FIELD (new_type, i), NULL);
10433 + SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
10434 + dwarf_locexpr_baton_eval (TYPE_FIELD_DWARF_BLOCK (type, i)));
10437 internal_error (__FILE__, __LINE__,
10438 _("Unexpected type field location kind: %d"),
10439 @@ -2923,17 +3154,30 @@ copy_type_recursive (struct objfile *objfile,
10443 + /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound. */
10444 + if (TYPE_CODE (type) == TYPE_CODE_RANGE
10445 + && TYPE_RANGE_HIGH_BOUND_IS_COUNT (type))
10447 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
10448 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (type)
10449 + + TYPE_HIGH_BOUND (type) - 1;
10452 + /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
10453 + possibly converted. */
10454 + TYPE_DYNAMIC (new_type) = 0;
10456 /* Copy pointers to other types. */
10457 if (TYPE_TARGET_TYPE (type))
10458 TYPE_TARGET_TYPE (new_type) =
10459 - copy_type_recursive (objfile,
10460 - TYPE_TARGET_TYPE (type),
10462 + copy_type_recursive_1 (objfile,
10463 + TYPE_TARGET_TYPE (type),
10465 if (TYPE_VPTR_BASETYPE (type))
10466 TYPE_VPTR_BASETYPE (new_type) =
10467 - copy_type_recursive (objfile,
10468 - TYPE_VPTR_BASETYPE (type),
10470 + copy_type_recursive_1 (objfile,
10471 + TYPE_VPTR_BASETYPE (type),
10473 /* Maybe copy the type_specific bits.
10475 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
10476 @@ -2951,6 +3195,17 @@ copy_type_recursive (struct objfile *objfile,
10480 +/* Recursively copy (deep copy) TYPE. Return a new type allocated using
10481 + malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
10482 + or TYPE if it is not associated with OBJFILE. */
10485 +copy_type_recursive (struct type *type,
10486 + htab_t copied_types)
10488 + return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
10491 /* Make a copy of the given TYPE, except that the pointer & reference
10492 types are not preserved.
10494 @@ -2973,6 +3228,217 @@ copy_type (const struct type *type)
10498 +/* Callback type for main_type_crawl. */
10499 +typedef int (*main_type_crawl_iter) (struct type *type, void *data);
10501 +/* Iterate all main_type structures reachable through any `struct type *' from
10502 + TYPE. ITER will be called only for one type of each main_type, use
10503 + TYPE_CHAIN traversal to find all the type instances. ITER is being called
10504 + for each main_type found. ITER returns non-zero if main_type_crawl should
10505 + depth-first enter the specific type. ITER must provide some detection for
10506 + reentering the same main_type as this function would otherwise endlessly
10510 +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
10512 + struct type *type_iter;
10518 + gdb_assert (TYPE_OBJFILE (type) == NULL);
10520 + /* `struct cplus_struct_type' handling is unsupported by this function. */
10521 + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
10522 + && TYPE_CODE (type) != TYPE_CODE_UNION)
10523 + || !HAVE_CPLUS_STRUCT (type) || !TYPE_CPLUS_SPECIFIC (type));
10525 + if (!(*iter) (type, data))
10528 + /* Iterate all the type instances of this main_type. */
10529 + type_iter = type;
10532 + gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
10534 + main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
10535 + main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
10537 + type_iter = TYPE_CHAIN (type_iter);
10539 + while (type_iter != type);
10541 + for (i = 0; i < TYPE_NFIELDS (type); i++)
10542 + main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
10544 + main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
10545 + main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
10548 +/* A helper for delete_type which deletes a main_type and the things to which
10549 + it refers. TYPE is a type whose main_type we wish to destroy. */
10552 +delete_main_type (struct type *type)
10556 + gdb_assert (TYPE_DISCARDABLE (type));
10557 + gdb_assert (TYPE_OBJFILE (type) == NULL);
10559 + xfree (TYPE_NAME (type));
10560 + xfree (TYPE_TAG_NAME (type));
10562 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
10564 + xfree (TYPE_FIELD_NAME (type, i));
10566 + if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
10567 + xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
10569 + xfree (TYPE_FIELDS (type));
10571 + /* `struct cplus_struct_type' handling is unsupported by this function. */
10572 + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
10573 + && TYPE_CODE (type) != TYPE_CODE_UNION)
10574 + || !HAVE_CPLUS_STRUCT (type) || !TYPE_CPLUS_SPECIFIC (type));
10576 + xfree (TYPE_MAIN_TYPE (type));
10579 +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
10580 + main_type. TYPE must be a reclaimable type - neither permanent nor objfile
10584 +delete_type_chain (struct type *type)
10586 + struct type *type_iter, *type_iter_to_free;
10588 + gdb_assert (TYPE_DISCARDABLE (type));
10589 + gdb_assert (TYPE_OBJFILE (type) == NULL);
10591 + delete_main_type (type);
10593 + type_iter = type;
10596 + type_iter_to_free = type_iter;
10597 + type_iter = TYPE_CHAIN (type_iter);
10598 + xfree (type_iter_to_free);
10600 + while (type_iter != type);
10603 +/* Hash function for type_discardable_table. */
10606 +type_discardable_hash (const void *p)
10608 + const struct type *type = p;
10610 + return htab_hash_pointer (TYPE_MAIN_TYPE (type));
10613 +/* Equality function for type_discardable_table. */
10616 +type_discardable_equal (const void *a, const void *b)
10618 + const struct type *left = a;
10619 + const struct type *right = b;
10621 + return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
10624 +/* A helper for type_mark_used. */
10627 +type_mark_used_crawl (struct type *type, void *unused)
10629 + if (!TYPE_DISCARDABLE (type))
10632 + if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
10635 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
10637 + /* Continue the traversal. */
10641 +/* Mark TYPE and its connected types as used in this free_all_types pass. */
10644 +type_mark_used (struct type *type)
10646 + if (type == NULL)
10649 + if (!TYPE_DISCARDABLE (type))
10652 + main_type_crawl (type, type_mark_used_crawl, NULL);
10655 +/* Increment the reference count for TYPE. */
10658 +type_incref (struct type *type)
10662 +/* Decrement the reference count for TYPE. If TYPE has no more
10663 + references, delete it. */
10666 +type_decref (struct type *type)
10670 +/* A traverse callback for type_discardable_table which removes any
10671 + type_discardable whose reference count is now zero (unused link). */
10674 +type_discardable_remove (void **slot, void *unused)
10676 + struct type *type = *slot;
10678 + gdb_assert (TYPE_DISCARDABLE (type));
10680 + if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
10682 + delete_type_chain (type);
10684 + htab_clear_slot (type_discardable_table, slot);
10690 +/* Free all the reclaimable types that have been allocated and that have
10691 + currently zero reference counter.
10693 + This function is called after each command, successful or not. Use this
10694 + cleanup only in the GDB idle state as GDB only marks those types used by
10695 + globally tracked objects (with no autovariable references tracking). */
10698 +free_all_types (void)
10700 + /* Mark a new pass. As GDB checks all the entries were visited after each
10701 + pass there cannot be any stale entries already containing the changed
10703 + type_discardable_age_current ^= 1;
10705 + observer_notify_mark_used ();
10707 + htab_traverse (type_discardable_table, type_discardable_remove, NULL);
10710 /* Helper functions to initialize architecture-specific types. */
10712 @@ -3463,6 +3929,11 @@ void
10713 _initialize_gdbtypes (void)
10715 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
10717 + type_discardable_table = htab_create_alloc (20, type_discardable_hash,
10718 + type_discardable_equal, NULL,
10721 objfile_type_data = register_objfile_data ();
10723 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
10724 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
10725 index be6ed55..6a51a4e 100644
10726 --- a/gdb/gdbtypes.h
10727 +++ b/gdb/gdbtypes.h
10728 @@ -137,6 +137,8 @@ enum type_code
10730 TYPE_CODE_DECFLOAT, /* Decimal floating point. */
10732 + TYPE_CODE_MODULE, /* Fortran module. */
10734 /* Internal function type. */
10735 TYPE_CODE_INTERNAL_FUNCTION
10737 @@ -213,6 +215,11 @@ enum type_instance_flag_value
10739 #define TYPE_TARGET_STUB(t) (TYPE_MAIN_TYPE (t)->flag_target_stub)
10741 +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
10744 +#define TYPE_DYNAMIC(t) (TYPE_MAIN_TYPE (t)->flag_dynamic)
10746 /* Static type. If this is set, the corresponding type had
10747 * a static modifier.
10748 * Note: This may be unnecessary, since static data members
10749 @@ -278,6 +285,48 @@ enum type_instance_flag_value
10750 #define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner
10751 #define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL)
10753 +/* Define this type as being reclaimable during free_all_types. Type is
10754 + required to be have TYPE_OBJFILE set to NULL. Setting this flag requires
10755 + initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable. */
10757 +#define TYPE_DISCARDABLE(t) (TYPE_MAIN_TYPE (t)->flag_discardable)
10759 +/* Marker this type has been visited by the type_mark_used by this
10760 + mark-and-sweep types garbage collecting pass. Current pass is represented
10761 + by TYPE_DISCARDABLE_AGE_CURRENT. */
10763 +#define TYPE_DISCARDABLE_AGE(t) (TYPE_MAIN_TYPE (t)->flag_discardable_age)
10765 +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)? */
10767 +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
10768 + (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
10770 +/* Not allocated. TYPE_ALLOCATED(t) must be NULL in such case. If this flag
10771 + is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated. If this
10772 + flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
10773 + determines the actual allocation state. */
10775 +#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
10777 +/* Not associated. TYPE_ASSOCIATED(t) must be NULL in such case. If this flag
10778 + is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated. If
10779 + this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
10780 + determines the actual association state. */
10782 +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
10784 +/* Address of the actual data as for DW_AT_data_location. Its dwarf block must
10785 + not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
10786 + false. If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
10787 + is the actual data address value. If unset and
10788 + TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
10789 + value_raw_address. If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
10790 + then its DWARF block determines the actual data address. */
10792 +#define TYPE_DATA_LOCATION_IS_ADDR(t) \
10793 + (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
10795 /* Constant type. If this is set, the corresponding type has a
10798 @@ -365,6 +414,13 @@ struct main_type
10799 unsigned int flag_nottext : 1;
10800 unsigned int flag_fixed_instance : 1;
10801 unsigned int flag_objfile_owned : 1;
10802 + unsigned int flag_discardable : 1;
10803 + unsigned int flag_discardable_age : 1;
10804 + unsigned int flag_dynamic : 1;
10805 + unsigned int flag_range_high_bound_is_count : 1;
10806 + unsigned int flag_not_allocated : 1;
10807 + unsigned int flag_not_associated : 1;
10808 + unsigned int flag_data_location_is_addr : 1;
10810 /* Number of fields described for this type. This field appears at
10811 this location because it packs nicely here. */
10812 @@ -431,6 +487,20 @@ struct main_type
10814 struct type *target_type;
10816 + /* For DW_AT_data_location. */
10819 + struct dwarf2_locexpr_baton *dwarf_block;
10824 + /* For DW_AT_allocated. */
10825 + struct dwarf2_locexpr_baton *allocated;
10827 + /* For DW_AT_associated. */
10828 + struct dwarf2_locexpr_baton *associated;
10830 /* For structure and union types, a description of each field.
10831 For set and pascal array types, there is one "field",
10832 whose type is the domain type of the set or array.
10833 @@ -538,6 +608,9 @@ struct main_type
10834 supporting multiple ABIs. Right now this is only fetched from
10835 the Dwarf-2 DW_AT_calling_convention attribute. */
10836 unsigned calling_convention;
10838 + /* For TYPE_CODE_MODULE, the list of symbols contained in the module. */
10839 + struct block *module_block;
10843 @@ -812,9 +885,9 @@ extern void allocate_cplus_struct_type (struct type *);
10844 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
10845 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
10846 #define TYPE_CHAIN(thistype) (thistype)->chain
10847 -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
10848 - But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
10849 - so you only have to call check_typedef once. Since allocate_value
10850 +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
10851 + check_typedef. But check_typedef does set the TYPE_LENGTH of the TYPEDEF
10852 + type, so you only have to call check_typedef once. Since allocate_value
10853 calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
10854 #define TYPE_LENGTH(thistype) (thistype)->length
10855 /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
10856 @@ -823,23 +896,44 @@ extern void allocate_cplus_struct_type (struct type *);
10857 #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
10858 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
10859 #define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
10860 +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
10861 +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
10862 +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
10863 +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
10865 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
10866 #define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
10867 #define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
10869 -/* Moto-specific stuff for FORTRAN arrays */
10871 -#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
10872 - (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
10873 +#define TYPE_BYTE_STRIDE(range_type) TYPE_FIELD_BITPOS (range_type, 2)
10875 +/* Whether we should use TYPE_FIELD_DWARF_BLOCK (and not TYPE_FIELD_BITPOS). */
10876 +#define TYPE_RANGE_BOUND_IS_DWARF_BLOCK(range_type, fieldno) \
10877 + (TYPE_FIELD_LOC_KIND (range_type, fieldno) == FIELD_LOC_KIND_DWARF_BLOCK)
10878 +#define TYPE_RANGE_BOUND_SET_DWARF_BLOCK(range_type, fieldno) \
10879 + (TYPE_FIELD_LOC_KIND (range_type, fieldno) = FIELD_LOC_KIND_DWARF_BLOCK)
10880 +#define TYPE_ARRAY_BOUND_IS_DWARF_BLOCK(array_type, fieldno) \
10881 + TYPE_RANGE_BOUND_IS_DWARF_BLOCK (TYPE_INDEX_TYPE (array_type), fieldno)
10883 +/* Unbound arrays, such as GCC array[]; at end of struct. */
10884 +#define TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED(rangetype) \
10885 + TYPE_FIELD_ARTIFICIAL((rangetype),0)
10886 +#define TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED(rangetype) \
10887 + TYPE_FIELD_ARTIFICIAL((rangetype),1)
10888 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
10889 - (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
10891 -#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
10892 - (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
10893 + TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (TYPE_INDEX_TYPE (arraytype))
10894 +#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
10895 + TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (TYPE_INDEX_TYPE (arraytype))
10897 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
10898 - (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
10899 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
10900 +#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
10901 + TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (arraytype))
10902 +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
10903 + element size if no specific stride value is known. */
10904 +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype) \
10905 + (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \
10906 + ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype)) \
10907 + : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
10911 @@ -855,6 +949,7 @@ extern void allocate_cplus_struct_type (struct type *);
10912 #define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
10913 #define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
10914 #define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
10915 +#define TYPE_MODULE_BLOCK(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.module_block
10916 #define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
10917 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
10918 #define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
10919 @@ -1131,7 +1226,7 @@ extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN
10920 Use alloc_type_arch to allocate a type owned by an architecture.
10921 Use alloc_type_copy to allocate a type with the same owner as a
10922 pre-existing template type, no matter whether objfile or gdbarch. */
10923 -extern struct type *alloc_type (struct objfile *);
10924 +extern struct type *alloc_type (struct objfile *, struct type *);
10925 extern struct type *alloc_type_arch (struct gdbarch *);
10926 extern struct type *alloc_type_copy (const struct type *);
10928 @@ -1226,6 +1321,18 @@ extern struct type *create_array_type (struct type *, struct type *,
10930 extern struct type *lookup_array_range_type (struct type *, int, int);
10932 +extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
10935 +extern int type_range_high_bound_internal (struct type *range_type);
10937 +extern int type_range_count_bound_internal (struct type *range_type);
10939 +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
10940 + struct type *element_type);
10942 +extern void finalize_type (struct type *type);
10944 extern struct type *create_string_type (struct type *, struct type *,
10946 extern struct type *lookup_string_range_type (struct type *, int, int);
10947 @@ -1262,6 +1369,8 @@ extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
10949 extern int is_ancestor (struct type *, struct type *);
10951 +extern void type_mark_used (struct type *type);
10953 /* Overload resolution */
10955 #define LENGTH_MATCH(bv) ((bv)->rank[0])
10956 @@ -1324,10 +1433,15 @@ extern void maintenance_print_type (char *, int);
10958 extern htab_t create_copied_types_hash (struct objfile *objfile);
10960 -extern struct type *copy_type_recursive (struct objfile *objfile,
10961 - struct type *type,
10962 +extern struct type *copy_type_recursive (struct type *type,
10963 htab_t copied_types);
10965 extern struct type *copy_type (const struct type *type);
10967 +extern void free_all_types (void);
10969 +extern void type_incref (struct type *type);
10971 +extern void type_decref (struct type *type);
10973 #endif /* GDBTYPES_H */
10974 diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
10975 index 0f9d44e..c910e88 100644
10976 --- a/gdb/gnu-v3-abi.c
10977 +++ b/gdb/gnu-v3-abi.c
10979 #include "demangle.h"
10980 #include "objfiles.h"
10981 #include "valprint.h"
10982 +#include "c-lang.h"
10984 #include "gdb_assert.h"
10985 #include "gdb_string.h"
10986 @@ -459,10 +460,8 @@ gnuv3_find_method_in (struct type *domain, CORE_ADDR voffset,
10987 LONGEST adjustment)
10990 - const char *physname;
10992 /* Search this class first. */
10994 if (adjustment == 0)
10997 @@ -590,15 +589,24 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
10999 char *demangled_name = cplus_demangle (physname,
11000 DMGL_ANSI | DMGL_PARAMS);
11001 - if (demangled_name != NULL)
11002 + fprintf_filtered (stream, "&virtual ");
11003 + if (demangled_name == NULL)
11004 + fputs_filtered (physname, stream);
11007 - fprintf_filtered (stream, "&virtual ");
11008 fputs_filtered (demangled_name, stream);
11009 xfree (demangled_name);
11015 + else if (ptr_value != 0)
11017 + /* Found a non-virtual function: print out the type. */
11018 + fputs_filtered ("(", stream);
11019 + c_print_type (type, "", stream, -1, 0);
11020 + fputs_filtered (") ", stream);
11023 /* We didn't find it; print the raw data. */
11025 diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
11026 index fe848ff..905dcc3 100644
11027 --- a/gdb/i386-linux-nat.c
11028 +++ b/gdb/i386-linux-nat.c
11029 @@ -586,6 +586,8 @@ i386_linux_store_inferior_registers (struct target_ops *ops,
11031 static unsigned long i386_linux_dr[DR_CONTROL + 1];
11033 +/* Get debug register REGNUM value from only the one LWP of PTID. */
11035 static unsigned long
11036 i386_linux_dr_get (ptid_t ptid, int regnum)
11038 @@ -614,6 +616,8 @@ i386_linux_dr_get (ptid_t ptid, int regnum)
11042 +/* Set debug register REGNUM to VALUE in only the one LWP of PTID. */
11045 i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
11047 @@ -630,6 +634,8 @@ i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
11048 perror_with_name (_("Couldn't write debug register"));
11051 +/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST. */
11054 i386_linux_dr_set_control (unsigned long control)
11056 @@ -641,6 +647,8 @@ i386_linux_dr_set_control (unsigned long control)
11057 i386_linux_dr_set (ptid, DR_CONTROL, control);
11060 +/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST. */
11063 i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
11065 @@ -654,18 +662,55 @@ i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
11066 i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
11069 +/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST. */
11072 i386_linux_dr_reset_addr (int regnum)
11074 i386_linux_dr_set_addr (regnum, 0);
11077 +/* Get DR_STATUS from only the one LWP of INFERIOR_PTID. */
11079 static unsigned long
11080 i386_linux_dr_get_status (void)
11082 return i386_linux_dr_get (inferior_ptid, DR_STATUS);
11085 +/* Unset MASK bits in DR_STATUS in all LWPs of LWP_LIST. */
11088 +i386_linux_dr_unset_status (unsigned long mask)
11090 + struct lwp_info *lp;
11093 + ALL_LWPS (lp, ptid)
11095 + unsigned long value;
11097 + value = i386_linux_dr_get (ptid, DR_STATUS);
11099 + i386_linux_dr_set (ptid, DR_STATUS, value);
11103 +/* See i386_dr_low_type.detach. Do not use wrappers i386_linux_dr_set_control
11104 + or i386_linux_dr_reset_addr as they would modify the register cache
11105 + (i386_linux_dr). */
11108 +i386_linux_dr_detach (void)
11112 + i386_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
11113 + i386_linux_dr_unset_status (~0UL);
11114 + for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
11115 + i386_linux_dr_set (inferior_ptid, regnum, 0);
11119 i386_linux_new_thread (ptid_t ptid)
11121 @@ -837,6 +882,8 @@ _initialize_i386_linux_nat (void)
11122 i386_dr_low.set_addr = i386_linux_dr_set_addr;
11123 i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
11124 i386_dr_low.get_status = i386_linux_dr_get_status;
11125 + i386_dr_low.unset_status = i386_linux_dr_unset_status;
11126 + i386_dr_low.detach = i386_linux_dr_detach;
11127 i386_set_debug_register_length (4);
11129 /* Override the default ptrace resume method. */
11130 diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c
11131 index 325b4df..631ccd6 100644
11132 --- a/gdb/i386-nat.c
11133 +++ b/gdb/i386-nat.c
11134 @@ -137,8 +137,11 @@ struct i386_dr_low_type i386_dr_low;
11135 #define I386_DR_GET_RW_LEN(i) \
11136 ((dr_control_mirror >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f)
11138 +/* Mask that this I'th watchpoint has triggered. */
11139 +#define I386_DR_WATCH_MASK(i) (1 << (i))
11141 /* Did the watchpoint whose address is in the I'th register break? */
11142 -#define I386_DR_WATCH_HIT(i) (dr_status_mirror & (1 << (i)))
11143 +#define I386_DR_WATCH_HIT(i) (dr_status_mirror & I386_DR_WATCH_MASK (i))
11145 /* A macro to loop over all debug registers. */
11146 #define ALL_DEBUG_REGISTERS(i) for (i = 0; i < DR_NADDR; i++)
11147 @@ -358,6 +361,10 @@ i386_insert_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits)
11148 i386_dr_low.set_addr (i, addr);
11149 i386_dr_low.set_control (dr_control_mirror);
11151 + /* Only a sanity check for leftover bits (set possibly only by inferior). */
11152 + if (i386_dr_low.unset_status)
11153 + i386_dr_low.unset_status (I386_DR_WATCH_MASK (i));
11158 @@ -387,6 +394,11 @@ i386_remove_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits)
11159 i386_dr_low.set_control (dr_control_mirror);
11160 if (i386_dr_low.reset_addr)
11161 i386_dr_low.reset_addr (i);
11163 + /* Status must be already queried for each LWP. Otherwise it will
11164 + be lost in all-stop mode + breakpoint always-inserted off. */
11165 + if (i386_dr_low.unset_status)
11166 + i386_dr_low.unset_status (I386_DR_WATCH_MASK (i));
11170 @@ -520,6 +532,17 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type)
11174 +/* See target_detach_watchpoints. */
11177 +i386_detach_watchpoints (void)
11179 + if (i386_dr_low.detach)
11180 + i386_dr_low.detach ();
11185 /* Return non-zero if we can watch a memory region that starts at
11186 address ADDR and whose length is LEN bytes. */
11188 @@ -578,28 +601,7 @@ static int
11189 i386_stopped_by_watchpoint (void)
11191 CORE_ADDR addr = 0;
11192 - return i386_stopped_data_address (¤t_target, &addr);
11195 -/* Return non-zero if the inferior has some break/watchpoint that
11199 -i386_stopped_by_hwbp (void)
11203 - dr_status_mirror = i386_dr_low.get_status ();
11204 - if (maint_show_dr)
11205 - i386_show_dr ("stopped_by_hwbp", 0, 0, hw_execute);
11207 - ALL_DEBUG_REGISTERS(i)
11209 - if (I386_DR_WATCH_HIT (i))
11214 + return target_stopped_data_address (¤t_target, &addr);
11217 /* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
11218 @@ -693,6 +695,7 @@ i386_use_watchpoints (struct target_ops *t)
11219 t->to_stopped_data_address = i386_stopped_data_address;
11220 t->to_insert_watchpoint = i386_insert_watchpoint;
11221 t->to_remove_watchpoint = i386_remove_watchpoint;
11222 + t->to_detach_watchpoints = i386_detach_watchpoints;
11223 t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
11224 t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
11226 diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h
11227 index f49b9f6..cd31958 100644
11228 --- a/gdb/i386-nat.h
11229 +++ b/gdb/i386-nat.h
11230 @@ -49,16 +49,23 @@ extern void i386_use_watchpoints (struct target_ops *);
11233 set_control -- set the debug control (DR7)
11234 - register to a given value
11235 + register to a given value for all LWPs
11237 set_addr -- put an address into one debug
11239 + register for all LWPs
11241 reset_addr -- reset the address stored in
11242 - one debug register
11243 + one debug register for all LWPs
11245 get_status -- return the value of the debug
11246 - status (DR6) register.
11247 + status (DR6) register for current LWP
11249 + unset_status -- unset the specified bits of the debug
11250 + status (DR6) register for all LWPs
11252 + detach -- clear all debug registers of only the
11253 + INFERIOR_PTID task without affecting any
11256 Additionally, the native file should set the debug_register_length
11257 field to 4 or 8 depending on the number of bytes used for
11258 @@ -70,6 +77,8 @@ struct i386_dr_low_type
11259 void (*set_addr) (int, CORE_ADDR);
11260 void (*reset_addr) (int);
11261 unsigned long (*get_status) (void);
11262 + void (*unset_status) (unsigned long);
11263 + void (*detach) (void);
11264 int debug_register_length;
11267 diff --git a/gdb/infcall.c b/gdb/infcall.c
11268 index c9d98cf..277399a 100644
11269 --- a/gdb/infcall.c
11270 +++ b/gdb/infcall.c
11271 @@ -441,6 +441,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
11272 struct gdbarch *gdbarch;
11273 struct breakpoint *terminate_bp = NULL;
11274 struct minimal_symbol *tm;
11275 + struct cleanup *terminate_bp_cleanup = NULL;
11276 ptid_t call_thread_ptid;
11277 struct gdb_exception e;
11279 @@ -772,7 +773,7 @@ call_function_by_hand (struct value *function, int nargs, struct value **args)
11281 /* Register a clean-up for unwind_on_terminating_exception_breakpoint. */
11283 - make_cleanup_delete_breakpoint (terminate_bp);
11284 + terminate_bp_cleanup = make_cleanup_delete_breakpoint (terminate_bp);
11286 /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP -
11287 If you're looking to implement asynchronous dummy-frames, then
11288 @@ -987,6 +988,11 @@ When the function is done executing, GDB will silently stop."),
11289 internal_error (__FILE__, __LINE__, _("... should not be here"));
11292 + /* If we get here and the std::terminate() breakpoint has been set,
11293 + it has to be cleaned manually. */
11294 + if (terminate_bp)
11295 + do_cleanups (terminate_bp_cleanup);
11297 /* If we get here the called FUNCTION ran to completion,
11298 and the dummy frame has already been popped. */
11300 diff --git a/gdb/infcmd.c b/gdb/infcmd.c
11301 index 9e98290..fab1892 100644
11304 @@ -801,7 +801,7 @@ nexti_command (char *count_string, int from_tty)
11305 step_1 (1, 1, count_string);
11310 delete_longjmp_breakpoint_cleanup (void *arg)
11312 int thread = * (int *) arg;
11313 @@ -841,10 +841,13 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
11315 if (!single_inst || skip_subroutines) /* leave si command alone */
11317 + struct thread_info *tp = inferior_thread ();
11319 if (in_thread_list (inferior_ptid))
11320 thread = pid_to_thread_id (inferior_ptid);
11322 set_longjmp_breakpoint (thread);
11323 + tp->initiating_frame = get_frame_id (get_current_frame ());
11325 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11327 @@ -1193,6 +1196,15 @@ signal_command (char *signum_exp, int from_tty)
11328 proceed ((CORE_ADDR) -1, oursig, 0);
11331 +/* A continuation callback for until_next_command. */
11334 +until_next_continuation (void *arg)
11336 + struct thread_info *tp = arg;
11337 + delete_longjmp_breakpoint (tp->num);
11340 /* Proceed until we reach a different source line with pc greater than
11341 our current one or exit the function. We skip calls in both cases.
11343 @@ -1209,6 +1221,8 @@ until_next_command (int from_tty)
11344 struct symbol *func;
11345 struct symtab_and_line sal;
11346 struct thread_info *tp = inferior_thread ();
11347 + int thread = tp->num;
11348 + struct cleanup *old_chain;
11350 clear_proceed_status ();
11352 @@ -1244,7 +1258,19 @@ until_next_command (int from_tty)
11354 tp->step_multi = 0; /* Only one call to proceed */
11356 + set_longjmp_breakpoint (thread);
11357 + tp->initiating_frame = get_frame_id (frame);
11358 + old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11360 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
11362 + if (target_can_async_p () && is_running (inferior_ptid))
11364 + discard_cleanups (old_chain);
11365 + add_continuation (tp, until_next_continuation, tp, NULL);
11368 + do_cleanups (old_chain);
11372 @@ -1421,6 +1447,7 @@ finish_command_continuation (void *arg)
11373 if (bs != NULL && tp->proceed_to_finish)
11374 observer_notify_normal_stop (bs, 1 /* print frame */);
11375 delete_breakpoint (a->breakpoint);
11376 + delete_longjmp_breakpoint (inferior_thread ()->num);
11380 @@ -1504,6 +1531,7 @@ finish_forward (struct symbol *function, struct frame_info *frame)
11381 struct breakpoint *breakpoint;
11382 struct cleanup *old_chain;
11383 struct finish_command_continuation_args *cargs;
11384 + int thread = tp->num;
11386 sal = find_pc_line (get_frame_pc (frame), 0);
11387 sal.pc = get_frame_pc (frame);
11388 @@ -1514,6 +1542,10 @@ finish_forward (struct symbol *function, struct frame_info *frame)
11390 old_chain = make_cleanup_delete_breakpoint (breakpoint);
11392 + set_longjmp_breakpoint (thread);
11393 + tp->initiating_frame = get_frame_id (frame);
11394 + make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11396 tp->proceed_to_finish = 1; /* We want stop_registers, please... */
11397 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
11399 diff --git a/gdb/inferior.h b/gdb/inferior.h
11400 index f1b5d17..31add7d 100644
11401 --- a/gdb/inferior.h
11402 +++ b/gdb/inferior.h
11403 @@ -272,6 +272,8 @@ extern void interrupt_target_command (char *args, int from_tty);
11405 extern void interrupt_target_1 (int all_threads);
11407 +extern void delete_longjmp_breakpoint_cleanup (void *arg);
11409 extern void detach_command (char *, int);
11411 extern void notice_new_inferior (ptid_t, int, int);
11412 diff --git a/gdb/infrun.c b/gdb/infrun.c
11413 index ff7c6b9..9d29b15 100644
11417 #include "language.h"
11420 +#include "dictionary.h"
11421 +#include "block.h"
11422 #include "gdb_assert.h"
11423 #include "mi/mi-common.h"
11424 #include "event-top.h"
11425 @@ -1782,6 +1784,8 @@ static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
11426 struct symtab_and_line sr_sal,
11427 struct frame_id sr_id);
11428 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
11429 +static void check_exception_resume (struct execution_control_state *,
11430 + struct frame_info *, struct symbol *);
11432 static void stop_stepping (struct execution_control_state *ecs);
11433 static void prepare_to_wait (struct execution_control_state *ecs);
11434 @@ -2687,6 +2691,10 @@ handle_inferior_event (struct execution_control_state *ecs)
11436 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
11438 + /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
11439 + confuse bpstat_stop_status and bpstat_explains_signal. */
11440 + watchpoints_triggered (&ecs->ws);
11442 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
11444 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
11445 @@ -2724,6 +2732,10 @@ handle_inferior_event (struct execution_control_state *ecs)
11447 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
11449 + /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
11450 + confuse bpstat_stop_status and bpstat_explains_signal. */
11451 + watchpoints_triggered (&ecs->ws);
11453 /* This causes the eventpoints and symbol table to be reset.
11454 Must do this now, before trying to determine whether to
11456 @@ -2845,6 +2857,9 @@ targets should add new threads to the thread list themselves in non-stop mode.")
11458 struct regcache *regcache = get_thread_regcache (ecs->ptid);
11459 struct gdbarch *gdbarch = get_regcache_arch (regcache);
11460 + struct cleanup *old_chain = save_inferior_ptid ();
11462 + inferior_ptid = ecs->ptid;
11464 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
11465 paddress (gdbarch, stop_pc));
11466 @@ -2861,6 +2876,8 @@ targets should add new threads to the thread list themselves in non-stop mode.")
11467 fprintf_unfiltered (gdb_stdlog,
11468 "infrun: (no data address available)\n");
11471 + do_cleanups (old_chain);
11474 if (stepping_past_singlestep_breakpoint)
11475 @@ -3468,23 +3485,33 @@ process_event_stop_test:
11477 ecs->event_thread->stepping_over_breakpoint = 1;
11479 - if (!gdbarch_get_longjmp_target_p (gdbarch)
11480 - || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
11481 + if (what.is_longjmp)
11483 - if (debug_infrun)
11484 - fprintf_unfiltered (gdb_stdlog, "\
11485 + if (!gdbarch_get_longjmp_target_p (gdbarch)
11486 + || !gdbarch_get_longjmp_target (gdbarch,
11487 + frame, &jmp_buf_pc))
11489 + if (debug_infrun)
11490 + fprintf_unfiltered (gdb_stdlog, "\
11491 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
11492 - keep_going (ecs);
11495 + keep_going (ecs);
11499 - /* We're going to replace the current step-resume breakpoint
11500 - with a longjmp-resume breakpoint. */
11501 - delete_step_resume_breakpoint (ecs->event_thread);
11502 + /* We're going to replace the current step-resume breakpoint
11503 + with a longjmp-resume breakpoint. */
11504 + delete_step_resume_breakpoint (ecs->event_thread);
11506 - /* Insert a breakpoint at resume address. */
11507 - insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
11508 + /* Insert a breakpoint at resume address. */
11509 + insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
11513 + struct symbol *func = get_frame_function (frame);
11516 + check_exception_resume (ecs, frame, func);
11521 @@ -3496,6 +3523,53 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
11522 gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
11523 delete_step_resume_breakpoint (ecs->event_thread);
11525 + if (!what.is_longjmp)
11527 + /* There are several cases to consider.
11529 + 1. The initiating frame no longer exists. In this case
11530 + we must stop, because the exception has gone too far.
11532 + 2. The initiating frame exists, and is the same as the
11535 + 2.1. If we are stepping, defer to the stepping logic.
11537 + 2.2. Otherwise, we are not stepping, so we are doing a
11538 + "finish" and we have reached the calling frame. So,
11541 + 3. The initiating frame exists and is different from
11542 + the current frame. This means the exception has been
11543 + caught beneath the initiating frame, so keep going. */
11544 + struct frame_info *init_frame
11545 + = frame_find_by_id (ecs->event_thread->initiating_frame);
11548 + struct frame_id current_id
11549 + = get_frame_id (get_current_frame ());
11550 + if (frame_id_eq (current_id,
11551 + ecs->event_thread->initiating_frame))
11553 + if (ecs->event_thread->step_range_start)
11560 + /* Case 2.2: fall through. */
11566 + keep_going (ecs);
11572 ecs->event_thread->stop_step = 1;
11573 print_stop_reason (END_STEPPING_RANGE, 0);
11574 stop_stepping (ecs);
11575 @@ -4500,6 +4574,96 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
11576 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
11579 +/* Insert an exception resume breakpoint. TP is the thread throwing
11580 + the exception. The block B is the block of the unwinder debug hook
11581 + function. FRAME is the frame corresponding to the call to this
11582 + function. SYM is the symbol of the function argument holding the
11583 + target PC of the exception. */
11586 +insert_exception_resume_breakpoint (struct thread_info *tp,
11588 + struct frame_info *frame,
11589 + struct symbol *sym)
11591 + struct gdb_exception e;
11593 + /* We want to ignore errors here. */
11594 + TRY_CATCH (e, RETURN_MASK_ALL)
11596 + struct symbol *vsym;
11597 + struct value *value;
11598 + CORE_ADDR handler;
11599 + struct breakpoint *bp;
11601 + vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
11602 + value = read_var_value (vsym, frame);
11603 + handler = value_as_address (value);
11605 + /* We're going to replace the current step-resume breakpoint
11606 + with an exception-resume breakpoint. */
11607 + delete_step_resume_breakpoint (tp);
11609 + if (debug_infrun)
11610 + fprintf_unfiltered (gdb_stdlog,
11611 + "infrun: exception resume at %lx\n",
11612 + (unsigned long) handler);
11614 + bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
11615 + handler, bp_exception_resume);
11616 + inferior_thread ()->step_resume_breakpoint = bp;
11620 +/* This is called when an exception has been intercepted. Check to
11621 + see whether the exception's destination is of interest, and if so,
11622 + set an exception resume breakpoint there. */
11625 +check_exception_resume (struct execution_control_state *ecs,
11626 + struct frame_info *frame, struct symbol *func)
11628 + struct gdb_exception e;
11630 + TRY_CATCH (e, RETURN_MASK_ALL)
11633 + struct dict_iterator iter;
11634 + struct symbol *sym;
11637 + /* The exception breakpoint is a thread-specific breakpoint on
11638 + the unwinder's debug hook, declared as:
11640 + void _Unwind_DebugHook (void *cfa, void *handler);
11642 + The CFA argument indicates the frame to which control is
11643 + about to be transferred. HANDLER is the destination PC.
11645 + We ignore the CFA and set a temporary breakpoint at HANDLER.
11646 + This is not extremely efficient but it avoids issues in gdb
11647 + with computing the DWARF CFA, and it also works even in weird
11648 + cases such as throwing an exception from inside a signal
11651 + b = SYMBOL_BLOCK_VALUE (func);
11652 + ALL_BLOCK_SYMBOLS (b, iter, sym)
11654 + if (!SYMBOL_IS_ARGUMENT (sym))
11661 + insert_exception_resume_breakpoint (ecs->event_thread,
11670 stop_stepping (struct execution_control_state *ecs)
11672 @@ -4568,6 +4732,8 @@ keep_going (struct execution_control_state *ecs)
11676 + if (debug_infrun)
11677 + exception_fprintf (gdb_stdlog, e, "infrun: exception while inserting breakpoints: ");
11678 stop_stepping (ecs);
11681 diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
11682 index 6b68e7d..5095180 100644
11683 --- a/gdb/jv-lang.c
11684 +++ b/gdb/jv-lang.c
11685 @@ -1121,6 +1121,7 @@ const struct exp_descriptor exp_descriptor_java =
11687 print_subexp_standard,
11688 operator_length_standard,
11689 + operator_check_standard,
11691 dump_subexp_body_standard,
11692 evaluate_subexp_java
11693 diff --git a/gdb/language.h b/gdb/language.h
11694 index c650e07..660fdf6 100644
11695 --- a/gdb/language.h
11696 +++ b/gdb/language.h
11697 @@ -237,7 +237,6 @@ struct language_defn
11700 struct symbol *(*la_lookup_symbol_nonlocal) (const char *,
11702 const struct block *,
11703 const domain_enum);
11705 diff --git a/gdb/linespec.c b/gdb/linespec.c
11706 index 3e943a1..b96d425 100644
11707 --- a/gdb/linespec.c
11708 +++ b/gdb/linespec.c
11711 #include "completer.h"
11712 #include "cp-abi.h"
11713 +#include "cp-support.h"
11714 #include "parser-defs.h"
11716 #include "objc-lang.h"
11717 @@ -839,13 +840,33 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
11719 else if (paren_pointer != NULL)
11721 - p = paren_pointer + 1;
11722 + /* We need to deal with method and function overloads
11723 + with no parameters. Gdb and gcc (and who knows about other
11724 + compilers) are very inconsistent with the keyword "void".
11725 + Canonicalizing C++ types is insufficient in this case, since
11726 + we still need to enforce the presence (or lack thereof) of
11727 + "void". For simplicity, omit the keyword "void" if present. */
11728 + if (strncmp (paren_pointer - 5, "(void)", 6) == 0)
11731 + a = paren_pointer - 4;
11732 + b = paren_pointer;
11733 + while ((*(a++) = *(b++)) != '\0') ;
11735 + p = paren_pointer - 3;
11738 + p = paren_pointer + 1;
11742 p = skip_quoted (*argptr);
11745 + /* Make sure we keep important kewords like "const" */
11746 + if (strncmp (p, " const", 6) == 0)
11749 /* Keep any template parameters */
11751 p = find_template_name_end (p);
11752 @@ -1257,6 +1278,9 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
11753 /* Move pointer ahead to next double-colon. */
11754 while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\''))
11756 + if (current_language->la_language == language_cplus)
11757 + p += cp_validate_operator (p);
11761 temp_end = find_template_name_end (p);
11762 @@ -1334,6 +1358,15 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
11763 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':')
11765 /* At this point p->"". String ended. */
11766 + /* Nope, C++ operators could have spaces in them
11767 + ("foo::operator <" or "foo::operator delete []").
11768 + I apologize, this is a bit hacky... */
11769 + if (current_language->la_language == language_cplus
11770 + && *p == ' ' && p - 8 - *argptr + 1 > 0)
11772 + /* The above loop has already swallowed "operator". */
11773 + p += cp_validate_operator (p - 8) - 8;
11777 /* Allocate our own copy of the substring between argptr and
11778 @@ -1407,6 +1440,7 @@ lookup_prefix_sym (char **argptr, char *p)
11782 + struct symbol *sym;
11784 /* Extract the class name. */
11786 @@ -1425,7 +1459,26 @@ lookup_prefix_sym (char **argptr, char *p)
11787 /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
11788 argptr->"inA::fun" */
11790 - return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
11791 + sym = lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
11794 + /* Typedefs are in VAR_DOMAIN so the above symbol lookup will
11795 + fail when the user attempts to lookup a method of a class
11796 + via a typedef'd name (NOT via the classes name, which is already
11797 + handled in symbol_matches_domain). So try the lookup again
11798 + using VAR_DOMAIN (where typedefs live) and double-check that we
11799 + found a struct/class type. */
11800 + struct symbol *s = lookup_symbol (copy, 0, VAR_DOMAIN, 0);
11803 + struct type *t = SYMBOL_TYPE (s);
11804 + CHECK_TYPEDEF (t);
11805 + if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
11813 /* This finds the method COPY in the class whose type is T and whose
11814 @@ -1474,26 +1527,16 @@ find_method (int funfirstline, char ***canonical, char *saved_arg,
11820 - if (is_operator_name (copy))
11822 - tmp = (char *) alloca (strlen (copy + 3) + 9);
11823 - strcpy (tmp, "operator ");
11824 - strcat (tmp, copy + 3);
11829 *not_found_ptr = 1;
11830 - if (tmp[0] == '~')
11831 + if (copy[0] == '~')
11832 cplusplus_error (saved_arg,
11833 "the class `%s' does not have destructor defined\n",
11834 SYMBOL_PRINT_NAME (sym_class));
11836 cplusplus_error (saved_arg,
11837 "the class %s does not have any method named %s\n",
11838 - SYMBOL_PRINT_NAME (sym_class), tmp);
11839 + SYMBOL_PRINT_NAME (sym_class), copy);
11843 @@ -1780,7 +1823,7 @@ symbol_found (int funfirstline, char ***canonical, char *copy,
11845 struct blockvector *bv = BLOCKVECTOR (SYMBOL_SYMTAB (sym));
11846 struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
11847 - if (lookup_block_symbol (b, copy, NULL, VAR_DOMAIN) != NULL)
11848 + if (lookup_block_symbol (b, copy, VAR_DOMAIN) != NULL)
11849 build_canonical_line_spec (values.sals, copy, canonical);
11852 diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
11853 index 98f6347..0907f03 100644
11854 --- a/gdb/linux-nat.c
11855 +++ b/gdb/linux-nat.c
11856 @@ -1710,6 +1710,7 @@ resume_callback (struct lwp_info *lp, void *data)
11859 memset (&lp->siginfo, 0, sizeof (lp->siginfo));
11860 + lp->watchpoint_hit_set = 0;
11862 else if (lp->stopped && debug_linux_nat)
11863 fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (has pending)\n",
11864 @@ -1847,6 +1848,7 @@ linux_nat_resume (struct target_ops *ops,
11866 linux_ops->to_resume (linux_ops, ptid, step, signo);
11867 memset (&lp->siginfo, 0, sizeof (lp->siginfo));
11868 + lp->watchpoint_hit_set = 0;
11870 if (debug_linux_nat)
11871 fprintf_unfiltered (gdb_stdlog,
11872 @@ -2286,6 +2288,78 @@ maybe_clear_ignore_sigint (struct lwp_info *lp)
11876 +/* Fetch the possible triggered data watchpoint info and store it to LP.
11877 + The hardware data watchpoint trigger gets cleared during this fetch. */
11880 +save_sigtrap (struct lwp_info *lp)
11882 + struct cleanup *old_chain;
11884 + /* linux_nat_stopped_data_address is not even installed in this case. */
11885 + if (linux_ops->to_stopped_data_address == NULL)
11888 + old_chain = save_inferior_ptid ();
11889 + inferior_ptid = lp->ptid;
11891 + lp->watchpoint_hit_set =
11892 + linux_ops->to_stopped_data_address (¤t_target, &lp->watchpoint_hit);
11894 + do_cleanups (old_chain);
11897 +/* Wrap target_stopped_data_address where the GNU/Linux native target may be
11898 + directed by the watchpoint/debug register number. Base the reported value
11899 + on the triggered data address instead. During inferior stop the assignment
11900 + of watchpoint/debug registers may change making the register number specific
11901 + trigger info stale. */
11904 +linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
11906 + struct lwp_info *lp = find_lwp_pid (inferior_ptid);
11908 + gdb_assert (lp != NULL);
11910 + *addr_p = lp->watchpoint_hit;
11912 + return lp->watchpoint_hit_set;
11915 +/* In `set follow-fork-mode child' with multithreaded parent we need to detach
11916 + watchpoints from all the LWPs. In such case INFERIOR_PTID will be the
11917 + non-threaded new child while LWP_LIST will still contain all the threads of
11918 + the parent being detached. */
11921 +linux_nat_detach_watchpoints (void)
11923 + struct lwp_info *lp;
11924 + int found = 0, retval = 0;
11925 + ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
11926 + struct cleanup *old_chain = save_inferior_ptid ();
11928 + for (lp = lwp_list; lp; lp = lp->next)
11929 + if (ptid_match (lp->ptid, filter))
11931 + inferior_ptid = lp->ptid;
11932 + retval |= linux_ops->to_detach_watchpoints ();
11936 + do_cleanups (old_chain);
11940 + gdb_assert (!is_lwp (inferior_ptid));
11942 + retval |= linux_ops->to_detach_watchpoints ();
11948 /* Wait until LP is stopped. */
11951 @@ -2337,6 +2411,8 @@ stop_wait_callback (struct lwp_info *lp, void *data)
11952 /* Save the trap's siginfo in case we need it later. */
11955 + save_sigtrap (lp);
11957 /* Now resume this LWP and get the SIGSTOP event. */
11959 ptrace (PTRACE_CONT, GET_LWP (lp->ptid), 0, 0);
11960 @@ -2701,10 +2777,14 @@ linux_nat_filter_event (int lwpid, int status, int options)
11961 add_thread (lp->ptid);
11964 - /* Save the trap's siginfo in case we need it later. */
11965 if (WIFSTOPPED (status)
11966 && (WSTOPSIG (status) == SIGTRAP || WSTOPSIG (status) == TRAP_IS_SYSCALL))
11967 - save_siginfo (lp);
11969 + /* Save the trap's siginfo in case we need it later. */
11970 + save_siginfo (lp);
11972 + save_sigtrap (lp);
11975 /* Handle GNU/Linux's extended waitstatus for trace events.
11976 It is necessary to check if WSTOPSIG is signaling that
11977 @@ -4999,6 +5079,10 @@ linux_nat_add_target (struct target_ops *t)
11978 t->to_thread_alive = linux_nat_thread_alive;
11979 t->to_pid_to_str = linux_nat_pid_to_str;
11980 t->to_has_thread_control = tc_schedlock;
11981 + if (linux_ops->to_stopped_data_address)
11982 + t->to_stopped_data_address = linux_nat_stopped_data_address;
11983 + if (linux_ops->to_detach_watchpoints)
11984 + t->to_detach_watchpoints = linux_nat_detach_watchpoints;
11986 t->to_can_async_p = linux_nat_can_async_p;
11987 t->to_is_async_p = linux_nat_is_async_p;
11988 diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
11989 index eae74f3..73204fc 100644
11990 --- a/gdb/linux-nat.h
11991 +++ b/gdb/linux-nat.h
11992 @@ -62,6 +62,12 @@ struct lwp_info
11993 be the address of a hardware watchpoint. */
11994 struct siginfo siginfo;
11996 + /* WATCHPOINT_HIT_SET is non-zero if this LWP stopped with a trap and a data
11997 + watchpoint has been found as triggered. In such case WATCHPOINT_HIT
11998 + contains data address of the triggered data watchpoint. */
11999 + unsigned watchpoint_hit_set : 1;
12000 + CORE_ADDR watchpoint_hit;
12002 /* Non-zero if we expect a duplicated SIGINT. */
12005 diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
12006 index 88c7e5e..2d0b3ca 100644
12007 --- a/gdb/m2-lang.c
12008 +++ b/gdb/m2-lang.c
12009 @@ -356,6 +356,7 @@ const struct exp_descriptor exp_descriptor_modula2 =
12011 print_subexp_standard,
12012 operator_length_standard,
12013 + operator_check_standard,
12015 dump_subexp_body_standard,
12016 evaluate_subexp_modula2
12017 diff --git a/gdb/machoread.c b/gdb/machoread.c
12018 index 5f9a0fe..66fa067 100644
12019 --- a/gdb/machoread.c
12020 +++ b/gdb/machoread.c
12021 @@ -681,6 +681,7 @@ static struct sym_fns macho_sym_fns = {
12022 macho_new_init, /* sym_new_init: init anything gbl to entire symtab */
12023 macho_symfile_init, /* sym_init: read initial info, setup for sym_read() */
12024 macho_symfile_read, /* sym_read: read a symbol file into symtab */
12025 + NULL, /* sym_read_psymbols */
12026 macho_symfile_finish, /* sym_finish: finished with file, cleanup */
12027 macho_symfile_offsets, /* sym_offsets: xlate external to internal form */
12028 NULL /* next: pointer to next struct sym_fns */
12029 diff --git a/gdb/main.c b/gdb/main.c
12030 index 55411a8..ac9a540 100644
12034 #include "interps.h"
12037 +#include "python/python.h"
12038 #include "source.h"
12040 /* If nonzero, display time usage both at startup and for each command. */
12041 @@ -259,6 +260,8 @@ captured_main (void *data)
12042 char *cdarg = NULL;
12043 char *ttyarg = NULL;
12045 + int python_script = 0;
12047 /* These are static so that we can take their address in an initializer. */
12048 static int print_help;
12049 static int print_version;
12050 @@ -434,10 +437,14 @@ captured_main (void *data)
12051 {"args", no_argument, &set_args, 1},
12052 {"l", required_argument, 0, 'l'},
12053 {"return-child-result", no_argument, &return_child_result, 1},
12055 + {"python", no_argument, 0, 'P'},
12056 + {"P", no_argument, 0, 'P'},
12058 {0, no_argument, 0, 0}
12062 + while (!python_script)
12066 @@ -455,6 +462,9 @@ captured_main (void *data)
12068 /* Long option that just sets a flag. */
12071 + python_script = 1;
12076 @@ -631,7 +641,31 @@ extern int gdbtk_test (char *);
12081 + if (python_script)
12083 + /* The first argument is a python script to evaluate, and
12084 + subsequent arguments are passed to the script for
12085 + processing there. */
12086 + if (optind >= argc)
12088 + fprintf_unfiltered (gdb_stderr,
12089 + _("%s: Python script file name required\n"),
12094 + /* FIXME: should handle inferior I/O intelligently here.
12095 + E.g., should be possible to run gdb in pipeline and have
12096 + Python (and gdb) output go to stderr or file; and if a
12097 + prompt is needed, open the tty. */
12099 + /* FIXME: should read .gdbinit if, and only if, a prompt is
12100 + requested by the script. Though... maybe this is not
12102 + /* FIXME: likewise, reading in history. */
12103 + inhibit_gdbinit = 1;
12105 + else if (set_args)
12107 /* The remaining options are the command-line options for the
12108 inferior. The first one is the sym/exec file, and the rest
12109 @@ -864,7 +898,8 @@ Can't attach to process and specify a core file at the same time."));
12112 /* Read in the old history after all the command files have been read. */
12114 + if (!python_script)
12119 @@ -893,13 +928,25 @@ Can't attach to process and specify a core file at the same time."));
12123 - /* NOTE: cagney/1999-11-07: There is probably no reason for not
12124 - moving this loop and the code found in captured_command_loop()
12125 - into the command_loop() proper. The main thing holding back that
12126 - change - SET_TOP_LEVEL() - has been eliminated. */
12129 + if (python_script)
12131 - catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
12132 + extern int pagination_enabled;
12133 + pagination_enabled = 0;
12134 + run_python_script (argc - optind, &argv[optind]);
12140 + /* NOTE: cagney/1999-11-07: There is probably no reason for not
12141 + moving this loop and the code found in captured_command_loop()
12142 + into the command_loop() proper. The main thing holding back that
12143 + change - SET_TOP_LEVEL() - has been eliminated. */
12146 + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
12149 /* No exit -- exit is through quit_command. */
12151 @@ -931,7 +978,12 @@ print_gdb_help (struct ui_file *stream)
12152 fputs_unfiltered (_("\
12153 This is the GNU debugger. Usage:\n\n\
12154 gdb [options] [executable-file [core-file or process-id]]\n\
12155 - gdb [options] --args executable-file [inferior-arguments ...]\n\n\
12156 + gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
12158 + fputs_unfiltered (_("\
12159 + gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
12161 + fputs_unfiltered (_("\n\
12164 fputs_unfiltered (_("\
12165 @@ -969,7 +1021,13 @@ Options:\n\n\
12166 --nw Do not use a window interface.\n\
12167 --nx Do not read "), stream);
12168 fputs_unfiltered (gdbinit, stream);
12169 - fputs_unfiltered (_(" file.\n\
12170 + fputs_unfiltered (_(" file.\n"), stream);
12172 + fputs_unfiltered (_("\
12173 + --python, -P Following argument is Python script file; remaining\n\
12174 + arguments are passed to script.\n"), stream);
12176 + fputs_unfiltered (_("\
12177 --quiet Do not print version number on startup.\n\
12178 --readnow Fully read symbol files on first access.\n\
12180 diff --git a/gdb/maint.c b/gdb/maint.c
12181 index ecbae12..80fc36e 100644
12184 @@ -914,4 +914,12 @@ When enabled GDB is profiled."),
12185 show_maintenance_profile_p,
12186 &maintenance_set_cmdlist,
12187 &maintenance_show_cmdlist);
12188 + add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
12189 + &gdb_datadir, _("Set GDB's datadir path."),
12190 + _("Show GDB's datadir path."),
12192 +When set, GDB uses the specified path to search for data files."),
12194 + &maintenance_set_cmdlist,
12195 + &maintenance_show_cmdlist);
12197 diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
12198 index aac82e9..626292c 100644
12199 --- a/gdb/mdebugread.c
12200 +++ b/gdb/mdebugread.c
12201 @@ -4802,7 +4802,7 @@ new_type (char *name)
12205 - t = alloc_type (current_objfile);
12206 + t = alloc_type (current_objfile, NULL);
12207 TYPE_NAME (t) = name;
12208 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
12210 diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
12211 index 0baaa83..94ebfeb 100644
12212 --- a/gdb/mi/mi-cmd-var.c
12213 +++ b/gdb/mi/mi-cmd-var.c
12214 @@ -697,7 +697,6 @@ mi_cmd_var_update (char *command, char **argv, int argc)
12218 - /* Get varobj handle, if a valid var obj name was specified */
12219 struct varobj *var = varobj_get_handle (name);
12221 varobj_update_one (var, print_values, 1 /* explicit */);
12222 diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
12223 index 857a5d5..6181002 100644
12224 --- a/gdb/mi/mi-main.c
12225 +++ b/gdb/mi/mi-main.c
12226 @@ -1130,7 +1130,7 @@ mi_cmd_list_features (char *command, char **argv, int argc)
12227 ui_out_field_string (uiout, NULL, "frozen-varobjs");
12228 ui_out_field_string (uiout, NULL, "pending-breakpoints");
12229 ui_out_field_string (uiout, NULL, "thread-info");
12233 ui_out_field_string (uiout, NULL, "python");
12235 diff --git a/gdb/mipsread.c b/gdb/mipsread.c
12236 index a84003f..924c1c5 100644
12237 --- a/gdb/mipsread.c
12238 +++ b/gdb/mipsread.c
12239 @@ -394,6 +394,7 @@ static struct sym_fns ecoff_sym_fns =
12240 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
12241 mipscoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
12242 mipscoff_symfile_read, /* sym_read: read a symbol file into symtab */
12243 + NULL, /* sym_read_psymbols */
12244 mipscoff_symfile_finish, /* sym_finish: finished with file, cleanup */
12245 default_symfile_offsets, /* sym_offsets: dummy FIXME til implem sym reloc */
12246 default_symfile_segments, /* sym_segments: Get segment information from
12247 diff --git a/gdb/objfiles.c b/gdb/objfiles.c
12248 index 8dcca70..e5442ca 100644
12249 --- a/gdb/objfiles.c
12250 +++ b/gdb/objfiles.c
12251 @@ -634,6 +634,11 @@ objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
12255 + /* Alread QUICK_ADDRMAP tiself assumes all sections have the same offset. */
12256 + if (objfile->quick_addrmap)
12257 + addrmap_relocate (objfile->quick_addrmap,
12258 + ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
12261 struct partial_symbol **psym;
12263 @@ -731,6 +736,20 @@ have_partial_symbols (void)
12264 if (objfile_has_partial_symbols (ofp))
12268 + /* Try again, after reading partial symbols. We do this in two
12269 + passes because objfiles are always added to the head of the list,
12270 + and there might be a later objfile for which we've already read
12271 + partial symbols. */
12272 + ALL_OBJFILES (ofp)
12274 + require_partial_symbols (ofp);
12275 + if (ofp->psymtabs != NULL)
12284 diff --git a/gdb/objfiles.h b/gdb/objfiles.h
12285 index 62fa498..1fc9c6a 100644
12286 --- a/gdb/objfiles.h
12287 +++ b/gdb/objfiles.h
12288 @@ -212,6 +212,11 @@ struct objfile
12290 struct partial_symtab *psymtabs;
12292 + /* An address map that can be used to quickly determine if an
12293 + address comes from this objfile. This can be NULL. */
12295 + struct addrmap *quick_addrmap;
12297 /* Map addresses to the entries of PSYMTABS. It would be more efficient to
12298 have a map per the whole process but ADDRMAP cannot selectively remove
12299 its items during FREE_OBJFILE. This mapping is already present even for
12300 @@ -414,6 +419,15 @@ struct objfile
12302 #define OBJF_USERLOADED (1 << 3) /* User loaded */
12304 +/* Set if we have tried to read partial symtabs for this objfile.
12305 + This is used to allow lazy reading of partial symtabs. */
12307 +#define OBJF_SYMTABS_READ (1 << 6)
12309 +/* This flag is set for the main objfile. */
12311 +#define OBJF_MAIN (1 << 7)
12313 /* The object file that the main symbol table was loaded from (e.g. the
12314 argument to the "symbol-file" or "file" command). */
12316 @@ -568,6 +582,13 @@ extern void gdb_bfd_unref (struct bfd *abfd);
12317 ALL_OBJFILES (objfile) \
12318 ALL_OBJFILE_PSYMTABS (objfile, p)
12320 +/* Like ALL_PSYMTABS, but ensure that partial symbols have been read
12321 + before examining the objfile. */
12323 +#define ALL_PSYMTABS_REQUIRED(objfile, p) \
12324 + ALL_OBJFILES (objfile) \
12325 + ALL_OBJFILE_PSYMTABS (require_partial_symbols (objfile), p)
12327 /* Traverse all minimal symbols in all objfiles. */
12329 #define ALL_MSYMBOLS(objfile, m) \
12330 diff --git a/gdb/parse.c b/gdb/parse.c
12331 index ef938e3..c243bd8 100644
12334 @@ -63,6 +63,7 @@ const struct exp_descriptor exp_descriptor_standard =
12336 print_subexp_standard,
12337 operator_length_standard,
12338 + operator_check_standard,
12340 dump_subexp_body_standard,
12341 evaluate_subexp_standard
12342 @@ -837,6 +838,15 @@ operator_length_standard (struct expression *expr, int endpos,
12343 args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
12346 + case TYPE_INSTANCE:
12347 + oplen = 4 + longest_to_int (expr->elts[endpos - 2].longconst);
12351 + case TYPE_INSTANCE_LOOKUP:
12355 case OP_OBJC_MSGCALL: /* Objective C message (method) call */
12357 args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
12358 @@ -1355,6 +1365,150 @@ parser_fprintf (FILE *x, const char *y, ...)
12362 +/* Implementation of the exp_descriptor method operator_check. */
12365 +operator_check_standard (struct expression *exp, int pos,
12366 + int (*type_func) (struct type *type, void *data),
12367 + int (*objfile_func) (struct objfile *objfile,
12371 + const union exp_element *const elts = exp->elts;
12372 + struct type *type = NULL;
12373 + struct objfile *objfile = NULL;
12375 + /* Extended operators should have been already handled by exp_descriptor
12376 + iterate method of its specific language. */
12377 + gdb_assert (elts[pos].opcode < OP_EXTENDED0);
12379 + /* Track the callers of write_exp_elt_type for this table. */
12381 + switch (elts[pos].opcode)
12385 + case OP_DECFLOAT:
12392 + case UNOP_MEMVAL:
12394 + type = elts[pos + 1].type;
12397 + case UNOP_MEMVAL_TLS:
12398 + objfile = elts[pos + 1].objfile;
12399 + type = elts[pos + 2].type;
12402 + case OP_VAR_VALUE:
12404 + const struct block *const block = elts[pos + 1].block;
12405 + const struct symbol *const symbol = elts[pos + 2].symbol;
12406 + const struct obj_section *const section = SYMBOL_OBJ_SECTION (symbol);
12408 + /* Check objfile where the variable itself is placed. */
12409 + if (section && objfile_func && (*objfile_func) (section->objfile, data))
12412 + /* Check objfile where is placed the code touching the variable. */
12413 + objfile = block_objfile (block);
12415 + type = SYMBOL_TYPE (symbol);
12420 + /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
12422 + if (type && type_func && (*type_func) (type, data))
12424 + if (type && TYPE_OBJFILE (type) && objfile_func
12425 + && (*objfile_func) (TYPE_OBJFILE (type), data))
12427 + if (objfile && objfile_func && (*objfile_func) (objfile, data))
12433 +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
12434 + referenced by EXP. The functions are never called with NULL TYPE or NULL
12435 + OBJFILE. Functions get passed an arbitrary caller supplied DATA pointer.
12436 + If any of the functions returns non-zero value then (any other) non-zero
12437 + value is immediately returned to the caller. Otherwise zero is returned
12438 + after iterating through whole EXP. */
12441 +exp_iterate (struct expression *exp,
12442 + int (*type_func) (struct type *type, void *data),
12443 + int (*objfile_func) (struct objfile *objfile, void *data),
12447 + const union exp_element *const elts = exp->elts;
12449 + for (endpos = exp->nelts; endpos > 0; )
12451 + int pos, args, oplen = 0;
12453 + exp->language_defn->la_exp_desc->operator_length (exp, endpos,
12455 + gdb_assert (oplen > 0);
12457 + pos = endpos - oplen;
12458 + if (exp->language_defn->la_exp_desc->operator_check (exp, pos, type_func,
12459 + objfile_func, data))
12468 +/* Helper for exp_uses_objfile. */
12471 +exp_uses_objfile_iter (struct objfile *exp_objfile, void *objfile_voidp)
12473 + struct objfile *objfile = objfile_voidp;
12475 + return exp_objfile == objfile;
12478 +/* Return 1 if EXP uses OBJFILE (and will become dangling when OBJFILE
12479 + is unloaded), otherwise return 0. */
12482 +exp_uses_objfile (struct expression *exp, struct objfile *objfile)
12484 + return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
12487 +/* Helper for exp_types_mark_used. */
12490 +exp_types_mark_used_iter (struct type *type, void *unused)
12492 + type_mark_used (type);
12494 + /* Continue the traversal. */
12498 +/* Call type_mark_used for any TYPE contained in EXP. */
12501 +exp_types_mark_used (struct expression *exp)
12503 + exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
12507 _initialize_parse (void)
12509 diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
12510 index cbda9c3..a07e6f2 100644
12511 --- a/gdb/parser-defs.h
12512 +++ b/gdb/parser-defs.h
12513 @@ -189,6 +189,13 @@ extern void operator_length (struct expression *, int, int *, int *);
12515 extern void operator_length_standard (struct expression *, int, int *, int *);
12517 +extern int operator_check_standard (struct expression *exp, int pos,
12518 + int (*type_func) (struct type *type,
12520 + int (*objfile_func)
12521 + (struct objfile *objfile, void *data),
12524 extern char *op_name_standard (enum exp_opcode);
12526 extern struct type *follow_types (struct type *);
12527 @@ -267,6 +274,20 @@ struct exp_descriptor
12528 the number of subexpressions it takes. */
12529 void (*operator_length) (struct expression*, int, int*, int *);
12531 + /* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
12532 + referenced by the single operator of EXP at position POS. Operator
12533 + parameters are located at positive (POS + number) offsets in EXP.
12534 + The functions should never be called with NULL TYPE or NULL OBJFILE.
12535 + Functions should get passed an arbitrary caller supplied DATA pointer.
12536 + If any of the functions returns non-zero value then (any other) non-zero
12537 + value should be immediately returned to the caller. Otherwise zero
12538 + should be returned. */
12539 + int (*operator_check) (struct expression *exp, int pos,
12540 + int (*type_func) (struct type *type, void *data),
12541 + int (*objfile_func) (struct objfile *objfile,
12545 /* Name of this operator for dumping purposes. */
12546 char *(*op_name) (enum exp_opcode);
12548 @@ -299,4 +320,8 @@ extern void print_subexp_standard (struct expression *, int *,
12550 extern void parser_fprintf (FILE *, const char *, ...) ATTR_FORMAT (printf, 2 ,3);
12552 +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
12554 +extern void exp_types_mark_used (struct expression *exp);
12556 #endif /* PARSER_DEFS_H */
12557 diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
12558 index 47b74ad..22fb2fc 100644
12559 --- a/gdb/ppc-linux-nat.c
12560 +++ b/gdb/ppc-linux-nat.c
12561 @@ -1391,6 +1391,24 @@ ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw)
12565 +/* See target_detach_watchpoints. Do not use wrapper
12566 + ppc_linux_remove_watchpoint as it would modify the register cache
12567 + (saved_dabr_value). */
12570 +ppc_linux_detach_watchpoints (void)
12574 + tid = TIDGET (inferior_ptid);
12576 + tid = PIDGET (inferior_ptid);
12578 + if (ptrace (PTRACE_SET_DEBUGREG, tid, NULL, NULL) < 0)
12584 ppc_linux_new_thread (ptid_t ptid)
12586 @@ -1648,6 +1666,7 @@ _initialize_ppc_linux_nat (void)
12587 t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
12588 t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
12589 t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
12590 + t->to_detach_watchpoints = ppc_linux_detach_watchpoints;
12591 t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
12592 t->to_stopped_data_address = ppc_linux_stopped_data_address;
12593 t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
12594 diff --git a/gdb/printcmd.c b/gdb/printcmd.c
12595 index 5d8b936..fb0a455 100644
12596 --- a/gdb/printcmd.c
12597 +++ b/gdb/printcmd.c
12599 #include "exceptions.h"
12600 #include "observer.h"
12601 #include "solist.h"
12602 -#include "solib.h"
12603 #include "parser-defs.h"
12604 #include "charset.h"
12606 @@ -900,6 +899,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
12608 val = access_value_history (0);
12610 + /* Do not try to OBJECT_ADDRESS_SET here anything. We are interested in the
12611 + source variable base addresses as found by READ_VAR_VALUE. The value here
12612 + can be already a calculated expression address inappropriate for
12613 + DW_OP_push_object_address. */
12615 if (voidprint || (val && value_type (val) &&
12616 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
12618 @@ -1396,6 +1400,22 @@ x_command (char *exp, int from_tty)
12619 set_internalvar (lookup_internalvar ("__"), last_examine_value);
12623 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
12626 +print_types_mark_used (void)
12628 + struct display *d;
12630 + if (last_examine_value)
12631 + type_mark_used (value_type (last_examine_value));
12633 + for (d = display_chain; d; d = d->next)
12635 + exp_types_mark_used (d->exp);
12640 /* Add an expression to the auto-display chain.
12641 @@ -1798,50 +1818,6 @@ disable_display_command (char *args, int from_tty)
12645 -/* Return 1 if D uses SOLIB (and will become dangling when SOLIB
12646 - is unloaded), otherwise return 0. */
12649 -display_uses_solib_p (const struct display *d,
12650 - const struct so_list *solib)
12653 - struct expression *const exp = d->exp;
12654 - const union exp_element *const elts = exp->elts;
12656 - if (d->block != NULL
12657 - && solib_contains_address_p (solib, d->block->startaddr))
12660 - for (endpos = exp->nelts; endpos > 0; )
12662 - int i, args, oplen = 0;
12664 - exp->language_defn->la_exp_desc->operator_length (exp, endpos,
12666 - gdb_assert (oplen > 0);
12668 - i = endpos - oplen;
12669 - if (elts[i].opcode == OP_VAR_VALUE)
12671 - const struct block *const block = elts[i + 1].block;
12672 - const struct symbol *const symbol = elts[i + 2].symbol;
12673 - const struct obj_section *const section =
12674 - SYMBOL_OBJ_SECTION (symbol);
12676 - if (block != NULL
12677 - && solib_contains_address_p (solib, block->startaddr))
12680 - if (section && section->objfile == solib->objfile)
12689 /* display_chain items point to blocks and expressions. Some expressions in
12690 turn may point to symbols.
12691 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
12692 @@ -1853,18 +1829,20 @@ display_uses_solib_p (const struct display *d,
12694 clear_dangling_display_expressions (struct so_list *solib)
12696 + struct objfile *objfile = solib->objfile;
12698 - struct objfile *objfile = NULL;
12700 - for (d = display_chain; d; d = d->next)
12702 - if (d->exp && display_uses_solib_p (d, solib))
12709 + if (objfile == NULL)
12712 + for (d = display_chain; d != NULL; d = d->next)
12713 + if (block_objfile (d->block) == objfile
12714 + || (d->exp && exp_uses_objfile (d->exp, objfile)))
12723 @@ -2749,4 +2727,6 @@ Show printing of source filename and line number with <symbol>."), NULL,
12725 show_print_symbol_filename,
12726 &setprintlist, &showprintlist);
12728 + observer_attach_mark_used (print_types_mark_used);
12730 diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
12731 new file mode 100644
12732 index 0000000..5654546
12734 +++ b/gdb/python/lib/gdb/FrameIterator.py
12736 +# Iterator over frames.
12738 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12740 +# This program is free software; you can redistribute it and/or modify
12741 +# it under the terms of the GNU General Public License as published by
12742 +# the Free Software Foundation; either version 3 of the License, or
12743 +# (at your option) any later version.
12745 +# This program is distributed in the hope that it will be useful,
12746 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12747 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12748 +# GNU General Public License for more details.
12750 +# You should have received a copy of the GNU General Public License
12751 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12753 +class FrameIterator:
12754 + """An iterator that iterates over frames."""
12756 + def __init__ (self, frame):
12757 + "Initialize a FrameIterator. FRAME is the starting frame."
12758 + self.frame = frame
12760 + def __iter__ (self):
12764 + result = self.frame
12765 + if result is None:
12766 + raise StopIteration
12767 + self.frame = result.older ()
12769 diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
12770 new file mode 100644
12771 index 0000000..b790a54
12773 +++ b/gdb/python/lib/gdb/FrameWrapper.py
12775 +# Wrapper API for frames.
12777 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12779 +# This program is free software; you can redistribute it and/or modify
12780 +# it under the terms of the GNU General Public License as published by
12781 +# the Free Software Foundation; either version 3 of the License, or
12782 +# (at your option) any later version.
12784 +# This program is distributed in the hope that it will be useful,
12785 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12786 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12787 +# GNU General Public License for more details.
12789 +# You should have received a copy of the GNU General Public License
12790 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12794 +# FIXME: arguably all this should be on Frame somehow.
12795 +class FrameWrapper:
12796 + def __init__ (self, frame):
12797 + self.frame = frame;
12799 + def write_symbol (self, stream, sym, block):
12800 + if len (sym.linkage_name):
12801 + nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
12802 + if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
12805 + stream.write (sym.print_name + "=")
12807 + val = self.read_var (sym)
12810 + # FIXME: would be nice to have a more precise exception here.
12811 + except RuntimeError, text:
12814 + stream.write ("???")
12816 + stream.write (str (val))
12818 + def print_frame_locals (self, stream, func):
12823 + block = func.value
12825 + for sym in block:
12826 + if sym.is_argument:
12829 + self.write_symbol (stream, sym, block)
12830 + stream.write ('\n')
12832 + def print_frame_args (self, stream, func):
12837 + block = func.value
12839 + for sym in block:
12840 + if not sym.is_argument:
12844 + stream.write (", ")
12846 + self.write_symbol (stream, sym, block)
12849 + # FIXME: this should probably just be a method on gdb.Frame.
12850 + # But then we need stream wrappers.
12851 + def describe (self, stream, full):
12852 + if self.type () == gdb.DUMMY_FRAME:
12853 + stream.write (" <function called from gdb>\n")
12854 + elif self.type () == gdb.SIGTRAMP_FRAME:
12855 + stream.write (" <signal handler called>\n")
12857 + sal = self.find_sal ()
12859 + name = self.name ()
12862 + if pc != sal.pc or not sal.symtab:
12863 + stream.write (" 0x%08x in" % pc)
12864 + stream.write (" " + name + " (")
12866 + func = self.function ()
12867 + self.print_frame_args (stream, func)
12869 + stream.write (")")
12871 + if sal.symtab and sal.symtab.filename:
12872 + stream.write (" at " + sal.symtab.filename)
12873 + stream.write (":" + str (sal.line))
12875 + if not self.name () or (not sal.symtab or not sal.symtab.filename):
12876 + lib = gdb.solib_address (pc)
12878 + stream.write (" from " + lib)
12880 + stream.write ("\n")
12883 + self.print_frame_locals (stream, func)
12885 + def __getattr__ (self, name):
12886 + return getattr (self.frame, name)
12887 diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
12888 new file mode 100644
12889 index 0000000..b375c68
12891 +++ b/gdb/python/lib/gdb/__init__.py
12895 +# Copyright (C) 2008 Free Software Foundation, Inc.
12897 +# This program is free software; you can redistribute it and/or modify
12898 +# it under the terms of the GNU General Public License as published by
12899 +# the Free Software Foundation; either version 3 of the License, or
12900 +# (at your option) any later version.
12902 +# This program is distributed in the hope that it will be useful,
12903 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12904 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12905 +# GNU General Public License for more details.
12907 +# You should have received a copy of the GNU General Public License
12908 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12910 +# Load the require command by default.
12911 +import gdb.command.require
12912 diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
12913 new file mode 100644
12914 index 0000000..2baab5f
12916 +++ b/gdb/python/lib/gdb/backtrace.py
12918 +# Filtering backtrace.
12920 +# Copyright (C) 2008 Free Software Foundation, Inc.
12922 +# This program is free software; you can redistribute it and/or modify
12923 +# it under the terms of the GNU General Public License as published by
12924 +# the Free Software Foundation; either version 3 of the License, or
12925 +# (at your option) any later version.
12927 +# This program is distributed in the hope that it will be useful,
12928 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12929 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12930 +# GNU General Public License for more details.
12932 +# You should have received a copy of the GNU General Public License
12933 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12938 +# Our only exports.
12939 +__all__ = ['push_frame_filter', 'create_frame_filter']
12941 +frame_filter = None
12943 +def push_frame_filter (constructor):
12944 + """Register a new backtrace filter class with the 'backtrace' command.
12945 +The filter will be passed an iterator as an argument. The iterator
12946 +will return gdb.Frame-like objects. The filter should in turn act as
12947 +an iterator returning such objects."""
12948 + global frame_filter
12949 + if frame_filter == None:
12950 + frame_filter = constructor
12952 + frame_filter = lambda iterator: constructor (frame_filter (iterator))
12954 +def create_frame_filter (iter):
12955 + global frame_filter
12956 + if frame_filter is None:
12958 + return frame_filter (iter)
12960 diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
12961 new file mode 100644
12962 index 0000000..8b13789
12964 +++ b/gdb/python/lib/gdb/command/__init__.py
12967 diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
12968 new file mode 100644
12969 index 0000000..96b6618
12971 +++ b/gdb/python/lib/gdb/command/alias.py
12975 +# Copyright (C) 2008 Free Software Foundation, Inc.
12977 +# This program is free software; you can redistribute it and/or modify
12978 +# it under the terms of the GNU General Public License as published by
12979 +# the Free Software Foundation; either version 3 of the License, or
12980 +# (at your option) any later version.
12982 +# This program is distributed in the hope that it will be useful,
12983 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12984 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12985 +# GNU General Public License for more details.
12987 +# You should have received a copy of the GNU General Public License
12988 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12992 +class AliasImplementation (gdb.Command):
12993 + def __init__ (self, name, real, doc):
12994 + # Have to set __doc__ before the super init call.
12995 + # It would be nice if gdb's help looked up __doc__ dynamically.
12996 + self.__doc__ = doc
12997 + # Note: no good way to complete :(
12998 + super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE)
13001 + def invoke(self, arg, from_tty):
13002 + gdb.execute (self.real + ' ' + arg, from_tty)
13004 +class AliasCommand (gdb.Command):
13005 + """Alias one command to another.
13006 +In the simplest form, the first word is the name of the alias, and
13007 +the remaining words are the the expansion.
13008 +An '=' by itself can be used to define a multi-word alias; words
13009 +before the '=' are the name of the new command."""
13011 + def __init__ (self):
13012 + # Completion is not quite right here.
13013 + super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE,
13014 + gdb.COMPLETE_COMMAND)
13016 + def invoke (self, arg, from_tty):
13017 + self.dont_repeat ()
13018 + # Without some form of quoting we can't alias a multi-word
13019 + # command to another command.
13020 + args = arg.split()
13022 + start = args.index ('=')
13024 + except ValueError:
13027 + target = " ".join(args[end:])
13028 + AliasImplementation (" ".join (args[0:start]), target,
13029 + "This command is an alias for '%s'." % target)
13032 diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
13033 new file mode 100644
13034 index 0000000..ec9a527
13036 +++ b/gdb/python/lib/gdb/command/backtrace.py
13038 +# New backtrace command.
13040 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13042 +# This program is free software; you can redistribute it and/or modify
13043 +# it under the terms of the GNU General Public License as published by
13044 +# the Free Software Foundation; either version 3 of the License, or
13045 +# (at your option) any later version.
13047 +# This program is distributed in the hope that it will be useful,
13048 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13049 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13050 +# GNU General Public License for more details.
13052 +# You should have received a copy of the GNU General Public License
13053 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13056 +import gdb.backtrace
13058 +from gdb.FrameIterator import FrameIterator
13059 +from gdb.FrameWrapper import FrameWrapper
13062 +class ReverseBacktraceParameter (gdb.Parameter):
13063 + """The new-backtrace command can show backtraces in 'reverse' order.
13064 +This means that the innermost frame will be printed last.
13065 +Note that reverse backtraces are more expensive to compute."""
13067 + set_doc = "Enable or disable reverse backtraces."
13068 + show_doc = "Show whether backtraces will be printed in reverse order."
13070 + def __init__(self):
13071 + gdb.Parameter.__init__ (self, "reverse-backtrace",
13072 + gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
13073 + # Default to compatibility with gdb.
13074 + self.value = False
13076 +class FilteringBacktrace (gdb.Command):
13077 + """Print backtrace of all stack frames, or innermost COUNT frames.
13078 +With a negative argument, print outermost -COUNT frames.
13079 +Use of the 'full' qualifier also prints the values of the local variables.
13080 +Use of the 'raw' qualifier avoids any filtering by loadable modules.
13083 + def __init__ (self):
13084 + # FIXME: this is not working quite well enough to replace
13085 + # "backtrace" yet.
13086 + gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
13087 + self.reverse = ReverseBacktraceParameter()
13089 + def reverse_iter (self, iter):
13091 + for item in iter:
13092 + result.append (item)
13096 + def final_n (self, iter, x):
13098 + for item in iter:
13099 + result.append (item)
13100 + return result[x:]
13102 + def invoke (self, arg, from_tty):
13108 + for word in arg.split (" "):
13111 + elif word == 'raw':
13113 + elif word == 'full':
13116 + count = int (word)
13118 + # FIXME: provide option to start at selected frame
13119 + # However, should still number as if starting from newest
13120 + newest_frame = gdb.selected_thread ().newest_frame ()
13121 + iter = itertools.imap (FrameWrapper,
13122 + FrameIterator (newest_frame))
13124 + iter = gdb.backtrace.create_frame_filter (iter)
13126 + # Now wrap in an iterator that numbers the frames.
13127 + iter = itertools.izip (itertools.count (0), iter)
13129 + # Reverse if the user wanted that.
13130 + if self.reverse.value:
13131 + iter = self.reverse_iter (iter)
13133 + # Extract sub-range user wants.
13135 + iter = self.final_n (iter, count)
13137 + iter = itertools.islice (iter, 0, count)
13139 + for pair in iter:
13140 + sys.stdout.write ("#%-2d" % pair[0])
13141 + pair[1].describe (sys.stdout, full)
13143 +FilteringBacktrace()
13144 diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
13145 new file mode 100644
13146 index 0000000..6fa48ff
13148 +++ b/gdb/python/lib/gdb/command/ignore_errors.py
13150 +# Ignore errors in user commands.
13152 +# Copyright (C) 2008 Free Software Foundation, Inc.
13154 +# This program is free software; you can redistribute it and/or modify
13155 +# it under the terms of the GNU General Public License as published by
13156 +# the Free Software Foundation; either version 3 of the License, or
13157 +# (at your option) any later version.
13159 +# This program is distributed in the hope that it will be useful,
13160 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13161 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13162 +# GNU General Public License for more details.
13164 +# You should have received a copy of the GNU General Public License
13165 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13169 +class IgnoreErrorsCommand (gdb.Command):
13170 + """Execute a single command, ignoring all errors.
13171 +Only one-line commands are supported.
13172 +This is primarily useful in scripts."""
13174 + def __init__ (self):
13175 + super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
13176 + gdb.COMMAND_OBSCURE,
13178 + gdb.COMPLETE_COMMAND)
13180 + def invoke (self, arg, from_tty):
13182 + gdb.execute (arg, from_tty)
13186 +IgnoreErrorsCommand ()
13187 diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
13188 new file mode 100644
13189 index 0000000..21a0bf0
13191 +++ b/gdb/python/lib/gdb/command/pahole.py
13193 +# pahole command for gdb
13195 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13197 +# This program is free software; you can redistribute it and/or modify
13198 +# it under the terms of the GNU General Public License as published by
13199 +# the Free Software Foundation; either version 3 of the License, or
13200 +# (at your option) any later version.
13202 +# This program is distributed in the hope that it will be useful,
13203 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13204 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13205 +# GNU General Public License for more details.
13207 +# You should have received a copy of the GNU General Public License
13208 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13212 +class Pahole (gdb.Command):
13213 + """Show the holes in a structure.
13214 +This command takes a single argument, a type name.
13215 +It prints the type and displays comments showing where holes are."""
13217 + def __init__ (self):
13218 + super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
13219 + gdb.COMPLETE_SYMBOL)
13221 + def pahole (self, type, level, name):
13227 + print '%sstruct %s {' % (' ' * (2 * level), tag)
13229 + for field in type.fields ():
13230 + # Skip static fields.
13231 + if not hasattr (field, ('bitpos')):
13234 + ftype = field.type.strip_typedefs()
13236 + if bitpos != field.bitpos:
13237 + hole = field.bitpos - bitpos
13238 + print ' /* XXX %d bit hole, try to pack */' % hole
13239 + bitpos = field.bitpos
13240 + if field.bitsize > 0:
13241 + fieldsize = field.bitsize
13243 + # TARGET_CHAR_BIT here...
13244 + fieldsize = 8 * ftype.sizeof
13246 + # TARGET_CHAR_BIT
13247 + print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
13248 + bitpos = bitpos + fieldsize
13250 + if ftype.code == gdb.TYPE_CODE_STRUCT:
13251 + self.pahole (ftype, level + 1, field.name)
13253 + print ' ' * (2 + 2 * level),
13254 + print '%s %s' % (str (ftype), field.name)
13256 + print ' ' * (14 + 2 * level),
13257 + print '} %s' % name
13259 + def invoke (self, arg, from_tty):
13260 + type = gdb.lookup_type (arg)
13261 + type = type.strip_typedefs ()
13262 + if type.code != gdb.TYPE_CODE_STRUCT:
13263 + raise TypeError, '%s is not a struct type' % arg
13265 + self.pahole (type, 0, '')
13268 diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
13269 new file mode 100644
13270 index 0000000..1fbc1e8
13272 +++ b/gdb/python/lib/gdb/command/require.py
13274 +# Demand-loading commands.
13276 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13278 +# This program is free software; you can redistribute it and/or modify
13279 +# it under the terms of the GNU General Public License as published by
13280 +# the Free Software Foundation; either version 3 of the License, or
13281 +# (at your option) any later version.
13283 +# This program is distributed in the hope that it will be useful,
13284 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13285 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13286 +# GNU General Public License for more details.
13288 +# You should have received a copy of the GNU General Public License
13289 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13294 +class RequireCommand (gdb.Command):
13295 + """Prefix command for requiring features."""
13297 + def __init__ (self):
13298 + super (RequireCommand, self).__init__ ("require",
13299 + gdb.COMMAND_SUPPORT,
13300 + gdb.COMPLETE_NONE,
13303 +class RequireSubcommand (gdb.Command):
13304 + """Demand-load a command by name."""
13306 + def __init__ (self, name):
13307 + self.__doc__ = "Demand-load a %s by name." % name
13308 + super (RequireSubcommand, self).__init__ ("require %s" % name,
13309 + gdb.COMMAND_SUPPORT)
13312 + def invoke (self, arg, from_tty):
13313 + for cmd in arg.split():
13314 + exec ('import gdb.' + self.name + '.' + cmd, globals ())
13316 + def complete (self, text, word):
13317 + dir = gdb.pythondir + '/gdb/' + self.name
13319 + for file in os.listdir(dir):
13320 + if not file.startswith (word) or not file.endswith ('.py'):
13322 + feature = file[0:-3]
13323 + if feature == 'require' or feature == '__init__':
13325 + result.append (feature)
13329 +RequireSubcommand("command")
13330 +RequireSubcommand("function")
13331 diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
13332 new file mode 100644
13333 index 0000000..6143187
13335 +++ b/gdb/python/lib/gdb/command/save_breakpoints.py
13337 +# Save breakpoints.
13339 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13341 +# This program is free software; you can redistribute it and/or modify
13342 +# it under the terms of the GNU General Public License as published by
13343 +# the Free Software Foundation; either version 3 of the License, or
13344 +# (at your option) any later version.
13346 +# This program is distributed in the hope that it will be useful,
13347 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13348 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13349 +# GNU General Public License for more details.
13351 +# You should have received a copy of the GNU General Public License
13352 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13354 +from __future__ import with_statement
13357 +class SavePrefixCommand (gdb.Command):
13358 + "Prefix command for saving things."
13360 + def __init__ (self):
13361 + super (SavePrefixCommand, self).__init__ ("save",
13362 + gdb.COMMAND_SUPPORT,
13363 + gdb.COMPLETE_NONE, True)
13365 +class SaveBreakpointsCommand (gdb.Command):
13366 + """Save the current breakpoints to a file.
13367 +This command takes a single argument, a file name.
13368 +The breakpoints can be restored using the 'source' command."""
13370 + def __init__ (self):
13371 + super (SaveBreakpointsCommand, self).__init__ ("save breakpoints",
13372 + gdb.COMMAND_SUPPORT,
13373 + gdb.COMPLETE_FILENAME)
13375 + def invoke (self, arg, from_tty):
13376 + self.dont_repeat ()
13377 + bps = gdb.breakpoints ()
13379 + raise RuntimeError, 'No breakpoints to save'
13380 + with open (arg.strip (), 'w') as f:
13382 + print >> f, "break", bp.location,
13383 + if bp.thread is not None:
13384 + print >> f, " thread", bp.thread,
13385 + if bp.condition is not None:
13386 + print >> f, " if", bp.condition,
13388 + if not bp.enabled:
13389 + print >> f, "disable $bpnum"
13390 + # Note: we don't save the ignore count; there doesn't
13391 + # seem to be much point.
13392 + commands = bp.commands
13393 + if commands is not None:
13394 + print >> f, "commands"
13395 + # Note that COMMANDS has a trailing newline.
13396 + print >> f, commands,
13397 + print >> f, "end"
13400 +SavePrefixCommand ()
13401 +SaveBreakpointsCommand ()
13402 diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
13403 new file mode 100644
13404 index 0000000..faf54ed
13406 +++ b/gdb/python/lib/gdb/command/upto.py
13410 +# Copyright (C) 2009 Free Software Foundation, Inc.
13412 +# This program is free software; you can redistribute it and/or modify
13413 +# it under the terms of the GNU General Public License as published by
13414 +# the Free Software Foundation; either version 3 of the License, or
13415 +# (at your option) any later version.
13417 +# This program is distributed in the hope that it will be useful,
13418 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13419 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13420 +# GNU General Public License for more details.
13422 +# You should have received a copy of the GNU General Public License
13423 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13427 +from gdb.FrameIterator import FrameIterator
13428 +from gdb.FrameWrapper import FrameWrapper
13430 +class UptoPrefix (gdb.Command):
13431 + def __init__ (self):
13432 + super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
13435 +class UptoImplementation (gdb.Command):
13436 + def __init__ (self, subcommand):
13437 + super (UptoImplementation, self).__init__ ("upto " + subcommand,
13438 + gdb.COMMAND_STACK)
13440 + def search (self):
13441 + saved = gdb.selected_frame ()
13442 + iter = FrameIterator (saved)
13445 + for frame in iter:
13448 + if self.filter (frame):
13449 + wrapper = FrameWrapper (frame)
13450 + wrapper.describe (sys.stdout, False)
13457 + raise RuntimeError, 'Could not find a matching frame'
13459 + def invoke (self, arg, from_tty):
13460 + self.rx = re.compile (arg)
13463 +class UptoSymbolCommand (UptoImplementation):
13464 + """Select and print some calling stack frame, based on symbol.
13465 +The argument is a regular expression. This command moves up the
13466 +stack, stopping at the first frame whose symbol matches the regular
13469 + def __init__ (self):
13470 + super (UptoSymbolCommand, self).__init__ ("symbol")
13472 + def filter (self, frame):
13473 + name = frame.name ()
13474 + if name is not None:
13475 + if self.rx.search (name) is not None:
13479 +class UptoSourceCommand (UptoImplementation):
13480 + """Select and print some calling stack frame, based on source file.
13481 +The argument is a regular expression. This command moves up the
13482 +stack, stopping at the first frame whose source file name matches the
13483 +regular expression."""
13485 + def __init__ (self):
13486 + super (UptoSourceCommand, self).__init__ ("source")
13488 + def filter (self, frame):
13489 + name = frame.find_sal ().symtab.filename
13490 + if name is not None:
13491 + if self.rx.search (name) is not None:
13495 +class UptoObjectCommand (UptoImplementation):
13496 + """Select and print some calling stack frame, based on object file.
13497 +The argument is a regular expression. This command moves up the
13498 +stack, stopping at the first frame whose object file name matches the
13499 +regular expression."""
13501 + def __init__ (self):
13502 + super (UptoObjectCommand, self).__init__ ("object")
13504 + def filter (self, frame):
13505 + name = frame.find_sal ().symtab.objfile.filename
13506 + if name is not None:
13507 + if self.rx.search (name) is not None:
13511 +class UptoWhereCommand (UptoImplementation):
13512 + """Select and print some calling stack frame, based on expression.
13513 +The argument is an expression. This command moves up the stack,
13514 +parsing and evaluating the expression in each frame. This stops when
13515 +the expression evaluates to a non-zero (true) value."""
13517 + def __init__ (self):
13518 + super (UptoWhereCommand, self).__init__ ("where")
13520 + def filter (self, frame):
13522 + if gdb.parse_and_eval (self.expression):
13528 + def invoke (self, arg, from_tty):
13529 + self.expression = arg
13533 +UptoSymbolCommand ()
13534 +UptoSourceCommand ()
13535 +UptoObjectCommand ()
13536 +UptoWhereCommand ()
13537 diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
13538 new file mode 100644
13539 index 0000000..8b13789
13541 +++ b/gdb/python/lib/gdb/function/__init__.py
13544 diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
13545 new file mode 100644
13546 index 0000000..2b9c5c7
13548 +++ b/gdb/python/lib/gdb/function/caller_is.py
13550 +# Caller-is functions.
13552 +# Copyright (C) 2008 Free Software Foundation, Inc.
13554 +# This program is free software; you can redistribute it and/or modify
13555 +# it under the terms of the GNU General Public License as published by
13556 +# the Free Software Foundation; either version 3 of the License, or
13557 +# (at your option) any later version.
13559 +# This program is distributed in the hope that it will be useful,
13560 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13561 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13562 +# GNU General Public License for more details.
13564 +# You should have received a copy of the GNU General Public License
13565 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13570 +class CallerIs (gdb.Function):
13571 + """Return True if the calling function's name is equal to a string.
13572 +This function takes one or two arguments.
13573 +The first argument is the name of a function; if the calling function's
13574 +name is equal to this argument, this function returns True.
13575 +The optional second argument tells this function how many stack frames
13576 +to traverse to find the calling function. The default is 1."""
13578 + def __init__ (self):
13579 + super (CallerIs, self).__init__ ("caller_is")
13581 + def invoke (self, name, nframes = 1):
13582 + frame = gdb.selected_frame ()
13583 + while nframes > 0:
13584 + frame = frame.older ()
13585 + nframes = nframes - 1
13586 + return frame.name () == name.string ()
13588 +class CallerMatches (gdb.Function):
13589 + """Return True if the calling function's name matches a string.
13590 +This function takes one or two arguments.
13591 +The first argument is a regular expression; if the calling function's
13592 +name is matched by this argument, this function returns True.
13593 +The optional second argument tells this function how many stack frames
13594 +to traverse to find the calling function. The default is 1."""
13596 + def __init__ (self):
13597 + super (CallerMatches, self).__init__ ("caller_matches")
13599 + def invoke (self, name, nframes = 1):
13600 + frame = gdb.selected_frame ()
13601 + while nframes > 0:
13602 + frame = frame.older ()
13603 + nframes = nframes - 1
13604 + return re.match (name.string (), frame.name ()) is not None
13608 diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
13609 new file mode 100644
13610 index 0000000..debb3bb
13612 +++ b/gdb/python/lib/gdb/function/in_scope.py
13614 +# In-scope function.
13616 +# Copyright (C) 2008 Free Software Foundation, Inc.
13618 +# This program is free software; you can redistribute it and/or modify
13619 +# it under the terms of the GNU General Public License as published by
13620 +# the Free Software Foundation; either version 3 of the License, or
13621 +# (at your option) any later version.
13623 +# This program is distributed in the hope that it will be useful,
13624 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13625 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13626 +# GNU General Public License for more details.
13628 +# You should have received a copy of the GNU General Public License
13629 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13633 +class InScope (gdb.Function):
13634 + """Return True if all the given variables or macros are in scope.
13635 +Takes one argument for each variable name to be checked."""
13637 + def __init__ (self):
13638 + super (InScope, self).__init__ ("in_scope")
13640 + def invoke (self, *vars):
13641 + if len (vars) == 0:
13642 + raise TypeError, "in_scope takes at least one argument"
13644 + # gdb.Value isn't hashable so it can't be put in a map.
13645 + # Convert to string first.
13646 + wanted = set (map (lambda x: x.string (), vars))
13648 + block = gdb.selected_frame ().block ()
13650 + for sym in block:
13651 + if (sym.is_argument or sym.is_constant
13652 + or sym.is_function or sym.is_variable):
13653 + if sym.name in wanted:
13654 + found.add (sym.name)
13656 + block = block.superblock
13658 + return wanted == found
13661 diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
13662 new file mode 100644
13663 index 0000000..8019e9d
13665 +++ b/gdb/python/py-block.c
13667 +/* Python interface to blocks.
13669 + Copyright (C) 2008 Free Software Foundation, Inc.
13671 + This file is part of GDB.
13673 + This program is free software; you can redistribute it and/or modify
13674 + it under the terms of the GNU General Public License as published by
13675 + the Free Software Foundation; either version 3 of the License, or
13676 + (at your option) any later version.
13678 + This program is distributed in the hope that it will be useful,
13679 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13680 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13681 + GNU General Public License for more details.
13683 + You should have received a copy of the GNU General Public License
13684 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13687 +#include "block.h"
13688 +#include "dictionary.h"
13689 +#include "symtab.h"
13690 +#include "python-internal.h"
13694 + struct block *block;
13699 + struct dictionary *dict;
13700 + struct dict_iterator iter;
13701 + int initialized_p;
13702 +} block_syms_iterator_object;
13704 +static PyTypeObject block_syms_iterator_object_type;
13707 +blpy_iter (PyObject *self)
13709 + block_syms_iterator_object *block_iter_obj;
13711 + block_iter_obj = PyObject_New (block_syms_iterator_object,
13712 + &block_syms_iterator_object_type);
13713 + if (block_iter_obj == NULL)
13715 + PyErr_SetString (PyExc_MemoryError,
13716 + "Could not allocate iterator object.");
13720 + block_iter_obj->dict = BLOCK_DICT (((block_object *) self)->block);
13721 + block_iter_obj->initialized_p = 0;
13723 + return (PyObject *) block_iter_obj;
13727 +blpy_get_start (PyObject *self, void *closure)
13729 + block_object *self_block = (block_object *) self;
13731 + return PyLong_FromUnsignedLongLong (BLOCK_START (self_block->block));
13735 +blpy_get_end (PyObject *self, void *closure)
13737 + block_object *self_block = (block_object *) self;
13739 + return PyLong_FromUnsignedLongLong (BLOCK_END (self_block->block));
13743 +blpy_get_function (PyObject *self, void *closure)
13745 + block_object *self_block = (block_object *) self;
13746 + struct symbol *sym;
13748 + sym = BLOCK_FUNCTION (self_block->block);
13750 + return symbol_to_symbol_object (sym);
13756 +blpy_get_superblock (PyObject *self, void *closure)
13758 + block_object *self_block = (block_object *) self;
13759 + struct block *block;
13761 + block = BLOCK_SUPERBLOCK (self_block->block);
13763 + return block_to_block_object (block);
13769 +block_to_block_object (struct block *block)
13771 + block_object *block_obj;
13773 + block_obj = PyObject_New (block_object, &block_object_type);
13774 + if (block_obj == NULL)
13776 + PyErr_SetString (PyExc_MemoryError, "Could not allocate block object.");
13780 + block_obj->block = block;
13782 + return (PyObject *) block_obj;
13786 +block_object_to_block (PyObject *obj)
13788 + if (! PyObject_TypeCheck (obj, &block_object_type))
13790 + return ((block_object *) obj)->block;
13794 +blpy_block_syms_iter (PyObject *self)
13800 +blpy_block_syms_iternext (PyObject *self)
13802 + block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self;
13803 + struct symbol *sym;
13805 + if (!iter_obj->initialized_p)
13807 + sym = dict_iterator_first (iter_obj->dict, &(iter_obj->iter));
13808 + iter_obj->initialized_p = 1;
13811 + sym = dict_iterator_next (&(iter_obj->iter));
13813 + return (sym == NULL)? NULL : symbol_to_symbol_object (sym);
13816 +/* Return the innermost lexical block containing the specified pc value,
13817 + or 0 if there is none. */
13820 +gdbpy_block_for_pc (PyObject *self, PyObject *args)
13822 + unsigned PY_LONG_LONG pc;
13823 + struct block *block;
13824 + PyObject *sym_obj;
13826 + if (!PyArg_ParseTuple (args, "K", &pc))
13829 + block = block_for_pc (pc);
13831 + return block_to_block_object (block);
13837 +gdbpy_initialize_blocks (void)
13839 + block_object_type.tp_new = PyType_GenericNew;
13840 + if (PyType_Ready (&block_object_type) < 0)
13843 + block_syms_iterator_object_type.tp_new = PyType_GenericNew;
13844 + if (PyType_Ready (&block_syms_iterator_object_type) < 0)
13847 + Py_INCREF (&block_object_type);
13848 + PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
13850 + Py_INCREF (&block_syms_iterator_object_type);
13851 + PyModule_AddObject (gdb_module, "BlockIterator",
13852 + (PyObject *) &block_syms_iterator_object_type);
13857 +static PyGetSetDef block_object_getset[] = {
13858 + { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
13859 + { "end", blpy_get_end, NULL, "End address of the block.", NULL },
13860 + { "function", blpy_get_function, NULL,
13861 + "Symbol that names the block, or None.", NULL },
13862 + { "superblock", blpy_get_superblock, NULL,
13863 + "Block containing the block, or None.", NULL },
13864 + { NULL } /* Sentinel */
13867 +PyTypeObject block_object_type = {
13868 + PyObject_HEAD_INIT (NULL)
13870 + "gdb.Block", /*tp_name*/
13871 + sizeof (block_object), /*tp_basicsize*/
13872 + 0, /*tp_itemsize*/
13873 + 0, /*tp_dealloc*/
13875 + 0, /*tp_getattr*/
13876 + 0, /*tp_setattr*/
13877 + 0, /*tp_compare*/
13879 + 0, /*tp_as_number*/
13880 + 0, /*tp_as_sequence*/
13881 + 0, /*tp_as_mapping*/
13885 + 0, /*tp_getattro*/
13886 + 0, /*tp_setattro*/
13887 + 0, /*tp_as_buffer*/
13888 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
13889 + "GDB block object", /* tp_doc */
13890 + 0, /* tp_traverse */
13891 + 0, /* tp_clear */
13892 + 0, /* tp_richcompare */
13893 + 0, /* tp_weaklistoffset */
13894 + blpy_iter, /* tp_iter */
13895 + 0, /* tp_iternext */
13896 + 0, /* tp_methods */
13897 + 0, /* tp_members */
13898 + block_object_getset /* tp_getset */
13901 +static PyTypeObject block_syms_iterator_object_type = {
13902 + PyObject_HEAD_INIT (NULL)
13904 + "gdb.BlockIterator", /*tp_name*/
13905 + sizeof (block_syms_iterator_object), /*tp_basicsize*/
13906 + 0, /*tp_itemsize*/
13907 + 0, /*tp_dealloc*/
13909 + 0, /*tp_getattr*/
13910 + 0, /*tp_setattr*/
13911 + 0, /*tp_compare*/
13913 + 0, /*tp_as_number*/
13914 + 0, /*tp_as_sequence*/
13915 + 0, /*tp_as_mapping*/
13919 + 0, /*tp_getattro*/
13920 + 0, /*tp_setattro*/
13921 + 0, /*tp_as_buffer*/
13922 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
13923 + "GDB block syms iterator object", /* tp_doc */
13924 + 0, /* tp_traverse */
13925 + 0, /* tp_clear */
13926 + 0, /* tp_richcompare */
13927 + 0, /* tp_weaklistoffset */
13928 + blpy_block_syms_iter, /* tp_iter */
13929 + blpy_block_syms_iternext, /* tp_iternext */
13930 + 0 /* tp_methods */
13932 diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
13933 new file mode 100644
13934 index 0000000..afa9526
13936 +++ b/gdb/python/py-breakpoint.c
13938 +/* Python interface to breakpoints
13940 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13942 + This file is part of GDB.
13944 + This program is free software; you can redistribute it and/or modify
13945 + it under the terms of the GNU General Public License as published by
13946 + the Free Software Foundation; either version 3 of the License, or
13947 + (at your option) any later version.
13949 + This program is distributed in the hope that it will be useful,
13950 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13951 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13952 + GNU General Public License for more details.
13954 + You should have received a copy of the GNU General Public License
13955 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13958 +#include "value.h"
13959 +#include "exceptions.h"
13960 +#include "python-internal.h"
13961 +#include "charset.h"
13962 +#include "breakpoint.h"
13963 +#include "gdbcmd.h"
13964 +#include "gdbthread.h"
13965 +#include "observer.h"
13968 +/* From breakpoint.c. */
13969 +extern struct breakpoint *breakpoint_chain;
13972 +typedef struct breakpoint_object breakpoint_object;
13974 +static PyTypeObject breakpoint_object_type;
13976 +/* A dynamically allocated vector of breakpoint objects. Each
13977 + breakpoint has a number. A breakpoint is valid if its slot in this
13978 + vector is non-null. When a breakpoint is deleted, we drop our
13979 + reference to it and zero its slot; this is how we let the Python
13980 + object have a lifetime which is independent from that of the gdb
13982 +static breakpoint_object **bppy_breakpoints;
13984 +/* Number of slots in bppy_breakpoints. */
13985 +static int bppy_slots;
13987 +/* Number of live breakpoints. */
13988 +static int bppy_live;
13990 +/* Variables used to pass information between the Breakpoint
13991 + constructor and the breakpoint-created hook function. */
13992 +static breakpoint_object *bppy_pending_object;
13994 +struct breakpoint_object
13998 + /* The breakpoint number according to gdb. */
14001 + /* The gdb breakpoint object, or NULL if the breakpoint has been
14003 + struct breakpoint *bp;
14006 +/* Evaluate to true if the breakpoint NUM is valid, false otherwise. */
14007 +#define BPPY_VALID_P(Num) \
14009 + && (Num) < bppy_slots \
14010 + && bppy_breakpoints[Num] != NULL)
14012 +/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
14013 + exception if it is invalid. */
14014 +#define BPPY_REQUIRE_VALID(Breakpoint) \
14016 + if (! BPPY_VALID_P ((Breakpoint)->number)) \
14017 + return PyErr_Format (PyExc_RuntimeError, "breakpoint %d is invalid", \
14018 + (Breakpoint)->number); \
14021 +/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
14022 + exception if it is invalid. This macro is for use in setter functions. */
14023 +#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
14025 + if (! BPPY_VALID_P ((Breakpoint)->number)) \
14027 + PyErr_Format (PyExc_RuntimeError, "breakpoint %d is invalid", \
14028 + (Breakpoint)->number); \
14033 +/* Python function which checks the validity of a breakpoint object. */
14035 +bppy_is_valid (PyObject *self, PyObject *args)
14037 + if (((breakpoint_object *) self)->bp)
14042 +/* Python function to test whether or not the breakpoint is enabled. */
14044 +bppy_get_enabled (PyObject *self, void *closure)
14046 + if (! ((breakpoint_object *) self)->bp)
14048 + /* Not clear what we really want here. */
14049 + if (((breakpoint_object *) self)->bp->enable_state == bp_enabled)
14054 +/* Python function to test whether or not the breakpoint is silent. */
14056 +bppy_get_silent (PyObject *self, void *closure)
14058 + BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14059 + if (((breakpoint_object *) self)->bp->silent)
14064 +/* Python function to set the enabled state of a breakpoint. */
14066 +bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
14068 + breakpoint_object *self_bp = (breakpoint_object *) self;
14071 + BPPY_SET_REQUIRE_VALID (self_bp);
14073 + if (newvalue == NULL)
14075 + PyErr_SetString (PyExc_TypeError, "cannot delete `enabled' attribute");
14078 + else if (! PyBool_Check (newvalue))
14080 + PyErr_SetString (PyExc_TypeError,
14081 + "the value of `enabled' must be a boolean");
14085 + cmp = PyObject_IsTrue (newvalue);
14088 + else if (cmp == 1)
14089 + enable_breakpoint (self_bp->bp);
14091 + disable_breakpoint (self_bp->bp);
14095 +/* Python function to set the 'silent' state of a breakpoint. */
14097 +bppy_set_silent (PyObject *self, PyObject *newvalue, void *closure)
14099 + breakpoint_object *self_bp = (breakpoint_object *) self;
14102 + BPPY_SET_REQUIRE_VALID (self_bp);
14104 + if (newvalue == NULL)
14106 + PyErr_SetString (PyExc_TypeError, "cannot delete `silent' attribute");
14109 + else if (! PyBool_Check (newvalue))
14111 + PyErr_SetString (PyExc_TypeError,
14112 + "the value of `silent' must be a boolean");
14116 + cmp = PyObject_IsTrue (newvalue);
14120 + self_bp->bp->silent = cmp;
14125 +/* Python function to set the thread of a breakpoint. */
14127 +bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
14129 + breakpoint_object *self_bp = (breakpoint_object *) self;
14132 + BPPY_SET_REQUIRE_VALID (self_bp);
14134 + if (newvalue == NULL)
14136 + PyErr_SetString (PyExc_TypeError, "cannot delete `thread' attribute");
14139 + else if (PyInt_Check (newvalue))
14141 + id = (int) PyInt_AsLong (newvalue);
14142 + if (! valid_thread_id (id))
14144 + PyErr_SetString (PyExc_RuntimeError, "invalid thread id");
14148 + else if (newvalue == Py_None)
14152 + PyErr_SetString (PyExc_TypeError,
14153 + "the value of `thread' must be an integer or None");
14157 + self_bp->bp->thread = id;
14162 +/* Python function to set the ignore count of a breakpoint. */
14164 +bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
14166 + breakpoint_object *self_bp = (breakpoint_object *) self;
14169 + BPPY_SET_REQUIRE_VALID (self_bp);
14171 + if (newvalue == NULL)
14173 + PyErr_SetString (PyExc_TypeError,
14174 + "cannot delete `ignore_count' attribute");
14177 + else if (! PyInt_Check (newvalue))
14179 + PyErr_SetString (PyExc_TypeError,
14180 + "the value of `ignore_count' must be an integer");
14184 + value = PyInt_AsLong (newvalue);
14187 + set_ignore_count (self_bp->number, (int) value, 0);
14192 +/* Python function to set the hit count of a breakpoint. */
14194 +bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
14196 + breakpoint_object *self_bp = (breakpoint_object *) self;
14198 + BPPY_SET_REQUIRE_VALID (self_bp);
14200 + if (newvalue == NULL)
14202 + PyErr_SetString (PyExc_TypeError, "cannot delete `hit_count' attribute");
14205 + else if (! PyInt_Check (newvalue) || PyInt_AsLong (newvalue) != 0)
14207 + PyErr_SetString (PyExc_AttributeError,
14208 + "the value of `hit_count' must be zero");
14212 + self_bp->bp->hit_count = 0;
14217 +/* Python function to get the location of a breakpoint. */
14219 +bppy_get_location (PyObject *self, void *closure)
14223 + BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14224 + str = ((breakpoint_object *) self)->bp->addr_string;
14225 + /* FIXME: watchpoints? tracepoints? */
14228 + return PyString_Decode (str, strlen (str), host_charset (), NULL);
14231 +/* Python function to get the condition expression of a breakpoint. */
14233 +bppy_get_condition (PyObject *self, void *closure)
14236 + BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14238 + str = ((breakpoint_object *) self)->bp->cond_string;
14241 + return PyString_Decode (str, strlen (str), host_charset (), NULL);
14245 +bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
14248 + breakpoint_object *self_bp = (breakpoint_object *) self;
14249 + volatile struct gdb_exception except;
14251 + BPPY_SET_REQUIRE_VALID (self_bp);
14253 + if (newvalue == NULL)
14255 + PyErr_SetString (PyExc_TypeError, "cannot delete `condition' attribute");
14258 + else if (newvalue == Py_None)
14262 + exp = python_string_to_host_string (newvalue);
14267 + TRY_CATCH (except, RETURN_MASK_ALL)
14269 + set_breakpoint_condition (self_bp->bp, exp, 0);
14271 + GDB_PY_SET_HANDLE_EXCEPTION (except);
14276 +/* Python function to get the commands attached to a breakpoint. */
14278 +bppy_get_commands (PyObject *self, void *closure)
14280 + breakpoint_object *self_bp = (breakpoint_object *) self;
14282 + volatile struct gdb_exception except;
14283 + struct ui_file *string_file;
14284 + struct cleanup *chain;
14285 + PyObject *result;
14288 + BPPY_REQUIRE_VALID (self_bp);
14290 + if (! self_bp->bp->commands)
14293 + string_file = mem_fileopen ();
14294 + chain = make_cleanup_ui_file_delete (string_file);
14296 + TRY_CATCH (except, RETURN_MASK_ALL)
14298 + /* FIXME: this can fail. Maybe we need to be making a new
14299 + ui_out object here? */
14300 + ui_out_redirect (uiout, string_file);
14301 + print_command_lines (uiout, self_bp->bp->commands, 0);
14302 + ui_out_redirect (uiout, NULL);
14304 + cmdstr = ui_file_xstrdup (string_file, &length);
14305 + GDB_PY_HANDLE_EXCEPTION (except);
14307 + result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
14308 + do_cleanups (chain);
14313 +/* Python function to get the breakpoint's number. */
14315 +bppy_get_number (PyObject *self, void *closure)
14317 + breakpoint_object *self_bp = (breakpoint_object *) self;
14319 + BPPY_REQUIRE_VALID (self_bp);
14321 + return PyInt_FromLong (self_bp->number);
14324 +/* Python function to get the breakpoint's thread ID. */
14326 +bppy_get_thread (PyObject *self, void *closure)
14328 + breakpoint_object *self_bp = (breakpoint_object *) self;
14330 + BPPY_REQUIRE_VALID (self_bp);
14332 + if (self_bp->bp->thread == -1)
14335 + return PyInt_FromLong (self_bp->bp->thread);
14338 +/* Python function to get the breakpoint's hit count. */
14340 +bppy_get_hit_count (PyObject *self, void *closure)
14342 + breakpoint_object *self_bp = (breakpoint_object *) self;
14344 + BPPY_REQUIRE_VALID (self_bp);
14346 + return PyInt_FromLong (self_bp->bp->hit_count);
14349 +/* Python function to get the breakpoint's ignore count. */
14351 +bppy_get_ignore_count (PyObject *self, void *closure)
14353 + breakpoint_object *self_bp = (breakpoint_object *) self;
14355 + BPPY_REQUIRE_VALID (self_bp);
14357 + return PyInt_FromLong (self_bp->bp->ignore_count);
14360 +/* Python function to create a new breakpoint. */
14362 +bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
14364 + PyObject *result;
14366 + volatile struct gdb_exception except;
14368 + /* FIXME: allow condition, thread, temporary, ... ? */
14369 + if (! PyArg_ParseTuple (args, "s", &spec))
14371 + result = subtype->tp_alloc (subtype, 0);
14374 + bppy_pending_object = (breakpoint_object *) result;
14375 + bppy_pending_object->number = -1;
14376 + bppy_pending_object->bp = NULL;
14378 + TRY_CATCH (except, RETURN_MASK_ALL)
14380 + set_breakpoint (python_gdbarch, spec, NULL, 0, 0, -1, 0,
14381 + AUTO_BOOLEAN_TRUE, 1);
14383 + if (except.reason < 0)
14385 + subtype->tp_free (result);
14386 + return PyErr_Format (except.reason == RETURN_QUIT
14387 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
14388 + "%s", except.message);
14391 + BPPY_REQUIRE_VALID ((breakpoint_object *) result);
14397 +/* Static function to return a tuple holding all breakpoints. */
14400 +gdbpy_breakpoints (PyObject *self, PyObject *args)
14402 + PyObject *result;
14404 + if (bppy_live == 0)
14407 + result = PyTuple_New (bppy_live);
14411 + for (i = 0; out < bppy_live; ++i)
14413 + if (! bppy_breakpoints[i])
14415 + Py_INCREF (bppy_breakpoints[i]);
14416 + PyTuple_SetItem (result, out, (PyObject *) bppy_breakpoints[i]);
14425 +/* Event callback functions. */
14427 +/* Callback that is used when a breakpoint is created. This function
14428 + will create a new Python breakpoint object. */
14430 +gdbpy_breakpoint_created (int num)
14432 + breakpoint_object *newbp;
14433 + struct breakpoint *bp;
14434 + PyGILState_STATE state;
14439 + for (bp = breakpoint_chain; bp; bp = bp->next)
14440 + if (bp->number == num)
14445 + if (num >= bppy_slots)
14447 + int old = bppy_slots;
14448 + bppy_slots = bppy_slots * 2 + 10;
14450 + = (breakpoint_object **) xrealloc (bppy_breakpoints,
14452 + * sizeof (breakpoint_object *)));
14453 + memset (&bppy_breakpoints[old], 0,
14454 + (bppy_slots - old) * sizeof (PyObject *));
14459 + state = PyGILState_Ensure ();
14461 + if (bppy_pending_object)
14463 + newbp = bppy_pending_object;
14464 + bppy_pending_object = NULL;
14467 + newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
14470 + PyObject *hookfn;
14472 + newbp->number = num;
14474 + bppy_breakpoints[num] = newbp;
14476 + hookfn = gdbpy_get_hook_function ("new_breakpoint");
14479 + PyObject *result;
14480 + result = PyObject_CallFunctionObjArgs (hookfn, newbp, NULL);
14483 + Py_DECREF (result);
14485 + Py_DECREF (hookfn);
14489 + /* Just ignore errors here. */
14492 + PyGILState_Release (state);
14495 +/* Callback that is used when a breakpoint is deleted. This will
14496 + invalidate the corresponding Python object. */
14498 +gdbpy_breakpoint_deleted (int num)
14500 + PyGILState_STATE state;
14502 + state = PyGILState_Ensure ();
14503 + if (BPPY_VALID_P (num))
14505 + bppy_breakpoints[num]->bp = NULL;
14506 + Py_DECREF (bppy_breakpoints[num]);
14507 + bppy_breakpoints[num] = NULL;
14510 + PyGILState_Release (state);
14515 +/* Initialize the Python breakpoint code. */
14517 +gdbpy_initialize_breakpoints (void)
14519 + breakpoint_object_type.tp_new = bppy_new;
14520 + if (PyType_Ready (&breakpoint_object_type) < 0)
14523 + Py_INCREF (&breakpoint_object_type);
14524 + PyModule_AddObject (gdb_module, "Breakpoint",
14525 + (PyObject *) &breakpoint_object_type);
14527 + observer_attach_breakpoint_created (gdbpy_breakpoint_created);
14528 + observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
14533 +static PyGetSetDef breakpoint_object_getset[] = {
14534 + { "enabled", bppy_get_enabled, bppy_set_enabled,
14535 + "Boolean telling whether the breakpoint is enabled.", NULL },
14536 + { "silent", bppy_get_silent, bppy_set_silent,
14537 + "Boolean telling whether the breakpoint is silent.", NULL },
14538 + { "thread", bppy_get_thread, bppy_set_thread,
14539 + "Thread ID for the breakpoint.\n\
14540 +If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
14541 +If the value is None, then this breakpoint not thread-specific.\n\
14542 +No other type of value can be used.", NULL },
14543 + { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
14544 + "Number of times this breakpoint should be automatically continued.",
14546 + { "number", bppy_get_number, NULL,
14547 + "Breakpoint's number assigned by GDB.", NULL },
14548 + { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
14549 + "Number of times the breakpoint has been hit.\n\
14550 +Can be set to zero to clear the count. No other value is valid\n\
14551 +when setting this property.", NULL },
14552 + { "location", bppy_get_location, NULL,
14553 + "Location of the breakpoint, as specified by the user.", NULL},
14554 + { "condition", bppy_get_condition, bppy_set_condition,
14555 + "Condition of the breakpoint, as specified by the user,\
14556 +or None if no condition set."},
14557 + { "commands", bppy_get_commands, NULL,
14558 + "Commands of the breakpoint, as specified by the user."},
14559 + { NULL } /* Sentinel. */
14562 +static PyMethodDef breakpoint_object_methods[] =
14564 + { "is_valid", bppy_is_valid, METH_NOARGS,
14565 + "Return true if this breakpoint is valid, false if not." },
14566 + { NULL } /* Sentinel. */
14569 +static PyTypeObject breakpoint_object_type =
14571 + PyObject_HEAD_INIT (NULL)
14573 + "gdb.Breakpoint", /*tp_name*/
14574 + sizeof (breakpoint_object), /*tp_basicsize*/
14575 + 0, /*tp_itemsize*/
14576 + 0, /*tp_dealloc*/
14578 + 0, /*tp_getattr*/
14579 + 0, /*tp_setattr*/
14580 + 0, /*tp_compare*/
14582 + 0, /*tp_as_number*/
14583 + 0, /*tp_as_sequence*/
14584 + 0, /*tp_as_mapping*/
14588 + 0, /*tp_getattro*/
14589 + 0, /*tp_setattro*/
14590 + 0, /*tp_as_buffer*/
14591 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
14592 + "GDB breakpoint object", /* tp_doc */
14593 + 0, /* tp_traverse */
14594 + 0, /* tp_clear */
14595 + 0, /* tp_richcompare */
14596 + 0, /* tp_weaklistoffset */
14598 + 0, /* tp_iternext */
14599 + breakpoint_object_methods, /* tp_methods */
14600 + 0, /* tp_members */
14601 + breakpoint_object_getset /* tp_getset */
14603 diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
14604 index 528aca6..04b3fd1 100644
14605 --- a/gdb/python/py-cmd.c
14606 +++ b/gdb/python/py-cmd.c
14607 @@ -49,8 +49,7 @@ static struct cmdpy_completer completers[] =
14609 #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
14611 -/* A gdb command. For the time being only ordinary commands (not
14612 - set/show commands) are allowed. */
14613 +/* A gdb command. */
14614 struct cmdpy_object
14617 @@ -70,7 +69,6 @@ typedef struct cmdpy_object cmdpy_object;
14619 static PyTypeObject cmdpy_object_type;
14622 /* Constants used by this module. */
14623 static PyObject *invoke_cst;
14624 static PyObject *complete_cst;
14625 @@ -263,10 +261,13 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
14626 *BASE_LIST is set to the final prefix command's list of
14629 + START_LIST is the list in which the search starts.
14631 This function returns the xmalloc()d name of the new command. On
14632 error sets the Python error and returns NULL. */
14634 -parse_command_name (char *text, struct cmd_list_element ***base_list)
14636 +gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
14637 + struct cmd_list_element **start_list)
14639 struct cmd_list_element *elt;
14640 int len = strlen (text);
14641 @@ -299,7 +300,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
14645 - *base_list = &cmdlist;
14646 + *base_list = start_list;
14650 @@ -308,7 +309,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
14651 prefix_text[i + 1] = '\0';
14653 text = prefix_text;
14654 - elt = lookup_cmd_1 (&text, cmdlist, NULL, 1);
14655 + elt = lookup_cmd_1 (&text, *start_list, NULL, 1);
14656 if (!elt || elt == (struct cmd_list_element *) -1)
14658 PyErr_Format (PyExc_RuntimeError, _("could not find command prefix %s"),
14659 @@ -399,7 +400,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
14663 - cmd_name = parse_command_name (name, &cmd_list);
14664 + cmd_name = gdbpy_parse_command_name (name, &cmd_list, &cmdlist);
14668 diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
14669 index 279415c..5d8ce0a 100644
14670 --- a/gdb/python/py-frame.c
14671 +++ b/gdb/python/py-frame.c
14672 @@ -202,10 +202,59 @@ frapy_pc (PyObject *self, PyObject *args)
14673 return PyLong_FromUnsignedLongLong (pc);
14676 +/* Implementation of gdb.Frame.block (self) -> gdb.Block.
14677 + Returns the frame's code block. */
14680 +frapy_block (PyObject *self, PyObject *args)
14682 + struct frame_info *frame;
14683 + struct block *block = NULL;
14684 + volatile struct gdb_exception except;
14686 + TRY_CATCH (except, RETURN_MASK_ALL)
14688 + FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14690 + block = block_for_pc (get_frame_address_in_block (frame));
14692 + GDB_PY_HANDLE_EXCEPTION (except);
14695 + return block_to_block_object (block);
14701 +/* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
14702 + Returns the symbol for the function corresponding to this frame. */
14705 +frapy_function (PyObject *self, PyObject *args)
14707 + struct symbol *sym = NULL;
14708 + struct frame_info *frame;
14709 + volatile struct gdb_exception except;
14711 + TRY_CATCH (except, RETURN_MASK_ALL)
14713 + FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14715 + sym = find_pc_function (get_frame_address_in_block (frame));
14717 + GDB_PY_HANDLE_EXCEPTION (except);
14720 + return symbol_to_symbol_object (sym);
14725 /* Convert a frame_info struct to a Python Frame object.
14726 Sets a Python exception and returns NULL on error. */
14728 -static frame_object *
14730 frame_info_to_frame_object (struct frame_info *frame)
14732 frame_object *frame_obj;
14733 @@ -235,7 +284,7 @@ frame_info_to_frame_object (struct frame_info *frame)
14735 frame_obj->gdbarch = get_frame_arch (frame);
14737 - return frame_obj;
14738 + return (PyObject *) frame_obj;
14741 /* Implementation of gdb.Frame.older (self) -> gdb.Frame.
14742 @@ -296,7 +345,30 @@ frapy_newer (PyObject *self, PyObject *args)
14746 -/* Implementation of gdb.Frame.read_var_value (self, variable) -> gdb.Value.
14747 +/* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line.
14748 + Returns the frame's symtab and line. */
14751 +frapy_find_sal (PyObject *self, PyObject *args)
14753 + struct frame_info *frame;
14754 + struct symtab_and_line sal;
14755 + volatile struct gdb_exception except;
14756 + PyObject *sal_obj = NULL; /* Initialize to appease gcc warning. */
14758 + TRY_CATCH (except, RETURN_MASK_ALL)
14760 + FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14762 + find_frame_sal (frame, &sal);
14763 + sal_obj = symtab_and_line_to_sal_object (sal);
14765 + GDB_PY_HANDLE_EXCEPTION (except);
14770 +/* Implementation of gdb.Frame.read_var (self, variable) -> gdb.Value.
14771 Returns the value of the given variable in this frame. The argument must be
14772 a string. Returns None if GDB can't find the specified variable. */
14774 @@ -312,7 +384,9 @@ frapy_read_var (PyObject *self, PyObject *args)
14775 if (!PyArg_ParseTuple (args, "O", &sym_obj))
14778 - if (gdbpy_is_string (sym_obj))
14779 + if (PyObject_TypeCheck (sym_obj, &symbol_object_type))
14780 + var = symbol_object_to_symbol (sym_obj);
14781 + else if (gdbpy_is_string (sym_obj))
14784 struct block *block = NULL;
14785 @@ -365,6 +439,25 @@ frapy_read_var (PyObject *self, PyObject *args)
14789 +/* Select this frame. */
14792 +frapy_select (PyObject *self, PyObject *args)
14794 + struct frame_info *fi;
14795 + frame_object *frame = (frame_object *) self;
14796 + volatile struct gdb_exception except;
14798 + TRY_CATCH (except, RETURN_MASK_ALL)
14800 + FRAPY_REQUIRE_VALID (frame, fi);
14801 + select_frame (fi);
14803 + GDB_PY_HANDLE_EXCEPTION (except);
14808 /* Implementation of gdb.selected_frame () -> gdb.Frame.
14809 Returns the selected frame object. */
14811 @@ -372,7 +465,7 @@ PyObject *
14812 gdbpy_selected_frame (PyObject *self, PyObject *args)
14814 struct frame_info *frame;
14815 - frame_object *frame_obj = NULL; /* Initialize to appease gcc warning. */
14816 + PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */
14817 volatile struct gdb_exception except;
14819 TRY_CATCH (except, RETURN_MASK_ALL)
14820 @@ -382,7 +475,7 @@ gdbpy_selected_frame (PyObject *self, PyObject *args)
14822 GDB_PY_HANDLE_EXCEPTION (except);
14824 - return (PyObject *) frame_obj;
14825 + return frame_obj;
14828 /* Implementation of gdb.stop_reason_string (Integer) -> String.
14829 @@ -484,15 +577,26 @@ Return the reason why it's not possible to find frames older than this." },
14830 { "pc", frapy_pc, METH_NOARGS,
14832 Return the frame's resume address." },
14833 + { "block", frapy_block, METH_NOARGS,
14834 + "block () -> gdb.Block.\n\
14835 +Return the frame's code block." },
14836 + { "function", frapy_function, METH_NOARGS,
14837 + "function () -> gdb.Symbol.\n\
14838 +Returns the symbol for the function corresponding to this frame." },
14839 { "older", frapy_older, METH_NOARGS,
14840 "older () -> gdb.Frame.\n\
14841 Return the frame that called this frame." },
14842 { "newer", frapy_newer, METH_NOARGS,
14843 "newer () -> gdb.Frame.\n\
14844 Return the frame called by this frame." },
14845 + { "find_sal", frapy_find_sal, METH_NOARGS,
14846 + "find_sal () -> gdb.Symtab_and_line.\n\
14847 +Return the frame's symtab and line." },
14848 { "read_var", frapy_read_var, METH_VARARGS,
14849 "read_var (variable) -> gdb.Value.\n\
14850 Return the value of the variable in this frame." },
14851 + { "select", frapy_select, METH_NOARGS,
14852 + "Select this frame as the user's current frame." },
14853 {NULL} /* Sentinel */
14856 diff --git a/gdb/python/py-hooks.c b/gdb/python/py-hooks.c
14857 new file mode 100644
14858 index 0000000..a3140bc
14860 +++ b/gdb/python/py-hooks.c
14862 +/* Notifications from gdb to Python
14864 + Copyright (C) 2008 Free Software Foundation, Inc.
14866 + This file is part of GDB.
14868 + This program is free software; you can redistribute it and/or modify
14869 + it under the terms of the GNU General Public License as published by
14870 + the Free Software Foundation; either version 3 of the License, or
14871 + (at your option) any later version.
14873 + This program is distributed in the hope that it will be useful,
14874 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14875 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14876 + GNU General Public License for more details.
14878 + You should have received a copy of the GNU General Public License
14879 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
14882 +#include "cli/cli-decode.h"
14883 +#include "charset.h"
14884 +#include "python.h"
14885 +#include "python-internal.h"
14886 +#include "observer.h"
14889 +gdbpy_get_hook_function (const char *name)
14892 + PyObject *result;
14894 + if (! PyObject_HasAttrString (gdb_module, "hooks"))
14896 + hooks = PyObject_GetAttrString (gdb_module, "hooks");
14899 + /* The cast is because the Python function doesn't declare const argument.
14900 + This is a problem in Python version 2.4, but not in 2.5. */
14901 + if (! PyObject_HasAttrString (hooks, (char *) name))
14903 + Py_DECREF (hooks);
14906 + /* The cast is because the Python function doesn't declare const argument.
14907 + This is a problem in Python version 2.4, but not in 2.5. */
14908 + result = PyObject_GetAttrString (hooks, (char *) name);
14909 + Py_DECREF (hooks);
14912 diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
14913 new file mode 100644
14914 index 0000000..5e90cc2
14916 +++ b/gdb/python/py-inferior.c
14918 +/* Python interface to inferiors.
14920 + Copyright (C) 2009 Free Software Foundation, Inc.
14922 + This file is part of GDB.
14924 + This program is free software; you can redistribute it and/or modify
14925 + it under the terms of the GNU General Public License as published by
14926 + the Free Software Foundation; either version 3 of the License, or
14927 + (at your option) any later version.
14929 + This program is distributed in the hope that it will be useful,
14930 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14931 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14932 + GNU General Public License for more details.
14934 + You should have received a copy of the GNU General Public License
14935 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
14938 +#include "exceptions.h"
14939 +#include "gdbcore.h"
14940 +#include "gdbthread.h"
14941 +#include "inferior.h"
14942 +#include "observer.h"
14943 +#include "python-internal.h"
14944 +#include "arch-utils.h"
14945 +#include "language.h"
14947 +struct threadlist_entry {
14948 + thread_object *thread_obj;
14949 + struct threadlist_entry *next;
14956 + /* The inferior we represent. */
14957 + struct inferior *inferior;
14959 + /* thread_object instances under this inferior. This list owns a reference
14960 + to each object it contains. */
14961 + struct threadlist_entry *threads;
14963 + /* Number of threads in the list. */
14965 +} inferior_object;
14967 +static PyTypeObject inferior_object_type;
14973 + /* These are kept just for mbpy_str. */
14975 + CORE_ADDR length;
14978 +static PyTypeObject membuf_object_type;
14980 +/* Require that INFERIOR be a valid inferior ID. */
14981 +#define INFPY_REQUIRE_VALID(Inferior) \
14983 + if (!Inferior->inferior) \
14985 + PyErr_SetString (PyExc_RuntimeError, \
14986 + "inferior no longer exists"); \
14991 +struct inflist_entry {
14992 + inferior_object *inf_obj;
14993 + struct inflist_entry *next;
14998 +/* Inferior objects list. */
15000 +/* List containing inferior_objects. This list owns a reference to each
15001 + object it contains. */
15002 +static struct inflist_entry *inferior_list;
15004 +static int ninferiors;
15007 +/* An observer callback function that is called when an inferior has
15008 + been created. Creates a corresponding Python object for the inferior
15009 + and adds it to the list. */
15011 +add_inferior_object (int pid)
15013 + struct inferior *inf = find_inferior_pid (pid);
15014 + inferior_object *inf_obj;
15015 + struct inflist_entry *entry;
15016 + struct cleanup *cleanup;
15020 + warning (_("Can't create Python Inferior object."));
15024 + cleanup = ensure_python_env (get_current_arch (), current_language);
15026 + inf_obj = PyObject_New (inferior_object, &inferior_object_type);
15029 + warning (_("Can't create Python Inferior object."));
15030 + gdbpy_print_stack ();
15031 + do_cleanups (cleanup);
15035 + inf_obj->inferior = inf;
15036 + inf_obj->threads = NULL;
15037 + inf_obj->nthreads = 0;
15039 + entry = xmalloc (sizeof (struct inflist_entry));
15040 + entry->inf_obj = inf_obj;
15041 + entry->next = inferior_list;
15043 + inferior_list = entry;
15047 + do_cleanups (cleanup);
15050 +/* An observer callback function that is called when an inferior has
15051 + been deleted. Removes the corresponding Python object from the
15052 + inferior list, and removes the list's reference to the object. */
15054 +delete_inferior_object (int pid)
15056 + PyGILState_STATE state;
15057 + struct inflist_entry **inf_entry, *inf_tmp;
15058 + struct threadlist_entry *th_entry, *th_tmp;
15060 + /* Find inferior_object for the given PID. */
15061 + for (inf_entry = &inferior_list; *inf_entry != NULL;
15062 + inf_entry = &(*inf_entry)->next)
15063 + if ((*inf_entry)->inf_obj->inferior->pid == pid)
15069 + state = PyGILState_Ensure ();
15071 + inf_tmp = *inf_entry;
15072 + inf_tmp->inf_obj->inferior = NULL;
15074 + /* Deallocate threads list. */
15075 + for (th_entry = inf_tmp->inf_obj->threads; th_entry != NULL;)
15077 + Py_DECREF (th_entry->thread_obj);
15079 + th_tmp = th_entry;
15080 + th_entry = th_entry->next;
15084 + inf_tmp->inf_obj->nthreads = 0;
15086 + *inf_entry = (*inf_entry)->next;
15087 + Py_DECREF (inf_tmp->inf_obj);
15092 + PyGILState_Release (state);
15095 +/* Finds the Python Inferior object for the given pid. Returns a borrowed
15098 +find_inferior_object (int pid)
15100 + struct inflist_entry *p;
15102 + for (p = inferior_list; p != NULL; p = p->next)
15103 + if (p->inf_obj->inferior->pid == pid)
15104 + return (PyObject *) p->inf_obj;
15109 +/* Finds the Python InferiorThread object for the given ptid. Returns a
15110 + borrowed reference. */
15112 +find_thread_object (ptid_t ptid)
15115 + struct inflist_entry *p;
15116 + struct threadlist_entry *q;
15118 + pid = PIDGET (ptid);
15119 + for (p = inferior_list; p != NULL; p = p->next)
15120 + if (p->inf_obj->inferior->pid == pid)
15121 + for (q = p->inf_obj->threads; q != NULL; q = q->next)
15122 + if (ptid_equal (q->thread_obj->thread->ptid, ptid))
15123 + return q->thread_obj;
15130 +/* Inferior object. */
15133 +add_thread_object (struct thread_info *tp)
15135 + PyGILState_STATE state;
15136 + thread_object *thread_obj;
15137 + inferior_object *inf_obj;
15138 + struct threadlist_entry *entry;
15140 + state = PyGILState_Ensure ();
15142 + thread_obj = create_thread_object (tp);
15145 + warning (_("Can't create Python InferiorThread object."));
15146 + gdbpy_print_stack ();
15147 + PyGILState_Release (state);
15151 + inf_obj = (inferior_object *) thread_obj->inf_obj;
15153 + entry = xmalloc (sizeof (struct threadlist_entry));
15154 + entry->thread_obj = thread_obj;
15155 + entry->next = inf_obj->threads;
15157 + inf_obj->threads = entry;
15158 + inf_obj->nthreads++;
15160 + PyGILState_Release (state);
15164 +delete_thread_object (struct thread_info *tp, int ignore)
15166 + PyGILState_STATE state;
15167 + inferior_object *inf_obj;
15168 + thread_object *thread_obj;
15169 + struct threadlist_entry **entry, *tmp;
15171 + inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
15175 + /* Find thread entry in its inferior's thread_list. */
15176 + for (entry = &inf_obj->threads; *entry != NULL; entry = &(*entry)->next)
15177 + if ((*entry)->thread_obj->thread == tp)
15183 + state = PyGILState_Ensure ();
15186 + tmp->thread_obj->thread = NULL;
15188 + *entry = (*entry)->next;
15189 + inf_obj->nthreads--;
15191 + Py_DECREF (tmp->thread_obj);
15195 + PyGILState_Release (state);
15199 +infpy_threads (PyObject *self, PyObject *args)
15202 + struct threadlist_entry *entry;
15203 + inferior_object *inf_obj = (inferior_object *) self;
15206 + INFPY_REQUIRE_VALID (inf_obj);
15209 + tuple = PyTuple_New (inf_obj->nthreads);
15213 + /* The list is in reverse order of thread age (i.e., newest comes first),
15214 + is this a problem? */
15215 + for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
15216 + i++, entry = entry->next)
15218 + Py_INCREF (entry->thread_obj);
15219 + PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj);
15226 +infpy_get_num (PyObject *self, void *closure)
15228 + inferior_object *inf = (inferior_object *) self;
15230 + INFPY_REQUIRE_VALID (inf);
15232 + return PyLong_FromLong (inf->inferior->num);
15236 +infpy_get_pid (PyObject *self, void *closure)
15238 + inferior_object *inf = (inferior_object *) self;
15240 + INFPY_REQUIRE_VALID (inf);
15242 + return PyLong_FromLong (inf->inferior->pid);
15246 +infpy_get_was_attached (PyObject *self, void *closure)
15248 + inferior_object *inf = (inferior_object *) self;
15249 + INFPY_REQUIRE_VALID (inf);
15250 + if (inf->inferior->attach_flag)
15257 +/* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
15258 + Returns a list of all inferiors. */
15261 +gdbpy_inferiors (PyObject *unused, PyObject *unused2)
15264 + struct inflist_entry *entry;
15267 + tuple = PyTuple_New (ninferiors);
15271 + /* The list is in reverse order of inferior age (i.e., newest comes first),
15272 + is this a problem? */
15273 + for (i = 0, entry = inferior_list; i < ninferiors; i++, entry = entry->next)
15275 + Py_INCREF (entry->inf_obj);
15276 + PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->inf_obj);
15284 +/* Membuf and memory manipulation. */
15286 +/* Implementation of gdb.read_memory (address, length).
15287 + Returns a Python buffer object with LENGTH bytes of the inferior's memory
15288 + at ADDRESS. Both arguments are integers. */
15291 +infpy_read_memory (PyObject *self, PyObject *args)
15294 + CORE_ADDR addr, length;
15295 + void *buffer = NULL;
15296 + membuf_object *membuf_obj;
15297 + PyObject *addr_obj, *length_obj;
15298 + struct cleanup *cleanups;
15299 + volatile struct gdb_exception except;
15301 + if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
15304 + cleanups = make_cleanup (null_cleanup, NULL);
15306 + TRY_CATCH (except, RETURN_MASK_ALL)
15308 + if (!get_addr_from_python (addr_obj, &addr)
15309 + || !get_addr_from_python (length_obj, &length))
15315 + buffer = xmalloc (length);
15316 + make_cleanup (xfree, buffer);
15318 + read_memory (addr, buffer, length);
15320 + GDB_PY_HANDLE_EXCEPTION (except);
15324 + do_cleanups (cleanups);
15328 + membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
15329 + if (membuf_obj == NULL)
15331 + PyErr_SetString (PyExc_MemoryError,
15332 + "Could not allocate memory buffer object.");
15333 + do_cleanups (cleanups);
15337 + discard_cleanups (cleanups);
15339 + membuf_obj->buffer = buffer;
15340 + membuf_obj->addr = addr;
15341 + membuf_obj->length = length;
15343 + return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
15344 + Py_END_OF_BUFFER);
15347 +/* Implementation of gdb.write_memory (address, buffer [, length]).
15348 + Writes the contents of BUFFER (a Python object supporting the read buffer
15349 + protocol) at ADDRESS in the inferior's memory. Write LENGTH bytes from
15350 + BUFFER, or its entire contents if the argument is not provided. The
15351 + function returns nothing. */
15354 +infpy_write_memory (PyObject *self, PyObject *args)
15356 + int buf_len, error = 0;
15357 + const char *buffer;
15358 + CORE_ADDR addr, length;
15359 + PyObject *addr_obj, *length_obj = NULL;
15360 + volatile struct gdb_exception except;
15362 + if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
15366 + TRY_CATCH (except, RETURN_MASK_ALL)
15368 + if (!get_addr_from_python (addr_obj, &addr))
15375 + length = buf_len;
15376 + else if (!get_addr_from_python (length_obj, &length))
15382 + write_memory (addr, buffer, length);
15384 + GDB_PY_HANDLE_EXCEPTION (except);
15392 +/* Destructor of Membuf objects. */
15395 +mbpy_dealloc (PyObject *self)
15397 + xfree (((membuf_object *) self)->buffer);
15398 + self->ob_type->tp_free (self);
15401 +/* Return a description of the Membuf object. */
15404 +mbpy_str (PyObject *self)
15406 + membuf_object *membuf_obj = (membuf_object *) self;
15408 + return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
15409 + paddress (python_gdbarch, membuf_obj->addr),
15410 + pulongest (membuf_obj->length));
15414 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
15416 + membuf_object *membuf_obj = (membuf_object *) self;
15420 + PyErr_SetString (PyExc_SystemError,
15421 + "The memory buffer supports only one segment.");
15425 + *ptrptr = membuf_obj->buffer;
15427 + return membuf_obj->length;
15431 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
15433 + return get_read_buffer (self, segment, ptrptr);
15437 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
15440 + *lenp = ((membuf_object *) self)->length;
15446 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
15448 + void *ptr = NULL;
15451 + ret = get_read_buffer (self, segment, &ptr);
15452 + *ptrptr = (char *) ptr;
15457 +/* Adds GDB value V to the pattern buffer in *PATTERN_BUF. If SIZE is not zero,
15458 + it specifies the number of bytes from V to copy to *PATTERN_BUF. The
15459 + function increases the size of *PATTERN_BUF as necessary, adjusting
15460 + *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process. */
15463 +add_value_pattern (struct value *v, int size, char **pattern_buf,
15464 + char **pattern_buf_end, ULONGEST *pattern_buf_size)
15470 + LONGEST x = value_as_long (v);
15473 + *(*pattern_buf_end)++ = x;
15476 + put_bits (x, *pattern_buf_end, size * 8,
15477 + gdbarch_byte_order (python_gdbarch) == BFD_ENDIAN_BIG);
15478 + *pattern_buf_end += size;
15483 + val_bytes = TYPE_LENGTH (value_type (v));
15485 + increase_pattern_buffer (pattern_buf, pattern_buf_end,
15486 + pattern_buf_size, val_bytes);
15488 + memcpy (*pattern_buf_end, value_contents_raw (v), val_bytes);
15489 + *pattern_buf_end += val_bytes;
15493 +/* This function does the actual work of constructing the pattern buffer from
15494 + OBJ. If OBJ is an object which implements the read buffer protocol (such
15495 + as a string, a byte array or gdb.Membuf), then its contents are directly
15496 + copied to *PATTERN_BUF. If it is a list, then this function is recursively
15497 + called for each of its elements. If OBJ is an object which can be converted
15498 + to a GDB value, then the contents of the value are copied to PATTERN_BUF.
15499 + If SIZE is different than zero, then it limits the number of bytes which
15500 + are copied to the buffer in case OBJ is converted to a GDB value. That
15501 + means that SIZE influences only Python scalars and gdb.Value objects.
15502 + The function increases the size of *PATTERN_BUF as necessary, adjusting
15503 + *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process.
15505 + Returns 1 on success or 0 on failure, with a Python exception set. This
15506 + function can also throw GDB exceptions. */
15509 +add_pattern_element (PyObject *obj, int size, char **pattern_buf,
15510 + char **pattern_buf_end, ULONGEST *pattern_buf_size)
15512 + if (PyObject_CheckReadBuffer (obj))
15514 + /* Handle string, Unicode string, byte array, gdb.Membuf and any other
15515 + object implementing the buffer protocol. The SIZE parameter is
15516 + ignored in this case. */
15518 + Py_ssize_t val_bytes;
15519 + const void *buffer;
15521 + if (PyObject_AsReadBuffer (obj, &buffer, &val_bytes) == -1)
15524 + increase_pattern_buffer (pattern_buf, pattern_buf_end,
15525 + pattern_buf_size, val_bytes);
15527 + memcpy (*pattern_buf_end, buffer, val_bytes);
15528 + *pattern_buf_end += val_bytes;
15530 + else if (gdbpy_is_value_object (obj))
15531 + add_value_pattern (value_object_to_value (obj), size, pattern_buf,
15532 + pattern_buf_end, pattern_buf_size);
15533 + else if (PySequence_Check (obj))
15535 + /* Handle lists and tuples. */
15537 + Py_ssize_t i, num_objs;
15539 + num_objs = PySequence_Size (obj);
15540 + for (i = 0; i < num_objs; i++)
15541 + if (!add_pattern_element (PySequence_GetItem (obj, i), size,
15542 + pattern_buf, pattern_buf_end,
15543 + pattern_buf_size))
15548 + /* See if we can convert from a Python object to a GDB value. */
15550 + struct value *v = convert_value_from_python (obj);
15553 + add_value_pattern (v, size, pattern_buf, pattern_buf_end,
15554 + pattern_buf_size);
15562 +/* Constructs the search pattern from OBJ, putting it in *PATTERN_BUFP, and its
15563 + size in *PATTERN_LENP. See the function add_pattern_element to learn how
15564 + the search pattern is obtained from OBJ.
15566 + Returns 1 on success or 0 on failure, with a Python exception set. This
15567 + function can also throw GDB exceptions. */
15570 +get_search_pattern (PyObject *obj, int size, char **pattern_bufp,
15571 + ULONGEST *pattern_lenp)
15573 + /* Buffer to hold the search pattern. */
15574 + char *pattern_buf;
15575 + /* Current size of search pattern buffer.
15576 + We realloc space as needed. */
15577 + ULONGEST pattern_buf_size;
15578 + /* Pointer to one past the last in-use part of pattern_buf. */
15579 + char *pattern_buf_end;
15580 + struct cleanup *old_cleanups;
15582 + allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
15583 + old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
15585 + if (!add_pattern_element (obj, size, &pattern_buf, &pattern_buf_end,
15586 + &pattern_buf_size))
15588 + do_cleanups (old_cleanups);
15593 + *pattern_bufp = pattern_buf;
15594 + *pattern_lenp = pattern_buf_end - pattern_buf;
15596 + discard_cleanups (old_cleanups);
15601 +/* Implementation of
15602 + gdb.search_memory (address, length, pattern [, size] [, max_count]).
15603 + The third argument may be either a pattern, or a list or tupple of patterns
15604 + to be searched. Size is the size in bytes of each search query value, either
15605 + 1, 2, 4 or 8. Returns a list of the addresses where matches were found. */
15608 +infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
15611 + unsigned int found_count = 0;
15612 + long max_count = 0;
15613 + CORE_ADDR start_addr, length;
15614 + char *pattern_buf;
15615 + static char *keywords[] = { "address", "length", "pattern", "size",
15616 + "max_count", NULL };
15617 + ULONGEST pattern_len, search_space_len;
15618 + PyObject *pattern, *list = NULL, *start_addr_obj, *length_obj;
15619 + volatile struct gdb_exception except;
15621 + if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO|il", keywords,
15622 + &start_addr_obj, &length_obj, &pattern,
15623 + &size, &max_count))
15627 + max_count = LONG_MAX;
15629 + if (size != 0 && size != 1 && size != 2 && size != 4 && size != 8)
15631 + PyErr_SetString (PyExc_ValueError, "invalid pattern size");
15635 + TRY_CATCH (except, RETURN_MASK_ALL)
15637 + if (get_addr_from_python (start_addr_obj, &start_addr)
15638 + && get_addr_from_python (length_obj, &length))
15642 + PyErr_SetString (PyExc_ValueError, "empty search range");
15645 + /* Watch for overflows. */
15646 + else if (length > CORE_ADDR_MAX
15647 + || (start_addr + length - 1) < start_addr)
15649 + PyErr_SetString (PyExc_ValueError, "search range too large");
15653 + search_space_len = length;
15655 + if (get_search_pattern (pattern, size, &pattern_buf, &pattern_len))
15657 + /* Any cleanups get automatically executed on an exception. */
15658 + struct cleanup *cleanups = make_cleanup (xfree, pattern_buf);
15660 + list = PyList_New (0);
15662 + while (search_space_len >= pattern_len && found_count < max_count)
15664 + CORE_ADDR found_addr;
15667 + found = search_memory (&start_addr, &search_space_len,
15668 + pattern_buf, pattern_len, &found_addr);
15672 + PyList_Append (list, PyLong_FromUnsignedLong (found_addr));
15676 + do_cleanups (cleanups);
15680 + GDB_PY_HANDLE_EXCEPTION (except);
15688 +gdbpy_initialize_inferior (void)
15690 + if (PyType_Ready (&inferior_object_type) < 0)
15693 + Py_INCREF (&inferior_object_type);
15694 + PyModule_AddObject (gdb_module, "Inferior",
15695 + (PyObject *) &inferior_object_type);
15697 + inferior_list = NULL;
15700 + observer_attach_new_inferior (add_inferior_object);
15701 + observer_attach_inferior_exit (delete_inferior_object);
15702 + observer_attach_new_thread (add_thread_object);
15703 + observer_attach_thread_exit (delete_thread_object);
15705 + if (PyType_Ready (&membuf_object_type) < 0)
15708 + Py_INCREF (&membuf_object_type);
15709 + PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
15714 +static PyGetSetDef inferior_object_getset[] =
15716 + { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
15717 + { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
15719 + { "was_attached", infpy_get_was_attached, NULL,
15720 + "True if the inferior was created using 'attach'.", NULL },
15725 +static PyMethodDef inferior_object_methods[] =
15727 + { "threads", infpy_threads, METH_NOARGS,
15728 + "Return all the threads of this inferior." },
15730 + { "read_memory", infpy_read_memory, METH_VARARGS,
15731 + "read_memory (address, length) -> buffer\n\
15732 +Return a buffer object for reading from the inferior's memory." },
15733 + { "write_memory", infpy_write_memory, METH_VARARGS,
15734 + "write_memory (address, buffer [, length])\n\
15735 +Write the given buffer object to the inferior's memory." },
15736 + { "search_memory", (PyCFunction) infpy_search_memory, METH_VARARGS | METH_KEYWORDS,
15737 + "search_memory (address, length, pattern [, size] [, max_count]) -> list\n\
15738 +Return a list with the addresses where matches were found." },
15743 +static PyTypeObject inferior_object_type =
15745 + PyObject_HEAD_INIT (NULL)
15747 + "gdb.Inferior", /* tp_name */
15748 + sizeof (inferior_object), /* tp_basicsize */
15749 + 0, /* tp_itemsize */
15750 + 0, /* tp_dealloc */
15751 + 0, /* tp_print */
15752 + 0, /* tp_getattr */
15753 + 0, /* tp_setattr */
15754 + 0, /* tp_compare */
15756 + 0, /* tp_as_number */
15757 + 0, /* tp_as_sequence */
15758 + 0, /* tp_as_mapping */
15762 + 0, /* tp_getattro */
15763 + 0, /* tp_setattro */
15764 + 0, /* tp_as_buffer */
15765 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /* tp_flags */
15766 + "GDB inferior object", /* tp_doc */
15767 + 0, /* tp_traverse */
15768 + 0, /* tp_clear */
15769 + 0, /* tp_richcompare */
15770 + 0, /* tp_weaklistoffset */
15772 + 0, /* tp_iternext */
15773 + inferior_object_methods, /* tp_methods */
15774 + 0, /* tp_members */
15775 + inferior_object_getset, /* tp_getset */
15778 + 0, /* tp_descr_get */
15779 + 0, /* tp_descr_set */
15780 + 0, /* tp_dictoffset */
15787 +/* Python doesn't provide a decent way to get compatibility here. */
15788 +#if HAVE_LIBPYTHON2_4
15789 +#define CHARBUFFERPROC_NAME getcharbufferproc
15791 +#define CHARBUFFERPROC_NAME charbufferproc
15794 +static PyBufferProcs buffer_procs = {
15796 + get_write_buffer,
15798 + /* The cast here works around a difference between Python 2.4 and
15800 + (CHARBUFFERPROC_NAME) get_char_buffer
15803 +static PyTypeObject membuf_object_type = {
15804 + PyObject_HEAD_INIT (NULL)
15806 + "gdb.Membuf", /*tp_name*/
15807 + sizeof (membuf_object), /*tp_basicsize*/
15808 + 0, /*tp_itemsize*/
15809 + mbpy_dealloc, /*tp_dealloc*/
15811 + 0, /*tp_getattr*/
15812 + 0, /*tp_setattr*/
15813 + 0, /*tp_compare*/
15815 + 0, /*tp_as_number*/
15816 + 0, /*tp_as_sequence*/
15817 + 0, /*tp_as_mapping*/
15820 + mbpy_str, /*tp_str*/
15821 + 0, /*tp_getattro*/
15822 + 0, /*tp_setattro*/
15823 + &buffer_procs, /*tp_as_buffer*/
15824 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
15825 + "GDB memory buffer object", /*tp_doc*/
15826 + 0, /* tp_traverse */
15827 + 0, /* tp_clear */
15828 + 0, /* tp_richcompare */
15829 + 0, /* tp_weaklistoffset */
15831 + 0, /* tp_iternext */
15832 + 0, /* tp_methods */
15833 + 0, /* tp_members */
15834 + 0, /* tp_getset */
15837 + 0, /* tp_descr_get */
15838 + 0, /* tp_descr_set */
15839 + 0, /* tp_dictoffset */
15841 + 0, /* tp_alloc */
15842 + PyType_GenericNew /* tp_new */
15844 diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
15845 new file mode 100644
15846 index 0000000..21e4eab
15848 +++ b/gdb/python/py-infthread.c
15850 +/* Python interface to inferior threads.
15852 + Copyright (C) 2009 Free Software Foundation, Inc.
15854 + This file is part of GDB.
15856 + This program is free software; you can redistribute it and/or modify
15857 + it under the terms of the GNU General Public License as published by
15858 + the Free Software Foundation; either version 3 of the License, or
15859 + (at your option) any later version.
15861 + This program is distributed in the hope that it will be useful,
15862 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15863 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15864 + GNU General Public License for more details.
15866 + You should have received a copy of the GNU General Public License
15867 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
15870 +#include "exceptions.h"
15871 +#include "gdbthread.h"
15872 +#include "inferior.h"
15873 +#include "python-internal.h"
15875 +static PyTypeObject thread_object_type;
15877 +/* Require that INFERIOR be a valid inferior ID. */
15878 +#define THPY_REQUIRE_VALID(Thread) \
15880 + if (!Thread->thread) \
15882 + PyErr_SetString (PyExc_RuntimeError, \
15883 + "thread no longer exists"); \
15891 +create_thread_object (struct thread_info *tp)
15893 + thread_object *thread_obj;
15895 + thread_obj = PyObject_New (thread_object, &thread_object_type);
15899 + thread_obj->thread = tp;
15900 + thread_obj->inf_obj = find_inferior_object (PIDGET (tp->ptid));
15901 + Py_INCREF (thread_obj->inf_obj);
15903 + return thread_obj;
15909 +thpy_dealloc (PyObject *self)
15911 + Py_DECREF (((thread_object *) self)->inf_obj);
15912 + self->ob_type->tp_free (self);
15916 +thpy_get_num (PyObject *self, void *closure)
15918 + thread_object *thread_obj = (thread_object *) self;
15920 + THPY_REQUIRE_VALID (thread_obj);
15922 + return PyLong_FromLong (thread_obj->thread->num);
15927 +/* Implementation of Inferior.frames () -> (gdb.Frame, ...).
15928 + Returns a tuple of all frame objects. */
15930 +thpy_frames (PyObject *self, PyObject *args)
15933 + struct frame_info *frame;
15934 + PyObject *frame_obj;
15935 + PyObject *list, *tuple;
15936 + thread_object *thread_obj = (thread_object *) self;
15937 + struct cleanup *cleanup;
15938 + volatile struct gdb_exception except;
15940 + THPY_REQUIRE_VALID (thread_obj);
15942 + list = PyList_New (0);
15943 + if (list == NULL)
15945 + PyErr_SetString (PyExc_MemoryError, "Could not allocate frames list.");
15949 + cleanup = make_cleanup_restore_current_thread ();
15951 + TRY_CATCH (except, RETURN_MASK_ALL)
15953 + switch_to_thread (thread_obj->thread->ptid);
15955 + for (frame = get_current_frame (); frame; frame = get_prev_frame (frame))
15957 + frame_obj = frame_info_to_frame_object (frame);
15958 + if (frame_obj == NULL)
15960 + Py_DECREF (list);
15965 + PyList_Append (list, frame_obj);
15968 + if (except.reason < 0)
15970 + Py_DECREF (list);
15971 + return PyErr_Format (except.reason == RETURN_QUIT
15972 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
15973 + "%s", except.message);
15976 + do_cleanups (cleanup);
15980 + tuple = PyList_AsTuple (list);
15981 + Py_DECREF (list);
15989 +/* Implementation of InferiorThread.newest_frame () -> gdb.Frame.
15990 + Returns the newest frame object. */
15992 +thpy_newest_frame (PyObject *self, PyObject *args)
15994 + struct frame_info *frame;
15995 + PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */
15996 + thread_object *thread_obj = (thread_object *) self;
15997 + struct cleanup *cleanup;
15998 + volatile struct gdb_exception except;
16000 + THPY_REQUIRE_VALID (thread_obj);
16002 + cleanup = make_cleanup_restore_current_thread ();
16004 + TRY_CATCH (except, RETURN_MASK_ALL)
16006 + switch_to_thread (thread_obj->thread->ptid);
16008 + frame = get_current_frame ();
16009 + frame_obj = frame_info_to_frame_object (frame);
16011 + GDB_PY_HANDLE_EXCEPTION (except);
16013 + do_cleanups (cleanup);
16015 + return frame_obj;
16018 +/* Implementation of InferiorThread.switch ().
16019 + Makes this the GDB selected thread. */
16021 +thpy_switch (PyObject *self, PyObject *args)
16023 + thread_object *thread_obj = (thread_object *) self;
16024 + struct cleanup *cleanup;
16025 + volatile struct gdb_exception except;
16027 + THPY_REQUIRE_VALID (thread_obj);
16029 + TRY_CATCH (except, RETURN_MASK_ALL)
16031 + switch_to_thread (thread_obj->thread->ptid);
16033 + GDB_PY_HANDLE_EXCEPTION (except);
16040 +/* Implementation of gdb.selected_thread () -> gdb.InferiorThread.
16041 + Returns the selected thread object. */
16043 +gdbpy_selected_thread (PyObject *self, PyObject *args)
16045 + PyObject *thread_obj;
16047 + thread_obj = (PyObject *) find_thread_object (inferior_ptid);
16050 + Py_INCREF (thread_obj);
16051 + return thread_obj;
16060 +gdbpy_initialize_thread (void)
16062 + if (PyType_Ready (&thread_object_type) < 0)
16065 + Py_INCREF (&thread_object_type);
16066 + PyModule_AddObject (gdb_module, "InferiorThread",
16067 + (PyObject *) &thread_object_type);
16072 +static PyGetSetDef thread_object_getset[] =
16074 + { "num", thpy_get_num, NULL, "ID of the thread, as assigned by GDB.", NULL },
16079 +static PyMethodDef thread_object_methods[] =
16081 + { "frames", thpy_frames, METH_NOARGS,
16082 + "frames () -> (gdb.Frame, ...)\n\
16083 +Return a tuple containing all frames in the thread." },
16084 + { "newest_frame", thpy_newest_frame, METH_NOARGS,
16085 + "newest_frame () -> gdb.Frame\n\
16086 +Return the newest frame in the thread." },
16087 + { "switch", thpy_switch, METH_NOARGS,
16089 +Makes this the GDB selected thread." },
16094 +static PyTypeObject thread_object_type =
16096 + PyObject_HEAD_INIT (NULL)
16098 + "gdb.InferiorThread", /*tp_name*/
16099 + sizeof (thread_object), /*tp_basicsize*/
16100 + 0, /*tp_itemsize*/
16101 + thpy_dealloc, /*tp_dealloc*/
16103 + 0, /*tp_getattr*/
16104 + 0, /*tp_setattr*/
16105 + 0, /*tp_compare*/
16107 + 0, /*tp_as_number*/
16108 + 0, /*tp_as_sequence*/
16109 + 0, /*tp_as_mapping*/
16113 + 0, /*tp_getattro*/
16114 + 0, /*tp_setattro*/
16115 + 0, /*tp_as_buffer*/
16116 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
16117 + "GDB thread object", /* tp_doc */
16118 + 0, /* tp_traverse */
16119 + 0, /* tp_clear */
16120 + 0, /* tp_richcompare */
16121 + 0, /* tp_weaklistoffset */
16123 + 0, /* tp_iternext */
16124 + thread_object_methods, /* tp_methods */
16125 + 0, /* tp_members */
16126 + thread_object_getset, /* tp_getset */
16129 + 0, /* tp_descr_get */
16130 + 0, /* tp_descr_set */
16131 + 0, /* tp_dictoffset */
16135 diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
16136 new file mode 100644
16137 index 0000000..7bc294c
16139 +++ b/gdb/python/py-membuf.c
16141 +/* Python interface to the inferior memory.
16143 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16145 + This file is part of GDB.
16147 + This program is free software; you can redistribute it and/or modify
16148 + it under the terms of the GNU General Public License as published by
16149 + the Free Software Foundation; either version 3 of the License, or
16150 + (at your option) any later version.
16152 + This program is distributed in the hope that it will be useful,
16153 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16154 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16155 + GNU General Public License for more details.
16157 + You should have received a copy of the GNU General Public License
16158 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
16161 +#include "exceptions.h"
16162 +#include "gdbcore.h"
16163 +#include "python-internal.h"
16169 + /* These are kept just for mbpy_str. */
16171 + CORE_ADDR length;
16174 +static PyTypeObject membuf_object_type;
16176 +/* Implementation of gdb.read_memory (address, length).
16177 + Returns a Python buffer object with LENGTH bytes of the inferior's memory
16178 + at ADDRESS. Both arguments are integers. */
16181 +gdbpy_read_memory (PyObject *self, PyObject *args)
16184 + CORE_ADDR addr, length;
16185 + void *buffer = NULL;
16186 + membuf_object *membuf_obj;
16187 + PyObject *addr_obj, *length_obj;
16188 + struct cleanup *cleanups = NULL;
16189 + volatile struct gdb_exception except;
16191 + if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
16194 + TRY_CATCH (except, RETURN_MASK_ALL)
16196 + if (!get_addr_from_python (addr_obj, &addr)
16197 + || !get_addr_from_python (length_obj, &length))
16203 + buffer = xmalloc (length);
16204 + cleanups = make_cleanup (xfree, buffer);
16206 + read_memory (addr, buffer, length);
16208 + GDB_PY_HANDLE_EXCEPTION (except);
16213 + discard_cleanups (cleanups);
16215 + membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
16216 + if (membuf_obj == NULL)
16219 + PyErr_SetString (PyExc_MemoryError,
16220 + "Could not allocate memory buffer object.");
16224 + membuf_obj->buffer = buffer;
16225 + membuf_obj->addr = addr;
16226 + membuf_obj->length = length;
16228 + return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
16229 + Py_END_OF_BUFFER);
16232 +/* Implementation of gdb.write_memory (address, buffer [, length]).
16233 + Writes the contents of BUFFER (a Python object supporting the read buffer
16234 + protocol) at ADDRESS in the inferior's memory. Write LENGTH bytes from
16235 + BUFFER, or its entire contents if the argument is not provided. The
16236 + function returns nothing. */
16239 +gdbpy_write_memory (PyObject *self, PyObject *args)
16241 + int buf_len, error = 0;
16242 + const char *buffer;
16243 + CORE_ADDR addr, length;
16244 + PyObject *addr_obj, *length_obj = NULL;
16245 + volatile struct gdb_exception except;
16247 + if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
16251 + TRY_CATCH (except, RETURN_MASK_ALL)
16253 + if (!get_addr_from_python (addr_obj, &addr))
16260 + length = buf_len;
16261 + else if (!get_addr_from_python (length_obj, &length))
16267 + write_memory (addr, buffer, length);
16269 + GDB_PY_HANDLE_EXCEPTION (except);
16277 +/* Destructor of Membuf objects. */
16280 +mbpy_dealloc (PyObject *self)
16282 + xfree (((membuf_object *) self)->buffer);
16283 + self->ob_type->tp_free (self);
16286 +/* Return a description of the Membuf object. */
16289 +mbpy_str (PyObject *self)
16291 + membuf_object *membuf_obj = (membuf_object *) self;
16293 + return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
16294 + paddress (membuf_obj->addr),
16295 + pulongest (membuf_obj->length));
16299 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
16301 + membuf_object *membuf_obj = (membuf_object *) self;
16305 + PyErr_SetString (PyExc_SystemError,
16306 + "The memory buffer supports only one segment.");
16310 + *ptrptr = membuf_obj->buffer;
16312 + return membuf_obj->length;
16316 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
16318 + return get_read_buffer (self, segment, ptrptr);
16322 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
16325 + *lenp = ((membuf_object *) self)->length;
16331 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
16333 + void *ptr = NULL;
16336 + ret = get_read_buffer (self, segment, &ptr);
16337 + *ptrptr = (char *) ptr;
16342 +/* Python doesn't provide a decent way to get compatibility here. */
16343 +#if HAVE_LIBPYTHON2_4
16344 +#define CHARBUFFERPROC_NAME getcharbufferproc
16346 +#define CHARBUFFERPROC_NAME charbufferproc
16349 +static PyBufferProcs buffer_procs = {
16351 + get_write_buffer,
16353 + /* The cast here works around a difference between Python 2.4 and
16355 + (CHARBUFFERPROC_NAME) get_char_buffer
16358 +static PyTypeObject membuf_object_type = {
16359 + PyObject_HEAD_INIT (NULL)
16361 + "gdb.Membuf", /*tp_name*/
16362 + sizeof (membuf_object), /*tp_basicsize*/
16363 + 0, /*tp_itemsize*/
16364 + mbpy_dealloc, /*tp_dealloc*/
16366 + 0, /*tp_getattr*/
16367 + 0, /*tp_setattr*/
16368 + 0, /*tp_compare*/
16370 + 0, /*tp_as_number*/
16371 + 0, /*tp_as_sequence*/
16372 + 0, /*tp_as_mapping*/
16375 + mbpy_str, /*tp_str*/
16376 + 0, /*tp_getattro*/
16377 + 0, /*tp_setattro*/
16378 + &buffer_procs, /*tp_as_buffer*/
16379 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
16380 + "GDB memory buffer object", /*tp_doc*/
16381 + 0, /* tp_traverse */
16382 + 0, /* tp_clear */
16383 + 0, /* tp_richcompare */
16384 + 0, /* tp_weaklistoffset */
16386 + 0, /* tp_iternext */
16387 + 0, /* tp_methods */
16388 + 0, /* tp_members */
16389 + 0, /* tp_getset */
16392 + 0, /* tp_descr_get */
16393 + 0, /* tp_descr_set */
16394 + 0, /* tp_dictoffset */
16396 + 0, /* tp_alloc */
16397 + PyType_GenericNew /* tp_new */
16401 +gdbpy_initialize_membuf (void)
16403 + if (PyType_Ready (&membuf_object_type) < 0)
16406 + Py_INCREF (&membuf_object_type);
16407 + PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
16409 diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
16410 new file mode 100644
16411 index 0000000..1f591a8
16413 +++ b/gdb/python/py-param.c
16415 +/* gdb parameters implemented in Python
16417 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16419 + This file is part of GDB.
16421 + This program is free software; you can redistribute it and/or modify
16422 + it under the terms of the GNU General Public License as published by
16423 + the Free Software Foundation; either version 3 of the License, or
16424 + (at your option) any later version.
16426 + This program is distributed in the hope that it will be useful,
16427 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16428 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16429 + GNU General Public License for more details.
16431 + You should have received a copy of the GNU General Public License
16432 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
16436 +#include "value.h"
16437 +#include "exceptions.h"
16438 +#include "python-internal.h"
16439 +#include "charset.h"
16440 +#include "gdbcmd.h"
16441 +#include "cli/cli-decode.h"
16442 +#include "completer.h"
16444 +/* Parameter constants and their values. */
16445 +struct parm_constant
16451 +struct parm_constant parm_constants[] =
16453 + { "PARAM_BOOLEAN", var_boolean },
16454 + { "PARAM_AUTO_BOOLEAN", var_auto_boolean },
16455 + { "PARAM_UINTEGER", var_uinteger },
16456 + { "PARAM_INTEGER", var_integer },
16457 + { "PARAM_STRING", var_string },
16458 + { "PARAM_STRING_NOESCAPE", var_string_noescape },
16459 + { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
16460 + { "PARAM_FILENAME", var_filename },
16461 + { "PARAM_ZINTEGER", var_zinteger },
16462 + { "PARAM_ENUM", var_enum },
16466 +/* A union that can hold anything described by enum var_types. */
16467 +union parmpy_variable
16469 + /* Hold an integer value, for boolean and integer types. */
16472 + /* Hold an auto_boolean. */
16473 + enum auto_boolean autoboolval;
16475 + /* Hold an unsigned integer value, for uinteger. */
16476 + unsigned int uintval;
16478 + /* Hold a string, for the various string types. */
16481 + /* Hold a string, for enums. */
16482 + const char *cstringval;
16485 +/* A gdb parameter. */
16486 +struct parmpy_object
16490 + /* The type of the parameter. */
16491 + enum var_types type;
16493 + /* The value of the parameter. */
16494 + union parmpy_variable value;
16496 + /* For an enum command, the possible values. The vector is
16497 + allocated with xmalloc, as is each element. It is
16498 + NULL-terminated. */
16499 + const char **enumeration;
16502 +typedef struct parmpy_object parmpy_object;
16504 +static PyTypeObject parmpy_object_type;
16506 +/* Some handy string constants. */
16507 +static PyObject *set_doc_cst;
16508 +static PyObject *show_doc_cst;
16512 +/* Get an attribute. */
16514 +get_attr (PyObject *obj, PyObject *attr_name)
16516 + if (PyString_Check (attr_name)
16517 + && ! strcmp (PyString_AsString (attr_name), "value"))
16519 + parmpy_object *self = (parmpy_object *) obj;
16520 + return gdbpy_parameter_value (self->type, &self->value);
16523 + return PyObject_GenericGetAttr (obj, attr_name);
16526 +/* Set a parameter value from a Python value. Return 0 on success, -1
16529 +set_parameter_value (parmpy_object *self, PyObject *value)
16533 + switch (self->type)
16536 + case var_string_noescape:
16537 + case var_optional_filename:
16538 + case var_filename:
16539 + if (! gdbpy_is_string (value)
16540 + && (self->type == var_filename
16541 + || value != Py_None))
16543 + PyErr_SetString (PyExc_RuntimeError, "string required");
16546 + if (self->value.stringval)
16547 + xfree (self->value.stringval);
16548 + if (value == Py_None)
16550 + if (self->type == var_optional_filename)
16551 + self->value.stringval = xstrdup ("");
16553 + self->value.stringval = NULL;
16556 + self->value.stringval = python_string_to_host_string (value);
16564 + if (! gdbpy_is_string (value))
16566 + PyErr_SetString (PyExc_RuntimeError, "string required");
16570 + str = python_string_to_host_string (value);
16571 + for (i = 0; self->enumeration[i]; ++i)
16572 + if (! strcmp (self->enumeration[i], str))
16575 + if (! self->enumeration[i])
16577 + PyErr_SetString (PyExc_RuntimeError,
16578 + "value must be member of enumeration");
16581 + self->value.cstringval = self->enumeration[i];
16585 + case var_boolean:
16586 + if (! PyBool_Check (value))
16588 + PyErr_SetString (PyExc_RuntimeError, "boolean required");
16591 + cmp = PyObject_IsTrue (value);
16594 + self->value.intval = cmp;
16597 + case var_auto_boolean:
16598 + if (! PyBool_Check (value) && value != Py_None)
16600 + PyErr_SetString (PyExc_RuntimeError,
16601 + "boolean or None required");
16605 + if (value == Py_None)
16606 + self->value.autoboolval = AUTO_BOOLEAN_AUTO;
16609 + cmp = PyObject_IsTrue (value);
16613 + self->value.autoboolval = AUTO_BOOLEAN_TRUE;
16615 + self->value.autoboolval = AUTO_BOOLEAN_FALSE;
16620 + case var_integer:
16621 + case var_zinteger:
16622 + case var_uinteger:
16627 + if (! PyInt_Check (value))
16629 + PyErr_SetString (PyExc_RuntimeError, "value must be integer");
16633 + l = PyInt_AsLong (value);
16634 + if (self->type == var_uinteger)
16636 + ok = (l >= 0 && l <= UINT_MAX);
16640 + else if (self->type == var_integer)
16642 + ok = (l >= INT_MIN && l <= INT_MAX);
16647 + ok = (l >= INT_MIN && l <= INT_MAX);
16651 + PyErr_SetString (PyExc_RuntimeError, "range exceeded");
16655 + self->value.intval = (int) l;
16660 + PyErr_SetString (PyExc_RuntimeError, "programmer error: unhandled type");
16667 +/* Set an attribute. */
16669 +set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
16671 + if (PyString_Check (attr_name)
16672 + && ! strcmp (PyString_AsString (attr_name), "value"))
16676 + PyErr_SetString (PyExc_RuntimeError,
16677 + "cannot delete a parameter's value");
16680 + return set_parameter_value ((parmpy_object *) obj, val);
16683 + return PyObject_GenericSetAttr (obj, attr_name, val);
16688 +/* A helper function that dispatches to the appropriate add_setshow
16691 +add_setshow_generic (int parmclass, enum command_class cmdclass,
16692 + char *cmd_name, parmpy_object *self,
16693 + char *set_doc, char *show_doc, char *help_doc,
16694 + struct cmd_list_element **set_list,
16695 + struct cmd_list_element **show_list)
16697 + switch (parmclass)
16699 + case var_boolean:
16700 + add_setshow_boolean_cmd (cmd_name, cmdclass, &self->value.intval,
16701 + set_doc, show_doc, help_doc,
16702 + NULL, NULL, set_list, show_list);
16705 + case var_auto_boolean:
16706 + add_setshow_auto_boolean_cmd (cmd_name, cmdclass,
16707 + &self->value.autoboolval,
16708 + set_doc, show_doc, help_doc,
16709 + NULL, NULL, set_list, show_list);
16712 + case var_uinteger:
16713 + add_setshow_uinteger_cmd (cmd_name, cmdclass, &self->value.uintval,
16714 + set_doc, show_doc, help_doc,
16715 + NULL, NULL, set_list, show_list);
16718 + case var_integer:
16719 + add_setshow_integer_cmd (cmd_name, cmdclass, &self->value.intval,
16720 + set_doc, show_doc, help_doc,
16721 + NULL, NULL, set_list, show_list);
16725 + add_setshow_string_cmd (cmd_name, cmdclass, &self->value.stringval,
16726 + set_doc, show_doc, help_doc,
16727 + NULL, NULL, set_list, show_list);
16730 + case var_string_noescape:
16731 + add_setshow_string_noescape_cmd (cmd_name, cmdclass,
16732 + &self->value.stringval,
16733 + set_doc, show_doc, help_doc,
16734 + NULL, NULL, set_list, show_list);
16737 + case var_optional_filename:
16738 + add_setshow_optional_filename_cmd (cmd_name, cmdclass,
16739 + &self->value.stringval,
16740 + set_doc, show_doc, help_doc,
16741 + NULL, NULL, set_list, show_list);
16744 + case var_filename:
16745 + add_setshow_filename_cmd (cmd_name, cmdclass, &self->value.stringval,
16746 + set_doc, show_doc, help_doc,
16747 + NULL, NULL, set_list, show_list);
16750 + case var_zinteger:
16751 + add_setshow_zinteger_cmd (cmd_name, cmdclass, &self->value.intval,
16752 + set_doc, show_doc, help_doc,
16753 + NULL, NULL, set_list, show_list);
16757 + add_setshow_enum_cmd (cmd_name, cmdclass, self->enumeration,
16758 + &self->value.cstringval,
16759 + set_doc, show_doc, help_doc,
16760 + NULL, NULL, set_list, show_list);
16761 + /* Initialize the value, just in case. */
16762 + self->value.cstringval = self->enumeration[0];
16767 +/* A helper which computes enum values. Returns 1 on success, 0 on
16770 +compute_enum_values (parmpy_object *self, PyObject *enum_values)
16772 + Py_ssize_t size, i;
16774 + if (! enum_values)
16776 + PyErr_SetString (PyExc_RuntimeError,
16777 + "enumeration required for PARAM_ENUM");
16781 + if (! PySequence_Check (enum_values))
16783 + PyErr_SetString (PyExc_RuntimeError, "enumeration is not a sequence");
16787 + size = PySequence_Size (enum_values);
16792 + PyErr_SetString (PyExc_RuntimeError, "empty enumeration");
16796 + self->enumeration = xmalloc ((size + 1) * sizeof (char *));
16797 + memset (self->enumeration, 0, (size + 1) * sizeof (char *));
16799 + for (i = 0; i < size; ++i)
16801 + PyObject *item = PySequence_GetItem (enum_values, i);
16804 + if (! gdbpy_is_string (item))
16806 + PyErr_SetString (PyExc_RuntimeError, "enumeration item not a string");
16809 + self->enumeration[i] = python_string_to_host_string (item);
16815 +/* A helper function which returns a documentation string for an
16818 +get_doc_string (PyObject *object, PyObject *attr)
16820 + char *result = NULL;
16821 + if (PyObject_HasAttr (object, attr))
16823 + PyObject *ds_obj = PyObject_GetAttr (object, attr);
16824 + if (ds_obj && gdbpy_is_string (ds_obj))
16825 + result = python_string_to_host_string (ds_obj);
16828 + result = xstrdup ("This command is not documented.");
16832 +/* Object initializer; sets up gdb-side structures for command.
16834 + Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
16836 + NAME is the name of the parameter. It may consist of multiple
16837 + words, in which case the final word is the name of the new command,
16838 + and earlier words must be prefix commands.
16840 + CMDCLASS is the kind of command. It should be one of the COMMAND_*
16841 + constants defined in the gdb module.
16843 + PARMCLASS is the type of the parameter. It should be one of the
16844 + PARAM_* constants defined in the gdb module.
16846 + If PARMCLASS is PARAM_ENUM, then the final argument should be a
16847 + collection of strings. These strings are the valid values for this
16850 + The documentation for the parameter is taken from the doc string
16851 + for the python class.
16855 +parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
16857 + parmpy_object *obj = (parmpy_object *) self;
16859 + char *set_doc, *show_doc, *doc;
16861 + int parmclass, cmdtype;
16862 + PyObject *enum_values = NULL;
16863 + struct cmd_list_element *cmd_list;
16864 + struct cmd_list_element **set_list, **show_list;
16865 + volatile struct gdb_exception except;
16867 + if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
16871 + if (cmdtype != no_class && cmdtype != class_run
16872 + && cmdtype != class_vars && cmdtype != class_stack
16873 + && cmdtype != class_files && cmdtype != class_support
16874 + && cmdtype != class_info && cmdtype != class_breakpoint
16875 + && cmdtype != class_trace && cmdtype != class_obscure
16876 + && cmdtype != class_maintenance)
16878 + PyErr_Format (PyExc_RuntimeError, "invalid command class argument");
16882 + if (parmclass != var_boolean && parmclass != var_auto_boolean
16883 + && parmclass != var_uinteger && parmclass != var_integer
16884 + && parmclass != var_string && parmclass != var_string_noescape
16885 + && parmclass != var_optional_filename && parmclass != var_filename
16886 + && parmclass != var_zinteger && parmclass != var_enum)
16888 + PyErr_SetString (PyExc_RuntimeError, "invalid parameter class argument");
16892 + if (enum_values && parmclass != var_enum)
16894 + PyErr_SetString (PyExc_RuntimeError,
16895 + "only PARAM_ENUM accepts a fourth argument");
16898 + if (parmclass == var_enum)
16900 + if (! compute_enum_values (obj, enum_values))
16904 + obj->type = (enum var_types) parmclass;
16905 + memset (&obj->value, 0, sizeof (obj->value));
16906 + obj->enumeration = NULL;
16908 + cmd_name = gdbpy_parse_command_name (name, &set_list, &setlist);
16911 + xfree (cmd_name);
16912 + cmd_name = gdbpy_parse_command_name (name, &show_list, &showlist);
16916 + /* FIXME: there is no way to register a destructor function for
16917 + set/show commands. So, these are leaked. */
16918 + set_doc = get_doc_string (self, set_doc_cst);
16919 + show_doc = get_doc_string (self, show_doc_cst);
16920 + doc = get_doc_string (self, gdbpy_doc_cst);
16922 + Py_INCREF (self);
16924 + TRY_CATCH (except, RETURN_MASK_ALL)
16926 + add_setshow_generic (parmclass, (enum command_class) cmdtype,
16928 + set_doc, show_doc,
16929 + doc, set_list, show_list);
16931 + if (except.reason < 0)
16933 + xfree (cmd_name);
16935 + xfree (show_doc);
16937 + Py_DECREF (self);
16938 + PyErr_Format (except.reason == RETURN_QUIT
16939 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
16940 + "%s", except.message);
16948 +/* Initialize the 'parameters' module. */
16950 +gdbpy_initialize_parameters (void)
16954 + if (PyType_Ready (&parmpy_object_type) < 0)
16957 + set_doc_cst = PyString_FromString ("set_doc");
16958 + if (! set_doc_cst)
16960 + show_doc_cst = PyString_FromString ("show_doc");
16961 + if (! show_doc_cst)
16964 + for (i = 0; parm_constants[i].name; ++i)
16966 + if (PyModule_AddIntConstant (gdb_module,
16967 + parm_constants[i].name,
16968 + parm_constants[i].value) < 0)
16972 + Py_INCREF (&parmpy_object_type);
16973 + PyModule_AddObject (gdb_module, "Parameter",
16974 + (PyObject *) &parmpy_object_type);
16979 +static PyTypeObject parmpy_object_type =
16981 + PyObject_HEAD_INIT (NULL)
16983 + "gdb.Parameter", /*tp_name*/
16984 + sizeof (parmpy_object), /*tp_basicsize*/
16985 + 0, /*tp_itemsize*/
16986 + 0, /*tp_dealloc*/
16988 + 0, /*tp_getattr*/
16989 + 0, /*tp_setattr*/
16990 + 0, /*tp_compare*/
16992 + 0, /*tp_as_number*/
16993 + 0, /*tp_as_sequence*/
16994 + 0, /*tp_as_mapping*/
16998 + get_attr, /*tp_getattro*/
16999 + set_attr, /*tp_setattro*/
17000 + 0, /*tp_as_buffer*/
17001 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
17002 + "GDB parameter object", /* tp_doc */
17003 + 0, /* tp_traverse */
17004 + 0, /* tp_clear */
17005 + 0, /* tp_richcompare */
17006 + 0, /* tp_weaklistoffset */
17008 + 0, /* tp_iternext */
17009 + 0, /* tp_methods */
17010 + 0, /* tp_members */
17011 + 0, /* tp_getset */
17014 + 0, /* tp_descr_get */
17015 + 0, /* tp_descr_set */
17016 + 0, /* tp_dictoffset */
17017 + parmpy_init, /* tp_init */
17018 + 0, /* tp_alloc */
17019 + PyType_GenericNew /* tp_new */
17021 diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
17022 index 5d696c8..a6348ba 100644
17023 --- a/gdb/python/py-prettyprint.c
17024 +++ b/gdb/python/py-prettyprint.c
17025 @@ -121,6 +121,7 @@ find_pretty_printer (PyObject *value)
17030 /* Pretty-print a single value, via the printer object PRINTER.
17031 If the function returns a string, a PyObject containing the string
17032 is returned. Otherwise, if the function returns a value,
17033 @@ -141,10 +142,15 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
17034 if (! gdbpy_is_string (result))
17036 *out_value = convert_value_from_python (result);
17037 - if (PyErr_Occurred ())
17038 - *out_value = NULL;
17039 - Py_DECREF (result);
17041 + if (PyErr_Occurred ())
17042 + *out_value = NULL;
17044 + /* We must increment the value's refcount, because we
17045 + are about to decref RESULT, and this may result in
17046 + the value being destroyed. */
17047 + value_incref (*out_value);
17048 + Py_DECREF (result);
17053 @@ -556,14 +562,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
17056 PyObject *pretty_printer = NULL;
17057 - volatile struct gdb_exception except;
17059 - TRY_CATCH (except, RETURN_MASK_ALL)
17061 - value = value_copy (value);
17063 - GDB_PY_HANDLE_EXCEPTION (except);
17065 val_obj = value_to_value_object (value);
17068 diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
17069 new file mode 100644
17070 index 0000000..03d43c1
17072 +++ b/gdb/python/py-symbol.c
17074 +/* Python interface to symbols.
17076 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
17078 + This file is part of GDB.
17080 + This program is free software; you can redistribute it and/or modify
17081 + it under the terms of the GNU General Public License as published by
17082 + the Free Software Foundation; either version 3 of the License, or
17083 + (at your option) any later version.
17085 + This program is distributed in the hope that it will be useful,
17086 + but WITHOUT ANY WARRANTY; without even the implied warranty of
17087 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17088 + GNU General Public License for more details.
17090 + You should have received a copy of the GNU General Public License
17091 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
17094 +#include "block.h"
17095 +#include "exceptions.h"
17096 +#include "frame.h"
17097 +#include "symtab.h"
17098 +#include "python-internal.h"
17102 + struct symbol *symbol;
17107 +sympy_str (PyObject *self)
17111 + PyObject *result;
17113 + ret = asprintf (&s, "symbol for %s",
17114 + SYMBOL_PRINT_NAME (((symbol_object *) self)->symbol));
17118 + result = PyString_FromString (s);
17125 +sympy_get_value (PyObject *self, void *closure)
17127 + symbol_object *self_sym = (symbol_object *) self;
17129 + switch (SYMBOL_CLASS (self_sym->symbol))
17132 + return block_to_block_object (SYMBOL_BLOCK_VALUE (self_sym->symbol));
17135 + PyErr_SetString (PyExc_NotImplementedError,
17136 + "Symbol type not yet supported in Python scripts.");
17141 +sympy_get_symtab (PyObject *self, void *closure)
17143 + symbol_object *self_sym = (symbol_object *) self;
17145 + return symtab_to_symtab_object (SYMBOL_SYMTAB (self_sym->symbol));
17149 +sympy_get_name (PyObject *self, void *closure)
17151 + symbol_object *self_sym = (symbol_object *) self;
17153 + return PyString_FromString (SYMBOL_NATURAL_NAME (self_sym->symbol));
17157 +sympy_get_linkage_name (PyObject *self, void *closure)
17159 + symbol_object *self_sym = (symbol_object *) self;
17161 + return PyString_FromString (SYMBOL_LINKAGE_NAME (self_sym->symbol));
17165 +sympy_get_print_name (PyObject *self, void *closure)
17167 + symbol_object *self_sym = (symbol_object *) self;
17169 + return PyString_FromString (SYMBOL_PRINT_NAME (self_sym->symbol));
17173 +sympy_get_addr_class (PyObject *self, void *closure)
17175 + symbol_object *self_sym = (symbol_object *) self;
17177 + return PyInt_FromLong (SYMBOL_CLASS (self_sym->symbol));
17181 +sympy_is_argument (PyObject *self, void *closure)
17183 + symbol_object *self_sym = (symbol_object *) self;
17185 + return PyBool_FromLong (SYMBOL_IS_ARGUMENT (self_sym->symbol));
17189 +sympy_is_constant (PyObject *self, void *closure)
17191 + symbol_object *self_sym = (symbol_object *) self;
17192 + enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17194 + return PyBool_FromLong (class == LOC_CONST || class == LOC_CONST_BYTES);
17198 +sympy_is_function (PyObject *self, void *closure)
17200 + symbol_object *self_sym = (symbol_object *) self;
17201 + enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17203 + return PyBool_FromLong (class == LOC_BLOCK);
17207 +sympy_is_variable (PyObject *self, void *closure)
17209 + symbol_object *self_sym = (symbol_object *) self;
17210 + enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17212 + return PyBool_FromLong (!SYMBOL_IS_ARGUMENT (self_sym->symbol)
17213 + && (class == LOC_LOCAL || class == LOC_REGISTER || class == LOC_STATIC
17214 + || class == LOC_COMPUTED || class == LOC_OPTIMIZED_OUT));
17218 +symbol_to_symbol_object (struct symbol *sym)
17220 + symbol_object *sym_obj;
17222 + sym_obj = PyObject_New (symbol_object, &symbol_object_type);
17223 + if (sym_obj == NULL)
17225 + PyErr_SetString (PyExc_MemoryError, "Could not allocate symbol object.");
17229 + sym_obj->symbol = sym;
17231 + return (PyObject *) sym_obj;
17235 +symbol_object_to_symbol (PyObject *obj)
17237 + if (! PyObject_TypeCheck (obj, &symbol_object_type))
17239 + return ((symbol_object *) obj)->symbol;
17242 +/* Implementation of
17243 + gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)
17244 + A tuple with 2 elements is always returned. The first is the symbol
17245 + object or None, the second is a boolean with the value of
17246 + is_a_field_of_this (see comment in lookup_symbol_in_language). */
17248 +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
17250 + int domain = VAR_DOMAIN, is_a_field_of_this = 0;
17251 + const char *name;
17252 + static char *keywords[] = { "name", "block", "domain", NULL };
17253 + struct symbol *symbol;
17254 + PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
17255 + struct block *block = NULL;
17257 + if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
17258 + &block_object_type, &block_obj, &domain))
17262 + block = block_object_to_block (block_obj);
17265 + struct frame_info *selected_frame;
17266 + volatile struct gdb_exception except;
17268 + TRY_CATCH (except, RETURN_MASK_ALL)
17270 + selected_frame = get_selected_frame (_("No frame selected."));
17271 + block = block_for_pc (get_frame_address_in_block (selected_frame));
17273 + GDB_PY_HANDLE_EXCEPTION (except);
17276 + symbol = lookup_symbol (name, block, domain, &is_a_field_of_this);
17278 + ret_tuple = PyTuple_New (2);
17281 + PyErr_SetString (PyExc_MemoryError, "Could not allocate tuple object.");
17287 + sym_obj = symbol_to_symbol_object (symbol);
17290 + Py_DECREF (ret_tuple);
17296 + sym_obj = Py_None;
17297 + Py_INCREF (Py_None);
17299 + PyTuple_SET_ITEM (ret_tuple, 0, sym_obj);
17301 + bool_obj = is_a_field_of_this? Py_True : Py_False;
17302 + Py_INCREF (bool_obj);
17303 + PyTuple_SET_ITEM (ret_tuple, 1, bool_obj);
17305 + return ret_tuple;
17309 +gdbpy_initialize_symbols (void)
17311 + if (PyType_Ready (&symbol_object_type) < 0)
17314 + /* FIXME: These would probably be best exposed as class attributes of Symbol,
17315 + but I don't know how to do it except by messing with the type's dictionary.
17316 + That seems too messy. */
17317 + /* FIXME 2: Some of these were removed from GDB since I first wrote this code,
17318 + so it's probably a good idea not to expose them to Python. */
17319 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
17320 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
17321 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
17322 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
17323 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
17324 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
17325 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
17326 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
17327 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
17328 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
17329 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
17330 + LOC_CONST_BYTES);
17331 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED", LOC_UNRESOLVED);
17332 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
17333 + LOC_OPTIMIZED_OUT);
17334 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
17335 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
17336 + LOC_REGPARM_ADDR);
17337 + PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
17338 + PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
17339 + PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
17340 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
17341 + PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
17342 + VARIABLES_DOMAIN);
17343 + PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
17344 + FUNCTIONS_DOMAIN);
17345 + PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
17347 + Py_INCREF (&symbol_object_type);
17348 + PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
17353 +static PyGetSetDef symbol_object_getset[] = {
17354 + { "value", sympy_get_value, NULL, "Value of the symbol.", NULL },
17355 + { "symtab", sympy_get_symtab, NULL,
17356 + "Symbol table in which the symbol appears.", NULL },
17357 + { "name", sympy_get_name, NULL,
17358 + "Name of the symbol, as it appears in the source code.", NULL },
17359 + { "linkage_name", sympy_get_linkage_name, NULL,
17360 + "Name of the symbol, as used by the linker (i.e., may be mangled).", NULL },
17361 + { "print_name", sympy_get_print_name, NULL,
17362 + "Name of the symbol in a form suitable for output.\n\
17363 +This is either name or linkage_name, depending on whether the user asked GDB\n\
17364 +to display demangled or mangled names.", NULL },
17365 + { "addr_class", sympy_get_addr_class, NULL, "Address class of the symbol." },
17366 + { "is_argument", sympy_is_argument, NULL,
17367 + "True if the symbol is an argument of a function." },
17368 + { "is_constant", sympy_is_constant, NULL,
17369 + "True if the symbol is a constant." },
17370 + { "is_function", sympy_is_function, NULL,
17371 + "True if the symbol is a function or method." },
17372 + { "is_variable", sympy_is_variable, NULL,
17373 + "True if the symbol is a variable." },
17374 + { NULL } /* Sentinel */
17377 +PyTypeObject symbol_object_type = {
17378 + PyObject_HEAD_INIT (NULL)
17380 + "gdb.Symbol", /*tp_name*/
17381 + sizeof (symbol_object), /*tp_basicsize*/
17382 + 0, /*tp_itemsize*/
17383 + 0, /*tp_dealloc*/
17385 + 0, /*tp_getattr*/
17386 + 0, /*tp_setattr*/
17387 + 0, /*tp_compare*/
17389 + 0, /*tp_as_number*/
17390 + 0, /*tp_as_sequence*/
17391 + 0, /*tp_as_mapping*/
17394 + sympy_str, /*tp_str*/
17395 + 0, /*tp_getattro*/
17396 + 0, /*tp_setattro*/
17397 + 0, /*tp_as_buffer*/
17398 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
17399 + "GDB symbol object", /* tp_doc */
17400 + 0, /* tp_traverse */
17401 + 0, /* tp_clear */
17402 + 0, /* tp_richcompare */
17403 + 0, /* tp_weaklistoffset */
17405 + 0, /* tp_iternext */
17406 + 0, /* tp_methods */
17407 + 0, /* tp_members */
17408 + symbol_object_getset /* tp_getset */
17410 diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
17411 new file mode 100644
17412 index 0000000..830e586
17414 +++ b/gdb/python/py-symtab.c
17416 +/* Python interface to symbol tables.
17418 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
17420 + This file is part of GDB.
17422 + This program is free software; you can redistribute it and/or modify
17423 + it under the terms of the GNU General Public License as published by
17424 + the Free Software Foundation; either version 3 of the License, or
17425 + (at your option) any later version.
17427 + This program is distributed in the hope that it will be useful,
17428 + but WITHOUT ANY WARRANTY; without even the implied warranty of
17429 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17430 + GNU General Public License for more details.
17432 + You should have received a copy of the GNU General Public License
17433 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
17436 +#include "charset.h"
17437 +#include "symtab.h"
17438 +#include "source.h"
17439 +#include "python-internal.h"
17443 + struct symtab *symtab;
17446 +static PyTypeObject symtab_object_type;
17450 + symtab_object *symtab;
17451 + struct symtab_and_line *sal;
17454 +static PyTypeObject sal_object_type;
17458 +stpy_str (PyObject *self)
17462 + PyObject *result;
17464 + ret = asprintf (&s, "symbol table for %s",
17465 + ((symtab_object *) self)->symtab->filename);
17469 + result = PyString_FromString (s);
17476 +stpy_get_filename (PyObject *self, void *closure)
17478 + symtab_object *self_symtab = (symtab_object *) self;
17479 + PyObject *str_obj;
17481 + /* FIXME: Can symtab->filename really be NULL? */
17482 + if (self_symtab->symtab->filename)
17483 + str_obj = PyString_Decode (self_symtab->symtab->filename,
17484 + strlen (self_symtab->symtab->filename),
17485 + host_charset (), NULL);
17488 + str_obj = Py_None;
17489 + Py_INCREF (Py_None);
17496 +stpy_get_objfile (PyObject *self, void *closure)
17498 + symtab_object *self_symtab = (symtab_object *) self;
17499 + PyObject *result = objfile_to_objfile_object (self_symtab->symtab->objfile);
17500 + Py_INCREF (result);
17505 +stpy_fullname (PyObject *self, PyObject *args)
17509 + fullname = symtab_to_fullname (((symtab_object *) self)->symtab);
17511 + return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
17517 +salpy_str (PyObject *self)
17520 + char *s, *filename;
17521 + sal_object *sal_obj;
17522 + PyObject *result;
17524 + sal_obj = (sal_object *) self;
17525 + filename = (sal_obj->symtab == (symtab_object *) Py_None)? "<unknown>" :
17526 + sal_obj->symtab->symtab->filename;
17527 + ret = asprintf (&s, "symbol and line for %s, line %d", filename,
17528 + sal_obj->sal->line);
17532 + result = PyString_FromString (s);
17539 +salpy_get_pc (PyObject *self, void *closure)
17541 + return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->pc);
17545 +salpy_get_line (PyObject *self, void *closure)
17547 + return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->line);
17551 +salpy_get_symtab (PyObject *self, void *closure)
17553 + sal_object *self_sal = (sal_object *) self;
17555 + Py_INCREF (self_sal->symtab);
17557 + return (PyObject *) self_sal->symtab;
17561 +salpy_dealloc (PyObject *self)
17563 + sal_object *self_sal = (sal_object *) self;
17565 + Py_DECREF (self_sal->symtab);
17566 + xfree (self_sal->sal);
17567 + self_sal->ob_type->tp_free (self);
17571 +symtab_and_line_to_sal_object (struct symtab_and_line sal)
17573 + sal_object *sal_obj;
17574 + symtab_object *symtab_obj;
17576 + sal_obj = PyObject_New (sal_object, &sal_object_type);
17577 + if (sal_obj == NULL)
17579 + PyErr_SetString (PyExc_MemoryError,
17580 + "Could not allocate Symtab_and_line object.");
17586 + symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab);
17587 + if (symtab_obj == NULL)
17589 + Py_DECREF (sal_obj);
17593 + symtab_obj->symtab = sal.symtab;
17597 + symtab_obj = (symtab_object *) Py_None;
17598 + Py_INCREF (Py_None);
17601 + sal_obj->sal = (struct symtab_and_line *)
17602 + xmalloc (sizeof (struct symtab_and_line));
17603 + *(sal_obj->sal) = sal;
17604 + sal_obj->symtab = symtab_obj;
17606 + return (PyObject *) sal_obj;
17610 +symtab_to_symtab_object (struct symtab *symtab)
17612 + symtab_object *symtab_obj;
17614 + symtab_obj = PyObject_New (symtab_object, &symtab_object_type);
17615 + if (symtab_obj == NULL)
17617 + PyErr_SetString (PyExc_MemoryError,
17618 + "Could not allocate Symtab object.");
17623 + symtab_obj->symtab = symtab;
17625 + return (PyObject *) symtab_obj;
17629 +gdbpy_initialize_symtabs (void)
17631 + symtab_object_type.tp_new = PyType_GenericNew;
17632 + if (PyType_Ready (&symtab_object_type) < 0)
17635 + sal_object_type.tp_new = PyType_GenericNew;
17636 + if (PyType_Ready (&sal_object_type) < 0)
17639 + Py_INCREF (&symtab_object_type);
17640 + PyModule_AddObject (gdb_module, "Symtab", (PyObject *) &symtab_object_type);
17642 + Py_INCREF (&sal_object_type);
17643 + PyModule_AddObject (gdb_module, "Symtab_and_line",
17644 + (PyObject *) &sal_object_type);
17649 +static PyGetSetDef symtab_object_getset[] = {
17650 + { "filename", stpy_get_filename, NULL,
17651 + "The symbol table's source filename.", NULL },
17652 + { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.",
17654 + {NULL} /* Sentinel */
17657 +static PyMethodDef symtab_object_methods[] = {
17658 + { "fullname", stpy_fullname, METH_NOARGS,
17659 + "Return the symtab's full source filename." },
17660 + {NULL} /* Sentinel */
17663 +static PyTypeObject symtab_object_type = {
17664 + PyObject_HEAD_INIT (NULL)
17666 + "gdb.Symtab", /*tp_name*/
17667 + sizeof (symtab_object), /*tp_basicsize*/
17668 + 0, /*tp_itemsize*/
17669 + 0, /*tp_dealloc*/
17671 + 0, /*tp_getattr*/
17672 + 0, /*tp_setattr*/
17673 + 0, /*tp_compare*/
17675 + 0, /*tp_as_number*/
17676 + 0, /*tp_as_sequence*/
17677 + 0, /*tp_as_mapping*/
17680 + stpy_str, /*tp_str*/
17681 + 0, /*tp_getattro*/
17682 + 0, /*tp_setattro*/
17683 + 0, /*tp_as_buffer*/
17684 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
17685 + "GDB symtab object", /* tp_doc */
17686 + 0, /* tp_traverse */
17687 + 0, /* tp_clear */
17688 + 0, /* tp_richcompare */
17689 + 0, /* tp_weaklistoffset */
17691 + 0, /* tp_iternext */
17692 + symtab_object_methods, /* tp_methods */
17693 + 0, /* tp_members */
17694 + symtab_object_getset /* tp_getset */
17697 +static PyGetSetDef sal_object_getset[] = {
17698 + { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
17699 + { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
17700 + { "line", salpy_get_line, NULL,
17701 + "Return the symtab_and_line's line.", NULL },
17702 + {NULL} /* Sentinel */
17705 +static PyTypeObject sal_object_type = {
17706 + PyObject_HEAD_INIT (NULL)
17708 + "gdb.Symtab_and_line", /*tp_name*/
17709 + sizeof (sal_object), /*tp_basicsize*/
17710 + 0, /*tp_itemsize*/
17711 + salpy_dealloc, /*tp_dealloc*/
17713 + 0, /*tp_getattr*/
17714 + 0, /*tp_setattr*/
17715 + 0, /*tp_compare*/
17717 + 0, /*tp_as_number*/
17718 + 0, /*tp_as_sequence*/
17719 + 0, /*tp_as_mapping*/
17722 + salpy_str, /*tp_str*/
17723 + 0, /*tp_getattro*/
17724 + 0, /*tp_setattro*/
17725 + 0, /*tp_as_buffer*/
17726 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
17727 + "GDB symtab_and_line object", /* tp_doc */
17728 + 0, /* tp_traverse */
17729 + 0, /* tp_clear */
17730 + 0, /* tp_richcompare */
17731 + 0, /* tp_weaklistoffset */
17733 + 0, /* tp_iternext */
17734 + 0, /* tp_methods */
17735 + 0, /* tp_members */
17736 + sal_object_getset /* tp_getset */
17738 diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
17739 index 590d90a..f512248 100644
17740 --- a/gdb/python/py-type.c
17741 +++ b/gdb/python/py-type.c
17743 #include "demangle.h"
17744 #include "objfiles.h"
17745 #include "language.h"
17746 +#include "observer.h"
17747 +#include "gdb_assert.h"
17749 typedef struct pyty_type_object
17751 @@ -35,11 +37,17 @@ typedef struct pyty_type_object
17753 /* If a Type object is associated with an objfile, it is kept on a
17754 doubly-linked list, rooted in the objfile. This lets us copy the
17755 - underlying struct type when the objfile is deleted. */
17756 + underlying struct type when the objfile is deleted.
17758 + With NULL objfile Type still can be doubly-linked in the list
17759 + PYTY_OBJECTS_DISCARDABLE. */
17760 struct pyty_type_object *prev;
17761 struct pyty_type_object *next;
17764 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types. */
17765 +static type_object *pyty_objects_discardable;
17767 static PyTypeObject type_object_type;
17769 /* A Field object. */
17770 @@ -169,6 +177,11 @@ convert_field (struct type *type, int field)
17771 if (PyObject_SetAttrString (result, "artificial", arg) < 0)
17774 + arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False;
17776 + if (PyObject_SetAttrString (result, "is_base_class", arg) < 0)
17779 arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
17782 @@ -361,7 +374,7 @@ typy_get_sizeof (PyObject *self, void *closure)
17785 static struct type *
17786 -typy_lookup_typename (char *type_name)
17787 +typy_lookup_typename (char *type_name, struct block *block)
17789 struct type *type = NULL;
17790 volatile struct gdb_exception except;
17791 @@ -375,7 +388,7 @@ typy_lookup_typename (char *type_name)
17792 type = lookup_enum (type_name + 5, NULL);
17794 type = lookup_typename (python_language, python_gdbarch,
17795 - type_name, NULL, 0);
17796 + type_name, block, 0);
17798 if (except.reason < 0)
17800 @@ -389,7 +402,8 @@ typy_lookup_typename (char *type_name)
17803 static struct type *
17804 -typy_lookup_type (struct demangle_component *demangled)
17805 +typy_lookup_type (struct demangle_component *demangled,
17806 + struct block *block)
17810 @@ -404,7 +418,7 @@ typy_lookup_type (struct demangle_component *demangled)
17811 || demangled_type == DEMANGLE_COMPONENT_CONST
17812 || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
17814 - type = typy_lookup_type (demangled->u.s_binary.left);
17815 + type = typy_lookup_type (demangled->u.s_binary.left, block);
17819 @@ -422,7 +436,7 @@ typy_lookup_type (struct demangle_component *demangled)
17822 type_name = cp_comp_to_string (demangled, 10);
17823 - type = typy_lookup_typename (type_name);
17824 + type = typy_lookup_typename (type_name, block);
17828 @@ -436,10 +450,23 @@ typy_template_argument (PyObject *self, PyObject *args)
17829 struct demangle_component *demangled;
17831 struct type *argtype;
17832 + struct block *block = NULL;
17833 + PyObject *block_obj = NULL;
17835 - if (! PyArg_ParseTuple (args, "i", &argno))
17836 + if (! PyArg_ParseTuple (args, "i|O", &argno, &block_obj))
17841 + block = block_object_to_block (block_obj);
17844 + PyErr_SetString (PyExc_RuntimeError,
17845 + "second argument must be block");
17850 type = check_typedef (type);
17851 if (TYPE_CODE (type) == TYPE_CODE_REF)
17852 type = check_typedef (TYPE_TARGET_TYPE (type));
17853 @@ -482,7 +509,7 @@ typy_template_argument (PyObject *self, PyObject *args)
17857 - argtype = typy_lookup_type (demangled->u.s_binary.left);
17858 + argtype = typy_lookup_type (demangled->u.s_binary.left, block);
17862 @@ -524,8 +551,59 @@ typy_str (PyObject *self)
17866 +/* Key associated with each objfile pointing to the first element of
17867 + a doubly-linked list of Types associated with this objfile. */
17868 static const struct objfile_data *typy_objfile_data_key;
17870 +/* Link TYPE_OBJ to its appropriate list. Either to its objfile associated one
17871 + or at least to the global list for TYPE_DISCARDABLE Types. Permanent types
17872 + do not get linked anywhere. */
17874 +typy_link (type_object *type_obj)
17876 + type_obj->prev = NULL;
17878 + if (type_obj->type && TYPE_OBJFILE (type_obj->type))
17880 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
17882 + type_obj->next = objfile_data (objfile, typy_objfile_data_key);
17883 + if (type_obj->next)
17884 + type_obj->next->prev = type_obj;
17885 + set_objfile_data (objfile, typy_objfile_data_key, type_obj);
17887 + else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
17889 + type_obj->next = pyty_objects_discardable;
17890 + if (type_obj->next)
17891 + type_obj->next->prev = type_obj;
17892 + pyty_objects_discardable = type_obj;
17895 + type_obj->next = NULL;
17898 +/* Unlink TYPE_OBJ from its current list. Permanent types are not linked
17899 + anywhere and this function has no effect on them. */
17901 +typy_unlink (type_object *type_obj)
17903 + if (type_obj->prev)
17904 + type_obj->prev->next = type_obj->next;
17905 + else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
17907 + /* Must reset head of list. */
17908 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
17910 + set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
17912 + else if (pyty_objects_discardable == type_obj)
17913 + pyty_objects_discardable = type_obj->next;
17915 + if (type_obj->next)
17916 + type_obj->next->prev = type_obj->prev;
17920 save_objfile_types (struct objfile *objfile, void *datum)
17922 @@ -543,12 +621,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
17924 type_object *next = obj->next;
17926 - htab_empty (copied_types);
17927 + gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
17928 + typy_unlink (obj);
17930 - obj->type = copy_type_recursive (objfile, obj->type, copied_types);
17931 + obj->type = copy_type_recursive (obj->type, copied_types);
17933 - obj->next = NULL;
17934 - obj->prev = NULL;
17935 + gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
17940 @@ -559,41 +638,25 @@ save_objfile_types (struct objfile *objfile, void *datum)
17944 -set_type (type_object *obj, struct type *type)
17945 +typy_dealloc (PyObject *obj)
17947 - obj->type = type;
17948 - obj->prev = NULL;
17949 - if (type && TYPE_OBJFILE (type))
17951 - struct objfile *objfile = TYPE_OBJFILE (type);
17952 + type_object *type_obj = (type_object *) obj;
17954 - obj->next = objfile_data (objfile, typy_objfile_data_key);
17956 - obj->next->prev = obj;
17957 - set_objfile_data (objfile, typy_objfile_data_key, obj);
17960 - obj->next = NULL;
17961 + typy_unlink (type_obj);
17963 + type_obj->ob_type->tp_free (obj);
17966 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
17968 -typy_dealloc (PyObject *obj)
17969 +typy_types_mark_used (void)
17971 - type_object *type = (type_object *) obj;
17974 - type->prev->next = type->next;
17975 - else if (type->type && TYPE_OBJFILE (type->type))
17977 - /* Must reset head of list. */
17978 - struct objfile *objfile = TYPE_OBJFILE (type->type);
17980 - set_objfile_data (objfile, typy_objfile_data_key, type->next);
17983 - type->next->prev = type->prev;
17984 + type_object *type_obj;
17986 - type->ob_type->tp_free (type);
17987 + for (type_obj = pyty_objects_discardable;
17988 + type_obj != NULL;
17989 + type_obj = type_obj->next)
17990 + type_mark_used (type_obj->type);
17993 /* Create a new Type referring to TYPE. */
17994 @@ -604,7 +667,10 @@ type_to_type_object (struct type *type)
17996 type_obj = PyObject_New (type_object, &type_object_type);
17998 - set_type (type_obj, type);
18000 + type_obj->type = type;
18001 + typy_link (type_obj);
18004 return (PyObject *) type_obj;
18006 @@ -623,14 +689,28 @@ type_object_to_type (PyObject *obj)
18008 gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
18010 - static char *keywords[] = { "name", NULL };
18011 + static char *keywords[] = { "name", "block", NULL };
18012 char *type_name = NULL;
18013 struct type *type = NULL;
18014 + PyObject *block_obj = NULL;
18015 + struct block *block = NULL;
18017 - if (! PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &type_name))
18018 + if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
18019 + &type_name, &block_obj))
18022 - type = typy_lookup_typename (type_name);
18025 + block = block_object_to_block (block_obj);
18028 + PyErr_SetString (PyExc_RuntimeError,
18029 + "'block' argument must be a Block");
18034 + type = typy_lookup_typename (type_name, block);
18038 @@ -664,6 +744,8 @@ gdbpy_initialize_types (void)
18040 Py_INCREF (&field_object_type);
18041 PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
18043 + observer_attach_mark_used (typy_types_mark_used);
18047 diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
18048 index 49c0437..84a476e 100644
18049 --- a/gdb/python/py-utils.c
18050 +++ b/gdb/python/py-utils.c
18054 #include "charset.h"
18055 +#include "value.h"
18056 #include "python-internal.h"
18059 @@ -219,3 +220,48 @@ gdbpy_is_string (PyObject *obj)
18061 return PyString_Check (obj) || PyUnicode_Check (obj);
18064 +/* Converts OBJ to a CORE_ADDR value.
18066 + Returns 1 on success or 0 on failure, with a Python exception set. This
18067 + function can also throw GDB exceptions. */
18070 +get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
18072 + if (gdbpy_is_value_object (obj))
18073 + *addr = value_as_address (value_object_to_value (obj));
18074 + else if (PyLong_Check (obj))
18076 + /* Assume CORE_ADDR corresponds to unsigned long. */
18077 + *addr = PyLong_AsUnsignedLong (obj);
18078 + if (PyErr_Occurred () != NULL)
18081 + else if (PyInt_Check (obj))
18085 + /* Assume CORE_ADDR corresponds to unsigned long. */
18086 + val = PyInt_AsLong (obj);
18092 + /* If no error ocurred, VAL is indeed negative. */
18093 + if (PyErr_Occurred () != NULL)
18096 + PyErr_SetString (PyExc_ValueError, "negative address");
18102 + PyErr_SetString (PyExc_TypeError, "invalid type for address");
18108 diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
18109 index 0146593..b82fcb6 100644
18110 --- a/gdb/python/py-value.c
18111 +++ b/gdb/python/py-value.c
18113 #include "language.h"
18115 #include "valprint.h"
18116 +#include "observer.h"
18121 /* Python's long type corresponds to C's long long type. */
18122 #define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
18124 +/* Python's long type corresponds to C's long long type. Unsigned version. */
18125 +#define builtin_type_upylong builtin_type \
18126 + (python_gdbarch)->builtin_unsigned_long_long
18128 #define builtin_type_pybool \
18129 language_bool_type (python_language, python_gdbarch)
18131 @@ -913,7 +918,34 @@ convert_value_from_python (PyObject *obj)
18133 LONGEST l = PyLong_AsLongLong (obj);
18135 - if (! PyErr_Occurred ())
18136 + if (PyErr_Occurred ())
18138 + /* If the error was an overflow, we can try converting to
18139 + ULONGEST instead. */
18140 + if (PyErr_ExceptionMatches (PyExc_OverflowError))
18142 + PyObject *etype, *evalue, *etraceback, *zero;
18144 + PyErr_Fetch (&etype, &evalue, &etraceback);
18145 + zero = PyInt_FromLong (0);
18147 + /* Check whether obj is positive. */
18148 + if (PyObject_RichCompareBool (obj, zero, Py_GT) > 0)
18152 + ul = PyLong_AsUnsignedLongLong (obj);
18153 + if (! PyErr_Occurred ())
18154 + value = value_from_ulongest (builtin_type_upylong, ul);
18157 + /* There's nothing we can do. */
18158 + PyErr_Restore (etype, evalue, etraceback);
18160 + Py_DECREF (zero);
18164 value = value_from_longest (builtin_type_pylong, l);
18166 else if (PyFloat_Check (obj))
18167 @@ -972,6 +1004,25 @@ gdbpy_history (PyObject *self, PyObject *args)
18168 return value_to_value_object (res_val);
18171 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
18174 +python_types_mark_used (void)
18176 + value_object *iter;
18178 + for (iter = values_in_python; iter; iter = iter->next)
18179 + type_mark_used (value_type (iter->value));
18182 +/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise. */
18185 +gdbpy_is_value_object (PyObject *obj)
18187 + return PyObject_TypeCheck (obj, &value_object_type);
18191 gdbpy_initialize_values (void)
18193 @@ -982,6 +1033,8 @@ gdbpy_initialize_values (void)
18194 PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
18196 values_in_python = NULL;
18198 + observer_attach_mark_used (python_types_mark_used);
18202 diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
18203 index 67a78af..47662d9 100644
18204 --- a/gdb/python/python-internal.h
18205 +++ b/gdb/python/python-internal.h
18206 @@ -61,33 +61,76 @@ typedef int Py_ssize_t;
18207 #define PyEval_ReleaseLock() 0
18210 +#include "command.h"
18214 +struct symtab_and_line;
18216 struct language_defn;
18218 extern PyObject *gdb_module;
18219 +extern PyTypeObject block_object_type;
18220 extern PyTypeObject value_object_type;
18221 +extern PyTypeObject symbol_object_type;
18223 +/* Used in python-inferior.c. */
18228 + /* The thread we represent. */
18229 + struct thread_info *thread;
18231 + /* The Inferior object to which this thread belongs. */
18232 + PyObject *inf_obj;
18235 PyObject *gdbpy_history (PyObject *self, PyObject *args);
18236 +PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
18237 PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
18238 +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
18239 PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
18240 +PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
18241 PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
18242 +PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
18243 +PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
18245 +PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
18246 +PyObject *symtab_to_symtab_object (struct symtab *symtab);
18247 +PyObject *symbol_to_symbol_object (struct symbol *sym);
18248 +PyObject *block_to_block_object (struct block *block);
18249 PyObject *value_to_value_object (struct value *v);
18250 PyObject *type_to_type_object (struct type *);
18251 PyObject *objfile_to_objfile_object (struct objfile *);
18252 +PyObject *frame_info_to_frame_object (struct frame_info *frame);
18253 +thread_object *create_thread_object (struct thread_info *tp);
18254 +thread_object *find_thread_object (ptid_t ptid);
18255 +PyObject *find_inferior_object (int pid);
18257 PyObject *objfpy_get_printers (PyObject *, void *);
18259 +struct block *block_object_to_block (PyObject *obj);
18260 +struct symbol *symbol_object_to_symbol (PyObject *obj);
18261 struct value *value_object_to_value (PyObject *self);
18262 struct value *convert_value_from_python (PyObject *obj);
18263 struct type *type_object_to_type (PyObject *obj);
18265 +PyObject *gdbpy_get_hook_function (const char *);
18267 void gdbpy_initialize_values (void);
18268 +void gdbpy_initialize_breakpoints (void);
18269 void gdbpy_initialize_frames (void);
18270 +void gdbpy_initialize_symtabs (void);
18271 void gdbpy_initialize_commands (void);
18272 +void gdbpy_initialize_symbols (void);
18273 void gdbpy_initialize_types (void);
18274 +void gdbpy_initialize_blocks (void);
18275 void gdbpy_initialize_functions (void);
18276 void gdbpy_initialize_objfile (void);
18277 +void gdbpy_initialize_parameters (void);
18278 +void gdbpy_initialize_thread (void);
18279 +void gdbpy_initialize_inferior (void);
18281 struct cleanup *make_cleanup_py_decref (PyObject *py);
18283 @@ -97,6 +140,12 @@ struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
18284 extern struct gdbarch *python_gdbarch;
18285 extern const struct language_defn *python_language;
18287 +char *gdbpy_parse_command_name (char *text,
18288 + struct cmd_list_element ***base_list,
18289 + struct cmd_list_element **start_list);
18291 +PyObject *gdbpy_parameter_value (enum var_types, void *);
18293 /* Use this after a TRY_EXCEPT to throw the appropriate Python
18295 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
18296 @@ -107,6 +156,19 @@ extern const struct language_defn *python_language;
18297 "%s", Exception.message); \
18300 +/* Use this after a TRY_EXCEPT to throw the appropriate Python
18301 + exception. This macro is for use inside setter functions. */
18302 +#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
18304 + if (Exception.reason < 0) \
18306 + PyErr_Format (Exception.reason == RETURN_QUIT \
18307 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
18308 + "%s", Exception.message); \
18314 void gdbpy_print_stack (void);
18316 @@ -118,17 +180,22 @@ char *python_string_to_host_string (PyObject *obj);
18317 PyObject *target_string_to_unicode (const gdb_byte *str, int length);
18318 int gdbpy_is_string (PyObject *obj);
18320 +int gdbpy_is_value_object (PyObject *obj);
18322 /* Note that these are declared here, and not in python.h with the
18323 other pretty-printer functions, because they refer to PyObject. */
18324 PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
18325 struct value **replacement);
18326 PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
18327 +PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
18328 char *gdbpy_get_display_hint (PyObject *printer);
18329 PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
18331 -extern PyObject *gdbpy_doc_cst;
18332 extern PyObject *gdbpy_children_cst;
18333 extern PyObject *gdbpy_to_string_cst;
18334 extern PyObject *gdbpy_display_hint_cst;
18335 +extern PyObject *gdbpy_doc_cst;
18337 +int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
18339 #endif /* GDB_PYTHON_INTERNAL_H */
18340 diff --git a/gdb/python/python.c b/gdb/python/python.c
18341 index 254bd28..5a2a9ae 100644
18342 --- a/gdb/python/python.c
18343 +++ b/gdb/python/python.c
18345 #include "observer.h"
18347 #include "language.h"
18348 +#include "event-loop.h"
18352 @@ -45,11 +46,18 @@ static int gdbpy_auto_load = 1;
18353 #include "cli/cli-decode.h"
18354 #include "charset.h"
18356 +#include "solib.h"
18357 #include "exceptions.h"
18358 #include "python-internal.h"
18359 +#include "linespec.h"
18360 +#include "symtab.h"
18361 +#include "source.h"
18362 #include "version.h"
18363 +#include "inferior.h"
18364 +#include "gdbthread.h"
18365 #include "target.h"
18366 #include "gdbthread.h"
18367 +#include "event-top.h"
18369 static PyMethodDef GdbMethods[];
18371 @@ -197,10 +205,10 @@ python_command (char *arg, int from_tty)
18372 NULL (and set a Python exception) on error. Helper function for
18376 -parameter_to_python (struct cmd_list_element *cmd)
18378 +gdbpy_parameter_value (enum var_types type, void *var)
18380 - switch (cmd->var_type)
18384 case var_string_noescape:
18385 @@ -208,7 +216,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18389 - char *str = * (char **) cmd->var;
18390 + char *str = * (char **) var;
18393 return PyString_Decode (str, strlen (str), host_charset (), NULL);
18394 @@ -216,7 +224,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18398 - if (* (int *) cmd->var)
18399 + if (* (int *) var)
18403 @@ -224,7 +232,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18405 case var_auto_boolean:
18407 - enum auto_boolean ab = * (enum auto_boolean *) cmd->var;
18408 + enum auto_boolean ab = * (enum auto_boolean *) var;
18409 if (ab == AUTO_BOOLEAN_TRUE)
18411 else if (ab == AUTO_BOOLEAN_FALSE)
18412 @@ -234,15 +242,15 @@ parameter_to_python (struct cmd_list_element *cmd)
18416 - if ((* (int *) cmd->var) == INT_MAX)
18417 + if ((* (int *) var) == INT_MAX)
18419 /* Fall through. */
18421 - return PyLong_FromLong (* (int *) cmd->var);
18422 + return PyLong_FromLong (* (int *) var);
18426 - unsigned int val = * (unsigned int *) cmd->var;
18427 + unsigned int val = * (unsigned int *) var;
18428 if (val == UINT_MAX)
18430 return PyLong_FromUnsignedLong (val);
18431 @@ -280,7 +288,7 @@ gdbpy_parameter (PyObject *self, PyObject *args)
18434 return PyErr_Format (PyExc_RuntimeError, "`%s' is not a parameter", arg);
18435 - return parameter_to_python (cmd);
18436 + return gdbpy_parameter_value (cmd->var_type, cmd->var);
18439 /* A Python function which evaluates a string using the gdb CLI. */
18440 @@ -319,6 +327,233 @@ execute_gdb_command (PyObject *self, PyObject *args)
18444 +/* Implementation of gdb.solib_address (Long) -> String.
18445 + Returns the name of the shared library holding a given address, or None. */
18448 +gdbpy_solib_address (PyObject *self, PyObject *args)
18450 + unsigned long long pc;
18452 + PyObject *str_obj;
18454 + if (!PyArg_ParseTuple (args, "K", &pc))
18457 + soname = solib_name_from_address (pc);
18459 + str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
18462 + str_obj = Py_None;
18463 + Py_INCREF (Py_None);
18469 +/* A Python function which is a wrapper for decode_line_1. */
18472 +gdbpy_decode_line (PyObject *self, PyObject *args)
18474 + struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc. */
18475 + struct symtab_and_line sal;
18476 + char *arg = NULL;
18477 + int free_sals = 0, i;
18478 + PyObject *result = NULL;
18479 + volatile struct gdb_exception except;
18481 + if (! PyArg_ParseTuple (args, "|s", &arg))
18484 + TRY_CATCH (except, RETURN_MASK_ALL)
18490 + arg = strdup (arg);
18493 + sals = decode_line_1 (©, 0, 0, 0, 0, 0);
18498 + set_default_source_symtab_and_line ();
18499 + sal = get_current_source_symtab_and_line ();
18500 + sals.sals = &sal;
18507 + if (except.reason < 0)
18510 + xfree (sals.sals);
18511 + /* We know this will always throw. */
18512 + GDB_PY_HANDLE_EXCEPTION (except);
18517 + result = PyTuple_New (sals.nelts);
18518 + for (i = 0; i < sals.nelts; ++i)
18523 + obj = symtab_and_line_to_sal_object (sals.sals[i]);
18526 + Py_DECREF (result);
18531 + PyTuple_SetItem (result, i, obj);
18536 + xfree (sals.sals);
18543 +/* Parse a string and evaluate it as an expression. */
18545 +gdbpy_parse_and_eval (PyObject *self, PyObject *args)
18548 + struct value *result = NULL;
18549 + volatile struct gdb_exception except;
18551 + if (!PyArg_ParseTuple (args, "s", &expr_str))
18554 + TRY_CATCH (except, RETURN_MASK_ALL)
18556 + result = parse_and_eval (expr_str);
18558 + GDB_PY_HANDLE_EXCEPTION (except);
18560 + return value_to_value_object (result);
18565 +/* Posting and handling events. */
18567 +/* A single event. */
18568 +struct gdbpy_event
18570 + /* The Python event. This is just a callable object. */
18572 + /* The next event. */
18573 + struct gdbpy_event *next;
18576 +/* All pending events. */
18577 +static struct gdbpy_event *gdbpy_event_list;
18578 +/* The final link of the event list. */
18579 +static struct gdbpy_event **gdbpy_event_list_end;
18581 +/* We use a file handler, and not an async handler, so that we can
18582 + wake up the main thread even when it is blocked in poll(). */
18583 +static int gdbpy_event_fds[2];
18585 +/* The file handler callback. This reads from the internal pipe, and
18586 + then processes the Python event queue. This will always be run in
18587 + the main gdb thread. */
18589 +gdbpy_run_events (int err, gdb_client_data ignore)
18591 + PyGILState_STATE state;
18592 + char buffer[100];
18595 + state = PyGILState_Ensure ();
18597 + /* Just read whatever is available on the fd. It is relatively
18598 + harmless if there are any bytes left over. */
18599 + r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
18601 + while (gdbpy_event_list)
18603 + /* Dispatching the event might push a new element onto the event
18604 + loop, so we update here "atomically enough". */
18605 + struct gdbpy_event *item = gdbpy_event_list;
18606 + gdbpy_event_list = gdbpy_event_list->next;
18607 + if (gdbpy_event_list == NULL)
18608 + gdbpy_event_list_end = &gdbpy_event_list;
18610 + /* Ignore errors. */
18611 + PyObject_CallObject (item->event, NULL);
18613 + Py_DECREF (item->event);
18617 + PyGILState_Release (state);
18620 +/* Submit an event to the gdb thread. */
18622 +gdbpy_post_event (PyObject *self, PyObject *args)
18624 + struct gdbpy_event *event;
18628 + if (!PyArg_ParseTuple (args, "O", &func))
18631 + if (!PyCallable_Check (func))
18633 + PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
18637 + Py_INCREF (func);
18639 + /* From here until the end of the function, we have the GIL, so we
18640 + can operate on our global data structures without worrying. */
18641 + wakeup = gdbpy_event_list == NULL;
18643 + event = XNEW (struct gdbpy_event);
18644 + event->event = func;
18645 + event->next = NULL;
18646 + *gdbpy_event_list_end = event;
18647 + gdbpy_event_list_end = &event->next;
18649 + /* Wake up gdb when needed. */
18652 + char c = 'q'; /* Anything. */
18653 + if (write (gdbpy_event_fds[1], &c, 1) != 1)
18654 + return PyErr_SetFromErrno (PyExc_IOError);
18660 +/* Initialize the Python event handler. */
18662 +gdbpy_initialize_events (void)
18664 + if (!pipe (gdbpy_event_fds))
18666 + gdbpy_event_list_end = &gdbpy_event_list;
18667 + add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
18674 @@ -357,6 +592,69 @@ gdbpy_print_stack (void)
18678 +/* Script interface. */
18680 +/* True if 'gdb -P' was used, false otherwise. */
18681 +static int running_python_script;
18683 +/* True if we are currently in a call to 'gdb.cli', false otherwise. */
18684 +static int in_cli;
18686 +/* Enter the command loop. */
18689 +gdbpy_cli (PyObject *unused1, PyObject *unused2)
18691 + if (! running_python_script || in_cli)
18692 + return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
18695 + cli_command_loop ();
18701 +/* Set up the Python argument vector and evaluate a script. This is
18702 + used to implement 'gdb -P'. */
18705 +run_python_script (int argc, char **argv)
18708 + PyGILState_STATE state;
18710 + /* We never free this, since we plan to exit at the end. */
18711 + state = PyGILState_Ensure ();
18713 + running_python_script = 1;
18714 + PySys_SetArgv (argc - 1, argv + 1);
18715 + input = fopen (argv[0], "r");
18718 + fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
18721 + PyRun_SimpleFile (input, argv[0]);
18727 +source_python_script (FILE *stream, char *file)
18729 + PyGILState_STATE state;
18731 + state = PyGILState_Ensure ();
18733 + PyRun_SimpleFile (stream, file);
18736 + PyGILState_Release (state);
18741 /* The "current" objfile. This is set when gdb detects that a new
18742 objfile has been loaded. It is only set for the duration of a call
18743 to gdbpy_new_objfile; it is NULL at other times. */
18744 @@ -501,6 +799,13 @@ eval_python_from_control_command (struct command_line *cmd)
18745 error (_("Python scripting is not supported in this copy of GDB."));
18749 +source_python_script (FILE *stream)
18752 + error (_("Python scripting is not supported in this copy of GDB."));
18755 #endif /* HAVE_PYTHON */
18758 @@ -592,13 +897,27 @@ Enables or disables auto-loading of Python code when an object is opened."),
18759 PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
18760 PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
18761 PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
18763 + PyModule_AddStringConstant (gdb_module, "pythondir", PYTHONDIR);
18766 + PyModule_AddStringConstant (gdb_module, "datadir", gdb_datadir);
18769 gdbpy_initialize_values ();
18770 + gdbpy_initialize_breakpoints ();
18771 gdbpy_initialize_frames ();
18772 + gdbpy_initialize_symtabs ();
18773 gdbpy_initialize_commands ();
18774 + gdbpy_initialize_symbols ();
18775 + gdbpy_initialize_blocks ();
18776 gdbpy_initialize_functions ();
18777 gdbpy_initialize_types ();
18778 + gdbpy_initialize_parameters ();
18779 gdbpy_initialize_objfile ();
18780 + gdbpy_initialize_thread ();
18781 + gdbpy_initialize_inferior ();
18782 + gdbpy_initialize_events ();
18784 PyRun_SimpleString ("import gdb");
18785 PyRun_SimpleString ("gdb.pretty_printers = []");
18786 @@ -634,6 +953,15 @@ class GdbOutputFile:\n\
18788 sys.stderr = GdbOutputFile()\n\
18789 sys.stdout = GdbOutputFile()\n\
18790 +if hasattr (gdb, 'datadir'):\n\
18791 + gdb.pythondir = gdb.datadir + '/python'\n\
18792 +if hasattr (gdb, 'pythondir'):\n\
18793 + sys.path.insert(0, gdb.pythondir)\n\
18794 + gdb.__path__ = [gdb.pythondir + '/gdb']\n\
18795 + from os.path import exists\n\
18796 + ipy = gdb.pythondir + '/gdb/__init__.py'\n\
18797 + if exists (ipy):\n\
18798 + execfile (ipy)\n\
18801 /* Release the GIL while gdb runs. */
18802 @@ -653,9 +981,14 @@ static PyMethodDef GdbMethods[] =
18803 "Get a value from history" },
18804 { "execute", execute_gdb_command, METH_VARARGS,
18805 "Execute a gdb command" },
18806 + { "cli", gdbpy_cli, METH_NOARGS,
18807 + "Enter the gdb CLI" },
18808 { "parameter", gdbpy_parameter, METH_VARARGS,
18809 "Return a gdb parameter's value" },
18811 + { "breakpoints", gdbpy_breakpoints, METH_NOARGS,
18812 + "Return a tuple of all breakpoint objects" },
18814 { "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
18815 "Find the default visualizer for a Value." },
18817 @@ -676,6 +1009,37 @@ Return a string explaining unwind stop reason." },
18818 "lookup_type (name [, block]) -> type\n\
18819 Return a Type corresponding to the given name." },
18821 + { "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
18822 + METH_VARARGS | METH_KEYWORDS,
18823 + "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
18824 +Return a tuple with the symbol corresponding to the given name (or None) and\n\
18825 +a boolean indicating if name is a field of the current implied argument\n\
18826 +`this' (when the current language is object-oriented)." },
18827 + { "solib_address", gdbpy_solib_address, METH_VARARGS,
18828 + "solib_address (Long) -> String.\n\
18829 +Return the name of the shared library holding a given address, or None." },
18831 + { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
18832 + "Return the block containing the given pc value, or None." },
18834 + { "decode_line", gdbpy_decode_line, METH_VARARGS,
18835 + "Decode a string argument the way that 'break' or 'edit' does.\n\
18836 +Return a tuple holding the file name (or None) and line number (or None).\n\
18837 +Note: may later change to return an object." },
18839 + { "selected_thread", gdbpy_selected_thread, METH_NOARGS,
18840 + "selected_thread () -> gdb.InferiorThread.\n\
18841 +Return the selected thread object." },
18842 + { "inferiors", gdbpy_inferiors, METH_NOARGS,
18843 + "inferiors () -> (gdb.Inferior, ...).\n\
18844 +Return a tuple containing all inferiors." },
18846 + { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
18847 + "Parse a string as an expression, evaluate it, and return the result." },
18849 + { "post_event", gdbpy_post_event, METH_VARARGS,
18850 + "Post an event into gdb's event loop." },
18852 { "write", gdbpy_write, METH_VARARGS,
18853 "Write a string using gdb's filtered stream." },
18854 { "flush", gdbpy_flush, METH_NOARGS,
18855 diff --git a/gdb/python/python.h b/gdb/python/python.h
18856 index e970180..bbb6184 100644
18857 --- a/gdb/python/python.h
18858 +++ b/gdb/python/python.h
18861 void eval_python_from_control_command (struct command_line *);
18863 +void source_python_script (FILE *stream, char *file);
18865 +void run_python_script (int argc, char **argv);
18867 int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
18868 int embedded_offset, CORE_ADDR address,
18869 struct ui_file *stream, int recurse,
18870 diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c
18871 index de34894..07518b0 100644
18872 --- a/gdb/scm-lang.c
18873 +++ b/gdb/scm-lang.c
18874 @@ -233,6 +233,7 @@ const struct exp_descriptor exp_descriptor_scm =
18876 print_subexp_standard,
18877 operator_length_standard,
18878 + operator_check_standard,
18880 dump_subexp_body_standard,
18882 diff --git a/gdb/scm-valprint.c b/gdb/scm-valprint.c
18883 index cc3319a..d0d4702 100644
18884 --- a/gdb/scm-valprint.c
18885 +++ b/gdb/scm-valprint.c
18886 @@ -62,9 +62,9 @@ scm_inferior_print (struct type *type, LONGEST value, struct ui_file *stream,
18888 /* XXX: Should we cache these symbols? */
18890 - lookup_symbol_global ("gdb_output", NULL, NULL, VAR_DOMAIN);
18891 + lookup_symbol_global ("gdb_output", NULL, VAR_DOMAIN);
18892 gdb_output_len_sym =
18893 - lookup_symbol_global ("gdb_output_length", NULL, NULL, VAR_DOMAIN);
18894 + lookup_symbol_global ("gdb_output_length", NULL, VAR_DOMAIN);
18896 if ((gdb_output_sym == NULL) || (gdb_output_len_sym == NULL))
18898 diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
18899 index 8b96a6f..9428d92 100644
18900 --- a/gdb/solib-darwin.c
18901 +++ b/gdb/solib-darwin.c
18902 @@ -389,7 +389,6 @@ darwin_relocate_section_addresses (struct so_list *so,
18903 static struct symbol *
18904 darwin_lookup_lib_symbol (const struct objfile *objfile,
18906 - const char *linkage_name,
18907 const domain_enum domain)
18910 diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
18911 index 19e3212..9f06fa9 100644
18912 --- a/gdb/solib-spu.c
18913 +++ b/gdb/solib-spu.c
18914 @@ -334,16 +334,13 @@ spu_bfd_open (char *pathname)
18915 static struct symbol *
18916 spu_lookup_lib_symbol (const struct objfile *objfile,
18918 - const char *linkage_name,
18919 const domain_enum domain)
18921 if (bfd_get_arch (objfile->obfd) == bfd_arch_spu)
18922 - return lookup_global_symbol_from_objfile (objfile, name, linkage_name,
18924 + return lookup_global_symbol_from_objfile (objfile, name, domain);
18926 if (svr4_so_ops.lookup_lib_global_symbol != NULL)
18927 - return svr4_so_ops.lookup_lib_global_symbol (objfile, name, linkage_name,
18929 + return svr4_so_ops.lookup_lib_global_symbol (objfile, name, domain);
18933 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
18934 index 6cfaa85..68aadc0 100644
18935 --- a/gdb/solib-svr4.c
18936 +++ b/gdb/solib-svr4.c
18937 @@ -1908,15 +1908,13 @@ struct target_so_ops svr4_so_ops;
18938 static struct symbol *
18939 elf_lookup_lib_symbol (const struct objfile *objfile,
18941 - const char *linkage_name,
18942 const domain_enum domain)
18944 if (objfile->obfd == NULL
18945 || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
18948 - return lookup_global_symbol_from_objfile
18949 - (objfile, name, linkage_name, domain);
18950 + return lookup_global_symbol_from_objfile (objfile, name, domain);
18953 extern initialize_file_ftype _initialize_svr4_solib; /* -Wmissing-prototypes */
18954 diff --git a/gdb/solib.c b/gdb/solib.c
18955 index a2ad0c4..3574e62 100644
18958 @@ -1127,13 +1127,12 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
18960 solib_global_lookup (const struct objfile *objfile,
18962 - const char *linkage_name,
18963 const domain_enum domain)
18965 struct target_so_ops *ops = solib_ops (target_gdbarch);
18967 if (ops->lookup_lib_global_symbol != NULL)
18968 - return ops->lookup_lib_global_symbol (objfile, name, linkage_name, domain);
18969 + return ops->lookup_lib_global_symbol (objfile, name, domain);
18973 diff --git a/gdb/solist.h b/gdb/solist.h
18974 index 63a6ba0..005e8f7 100644
18977 @@ -114,7 +114,6 @@ struct target_so_ops
18978 /* Hook for looking up global symbols in a library-specific way. */
18979 struct symbol * (*lookup_lib_global_symbol) (const struct objfile *objfile,
18981 - const char *linkage_name,
18982 const domain_enum domain);
18984 /* Given two so_list objects, one from the GDB thread list
18985 @@ -146,7 +145,6 @@ extern struct target_so_ops *current_target_so_ops;
18986 /* Handler for library-specific global symbol lookup in solib.c. */
18987 struct symbol *solib_global_lookup (const struct objfile *objfile,
18989 - const char *linkage_name,
18990 const domain_enum domain);
18993 diff --git a/gdb/somread.c b/gdb/somread.c
18994 index 36a2b28..4d5bda9 100644
18995 --- a/gdb/somread.c
18996 +++ b/gdb/somread.c
18997 @@ -435,6 +435,7 @@ static struct sym_fns som_sym_fns =
18998 som_new_init, /* sym_new_init: init anything gbl to entire symtab */
18999 som_symfile_init, /* sym_init: read initial info, setup for sym_read() */
19000 som_symfile_read, /* sym_read: read a symbol file into symtab */
19001 + NULL, /* sym_read_psymbols */
19002 som_symfile_finish, /* sym_finish: finished with file, cleanup */
19003 som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
19004 default_symfile_segments, /* sym_segments: Get segment information from
19005 diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
19006 index 7e7ab9c..a014b7a 100644
19007 --- a/gdb/spu-tdep.c
19008 +++ b/gdb/spu-tdep.c
19009 @@ -1839,7 +1839,7 @@ spu_catch_start (struct objfile *objfile)
19010 struct symbol *sym;
19011 struct symtab_and_line sal;
19013 - sym = lookup_block_symbol (block, "main", NULL, VAR_DOMAIN);
19014 + sym = lookup_block_symbol (block, "main", VAR_DOMAIN);
19017 fixup_symbol_section (sym, objfile);
19018 diff --git a/gdb/stabsread.c b/gdb/stabsread.c
19019 index e62bb15..ad6568e 100644
19020 --- a/gdb/stabsread.c
19021 +++ b/gdb/stabsread.c
19022 @@ -322,7 +322,7 @@ dbx_alloc_type (int typenums[2], struct objfile *objfile)
19024 if (typenums[0] == -1)
19026 - return (alloc_type (objfile));
19027 + return (alloc_type (objfile, NULL));
19030 type_addr = dbx_lookup_type (typenums, objfile);
19031 @@ -332,7 +332,7 @@ dbx_alloc_type (int typenums[2], struct objfile *objfile)
19032 We will fill it in later if we find out how. */
19033 if (*type_addr == 0)
19035 - *type_addr = alloc_type (objfile);
19036 + *type_addr = alloc_type (objfile, NULL);
19039 return (*type_addr);
19040 diff --git a/gdb/stack.c b/gdb/stack.c
19041 index 1c37801..594eb16 100644
19044 @@ -1308,24 +1308,24 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
19048 - if (info_verbose)
19050 - struct partial_symtab *ps;
19052 - /* Read in symbols for all of the frames. Need to do this in a
19053 - separate pass so that "Reading in symbols for xxx" messages
19054 - don't screw up the appearance of the backtrace. Also if
19055 - people have strong opinions against reading symbols for
19056 - backtrace this may have to be an option. */
19058 - for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
19061 - ps = find_pc_psymtab (get_frame_address_in_block (fi));
19063 - PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in. */
19067 + struct partial_symtab *ps;
19069 + /* Read in symbols for all of the frames. Need to do this
19070 + unconditionally to ensure that psymbols are read. Also need to
19071 + do this in a separate pass so that "Reading in symbols for xxx"
19072 + messages don't screw up the appearance of the backtrace. Also
19073 + if people have strong opinions against reading symbols for
19074 + backtrace this may have to be an option. */
19076 + for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
19079 + ps = find_pc_psymtab (get_frame_address_in_block (fi));
19080 + if (info_verbose && ps)
19081 + PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in. */
19085 for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
19087 @@ -1473,6 +1473,8 @@ print_block_frame_locals (struct block *b, struct frame_info *frame,
19089 if (SYMBOL_IS_ARGUMENT (sym))
19091 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
19093 values_printed = 1;
19094 print_variable_and_value (NULL, sym, frame, stream, 4 * num_tabs);
19096 diff --git a/gdb/symfile.c b/gdb/symfile.c
19097 index 2458201..c31b72a 100644
19098 --- a/gdb/symfile.c
19099 +++ b/gdb/symfile.c
19100 @@ -921,6 +921,17 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
19101 clear_complaints (&symfile_complaints, 0, add_flags & SYMFILE_VERBOSE);
19104 +/* A helper function which returns true if OBJFILE has any debug
19105 + symbols, and false otherwise. */
19107 +has_any_debug_symbols (struct objfile *objfile)
19109 + return (objfile->psymtabs || objfile->quick_addrmap
19110 + || (objfile->separate_debug_objfile
19111 + && (objfile->separate_debug_objfile->psymtabs
19112 + || objfile->separate_debug_objfile->quick_addrmap)));
19115 /* Process a symbol file, as either the main file or as a dynamically
19118 @@ -958,13 +969,16 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19119 /* Give user a chance to burp if we'd be
19120 interactively wiping out any existing symbols. */
19122 - if ((have_full_symbols () || have_partial_symbols ())
19123 - && (add_flags & SYMFILE_MAINLINE)
19124 + if ((add_flags & SYMFILE_MAINLINE)
19125 + && (have_full_symbols () || have_partial_symbols ())
19127 + && (have_full_symbols () || have_partial_symbols ())
19128 && !query (_("Load new symbol table from \"%s\"? "), name))
19129 error (_("Not confirmed."));
19131 objfile = allocate_objfile (abfd, flags);
19132 + if (add_flags & SYMFILE_MAINLINE)
19133 + objfile->flags |= OBJF_MAIN;
19134 discard_cleanups (my_cleanups);
19137 @@ -997,6 +1011,8 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19139 if ((flags & OBJF_READNOW) || readnow_symbol_files)
19141 + require_partial_symbols (objfile);
19143 if (from_tty || info_verbose)
19145 printf_unfiltered (_("expanding to full symbols..."));
19146 @@ -1015,7 +1031,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19147 /* If the file has its own symbol tables it has no separate debug info.
19148 `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
19149 `.gnu_debuglink' may no longer be present with `.note.gnu.build-id'. */
19150 - if (objfile->psymtabs == NULL)
19151 + if (!has_any_debug_symbols (objfile))
19152 debugfile = find_separate_debug_file (objfile);
19155 @@ -1039,9 +1055,10 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19159 + /* has_any_debug_symbols is not fully compatible with the former calls which
19160 + would just be needlessly expensive here. */
19161 if ((from_tty || info_verbose)
19162 - && !objfile_has_partial_symbols (objfile)
19163 - && !objfile_has_full_symbols (objfile))
19164 + && !has_any_debug_symbols (objfile))
19167 printf_unfiltered (_("(no debugging symbols found)..."));
19168 @@ -2422,14 +2439,15 @@ reread_symbols (void)
19169 zero is OK since dbxread.c also does what it needs to do if
19170 objfile->global_psymbols.size is 0. */
19171 (*objfile->sf->sym_read) (objfile, 0);
19172 - if (!objfile_has_partial_symbols (objfile)
19173 - && !objfile_has_full_symbols (objfile))
19174 + if (!has_any_debug_symbols (objfile))
19177 printf_unfiltered (_("(no debugging symbols found)\n"));
19181 + objfile->flags &= ~OBJF_SYMTABS_READ;
19183 /* We're done reading the symbol file; finish off complaints. */
19184 clear_complaints (&symfile_complaints, 0, 1);
19186 @@ -2727,7 +2745,7 @@ allocate_symtab (char *filename, struct objfile *objfile)
19189 struct partial_symtab *
19190 -allocate_psymtab (char *filename, struct objfile *objfile)
19191 +allocate_psymtab (const char *filename, struct objfile *objfile)
19193 struct partial_symtab *psymtab;
19195 @@ -3041,7 +3059,8 @@ again2:
19197 struct partial_symtab *
19198 start_psymtab_common (struct objfile *objfile,
19199 - struct section_offsets *section_offsets, char *filename,
19200 + struct section_offsets *section_offsets,
19201 + const char *filename,
19202 CORE_ADDR textlow, struct partial_symbol **global_syms,
19203 struct partial_symbol **static_syms)
19205 diff --git a/gdb/symfile.h b/gdb/symfile.h
19206 index 8c9249c..bf9d9e7 100644
19207 --- a/gdb/symfile.h
19208 +++ b/gdb/symfile.h
19209 @@ -140,6 +140,12 @@ struct sym_fns
19211 void (*sym_read) (struct objfile *, int);
19213 + /* Read the partial symbols for an objfile. This may be NULL, in
19214 + which case gdb assumes that sym_read already read the partial
19217 + void (*sym_read_psymbols) (struct objfile *);
19219 /* Called when we are finished with an objfile. Should do all
19220 cleanup that is specific to the object file format for the
19221 particular objfile. */
19222 @@ -266,7 +272,7 @@ extern void free_section_addr_info (struct section_addr_info *);
19224 extern struct partial_symtab *start_psymtab_common (struct objfile *,
19225 struct section_offsets *,
19226 - char *, CORE_ADDR,
19227 + const char *, CORE_ADDR,
19228 struct partial_symbol **,
19229 struct partial_symbol **);
19231 @@ -309,7 +315,7 @@ extern int auto_solib_limit;
19233 extern void set_initial_language (void);
19235 -extern struct partial_symtab *allocate_psymtab (char *, struct objfile *);
19236 +extern struct partial_symtab *allocate_psymtab (const char *, struct objfile *);
19238 extern void discard_psymtab (struct partial_symtab *);
19240 @@ -378,7 +384,7 @@ void free_symfile_segment_data (struct symfile_segment_data *data);
19241 /* From dwarf2read.c */
19243 extern int dwarf2_has_info (struct objfile *);
19245 +extern void dwarf2_create_quick_addrmap (struct objfile *);
19246 extern void dwarf2_build_psymtabs (struct objfile *, int);
19247 extern void dwarf2_build_frame_info (struct objfile *);
19249 diff --git a/gdb/symmisc.c b/gdb/symmisc.c
19250 index eb35369..dfd8c8c 100644
19251 --- a/gdb/symmisc.c
19252 +++ b/gdb/symmisc.c
19253 @@ -1128,7 +1128,7 @@ maintenance_check_symtabs (char *ignore, int from_tty)
19256 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
19257 - NULL, SYMBOL_DOMAIN (*psym));
19258 + SYMBOL_DOMAIN (*psym));
19261 printf_filtered ("Static symbol `");
19262 @@ -1145,7 +1145,7 @@ maintenance_check_symtabs (char *ignore, int from_tty)
19265 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
19266 - NULL, SYMBOL_DOMAIN (*psym));
19267 + SYMBOL_DOMAIN (*psym));
19270 printf_filtered ("Global symbol `");
19271 diff --git a/gdb/symtab.c b/gdb/symtab.c
19272 index 8d9d72c..82e0163 100644
19276 #include "ada-lang.h"
19277 #include "p-lang.h"
19278 #include "addrmap.h"
19279 +#include "cp-support.h"
19281 #include "hashtab.h"
19283 @@ -85,7 +86,6 @@ static int find_line_common (struct linetable *, int, int *);
19284 char *operator_chars (char *p, char **end);
19286 static struct symbol *lookup_symbol_aux (const char *name,
19287 - const char *linkage_name,
19288 const struct block *block,
19289 const domain_enum domain,
19290 enum language language,
19291 @@ -93,20 +93,19 @@ static struct symbol *lookup_symbol_aux (const char *name,
19294 struct symbol *lookup_symbol_aux_local (const char *name,
19295 - const char *linkage_name,
19296 const struct block *block,
19297 - const domain_enum domain);
19298 + const domain_enum domain,
19299 + enum language language,
19300 + int *is_a_field_of_this);
19303 struct symbol *lookup_symbol_aux_symtabs (int block_index,
19305 - const char *linkage_name,
19306 const domain_enum domain);
19309 struct symbol *lookup_symbol_aux_psymtabs (int block_index,
19311 - const char *linkage_name,
19312 const domain_enum domain);
19314 static int file_matches (char *, char **, int);
19315 @@ -271,7 +270,7 @@ lookup_partial_symtab (const char *name)
19316 make_cleanup (xfree, real_path);
19319 - ALL_PSYMTABS (objfile, pst)
19320 + ALL_PSYMTABS_REQUIRED (objfile, pst)
19322 if (FILENAME_CMP (name, pst->filename) == 0)
19324 @@ -414,7 +413,8 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
19325 gsymbol->language = language;
19326 if (gsymbol->language == language_cplus
19327 || gsymbol->language == language_java
19328 - || gsymbol->language == language_objc)
19329 + || gsymbol->language == language_objc
19330 + || gsymbol->language == language_fortran)
19332 gsymbol->language_specific.cplus_specific.demangled_name = NULL;
19334 @@ -474,7 +474,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
19335 || gsymbol->language == language_auto)
19338 - cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
19339 + cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
19340 if (demangled != NULL)
19342 gsymbol->language = language_cplus;
19343 @@ -633,6 +633,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
19344 case language_cplus:
19345 case language_java:
19346 case language_objc:
19347 + case language_fortran:
19348 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
19349 return gsymbol->language_specific.cplus_specific.demangled_name;
19351 @@ -658,6 +659,7 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
19352 case language_cplus:
19353 case language_java:
19354 case language_objc:
19355 + case language_fortran:
19356 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
19357 return gsymbol->language_specific.cplus_specific.demangled_name;
19359 @@ -868,7 +870,13 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
19360 than the later used TEXTLOW/TEXTHIGH one. */
19362 ALL_OBJFILES (objfile)
19363 - if (objfile->psymtabs_addrmap != NULL)
19365 + if (objfile->quick_addrmap)
19367 + if (!addrmap_find (objfile->quick_addrmap, pc))
19370 + if (require_partial_symbols (objfile)->psymtabs_addrmap != NULL)
19372 struct partial_symtab *pst;
19374 @@ -901,6 +909,7 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
19380 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
19381 which still have no corresponding full SYMTABs read. But it is not
19382 @@ -1168,6 +1177,22 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
19386 +/* Ensure that the partial symbols for OBJFILE have been loaded. This
19387 + function always returns its argument, as a convenience. */
19390 +require_partial_symbols (struct objfile *objfile)
19392 + if ((objfile->flags & OBJF_SYMTABS_READ) == 0)
19394 + objfile->flags |= OBJF_SYMTABS_READ;
19396 + if (objfile->sf->sym_read_psymbols)
19397 + (*objfile->sf->sym_read_psymbols) (objfile);
19402 /* Find the definition for a specified symbol name NAME
19403 in domain DOMAIN, visible from lexical block BLOCK.
19404 Returns the struct symbol pointer, or zero if no symbol is found.
19405 @@ -1194,10 +1219,14 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19407 char *demangled_name = NULL;
19408 const char *modified_name = NULL;
19409 - const char *mangled_name = NULL;
19410 struct symbol *returnval;
19411 struct cleanup *cleanup = make_cleanup (null_cleanup, 0);
19413 + if(strncmp(name, "::", 2) == 0){/* this must be a global name */
19418 modified_name = name;
19420 /* If we are using C++ or Java, demangle the name before doing a lookup, so
19421 @@ -1207,7 +1236,6 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19422 demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
19423 if (demangled_name)
19425 - mangled_name = name;
19426 modified_name = demangled_name;
19427 make_cleanup (xfree, demangled_name);
19429 @@ -1229,7 +1257,6 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19430 DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
19431 if (demangled_name)
19433 - mangled_name = name;
19434 modified_name = demangled_name;
19435 make_cleanup (xfree, demangled_name);
19437 @@ -1248,8 +1275,8 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19438 modified_name = copy;
19441 - returnval = lookup_symbol_aux (modified_name, mangled_name, block,
19442 - domain, lang, is_a_field_of_this);
19443 + returnval = lookup_symbol_aux (modified_name, block, domain, lang,
19444 + is_a_field_of_this);
19445 do_cleanups (cleanup);
19448 @@ -1273,9 +1300,9 @@ lookup_symbol (const char *name, const struct block *block,
19451 static struct symbol *
19452 -lookup_symbol_aux (const char *name, const char *linkage_name,
19453 - const struct block *block, const domain_enum domain,
19454 - enum language language, int *is_a_field_of_this)
19455 +lookup_symbol_aux (const char *name, const struct block *block,
19456 + const domain_enum domain, enum language language,
19457 + int *is_a_field_of_this)
19459 struct symbol *sym;
19460 const struct language_defn *langdef;
19461 @@ -1291,55 +1318,19 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19462 /* Search specified block and its superiors. Don't search
19463 STATIC_BLOCK or GLOBAL_BLOCK. */
19465 - sym = lookup_symbol_aux_local (name, linkage_name, block, domain);
19466 + sym = lookup_symbol_aux_local (name, block, domain, language, is_a_field_of_this);
19470 - /* If requested to do so by the caller and if appropriate for LANGUAGE,
19471 - check to see if NAME is a field of `this'. */
19473 - langdef = language_def (language);
19475 - if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL
19476 - && block != NULL)
19478 - struct symbol *sym = NULL;
19479 - /* 'this' is only defined in the function's block, so find the
19480 - enclosing function block. */
19481 - for (; block && !BLOCK_FUNCTION (block);
19482 - block = BLOCK_SUPERBLOCK (block));
19484 - if (block && !dict_empty (BLOCK_DICT (block)))
19485 - sym = lookup_block_symbol (block, langdef->la_name_of_this,
19486 - NULL, VAR_DOMAIN);
19489 - struct type *t = sym->type;
19491 - /* I'm not really sure that type of this can ever
19492 - be typedefed; just be safe. */
19493 - CHECK_TYPEDEF (t);
19494 - if (TYPE_CODE (t) == TYPE_CODE_PTR
19495 - || TYPE_CODE (t) == TYPE_CODE_REF)
19496 - t = TYPE_TARGET_TYPE (t);
19498 - if (TYPE_CODE (t) != TYPE_CODE_STRUCT
19499 - && TYPE_CODE (t) != TYPE_CODE_UNION)
19500 - error (_("Internal error: `%s' is not an aggregate"),
19501 - langdef->la_name_of_this);
19503 - if (check_field (t, name))
19505 - *is_a_field_of_this = 1;
19510 + /* this symbol was found to be a member variable
19511 + do not perform the global search. */
19512 + if (is_a_field_of_this && *is_a_field_of_this)
19515 /* Now do whatever is appropriate for LANGUAGE to look
19516 up static and global variables. */
19518 - sym = langdef->la_lookup_symbol_nonlocal (name, linkage_name, block, domain);
19519 + langdef = language_def (language);
19520 + sym = langdef->la_lookup_symbol_nonlocal (name, block, domain);
19524 @@ -1349,11 +1340,11 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19525 desired name as a file-level static, then do psymtab-to-symtab
19526 conversion on the fly and return the found symbol. */
19528 - sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, linkage_name, domain);
19529 + sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
19533 - sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, linkage_name, domain);
19534 + sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, domain);
19538 @@ -1364,30 +1355,81 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19539 Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
19541 static struct symbol *
19542 -lookup_symbol_aux_local (const char *name, const char *linkage_name,
19543 - const struct block *block,
19544 - const domain_enum domain)
19545 +lookup_symbol_aux_local (const char *name, const struct block *block,
19546 + const domain_enum domain, enum language language,
19547 + int *is_a_field_of_this)
19549 struct symbol *sym;
19550 - const struct block *static_block = block_static_block (block);
19551 + const struct block *global_block = block_global_block (block);
19552 + const struct block *block_iterator = block;
19553 + const struct language_defn *langdef;
19555 + langdef = language_def (language);
19557 /* Check if either no block is specified or it's a global block. */
19559 - if (static_block == NULL)
19560 + if (global_block == NULL)
19563 - while (block != static_block)
19564 + while (block_iterator != global_block)
19566 - sym = lookup_symbol_aux_block (name, linkage_name, block, domain);
19568 + sym = lookup_symbol_aux_block (name, block_iterator, domain);
19573 - if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block))
19575 - block = BLOCK_SUPERBLOCK (block);
19577 + if (language == language_cplus )
19579 + sym = cp_lookup_symbol_imports (block_scope (block_iterator), name,
19580 + block_iterator, domain, 1, 1);
19586 + if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL
19587 + && BLOCK_FUNCTION (block_iterator))
19589 + if (!dict_empty (BLOCK_DICT (block_iterator)))
19591 + sym = lookup_block_symbol (block_iterator,
19592 + langdef->la_name_of_this,
19598 + struct type *t = sym->type;
19600 + /* I'm not really sure that type of this can ever
19601 + be typedefed; just be safe. */
19602 + CHECK_TYPEDEF (t);
19603 + if (TYPE_CODE (t) == TYPE_CODE_PTR
19604 + || TYPE_CODE (t) == TYPE_CODE_REF)
19605 + t = TYPE_TARGET_TYPE (t);
19607 + if (TYPE_CODE (t) != TYPE_CODE_STRUCT
19608 + && TYPE_CODE (t) != TYPE_CODE_UNION)
19609 + error (_("Internal error: `%s' is not an aggregate"),
19610 + langdef->la_name_of_this);
19612 + if (check_field (t, name))
19614 + *is_a_field_of_this = 1;
19621 + if (BLOCK_FUNCTION (block_iterator) != NULL && block_inlined_p (block_iterator))
19624 + block_iterator = BLOCK_SUPERBLOCK (block_iterator);
19627 - /* We've reached the edge of the function without finding a result. */
19628 + /* We've reached the global block without finding a result. */
19632 @@ -1416,13 +1458,12 @@ lookup_objfile_from_block (const struct block *block)
19633 block_found appropriately. */
19636 -lookup_symbol_aux_block (const char *name, const char *linkage_name,
19637 - const struct block *block,
19638 +lookup_symbol_aux_block (const char *name, const struct block *block,
19639 const domain_enum domain)
19641 struct symbol *sym;
19643 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19644 + sym = lookup_block_symbol (block, name, domain);
19647 block_found = block;
19648 @@ -1438,7 +1479,6 @@ lookup_symbol_aux_block (const char *name, const char *linkage_name,
19650 lookup_global_symbol_from_objfile (const struct objfile *objfile,
19652 - const char *linkage_name,
19653 const domain_enum domain)
19655 struct symbol *sym;
19656 @@ -1452,7 +1492,7 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19658 bv = BLOCKVECTOR (s);
19659 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19660 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19661 + sym = lookup_block_symbol (block, name, domain);
19664 block_found = block;
19665 @@ -1461,23 +1501,23 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19668 /* Now go through psymtabs. */
19669 + require_partial_symbols ((struct objfile *) objfile);
19670 ALL_OBJFILE_PSYMTABS (objfile, ps)
19673 - && lookup_partial_symbol (ps, name, linkage_name,
19675 + && lookup_partial_symbol (ps, name, 1, domain))
19677 s = PSYMTAB_TO_SYMTAB (ps);
19678 bv = BLOCKVECTOR (s);
19679 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19680 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19681 + sym = lookup_block_symbol (block, name, domain);
19682 return fixup_symbol_section (sym, (struct objfile *)objfile);
19686 if (objfile->separate_debug_objfile)
19687 return lookup_global_symbol_from_objfile (objfile->separate_debug_objfile,
19688 - name, linkage_name, domain);
19693 @@ -1488,8 +1528,7 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19696 static struct symbol *
19697 -lookup_symbol_aux_symtabs (int block_index,
19698 - const char *name, const char *linkage_name,
19699 +lookup_symbol_aux_symtabs (int block_index, const char *name,
19700 const domain_enum domain)
19702 struct symbol *sym;
19703 @@ -1502,7 +1541,7 @@ lookup_symbol_aux_symtabs (int block_index,
19705 bv = BLOCKVECTOR (s);
19706 block = BLOCKVECTOR_BLOCK (bv, block_index);
19707 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19708 + sym = lookup_block_symbol (block, name, domain);
19711 block_found = block;
19712 @@ -1520,7 +1559,6 @@ lookup_symbol_aux_symtabs (int block_index,
19714 static struct symbol *
19715 lookup_symbol_aux_psymtabs (int block_index, const char *name,
19716 - const char *linkage_name,
19717 const domain_enum domain)
19719 struct symbol *sym;
19720 @@ -1531,16 +1569,15 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19722 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
19724 - ALL_PSYMTABS (objfile, ps)
19725 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19728 - && lookup_partial_symbol (ps, name, linkage_name,
19729 - psymtab_index, domain))
19730 + && lookup_partial_symbol (ps, name, psymtab_index, domain))
19732 s = PSYMTAB_TO_SYMTAB (ps);
19733 bv = BLOCKVECTOR (s);
19734 block = BLOCKVECTOR_BLOCK (bv, block_index);
19735 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19736 + sym = lookup_block_symbol (block, name, domain);
19739 /* This shouldn't be necessary, but as a last resort try
19740 @@ -1557,7 +1594,7 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19741 block = BLOCKVECTOR_BLOCK (bv,
19742 block_index == GLOBAL_BLOCK ?
19743 STATIC_BLOCK : GLOBAL_BLOCK);
19744 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19745 + sym = lookup_block_symbol (block, name, domain);
19747 error (_("Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n%s may be an inlined function, or may be a template function\n(if a template, try specifying an instantiation: %s<type>)."),
19748 block_index == GLOBAL_BLOCK ? "global" : "static",
19749 @@ -1576,7 +1613,6 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19752 basic_lookup_symbol_nonlocal (const char *name,
19753 - const char *linkage_name,
19754 const struct block *block,
19755 const domain_enum domain)
19757 @@ -1610,11 +1646,11 @@ basic_lookup_symbol_nonlocal (const char *name,
19758 than that one, so I don't think we should worry about that for
19761 - sym = lookup_symbol_static (name, linkage_name, block, domain);
19762 + sym = lookup_symbol_static (name, block, domain);
19766 - return lookup_symbol_global (name, linkage_name, block, domain);
19767 + return lookup_symbol_global (name, block, domain);
19770 /* Lookup a symbol in the static block associated to BLOCK, if there
19771 @@ -1622,14 +1658,13 @@ basic_lookup_symbol_nonlocal (const char *name,
19774 lookup_symbol_static (const char *name,
19775 - const char *linkage_name,
19776 const struct block *block,
19777 const domain_enum domain)
19779 const struct block *static_block = block_static_block (block);
19781 if (static_block != NULL)
19782 - return lookup_symbol_aux_block (name, linkage_name, static_block, domain);
19783 + return lookup_symbol_aux_block (name, static_block, domain);
19787 @@ -1639,7 +1674,6 @@ lookup_symbol_static (const char *name,
19790 lookup_symbol_global (const char *name,
19791 - const char *linkage_name,
19792 const struct block *block,
19793 const domain_enum domain)
19795 @@ -1649,15 +1683,15 @@ lookup_symbol_global (const char *name,
19796 /* Call library-specific lookup procedure. */
19797 objfile = lookup_objfile_from_block (block);
19798 if (objfile != NULL)
19799 - sym = solib_global_lookup (objfile, name, linkage_name, domain);
19800 + sym = solib_global_lookup (objfile, name, domain);
19804 - sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name, domain);
19805 + sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain);
19809 - return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name, domain);
19810 + return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, domain);
19814 @@ -1681,14 +1715,11 @@ symbol_matches_domain (enum language symbol_language,
19817 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
19818 - If LINKAGE_NAME is non-NULL, check in addition that the symbol's
19819 - linkage name matches it. Check the global symbols if GLOBAL, the
19820 - static symbols if not */
19821 + Check the global symbols if GLOBAL, the static symbols if not. */
19823 struct partial_symbol *
19824 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19825 - const char *linkage_name, int global,
19826 - domain_enum domain)
19827 + int global, domain_enum domain)
19829 struct partial_symbol *temp;
19830 struct partial_symbol **start, **psym;
19831 @@ -1740,9 +1771,7 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19832 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
19834 while (top <= real_top
19835 - && (linkage_name != NULL
19836 - ? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0
19837 - : SYMBOL_MATCHES_SEARCH_NAME (*top,name)))
19838 + && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
19840 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
19841 SYMBOL_DOMAIN (*top), domain))
19842 @@ -1759,15 +1788,9 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19843 for (psym = start; psym < start + length; psym++)
19845 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
19846 - SYMBOL_DOMAIN (*psym), domain))
19848 - if (linkage_name != NULL
19849 - ? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0
19850 - : SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
19855 + SYMBOL_DOMAIN (*psym), domain)
19856 + && SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
19861 @@ -1809,22 +1832,25 @@ basic_lookup_transparent_type (const char *name)
19863 bv = BLOCKVECTOR (s);
19864 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19865 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19866 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19867 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
19869 return SYMBOL_TYPE (sym);
19873 - ALL_PSYMTABS (objfile, ps)
19874 + /* FIXME: .debug_pubnames should be read in.
19876 + One may also try to the first pass without the require_partial_symbols
19877 + call but that would behave nondeterministically. */
19878 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19880 - if (!ps->readin && lookup_partial_symbol (ps, name, NULL,
19881 - 1, STRUCT_DOMAIN))
19882 + if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_DOMAIN))
19884 s = PSYMTAB_TO_SYMTAB (ps);
19885 bv = BLOCKVECTOR (s);
19886 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19887 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19888 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19891 /* This shouldn't be necessary, but as a last resort
19892 @@ -1833,7 +1859,7 @@ basic_lookup_transparent_type (const char *name)
19893 * the psymtab gets it wrong in some cases.
19895 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19896 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19897 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19899 error (_("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
19900 %s may be an inlined function, or may be a template function\n\
19901 @@ -1857,21 +1883,26 @@ basic_lookup_transparent_type (const char *name)
19903 bv = BLOCKVECTOR (s);
19904 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19905 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19906 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19907 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
19909 return SYMBOL_TYPE (sym);
19913 - ALL_PSYMTABS (objfile, ps)
19914 + /* FIXME: Something like .debug_pubnames containing also static symbols
19915 + should be read in. Compiler needs to be taught to generate it first.
19917 + One may also try to the first pass without the require_partial_symbols
19918 + call but that would behave nondeterministically. */
19919 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19921 - if (!ps->readin && lookup_partial_symbol (ps, name, NULL, 0, STRUCT_DOMAIN))
19922 + if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_DOMAIN))
19924 s = PSYMTAB_TO_SYMTAB (ps);
19925 bv = BLOCKVECTOR (s);
19926 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19927 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19928 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19931 /* This shouldn't be necessary, but as a last resort
19932 @@ -1880,7 +1911,7 @@ basic_lookup_transparent_type (const char *name)
19933 * the psymtab gets it wrong in some cases.
19935 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19936 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19937 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19939 error (_("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
19940 %s may be an inlined function, or may be a template function\n\
19941 @@ -1905,9 +1936,23 @@ find_main_psymtab (void)
19942 struct partial_symtab *pst;
19943 struct objfile *objfile;
19945 - ALL_PSYMTABS (objfile, pst)
19946 + ALL_OBJFILES (objfile)
19948 + if ((objfile->flags & OBJF_MAIN) == 0)
19950 + require_partial_symbols (objfile);
19951 + ALL_OBJFILE_PSYMTABS (objfile, pst)
19953 + if (lookup_partial_symbol (pst, main_name (), 1, VAR_DOMAIN))
19960 + ALL_PSYMTABS_REQUIRED (objfile, pst)
19962 - if (lookup_partial_symbol (pst, main_name (), NULL, 1, VAR_DOMAIN))
19963 + if (lookup_partial_symbol (pst, main_name (), 1, VAR_DOMAIN))
19967 @@ -1925,14 +1970,10 @@ find_main_psymtab (void)
19968 search on the symbols. Each symbol which is marked as being a ObjC/C++
19969 symbol (language_cplus or language_objc set) has both the encoded and
19970 non-encoded names tested for a match.
19972 - If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
19973 - particular mangled name.
19977 lookup_block_symbol (const struct block *block, const char *name,
19978 - const char *linkage_name,
19979 const domain_enum domain)
19981 struct dict_iterator iter;
19982 @@ -1945,9 +1986,7 @@ lookup_block_symbol (const struct block *block, const char *name,
19983 sym = dict_iter_name_next (name, &iter))
19985 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
19986 - SYMBOL_DOMAIN (sym), domain)
19987 - && (linkage_name != NULL
19988 - ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
19989 + SYMBOL_DOMAIN (sym), domain))
19993 @@ -1967,9 +2006,7 @@ lookup_block_symbol (const struct block *block, const char *name,
19994 sym = dict_iter_name_next (name, &iter))
19996 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
19997 - SYMBOL_DOMAIN (sym), domain)
19998 - && (linkage_name != NULL
19999 - ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
20000 + SYMBOL_DOMAIN (sym), domain))
20003 if (!SYMBOL_IS_ARGUMENT (sym))
20004 @@ -3172,7 +3209,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
20005 matching the regexp. That way we don't have to reproduce all of
20006 the machinery below. */
20008 - ALL_PSYMTABS (objfile, ps)
20009 + ALL_PSYMTABS_REQUIRED (objfile, ps)
20011 struct partial_symbol **bound, **gbound, **sbound;
20012 int keep_going = 1;
20013 diff --git a/gdb/symtab.h b/gdb/symtab.h
20014 index 740d4e0..461ff95 100644
20017 @@ -171,9 +171,6 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
20018 #define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
20019 #define SYMBOL_OBJ_SECTION(symbol) (symbol)->ginfo.obj_section
20021 -#define SYMBOL_CPLUS_DEMANGLED_NAME(symbol) \
20022 - (symbol)->ginfo.language_specific.cplus_specific.demangled_name
20024 /* Initializes the language dependent portion of a symbol
20025 depending upon the language for the symbol. */
20026 #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language) \
20027 @@ -394,7 +391,13 @@ typedef enum domain_enum_tag
20030 /* All defined types */
20034 + /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. */
20035 + COMMON_BLOCK_DOMAIN,
20037 + /* Fortran module. Their naming must be separate. */
20042 @@ -990,7 +993,6 @@ extern struct symbol *lookup_symbol (const char *, const struct block *,
20043 that can't think of anything better to do. */
20045 extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
20047 const struct block *,
20048 const domain_enum);
20050 @@ -1001,7 +1003,6 @@ extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
20051 is one; do nothing if BLOCK is NULL or a global block. */
20053 extern struct symbol *lookup_symbol_static (const char *name,
20054 - const char *linkage_name,
20055 const struct block *block,
20056 const domain_enum domain);
20058 @@ -1009,7 +1010,6 @@ extern struct symbol *lookup_symbol_static (const char *name,
20061 extern struct symbol *lookup_symbol_global (const char *name,
20062 - const char *linkage_name,
20063 const struct block *block,
20064 const domain_enum domain);
20066 @@ -1018,21 +1018,18 @@ extern struct symbol *lookup_symbol_global (const char *name,
20067 will fix up the symbol if necessary. */
20069 extern struct symbol *lookup_symbol_aux_block (const char *name,
20070 - const char *linkage_name,
20071 const struct block *block,
20072 const domain_enum domain);
20074 /* Lookup a partial symbol. */
20076 extern struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
20081 /* lookup a symbol by name, within a specified block */
20083 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
20085 const domain_enum);
20087 /* lookup a [struct, union, enum] by name, within a specified block */
20088 @@ -1062,6 +1059,8 @@ extern void clear_pc_function_cache (void);
20090 /* from symtab.c: */
20092 +struct objfile *require_partial_symbols (struct objfile *);
20094 /* lookup partial symbol table by filename */
20096 extern struct partial_symtab *lookup_partial_symtab (const char *);
20097 @@ -1356,7 +1355,6 @@ extern /*const */ char *main_name (void);
20098 /* Check global symbols in objfile. */
20099 struct symbol *lookup_global_symbol_from_objfile (const struct objfile *objfile,
20101 - const char *linkage_name,
20102 const domain_enum domain);
20104 extern struct symtabs_and_lines
20105 diff --git a/gdb/target.c b/gdb/target.c
20106 index e5d14fd..37fab72 100644
20109 @@ -124,6 +124,8 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
20111 static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
20113 +static int debug_to_detach_watchpoints (void);
20115 static int debug_to_stopped_by_watchpoint (void);
20117 static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
20118 @@ -622,6 +624,7 @@ update_current_target (void)
20119 INHERIT (to_remove_hw_breakpoint, t);
20120 INHERIT (to_insert_watchpoint, t);
20121 INHERIT (to_remove_watchpoint, t);
20122 + INHERIT (to_detach_watchpoints, t);
20123 INHERIT (to_stopped_data_address, t);
20124 INHERIT (to_have_steppable_watchpoint, t);
20125 INHERIT (to_have_continuable_watchpoint, t);
20126 @@ -733,6 +736,9 @@ update_current_target (void)
20127 de_fault (to_remove_watchpoint,
20128 (int (*) (CORE_ADDR, int, int))
20130 + de_fault (to_detach_watchpoints,
20133 de_fault (to_stopped_by_watchpoint,
20136 @@ -3173,6 +3179,19 @@ debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
20141 +debug_to_detach_watchpoints (void)
20145 + retval = debug_target.to_detach_watchpoints ();
20147 + fprintf_unfiltered (gdb_stdlog,
20148 + "target_detach_watchpoints () = %ld\n",
20149 + (unsigned long) retval);
20154 debug_to_terminal_init (void)
20156 @@ -3420,6 +3439,7 @@ setup_target_debug (void)
20157 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
20158 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
20159 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
20160 + current_target.to_detach_watchpoints = debug_to_detach_watchpoints;
20161 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
20162 current_target.to_stopped_data_address = debug_to_stopped_data_address;
20163 current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
20164 diff --git a/gdb/target.h b/gdb/target.h
20165 index b1cb852..3c06eba 100644
20168 @@ -395,6 +395,7 @@ struct target_ops
20169 int (*to_remove_hw_breakpoint) (struct gdbarch *, struct bp_target_info *);
20170 int (*to_remove_watchpoint) (CORE_ADDR, int, int);
20171 int (*to_insert_watchpoint) (CORE_ADDR, int, int);
20172 + int (*to_detach_watchpoints) (void);
20173 int (*to_stopped_by_watchpoint) (void);
20174 int to_have_steppable_watchpoint;
20175 int to_have_continuable_watchpoint;
20176 @@ -1124,7 +1125,7 @@ extern char *normal_pid_to_str (ptid_t ptid);
20177 /* Hardware watchpoint interfaces. */
20179 /* Returns non-zero if we were stopped by a hardware watchpoint (memory read or
20181 + write). Only the INFERIOR_PTID task is being queried. */
20183 #define target_stopped_by_watchpoint \
20184 (*current_target.to_stopped_by_watchpoint)
20185 @@ -1166,14 +1167,26 @@ extern char *normal_pid_to_str (ptid_t ptid);
20186 #define target_remove_watchpoint(addr, len, type) \
20187 (*current_target.to_remove_watchpoint) (addr, len, type)
20189 +/* Clear all debug registers without affecting any register caches. Function
20190 + acts on INFERIOR_PTID which should be the forked-off process, either the
20191 + non-threaded child one or the threaded parent one, depending on `set
20192 + follow-fork-mode'. Both watchpoints and hardware breakpoints get removed.
20193 + Return 0 on success, -1 on failure. */
20195 +#define target_detach_watchpoints() \
20196 + (*current_target.to_detach_watchpoints) ()
20198 #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
20199 (*current_target.to_insert_hw_breakpoint) (gdbarch, bp_tgt)
20201 #define target_remove_hw_breakpoint(gdbarch, bp_tgt) \
20202 (*current_target.to_remove_hw_breakpoint) (gdbarch, bp_tgt)
20204 -#define target_stopped_data_address(target, x) \
20205 - (*target.to_stopped_data_address) (target, x)
20206 +/* Return non-zero if target knows the data address which triggered this
20207 + target_stopped_by_watchpoint, in such case place it to *ADDR_P. Only the
20208 + INFERIOR_PTID task is being queried. */
20209 +#define target_stopped_data_address(target, addr_p) \
20210 + (*target.to_stopped_data_address) (target, addr_p)
20212 #define target_watchpoint_addr_within_range(target, addr, start, length) \
20213 (*target.to_watchpoint_addr_within_range) (target, addr, start, length)
20214 @@ -1203,6 +1216,20 @@ extern int target_search_memory (CORE_ADDR start_addr,
20215 ULONGEST pattern_len,
20216 CORE_ADDR *found_addrp);
20218 +/* Utility functions which can be used by search_memory implementations. */
20220 +void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
20221 + ULONGEST *pattern_buf_size);
20223 +void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
20224 + ULONGEST *pattern_buf_size, int val_bytes);
20226 +int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
20227 + const char *pattern_buf, ULONGEST pattern_len,
20228 + CORE_ADDR *found_addr);
20230 +void put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p);
20232 /* Command logging facility. */
20234 #define target_log_command(p) \
20235 @@ -1322,6 +1349,14 @@ extern struct target_ops *find_target_beneath (struct target_ops *);
20237 extern char *target_get_osdata (const char *type);
20239 +/* Read OS data object of type TYPE from the target, and return it in
20240 + XML format. The result is NUL-terminated and returned as a string,
20241 + allocated using xmalloc. If an error occurs or the transfer is
20242 + unsupported, NULL is returned. Empty objects are returned as
20243 + allocated but empty strings. */
20245 +extern char *target_get_osdata (const char *type);
20248 /* Stuff that should be shared among the various remote targets. */
20250 diff --git a/gdb/testsuite/gdb.arch/powerpc-power7.exp b/gdb/testsuite/gdb.arch/powerpc-power7.exp
20251 new file mode 100644
20252 index 0000000..ae301db
20254 +++ b/gdb/testsuite/gdb.arch/powerpc-power7.exp
20256 +# Copyright 2009 Free Software Foundation, Inc.
20258 +# This program is free software; you can redistribute it and/or modify
20259 +# it under the terms of the GNU General Public License as published by
20260 +# the Free Software Foundation; either version 2 of the License, or
20261 +# (at your option) any later version.
20263 +# This program is distributed in the hope that it will be useful,
20264 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
20265 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20266 +# GNU General Public License for more details.
20268 +# You should have received a copy of the GNU General Public License
20269 +# along with this program; if not, write to the Free Software
20270 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20272 +# Test PowerPC Power7 instructions disassembly.
20274 +if {![istarget "powerpc*-*-*"]} then {
20275 + verbose "Skipping PowerPC Power7 instructions disassembly."
20279 +set testfile "powerpc-power7"
20280 +set srcfile ${testfile}.s
20281 +set objfile ${objdir}/${subdir}/${testfile}.o
20283 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug}] != "" } {
20284 + untested "PowerPC Power7 instructions disassembly"
20291 +gdb_reinitialize_dir $srcdir/$subdir
20292 +gdb_load ${objfile}
20295 +# Disassemble the function.
20297 +set test "disass func"
20298 +gdb_test_multiple $test $test {
20299 + -re "\r\nDump of assembler code for function func:(\r\n.*\r\n)End of assembler dump.\r\n$gdb_prompt $" {
20300 + set func $expect_out(1,string)
20305 +proc instr_to_patt {offset instr} {
20306 + # 0x0000000000000018 <func+24>: stxvd2x vs43,r4,r5
20307 + return ".*\r\n[string map {0x 0x0*} $offset] <func\\+?\[0-9\]*>:\[ \t\]*[string map [list { } "\[ \t\]+" . {\.}] $instr]\[ \t\]*\r\n.*"
20310 +# KFAIL strings would not exist if -Many would print the same as -Mpower7.
20311 +# That means the power7 form should be the preferred one.
20312 +# http://sourceware.org/ml/gdb-patches/2009-03/threads.html#00020
20314 +proc func_check {offset instr {kfail ""}} {
20317 + set test "Found $offset: $instr"
20318 + if [regexp -nocase -line [instr_to_patt $offset $instr] $func] {
20320 + } elseif {$kfail != "" && [regexp -nocase -line [instr_to_patt $offset $kfail] $func]} {
20321 + kfail gdb/NNNN $test
20327 +func_check 0x0 "lxvd2x vs3,r4,r5"
20328 +func_check 0x4 "lxvd2ux vs3,r4,r5"
20329 +func_check 0x8 "lxvd2x vs43,r4,r5"
20330 +func_check 0xc "lxvd2ux vs43,r4,r5"
20331 +func_check 0x10 "stxvd2x vs3,r4,r5"
20332 +func_check 0x14 "stxvd2ux vs3,r4,r5"
20333 +func_check 0x18 "stxvd2x vs43,r4,r5"
20334 +func_check 0x1c "stxvd2ux vs43,r4,r5"
20335 +func_check 0x20 "xxmrghd vs3,vs4,vs5"
20336 +func_check 0x24 "xxmrghd vs43,vs44,vs45"
20337 +func_check 0x28 "xxmrgld vs3,vs4,vs5"
20338 +func_check 0x2c "xxmrgld vs43,vs44,vs45"
20339 +func_check 0x30 "xxmrghd vs3,vs4,vs5"
20340 +func_check 0x34 "xxmrghd vs43,vs44,vs45"
20341 +func_check 0x38 "xxmrgld vs3,vs4,vs5"
20342 +func_check 0x3c "xxmrgld vs43,vs44,vs45"
20343 +func_check 0x40 "xxpermdi vs3,vs4,vs5,1"
20344 +func_check 0x44 "xxpermdi vs43,vs44,vs45,1"
20345 +func_check 0x48 "xxpermdi vs3,vs4,vs5,2"
20346 +func_check 0x4c "xxpermdi vs43,vs44,vs45,2"
20347 +func_check 0x50 "xvmovdp vs3,vs4"
20348 +func_check 0x54 "xvmovdp vs43,vs44"
20349 +func_check 0x58 "xvmovdp vs3,vs4"
20350 +func_check 0x5c "xvmovdp vs43,vs44"
20351 +func_check 0x60 "xvcpsgndp vs3,vs4,vs5"
20352 +func_check 0x64 "xvcpsgndp vs43,vs44,vs45"
20353 +func_check 0x68 "wait"
20354 +func_check 0x6c "wait"
20355 +func_check 0x70 "waitrsv"
20356 +func_check 0x74 "waitrsv"
20357 +func_check 0x78 "waitimpl"
20358 +func_check 0x7c "waitimpl"
20359 +func_check 0x80 "doze"
20360 +func_check 0x84 "nap"
20361 +func_check 0x88 "sleep"
20362 +func_check 0x8c "rvwinkle"
20363 +func_check 0x90 "prtyw r3,r4"
20364 +func_check 0x94 "prtyd r13,r14"
20365 +func_check 0x98 "mfcfar r10" "mfspr r10,28"
20366 +func_check 0x9c "mtcfar r11" "mtspr 28,r11"
20367 +func_check 0xa0 "cmpb r3,r4,r5"
20368 +func_check 0xa4 "lwzcix r10,r11,r12"
20369 +func_check 0xa8 "dadd f16,f17,f18"
20370 +func_check 0xac "daddq f20,f22,f24"
20371 +func_check 0xb0 "dss 3"
20372 +func_check 0xb4 "dssall"
20373 +func_check 0xb8 "dst r5,r4,1"
20374 +func_check 0xbc "dstt r8,r7,0"
20375 +func_check 0xc0 "dstst r5,r6,3"
20376 +func_check 0xc4 "dststt r4,r5,2"
20377 +func_check 0xc8 "divwe r10,r11,r12"
20378 +func_check 0xcc "divwe. r11,r12,r13"
20379 +func_check 0xd0 "divweo r12,r13,r14"
20380 +func_check 0xd4 "divweo. r13,r14,r15"
20381 +func_check 0xd8 "divweu r10,r11,r12"
20382 +func_check 0xdc "divweu. r11,r12,r13"
20383 +func_check 0xe0 "divweuo r12,r13,r14"
20384 +func_check 0xe4 "divweuo. r13,r14,r15"
20385 +func_check 0xe8 "bpermd r7,r17,r27"
20386 +func_check 0xec "popcntw r10,r20"
20387 +func_check 0xf0 "popcntd r10,r20"
20388 +func_check 0xf4 "ldbrx r20,r21,r22"
20389 +func_check 0xf8 "stdbrx r20,r21,r22"
20390 +func_check 0xfc "lfiwzx f10,0,r10"
20391 +func_check 0x100 "lfiwzx f10,r9,r10"
20392 +func_check 0x104 "fcfids f4,f5"
20393 +func_check 0x108 "fcfids. f4,f5"
20394 +func_check 0x10c "fcfidus f4,f5"
20395 +func_check 0x110 "fcfidus. f4,f5"
20396 +func_check 0x114 "fctiwu f4,f5"
20397 +func_check 0x118 "fctiwu. f4,f5"
20398 +func_check 0x11c "fctiwuz f4,f5"
20399 +func_check 0x120 "fctiwuz. f4,f5"
20400 +func_check 0x124 "fctidu f4,f5"
20401 +func_check 0x128 "fctidu. f4,f5"
20402 +func_check 0x12c "fctiduz f4,f5"
20403 +func_check 0x130 "fctiduz. f4,f5"
20404 +func_check 0x134 "fcfidu f4,f5"
20405 +func_check 0x138 "fcfidu. f4,f5"
20406 +func_check 0x13c "ftdiv cr0,f10,f11"
20407 +func_check 0x140 "ftdiv cr7,f10,f11"
20408 +func_check 0x144 "ftsqrt cr0,f10"
20409 +func_check 0x148 "ftsqrt cr7,f10"
20410 +func_check 0x14c "dcbtt r8,r9" "dcbt 16,r8,r9"
20411 +func_check 0x150 "dcbtstt r8,r9" "dcbtst 16,r8,r9"
20412 +func_check 0x154 "dcffix f10,f12"
20413 +func_check 0x158 "dcffix. f20,f22"
20414 +func_check 0x15c "lbarx r10,r11,r12"
20415 +func_check 0x160 "lbarx r10,r11,r12"
20416 +func_check 0x164 "lbarx r10,r11,r12,1"
20417 +func_check 0x168 "lharx r20,r21,r22"
20418 +func_check 0x16c "lharx r20,r21,r22"
20419 +func_check 0x170 "lharx r20,r21,r22,1"
20420 +func_check 0x174 "stbcx. r10,r11,r12"
20421 +func_check 0x178 "sthcx. r10,r11,r12"
20422 +func_check 0x17c "fre f14,f15"
20423 +func_check 0x180 "fre. f14,f15"
20424 +func_check 0x184 "fres f14,f15"
20425 +func_check 0x188 "fres. f14,f15"
20426 +func_check 0x18c "frsqrte f14,f15"
20427 +func_check 0x190 "frsqrte. f14,f15"
20428 +func_check 0x194 "frsqrtes f14,f15"
20429 +func_check 0x198 "frsqrtes. f14,f15"
20430 +func_check 0x19c "isel r2,r3,r4,28"
20431 diff --git a/gdb/testsuite/gdb.arch/powerpc-power7.s b/gdb/testsuite/gdb.arch/powerpc-power7.s
20432 new file mode 100644
20433 index 0000000..98b2e79
20435 +++ b/gdb/testsuite/gdb.arch/powerpc-power7.s
20440 + .long 0x7c642e98 /* 0: lxvd2x vs3,r4,r5 */
20441 + .long 0x7c642ed8 /* 4: lxvd2ux vs3,r4,r5 */
20442 + .long 0x7d642e99 /* 8: lxvd2x vs43,r4,r5 */
20443 + .long 0x7d642ed9 /* c: lxvd2ux vs43,r4,r5 */
20444 + .long 0x7c642f98 /* 10: stxvd2x vs3,r4,r5 */
20445 + .long 0x7c642fd8 /* 14: stxvd2ux vs3,r4,r5 */
20446 + .long 0x7d642f99 /* 18: stxvd2x vs43,r4,r5 */
20447 + .long 0x7d642fd9 /* 1c: stxvd2ux vs43,r4,r5 */
20448 + .long 0xf0642850 /* 20: xxmrghd vs3,vs4,vs5 */
20449 + .long 0xf16c6857 /* 24: xxmrghd vs43,vs44,vs45 */
20450 + .long 0xf0642b50 /* 28: xxmrgld vs3,vs4,vs5 */
20451 + .long 0xf16c6b57 /* 2c: xxmrgld vs43,vs44,vs45 */
20452 + .long 0xf0642850 /* 30: xxmrghd vs3,vs4,vs5 */
20453 + .long 0xf16c6857 /* 34: xxmrghd vs43,vs44,vs45 */
20454 + .long 0xf0642b50 /* 38: xxmrgld vs3,vs4,vs5 */
20455 + .long 0xf16c6b57 /* 3c: xxmrgld vs43,vs44,vs45 */
20456 + .long 0xf0642950 /* 40: xxpermdi vs3,vs4,vs5,1 */
20457 + .long 0xf16c6957 /* 44: xxpermdi vs43,vs44,vs45,1 */
20458 + .long 0xf0642a50 /* 48: xxpermdi vs3,vs4,vs5,2 */
20459 + .long 0xf16c6a57 /* 4c: xxpermdi vs43,vs44,vs45,2 */
20460 + .long 0xf0642780 /* 50: xvmovdp vs3,vs4 */
20461 + .long 0xf16c6787 /* 54: xvmovdp vs43,vs44 */
20462 + .long 0xf0642780 /* 58: xvmovdp vs3,vs4 */
20463 + .long 0xf16c6787 /* 5c: xvmovdp vs43,vs44 */
20464 + .long 0xf0642f80 /* 60: xvcpsgndp vs3,vs4,vs5 */
20465 + .long 0xf16c6f87 /* 64: xvcpsgndp vs43,vs44,vs45 */
20466 + .long 0x7c00007c /* 68: wait */
20467 + .long 0x7c00007c /* 6c: wait */
20468 + .long 0x7c20007c /* 70: waitrsv */
20469 + .long 0x7c20007c /* 74: waitrsv */
20470 + .long 0x7c40007c /* 78: waitimpl */
20471 + .long 0x7c40007c /* 7c: waitimpl */
20472 + .long 0x4c000324 /* 80: doze */
20473 + .long 0x4c000364 /* 84: nap */
20474 + .long 0x4c0003a4 /* 88: sleep */
20475 + .long 0x4c0003e4 /* 8c: rvwinkle */
20476 + .long 0x7c830134 /* 90: prtyw r3,r4 */
20477 + .long 0x7dcd0174 /* 94: prtyd r13,r14 */
20478 + .long 0x7d5c02a6 /* 98: mfcfar r10 */
20479 + .long 0x7d7c03a6 /* 9c: mtcfar r11 */
20480 + .long 0x7c832bf8 /* a0: cmpb r3,r4,r5 */
20481 + .long 0x7d4b662a /* a4: lwzcix r10,r11,r12 */
20482 + .long 0xee119004 /* a8: dadd f16,f17,f18 */
20483 + .long 0xfe96c004 /* ac: daddq f20,f22,f24 */
20484 + .long 0x7c60066c /* b0: dss 3 */
20485 + .long 0x7e00066c /* b4: dssall */
20486 + .long 0x7c2522ac /* b8: dst r5,r4,1 */
20487 + .long 0x7e083aac /* bc: dstt r8,r7,0 */
20488 + .long 0x7c6532ec /* c0: dstst r5,r6,3 */
20489 + .long 0x7e442aec /* c4: dststt r4,r5,2 */
20490 + .long 0x7d4b6356 /* c8: divwe r10,r11,r12 */
20491 + .long 0x7d6c6b57 /* cc: divwe. r11,r12,r13 */
20492 + .long 0x7d8d7756 /* d0: divweo r12,r13,r14 */
20493 + .long 0x7dae7f57 /* d4: divweo. r13,r14,r15 */
20494 + .long 0x7d4b6316 /* d8: divweu r10,r11,r12 */
20495 + .long 0x7d6c6b17 /* dc: divweu. r11,r12,r13 */
20496 + .long 0x7d8d7716 /* e0: divweuo r12,r13,r14 */
20497 + .long 0x7dae7f17 /* e4: divweuo. r13,r14,r15 */
20498 + .long 0x7e27d9f8 /* e8: bpermd r7,r17,r27 */
20499 + .long 0x7e8a02f4 /* ec: popcntw r10,r20 */
20500 + .long 0x7e8a03f4 /* f0: popcntd r10,r20 */
20501 + .long 0x7e95b428 /* f4: ldbrx r20,r21,r22 */
20502 + .long 0x7e95b528 /* f8: stdbrx r20,r21,r22 */
20503 + .long 0x7d4056ee /* fc: lfiwzx f10,0,r10 */
20504 + .long 0x7d4956ee /* 100: lfiwzx f10,r9,r10 */
20505 + .long 0xec802e9c /* 104: fcfids f4,f5 */
20506 + .long 0xec802e9d /* 108: fcfids. f4,f5 */
20507 + .long 0xec802f9c /* 10c: fcfidus f4,f5 */
20508 + .long 0xec802f9d /* 110: fcfidus. f4,f5 */
20509 + .long 0xfc80291c /* 114: fctiwu f4,f5 */
20510 + .long 0xfc80291d /* 118: fctiwu. f4,f5 */
20511 + .long 0xfc80291e /* 11c: fctiwuz f4,f5 */
20512 + .long 0xfc80291f /* 120: fctiwuz. f4,f5 */
20513 + .long 0xfc802f5c /* 124: fctidu f4,f5 */
20514 + .long 0xfc802f5d /* 128: fctidu. f4,f5 */
20515 + .long 0xfc802f5e /* 12c: fctiduz f4,f5 */
20516 + .long 0xfc802f5f /* 130: fctiduz. f4,f5 */
20517 + .long 0xfc802f9c /* 134: fcfidu f4,f5 */
20518 + .long 0xfc802f9d /* 138: fcfidu. f4,f5 */
20519 + .long 0xfc0a5900 /* 13c: ftdiv cr0,f10,f11 */
20520 + .long 0xff8a5900 /* 140: ftdiv cr7,f10,f11 */
20521 + .long 0xfc005140 /* 144: ftsqrt cr0,f10 */
20522 + .long 0xff805140 /* 148: ftsqrt cr7,f10 */
20523 + .long 0x7e084a2c /* 14c: dcbtt r8,r9 */
20524 + .long 0x7e0849ec /* 150: dcbtstt r8,r9 */
20525 + .long 0xed406644 /* 154: dcffix f10,f12 */
20526 + .long 0xee80b645 /* 158: dcffix. f20,f22 */
20527 + .long 0x7d4b6068 /* 15c: lbarx r10,r11,r12 */
20528 + .long 0x7d4b6068 /* 160: lbarx r10,r11,r12 */
20529 + .long 0x7d4b6069 /* 164: lbarx r10,r11,r12,1 */
20530 + .long 0x7e95b0e8 /* 168: lharx r20,r21,r22 */
20531 + .long 0x7e95b0e8 /* 16c: lharx r20,r21,r22 */
20532 + .long 0x7e95b0e9 /* 170: lharx r20,r21,r22,1 */
20533 + .long 0x7d4b656d /* 174: stbcx. r10,r11,r12 */
20534 + .long 0x7d4b65ad /* 178: sthcx. r10,r11,r12 */
20535 + .long 0xfdc07830 /* 17c: fre f14,f15 */
20536 + .long 0xfdc07831 /* 180: fre. f14,f15 */
20537 + .long 0xedc07830 /* 184: fres f14,f15 */
20538 + .long 0xedc07831 /* 188: fres. f14,f15 */
20539 + .long 0xfdc07834 /* 18c: frsqrte f14,f15 */
20540 + .long 0xfdc07835 /* 190: frsqrte. f14,f15 */
20541 + .long 0xedc07834 /* 194: frsqrtes f14,f15 */
20542 + .long 0xedc07835 /* 198: frsqrtes. f14,f15 */
20543 + .long 0x7c43271e /* 19c: isel r2,r3,r4,28 */
20544 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
20545 new file mode 100644
20546 index 0000000..66f7a39
20548 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
20550 + .file "x86_64-vla-typedef.c"
20551 + .section .debug_abbrev,"",@progbits
20553 + .section .debug_info,"",@progbits
20555 + .section .debug_line,"",@progbits
20560 + .type foo, @function
20563 + .file 1 "x86_64-vla-typedef.c"
20571 + movl %edi, -36(%rbp)
20574 + movq %rax, -48(%rbp)
20576 + movl -36(%rbp), %edx
20579 + movq %rax, -24(%rbp)
20587 + movq %rsp, -56(%rbp)
20588 + movq -56(%rbp), %rax
20592 + movq %rax, -56(%rbp)
20593 + movq -56(%rbp), %rax
20594 + movq %rax, -16(%rbp)
20596 + movl $0, -4(%rbp)
20600 + movl -4(%rbp), %esi
20601 + movl -4(%rbp), %eax
20603 + movq -16(%rbp), %rdx
20605 + movb %cl, (%rdx,%rax)
20607 + addl $1, -4(%rbp)
20609 + movl -4(%rbp), %eax
20610 + cmpl -36(%rbp), %eax
20613 + .globl break_here
20615 + movq -16(%rbp), %rax
20617 + movq -48(%rbp), %rsp
20623 + .section .debug_frame,"",@progbits
20625 + .long .LECIE0-.LSCIE0
20641 + .long .LEFDE0-.LASFDE0
20645 + .quad .LFE2-.LFB2
20647 + .long .LCFI0-.LFB2
20653 + .long .LCFI1-.LCFI0
20658 + .section .eh_frame,"a",@progbits
20660 + .long .LECIE1-.LSCIE1
20678 + .long .LEFDE1-.LASFDE1
20680 + .long .LASFDE1-.Lframe1
20682 + .long .LFE2-.LFB2
20685 + .long .LCFI0-.LFB2
20691 + .long .LCFI1-.LCFI0
20698 + .section .debug_loc,"",@progbits
20701 + .quad .LFB2-.Ltext0
20702 + .quad .LCFI0-.Ltext0
20706 + .quad .LCFI0-.Ltext0
20707 + .quad .LCFI1-.Ltext0
20711 + .quad .LCFI1-.Ltext0
20712 + .quad .LFE2-.Ltext0
20718 + .section .debug_info
20719 + .long .Ldebug_end - .Ldebug_start
20722 + .long .Ldebug_abbrev0
20731 + .long .Ldebug_line0
20755 + .long .Ltag_array_type - .debug_info
20756 + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */
20761 + .long .Ltag_typedef - .debug_info
20763 + /* Debugging only: Skip the typedef indirection. */
20764 + .long .Ltag_array_type - .debug_info
20766 + /* DW_AT_location: DW_FORM_block1: start */
20771 + .byte 0x6 /* DW_OP_deref */
20773 + .byte 0x96 /* DW_OP_nop */
20775 + /* DW_AT_location: DW_FORM_block1: end */
20790 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
20791 + .long 0xa0 + (2f - 1f) /* DW_AT_type: DW_FORM_ref4 */
20792 + .long 0x9d + (2f - 1f) /* DW_AT_sibling: DW_FORM_ref4 */
20793 +1: /* DW_AT_data_location: DW_FORM_block1: start */
20794 + .byte 2f - 3f /* length */
20796 + .byte 0x97 /* DW_OP_push_object_address */
20797 + .byte 0x6 /* DW_OP_deref */
20798 +2: /* DW_AT_data_location: DW_FORM_block1: end */
20800 + .long 0x9d + (2b - 1b) /* DW_AT_type: DW_FORM_ref4 */
20815 + .section .debug_abbrev
20927 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
20930 + .uleb128 0x49 /* DW_AT_type */
20931 + .uleb128 0x13 /* DW_FORM_ref4 */
20932 + .uleb128 0x1 /* DW_AT_sibling */
20933 + .uleb128 0x13 /* DW_FORM_ref4 */
20934 + .uleb128 0x50 /* DW_AT_data_location */
20935 + .uleb128 0xa /* DW_FORM_block1 */
20941 + .uleb128 0x49 /* DW_AT_type */
20942 + .uleb128 0x13 /* DW_FORM_ref4 */
20968 + .section .debug_pubnames,"",@progbits
20971 + .long .Ldebug_info0
20976 + .section .debug_aranges,"",@progbits
20979 + .long .Ldebug_info0
20985 + .quad .Letext0-.Ltext0
20988 + .section .debug_str,"MS",@progbits,1
20994 + .string "x86_64-vla-typedef.c"
20996 + .string "array_t"
21000 + .string "gdb.arch"
21002 + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
21003 + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
21004 + .section .note.GNU-stack,"",@progbits
21005 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
21006 new file mode 100644
21007 index 0000000..b809c4e
21009 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
21011 +/* This testcase is part of GDB, the GNU debugger.
21013 + Copyright 2008 Free Software Foundation, Inc.
21015 + This program is free software; you can redistribute it and/or modify
21016 + it under the terms of the GNU General Public License as published by
21017 + the Free Software Foundation; either version 3 of the License, or
21018 + (at your option) any later version.
21020 + This program is distributed in the hope that it will be useful,
21021 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21022 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21023 + GNU General Public License for more details.
21025 + You should have received a copy of the GNU General Public License
21026 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21033 + typedef char array_t[size];
21037 + for (i = 0; i < size; i++)
21040 + array[0] = 0; /* break-here */
21054 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
21055 new file mode 100644
21056 index 0000000..b05411e
21058 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
21060 +# Copyright 2009 Free Software Foundation, Inc.
21062 +# This program is free software; you can redistribute it and/or modify
21063 +# it under the terms of the GNU General Public License as published by
21064 +# the Free Software Foundation; either version 3 of the License, or
21065 +# (at your option) any later version.
21067 +# This program is distributed in the hope that it will be useful,
21068 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21069 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21070 +# GNU General Public License for more details.
21072 +# You should have received a copy of the GNU General Public License
21073 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21075 +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
21077 +if ![istarget "x86_64-*-*"] then {
21078 + verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
21082 +set testfile x86_64-vla-typedef
21083 +set srcasmfile ${testfile}-foo.S
21084 +set srcfile ${testfile}.c
21085 +set binfile ${objdir}/${subdir}/${testfile}
21086 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
21087 +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
21088 + untested "Couldn't compile test program"
21091 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
21092 + untested "Couldn't compile test program"
21098 +gdb_reinitialize_dir $srcdir/$subdir
21099 +gdb_load ${binfile}
21101 +if ![runto_main] {
21102 + untested x86_64-vla-typedef
21106 +gdb_breakpoint "break_here"
21108 +gdb_continue_to_breakpoint "break_here"
21110 +gdb_test "whatis array" "type = array_t" "first: whatis array"
21112 +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
21114 +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
21115 +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
21116 +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
21117 +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
21119 +gdb_continue_to_breakpoint "break_here"
21121 +gdb_test "whatis array" "type = array_t" "second: whatis array"
21123 +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
21124 diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
21125 index 98d4d35..f98a656 100644
21126 --- a/gdb/testsuite/gdb.base/arrayidx.c
21127 +++ b/gdb/testsuite/gdb.base/arrayidx.c
21130 int array[] = {1, 2, 3, 4};
21142 diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
21143 index 71ce4aa..af0e5f8 100644
21144 --- a/gdb/testsuite/gdb.base/arrayidx.exp
21145 +++ b/gdb/testsuite/gdb.base/arrayidx.exp
21146 @@ -59,4 +59,12 @@ gdb_test "print array" \
21147 "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
21148 "Print array with array-indexes on"
21151 +set test "p unbound.a == &unbound.a\[0\]"
21152 +gdb_test_multiple $test $test {
21153 + -re " = 1\r\n$gdb_prompt $" {
21156 + -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
21157 + unsupported "$test (no GCC)"
21160 diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
21161 index d76cc36..496ff18 100644
21162 --- a/gdb/testsuite/gdb.base/help.exp
21163 +++ b/gdb/testsuite/gdb.base/help.exp
21164 @@ -606,7 +606,7 @@ gdb_test "help stepi" "Step one instruction exactly\.\[\r\n\]+Argument N means d
21165 gdb_test "help signal" "Continue program giving it signal.*" "help signal"
21167 # vxgdb reads .vxgdbinit
21168 -gdb_test "help source" "Read commands from a file named FILE\.\[\r\n\]+Optional -v switch \\(before the filename\\) causes each command in\[\r\n\]+FILE to be echoed as it is executed\.\[\r\n\]+Note that the file \"\[^\"\]*\" is read automatically in this way\[\r\n\]+when GDB is started\." "help source"
21169 +gdb_test "help source" "Read commands from a file named FILE\.\[\r\n\]+Optional -v switch \\(before the filename\\) causes each command in\[\r\n\]+FILE to be echoed as it is executed\.\[\r\n\]+Note that the file \"\[^\"\]*\" is read automatically in this way\[\r\n\]+when GDB is started\.\[\r\n\]+Optional -p switch \\(before the filename\\) causes FILE to be evaluated\[\r\n\]+as Python code\." "help source"
21171 test_class_help "stack" {
21172 "Examining the stack\..*\[\r\n\]+"
21173 diff --git a/gdb/testsuite/gdb.base/lineno-makeup-func.c b/gdb/testsuite/gdb.base/lineno-makeup-func.c
21174 new file mode 100644
21175 index 0000000..1a0220e
21177 +++ b/gdb/testsuite/gdb.base/lineno-makeup-func.c
21179 +/* This testcase is part of GDB, the GNU debugger.
21181 + Copyright 2009 Free Software Foundation, Inc.
21183 + This program is free software; you can redistribute it and/or modify
21184 + it under the terms of the GNU General Public License as published by
21185 + the Free Software Foundation; either version 3 of the License, or
21186 + (at your option) any later version.
21188 + This program is distributed in the hope that it will be useful,
21189 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21190 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21191 + GNU General Public License for more details.
21193 + You should have received a copy of the GNU General Public License
21194 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21200 diff --git a/gdb/testsuite/gdb.base/lineno-makeup.c b/gdb/testsuite/gdb.base/lineno-makeup.c
21201 new file mode 100644
21202 index 0000000..bb20e98
21204 +++ b/gdb/testsuite/gdb.base/lineno-makeup.c
21206 +/* This testcase is part of GDB, the GNU debugger.
21208 + Copyright 2009 Free Software Foundation, Inc.
21210 + This program is free software; you can redistribute it and/or modify
21211 + it under the terms of the GNU General Public License as published by
21212 + the Free Software Foundation; either version 3 of the License, or
21213 + (at your option) any later version.
21215 + This program is distributed in the hope that it will be useful,
21216 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21217 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21218 + GNU General Public License for more details.
21220 + You should have received a copy of the GNU General Public License
21221 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21223 +/* DW_AT_low_pc-DW_AT_high_pc should cover the function without line number
21224 + information (.debug_line) so we cannot use an external object file.
21226 + It must not be just a label as it would alias on the next function even for
21227 + correct GDB. Therefore some stub data must be placed there.
21229 + We need to provide a real stub function body as at least s390
21230 + (s390_analyze_prologue) would skip the whole body till reaching `main'. */
21232 +extern void func (void);
21233 +asm ("func: .incbin \"gdb.base/lineno-makeup-func.bin\"");
21241 diff --git a/gdb/testsuite/gdb.base/lineno-makeup.exp b/gdb/testsuite/gdb.base/lineno-makeup.exp
21242 new file mode 100644
21243 index 0000000..0c75b84
21245 +++ b/gdb/testsuite/gdb.base/lineno-makeup.exp
21247 +# Copyright 2009 Free Software Foundation, Inc.
21249 +# This program is free software; you can redistribute it and/or modify
21250 +# it under the terms of the GNU General Public License as published by
21251 +# the Free Software Foundation; either version 3 of the License, or
21252 +# (at your option) any later version.
21254 +# This program is distributed in the hope that it will be useful,
21255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21257 +# GNU General Public License for more details.
21259 +# You should have received a copy of the GNU General Public License
21260 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21262 +set testfile "lineno-makeup"
21263 +set srcfuncfile ${testfile}-func.c
21264 +set srcfile ${testfile}.c
21265 +set objfuncfile ${objdir}/${subdir}/${testfile}-func.o
21266 +set binfuncfile ${objdir}/${subdir}/${testfile}-func.bin
21267 +set binfile ${objdir}/${subdir}/${testfile}
21269 +if { [gdb_compile "${srcdir}/${subdir}/${srcfuncfile}" "${objfuncfile}" object {}] != "" } {
21270 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21273 +set objcopy [catch "exec objcopy -O binary --only-section .text ${objfuncfile} ${binfuncfile}" output]
21274 +verbose -log "objcopy=$objcopy: $output"
21275 +if { $objcopy != 0 } {
21276 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21278 +set binfuncfilesize [file size $binfuncfile]
21279 +verbose -log "file size $binfuncfile = $binfuncfilesize"
21281 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21282 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21287 +gdb_reinitialize_dir $srcdir/$subdir
21288 +gdb_load ${binfile}
21291 +set test "break func"
21292 +gdb_test_multiple $test $test {
21293 + -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
21294 + set b_addr $expect_out(1,string)
21297 + -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+): .*\r\n$gdb_prompt $" {
21298 + set b_addr $expect_out(1,string)
21302 +verbose -log "b_addr=<$b_addr>"
21305 +set test "print func"
21306 +gdb_test_multiple $test $test {
21307 + -re "\\$\[0-9\]+ = {<text variable, no debug info>} (0x\[0-9a-f\]+) <func>\r\n$gdb_prompt $" {
21308 + set p_addr $expect_out(1,string)
21312 +verbose -log "p_addr=<$p_addr>"
21314 +set test "break address belongs to func"
21315 +if {$b_addr == $p_addr} {
21316 + pass "$test (exact match)"
21318 + set skip [expr $b_addr - $p_addr]
21319 + if {$skip > 0 && $skip < $binfuncfilesize} {
21320 + pass "$test (prologue skip by $skip bytes)"
21325 diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
21326 index 55c4d31..df25d3c 100644
21327 --- a/gdb/testsuite/gdb.base/macscp.exp
21328 +++ b/gdb/testsuite/gdb.base/macscp.exp
21329 @@ -33,6 +33,14 @@ if [test_compiler_info gcc*] {
21330 lappend options additional_flags=-g3
21333 +# Workaround ccache making lineno non-zero for command-line definitions.
21334 +if {[find_gcc] == "gcc" && [file executable "/usr/bin/gcc"]} {
21335 + set result [catch "exec which gcc" output]
21336 + if {$result == 0 && [string first "/ccache/" $output] >= -1} {
21337 + lappend options "compiler=/usr/bin/gcc"
21341 # Generate the intermediate object file. This is required by Darwin to
21342 # have access to the .debug_macinfo section.
21343 if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \
21344 diff --git a/gdb/testsuite/gdb.base/radix.exp b/gdb/testsuite/gdb.base/radix.exp
21345 index 750fd23..dfdb929 100644
21346 --- a/gdb/testsuite/gdb.base/radix.exp
21347 +++ b/gdb/testsuite/gdb.base/radix.exp
21348 @@ -162,13 +162,6 @@ gdb_test "set radix" \
21349 "Input and output radices now set to decimal 10, hex a, octal 12\." \
21352 -gdb_test "set input-radix 0" \
21353 - "Nonsense input radix ``decimal 0''; input radix unchanged\\." \
21354 - "Reject input-radix 0"
21355 -gdb_test "show input-radix" \
21356 - "Default input radix for entering numbers is 10\\." \
21357 - "Input radix unchanged after rejecting 0"
21359 gdb_test "set input-radix 1" \
21360 "Nonsense input radix ``decimal 1''; input radix unchanged\\." \
21361 "Reject input-radix 1"
21362 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.c b/gdb/testsuite/gdb.base/valgrind-attach.c
21363 new file mode 100644
21364 index 0000000..84b57db
21366 +++ b/gdb/testsuite/gdb.base/valgrind-attach.c
21368 +/* This testcase is part of GDB, the GNU debugger.
21370 + Copyright 2009 Free Software Foundation, Inc.
21372 + This program is free software; you can redistribute it and/or modify
21373 + it under the terms of the GNU General Public License as published by
21374 + the Free Software Foundation; either version 3 of the License, or
21375 + (at your option) any later version.
21377 + This program is distributed in the hope that it will be useful,
21378 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21379 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21380 + GNU General Public License for more details.
21382 + You should have received a copy of the GNU General Public License
21383 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21385 +#include <stdlib.h>
21390 + int *a = malloc (1);
21392 + a[10] = 0; /* crash-here */
21396 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.exp b/gdb/testsuite/gdb.base/valgrind-attach.exp
21397 new file mode 100644
21398 index 0000000..1f9b26e
21400 +++ b/gdb/testsuite/gdb.base/valgrind-attach.exp
21402 +# Copyright 2009 Free Software Foundation, Inc.
21404 +# This program is free software; you can redistribute it and/or modify
21405 +# it under the terms of the GNU General Public License as published by
21406 +# the Free Software Foundation; either version 3 of the License, or
21407 +# (at your option) any later version.
21409 +# This program is distributed in the hope that it will be useful,
21410 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21411 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21412 +# GNU General Public License for more details.
21414 +# You should have received a copy of the GNU General Public License
21415 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21417 +set testfile valgrind-attach
21418 +set shfile ${testfile}.sh
21419 +set srcfile ${testfile}.c
21420 +set binfile ${objdir}/${subdir}/${testfile}
21421 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21422 + untested "Couldn't compile test program"
21427 +gdb_stop_suppressing_tests;
21429 +set VALGRIND "valgrind"
21431 +# Syntax for ${shfile} is: <binfile> <valgrind> <db-command-arguments>
21432 +set VALGRIND_SPAWN "sh ${srcdir}/${subdir}/${shfile} $binfile $VALGRIND $GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"
21434 +set test "spawn valgrind"
21435 +verbose "Spawning $VALGRIND_SPAWN"
21437 +if [info exists gdb_spawn_id] {
21442 +if ![is_remote host] {
21443 + if { [which $VALGRIND] == 0 } then {
21444 + untested "Couldn't find $VALGRIND"
21448 +set res [remote_spawn host "$VALGRIND_SPAWN"]
21449 +if { $res < 0 || $res == "" } {
21450 + perror "Spawning $VALGRIND_SPAWN failed."
21453 +set gdb_spawn_id -1;
21456 + -re "---- Attach to debugger \\? --- \\\[Return/N/n/Y/y/C/c\\\] ---- $" {
21460 + perror "(eof) $VALGRIND never initialized"
21461 + remote_close host
21465 + perror "(timeout) $VALGRIND never initialized"
21466 + remote_close host
21472 +set test "spawn gdb"
21473 +set test2 "crash line caught"
21475 + -re "starting debugger with cmd:.* in main .* crash-here .*\[\r\n\]$gdb_prompt $" {
21479 + -re "starting debugger with cmd:.*\[\r\n\]$gdb_prompt $" {
21484 + perror "(eof) $GDB never initialized"
21485 + remote_close host
21489 + perror "(timeout) $GDB never initialized"
21490 + remote_close host
21496 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.sh b/gdb/testsuite/gdb.base/valgrind-attach.sh
21497 new file mode 100755
21498 index 0000000..f02c6f7
21500 +++ b/gdb/testsuite/gdb.base/valgrind-attach.sh
21504 +# Copyright 2009 Free Software Foundation, Inc.
21506 +# This program is free software; you can redistribute it and/or modify
21507 +# it under the terms of the GNU General Public License as published by
21508 +# the Free Software Foundation; either version 3 of the License, or
21509 +# (at your option) any later version.
21511 +# This program is distributed in the hope that it will be useful,
21512 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21513 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21514 +# GNU General Public License for more details.
21516 +# You should have received a copy of the GNU General Public License
21517 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21519 +BINFILE="$1"; shift
21520 +VALGRIND="$1"; shift
21521 +"$VALGRIND" --db-attach=yes --db-command="$* %f %p" "$BINFILE"
21522 diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
21523 new file mode 100644
21524 index 0000000..c5d5ee0
21526 +++ b/gdb/testsuite/gdb.base/vla-overflow.c
21528 +/* This testcase is part of GDB, the GNU debugger.
21530 + Copyright 2008 Free Software Foundation, Inc.
21532 + This program is free software; you can redistribute it and/or modify
21533 + it under the terms of the GNU General Public License as published by
21534 + the Free Software Foundation; either version 3 of the License, or
21535 + (at your option) any later version.
21537 + This program is distributed in the hope that it will be useful,
21538 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21539 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21540 + GNU General Public License for more details.
21542 + You should have received a copy of the GNU General Public License
21543 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21545 +#include <stdlib.h>
21548 +main (int argc, char **argv)
21552 + array[0] = array[0];
21558 diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
21559 new file mode 100644
21560 index 0000000..7203a48
21562 +++ b/gdb/testsuite/gdb.base/vla-overflow.exp
21564 +# Copyright 2008 Free Software Foundation, Inc.
21566 +# This program is free software; you can redistribute it and/or modify
21567 +# it under the terms of the GNU General Public License as published by
21568 +# the Free Software Foundation; either version 3 of the License, or
21569 +# (at your option) any later version.
21571 +# This program is distributed in the hope that it will be useful,
21572 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21573 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21574 +# GNU General Public License for more details.
21576 +# You should have received a copy of the GNU General Public License
21577 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21579 +# We could crash in:
21580 +# #0 block_linkage_function (bl=0x0) at ../../gdb/block.c:69
21581 +# #1 in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
21582 +# 97 framefunc = block_linkage_function (get_frame_block (frame, NULL));
21583 +# #2 in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
21584 +# #3 in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
21585 +# #4 dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
21586 +# #5 in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
21587 +# #6 in create_array_type (...) at ../../gdb/gdbtypes.c:840
21589 +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
21591 +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
21593 +set testfile vla-overflow
21594 +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
21595 +set srcfile ${testfile}.c
21596 +set binfile ${objdir}/${subdir}/${testfile}
21597 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21598 + untested "Couldn't compile test program"
21602 +set f [open "|getconf PAGESIZE" "r"]
21608 +gdb_reinitialize_dir $srcdir/$subdir
21609 +gdb_load ${binfile}
21611 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
21613 +if { [runto_main] < 0 } {
21614 + untested vla-overflow
21618 +# Get the GDB memory size when we stay at main.
21620 +proc memory_v_pages_get {} {
21621 + global pid_of_gdb pagesize
21622 + set fd [open "/proc/$pid_of_gdb/statm"]
21625 + # number of pages of virtual memory
21626 + scan $line "%d" drs
21630 +set pages_found [memory_v_pages_get]
21633 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
21634 +set kb_found [expr $pages_found * $pagesize / 1024]
21635 +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
21636 +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
21638 +# Create the ulimit wrapper.
21639 +set f [open $shfile "w"]
21640 +puts $f "#! /bin/sh"
21641 +puts $f "ulimit -v $kb_permit"
21642 +puts $f "exec $GDB \"\$@\""
21644 +remote_exec host "chmod +x $shfile"
21652 +gdb_reinitialize_dir $srcdir/$subdir
21653 +gdb_load ${binfile}
21655 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
21657 +# Check the size again after the second run.
21658 +# We must not stop in main as it would cache `array' and never crash later.
21662 +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21664 +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
21666 +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21668 +# `abort' can get expressed as `*__GI_abort'.
21669 +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
21671 +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21672 diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
21673 new file mode 100644
21674 index 0000000..e1f3ed1
21676 +++ b/gdb/testsuite/gdb.base/vla.c
21678 +/* This testcase is part of GDB, the GNU debugger.
21680 + Copyright 2008 Free Software Foundation, Inc.
21682 + This program is free software; you can redistribute it and/or modify
21683 + it under the terms of the GNU General Public License as published by
21684 + the Free Software Foundation; either version 3 of the License, or
21685 + (at your option) any later version.
21687 + This program is distributed in the hope that it will be useful,
21688 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21689 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21690 + GNU General Public License for more details.
21692 + You should have received a copy of the GNU General Public License
21693 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21695 +#include <string.h>
21703 +bar (char *a, char *b, char *c, int size)
21705 + memset (a, '1', size);
21706 + memset (b, '2', size);
21707 + memset (c, '3', 48);
21713 + char temp1[size];
21716 + temp1[size - 1] = '\0';
21718 + char temp2[size];
21720 + bar (temp1, temp2, temp3, size);
21722 + marker (); /* break-here */
21733 diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
21734 new file mode 100644
21735 index 0000000..5da7378
21737 +++ b/gdb/testsuite/gdb.base/vla.exp
21739 +# Copyright 2008 Free Software Foundation, Inc.
21741 +# This program is free software; you can redistribute it and/or modify
21742 +# it under the terms of the GNU General Public License as published by
21743 +# the Free Software Foundation; either version 3 of the License, or
21744 +# (at your option) any later version.
21746 +# This program is distributed in the hope that it will be useful,
21747 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21748 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21749 +# GNU General Public License for more details.
21751 +# You should have received a copy of the GNU General Public License
21752 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21755 +set srcfile ${testfile}.c
21756 +set binfile ${objdir}/${subdir}/${testfile}
21757 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21758 + untested "Couldn't compile test program"
21764 +gdb_reinitialize_dir $srcdir/$subdir
21765 +gdb_load ${binfile}
21767 +if ![runto_main] {
21772 +gdb_breakpoint [gdb_get_line_number "break-here"]
21774 +gdb_continue_to_breakpoint "break-here"
21776 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
21777 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
21778 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
21780 +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
21781 +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
21782 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
21784 +gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
21785 +gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
21786 +gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
21788 +gdb_continue_to_breakpoint "break-here"
21790 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
21791 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
21792 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
21794 +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
21795 +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
21796 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
21798 +gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
21799 +gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
21800 +gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
21801 diff --git a/gdb/testsuite/gdb.base/watchpoint-hw.c b/gdb/testsuite/gdb.base/watchpoint-hw.c
21802 index 8da9af5..e2de53a 100644
21803 --- a/gdb/testsuite/gdb.base/watchpoint-hw.c
21804 +++ b/gdb/testsuite/gdb.base/watchpoint-hw.c
21805 @@ -20,5 +20,11 @@ int watchee;
21809 + volatile int dummy;
21813 + dummy = 2; /* break-at-exit */
21817 diff --git a/gdb/testsuite/gdb.base/watchpoint-hw.exp b/gdb/testsuite/gdb.base/watchpoint-hw.exp
21818 index a2bb731..d74d6c7 100644
21819 --- a/gdb/testsuite/gdb.base/watchpoint-hw.exp
21820 +++ b/gdb/testsuite/gdb.base/watchpoint-hw.exp
21821 @@ -21,19 +21,12 @@ if {(![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"]
21825 -set testfile watchpoint-hw
21826 -set srcfile ${testfile}.c
21827 -set binfile ${objdir}/${subdir}/${testfile}
21828 -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21829 - untested "Couldn't compile test program"
21830 +set test watchpoint-hw
21831 +set srcfile ${test}.c
21832 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile}] } {
21838 -gdb_reinitialize_dir $srcdir/$subdir
21839 -gdb_load ${binfile}
21841 # Create the watchpoint before the inferior gets started. Now the native CPU
21842 # target is still not active and its `to_can_use_hw_breakpoint' is not
21843 # installed, therefore only a software watchpoint gets created.
21844 @@ -43,10 +36,40 @@ gdb_test "watch watchee" "atchpoint 1: watchee"
21845 # `runto_main' or `runto main' would delete the watchpoint created above.
21847 if { [gdb_start_cmd] < 0 } {
21849 + untested ${test}.exp
21852 gdb_test "" "main .* at .*" "start"
21854 # Check it is really a `hw'-watchpoint.
21855 gdb_test "info watchpoints" "1 *hw watchpoint .* watchee"
21857 +# Before the inferior gets started we would get:
21858 +# Target does not support this type of hardware watchpoint.
21859 +gdb_test "delete 1"
21860 +gdb_test "rwatch watchee"
21862 +set breakline [gdb_get_line_number "break-at-exit"]
21863 +gdb_breakpoint $breakline
21865 +gdb_test "continue" "Continuing.\r\nHardware read watchpoint 3: watchee\r\n\r\nValue = 0\r\n.*"
21867 +# Here should be no repeated notification of the read watchpoint.
21868 +gdb_test "continue" \
21869 + "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \
21870 + "continue to break-at-exit after rwatch"
21872 +clean_restart ${test}
21874 +if ![runto_main] {
21875 + untested ${test}.exp
21879 +gdb_test "hbreak ${srcfile}:${breakline}" \
21880 + "Hardware assisted breakpoint 2 at 0x\[0-9a-f\]+: file .*${srcfile}, line ${breakline}\\." \
21883 +gdb_test "continue" \
21884 + "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \
21885 + "continue to break-at-exit after hbreak"
21886 diff --git a/gdb/testsuite/gdb.cp/Makefile.in b/gdb/testsuite/gdb.cp/Makefile.in
21887 index 0a087c7..b4880f2 100644
21888 --- a/gdb/testsuite/gdb.cp/Makefile.in
21889 +++ b/gdb/testsuite/gdb.cp/Makefile.in
21890 @@ -4,7 +4,7 @@ srcdir = @srcdir@
21891 EXECUTABLES = ambiguous annota2 anon-union cplusfuncs cttiadd \
21892 derivation inherit local member-ptr method misc \
21893 overload ovldbreak ref-typ ref-typ2 templates userdef virtfunc namespace \
21894 - ref-types ref-params method2 pr9594 gdb2495
21895 + ref-types ref-params method2 pr9594 gdb2495 gdb9593
21897 all info install-info dvi install uninstall installcheck check:
21898 @echo "Nothing to be done for $@..."
21899 diff --git a/gdb/testsuite/gdb.cp/cp-relocate.exp b/gdb/testsuite/gdb.cp/cp-relocate.exp
21900 index 4095ccf..03c07d5 100644
21901 --- a/gdb/testsuite/gdb.cp/cp-relocate.exp
21902 +++ b/gdb/testsuite/gdb.cp/cp-relocate.exp
21903 @@ -30,7 +30,7 @@ proc get_func_address { func } {
21904 global gdb_prompt hex
21906 set rfunc [string_to_regexp $func]
21907 - gdb_test_multiple "print '${func}'" "get address of ${func}" {
21908 + gdb_test_multiple "print ${func}" "get address of ${func}" {
21909 -re "\\\$\[0-9\]+ = \\{.*\\} (0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
21910 # $1 = {int ()} 0x24 <function_bar>
21911 # But if the function is at zero, the name may be omitted.
21912 @@ -130,7 +130,7 @@ gdb_test "add-symbol-file ${binfile} 0 -s ${func1_sec} 0x10000 -s ${func2_sec} 0
21915 # Make sure the function addresses were updated.
21916 -gdb_test "break *'$func1_name'" \
21917 +gdb_test "break *$func1_name" \
21918 "Breakpoint $decimal at 0x1....: file .*"
21919 -gdb_test "break *'$func2_name'" \
21920 +gdb_test "break *$func2_name" \
21921 "Breakpoint $decimal at 0x2....: file .*"
21922 diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.cc b/gdb/testsuite/gdb.cp/cplusfuncs.cc
21923 index 7f033d6..11dba06 100644
21924 --- a/gdb/testsuite/gdb.cp/cplusfuncs.cc
21925 +++ b/gdb/testsuite/gdb.cp/cplusfuncs.cc
21926 @@ -46,7 +46,9 @@ public:
21927 void operator [] (foo&);
21928 void operator () (foo&);
21929 void* operator new (size_t) throw ();
21930 + void* operator new[] (size_t) throw ();
21931 void operator delete (void *);
21932 + void operator delete[] (void *);
21933 /**/ operator int ();
21934 /**/ operator char* ();
21936 @@ -115,7 +117,9 @@ void foo::operator ->* (foo& afoo) { afoo.ifoo = 0; }
21937 void foo::operator [] (foo& afoo) { afoo.ifoo = 0; }
21938 void foo::operator () (foo& afoo) { afoo.ifoo = 0; }
21939 void* foo::operator new (size_t ival) throw () { ival = 0; return 0; }
21940 +void* foo::operator new[] (size_t ival) throw () { ival = 0; return 0; }
21941 void foo::operator delete (void *ptr) { ptr = 0; }
21942 +void foo::operator delete[] (void *ptr) { ptr = 0; }
21943 /**/ foo::operator int () { return 0; }
21944 /**/ foo::operator char* () { return 0; }
21946 @@ -191,6 +195,12 @@ char * dm_type_char_star (char * p) { return p; }
21947 int dm_type_foo_ref (foo & foo) { return foo.ifoo; }
21948 int * dm_type_int_star (int * p) { return p; }
21949 long * dm_type_long_star (long * p) { return p; }
21950 +int dm_type_short (short i) { return i; }
21951 +int dm_type_long (long i) { return i; }
21952 int dm_type_unsigned_int (unsigned int i) { return i; }
21953 +int dm_type_unsigned_short (unsigned short i) { return i; }
21954 +int dm_type_unsigned_long (unsigned long i) { return i; }
21955 int dm_type_void (void) { return 0; }
21956 void * dm_type_void_star (void * p) { return p; }
21957 +typedef int myint;
21958 +int dm_type_typedef (myint i) { return i; }
21959 diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp
21960 index 5e08768..2ec50ca 100644
21961 --- a/gdb/testsuite/gdb.cp/cplusfuncs.exp
21962 +++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp
21963 @@ -63,12 +63,28 @@ set dm_type_foo_ref "foo&"
21964 set dm_type_int_star "int*"
21965 set dm_type_long_star "long*"
21966 set dm_type_unsigned_int "unsigned"
21967 -set dm_type_void ""
21968 +set dm_type_void "void"
21969 set dm_type_void_star "void*"
21971 +# Some other vagaries of GDB's type printing machinery. The integer types
21972 +# may have unsigned before or after their length, and may have "int"
21973 +# appended. The char* conversion operator may have name "char*" even if
21974 +# the type is "char *", because the name comes from the debug information
21975 +# and the type from GDB. Function types may not see through typedefs.
21977 +set dm_type_short "short"
21978 +set dm_type_long "long"
21979 +set dm_type_unsigned_short "unsigned short"
21980 +set dm_type_unsigned_long "unsigned long"
21981 +set dm_operator_char_star "char*"
21982 +set dm_operator_char_star_quoted "char\\*"
21983 +set dm_type_typedef 0
21985 proc probe_demangler { } {
21987 global dm_operator_comma
21988 + global dm_operator_char_star
21989 + global dm_operator_char_star_quoted
21990 global dm_type_char_star
21991 global dm_type_char_star_quoted
21992 global dm_type_foo_ref
21993 @@ -77,8 +93,13 @@ proc probe_demangler { } {
21994 global dm_type_unsigned_int
21995 global dm_type_void
21996 global dm_type_void_star
21997 + global dm_type_short
21998 + global dm_type_unsigned_short
21999 + global dm_type_long
22000 + global dm_type_unsigned_long
22001 + global dm_type_typedef
22003 - send_gdb "print &'foo::operator,(foo&)'\n"
22004 + send_gdb "print &foo::operator,(foo&)\n"
22006 -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
22008 @@ -97,6 +118,26 @@ proc probe_demangler { } {
22012 + send_gdb "print &foo::operator char*($dm_type_void)\n"
22014 + -re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
22015 + # v2 demangler or GDB type printer
22016 + set dm_operator_char_star "char *"
22017 + set dm_operator_char_star_quoted "char \\*"
22018 + pass "detect dm_operator_char_star"
22020 + -re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
22022 + pass "detect dm_operator_char_star"
22024 + -re ".*$gdb_prompt $" {
22025 + fail "detect dm_operator_char_star"
22028 + fail "detect dm_operator_char_star"
22032 send_gdb "print &'dm_type_char_star'\n"
22034 -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
22035 @@ -166,6 +207,11 @@ proc probe_demangler { } {
22037 pass "detect dm_type_long_star"
22039 + -re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
22040 + # GCC v3 and GDB's type printer
22041 + set dm_type_long_star "long int *"
22042 + pass "detect dm_type_long_star"
22044 -re ".*$gdb_prompt $" {
22045 fail "detect dm_type_long_star"
22047 @@ -230,6 +276,101 @@ proc probe_demangler { } {
22048 fail "detect dm_type_void_star (timeout)"
22052 + send_gdb "print &'dm_type_short'\n"
22054 + -re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
22055 + # v2 and v3 demanglers
22056 + pass "detect dm_type_short"
22058 + -re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
22059 + # GDB type printer
22060 + set dm_type_short "short int"
22061 + pass "detect dm_type_short"
22063 + -re ".*$gdb_prompt $" {
22064 + fail "detect dm_type_short"
22067 + fail "detect dm_type_short (timeout)"
22071 + send_gdb "print &'dm_type_unsigned_short'\n"
22073 + -re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
22074 + # v2 and v3 demanglers
22075 + pass "detect dm_type_unsigned_short"
22077 + -re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
22078 + # GDB type printer
22079 + set dm_type_unsigned_short "short unsigned int"
22080 + pass "detect dm_type_unsigned_short"
22082 + -re ".*$gdb_prompt $" {
22083 + fail "detect dm_type_unsigned_short"
22086 + fail "detect dm_type_unsigned_short (timeout)"
22090 + send_gdb "print &'dm_type_long'\n"
22092 + -re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
22093 + # v2 and v3 demanglers
22094 + pass "detect dm_type_long"
22096 + -re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
22097 + # GDB type printer
22098 + set dm_type_long "long int"
22099 + pass "detect dm_type_long"
22101 + -re ".*$gdb_prompt $" {
22102 + fail "detect dm_type_long"
22105 + fail "detect dm_type_long (timeout)"
22109 + send_gdb "print &'dm_type_unsigned_long'\n"
22111 + -re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
22112 + # v2 and v3 demanglers
22113 + pass "detect dm_type_unsigned_long"
22115 + -re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
22116 + # GDB type printer
22117 + set dm_type_unsigned_long "long unsigned int"
22118 + pass "detect dm_type_unsigned_long"
22120 + -re ".*$gdb_prompt $" {
22121 + fail "detect dm_type_unsigned_long"
22124 + fail "detect dm_type_unsigned_long (timeout)"
22128 + send_gdb "print &'dm_type_typedef'\n"
22130 + -re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
22131 + # v2 and v3 demanglers
22132 + pass "detect dm_type_typedef"
22134 + -re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
22135 + # GDB type printer
22136 + set dm_type_typedef 1
22137 + pass "detect dm_type_typedef"
22139 + -re ".*$gdb_prompt $" {
22140 + fail "detect dm_type_typedef"
22143 + fail "detect dm_type_typedef (timeout)"
22149 @@ -241,6 +382,7 @@ proc info_func_regexp { name demangled } {
22152 send_gdb "info function $name\n"
22153 + set demangled [regsub {\\\(void\\\)} $demangled {\(\)}]
22155 -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
22156 pass "info function for \"$name\""
22157 @@ -277,16 +419,16 @@ proc print_addr_2 { name good } {
22159 set good_pattern [string_to_regexp $good]
22161 - send_gdb "print &'$name'\n"
22162 + send_gdb "print &$name\n"
22164 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
22165 - pass "print &'$name'"
22166 + pass "print &$name"
22168 -re ".*$gdb_prompt $" {
22169 - fail "print &'$name'"
22170 + fail "print &$name"
22173 - fail "print &'$name' (timeout)"
22174 + fail "print &$name (timeout)"
22178 @@ -327,7 +469,12 @@ proc print_addr_2_kfail { name good bad bugid } {
22181 proc print_addr { name } {
22182 - print_addr_2 "$name" "$name"
22183 + set expected [regsub {\(void\)} $name {()}]
22184 + if {[string first "::" $name] == -1} {
22185 + # C function -- must be qutoed
22186 + set name "'$name'"
22188 + print_addr_2 "$name" $expected
22192 @@ -345,8 +492,9 @@ proc print_addr { name } {
22194 proc test_lookup_operator_functions {} {
22195 global dm_operator_comma
22196 + global dm_operator_char_star
22197 global dm_type_char_star
22198 - global dm_type_char_star_quoted
22199 + global dm_operator_char_star_quoted
22200 global dm_type_foo_ref
22201 global dm_type_void
22202 global dm_type_void_star
22203 @@ -404,8 +552,8 @@ proc test_lookup_operator_functions {} {
22205 info_func "operator int(" "int foo::operator int($dm_type_void);"
22206 info_func "operator()(" "void foo::operator()($dm_type_foo_ref);"
22207 - info_func "operator $dm_type_char_star_quoted\(" \
22208 - "char *foo::operator $dm_type_char_star\($dm_type_void);"
22209 + info_func "operator $dm_operator_char_star_quoted\(" \
22210 + "char *foo::operator $dm_operator_char_star\($dm_type_void);"
22214 @@ -420,6 +568,7 @@ proc test_paddr_operator_functions {} {
22215 global dm_type_unsigned_int
22216 global dm_type_void
22217 global dm_type_void_star
22218 + global dm_operator_char_star
22220 print_addr "foo::operator*($dm_type_foo_ref)"
22221 print_addr "foo::operator%($dm_type_foo_ref)"
22222 @@ -460,17 +609,20 @@ proc test_paddr_operator_functions {} {
22223 print_addr "foo::operator\[\]($dm_type_foo_ref)"
22224 print_addr "foo::operator()($dm_type_foo_ref)"
22226 - gdb_test "print &'foo::operator new'" \
22227 + gdb_test "print &foo::operator new" \
22228 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
22229 + gdb_test "print &foo::operator new\[\]" \
22230 + " = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"
22231 if { !$hp_aCC_compiler } {
22232 print_addr "foo::operator delete($dm_type_void_star)"
22233 + print_addr "foo::operator delete[]($dm_type_void_star)"
22235 gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
22236 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
22239 print_addr "foo::operator int($dm_type_void)"
22240 - print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
22241 + print_addr "foo::operator $dm_operator_char_star\($dm_type_void)"
22245 @@ -480,17 +632,21 @@ proc test_paddr_operator_functions {} {
22246 proc test_paddr_overloaded_functions {} {
22247 global dm_type_unsigned_int
22248 global dm_type_void
22249 + global dm_type_short
22250 + global dm_type_unsigned_short
22251 + global dm_type_long
22252 + global dm_type_unsigned_long
22254 print_addr "overload1arg($dm_type_void)"
22255 print_addr "overload1arg(char)"
22256 print_addr "overload1arg(signed char)"
22257 print_addr "overload1arg(unsigned char)"
22258 - print_addr "overload1arg(short)"
22259 - print_addr "overload1arg(unsigned short)"
22260 + print_addr "overload1arg($dm_type_short)"
22261 + print_addr "overload1arg($dm_type_unsigned_short)"
22262 print_addr "overload1arg(int)"
22263 print_addr "overload1arg($dm_type_unsigned_int)"
22264 - print_addr "overload1arg(long)"
22265 - print_addr "overload1arg(unsigned long)"
22266 + print_addr "overload1arg($dm_type_long)"
22267 + print_addr "overload1arg($dm_type_unsigned_long)"
22268 print_addr "overload1arg(float)"
22269 print_addr "overload1arg(double)"
22271 @@ -513,17 +669,31 @@ proc test_paddr_hairy_functions {} {
22272 global dm_type_char_star
22273 global dm_type_int_star
22274 global dm_type_long_star
22275 + global dm_type_typedef
22277 print_addr_2 "hairyfunc1" "hairyfunc1(int)"
22278 - print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
22279 - print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
22280 - print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
22282 - # gdb-gnats bug gdb/19:
22283 - # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22284 - print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
22285 - print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
22286 - print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
22288 + if {$dm_type_typedef == 0} {
22289 + print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
22290 + print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
22291 + print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
22293 + # gdb-gnats bug gdb/19:
22294 + # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22295 + print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
22296 + print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
22297 + print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
22299 + print_addr_2 "hairyfunc2" "hairyfunc2(PFPc_i)"
22300 + print_addr_2 "hairyfunc3" "hairyfunc3(PFPFPl_s_i)"
22301 + print_addr_2 "hairyfunc4" "hairyfunc4(PFPFPc_s_i)"
22303 + # gdb-gnats bug gdb/19:
22304 + # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22305 + print_addr_2 "hairyfunc5" "hairyfunc5(PFPc_PFl_i)"
22306 + print_addr_2 "hairyfunc6" "hairyfunc6(PFPi_PFl_i)"
22307 + print_addr_2 "hairyfunc7" "hairyfunc7(PFPFPc_i_PFl_i)"
22312 @@ -534,6 +704,7 @@ proc do_tests {} {
22316 + global dm_type_int_star
22320 @@ -557,6 +728,10 @@ proc do_tests {} {
22321 test_paddr_operator_functions
22322 test_paddr_hairy_functions
22323 test_lookup_operator_functions
22325 + # A regression test on errors involving operators
22326 + gdb_test "list foo::operator $dm_type_int_star" \
22327 + ".*the class foo does not have any method named operator $dm_type_int_star.*"
22331 diff --git a/gdb/testsuite/gdb.cp/expand-sals.exp b/gdb/testsuite/gdb.cp/expand-sals.exp
22332 index 3c302c3..cd0496d 100644
22333 --- a/gdb/testsuite/gdb.cp/expand-sals.exp
22334 +++ b/gdb/testsuite/gdb.cp/expand-sals.exp
22335 @@ -48,7 +48,7 @@ gdb_continue_to_breakpoint "caller" ".*caller-line.*"
22337 # Test GDB caught this return call and not the next one through B::B()
22339 - "#0 \[^\r\n\]* A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
22340 + "#0 \[^\r\n\]* (A::)?A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
22343 gdb_continue_to_breakpoint "next caller func" ".*func-line.*"
22344 diff --git a/gdb/testsuite/gdb.cp/gdb9593.cc b/gdb/testsuite/gdb.cp/gdb9593.cc
22345 new file mode 100644
22346 index 0000000..783c962
22348 +++ b/gdb/testsuite/gdb.cp/gdb9593.cc
22350 +/* This testcase is part of GDB, the GNU debugger.
22352 + Copyright 2008, 2009 Free Software Foundation, Inc.
22354 + This program is free software; you can redistribute it and/or modify
22355 + it under the terms of the GNU General Public License as published by
22356 + the Free Software Foundation; either version 3 of the License, or
22357 + (at your option) any later version.
22359 + This program is distributed in the hope that it will be useful,
22360 + but WITHOUT ANY WARRANTY; without even the implied warranty of
22361 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22362 + GNU General Public License for more details.
22364 + You should have received a copy of the GNU General Public License
22365 + along with this program. If not, see <http://www.gnu.org/licenses/>.
22367 +#include <iostream>
22369 +using namespace std;
22371 +class NextOverThrowDerivates
22377 + // Single throw an exception in this function.
22383 + // Throw an exception in another function.
22389 + // Throw an exception in another function, but handle it
22391 + void function3 ()
22400 + cout << "Caught and handled function1 exception" << endl;
22419 + // We use this to test that a "finish" here does not end up in
22420 + // this frame, but in the one above.
22428 + function1 (); // marker for until
22434 + function1 (); // until here
22438 +NextOverThrowDerivates next_cases;
22445 + next_cases.function1 ();
22454 + next_cases.function2 ();
22463 + // This is duplicated so we can next over one but step into
22465 + next_cases.function2 ();
22472 + next_cases.function3 ();
22476 + next_cases.rethrow ();
22485 + // Another duplicate so we can test "finish".
22486 + next_cases.function2 ();
22493 + // Another test for "finish".
22496 + next_cases.finish ();
22502 + // Test of "until".
22505 + next_cases.finish ();
22511 + // Test of "until" with an argument.
22514 + next_cases.until ();
22520 + // Test of "advance".
22523 + next_cases.until ();
22530 diff --git a/gdb/testsuite/gdb.cp/gdb9593.exp b/gdb/testsuite/gdb.cp/gdb9593.exp
22531 new file mode 100644
22532 index 0000000..ee9aeff
22534 +++ b/gdb/testsuite/gdb.cp/gdb9593.exp
22536 +# Copyright 2008, 2009 Free Software Foundation, Inc.
22538 +# This program is free software; you can redistribute it and/or modify
22539 +# it under the terms of the GNU General Public License as published by
22540 +# the Free Software Foundation; either version 3 of the License, or
22541 +# (at your option) any later version.
22543 +# This program is distributed in the hope that it will be useful,
22544 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22545 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22546 +# GNU General Public License for more details.
22548 +# You should have received a copy of the GNU General Public License
22549 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22552 +if $tracelevel then {
22553 + strace $tracelevel
22556 +if { [skip_cplus_tests] } { continue }
22561 +set testfile "gdb9593"
22562 +set srcfile ${testfile}.cc
22563 +set binfile $objdir/$subdir/$testfile
22565 +# Create and source the file that provides information about the compiler
22566 +# used to compile the test case.
22567 +if [get_compiler_info ${binfile} "c++"] {
22568 + untested gdb9593.exp
22572 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22573 + untested gdb9593.exp
22577 +# Some targets can't do function calls, so don't even bother with this
22579 +if [target_info exists gdb,cannot_call_functions] {
22580 + setup_xfail "*-*-*" 9593
22581 + fail "This target can not call functions"
22587 +gdb_reinitialize_dir $srcdir/$subdir
22588 +gdb_load ${binfile}
22590 +if ![runto_main] then {
22591 + perror "couldn't run to main"
22595 +# See whether we have the needed unwinder hooks.
22597 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
22598 + -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
22599 + pass "check for unwinder hook"
22601 + -re "No symbol .* in current context.\r\n$gdb_prompt $" {
22602 + # Pass the test so we don't get bogus fails in the results.
22603 + pass "check for unwinder hook"
22608 + untested gdb9593.exp
22612 +# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
22615 + ".*catch (...).*" \
22616 + "next over a throw 1"
22619 + ".*next_cases.function2.*" \
22620 + "next past catch 1"
22623 + ".*catch (...).*" \
22624 + "next over a throw 2"
22627 + ".*next_cases.function2.*" \
22628 + "next past catch 2"
22631 + ".*function1().*" \
22632 + "step into function2 1"
22635 + ".*catch (...).*" \
22636 + "next over a throw 3"
22639 + ".*next_cases.function3.*" \
22640 + "next past catch 3"
22643 + ".*next_cases.rethrow.*" \
22644 + "next over a throw 4"
22647 + ".*catch (...).*" \
22648 + "next over a rethrow"
22651 + ".*next_cases.function2.*" \
22652 + "next after a rethrow"
22655 + ".*function1().*" \
22656 + "step into function2 2"
22658 +gdb_test "finish" \
22659 + ".*catch (...).*" \
22663 + ".*next_cases.finish ().*" \
22664 + "next past catch 4"
22667 + ".*function1 ().*" \
22668 + "step into finish method"
22670 +gdb_test "finish" \
22671 + ".*catch (...).*" \
22675 + ".*next_cases.finish ().*" \
22676 + "next past catch 5"
22679 + ".*function1 ().*" \
22680 + "step into finish, for until"
22682 +gdb_test "until" \
22683 + ".*catch .int x.*" \
22684 + "until with no argument 1"
22686 +set line [gdb_get_line_number "marker for until" $testfile.cc]
22688 +gdb_test "until $line" \
22689 + ".*function1 ().*" \
22690 + "next past catch 6"
22692 +gdb_test "until" \
22693 + ".*catch (...).*" \
22694 + "until with no argument 2"
22696 +set line [gdb_get_line_number "until here" $testfile.cc]
22699 + ".*next_cases.until ().*" \
22700 + "next past catch 6"
22703 + ".*function1 ().*" \
22704 + "step into until"
22706 +gdb_test "until $line" \
22707 + ".*catch (...).*" \
22708 + "until-over-throw"
22711 + ".*next_cases.until ().*" \
22712 + "next past catch 7"
22715 + ".*function1 ().*" \
22716 + "step into until, for advance"
22718 +gdb_test "advance $line" \
22719 + ".*catch (...).*" \
22720 + "advance-over-throw"
22721 diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
22722 index 1dff70a..648b2af 100644
22723 --- a/gdb/testsuite/gdb.cp/member-ptr.cc
22724 +++ b/gdb/testsuite/gdb.cp/member-ptr.cc
22725 @@ -138,6 +138,7 @@ class Diamond : public Padding, public Left, public Right
22728 virtual int vget_base ();
22729 + int (*func_ptr) (int);
22732 int Diamond::vget_base ()
22733 @@ -145,6 +146,12 @@ int Diamond::vget_base ()
22734 return this->Left::x + 2000;
22746 @@ -162,6 +169,7 @@ int main ()
22747 int (Diamond::*right_vpmf) ();
22748 int (Base::*base_vpmf) ();
22749 int Diamond::*diamond_pmi;
22750 + int (* Diamond::*diamond_pfunc_ptr) (int);
22754 @@ -179,6 +187,7 @@ int main ()
22756 diamond.Left::x = 77;
22757 diamond.Right::x = 88;
22758 + diamond.func_ptr = func;
22760 /* Some valid pointer to members from a base class. */
22761 left_pmf = (int (Diamond::*) ()) (int (Left::*) ()) (&Base::get_x);
22762 @@ -193,11 +202,19 @@ int main ()
22763 /* A pointer to data member from a base class. */
22764 diamond_pmi = (int Diamond::*) (int Left::*) &Base::x;
22766 + /* A pointer to data member, where the member is itself a pointer to
22768 + diamond_pfunc_ptr = (int (* Diamond::*) (int)) &Diamond::func_ptr;
22773 pmi = NULL; /* Breakpoint 1 here. */
22775 + // Invalid (uses diamond_pfunc_ptr as a function):
22776 + // diamond.*diamond_pfunc_ptr (20);
22777 + (diamond.*diamond_pfunc_ptr) (20);
22782 diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
22783 index b69d4ad..83dd0d5 100644
22784 --- a/gdb/testsuite/gdb.cp/member-ptr.exp
22785 +++ b/gdb/testsuite/gdb.cp/member-ptr.exp
22786 @@ -390,6 +390,33 @@ gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
22790 +# Check pointers to data members, which are themselves pointers to
22791 +# functions. These behave like data members, not like pointers to
22792 +# member functions.
22794 +gdb_test "ptype diamond_pfunc_ptr" \
22795 + "type = int \\(\\*Diamond::\\*\\)\\(int\\)"
22797 +gdb_test "ptype diamond.*diamond_pfunc_ptr" \
22798 + "type = int \\(\\*\\)\\(int\\)"
22800 +# This one is invalid; () binds more tightly than .*, so it tries to
22801 +# call the member pointer as a normal pointer-to-function.
22803 +gdb_test "print diamond.*diamond_pfunc_ptr (20)" \
22804 + "Invalid data type for function to be called."
22806 +# With parentheses, it is valid.
22808 +gdb_test "print (diamond.*diamond_pfunc_ptr) (20)" \
22811 +# Make sure that we do not interpret this as either a member pointer
22812 +# call or a member function call.
22814 +gdb_test "print diamond.func_ptr (20)" \
22817 # ==========================
22818 # pointer to member function
22819 # ==========================
22820 @@ -420,7 +447,7 @@ gdb_test_multiple "ptype pmf" $name {
22822 set name "print pmf"
22823 gdb_test_multiple "print pmf" $name {
22824 - -re "$vhn = $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
22825 + -re "$vhn = \\(int \\(A::\\*\\)\\(A \\*, int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
22828 -re "$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
22829 @@ -608,6 +635,9 @@ gdb_test_multiple "print (a.*pmf)(3)" $name {
22833 +gdb_test "ptype a.*pmf" "type = int \\(A \\*, int\\)"
22834 +gdb_test "ptype (a.*pmf)(3)" "type = int"
22836 # Print out a pointer to data member which requires looking into
22838 gdb_test "print diamond_pmi" "$vhn = &Base::x"
22839 @@ -658,5 +688,5 @@ gdb_test "print null_pmi = &A::j" "$vhn = &A::j"
22840 gdb_test "print null_pmi = 0" "$vhn = NULL"
22842 gdb_test "print null_pmf" "$vhn = NULL"
22843 -gdb_test "print null_pmf = &A::foo" "$vhn = $hex <A::foo ?\\(int\\)>"
22844 +gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*, int\\)\\) $hex <A::foo ?\\(int\\)>"
22845 gdb_test "print null_pmf = 0" "$vhn = NULL"
22846 diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
22847 new file mode 100644
22848 index 0000000..6b180d6
22850 +++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
22859 +using namespace A;
22872 diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
22873 new file mode 100644
22874 index 0000000..e4bb9f8
22876 +++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
22878 +# Copyright 2008 Free Software Foundation, Inc.
22880 +# This program is free software; you can redistribute it and/or modify
22881 +# it under the terms of the GNU General Public License as published by
22882 +# the Free Software Foundation; either version 3 of the License, or
22883 +# (at your option) any later version.
22885 +# This program is distributed in the hope that it will be useful,
22886 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22887 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22888 +# GNU General Public License for more details.
22890 +# You should have received a copy of the GNU General Public License
22891 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22893 +if $tracelevel then {
22894 + strace $tracelevel
22900 +set testfile namespace-multiple-imports
22901 +set srcfile ${testfile}.cc
22902 +set binfile ${objdir}/${subdir}/${testfile}
22903 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22904 + untested "Couldn't compile test program"
22908 +# Get things started.
22912 +gdb_reinitialize_dir $srcdir/$subdir
22913 +gdb_load ${binfile}
22915 +############################################
22916 +# test printing of namespace imported within
22919 +if ![runto_main] then {
22920 + perror "couldn't run to breakpoint main"
22924 +gdb_test "print x" "\\$\[0-9\].* = 11"
22925 +gdb_test "print xx" "\\$\[0-9\].* = 22"
22926 +gdb_test "print xxx" "\\$\[0-9\].* = 33"
22927 diff --git a/gdb/testsuite/gdb.cp/namespace-nested-imports.cc b/gdb/testsuite/gdb.cp/namespace-nested-imports.cc
22928 new file mode 100644
22929 index 0000000..9723f87
22931 +++ b/gdb/testsuite/gdb.cp/namespace-nested-imports.cc
22945 + using namespace A::B;
22959 + return D::second();
22967 + return C::first();
22969 diff --git a/gdb/testsuite/gdb.cp/namespace-nested-imports.exp b/gdb/testsuite/gdb.cp/namespace-nested-imports.exp
22970 new file mode 100644
22971 index 0000000..d279fb5
22973 +++ b/gdb/testsuite/gdb.cp/namespace-nested-imports.exp
22975 +# Copyright 2008 Free Software Foundation, Inc.
22977 +# This program is free software; you can redistribute it and/or modify
22978 +# it under the terms of the GNU General Public License as published by
22979 +# the Free Software Foundation; either version 3 of the License, or
22980 +# (at your option) any later version.
22982 +# This program is distributed in the hope that it will be useful,
22983 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22984 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22985 +# GNU General Public License for more details.
22987 +# You should have received a copy of the GNU General Public License
22988 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22990 +if $tracelevel then {
22991 + strace $tracelevel
22997 +set testfile namespace-nested-imports
22998 +set srcfile ${testfile}.cc
22999 +set binfile ${objdir}/${subdir}/${testfile}
23000 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23001 + untested "Couldn't compile test program"
23005 +# Get things started.
23009 +gdb_reinitialize_dir $srcdir/$subdir
23010 +gdb_load ${binfile}
23012 +############################################
23013 +if ![runto_main] then {
23014 + perror "couldn't run to breakpoint main"
23018 +gdb_test "print ab" "No symbol .* in current context."
23020 +############################################
23021 +gdb_breakpoint C::first
23022 +gdb_continue_to_breakpoint "C::first"
23024 +gdb_test "print ab" "No symbol .* in current context."
23025 +gdb_test "print C::D::ab" "= 11"
23027 +############################################
23028 +gdb_breakpoint C::D::second
23029 +gdb_continue_to_breakpoint "C::D::second"
23031 +gdb_test "print ab" "= 11"
23032 diff --git a/gdb/testsuite/gdb.cp/namespace-no-imports.cc b/gdb/testsuite/gdb.cp/namespace-no-imports.cc
23033 new file mode 100644
23034 index 0000000..d1c68ab
23036 +++ b/gdb/testsuite/gdb.cp/namespace-no-imports.cc
23061 + return C::second();
23073 + return A::B::first();
23075 diff --git a/gdb/testsuite/gdb.cp/namespace-no-imports.exp b/gdb/testsuite/gdb.cp/namespace-no-imports.exp
23076 new file mode 100644
23077 index 0000000..e508103
23079 +++ b/gdb/testsuite/gdb.cp/namespace-no-imports.exp
23081 +# Copyright 2008 Free Software Foundation, Inc.
23083 +# This program is free software; you can redistribute it and/or modify
23084 +# it under the terms of the GNU General Public License as published by
23085 +# the Free Software Foundation; either version 3 of the License, or
23086 +# (at your option) any later version.
23088 +# This program is distributed in the hope that it will be useful,
23089 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23090 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23091 +# GNU General Public License for more details.
23093 +# You should have received a copy of the GNU General Public License
23094 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23096 +if $tracelevel then {
23097 + strace $tracelevel
23103 +set testfile namespace-no-imports
23104 +set srcfile ${testfile}.cc
23105 +set binfile ${objdir}/${subdir}/${testfile}
23106 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23107 + untested "Couldn't compile test program"
23111 +# Get things started.
23115 +gdb_reinitialize_dir $srcdir/$subdir
23116 +gdb_load ${binfile}
23118 +############################################
23119 +if ![runto_main] then {
23120 + perror "couldn't run to breakpoint main"
23124 +gdb_test "print A::_a" "= 11"
23125 +gdb_test "print A::B::ab" "= 22"
23126 +gdb_test "print A::B::C::abc" "= 33"
23128 +gdb_test "print _a" "No symbol .* in current context."
23129 +gdb_test "print ab" "No symbol .* in current context."
23130 +gdb_test "print abc" "No symbol .* in current context."
23132 +############################################
23133 +gdb_breakpoint A::B::first
23134 +gdb_continue_to_breakpoint "A::B::first"
23136 +gdb_test "print A::_a" "= 11"
23137 +gdb_test "print A::B::ab" "= 22"
23138 +gdb_test "print A::B::C::abc" "= 33"
23140 +gdb_test "print _a" "= 11"
23141 +gdb_test "print ab" "= 22"
23142 +gdb_test "print C::abc" "= 33"
23144 +gdb_test "print abc" "No symbol .* in current context."
23146 +############################################
23147 +gdb_breakpoint A::B::C::second
23148 +gdb_continue_to_breakpoint "A::B::C::second"
23150 +gdb_test "print A::_a" "= 11"
23151 +gdb_test "print A::B::ab" "= 22"
23152 +gdb_test "print A::B::C::abc" "= 33"
23154 +gdb_test "print _a" "= 11"
23155 +gdb_test "print ab" "= 22"
23156 +gdb_test "print abc" "= 33"
23157 diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.cc b/gdb/testsuite/gdb.cp/namespace-recursive.cc
23158 new file mode 100644
23159 index 0000000..46d4c18
23161 +++ b/gdb/testsuite/gdb.cp/namespace-recursive.cc
23168 + using namespace A;
23172 + using namespace B;
23175 +using namespace C;
23179 + using namespace D;
23182 +using namespace D;
23197 + namespace FE = E;
23201 + namespace GF = F;
23204 +//----------------
23206 + using namespace D;
23207 + namespace GX = G;
23208 + return ax + dx + xx + G::GF::FE::ex;
23210 diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.exp b/gdb/testsuite/gdb.cp/namespace-recursive.exp
23211 new file mode 100644
23212 index 0000000..5543757
23214 +++ b/gdb/testsuite/gdb.cp/namespace-recursive.exp
23216 +# Copyright 2008 Free Software Foundation, Inc.
23218 +# This program is free software; you can redistribute it and/or modify
23219 +# it under the terms of the GNU General Public License as published by
23220 +# the Free Software Foundation; either version 3 of the License, or
23221 +# (at your option) any later version.
23223 +# This program is distributed in the hope that it will be useful,
23224 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23225 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23226 +# GNU General Public License for more details.
23228 +# You should have received a copy of the GNU General Public License
23229 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23231 +if $tracelevel then {
23232 + strace $tracelevel
23238 +set testfile namespace-recursive
23239 +set srcfile ${testfile}.cc
23240 +set binfile ${objdir}/${subdir}/${testfile}
23241 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23242 + untested "Couldn't compile test program"
23246 +if [get_compiler_info ${binfile}] {
23251 +# Get things started.
23255 +gdb_reinitialize_dir $srcdir/$subdir
23256 +gdb_load ${binfile}
23258 +if ![runto_main] then {
23259 + perror "couldn't run to breakpoint main"
23263 +############################################
23264 +# test printing from namespace imported into
23265 +# imported namespace
23267 +gdb_test "print ax" "= 9"
23269 +############################################
23270 +# test that gdb can print without falling
23271 +# into search loop
23273 +gdb_test "print dx" "= 99"
23275 +############################################
23276 +# test printing from namespace imported into
23277 +# imported namespace where imports are implicit
23278 +# anonymous namespace imports.
23280 +gdb_test "print xx" "= 999"
23282 +############################################
23283 +# Test printing using recursive namespace
23286 +setup_kfail "gdb/10541" "*-*-*"
23287 +gdb_test "ptype G::GF" "= namespace F"
23289 +setup_kfail "gdb/10541" "*-*-*"
23290 +gdb_test "print G::GF::FE::ex" "= 9999"
23291 diff --git a/gdb/testsuite/gdb.cp/namespace-stress-declarations.cc b/gdb/testsuite/gdb.cp/namespace-stress-declarations.cc
23292 new file mode 100644
23293 index 0000000..173e49b
23295 +++ b/gdb/testsuite/gdb.cp/namespace-stress-declarations.cc
23384 +using namespace A;
23390 \ No newline at end of file
23391 diff --git a/gdb/testsuite/gdb.cp/namespace-stress-declarations.exp b/gdb/testsuite/gdb.cp/namespace-stress-declarations.exp
23392 new file mode 100644
23393 index 0000000..f22a14e
23395 +++ b/gdb/testsuite/gdb.cp/namespace-stress-declarations.exp
23397 +# Copyright 2008 Free Software Foundation, Inc.
23399 +# This program is free software; you can redistribute it and/or modify
23400 +# it under the terms of the GNU General Public License as published by
23401 +# the Free Software Foundation; either version 3 of the License, or
23402 +# (at your option) any later version.
23404 +# This program is distributed in the hope that it will be useful,
23405 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23406 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23407 +# GNU General Public License for more details.
23409 +# You should have received a copy of the GNU General Public License
23410 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23412 +if $tracelevel then {
23413 + strace $tracelevel
23419 +set testfile namespace-stress-declarations
23420 +set srcfile ${testfile}.cc
23421 +set binfile ${objdir}/${subdir}/${testfile}
23422 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23423 + untested "Couldn't compile test program"
23427 +if [get_compiler_info ${binfile}] {
23431 +# Get things started.
23435 +gdb_reinitialize_dir $srcdir/$subdir
23436 +gdb_load ${binfile}
23438 +if ![runto_main] then {
23439 + perror "couldn't run to breakpoint main"
23443 +############################################
23444 +# Test that the search can fail efficiently
23446 +gdb_test "print fakex" "No symbol \"fakex\" in current context."
23447 diff --git a/gdb/testsuite/gdb.cp/namespace-stress.cc b/gdb/testsuite/gdb.cp/namespace-stress.cc
23448 new file mode 100644
23449 index 0000000..f34083e
23451 +++ b/gdb/testsuite/gdb.cp/namespace-stress.cc
23454 +namespace A{ int x; }
23455 +namespace B{ int x; }
23456 +namespace C{ int x; }
23457 +namespace D{ int x; }
23458 +namespace E{ int x; }
23459 +namespace F{ int x; }
23460 +namespace G{ int x; }
23461 +namespace H{ int x; }
23462 +namespace I{ int x; }
23463 +namespace J{ int x; }
23464 +namespace K{ int x; }
23465 +namespace L{ int x; }
23466 +namespace M{ int x; }
23467 +namespace N{ int x; }
23468 +namespace O{ int x; }
23469 +namespace P{ int x; }
23470 +namespace Q{ int x; }
23471 +namespace R{ int x; }
23472 +namespace S{ int x; }
23473 +namespace T{ int x; }
23474 +namespace U{ int x; }
23475 +namespace V{ int x; }
23476 +namespace W{ int x; }
23477 +namespace X{ int x; }
23478 +namespace Y{ int x; }
23479 +namespace Z{ int x; }
23484 + using namespace A;
23485 + using namespace B;
23486 + using namespace C;
23487 + using namespace D;
23488 + using namespace E;
23489 + using namespace F;
23490 + using namespace G;
23491 + using namespace H;
23492 + using namespace I;
23493 + using namespace J;
23494 + using namespace K;
23495 + using namespace L;
23496 + using namespace M;
23497 + using namespace N;
23498 + using namespace O;
23499 + using namespace P;
23500 + using namespace Q;
23501 + using namespace R;
23502 + using namespace S;
23503 + using namespace T;
23504 + using namespace U;
23505 + using namespace V;
23506 + using namespace W;
23507 + using namespace X;
23508 + using namespace Y;
23509 + using namespace Z;
23513 \ No newline at end of file
23514 diff --git a/gdb/testsuite/gdb.cp/namespace-stress.exp b/gdb/testsuite/gdb.cp/namespace-stress.exp
23515 new file mode 100644
23516 index 0000000..1806523
23518 +++ b/gdb/testsuite/gdb.cp/namespace-stress.exp
23520 +# Copyright 2008 Free Software Foundation, Inc.
23522 +# This program is free software; you can redistribute it and/or modify
23523 +# it under the terms of the GNU General Public License as published by
23524 +# the Free Software Foundation; either version 3 of the License, or
23525 +# (at your option) any later version.
23527 +# This program is distributed in the hope that it will be useful,
23528 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23529 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23530 +# GNU General Public License for more details.
23532 +# You should have received a copy of the GNU General Public License
23533 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23535 +if $tracelevel then {
23536 + strace $tracelevel
23542 +set testfile namespace-stress
23543 +set srcfile ${testfile}.cc
23544 +set binfile ${objdir}/${subdir}/${testfile}
23545 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23546 + untested "Couldn't compile test program"
23550 +if [get_compiler_info ${binfile}] {
23554 +# Get things started.
23558 +gdb_reinitialize_dir $srcdir/$subdir
23559 +gdb_load ${binfile}
23561 +if ![runto_main] then {
23562 + perror "couldn't run to breakpoint main"
23566 +############################################
23567 +# Test that the search can fail efficiently
23569 +gdb_test "print y" "No symbol \"y\" in current context."
23570 diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc b/gdb/testsuite/gdb.cp/namespace-using.cc
23571 index 4786fd5..8ff5622 100644
23572 --- a/gdb/testsuite/gdb.cp/namespace-using.cc
23573 +++ b/gdb/testsuite/gdb.cp/namespace-using.cc
23587 + using namespace M;
23588 + int y = x + 1; // marker10 stop
23589 + using namespace N;
23604 + return marker10 ();
23610 + using namespace J;
23615 + return K::marker9 ();
23632 + using namespace G::H;
23634 + return L::marker8 ();
23646 +using namespace E::F;
23651 + return I::marker7 ();
23673 +using namespace C;
23678 + return marker6 ();
23685 + return marker5 ();
23689 - return marker4();
23693 + return marker4 ();
23702 - return marker3();
23703 + return marker3 ();
23712 @@ -29,17 +132,18 @@ int marker1()
23717 - total = _a + b + c + d + marker2(); // marker1 stop
23719 + total = _a + b + c + d + marker2 (); // marker1 stop
23732 - return marker1();
23733 + return marker1 ();
23735 diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp b/gdb/testsuite/gdb.cp/namespace-using.exp
23736 index f24973f..fc23115 100644
23737 --- a/gdb/testsuite/gdb.cp/namespace-using.exp
23738 +++ b/gdb/testsuite/gdb.cp/namespace-using.exp
23739 @@ -28,6 +28,11 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
23743 +if [get_compiler_info ${binfile}] {
23748 # Get things started.
23751 @@ -46,42 +51,155 @@ if ![runto_main] then {
23753 gdb_test "print _a" "= 1"
23755 +# Test that names are not printed when they
23756 +# are not imported
23758 +gdb_breakpoint marker3
23759 +gdb_continue_to_breakpoint "marker3"
23761 +#send_gdb "break marker3\n"
23762 +#send_gdb "continue\n"
23764 +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import"
23768 +gdb_reinitialize_dir $srcdir/$subdir
23769 +gdb_load ${binfile}
23772 ############################################
23773 # test printing of namespace imported into
23774 # a scope containing the pc.
23776 +if ![runto_main] then {
23777 + perror "couldn't run to breakpoint main"
23781 gdb_breakpoint [gdb_get_line_number "marker1 stop"]
23782 gdb_continue_to_breakpoint "marker1 stop"
23784 gdb_test "print _a" "= 1" "print _a in a nested scope"
23789 +gdb_reinitialize_dir $srcdir/$subdir
23790 +gdb_load ${binfile}
23792 +############################################
23793 +# test printing of namespace imported into
23797 +if ![runto marker5] then {
23798 + perror "couldn't run to breakpoint marker5"
23802 +gdb_test "print cc" "= 3"
23806 +gdb_reinitialize_dir $srcdir/$subdir
23807 +gdb_load ${binfile}
23810 ############################################
23811 # Test printing of namespace aliases
23813 -setup_kfail "gdb/7935" "*-*-*"
23814 if ![runto marker2] then {
23815 perror "couldn't run to breakpoint marker2"
23819 -gdb_test "print B::a" "= 1"
23820 +gdb_test "print B::_a" "= 1"
23822 +gdb_test "print _a" "No symbol \"_a\" in current context." "print _a in namespace alias scope"
23823 +gdb_test "print x" "No symbol \"x\" in current context." "print x in namespace alias scope"
23827 +gdb_reinitialize_dir $srcdir/$subdir
23828 +gdb_load ${binfile}
23831 ############################################
23832 # Test that names are not printed when they
23835 -gdb_breakpoint "marker3"
23836 -gdb_continue_to_breakpoint "marker3"
23837 +if {![runto marker3]} {
23838 + perror "couldn't run to breakpoint marker3"
23841 -gdb_test "print _a" "No symbol \"_a\" in current context." "Print a without import"
23842 +# gcc-4-3 puts import statements for aliases in
23843 +# the global scope instead of the corresponding
23844 +# function scope. These wrong import statements throw
23845 +# this test off. This is fixed in gcc-4-4.
23846 +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
23848 +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import"
23850 ############################################
23851 # Test printing of individually imported elements
23853 -setup_kfail "gdb/7936" "*-*-*"
23854 if ![runto marker4] then {
23855 perror "couldn't run to breakpoint marker4"
23859 -gdb_test "print x" "= 2"
23860 +gdb_test "print dx" "= 4"
23862 +############################################
23863 +# Test printing of namespace aliases
23865 +if ![runto marker5] then {
23866 + perror "couldn't run to marker5"
23870 +gdb_test "print efx" "= 5"
23872 +############################################
23873 +# Test printing of variables imported from
23874 +# nested namespaces
23876 +if ![runto I::marker7] then {
23877 + perror "couldn't run to breakpoint I::marker7"
23881 +gdb_test "print ghx" "= 6"
23883 +############################################
23884 +# Test that variables are not printed in a namespace
23885 +# that is sibling to the namespace containing an import
23887 +if ![runto L::marker8] then {
23888 + perror "couldn't run to breakpoint L::marker8"
23892 +gdb_test "print jx" "= 44"
23894 +gdb_breakpoint "K::marker9"
23895 +gdb_continue_to_breakpoint "K::marker9"
23897 +gdb_test "print jx" "No symbol \"jx\" in current context."
23899 +############################################
23900 +# Test that variables are only printed after the line
23901 +# containing the import
23903 +if ![runto_main] then {
23904 + perror "couldn't run to breakpoint main"
23908 +gdb_breakpoint [gdb_get_line_number "marker10 stop"]
23909 +gdb_continue_to_breakpoint "marker10 stop"
23911 +# Assert that M::x is printed and not N::x
23912 +gdb_test "print x" "= 911" "print x (from M::x)"
23914 diff --git a/gdb/testsuite/gdb.cp/namespace.exp b/gdb/testsuite/gdb.cp/namespace.exp
23915 index 76b1b82..2042db2 100644
23916 --- a/gdb/testsuite/gdb.cp/namespace.exp
23917 +++ b/gdb/testsuite/gdb.cp/namespace.exp
23920 # Note: As of 2000-06-03, they passed under g++ - djb
23922 +load_lib "cp-support.exp"
23924 if $tracelevel then {
23926 @@ -259,11 +260,16 @@ gdb_test "ptype E" "type = namespace C::D::E"
23927 gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
23928 gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
23929 gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
23930 -setup_kfail "gdb/1448" "*-*-*"
23931 -gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
23932 -setup_kfail "gdb/1448" "*-*-*"
23933 -gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
23934 -setup_kfail "gdb/1448" "*-*-*"
23935 +cp_test_ptype_class \
23936 + "ptype ::C::CClass" "" "class" "C::CClass" \
23938 + { field public "int x;" }
23940 +cp_test_ptype_class \
23941 + "ptype ::C::CClass::NestedClass" "" "class" "C::CClass::NestedClass" \
23943 + { field public "int y;" }
23945 gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
23946 gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
23947 gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
23948 @@ -273,8 +279,11 @@ gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"
23950 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
23951 gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}"
23952 -setup_kfail "gdb/1448" "*-*-*"
23953 -gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
23954 +cp_test_ptype_class \
23955 + "ptype ::C::OtherFileClass" "" "class" "C::OtherFileClass" \
23957 + { field public "int z;" }
23959 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
23961 # Some anonymous namespace tests.
23962 diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp
23963 index 24025a2..a72932e 100644
23964 --- a/gdb/testsuite/gdb.cp/overload.exp
23965 +++ b/gdb/testsuite/gdb.cp/overload.exp
23966 @@ -74,12 +74,12 @@ set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);"
23967 set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
23968 set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
23969 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
23970 -set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
23971 -set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
23972 +set re_methods "${re_methods}${ws}int overload1arg\\(short( int)?\\);"
23973 +set re_methods "${re_methods}${ws}int overload1arg\\((unsigned short|short unsigned)( int)?\\);"
23974 set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
23975 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
23976 -set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
23977 -set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
23978 +set re_methods "${re_methods}${ws}int overload1arg\\(long( int)?\\);"
23979 +set re_methods "${re_methods}${ws}int overload1arg\\((unsigned long|long unsigned)( int)?\\);"
23980 set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
23981 set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
23982 set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
23983 diff --git a/gdb/testsuite/gdb.cp/ovldbreak.exp b/gdb/testsuite/gdb.cp/ovldbreak.exp
23984 index 8a6b795..9997a45 100644
23985 --- a/gdb/testsuite/gdb.cp/ovldbreak.exp
23986 +++ b/gdb/testsuite/gdb.cp/ovldbreak.exp
23987 @@ -127,10 +127,24 @@ proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
23990 # This is the expected menu for overload1arg.
23991 -# Note the arg type variations on lines 6 and 13.
23992 +# Note the arg type variations for void and integer types.
23993 # This accommodates different versions of g++.
23995 -set menu_overload1arg "\\\[0\\\] cancel\r\n\\\[1\\\] all\r\n\\\[2\\\] foo::overload1arg\\(double\\) at.*$srcfile:121\r\n\\\[3\\\] foo::overload1arg\\(float\\) at.*$srcfile:120\r\n\\\[4\\\] foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r\n\\\[5\\\] foo::overload1arg\\(long\\) at.*$srcfile:118\r\n\\\[6\\\] foo::overload1arg\\((unsigned int|unsigned)\\) at.*$srcfile:117\r\n\\\[7\\\] foo::overload1arg\\(int\\) at.*$srcfile:116\r\n\\\[8\\\] foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r\n\\\[9\\\] foo::overload1arg\\(short\\) at.*$srcfile:114\r\n\\\[10\\\] foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r\n\\\[11\\\] foo::overload1arg\\(signed char\\) at.*$srcfile:112\r\n\\\[12\\\] foo::overload1arg\\(char\\) at.*$srcfile:111\r\n\\\[13\\\] foo::overload1arg\\((void|)\\) at.*$srcfile:110\r\n> $"
23996 +set menu_overload1arg "\\\[0\\\] cancel\r\n"
23997 +append menu_overload1arg "\\\[1\\\] all\r\n"
23998 +append menu_overload1arg "\\\[2\\\] foo::overload1arg\\(double\\) at.*$srcfile:121\r\n"
23999 +append menu_overload1arg "\\\[3\\\] foo::overload1arg\\(float\\) at.*$srcfile:120\r\n"
24000 +append menu_overload1arg "\\\[4\\\] foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r\n"
24001 +append menu_overload1arg "\\\[5\\\] foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r\n"
24002 +append menu_overload1arg "\\\[6\\\] foo::overload1arg\\((unsigned int|unsigned)\\) at.*$srcfile:117\r\n"
24003 +append menu_overload1arg "\\\[7\\\] foo::overload1arg\\(int\\) at.*$srcfile:116\r\n"
24004 +append menu_overload1arg "\\\[8\\\] foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r\n"
24005 +append menu_overload1arg "\\\[9\\\] foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r\n"
24006 +append menu_overload1arg "\\\[10\\\] foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r\n"
24007 +append menu_overload1arg "\\\[11\\\] foo::overload1arg\\(signed char\\) at.*$srcfile:112\r\n"
24008 +append menu_overload1arg "\\\[12\\\] foo::overload1arg\\(char\\) at.*$srcfile:111\r\n"
24009 +append menu_overload1arg "\\\[13\\\] foo::overload1arg\\((void|)\\) at.*$srcfile:110\r\n"
24010 +append menu_overload1arg "> $"
24012 # Set multiple-symbols to "ask", to allow us to test the use
24013 # of the multiple-choice menu when breaking on an overloaded method.
24014 @@ -157,17 +171,17 @@ set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 13 13 110
24016 gdb_test "info break" \
24017 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
24018 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
24019 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
24020 \[\t \]+breakpoint already hit 1 time\r
24021 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
24022 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
24023 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
24024 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
24025 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
24026 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
24027 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
24028 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
24029 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
24030 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
24031 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
24032 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
24033 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
24034 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
24035 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
24036 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
24037 @@ -215,17 +229,17 @@ gdb_expect {
24039 gdb_test "info break" \
24040 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
24041 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
24042 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
24043 \[\t \]+breakpoint already hit 1 time\r
24044 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
24045 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
24046 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
24047 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
24048 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
24049 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
24050 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
24051 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
24052 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
24053 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
24054 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
24055 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
24056 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
24057 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
24058 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
24059 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
24060 @@ -296,12 +310,12 @@ gdb_test "info break" \
24061 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
24062 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
24063 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
24064 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
24065 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
24066 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
24067 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
24068 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
24069 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
24070 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
24071 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
24072 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
24073 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
24074 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
24075 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
24076 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
24077 diff --git a/gdb/testsuite/gdb.cp/shadowing.cc b/gdb/testsuite/gdb.cp/shadowing.cc
24078 new file mode 100644
24079 index 0000000..6d9c2f1
24081 +++ b/gdb/testsuite/gdb.cp/shadowing.cc
24111 + int z = x; //prevent gcc from optimizing away this scope
24112 + using namespace A;
24129 + return theB.func();
24131 diff --git a/gdb/testsuite/gdb.cp/shadowing.exp b/gdb/testsuite/gdb.cp/shadowing.exp
24132 new file mode 100644
24133 index 0000000..6922eed
24135 +++ b/gdb/testsuite/gdb.cp/shadowing.exp
24137 +# Copyright 2008 Free Software Foundation, Inc.
24139 +# This program is free software; you can redistribute it and/or modify
24140 +# it under the terms of the GNU General Public License as published by
24141 +# the Free Software Foundation; either version 3 of the License, or
24142 +# (at your option) any later version.
24144 +# This program is distributed in the hope that it will be useful,
24145 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24146 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24147 +# GNU General Public License for more details.
24149 +# You should have received a copy of the GNU General Public License
24150 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
24152 +if $tracelevel then {
24153 + strace $tracelevel
24159 +set testfile shadowing
24160 +set srcfile ${testfile}.cc
24161 +set binfile ${objdir}/${subdir}/${testfile}
24162 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
24163 + untested "Couldn't compile test program"
24167 +if [get_compiler_info ${binfile}] {
24171 +# Get things started.
24175 +gdb_reinitialize_dir $srcdir/$subdir
24176 +gdb_load ${binfile}
24178 +if ![runto_main] then {
24179 + perror "couldn't run to breakpoint main"
24183 +############################################
24184 +# Test printing of class variable is not shadowed
24185 +# by global variable
24187 +gdb_breakpoint [gdb_get_line_number "marker1"]
24188 +gdb_continue_to_breakpoint "marker1"
24190 +gdb_test "print x" "= 33" "Print class x shadowing global x"
24193 +############################################
24194 +# Test printing local variable is not shadowed
24195 +# by class variable
24197 +gdb_breakpoint [gdb_get_line_number "marker2"]
24198 +gdb_continue_to_breakpoint "marker2"
24200 +gdb_test "print x" "= 44" "Print local x shadowing class x"
24202 +############################################
24203 +# Test inner scope x is printed not outer scope
24205 +gdb_breakpoint [gdb_get_line_number "marker3"]
24206 +gdb_continue_to_breakpoint "marker3"
24208 +gdb_test "print x" "= 55" "Print inner scope x"
24210 +############################################
24211 +# Test printing local variable is not shadowed
24212 +# by namespace variable
24214 +gdb_breakpoint [gdb_get_line_number "marker4"]
24215 +gdb_continue_to_breakpoint "marker4"
24217 +gdb_test "print x" "= 55" "Print local x not namespace x"
24219 +############################################
24220 +# Test imported namespace element is printed
24222 +gdb_breakpoint [gdb_get_line_number "marker5"]
24223 +gdb_continue_to_breakpoint "marker5"
24225 +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
24227 +gdb_test "print x" "= 11" "Print imported namespace x"
24228 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.S b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
24229 new file mode 100644
24230 index 0000000..d5b9ca5
24232 +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
24234 +/* This testcase is part of GDB, the GNU debugger.
24236 + Copyright 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
24238 + This program is free software; you can redistribute it and/or modify
24239 + it under the terms of the GNU General Public License as published by
24240 + the Free Software Foundation; either version 3 of the License, or
24241 + (at your option) any later version.
24243 + This program is distributed in the hope that it will be useful,
24244 + but WITHOUT ANY WARRANTY; without even the implied warranty of
24245 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24246 + GNU General Public License for more details.
24248 + You should have received a copy of the GNU General Public License
24249 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
24251 +/* Test .debug_aranges containing zero address_size. */
24253 +/* Dummy function to provide debug information for. */
24258 + .type main, %function
24263 + .size main, .-main
24266 +/* Debug information */
24268 + .section .debug_info
24271 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
24273 + .2byte 2 /* DWARF Version */
24274 + .4byte .Labbrev1_begin /* Offset into abbrev section */
24275 + .byte 4 /* Pointer size */
24278 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
24279 + .4byte .Lend_text1 /* DW_AT_high_pc */
24280 + .4byte .Lbegin_text1 /* DW_AT_low_pc */
24281 + .ascii "file1.txt\0" /* DW_AT_name */
24282 + .ascii "GNU C 3.3.3\0" /* DW_AT_producer */
24283 + .byte 1 /* DW_AT_language (C) */
24286 + .uleb128 2 /* Abbrev: DW_TAG_subprogram */
24287 + .byte 1 /* DW_AT_external */
24288 + .byte 1 /* DW_AT_decl_file */
24289 + .byte 2 /* DW_AT_decl_line */
24290 + .ascii "main\0" /* DW_AT_name */
24291 + .4byte .Ltype_int-.Lcu1_begin /* DW_AT_type */
24292 + .4byte .Lbegin_main /* DW_AT_low_pc */
24293 + .4byte .Lend_main /* DW_AT_high_pc */
24294 + .byte 1 /* DW_AT_frame_base: length */
24295 + .byte 0x55 /* DW_AT_frame_base: DW_OP_reg5 */
24298 + .uleb128 3 /* Abbrev: DW_TAG_base_type */
24299 + .ascii "int\0" /* DW_AT_name */
24300 + .byte 4 /* DW_AT_byte_size */
24301 + .byte 5 /* DW_AT_encoding */
24303 + .byte 0 /* End of children of CU */
24307 +/* Abbrev table */
24308 + .section .debug_abbrev
24310 + .uleb128 1 /* Abbrev code */
24311 + .uleb128 0x11 /* DW_TAG_compile_unit */
24312 + .byte 1 /* has_children */
24313 + .uleb128 0x12 /* DW_AT_high_pc */
24314 + .uleb128 0x1 /* DW_FORM_addr */
24315 + .uleb128 0x11 /* DW_AT_low_pc */
24316 + .uleb128 0x1 /* DW_FORM_addr */
24317 + .uleb128 0x3 /* DW_AT_name */
24318 + .uleb128 0x8 /* DW_FORM_string */
24319 + .uleb128 0x25 /* DW_AT_producer */
24320 + .uleb128 0x8 /* DW_FORM_string */
24321 + .uleb128 0x13 /* DW_AT_language */
24322 + .uleb128 0xb /* DW_FORM_data1 */
24323 + .byte 0x0 /* Terminator */
24324 + .byte 0x0 /* Terminator */
24326 + .uleb128 2 /* Abbrev code */
24327 + .uleb128 0x2e /* DW_TAG_subprogram */
24328 + .byte 0 /* has_children */
24329 + .uleb128 0x3f /* DW_AT_external */
24330 + .uleb128 0xc /* DW_FORM_flag */
24331 + .uleb128 0x3a /* DW_AT_decl_file */
24332 + .uleb128 0xb /* DW_FORM_data1 */
24333 + .uleb128 0x3b /* DW_AT_decl_line */
24334 + .uleb128 0xb /* DW_FORM_data1 */
24335 + .uleb128 0x3 /* DW_AT_name */
24336 + .uleb128 0x8 /* DW_FORM_string */
24337 + .uleb128 0x49 /* DW_AT_type */
24338 + .uleb128 0x13 /* DW_FORM_ref4 */
24339 + .uleb128 0x11 /* DW_AT_low_pc */
24340 + .uleb128 0x1 /* DW_FORM_addr */
24341 + .uleb128 0x12 /* DW_AT_high_pc */
24342 + .uleb128 0x1 /* DW_FORM_addr */
24343 + .uleb128 0x40 /* DW_AT_frame_base */
24344 + .uleb128 0xa /* DW_FORM_block1 */
24345 + .byte 0x0 /* Terminator */
24346 + .byte 0x0 /* Terminator */
24348 + .uleb128 3 /* Abbrev code */
24349 + .uleb128 0x24 /* DW_TAG_base_type */
24350 + .byte 0 /* has_children */
24351 + .uleb128 0x3 /* DW_AT_name */
24352 + .uleb128 0x8 /* DW_FORM_string */
24353 + .uleb128 0xb /* DW_AT_byte_size */
24354 + .uleb128 0xb /* DW_FORM_data1 */
24355 + .uleb128 0x3e /* DW_AT_encoding */
24356 + .uleb128 0xb /* DW_FORM_data1 */
24357 + .byte 0x0 /* Terminator */
24358 + .byte 0x0 /* Terminator */
24360 + .byte 0x0 /* Terminator */
24361 + .byte 0x0 /* Terminator */
24363 +/* aranges table */
24364 + .section .debug_aranges
24365 + .long .Laranges_end - 1f
24367 + .2byte 2 /* aranges Version */
24368 + .4byte .Lcu1_begin - .debug_info /* Offset into .debug_info section */
24369 + /* The GDB crasher is this zero value. */
24370 + .byte 0 /* aranges address_size */
24371 + .byte 0 /* aranges segment_size */
24374 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
24375 new file mode 100644
24376 index 0000000..39632d5
24378 +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
24380 +# Copyright 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
24382 +# This program is free software; you can redistribute it and/or modify
24383 +# it under the terms of the GNU General Public License as published by
24384 +# the Free Software Foundation; either version 3 of the License, or
24385 +# (at your option) any later version.
24387 +# This program is distributed in the hope that it will be useful,
24388 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24389 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24390 +# GNU General Public License for more details.
24392 +# You should have received a copy of the GNU General Public License
24393 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
24395 +# Test .debug_aranges containing zero address_size.
24397 +# This test can only be run on targets which support DWARF-2 and use gas.
24398 +# For now pick a sampling of likely targets.
24399 +if {![istarget *-*-linux*]
24400 + && ![istarget *-*-gnu*]
24401 + && ![istarget *-*-elf*]
24402 + && ![istarget *-*-openbsd*]
24403 + && ![istarget arm-*-eabi*]
24404 + && ![istarget powerpc-*-eabi*]} {
24408 +set testfile "dw2-aranges"
24409 +set srcfile ${testfile}.S
24410 +set binfile ${objdir}/${subdir}/${testfile}
24412 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {nodebug}] != "" } {
24416 +clean_restart $testfile
24418 +# Failed gdb_load would abort the testcase execution earlier.
24419 +pass "file loaded"
24420 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
24421 new file mode 100644
24422 index 0000000..1f02d90
24424 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
24426 +/* This testcase is part of GDB, the GNU debugger.
24428 + Copyright 2004 Free Software Foundation, Inc.
24430 + This program is free software; you can redistribute it and/or modify
24431 + it under the terms of the GNU General Public License as published by
24432 + the Free Software Foundation; either version 2 of the License, or
24433 + (at your option) any later version.
24435 + This program is distributed in the hope that it will be useful,
24436 + but WITHOUT ANY WARRANTY; without even the implied warranty of
24437 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24438 + GNU General Public License for more details.
24440 + You should have received a copy of the GNU General Public License
24441 + along with this program; if not, write to the Free Software
24442 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24446 +/* The function `func1' traced into must have debug info on offset > 0;
24447 + (DW_UNSND (attr)). This is the reason of `func0' existence. */
24450 +func0(int a, int b)
24454 +/* `func1' being traced into must have some arguments to dump. */
24457 +func1(int a, int b)
24468 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
24469 new file mode 100644
24470 index 0000000..1c6e84a
24472 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
24474 +# Copyright 2006 Free Software Foundation, Inc.
24476 +# This program is free software; you can redistribute it and/or modify
24477 +# it under the terms of the GNU General Public License as published by
24478 +# the Free Software Foundation; either version 2 of the License, or
24479 +# (at your option) any later version.
24481 +# This program is distributed in the hope that it will be useful,
24482 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24483 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24484 +# GNU General Public License for more details.
24486 +# You should have received a copy of the GNU General Public License
24487 +# along with this program; if not, write to the Free Software
24488 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24490 +# Minimal DWARF-2 unit test
24492 +# This test can only be run on targets which support DWARF-2.
24493 +# For now pick a sampling of likely targets.
24494 +if {![istarget *-*-linux*]
24495 + && ![istarget *-*-gnu*]
24496 + && ![istarget *-*-elf*]
24497 + && ![istarget *-*-openbsd*]
24498 + && ![istarget arm-*-eabi*]
24499 + && ![istarget powerpc-*-eabi*]} {
24503 +set testfile "dw2-stripped"
24504 +set srcfile ${testfile}.c
24505 +set binfile ${objdir}/${subdir}/${testfile}.x
24507 +remote_exec build "rm -f ${binfile}"
24509 +# get the value of gcc_compiled
24510 +if [get_compiler_info ${binfile}] {
24514 +# This test can only be run on gcc as we use additional_flags=FIXME
24515 +if {$gcc_compiled == 0} {
24519 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
24523 +remote_exec build "objcopy -R .debug_loc ${binfile}"
24524 +set strip_output [remote_exec build "objdump -h ${binfile}"]
24526 +set test "stripping test file preservation"
24527 +if [ regexp ".debug_info " $strip_output] {
24528 + pass "$test (.debug_info preserved)"
24530 + fail "$test (.debug_info got also stripped)"
24533 +set test "stripping test file functionality"
24534 +if [ regexp ".debug_loc " $strip_output] {
24535 + fail "$test (.debug_loc still present)"
24537 + pass "$test (.debug_loc stripped)"
24542 +gdb_reinitialize_dir $srcdir/$subdir
24543 +gdb_load ${binfile}
24545 +# For C programs, "start" should stop in main().
24547 +gdb_test "start" \
24548 + ".*main \\(\\) at .*" \
24551 + "func.* \\(.*\\) at .*" \
24553 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
24554 new file mode 100644
24555 index 0000000..5fcdd84
24557 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
24559 +/* This testcase is part of GDB, the GNU debugger.
24561 + Copyright 2009 Free Software Foundation, Inc.
24563 + This program is free software; you can redistribute it and/or modify
24564 + it under the terms of the GNU General Public License as published by
24565 + the Free Software Foundation; either version 3 of the License, or
24566 + (at your option) any later version.
24568 + This program is distributed in the hope that it will be useful,
24569 + but WITHOUT ANY WARRANTY; without even the implied warranty of
24570 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24571 + GNU General Public License for more details.
24573 + You should have received a copy of the GNU General Public License
24574 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
24576 +/* Debug information */
24578 + .section .debug_info
24581 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
24583 + .2byte 2 /* DWARF Version */
24584 + .4byte .Labbrev1_begin /* Offset into abbrev section */
24585 + .byte 4 /* Pointer size */
24588 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
24589 + .ascii "dw2-struct-member-data-location.c\0" /* DW_AT_name */
24590 + .ascii "GNU C 4.3.2\0" /* DW_AT_producer */
24591 + .byte 1 /* DW_AT_language (C) */
24594 + .uleb128 2 /* Abbrev: DW_TAG_structure_type */
24595 + .ascii "some_struct\0" /* DW_AT_name */
24597 + .uleb128 3 /* Abbrev: DW_TAG_member */
24598 + .ascii "field\0" /* DW_AT_name */
24599 + .byte 0 /* DW_AT_data_member_location */
24601 + .byte 0 /* End of children of some_struct */
24603 + .byte 0 /* End of children of CU */
24607 +/* Abbrev table */
24608 + .section .debug_abbrev
24610 + .uleb128 1 /* Abbrev code */
24611 + .uleb128 0x11 /* DW_TAG_compile_unit */
24612 + .byte 1 /* has_children */
24613 + .uleb128 0x3 /* DW_AT_name */
24614 + .uleb128 0x8 /* DW_FORM_string */
24615 + .uleb128 0x25 /* DW_AT_producer */
24616 + .uleb128 0x8 /* DW_FORM_string */
24617 + .uleb128 0x13 /* DW_AT_language */
24618 + .uleb128 0xb /* DW_FORM_data1 */
24619 + .byte 0x0 /* Terminator */
24620 + .byte 0x0 /* Terminator */
24622 + .uleb128 2 /* Abbrev code */
24623 + .uleb128 0x13 /* DW_TAG_structure_type */
24624 + .byte 1 /* has_children */
24625 + .uleb128 0x3 /* DW_AT_name */
24626 + .uleb128 0x8 /* DW_FORM_string */
24627 + .byte 0x0 /* Terminator */
24628 + .byte 0x0 /* Terminator */
24630 + .uleb128 3 /* Abbrev code */
24631 + .uleb128 0x0d /* DW_TAG_member */
24632 + .byte 0 /* has_children */
24633 + .uleb128 0x3 /* DW_AT_name */
24634 + .uleb128 0x8 /* DW_FORM_string */
24635 + .uleb128 0x38 /* DW_AT_data_member_location */
24636 + .uleb128 0x0b /* DW_FORM_data1 */
24637 + .byte 0x0 /* Terminator */
24638 + .byte 0x0 /* Terminator */
24640 + .byte 0x0 /* Terminator */
24641 + .byte 0x0 /* Terminator */
24642 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
24643 new file mode 100644
24644 index 0000000..c41151c
24646 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
24648 +# Copyright 2009 Free Software Foundation, Inc.
24650 +# This program is free software; you can redistribute it and/or modify
24651 +# it under the terms of the GNU General Public License as published by
24652 +# the Free Software Foundation; either version 3 of the License, or
24653 +# (at your option) any later version.
24655 +# This program is distributed in the hope that it will be useful,
24656 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24657 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24658 +# GNU General Public License for more details.
24660 +# You should have received a copy of the GNU General Public License
24661 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
24663 +# This test can only be run on targets which support DWARF-2 and use gas.
24664 +# For now pick a sampling of likely targets.
24665 +if {![istarget *-*-linux*]
24666 + && ![istarget *-*-gnu*]
24667 + && ![istarget *-*-elf*]
24668 + && ![istarget *-*-openbsd*]
24669 + && ![istarget arm-*-eabi*]
24670 + && ![istarget powerpc-*-eabi*]} {
24674 +set testfile "dw2-struct-member-data-location"
24675 +set srcfile ${testfile}.S
24676 +set binfile ${testfile}.x
24678 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
24682 +clean_restart $binfile
24684 +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
24685 diff --git a/gdb/testsuite/gdb.fortran/common-block.exp b/gdb/testsuite/gdb.fortran/common-block.exp
24686 new file mode 100644
24687 index 0000000..888f6c3
24689 +++ b/gdb/testsuite/gdb.fortran/common-block.exp
24691 +# Copyright 2008 Free Software Foundation, Inc.
24693 +# This program is free software; you can redistribute it and/or modify
24694 +# it under the terms of the GNU General Public License as published by
24695 +# the Free Software Foundation; either version 2 of the License, or
24696 +# (at your option) any later version.
24698 +# This program is distributed in the hope that it will be useful,
24699 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24700 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24701 +# GNU General Public License for more details.
24703 +# You should have received a copy of the GNU General Public License
24704 +# along with this program; if not, write to the Free Software
24705 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24707 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24709 +set testfile "common-block"
24710 +set srcfile ${testfile}.f90
24711 +set binfile ${objdir}/${subdir}/${testfile}
24713 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
24714 + untested "Couldn't compile ${srcfile}"
24720 +gdb_reinitialize_dir $srcdir/$subdir
24721 +gdb_load ${binfile}
24723 +if ![runto MAIN__] then {
24724 + perror "couldn't run to breakpoint MAIN__"
24728 +gdb_breakpoint [gdb_get_line_number "stop-here-out"]
24729 +gdb_continue_to_breakpoint "stop-here-out"
24731 +# Common block naming with source name /foo/:
24732 +# .symtab DW_TAG_common_block's DW_AT_name
24733 +# Intel Fortran foo_ foo_
24734 +# GNU Fortran foo_ foo
24738 +set int4 {(integer\(kind=4\)|INTEGER\(4\))}
24739 +set real4 {(real\(kind=4\)|REAL\(4\))}
24740 +set real8 {(real\(kind=8\)|REAL\(8\))}
24742 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context."
24743 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context."
24744 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context."
24745 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24746 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24747 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24749 +gdb_test "info locals" "ix_x = 11\r\niy_y = 22\r\niz_z = 33\r\nix = 1\r\niy = 2\r\niz = 3" "info locals out"
24750 +gdb_test "info common" "Contents of F77 COMMON block 'fo_o':\r\nix_x = 11\r\niy_y = 22\r\niz_z = 33\r\n\r\nContents of F77 COMMON block 'foo':\r\nix = 1\r\niy = 2\r\niz = 3" "info common out"
24752 +gdb_test "ptype ix" "type = $int4" "ptype ix out"
24753 +gdb_test "ptype iy" "type = $real4" "ptype iy out"
24754 +gdb_test "ptype iz" "type = $real8" "ptype iz out"
24755 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x out"
24756 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y out"
24757 +gdb_test "ptype iz_z" "type = $real8" "ptype iz_z out"
24759 +gdb_test "p ix" " = 1 *" "p ix out"
24760 +gdb_test "p iy" " = 2 *" "p iy out"
24761 +gdb_test "p iz" " = 3 *" "p iz out"
24762 +gdb_test "p ix_x" " = 11 *" "p ix_x out"
24763 +gdb_test "p iy_y" " = 22 *" "p iy_y out"
24764 +gdb_test "p iz_z" " = 33 *" "p iz_z out"
24766 +gdb_breakpoint [gdb_get_line_number "stop-here-in"]
24767 +gdb_continue_to_breakpoint "stop-here-in"
24769 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context." "whatis foo$suffix in"
24770 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context." "ptype foo$suffix in"
24771 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context." "p foo$suffix in"
24772 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "whatis fo_o$suffix in"
24773 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "ptype fo_o$suffix in"
24774 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "p fo_o$suffix in"
24776 +gdb_test "info locals" "ix = 11\r\niy2 = 22\r\niz = 33\r\nix_x = 1\r\niy_y = 2\r\niz_z2 = 3\r\niy = 5\r\niz_z = 55" "info locals in"
24777 +gdb_test "info common" "Contents of F77 COMMON block 'fo_o':\r\nix = 11\r\niy2 = 22\r\niz = 33\r\n\r\nContents of F77 COMMON block 'foo':\r\nix_x = 1\r\niy_y = 2\r\niz_z2 = 3" "info common in"
24779 +gdb_test "ptype ix" "type = $int4" "ptype ix in"
24780 +gdb_test "ptype iy2" "type = $real4" "ptype iy2 in"
24781 +gdb_test "ptype iz" "type = $real8" "ptype iz in"
24782 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x in"
24783 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y in"
24784 +gdb_test "ptype iz_z2" "type = $real8" "ptype iz_z2 in"
24786 +gdb_test "p ix" " = 11 *" "p ix in"
24787 +gdb_test "p iy2" " = 22 *" "p iy2 in"
24788 +gdb_test "p iz" " = 33 *" "p iz in"
24789 +gdb_test "p ix_x" " = 1 *" "p ix_x in"
24790 +gdb_test "p iy_y" " = 2 *" "p iy_y in"
24791 +gdb_test "p iz_z2" " = 3 *" "p iz_z2 in"
24792 diff --git a/gdb/testsuite/gdb.fortran/common-block.f90 b/gdb/testsuite/gdb.fortran/common-block.f90
24793 new file mode 100644
24794 index 0000000..b614e8a
24796 +++ b/gdb/testsuite/gdb.fortran/common-block.f90
24798 +! Copyright 2008 Free Software Foundation, Inc.
24800 +! This program is free software; you can redistribute it and/or modify
24801 +! it under the terms of the GNU General Public License as published by
24802 +! the Free Software Foundation; either version 2 of the License, or
24803 +! (at your option) any later version.
24805 +! This program is distributed in the hope that it will be useful,
24806 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24807 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24808 +! GNU General Public License for more details.
24810 +! You should have received a copy of the GNU General Public License
24811 +! along with this program; if not, write to the Free Software
24812 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24814 +! Ihis file is the Fortran source file for dynamic.exp.
24815 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
24816 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
24828 + common /fo_o/ix,iy2,iz
24829 + common /foo/ix_x,iy_y,iz_z2
24834 + if (ix .ne. 11 .or. iy2 .ne. 22.0 .or. iz .ne. 33.0) call abort
24835 + if (ix_x .ne. 1 .or. iy_y .ne. 2.0 .or. iz_z2 .ne. 3.0) call abort
24837 + ix = 0 ! stop-here-in
24841 +program common_test
24851 + common /foo/ix,iy,iz
24852 + common /fo_o/ix_x,iy_y,iz_z
24862 + call in ! stop-here-out
24864 +end program common_test
24865 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
24866 new file mode 100644
24867 index 0000000..cd3486b
24869 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
24871 +# Copyright 2009 Free Software Foundation, Inc.
24873 +# This program is free software; you can redistribute it and/or modify
24874 +# it under the terms of the GNU General Public License as published by
24875 +# the Free Software Foundation; either version 2 of the License, or
24876 +# (at your option) any later version.
24878 +# This program is distributed in the hope that it will be useful,
24879 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24880 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24881 +# GNU General Public License for more details.
24883 +# You should have received a copy of the GNU General Public License
24884 +# along with this program; if not, write to the Free Software
24885 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24887 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24889 +# This file is part of the gdb testsuite. Array element stride must not be
24890 +# specified in the number of elements but in a number of bytes instead.
24891 +# Original problem:
24892 +# (gdb) p c40pt(1)
24893 +# $1 = '0-hello', ' ' <repeats 33 times>
24894 +# (gdb) p c40pt(2)
24895 +# warning: Fortran array stride not divisible by the element size
24897 +set testfile dwarf-stride
24898 +set srcfile ${testfile}.f90
24900 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } {
24904 +if ![runto MAIN__] then {
24905 + perror "couldn't run to breakpoint MAIN__"
24909 +gdb_breakpoint [gdb_get_line_number "break-here"]
24910 +gdb_continue_to_breakpoint "break-here" ".*break-here.*"
24911 +gdb_test "p c40pt(1)" " = '0-hello.*"
24912 +gdb_test "p c40pt(2)" " = '1-hello.*"
24913 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
24914 new file mode 100644
24915 index 0000000..e492b3a
24917 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
24919 +! Copyright 2009 Free Software Foundation, Inc.
24921 +! This program is free software; you can redistribute it and/or modify
24922 +! it under the terms of the GNU General Public License as published by
24923 +! the Free Software Foundation; either version 2 of the License, or
24924 +! (at your option) any later version.
24926 +! This program is distributed in the hope that it will be useful,
24927 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24928 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24929 +! GNU General Public License for more details.
24931 +! You should have received a copy of the GNU General Public License
24932 +! along with this program; if not, write to the Free Software
24933 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24935 +! File written by Alan Matsuoka.
24939 + type small_stride
24940 + character*40 long_string
24941 + integer small_pad
24942 + end type small_stride
24944 + type(small_stride), dimension (20), target :: unpleasant
24945 + character*40, pointer, dimension(:):: c40pt
24950 + unpleasant(i+1)%small_pad = i+1
24951 + unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
24954 + c40pt => unpleasant%long_string
24956 + print *, c40pt ! break-here
24959 diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
24960 new file mode 100644
24961 index 0000000..0ccebe0
24963 +++ b/gdb/testsuite/gdb.fortran/dynamic.exp
24965 +# Copyright 2007 Free Software Foundation, Inc.
24967 +# This program is free software; you can redistribute it and/or modify
24968 +# it under the terms of the GNU General Public License as published by
24969 +# the Free Software Foundation; either version 2 of the License, or
24970 +# (at your option) any later version.
24972 +# This program is distributed in the hope that it will be useful,
24973 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24974 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24975 +# GNU General Public License for more details.
24977 +# You should have received a copy of the GNU General Public License
24978 +# along with this program; if not, write to the Free Software
24979 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24981 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24983 +# This file is part of the gdb testsuite. It contains tests for dynamically
24984 +# allocated Fortran arrays.
24985 +# It depends on the GCC dynamic Fortran arrays DWARF support:
24986 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
24988 +set testfile "dynamic"
24989 +set srcfile ${testfile}.f90
24990 +set binfile ${objdir}/${subdir}/${testfile}
24992 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
24993 + untested "Couldn't compile ${srcfile}"
24999 +gdb_reinitialize_dir $srcdir/$subdir
25000 +gdb_load ${binfile}
25002 +if ![runto MAIN__] then {
25003 + perror "couldn't run to breakpoint MAIN__"
25007 +gdb_breakpoint [gdb_get_line_number "varx-init"]
25008 +gdb_continue_to_breakpoint "varx-init"
25009 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
25010 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
25011 +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"
25012 +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"
25013 +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"
25015 +gdb_breakpoint [gdb_get_line_number "varx-allocated"]
25016 +gdb_continue_to_breakpoint "varx-allocated"
25017 +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
25018 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
25019 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
25020 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
25022 +gdb_breakpoint [gdb_get_line_number "varx-filled"]
25023 +gdb_continue_to_breakpoint "varx-filled"
25024 +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
25025 +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
25026 +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
25027 +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
25028 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
25029 +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"
25030 +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"
25032 +gdb_breakpoint [gdb_get_line_number "varv-associated"]
25033 +gdb_continue_to_breakpoint "varv-associated"
25034 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
25035 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
25036 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
25037 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
25038 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
25039 +# Intel Fortran Compiler 10.1.008 uses the pointer type.
25040 +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
25042 +gdb_breakpoint [gdb_get_line_number "varv-filled"]
25043 +gdb_continue_to_breakpoint "varv-filled"
25044 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
25045 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
25047 +gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
25048 +gdb_continue_to_breakpoint "varv-deassociated"
25049 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
25050 +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"
25051 +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"
25052 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
25053 +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
25054 +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
25056 +gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
25057 +gdb_continue_to_breakpoint "varx-deallocated"
25058 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
25059 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
25060 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
25061 +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"
25062 +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"
25064 +gdb_breakpoint [gdb_get_line_number "vary-passed"]
25065 +gdb_continue_to_breakpoint "vary-passed"
25066 +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
25067 +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
25069 +gdb_breakpoint [gdb_get_line_number "vary-filled"]
25070 +gdb_continue_to_breakpoint "vary-filled"
25071 +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
25072 +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
25073 +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
25074 +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
25075 +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
25076 +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
25078 +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
25079 +gdb_continue_to_breakpoint "varw-almostfilled"
25080 +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
25081 +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
25082 +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
25083 +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
25084 +# "up" works with GCC but other Fortran compilers may copy the values into the
25085 +# outer function only on the exit of the inner function.
25086 +# We need both variants as depending on the arch we optionally may still be
25087 +# executing the caller line or not after `finish'.
25088 +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
25089 +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
25090 +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
25091 +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
25092 +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
25094 +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
25095 +gdb_continue_to_breakpoint "varz-almostfilled"
25096 +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
25097 +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
25098 +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
25099 +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
25100 +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
25101 +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
25102 +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
25103 +gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
25104 +# maps to foo::vary(1,1)
25105 +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
25106 +# maps to foo::vary(2,2)
25107 +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
25108 +# maps to foo::vary(1,3)
25109 +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
25110 diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
25111 new file mode 100644
25112 index 0000000..0f43564
25114 +++ b/gdb/testsuite/gdb.fortran/dynamic.f90
25116 +! Copyright 2007 Free Software Foundation, Inc.
25118 +! This program is free software; you can redistribute it and/or modify
25119 +! it under the terms of the GNU General Public License as published by
25120 +! the Free Software Foundation; either version 2 of the License, or
25121 +! (at your option) any later version.
25123 +! This program is distributed in the hope that it will be useful,
25124 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25125 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25126 +! GNU General Public License for more details.
25128 +! You should have received a copy of the GNU General Public License
25129 +! along with this program; if not, write to the Free Software
25130 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25132 +! Ihis file is the Fortran source file for dynamic.exp.
25133 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25134 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25137 + real, target, allocatable :: varx (:, :, :)
25138 + real, pointer :: varv (:, :, :)
25139 + real, target :: varu (1, 2, 3)
25141 + allocate (varx (1:6, 5:15, 17:28)) ! varx-init
25142 + l = allocated (varx)
25143 + varx(:, :, :) = 6 ! varx-allocated
25144 + varx(1, 5, 17) = 7
25145 + varx(2, 6, 18) = 8
25146 + varx(6, 15, 28) = 9
25147 + varv => varx ! varx-filled
25148 + l = associated (varv)
25149 + varv(3, 7, 19) = 10 ! varv-associated
25150 + varv => null () ! varv-filled
25151 + l = associated (varv)
25152 + deallocate (varx) ! varv-deassociated
25153 + l = allocated (varx)
25154 + varu(:, :, :) = 10 ! varx-deallocated
25155 + allocate (varv (1:6, 5:15, 17:28))
25156 + l = associated (varv)
25157 + varv(:, :, :) = 6
25158 + varv(1, 5, 17) = 7
25159 + varv(2, 6, 18) = 8
25160 + varv(6, 15, 28) = 9
25161 + deallocate (varv)
25162 + l = associated (varv)
25164 + varv(1, 1, 1) = 6
25165 + varv(1, 2, 3) = 7
25166 + l = associated (varv)
25167 +end subroutine baz
25168 +subroutine foo (vary, varw)
25169 + real :: vary (:, :)
25170 + real :: varw (:, :, :)
25171 + vary(:, :) = 4 ! vary-passed
25175 + varw(:, :, :) = 5 ! vary-filled
25176 + varw(1, 1, 1) = 6
25177 + varw(2, 2, 2) = 7 ! varw-almostfilled
25178 +end subroutine foo
25179 +subroutine bar (varz, vart)
25181 + real :: vart (2:11, 7:*)
25183 + varz(2) = 5 ! varz-almostfilled
25184 + vart(2,7) = vart(2,7)
25185 +end subroutine bar
25188 + subroutine foo (vary, varw)
25189 + real :: vary (:, :)
25190 + real :: varw (:, :, :)
25194 + subroutine bar (varz, vart)
25196 + real :: vart (2:11, 7:*)
25199 + real :: x (10, 10), y (5), z(8, 8, 8)
25204 + call foo (x, z(2:6, 4:7, 6:8))
25206 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
25207 + if (x (1, 3) .ne. 10) call abort
25208 + if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
25209 + if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
25210 + call foo (transpose (x), z)
25211 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
25212 + if (x (3, 1) .ne. 10) call abort
25214 diff --git a/gdb/testsuite/gdb.fortran/library-module-lib.f90 b/gdb/testsuite/gdb.fortran/library-module-lib.f90
25215 new file mode 100644
25216 index 0000000..6369d34
25218 +++ b/gdb/testsuite/gdb.fortran/library-module-lib.f90
25220 +! Copyright 2009 Free Software Foundation, Inc.
25222 +! This program is free software; you can redistribute it and/or modify
25223 +! it under the terms of the GNU General Public License as published by
25224 +! the Free Software Foundation; either version 3 of the License, or
25225 +! (at your option) any later version.
25227 +! This program is distributed in the hope that it will be useful,
25228 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25229 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25230 +! GNU General Public License for more details.
25232 +! You should have received a copy of the GNU General Public License
25233 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
25236 + integer :: var_i = 1
25238 + subroutine lib_func
25239 + if (var_i .ne. 1) call abort
25241 + end subroutine lib_func
25245 + integer :: var_j = 3
25246 + integer :: var_k = 4
25247 +end module libmany
25248 diff --git a/gdb/testsuite/gdb.fortran/library-module-main.f90 b/gdb/testsuite/gdb.fortran/library-module-main.f90
25249 new file mode 100644
25250 index 0000000..de63a65
25252 +++ b/gdb/testsuite/gdb.fortran/library-module-main.f90
25254 +! Copyright 2009 Free Software Foundation, Inc.
25256 +! This program is free software; you can redistribute it and/or modify
25257 +! it under the terms of the GNU General Public License as published by
25258 +! the Free Software Foundation; either version 3 of the License, or
25259 +! (at your option) any later version.
25261 +! This program is distributed in the hope that it will be useful,
25262 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25263 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25264 +! GNU General Public License for more details.
25266 +! You should have received a copy of the GNU General Public License
25267 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
25270 + use libmany, only: var_j
25271 + if (var_i .ne. 1) call abort
25273 + if (var_i .ne. 2) call abort
25274 + if (var_j .ne. 3) call abort
25275 + var_i = var_i ! i-is-2
25277 diff --git a/gdb/testsuite/gdb.fortran/library-module.exp b/gdb/testsuite/gdb.fortran/library-module.exp
25278 new file mode 100644
25279 index 0000000..4b4ea4c
25281 +++ b/gdb/testsuite/gdb.fortran/library-module.exp
25283 +# Copyright 2009 Free Software Foundation, Inc.
25285 +# This program is free software; you can redistribute it and/or modify
25286 +# it under the terms of the GNU General Public License as published by
25287 +# the Free Software Foundation; either version 3 of the License, or
25288 +# (at your option) any later version.
25290 +# This program is distributed in the hope that it will be useful,
25291 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25292 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25293 +# GNU General Public License for more details.
25295 +# You should have received a copy of the GNU General Public License
25296 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
25298 +set testfile "library-module"
25299 +set srcfile ${testfile}-main.f90
25300 +set srclibfile ${testfile}-lib.f90
25301 +set libfile ${testfile}-lib.so
25302 +set binfile ${testfile}
25304 +# Required for -fPIC by gdb_compile_shlib.
25305 +if [get_compiler_info not-used] {
25306 + warning "Could not get compiler info"
25310 +if { [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfile}" $objdir/$subdir/$libfile {debug f77}] != "" } {
25311 + untested "Couldn't compile ${srclibfile}"
25315 +# prepare_for_testing cannot be used as linking with $libfile cannot be passed
25316 +# just for the linking phase (and not the source compilation phase). And any
25317 +# warnings on ignored $libfile abort the process.
25319 +if { [gdb_compile [list $srcdir/$subdir/$srcfile $objdir/$subdir/$libfile] $objdir/$subdir/$binfile executable {debug f77}] != "" } {
25320 + untested "Couldn't compile ${srcfile}"
25324 +clean_restart $binfile
25326 +if ![runto MAIN__] then {
25327 + perror "couldn't run to breakpoint MAIN__"
25331 +gdb_breakpoint [gdb_get_line_number "i-is-2"]
25332 +gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
25333 +gdb_test "print var_i" " = 2"
25334 +gdb_test "print var_j" " = 3"
25335 +gdb_test "print var_k" "No symbol \"var_k\" in current context\\."
25336 diff --git a/gdb/testsuite/gdb.fortran/logical.exp b/gdb/testsuite/gdb.fortran/logical.exp
25337 new file mode 100644
25338 index 0000000..ef76f43
25340 +++ b/gdb/testsuite/gdb.fortran/logical.exp
25342 +# Copyright 2007 Free Software Foundation, Inc.
25344 +# This program is free software; you can redistribute it and/or modify
25345 +# it under the terms of the GNU General Public License as published by
25346 +# the Free Software Foundation; either version 2 of the License, or
25347 +# (at your option) any later version.
25349 +# This program is distributed in the hope that it will be useful,
25350 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25351 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25352 +# GNU General Public License for more details.
25354 +# You should have received a copy of the GNU General Public License
25355 +# along with this program; if not, write to the Free Software
25356 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25358 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25360 +set testfile "logical"
25361 +set srcfile ${testfile}.f90
25362 +set binfile ${objdir}/${subdir}/${testfile}
25364 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25365 + untested "Couldn't compile ${srcfile}"
25371 +gdb_reinitialize_dir $srcdir/$subdir
25372 +gdb_load ${binfile}
25374 +if ![runto MAIN__] then {
25375 + perror "couldn't run to breakpoint MAIN__"
25379 +gdb_breakpoint [gdb_get_line_number "stop-here"]
25380 +gdb_continue_to_breakpoint "stop-here"
25381 +gdb_test "p l" " = \\.TRUE\\."
25382 +gdb_test "p l1" " = \\.TRUE\\."
25383 +gdb_test "p l2" " = \\.TRUE\\."
25384 +gdb_test "p l4" " = \\.TRUE\\."
25385 +gdb_test "p l8" " = \\.TRUE\\."
25386 diff --git a/gdb/testsuite/gdb.fortran/logical.f90 b/gdb/testsuite/gdb.fortran/logical.f90
25387 new file mode 100644
25388 index 0000000..4229304
25390 +++ b/gdb/testsuite/gdb.fortran/logical.f90
25392 +! Copyright 2008 Free Software Foundation, Inc.
25394 +! This program is free software; you can redistribute it and/or modify
25395 +! it under the terms of the GNU General Public License as published by
25396 +! the Free Software Foundation; either version 2 of the License, or
25397 +! (at your option) any later version.
25399 +! This program is distributed in the hope that it will be useful,
25400 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25401 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25402 +! GNU General Public License for more details.
25404 +! You should have received a copy of the GNU General Public License
25405 +! along with this program; if not, write to the Free Software
25406 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25408 +! Ihis file is the Fortran source file for dynamic.exp.
25409 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25410 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25414 + logical (kind=1) :: l1
25415 + logical (kind=2) :: l2
25416 + logical (kind=4) :: l4
25417 + logical (kind=8) :: l8
25423 + l = .FALSE. ! stop-here
25425 diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
25426 index 342ccee..c836c3c 100644
25427 --- a/gdb/testsuite/gdb.fortran/module.exp
25428 +++ b/gdb/testsuite/gdb.fortran/module.exp
25429 @@ -15,21 +15,31 @@
25431 set testfile "module"
25432 set srcfile ${testfile}.f90
25433 -set binfile ${objdir}/${subdir}/${testfile}
25435 -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25436 - untested "Couldn't compile ${srcfile}"
25437 +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f77}] } {
25443 -gdb_reinitialize_dir $srcdir/$subdir
25444 -gdb_load ${binfile}
25446 if ![runto MAIN__] then {
25447 perror "couldn't run to breakpoint MAIN__"
25451 -gdb_test "print i" " = 42"
25452 +# Do not use simple single-letter names as GDB would pick up for expectedly
25453 +# nonexisting symbols some static variables from system libraries debuginfos.
25455 +gdb_breakpoint [gdb_get_line_number "i-is-1"]
25456 +gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
25457 +gdb_test "print var_i" " = 1" "print var_i value 1"
25459 +gdb_breakpoint [gdb_get_line_number "i-is-2"]
25460 +gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
25461 +gdb_test "print var_i" " = 2" "print var_i value 2"
25463 +gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
25464 +gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
25465 +gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
25466 +gdb_test "print var_b" " = 11"
25467 +gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
25468 +gdb_test "print var_d" " = 12"
25469 +gdb_test "print var_i" " = 14" "print var_i value 14"
25470 diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
25471 index 501ccc8..118931d 100644
25472 --- a/gdb/testsuite/gdb.fortran/module.f90
25473 +++ b/gdb/testsuite/gdb.fortran/module.f90
25474 @@ -13,10 +13,37 @@
25475 ! You should have received a copy of the GNU General Public License
25476 ! along with this program. If not, see <http://www.gnu.org/licenses/>.
25479 - integer :: i = 42
25482 + integer :: var_i = 1
25488 + integer :: var_i = 2
25492 + integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
25493 +end module modmany
25497 + if (var_i .ne. 1) call abort
25498 + var_i = var_i ! i-is-1
25503 + if (var_i .ne. 2) call abort
25504 + var_i = var_i ! i-is-2
25507 + use modmany, only: var_b, var_d => var_c, var_i
25512 + if (var_b .ne. 11) call abort
25513 + if (var_d .ne. 12) call abort
25514 + if (var_i .ne. 14) call abort
25515 + var_b = var_b ! a-b-c-d
25517 diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
25518 new file mode 100644
25519 index 0000000..b1120c3
25521 +++ b/gdb/testsuite/gdb.fortran/string.exp
25523 +# Copyright 2008 Free Software Foundation, Inc.
25525 +# This program is free software; you can redistribute it and/or modify
25526 +# it under the terms of the GNU General Public License as published by
25527 +# the Free Software Foundation; either version 2 of the License, or
25528 +# (at your option) any later version.
25530 +# This program is distributed in the hope that it will be useful,
25531 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25532 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25533 +# GNU General Public License for more details.
25535 +# You should have received a copy of the GNU General Public License
25536 +# along with this program; if not, write to the Free Software
25537 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25539 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25541 +# This file is part of the gdb testsuite. It contains tests for Fortran
25542 +# strings with dynamic length.
25544 +set testfile "string"
25545 +set srcfile ${testfile}.f90
25546 +set binfile ${objdir}/${subdir}/${testfile}
25548 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25549 + untested "Couldn't compile ${srcfile}"
25555 +gdb_reinitialize_dir $srcdir/$subdir
25556 +gdb_load ${binfile}
25558 +if ![runto MAIN__] then {
25559 + perror "couldn't run to breakpoint MAIN__"
25563 +gdb_breakpoint [gdb_get_line_number "var-init"]
25564 +gdb_continue_to_breakpoint "var-init"
25565 +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
25566 +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
25567 +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
25568 +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
25569 +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
25570 +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
25571 +gdb_test "p c" "\\$\[0-9\]* = 'c'"
25572 +gdb_test "p d" "\\$\[0-9\]* = 'd '"
25573 +gdb_test "p e" "\\$\[0-9\]* = 'g '"
25574 +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 '\\) \\)"
25575 +gdb_test "p *e" "Attempt to take contents of a non-pointer value."
25576 +gdb_test "p *f" "Attempt to take contents of a non-pointer value."
25578 +gdb_breakpoint [gdb_get_line_number "var-finish"]
25579 +gdb_continue_to_breakpoint "var-finish"
25580 +gdb_test "p e" "\\$\[0-9\]* = 'e '" "p e re-set"
25581 +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"
25582 diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
25583 new file mode 100644
25584 index 0000000..226dc5d
25586 +++ b/gdb/testsuite/gdb.fortran/string.f90
25588 +! Copyright 2008 Free Software Foundation, Inc.
25590 +! This program is free software; you can redistribute it and/or modify
25591 +! it under the terms of the GNU General Public License as published by
25592 +! the Free Software Foundation; either version 2 of the License, or
25593 +! (at your option) any later version.
25595 +! This program is distributed in the hope that it will be useful,
25596 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25597 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25598 +! GNU General Public License for more details.
25600 +! You should have received a copy of the GNU General Public License
25601 +! along with this program; if not, write to the Free Software
25602 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25604 +! Ihis file is the Fortran source file for dynamic.exp.
25605 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25606 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25608 +subroutine foo (e, f)
25609 + character (len=1) :: c
25610 + character (len=8) :: d
25611 + character (len=*) :: e
25612 + character (len=*) :: f (1:7, 8:10)
25615 + e = 'e' ! var-init
25618 + c = 'c' ! var-finish
25619 +end subroutine foo
25620 + character (len=4) :: g, h (1:7, 8:10)
25625 diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
25626 index 495ae45..d08d7a4 100644
25627 --- a/gdb/testsuite/gdb.gdb/selftest.exp
25628 +++ b/gdb/testsuite/gdb.gdb/selftest.exp
25629 @@ -95,6 +95,10 @@ proc do_steps_and_nexts {} {
25630 set description "step over ttyarg initialization"
25633 + -re ".*python_script = 0.*$gdb_prompt $" {
25634 + set description "step over python_script initialization"
25635 + set command "step"
25637 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
25638 set description "next over get_run_time and everything it calls"
25640 diff --git a/gdb/testsuite/gdb.java/jnpe.exp b/gdb/testsuite/gdb.java/jnpe.exp
25641 new file mode 100644
25642 index 0000000..e71391e
25644 +++ b/gdb/testsuite/gdb.java/jnpe.exp
25646 +# Copyright 2009 Free Software Foundation, Inc.
25648 +# This program is free software; you can redistribute it and/or modify
25649 +# it under the terms of the GNU General Public License as published by
25650 +# the Free Software Foundation; either version 3 of the License, or
25651 +# (at your option) any later version.
25653 +# This program is distributed in the hope that it will be useful,
25654 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25655 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25656 +# GNU General Public License for more details.
25658 +# You should have received a copy of the GNU General Public License
25659 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
25661 +if $tracelevel then {
25662 + strace $tracelevel
25665 +load_lib "java.exp"
25667 +set testfile "jnpe"
25668 +set srcfile ${testfile}.java
25669 +set binfile ${objdir}/${subdir}/${testfile}
25670 +if { [compile_java_from_source ${srcdir}/$subdir/${srcfile} ${binfile} "-g"] != "" } {
25671 + untested "Couldn't compile ${srcdir}/$subdir/${srcfile}"
25678 +# Start with a fresh gdb.
25682 +gdb_reinitialize_dir $srcdir/$subdir
25683 +gdb_load ${binfile}
25685 +set line [gdb_get_line_number "break here" $testfile.java]
25686 +gdb_test "break $testfile.java:$line" ""
25689 + "// break here.*" \
25690 + "run java next-over-throw"
25692 +# See whether we have the needed unwinder hooks.
25694 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook in java" {
25695 + -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
25696 + pass "check for unwinder hook in java"
25698 + -re "No symbol .* in current context.?\r\n$gdb_prompt $" {
25699 + # Pass the test so we don't get bogus fails in the results.
25700 + setup_xfail *-*-*
25701 + fail "check for unwinder hook in java"
25706 + untested jnpe.exp
25710 +gdb_test "handle SIGSEGV nostop noprint" \
25711 + "SIGSEGV.*fault" \
25712 + "disable SIGSEGV for next-over-NPE"
25714 +# The line where we stop differ according to gcj; check just we did not already
25715 +# execute the catch point.
25721 +gdb_breakpoint [gdb_get_line_number "catch point"]
25722 +gdb_continue_to_breakpoint "catch point" ".*// catch point.*"
25723 diff --git a/gdb/testsuite/gdb.java/jnpe.java b/gdb/testsuite/gdb.java/jnpe.java
25724 new file mode 100644
25725 index 0000000..3524830
25727 +++ b/gdb/testsuite/gdb.java/jnpe.java
25729 +// Test next-over-NPE.
25730 +/* This testcase is part of GDB, the GNU debugger.
25732 + Copyright 2009 Free Software Foundation, Inc.
25734 + This program is free software; you can redistribute it and/or modify
25735 + it under the terms of the GNU General Public License as published by
25736 + the Free Software Foundation; either version 3 of the License, or
25737 + (at your option) any later version.
25739 + This program is distributed in the hope that it will be useful,
25740 + but WITHOUT ANY WARRANTY; without even the implied warranty of
25741 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25742 + GNU General Public License for more details.
25744 + You should have received a copy of the GNU General Public License
25745 + along with this program. If not, see <http://www.gnu.org/licenses/>.
25750 + public static String npe ()
25752 + return ((Object) null).toString();
25755 + public static void main (String[] args)
25759 + System.out.println (npe ()); // break here
25761 + catch (NullPointerException n)
25763 + System.out.println ("success"); // catch point
25767 diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
25768 new file mode 100644
25769 index 0000000..729f457
25771 +++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
25773 +/* This file is part of GDB, the GNU debugger.
25775 + Copyright 2009 Free Software Foundation, Inc.
25777 + This program is free software; you can redistribute it and/or modify
25778 + it under the terms of the GNU General Public License as published by
25779 + the Free Software Foundation; either version 3 of the License, or
25780 + (at your option) any later version.
25782 + This program is distributed in the hope that it will be useful,
25783 + but WITHOUT ANY WARRANTY; without even the implied warranty of
25784 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25785 + GNU General Public License for more details.
25787 + You should have received a copy of the GNU General Public License
25788 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
25795 diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
25796 new file mode 100644
25797 index 0000000..3090e7e
25799 +++ b/gdb/testsuite/gdb.opt/array-from-register.c
25801 +/* This file is part of GDB, the GNU debugger.
25803 + Copyright 2009 Free Software Foundation, Inc.
25805 + This program is free software; you can redistribute it and/or modify
25806 + it under the terms of the GNU General Public License as published by
25807 + the Free Software Foundation; either version 3 of the License, or
25808 + (at your option) any later version.
25810 + This program is distributed in the hope that it will be useful,
25811 + but WITHOUT ANY WARRANTY; without even the implied warranty of
25812 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25813 + GNU General Public License for more details.
25815 + You should have received a copy of the GNU General Public License
25816 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
25818 +extern int func (int *arr);
25823 + int arr[] = { 42 };
25829 diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
25830 new file mode 100644
25831 index 0000000..f2de718
25833 +++ b/gdb/testsuite/gdb.opt/array-from-register.exp
25835 +# Copyright 2009 Free Software Foundation, Inc.
25837 +# This program is free software; you can redistribute it and/or modify
25838 +# it under the terms of the GNU General Public License as published by
25839 +# the Free Software Foundation; either version 2 of the License, or
25840 +# (at your option) any later version.
25842 +# This program is distributed in the hope that it will be useful,
25843 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25844 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25845 +# GNU General Public License for more details.
25847 +# You should have received a copy of the GNU General Public License
25848 +# along with this program; if not, write to the Free Software
25849 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25851 +# This file is part of the gdb testsuite.
25853 +if { [prepare_for_testing array-from-register.exp "array-from-register" \
25854 + {array-from-register.c array-from-register-func.c} \
25855 + {debug optimize=-O2}] } {
25859 +if ![runto func] then {
25863 +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
25865 +# Seen regression:
25866 +# Address requested for identifier "arr" which is in register $rdi
25867 +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
25868 diff --git a/gdb/testsuite/gdb.opt/fortran-string.exp b/gdb/testsuite/gdb.opt/fortran-string.exp
25869 new file mode 100644
25870 index 0000000..f997eec
25872 +++ b/gdb/testsuite/gdb.opt/fortran-string.exp
25874 +# Copyright 2009 Free Software Foundation, Inc.
25876 +# This program is free software; you can redistribute it and/or modify
25877 +# it under the terms of the GNU General Public License as published by
25878 +# the Free Software Foundation; either version 2 of the License, or
25879 +# (at your option) any later version.
25881 +# This program is distributed in the hope that it will be useful,
25882 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25883 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25884 +# GNU General Public License for more details.
25886 +# You should have received a copy of the GNU General Public License
25887 +# along with this program; if not, write to the Free Software
25888 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25890 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25892 +# Test GDB can cope with Fortran strings having their length present in a CPU
25893 +# register. With -O0 the string length is passed on the stack. To make this
25894 +# test meaningful the follow assertion should pass. It is not being checked
25895 +# here as the "_s" symbol is compiler dependent:
25896 +# (gdb) info address _s
25897 +# Symbol "_s" is a variable in register XX.
25899 +set test fortran-string
25900 +set srcfile ${test}.f90
25901 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile} {debug f77 additional_flags=-O2}] } {
25905 +if ![runto MAIN__] then {
25906 + perror "couldn't run to breakpoint MAIN__"
25910 +gdb_breakpoint [gdb_get_line_number "s = s"]
25911 +gdb_continue_to_breakpoint "s = s"
25912 +gdb_test "frame" ".*s='foo'.*"
25913 +gdb_test "ptype s" "type = character\\*3"
25914 +gdb_test "p s" "\\$\[0-9\]* = 'foo'"
25915 diff --git a/gdb/testsuite/gdb.opt/fortran-string.f90 b/gdb/testsuite/gdb.opt/fortran-string.f90
25916 new file mode 100644
25917 index 0000000..e48d520
25919 +++ b/gdb/testsuite/gdb.opt/fortran-string.f90
25921 +! Copyright 2009 Free Software Foundation, Inc.
25923 +! This program is free software; you can redistribute it and/or modify
25924 +! it under the terms of the GNU General Public License as published by
25925 +! the Free Software Foundation; either version 2 of the License, or
25926 +! (at your option) any later version.
25928 +! This program is distributed in the hope that it will be useful,
25929 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25930 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25931 +! GNU General Public License for more details.
25933 +! You should have received a copy of the GNU General Public License
25934 +! along with this program; if not, write to the Free Software
25935 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25937 +! Ihis file is the Fortran source file for dynamic.exp.
25938 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25939 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25949 diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
25950 index f6ef938..1032a2d 100644
25951 --- a/gdb/testsuite/gdb.python/py-cmd.exp
25952 +++ b/gdb/testsuite/gdb.python/py-cmd.exp
25953 @@ -20,36 +20,15 @@ if $tracelevel then {
25957 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
25958 -# Run a test named NAME, consisting of multiple lines of input.
25959 -# After each input line INPUT, search for result line RESULT.
25960 -# Succeed if all results are seen; fail otherwise.
25961 -proc gdb_py_test_multiple {name args} {
25962 - global gdb_prompt
25963 - foreach {input result} $args {
25964 - if {[gdb_test_multiple $input "$name - $input" {
25965 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
25966 - pass "$name - $input"
25975 # Start with a fresh gdb.
25979 gdb_reinitialize_dir $srcdir/$subdir
25981 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25982 - -re "not supported.*$gdb_prompt $" {
25983 - unsupported "python support is disabled"
25986 - -re "$gdb_prompt $" {}
25987 +if ![python_supported] then {
25988 + unsupported "python support is disabled"
25992 # Test a simple command.
25993 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
25994 index a67eaa3..5380c0f 100644
25995 --- a/gdb/testsuite/gdb.python/py-frame.exp
25996 +++ b/gdb/testsuite/gdb.python/py-frame.exp
25997 @@ -20,40 +20,28 @@ if $tracelevel then {
26001 +# Start with a fresh gdb.
26005 +gdb_reinitialize_dir $srcdir/$subdir
26007 +if ![python_supported] then {
26008 + unsupported "python support is disabled"
26012 set testfile "py-frame"
26013 set srcfile ${testfile}.c
26014 set binfile ${objdir}/${subdir}/${testfile}
26016 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26017 untested "Couldn't compile ${srcfile}"
26021 -# Run a command in GDB, and report a failure if a Python exception is thrown.
26022 -# If report_pass is true, report a pass if no exception is thrown.
26023 -proc gdb_py_test_silent_cmd {cmd name report_pass} {
26024 - global gdb_prompt
26026 - gdb_test_multiple $cmd $name {
26027 - -re "Traceback.*$gdb_prompt $" { fail $name }
26028 - -re "$gdb_prompt $" { if $report_pass { pass $name } }
26032 -# Start with a fresh gdb.
26036 -gdb_reinitialize_dir $srcdir/$subdir
26037 gdb_load ${binfile}
26039 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26040 - -re "not supported.*$gdb_prompt $" {
26041 - unsupported "python support is disabled"
26044 - -re "$gdb_prompt $" {}
26047 # The following tests require execution.
26049 if ![runto_main] then {
26050 @@ -65,19 +53,20 @@ gdb_breakpoint "f2"
26051 gdb_continue_to_breakpoint "breakpoint at f2"
26052 gdb_test "up" "" ""
26054 -gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
26055 -gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
26056 +gdb_py_test_silent_cmd "python frames = gdb.selected_thread ().frames ()" "get frames list" 1
26057 +gdb_test "python print frames" "\\(<gdb.Frame object at 0x\[\[:xdigit:\]\]+>, <gdb.Frame object at 0x\[\[:xdigit:\]\]+>, <gdb.Frame object at 0x\[\[:xdigit:\]\]+>\\)" "verify frames list"
26058 +gdb_py_test_silent_cmd "python f0 = frames\[0\]" "get first frame" 0
26059 +gdb_py_test_silent_cmd "python f1 = frames\[1\]" "get second frame" 0
26061 gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
26062 gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
26063 -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
26064 -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
26065 gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
26066 gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
26067 gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
26068 gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type"
26069 gdb_test "python print 'result =', gdb.frame_stop_reason_string (gdb.FRAME_UNWIND_INNER_ID)" " = previous frame inner to this frame \\(corrupt stack\\?\\)" "test gdb.frame_stop_reason_string"
26070 gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
26071 +gdb_test "python print 'result =', f0.function ()" " = symbol for f2" "test Frame.function"
26072 gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older"
26073 gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer"
26074 gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \
26075 @@ -85,4 +74,7 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
26076 "test Frame.read_var - error"
26077 gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
26079 +gdb_test "python print 'result =', gdb.selected_thread ().newest_frame () == f0" " = True" "test gdb.newest_frame"
26080 gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
26082 +gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
26083 diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
26084 index 30fde7d..14cd90c 100644
26085 --- a/gdb/testsuite/gdb.python/py-function.exp
26086 +++ b/gdb/testsuite/gdb.python/py-function.exp
26087 @@ -20,36 +20,15 @@ if $tracelevel then {
26091 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
26092 -# Run a test named NAME, consisting of multiple lines of input.
26093 -# After each input line INPUT, search for result line RESULT.
26094 -# Succeed if all results are seen; fail otherwise.
26095 -proc gdb_py_test_multiple {name args} {
26096 - global gdb_prompt
26097 - foreach {input result} $args {
26098 - if {[gdb_test_multiple $input "$name - $input" {
26099 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
26100 - pass "$name - $input"
26109 # Start with a fresh gdb.
26113 gdb_reinitialize_dir $srcdir/$subdir
26115 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26116 - -re "not supported.*$gdb_prompt $" {
26117 - unsupported "python support is disabled"
26120 - -re "$gdb_prompt $" {}
26121 +if ![python_supported] then {
26122 + unsupported "python support is disabled"
26126 gdb_py_test_multiple "input convenience function" \
26127 diff --git a/gdb/testsuite/gdb.python/py-inferior.c b/gdb/testsuite/gdb.python/py-inferior.c
26128 new file mode 100644
26129 index 0000000..0b48299
26131 +++ b/gdb/testsuite/gdb.python/py-inferior.c
26133 +#include <stdio.h>
26134 +#include <stdlib.h>
26135 +#include <stdint.h>
26136 +#include <string.h>
26138 +#define CHUNK_SIZE 16000 /* same as findcmd.c's */
26139 +#define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
26141 +static int8_t int8_search_buf[100];
26142 +static int16_t int16_search_buf[100];
26143 +static int32_t int32_search_buf[100];
26144 +static int64_t int64_search_buf[100];
26146 +static char *search_buf;
26147 +static int search_buf_size;
26154 + char *str = "hello, testsuite";
26156 + puts (str); /* Break here. */
26161 +int f1 (int a, int b)
26163 + return f2(a) + b;
26169 + search_buf_size = BUF_SIZE;
26170 + search_buf = malloc (search_buf_size);
26171 + if (search_buf == NULL)
26173 + memset (search_buf, 'x', search_buf_size);
26176 +int main (int argc, char *argv[])
26180 + return f1 (1, 2);
26182 diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
26183 new file mode 100644
26184 index 0000000..719b178
26186 +++ b/gdb/testsuite/gdb.python/py-inferior.exp
26188 +# Copyright (C) 2009 Free Software Foundation, Inc.
26190 +# This program is free software; you can redistribute it and/or modify
26191 +# it under the terms of the GNU General Public License as published by
26192 +# the Free Software Foundation; either version 3 of the License, or
26193 +# (at your option) any later version.
26195 +# This program is distributed in the hope that it will be useful,
26196 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
26197 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26198 +# GNU General Public License for more details.
26200 +# You should have received a copy of the GNU General Public License
26201 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
26203 +# This file is part of the GDB testsuite. It tests the mechanism
26204 +# exposing inferiors to Python.
26206 +if $tracelevel then {
26207 + strace $tracelevel
26210 +# Start with a fresh gdb.
26214 +gdb_reinitialize_dir $srcdir/$subdir
26216 +if ![python_supported] then {
26217 + unsupported "python support is disabled"
26221 +set testfile "py-inferior"
26222 +set srcfile ${testfile}.c
26223 +set binfile ${objdir}/${subdir}/${testfile}
26225 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26226 + untested "Couldn't compile ${srcfile}"
26230 +gdb_load ${binfile}
26232 +# The following tests require execution.
26234 +if ![runto_main] then {
26235 + fail "Can't run to main"
26239 +runto [gdb_get_line_number "Break here."]
26241 +# Test basic gdb.Inferior attributes and methods.
26243 +gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
26244 +gdb_test "python print inferiors" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list"
26245 +gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
26247 +gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)"
26248 +gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num"
26249 +gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
26250 +gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
26251 +gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
26253 +# Test memory read and write operations.
26255 +gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
26256 + "read str address" 0
26257 +gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \
26258 + "read str contents" 1
26259 +gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0
26260 +gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
26262 +gdb_test "print str" " = 0x\[\[:xdigit:\]\]+ \"hallo, testsuite\"" \
26263 + "ensure str was changed in the inferior"
26265 +# Test memory search.
26267 +set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
26268 +set dec_number {[0-9]+}
26269 +set history_prefix {[$][0-9]* = }
26270 +set newline {[\r\n]+}
26271 +set pattern_not_found "${newline}.]"
26272 +set one_pattern_found "${newline}.${dec_number}L]"
26273 +set two_patterns_found "${newline}.${dec_number}L, ${dec_number}L]"
26275 +# Test string pattern.
26277 +gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
26278 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')" "" ""
26279 +gdb_test "py start_addr = search_buf.address" "" ""
26280 +gdb_test "py length = search_buf.type.sizeof" "" ""
26282 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa')" \
26283 + "${two_patterns_found}" "find string pattern"
26285 +# Test not finding pattern because search range too small, with
26286 +# potential find at the edge of the range.
26288 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3, 'aaaa')" \
26289 + "${pattern_not_found}" "pattern not found at end of range"
26291 +# Increase the search range by 1 and we should find the pattern.
26293 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3+1, \['a', 'a', 'a', 'a'\])" \
26294 + "${one_pattern_found}" "pattern found at end of range"
26296 +# Test max-count with size, with different parameter position
26298 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], 1, 1)" \
26299 + "${one_pattern_found}" "size = 1, max_count = 1"
26301 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], 1, 2)" \
26302 + "${two_patterns_found}" "size = 1, max_count = 2, normal ordering"
26304 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], size = 1, max_count = 2)" \
26305 + "${two_patterns_found}" "size = 1, max_count = 2, normal ordering, with keywords"
26307 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], max_count = 2, size = 1)" \
26308 + "${two_patterns_found}" "size = 1, max_count = 2, inverted ordering"
26310 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \['a', 'a'\], max_count = 2)" \
26311 + "${two_patterns_found}" "max_count = 2, with keyword"
26313 +# Test 16-bit pattern.
26315 +gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
26316 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" ""
26317 +gdb_test "py start_addr = search_buf.address" "" ""
26318 +gdb_test "py length = search_buf.type.sizeof" "" ""
26319 +gdb_test "py pattern = gdb.parse_and_eval ('(int16_t) 0x1234')" "" ""
26321 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x1234, 2)" \
26322 + "${one_pattern_found}" "find 16-bit pattern, with python pattern"
26324 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26325 + "${one_pattern_found}" "find 16-bit pattern, with value pattern"
26327 +# Test 32-bit pattern.
26329 +gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
26330 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" ""
26331 +gdb_test "py start_addr = search_buf.address" "" ""
26332 +gdb_test "py length = search_buf.type.sizeof" "" ""
26333 +gdb_test "py pattern = gdb.parse_and_eval ('(int32_t) 0x12345678')" "" ""
26335 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x12345678, 4)" \
26336 + "${one_pattern_found}" "find 32-bit pattern, with python pattern"
26337 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26338 + "${one_pattern_found}" "find 32-bit pattern, with value pattern"
26340 +# Test 64-bit pattern.
26342 +gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
26343 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" ""
26344 +gdb_test "py start_addr = search_buf.address" "" ""
26345 +gdb_test "py length = search_buf.type.sizeof" "" ""
26346 +gdb_test "py pattern = gdb.parse_and_eval ('(int64_t) 0xfedcba9876543210LL')" "" ""
26348 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0xfedcba9876543210, 8)" \
26349 + "${one_pattern_found}" "find 64-bit pattern, with python pattern"
26350 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26351 + "${one_pattern_found}" "find 64-bit pattern, with value pattern"
26353 +# Test mixed-sized patterns.
26355 +gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
26356 +gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
26357 +gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
26358 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" ""
26359 +gdb_test "py start_addr = search_buf\[0\].address" "" ""
26360 +gdb_test "py pattern1 = gdb.parse_and_eval ('(int8_t) 0x62')" "" ""
26361 +gdb_test "py pattern2 = gdb.parse_and_eval ('(int16_t) 0x6363')" "" ""
26362 +gdb_test "py pattern3 = gdb.parse_and_eval ('(int32_t) 0x64646464')" "" ""
26364 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, \[pattern1, pattern2, pattern3\])" \
26365 + "${one_pattern_found}" "find mixed-sized pattern"
26367 +# Test search spanning a large range, in the particular case of native
26368 +# targets, test the search spanning multiple chunks.
26369 +# Remote targets may implement the search differently.
26371 +set CHUNK_SIZE 16000 ;
26373 +gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
26374 +gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
26375 +gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
26376 +gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" ""
26378 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x12345678, 4)" \
26379 + "${two_patterns_found}" "search spanning large range"
26381 +# For native targets, test a pattern straddling a chunk boundary.
26384 + gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
26386 + gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0xfdb97531, 4)" \
26387 + "${one_pattern_found}" "find pattern straddling chunk boundary"
26389 diff --git a/gdb/testsuite/gdb.python/py-infthread.c b/gdb/testsuite/gdb.python/py-infthread.c
26390 new file mode 100644
26391 index 0000000..22eb9f2
26393 +++ b/gdb/testsuite/gdb.python/py-infthread.c
26400 +int f1 (int a, int b)
26402 + return f2(a) + b;
26405 +int main (int argc, char *argv[])
26407 + return f1 (1, 2);
26409 diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
26410 new file mode 100644
26411 index 0000000..e9d18b7
26413 +++ b/gdb/testsuite/gdb.python/py-infthread.exp
26415 +# Copyright (C) 2009 Free Software Foundation, Inc.
26417 +# This program is free software; you can redistribute it and/or modify
26418 +# it under the terms of the GNU General Public License as published by
26419 +# the Free Software Foundation; either version 3 of the License, or
26420 +# (at your option) any later version.
26422 +# This program is distributed in the hope that it will be useful,
26423 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
26424 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26425 +# GNU General Public License for more details.
26427 +# You should have received a copy of the GNU General Public License
26428 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
26430 +# This file is part of the GDB testsuite. It tests the mechanism
26431 +# exposing inferior threads to Python.
26433 +if $tracelevel then {
26434 + strace $tracelevel
26437 +# Start with a fresh gdb.
26441 +gdb_reinitialize_dir $srcdir/$subdir
26443 +if ![python_supported] then {
26444 + unsupported "python support is disabled"
26448 +set testfile "py-infthread"
26449 +set srcfile ${testfile}.c
26450 +set binfile ${objdir}/${subdir}/${testfile}
26452 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26453 + untested "Couldn't compile ${srcfile}"
26457 +gdb_load ${binfile}
26459 +# The following tests require execution.
26461 +if ![runto_main] then {
26462 + fail "Can't run to main"
26466 +runto [gdb_get_line_number "Break here."]
26468 +# Test basic gdb.Inferior attributes and methods.
26470 +gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1
26471 +gdb_test "python print t0" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
26472 +gdb_test "python print 'result =', t0.num" " = \[0-9\]+" "test Inferior.num"
26473 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
26474 index b4b3776..359c4ed 100644
26475 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp
26476 +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
26477 @@ -27,12 +27,20 @@ set binfile ${objdir}/${subdir}/${testfile}
26478 # Start with a fresh gdb.
26481 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26482 - -re "not supported.*$gdb_prompt $" {
26483 - unsupported "python support is disabled"
26486 - -re "$gdb_prompt $" {}
26487 +if ![python_supported] then {
26488 + unsupported "python support is disabled"
26492 +# Run a command in GDB, and report a failure if a Python exception is thrown.
26493 +# If report_pass is true, report a pass if no exception is thrown.
26494 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
26495 + global gdb_prompt
26497 + gdb_test_multiple $cmd $name {
26498 + -re "Traceback.*$gdb_prompt $" { fail $name }
26499 + -re "$gdb_prompt $" { if $report_pass { pass $name } }
26503 # Run a command in GDB, and report a failure if a Python exception is thrown.
26504 @@ -102,6 +110,8 @@ proc run_lang_tests {lang} {
26506 gdb_test "print c" " = container $hex \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
26508 + gdb_test "print nullstr" "RuntimeError: Error reading string from inferior.*"
26510 gdb_test "continue" "Program exited normally\."
26513 diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp
26514 index cea6ae0..c9a63d4 100644
26515 --- a/gdb/testsuite/gdb.python/py-template.exp
26516 +++ b/gdb/testsuite/gdb.python/py-template.exp
26517 @@ -20,6 +20,17 @@ if $tracelevel then {
26521 +# Start with a fresh gdb.
26525 +gdb_reinitialize_dir $srcdir/$subdir
26527 +if ![python_supported] then {
26528 + unsupported "python support is disabled"
26532 set testfile "py-template"
26533 set srcfile ${testfile}.cc
26534 set binfile ${objdir}/${subdir}/${testfile}
26535 @@ -29,20 +40,6 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
26539 -# Start with a fresh gdb.
26543 -gdb_reinitialize_dir $srcdir/$subdir
26545 -gdb_test_multiple "python print 23" "verify python support" {
26546 - -re "not supported.*$gdb_prompt $" {
26547 - unsupported "python support is disabled"
26550 - -re "$gdb_prompt $" {}
26553 proc test_template_arg {type} {
26554 global testfile srcdir subdir srcfile binfile
26555 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
26556 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
26557 index 2958233..0de1cae 100644
26558 --- a/gdb/testsuite/gdb.python/py-value.exp
26559 +++ b/gdb/testsuite/gdb.python/py-value.exp
26560 @@ -292,6 +292,15 @@ proc test_value_after_death {} {
26561 "print value's type"
26564 +# Regression test for a cast failure. The bug was that if we cast a
26565 +# value to its own type, gdb could crash. This happened because we
26566 +# could end up double-freeing a struct value.
26567 +proc test_cast_regression {} {
26568 + gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
26569 + gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
26570 + gdb_test "python print v" "5" "print value for cast test"
26573 # Regression test for invalid subscript operations. The bug was that
26574 # the type of the value was not being checked before allowing a
26575 # subscript operation to proceed.
26576 @@ -366,16 +375,23 @@ proc test_subscript_regression {lang} {
26579 gdb_reinitialize_dir $srcdir/$subdir
26580 -gdb_load ${binfile}
26582 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26583 - -re "not supported.*$gdb_prompt $" {
26584 - unsupported "python support is disabled"
26587 - -re "$gdb_prompt $" {}
26588 +if ![python_supported] then {
26589 + unsupported "python support is disabled"
26593 +set testfile "py-value"
26594 +set srcfile ${testfile}.c
26595 +set binfile ${objdir}/${subdir}/${testfile}
26597 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26598 + untested "Couldn't compile ${srcfile}"
26602 +gdb_load ${binfile}
26604 test_value_creation
26605 test_value_numeric_ops
26607 @@ -391,6 +407,7 @@ if ![runto_main] then {
26609 test_value_in_inferior
26610 test_value_after_death
26611 +test_cast_regression
26613 # The following test recompiles the binary to test either C or C++
26615 diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
26616 index 5223fc8..03e1eab 100644
26617 --- a/gdb/testsuite/gdb.python/python.exp
26618 +++ b/gdb/testsuite/gdb.python/python.exp
26619 @@ -26,30 +26,9 @@ gdb_exit
26621 gdb_reinitialize_dir $srcdir/$subdir
26623 -gdb_test_multiple "python print 23" "verify python support" {
26624 - -re "not supported.*$gdb_prompt $" {
26625 - unsupported "python support is disabled"
26628 - -re "$gdb_prompt $" {}
26631 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
26632 -# Run a test named NAME, consisting of multiple lines of input.
26633 -# After each input line INPUT, search for result line RESULT.
26634 -# Succeed if all results are seen; fail otherwise.
26635 -proc gdb_py_test_multiple {name args} {
26636 - global gdb_prompt
26637 - foreach {input result} $args {
26638 - if {[gdb_test_multiple $input "$name - $input" {
26639 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
26640 - pass "$name - $input"
26647 +if ![python_supported] then {
26648 + unsupported "python support is disabled"
26652 gdb_py_test_multiple "multi-line python command" \
26653 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
26654 new file mode 100644
26655 index 0000000..4dc308b
26657 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
26659 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26661 + Copyright 2008, 2009 Free Software Foundation, Inc.
26663 + This file is part of GDB.
26665 + This program is free software; you can redistribute it and/or modify
26666 + it under the terms of the GNU General Public License as published by
26667 + the Free Software Foundation; either version 2 of the License, or
26668 + (at your option) any later version.
26670 + This program is distributed in the hope that it will be useful,
26671 + but WITHOUT ANY WARRANTY; without even the implied warranty of
26672 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26673 + GNU General Public License for more details.
26675 + You should have received a copy of the GNU General Public License
26676 + along with this program; if not, write to the Free Software
26677 + Foundation, Inc., 59 Temple Place - Suite 330,
26678 + Boston, MA 02111-1307, USA. */
26680 +#include <string.h>
26681 +#include <errno.h>
26686 + int i = usleep (1000000 / 100);
26687 + assert (i == 0 || errno == EINTR);
26690 +#if defined FOLLOW_PARENT
26695 + pid_t child, pid_got;
26696 + int exit_code = 42 + nr;
26705 + printf ("child%d: %d\n", nr, (int) getpid ());
26706 + /* Delay to get both the "child%d" and "parent%d" message printed without
26707 + a race breaking expect by its endless wait on `$gdb_prompt$':
26708 + Breakpoint 3, breakpoint () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
26710 + (gdb) parent2: 14223 */
26714 + /* We must not get caught here (against a forgotten breakpoint). */
26718 + _exit (exit_code);
26720 + printf ("parent%d: %d\n", nr, (int) child);
26721 + /* Delay to get both the "child%d" and "parent%d" message printed, see
26726 + pid_got = wait (&status);
26727 + assert (pid_got == child);
26728 + assert (WIFEXITED (status));
26729 + assert (WEXITSTATUS (status) == exit_code);
26731 + /* We must get caught here (against a false watchpoint removal). */
26736 +#elif defined FOLLOW_CHILD
26738 +static volatile int usr1_got;
26741 +handler_usr1 (int signo)
26751 + struct sigaction act, oldact;
26753 + void *thread_result;
26756 + memset (&act, 0, sizeof act);
26757 + act.sa_flags = SA_RESTART;
26758 + act.sa_handler = handler_usr1;
26759 + sigemptyset (&act.sa_mask);
26760 + i = sigaction (SIGUSR1, &act, &oldact);
26769 + printf ("parent%d: %d\n", nr, (int) child);
26771 + /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB
26772 + tracing the child fork with no longer valid thread/lwp entries of the
26778 + /* We must not get caught here (against a forgotten breakpoint). */
26784 + /* And neither got caught our thread. */
26787 + i = pthread_join (thread, &thread_result);
26789 + assert (thread_result == (void *) 99UL);
26792 + /* Be sure our child knows we did not get caught above. */
26794 + i = kill (child, SIGUSR1);
26797 + /* Sleep for a while to check GDB's `info threads' no longer tracks us in
26798 + the child fork. */
26805 + printf ("child%d: %d\n", nr, (int) getpid ());
26807 + /* Let the parent signal us about its success. Be careful of races. */
26809 + for (loop = 0; loop < 1000; loop++)
26811 + /* Parent either died (and USR1_GOT is zero) or it succeeded. */
26812 + if (kill (getppid (), 0) != 0)
26814 + /* Parent succeeded? */
26820 + assert (usr1_got);
26822 + /* We must get caught here (against a false watchpoint removal). */
26827 + i = sigaction (SIGUSR1, &oldact, NULL);
26832 +# error "!FOLLOW_PARENT && !FOLLOW_CHILD"
26834 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
26835 new file mode 100644
26836 index 0000000..edacfc0
26838 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
26840 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26842 + Copyright 2008, 2009 Free Software Foundation, Inc.
26844 + This file is part of GDB.
26846 + This program is free software; you can redistribute it and/or modify
26847 + it under the terms of the GNU General Public License as published by
26848 + the Free Software Foundation; either version 2 of the License, or
26849 + (at your option) any later version.
26851 + This program is distributed in the hope that it will be useful,
26852 + but WITHOUT ANY WARRANTY; without even the implied warranty of
26853 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26854 + GNU General Public License for more details.
26856 + You should have received a copy of the GNU General Public License
26857 + along with this program; if not, write to the Free Software
26858 + Foundation, Inc., 59 Temple Place - Suite 330,
26859 + Boston, MA 02111-1307, USA. */
26861 +#include <assert.h>
26862 +#include <unistd.h>
26863 +#include <sys/wait.h>
26864 +#include <stdio.h>
26865 +#include <stdlib.h>
26866 +#include <pthread.h>
26868 +#include <asm/unistd.h>
26869 +#include <unistd.h>
26870 +#define gettid() syscall (__NR_gettid)
26872 +/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
26873 + variable. Hit-comments need to be duplicite there to catch both at-stops
26874 + and behind-stops, depending on the target. */
26876 +static volatile int var;
26888 +/* Include here the functions:
26889 + static void forkoff (int nr);
26890 + static void delay (void); */
26892 +static pthread_t thread;
26893 +static volatile int step;
26896 +#include "watchpoint-fork-forkoff.c"
26904 + while (step != 1)
26907 + var++; /* validity-thread-B */
26908 + dummy (); /* validity-thread-B */
26910 + while (step != 3)
26921 + var++; /* after-fork1-B */
26922 + dummy (); /* after-fork1-B */
26924 + while (step != 5)
26932 + var++; /* after-fork2-B */
26933 + dummy (); /* after-fork2-B */
26934 + return (void *) 5UL;
26937 + /* We must not get caught here (against a forgotten breakpoint). */
26940 + return (void *) 99UL;
26947 + void *thread_result;
26949 + setbuf (stdout, NULL);
26950 + printf ("main: %d\n", (int) gettid ());
26952 + /* General watchpoints validity. */
26953 + var++; /* validity-first */
26954 + dummy (); /* validity-first */
26956 + i = pthread_create (&thread, NULL, start, NULL);
26959 + var++; /* validity-thread-A */
26960 + dummy (); /* validity-thread-A */
26962 + while (step != 2)
26965 + /* Hardware watchpoints got disarmed here. */
26968 + var++; /* after-fork1-A */
26969 + dummy (); /* after-fork1-A */
26971 +#ifdef FOLLOW_CHILD
26972 + /* Spawn new thread as it was deleted in the child of FORK. */
26973 + i = pthread_create (&thread, NULL, start, NULL);
26976 + while (step != 4)
26979 + /* A sanity check for double hardware watchpoints removal. */
26982 + var++; /* after-fork2-A */
26983 + dummy (); /* after-fork2-A */
26985 +#ifdef FOLLOW_CHILD
26986 + /* Spawn new thread as it was deleted in the child of FORK. */
26987 + i = pthread_create (&thread, NULL, start, NULL);
26991 + i = pthread_join (thread, &thread_result);
26993 + assert (thread_result == (void *) 5UL);
26997 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.c b/gdb/testsuite/gdb.threads/watchpoint-fork.c
26998 new file mode 100644
26999 index 0000000..5f62e7f
27001 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.c
27003 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
27005 + Copyright 2008, 2009 Free Software Foundation, Inc.
27007 + This file is part of GDB.
27009 + This program is free software; you can redistribute it and/or modify
27010 + it under the terms of the GNU General Public License as published by
27011 + the Free Software Foundation; either version 2 of the License, or
27012 + (at your option) any later version.
27014 + This program is distributed in the hope that it will be useful,
27015 + but WITHOUT ANY WARRANTY; without even the implied warranty of
27016 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27017 + GNU General Public License for more details.
27019 + You should have received a copy of the GNU General Public License
27020 + along with this program; if not, write to the Free Software
27021 + Foundation, Inc., 59 Temple Place - Suite 330,
27022 + Boston, MA 02111-1307, USA. */
27024 +#include <assert.h>
27025 +#include <unistd.h>
27026 +#include <sys/wait.h>
27027 +#include <stdio.h>
27028 +#include <stdlib.h>
27030 +static volatile int var;
27037 +/* Include here the function:
27038 + static void forkoff (int nr); */
27040 +#include "watchpoint-fork-forkoff.c"
27045 + setbuf (stdout, NULL);
27046 + printf ("main: %d\n", (int) getpid ());
27048 + /* General watchpoints validity. */
27050 + /* Hardware watchpoints got disarmed here. */
27052 + /* This watchpoint got lost before. */
27054 + /* A sanity check for double hardware watchpoints removal. */
27060 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
27061 new file mode 100644
27062 index 0000000..1dc93ab
27064 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
27066 +# Copyright 2008, 2009 Free Software Foundation, Inc.
27068 +# This program is free software; you can redistribute it and/or modify
27069 +# it under the terms of the GNU General Public License as published by
27070 +# the Free Software Foundation; either version 3 of the License, or
27071 +# (at your option) any later version.
27073 +# This program is distributed in the hope that it will be useful,
27074 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
27075 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27076 +# GNU General Public License for more details.
27078 +# You should have received a copy of the GNU General Public License
27079 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
27081 +# Test case for forgotten hw-watchpoints after fork()-off of a process.
27083 +proc test {type symbol} {
27084 + global objdir subdir srcdir
27086 + set test watchpoint-fork
27089 + set prefix_test $pf_prefix
27090 + lappend pf_prefix "$type:"
27091 + set prefix_mt $pf_prefix
27095 + set pf_prefix $prefix_mt
27096 + lappend pf_prefix "singlethreaded:"
27098 + set executable ${test}-${type}
27099 + if { [gdb_compile ${srcdir}/${subdir}/${test}.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
27100 + untested ${test}.exp
27103 + clean_restart $executable
27105 + gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on."
27106 + gdb_test "set follow-fork-mode $type"
27107 + gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"."
27108 + # Testcase uses it for the `follow-fork-mode child' type.
27109 + gdb_test "handle SIGUSR1 nostop noprint pass"
27111 + if { ![runto_main] } then {
27112 + gdb_suppress_tests
27116 + # Install the watchpoint only after getting into MAIN - workaround some PPC
27118 + gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
27120 + # It is never hit but it should not be left over in the fork()ed-off child.
27121 + gdb_breakpoint "breakpoint"
27123 + gdb_test "continue" \
27124 + "atchpoint 2: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
27125 + gdb_test "continue" \
27126 + "reakpoint 3, breakpoint.*" "breakpoint after the first fork"
27127 + gdb_test "continue" \
27128 + "atchpoint 2: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
27129 + gdb_test "continue" \
27130 + "reakpoint 3, breakpoint.*" "breakpoint after the second fork"
27131 + gdb_test "continue" \
27132 + "atchpoint 2: var.*Old value = 2.*New value = 3.*return *0;" "watchpoint after the second fork"
27133 + gdb_test "continue" "Continuing..*Program exited normally." "finish"
27138 + set pf_prefix $prefix_mt
27139 + lappend pf_prefix "multithreaded:"
27141 + set executable ${test}-mt-${type}
27142 + if { [gdb_compile_pthreads ${srcdir}/${subdir}/${test}-mt.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
27143 + untested ${test}.exp
27146 + clean_restart $executable
27148 + gdb_test "set follow-fork-mode $type"
27149 + # Testcase uses it for the `follow-fork-mode child' type.
27150 + gdb_test "handle SIGUSR1 nostop noprint pass"
27152 + if { ![runto_main] } then {
27153 + gdb_suppress_tests
27157 + # Install the watchpoint only after getting into MAIN - workaround some PPC
27159 + gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
27161 + # It is never hit but it should not be left over in the fork()ed-off child.
27162 + gdb_breakpoint "breakpoint"
27164 + gdb_test "continue" \
27165 + "atchpoint 2: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
27166 + gdb_test "continue" \
27167 + "atchpoint 2: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
27168 + gdb_test "continue" \
27169 + "atchpoint 2: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
27170 + gdb_test "continue" \
27171 + "reakpoint 3, breakpoint.*" "breakpoint (A) after the first fork"
27172 + gdb_test "continue" \
27173 + "atchpoint 2: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
27174 + gdb_test "continue" \
27175 + "atchpoint 2: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
27176 + gdb_test "continue" \
27177 + "reakpoint 3, breakpoint.*" "breakpoint (A) after the second fork"
27178 + gdb_test "continue" \
27179 + "atchpoint 2: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
27180 + gdb_test "continue" \
27181 + "atchpoint 2: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
27182 + gdb_test "continue" "Continuing..*Program exited normally." "finish"
27187 + set pf_prefix $prefix_test
27190 +test parent FOLLOW_PARENT
27192 +# Only GNU/Linux is known to support `set follow-fork-mode child'.
27193 +if {[istarget "*-*-linux*"]} {
27194 + test child FOLLOW_CHILD
27196 diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.c b/gdb/testsuite/gdb.threads/watchthreads-reorder.c
27197 new file mode 100644
27198 index 0000000..14f42d6
27200 +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.c
27202 +/* This testcase is part of GDB, the GNU debugger.
27204 + Copyright 2009 Free Software Foundation, Inc.
27206 + This program is free software; you can redistribute it and/or modify
27207 + it under the terms of the GNU General Public License as published by
27208 + the Free Software Foundation; either version 3 of the License, or
27209 + (at your option) any later version.
27211 + This program is distributed in the hope that it will be useful,
27212 + but WITHOUT ANY WARRANTY; without even the implied warranty of
27213 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27214 + GNU General Public License for more details.
27216 + You should have received a copy of the GNU General Public License
27217 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
27219 +#define _GNU_SOURCE
27220 +#include <pthread.h>
27221 +#include <stdio.h>
27222 +#include <limits.h>
27223 +#include <errno.h>
27224 +#include <stdlib.h>
27225 +#include <string.h>
27226 +#include <assert.h>
27227 +#include <sys/types.h>
27228 +#include <signal.h>
27229 +#include <unistd.h>
27230 +#include <asm/unistd.h>
27232 +#define gettid() syscall (__NR_gettid)
27234 +/* Terminate always in the main task, it can lock up with SIGSTOPped GDB
27236 +#define TIMEOUT (gettid () == getpid() ? 10 : 15)
27238 +static pthread_mutex_t gdbstop_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
27240 +static pid_t thread1_tid;
27241 +static pthread_cond_t thread1_tid_cond = PTHREAD_COND_INITIALIZER;
27242 +static pthread_mutex_t thread1_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
27244 +static pid_t thread2_tid;
27245 +static pthread_cond_t thread2_tid_cond = PTHREAD_COND_INITIALIZER;
27246 +static pthread_mutex_t thread2_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
27248 +static pthread_mutex_t terminate_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
27250 +static volatile int thread1_rwatch;
27251 +static volatile int thread2_rwatch;
27253 +static int unused1_rwatch;
27254 +static int unused2_rwatch;
27256 +/* Do not use alarm as it would create a ptrace event which would hang up us if
27257 + * we are being traced by GDB which we stopped ourselves. */
27259 +static void timed_mutex_lock (pthread_mutex_t *mutex)
27262 + struct timespec start, now;
27264 + i = clock_gettime (CLOCK_MONOTONIC, &start);
27269 + i = pthread_mutex_trylock (mutex);
27272 + assert (i == EBUSY);
27274 + i = clock_gettime (CLOCK_MONOTONIC, &now);
27276 + assert (now.tv_sec >= start.tv_sec);
27278 + while (now.tv_sec - start.tv_sec < TIMEOUT);
27280 + fprintf (stderr, "Timed out waiting for internal lock!\n");
27281 + exit (EXIT_FAILURE);
27285 +thread1_func (void *unused)
27288 + volatile int rwatch_store;
27290 + thread1_tid = gettid ();
27291 + i = pthread_cond_signal (&thread1_tid_cond);
27294 + /* Be sure GDB is already stopped before continuing. */
27295 + timed_mutex_lock (&gdbstop_mutex);
27296 + i = pthread_mutex_unlock (&gdbstop_mutex);
27299 + rwatch_store = thread1_rwatch;
27301 + /* Be sure the "T (tracing stop)" test can proceed for both threads. */
27302 + timed_mutex_lock (&terminate_mutex);
27303 + i = pthread_mutex_unlock (&terminate_mutex);
27310 +thread2_func (void *unused)
27313 + volatile int rwatch_store;
27315 + thread2_tid = gettid ();
27316 + i = pthread_cond_signal (&thread2_tid_cond);
27319 + /* Be sure GDB is already stopped before continuing. */
27320 + timed_mutex_lock (&gdbstop_mutex);
27321 + i = pthread_mutex_unlock (&gdbstop_mutex);
27324 + rwatch_store = thread2_rwatch;
27326 + /* Be sure the "T (tracing stop)" test can proceed for both threads. */
27327 + timed_mutex_lock (&terminate_mutex);
27328 + i = pthread_mutex_unlock (&terminate_mutex);
27334 +static const char *
27335 +proc_string (const char *filename, const char *line)
27338 + static char buf[LINE_MAX];
27339 + size_t line_len = strlen (line);
27341 + f = fopen (filename, "r");
27344 + fprintf (stderr, "fopen (\"%s\") for \"%s\": %s\n", filename, line,
27345 + strerror (errno));
27346 + exit (EXIT_FAILURE);
27348 + while (errno = 0, fgets (buf, sizeof (buf), f))
27352 + s = strchr (buf, '\n');
27353 + assert (s != NULL);
27356 + if (strncmp (buf, line, line_len) != 0)
27361 + fprintf (stderr, "fclose (\"%s\") for \"%s\": %s\n", filename, line,
27362 + strerror (errno));
27363 + exit (EXIT_FAILURE);
27366 + return &buf[line_len];
27370 + fprintf (stderr, "fgets (\"%s\": %s\n", filename, strerror (errno));
27371 + exit (EXIT_FAILURE);
27373 + fprintf (stderr, "\"%s\": No line \"%s\" found.\n", filename, line);
27374 + exit (EXIT_FAILURE);
27377 +static unsigned long
27378 +proc_ulong (const char *filename, const char *line)
27380 + const char *s = proc_string (filename, line);
27385 + retval = strtol (s, &end, 10);
27386 + if (retval < 0 || retval >= LONG_MAX || (end && *end))
27388 + fprintf (stderr, "\"%s\":\"%s\": %ld, %s\n", filename, line, retval,
27389 + strerror (errno));
27390 + exit (EXIT_FAILURE);
27396 +state_wait (pid_t process, const char *wanted)
27400 + struct timespec start, now;
27401 + const char *state;
27403 + i = asprintf (&filename, "/proc/%lu/status", (unsigned long) process);
27406 + i = clock_gettime (CLOCK_MONOTONIC, &start);
27411 + state = proc_string (filename, "State:\t");
27412 + if (strcmp (state, wanted) == 0)
27418 + if (sched_yield ())
27420 + perror ("sched_yield()");
27421 + exit (EXIT_FAILURE);
27424 + i = clock_gettime (CLOCK_MONOTONIC, &now);
27426 + assert (now.tv_sec >= start.tv_sec);
27428 + while (now.tv_sec - start.tv_sec < TIMEOUT);
27430 + fprintf (stderr, "Timed out waiting for PID %lu \"%s\" (now it is \"%s\")!\n",
27431 + (unsigned long) process, wanted, state);
27432 + exit (EXIT_FAILURE);
27435 +static volatile pid_t tracer = 0;
27436 +static pthread_t thread1, thread2;
27441 + printf ("Resuming GDB PID %lu.\n", (unsigned long) tracer);
27446 + int tracer_save = tracer;
27450 + i = kill (tracer_save, SIGCONT);
27456 +main (int argc, char **argv)
27459 + int standalone = 0;
27461 + if (argc == 2 && strcmp (argv[1], "-s") == 0)
27464 + assert (argc == 1);
27466 + setbuf (stdout, NULL);
27468 + timed_mutex_lock (&gdbstop_mutex);
27470 + timed_mutex_lock (&terminate_mutex);
27472 + i = pthread_create (&thread1, NULL, thread1_func, NULL);
27475 + i = pthread_create (&thread2, NULL, thread2_func, NULL);
27480 + tracer = proc_ulong ("/proc/self/status", "TracerPid:\t");
27483 + fprintf (stderr, "The testcase must be run by GDB!\n");
27484 + exit (EXIT_FAILURE);
27486 + if (tracer != getppid ())
27488 + fprintf (stderr, "The testcase parent must be our GDB tracer!\n");
27489 + exit (EXIT_FAILURE);
27493 + /* SIGCONT our debugger in the case of our crash as we would deadlock
27496 + atexit (cleanup);
27498 + printf ("Stopping GDB PID %lu.\n", (unsigned long) tracer);
27502 + i = kill (tracer, SIGSTOP);
27504 + state_wait (tracer, "T (stopped)");
27507 + timed_mutex_lock (&thread1_tid_mutex);
27508 + timed_mutex_lock (&thread2_tid_mutex);
27510 + /* Let the threads start. */
27511 + i = pthread_mutex_unlock (&gdbstop_mutex);
27514 + printf ("Waiting till the threads initialize their TIDs.\n");
27516 + if (thread1_tid == 0)
27518 + i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex);
27521 + assert (thread1_tid > 0);
27524 + if (thread2_tid == 0)
27526 + i = pthread_cond_wait (&thread2_tid_cond, &thread2_tid_mutex);
27529 + assert (thread2_tid > 0);
27532 + printf ("Thread 1 TID = %lu, thread 2 TID = %lu, PID = %lu.\n",
27533 + (unsigned long) thread1_tid, (unsigned long) thread2_tid,
27534 + (unsigned long) getpid ());
27536 + printf ("Waiting till the threads get trapped by the watchpoints.\n");
27540 + /* s390x-unknown-linux-gnu will fail with "R (running)". */
27542 + state_wait (thread1_tid, "T (tracing stop)");
27544 + state_wait (thread2_tid, "T (tracing stop)");
27549 + printf ("Joining the threads.\n");
27551 + i = pthread_mutex_unlock (&terminate_mutex);
27554 + i = pthread_join (thread1, NULL);
27557 + i = pthread_join (thread2, NULL);
27560 + printf ("Exiting.\n"); /* break-at-exit */
27562 + /* Just prevent compiler `warning:
\e$B!F
\e(BunusedX_rwatch
\e$B!G
\e(B defined but not used'. */
27563 + unused1_rwatch = 1;
27564 + unused2_rwatch = 2;
27566 + return EXIT_SUCCESS;
27568 diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.exp b/gdb/testsuite/gdb.threads/watchthreads-reorder.exp
27569 new file mode 100644
27570 index 0000000..5ad1a4e
27572 +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.exp
27574 +# This testcase is part of GDB, the GNU debugger.
27576 +# Copyright 2009 Free Software Foundation, Inc.
27578 +# This program is free software; you can redistribute it and/or modify
27579 +# it under the terms of the GNU General Public License as published by
27580 +# the Free Software Foundation; either version 3 of the License, or
27581 +# (at your option) any later version.
27583 +# This program is distributed in the hope that it will be useful,
27584 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
27585 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27586 +# GNU General Public License for more details.
27588 +# You should have received a copy of the GNU General Public License
27589 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
27591 +# Test GDB can cope with two watchpoints being hit by different threads at the
27592 +# same time, GDB reports one of them and after "continue" to report the other
27593 +# one GDB should not be confused by differently set watchpoints that time.
27594 +# This is the goal of "reorder1". "reorder0" tests the basic functionality of
27595 +# two watchpoint being hit at the same time, without reordering them during the
27596 +# stop. The formerly broken functionality is due to the all-stop mode default
27597 +# "show breakpoint always-inserted" being "off". Formerly the remembered hit
27598 +# could be assigned during continuation of a thread with pending SIGTRAP to the
27599 +# different/new watchpoint, just based on the watchpoint/debug register number.
27601 +if {[target_info exists gdb,no_hardware_watchpoints]
27602 + || ![istarget *-*-linux*]} {
27606 +set testfile "watchthreads-reorder"
27607 +set srcfile ${testfile}.c
27608 +set binfile ${objdir}/${subdir}/${testfile}
27609 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" ${binfile} executable [list debug additional_flags=-lrt]] != "" } {
27613 +foreach reorder {0 1} {
27616 + set prefix_test $pf_prefix
27617 + lappend pf_prefix "reorder$reorder:"
27619 + clean_restart $testfile
27621 + gdb_test "set can-use-hw-watchpoints 1"
27623 + if ![runto_main] {
27624 + gdb_suppress_tests
27627 + # Use "rwatch" as "watch" would report the watchpoint changed just based on its
27628 + # read memory value during a stop by unrelated event. We are interested to not
27629 + # to lose the hardware watchpoint trigger.
27631 + gdb_test "rwatch thread1_rwatch" "Hardware read watchpoint \[0-9\]+: thread1_rwatch"
27632 + gdb_test {set $rwatch1=$bpnum}
27633 + set test "rwatch thread2_rwatch"
27634 + gdb_test_multiple $test $test {
27635 + -re "Target does not support this type of hardware watchpoint\\.\r\n$gdb_prompt $" {
27636 + # ppc64 supports at most 1 hw watchpoints.
27637 + unsupported $test
27640 + -re "Hardware read watchpoint \[0-9\]+: thread2_rwatch\r\n$gdb_prompt $" {
27644 + gdb_test {set $rwatch2=$bpnum}
27645 + gdb_breakpoint [gdb_get_line_number "break-at-exit"]
27647 + # The watchpoints can happen in arbitrary order depending on random:
27648 + # SEL: Found 2 SIGTRAP events, selecting #[01]
27649 + # As GDB contains no srand() on the specific host/OS it will behave always the
27650 + # same. Such order cannot be guaranteed for GDB in general.
27652 + gdb_test "continue" \
27653 + "Hardware read watchpoint \[0-9\]+: thread\[12\]_rwatch\r\n\r\nValue = 0\r\n0x\[0-9a-f\]+ in thread\[12\]_func .*" \
27657 + gdb_test {delete $rwatch1}
27658 + gdb_test {delete $rwatch2}
27660 + gdb_test "rwatch unused1_rwatch" "Hardware read watchpoint \[0-9\]+: unused1_rwatch"
27661 + gdb_test "rwatch unused2_rwatch" "Hardware read watchpoint \[0-9\]+: unused2_rwatch"
27663 + gdb_test "rwatch thread1_rwatch" "Hardware read watchpoint \[0-9\]+: thread1_rwatch"
27664 + gdb_test "rwatch thread2_rwatch" "Hardware read watchpoint \[0-9\]+: thread2_rwatch"
27667 + gdb_test "continue" \
27668 + "Hardware read watchpoint \[0-9\]+: thread\[12\]_rwatch\r\n\r\nValue = 0\r\n0x\[0-9a-f\]+ in thread\[12\]_func .*" \
27671 + # While the debug output itself is not checked in this testcase one bug was
27672 + # found in the DEBUG_INFRUN code path.
27673 + gdb_test "set debug infrun 1"
27675 + gdb_continue_to_breakpoint "break-at-exit" ".*break-at-exit.*"
27677 + set pf_prefix $prefix_test
27679 diff --git a/gdb/testsuite/lib/cp-support.exp b/gdb/testsuite/lib/cp-support.exp
27680 index dbd2f59..44e1b51 100644
27681 --- a/gdb/testsuite/lib/cp-support.exp
27682 +++ b/gdb/testsuite/lib/cp-support.exp
27683 @@ -222,7 +222,7 @@ proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table {
27686 gdb_test_multiple "$in_command" "$in_testname // parse failed" {
27687 - -re "type = (struct|class)${wsopt}(\[A-Za-z0-9_\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" {
27688 + -re "type = (struct|class)${wsopt}(\[A-Za-z0-9_:\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" {
27690 set actual_key $expect_out(1,string)
27691 set actual_tag $expect_out(2,string)
27692 @@ -231,6 +231,7 @@ proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table {
27693 set actual_tail $expect_out(6,string)
27697 if { ! $parse_okay } then { return }
27699 # Check the actual key. It would be nice to require that it match
27700 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
27701 index 0c93a73..d0c3493 100644
27702 --- a/gdb/testsuite/lib/gdb.exp
27703 +++ b/gdb/testsuite/lib/gdb.exp
27704 @@ -27,6 +27,7 @@ if {$tool == ""} {
27707 load_lib libgloss.exp
27708 +load_lib python-support.exp
27712 diff --git a/gdb/testsuite/lib/python-support.exp b/gdb/testsuite/lib/python-support.exp
27713 new file mode 100644
27714 index 0000000..b8e9836
27716 +++ b/gdb/testsuite/lib/python-support.exp
27718 +global python_supported_saved
27720 +# Return 1 if Python scripting is supported in GDB, 0 if not.
27721 +proc python_supported { } {
27722 + global gdb_prompt
27723 + global python_supported_saved
27725 + if [info exists python_supported_saved] {
27726 + verbose "python_supported: returning saved $python_supported_saved" 2
27727 + return $python_supported_saved
27730 + gdb_test_multiple "python print 'hello, world!'" "verify python support" {
27731 + -re "not supported.*$gdb_prompt $" {
27732 + return [set python_supported_saved 0]
27734 + -re "$gdb_prompt $" {
27735 + return [set python_supported_saved 1]
27739 + return [set python_supported_saved 0]
27742 +# Run a command in GDB, and report a failure if a Python exception is thrown.
27743 +# If report_pass is true, report a pass if no exception is thrown.
27744 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
27745 + global gdb_prompt
27747 + gdb_test_multiple $cmd $name {
27748 + -re "Traceback.*$gdb_prompt $" { fail $name }
27749 + -re "$gdb_prompt $" { if $report_pass { pass $name } }
27753 +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
27754 +# Run a test named NAME, consisting of multiple lines of input.
27755 +# After each input line INPUT, search for result line RESULT.
27756 +# Succeed if all results are seen; fail otherwise.
27757 +proc gdb_py_test_multiple {name args} {
27758 + global gdb_prompt
27760 + foreach {input result} $args {
27761 + if {[gdb_test_multiple $input "$name - $input" {
27762 + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
27763 + pass "$name - $input"
27771 diff --git a/gdb/thread.c b/gdb/thread.c
27772 index 55b4b96..e0ad2d3 100644
27775 @@ -61,7 +61,6 @@ static int thread_alive (struct thread_info *);
27776 static void info_threads_command (char *, int);
27777 static void thread_apply_command (char *, int);
27778 static void restore_current_thread (ptid_t);
27779 -static void prune_threads (void);
27781 /* Frontend view of the thread state. Possible extensions: stepping,
27782 finishing, until(ling),... */
27783 @@ -497,16 +496,23 @@ thread_alive (struct thread_info *tp)
27789 prune_threads (void)
27791 - struct thread_info *tp, *next;
27792 + struct thread_info *tp;
27793 + struct thread_info **prevp = &thread_list;
27795 - for (tp = thread_list; tp; tp = next)
27796 + for (tp = *prevp; tp; tp = *prevp)
27799 + /* If the thread has died, free it and unlink it from the list.
27800 + Otherwise, advance to the next thread. */
27801 if (!thread_alive (tp))
27802 - delete_thread (tp->ptid);
27804 + *prevp = tp->next;
27805 + free_thread (tp);
27808 + prevp = &tp->next;
27812 diff --git a/gdb/top.c b/gdb/top.c
27813 index 1b4aa9d..3cfe57e 100644
27816 @@ -349,6 +349,7 @@ void
27817 prepare_execute_command (void)
27819 free_all_values ();
27820 + free_all_types ();
27822 /* With multiple threads running while the one we're examining is stopped,
27823 the dcache can get stale without us being able to detect it.
27824 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
27825 index f090231..fc15ec1 100644
27826 --- a/gdb/typeprint.c
27827 +++ b/gdb/typeprint.c
27829 #include "gdb_string.h"
27830 #include "exceptions.h"
27831 #include "valprint.h"
27832 +#include "dwarf2loc.h"
27836 extern void _initialize_typeprint (void);
27837 @@ -76,6 +78,9 @@ void
27838 type_print (struct type *type, char *varstring, struct ui_file *stream,
27842 + type = check_typedef (type);
27844 LA_PRINT_TYPE (type, varstring, stream, show, 0);
27847 @@ -114,7 +119,8 @@ whatis_exp (char *exp, int show)
27849 struct expression *expr;
27851 - struct cleanup *old_chain = NULL;
27852 + /* Required at least for the object_address_set call. */
27853 + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
27854 struct type *real_type = NULL;
27857 @@ -125,12 +131,13 @@ whatis_exp (char *exp, int show)
27860 expr = parse_expression (exp);
27861 - old_chain = make_cleanup (free_current_contents, &expr);
27862 + make_cleanup (free_current_contents, &expr);
27863 val = evaluate_type (expr);
27866 val = access_value_history (0);
27868 + object_address_set (value_raw_address (val));
27869 type = value_type (val);
27871 get_user_print_options (&opts);
27872 @@ -167,8 +174,7 @@ whatis_exp (char *exp, int show)
27873 type_print (type, "", gdb_stdout, show);
27874 printf_filtered ("\n");
27877 - do_cleanups (old_chain);
27878 + do_cleanups (old_chain);
27882 diff --git a/gdb/typeprint.h b/gdb/typeprint.h
27883 index f561310..d261c79 100644
27884 --- a/gdb/typeprint.h
27885 +++ b/gdb/typeprint.h
27886 @@ -20,10 +20,13 @@
27887 #ifndef TYPEPRINT_H
27888 #define TYPEPRINT_H
27893 void print_type_scalar (struct type * type, LONGEST, struct ui_file *);
27895 void c_type_print_varspec_suffix (struct type *, struct ui_file *, int,
27898 +void c_type_print_args (struct type *, struct ui_file *, int, enum language);
27900 diff --git a/gdb/ui-file.c b/gdb/ui-file.c
27901 index 527917c..07d959a 100644
27902 --- a/gdb/ui-file.c
27903 +++ b/gdb/ui-file.c
27907 #include "ui-file.h"
27908 +#include "gdb_obstack.h"
27909 #include "gdb_string.h"
27912 @@ -263,7 +264,7 @@ set_ui_file_data (struct ui_file *file, void *data,
27915 /* ui_file utility function for converting a ``struct ui_file'' into
27916 - a memory buffer''. */
27917 + a memory buffer. */
27919 struct accumulated_ui_file
27921 @@ -297,6 +298,23 @@ ui_file_xstrdup (struct ui_file *file, long *length)
27922 *length = acc.length;
27927 +do_ui_file_obsavestring (void *context, const char *buffer, long length)
27929 + struct obstack *obstack = (struct obstack *) context;
27930 + obstack_grow (obstack, buffer, length);
27934 +ui_file_obsavestring (struct ui_file *file, struct obstack *obstack,
27937 + ui_file_put (file, do_ui_file_obsavestring, obstack);
27938 + *length = obstack_object_size (obstack);
27939 + obstack_1grow (obstack, '\0');
27940 + return obstack_finish (obstack);
27943 /* A pure memory based ``struct ui_file'' that can be used an output
27944 buffer. The buffers accumulated contents are available via
27945 diff --git a/gdb/ui-file.h b/gdb/ui-file.h
27946 index bf9915c..233206c 100644
27947 --- a/gdb/ui-file.h
27948 +++ b/gdb/ui-file.h
27956 /* Create a generic ui_file object with null methods. */
27957 @@ -77,7 +78,10 @@ extern void ui_file_put (struct ui_file *src, ui_file_put_method_ftype *write, v
27958 minus that appended NUL. */
27959 extern char *ui_file_xstrdup (struct ui_file *file, long *length);
27962 +/* Similar to ui_file_xstrdup, but return a new string allocated on
27964 +extern char *ui_file_obsavestring (struct ui_file *file,
27965 + struct obstack *obstack, long *length);
27967 extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
27969 diff --git a/gdb/utils.c b/gdb/utils.c
27970 index 16ad084..3021a43 100644
27973 @@ -2610,7 +2610,10 @@ fprintf_symbol_filtered (struct ui_file *stream, char *name,
27974 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
27975 This "feature" is useful when searching for matching C++ function names
27976 (such as if the user types 'break FOO', where FOO is a mangled C++
27980 + As an extra-special hack, we do the same with ' ', so that
27981 + "FOO(ARGS) const" can match "FOO", too. */
27984 strcmp_iw (const char *string1, const char *string2)
27985 @@ -2635,7 +2638,7 @@ strcmp_iw (const char *string1, const char *string2)
27989 - return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
27990 + return (*string1 != ' ' && *string1 != '\0' && *string1 != '(') || (*string2 != '\0' && *string2 != '(');
27993 /* This is like strcmp except that it ignores whitespace and treats
27994 diff --git a/gdb/valarith.c b/gdb/valarith.c
27995 index a9c875d..12f6f07 100644
27996 --- a/gdb/valarith.c
27997 +++ b/gdb/valarith.c
27998 @@ -139,7 +139,6 @@ an integer nor a pointer of the same type."));
28000 value_subscript (struct value *array, LONGEST index)
28002 - struct value *bound;
28003 int c_style = current_language->c_style_arrays;
28004 struct type *tarray;
28006 @@ -154,12 +153,26 @@ value_subscript (struct value *array, LONGEST index)
28007 get_discrete_bounds (range_type, &lowerbound, &upperbound);
28009 if (VALUE_LVAL (array) != lval_memory)
28010 - return value_subscripted_rvalue (array, index, lowerbound);
28012 + if (index >= lowerbound && index <= upperbound)
28014 + CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
28015 + CORE_ADDR offset = (index - lowerbound) * element_size;
28017 + return value_subscripted_rvalue (array, offset);
28019 + error (_("array or string index out of range"));
28024 if (index >= lowerbound && index <= upperbound)
28025 - return value_subscripted_rvalue (array, index, lowerbound);
28027 + CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
28028 + CORE_ADDR offset = (index - lowerbound) * element_size;
28030 + return value_subscripted_rvalue (array, offset);
28032 /* Emit warning unless we have an array of unknown size.
28033 An array of unknown size has lowerbound 0 and upperbound -1. */
28034 if (upperbound > -1)
28035 @@ -178,33 +191,37 @@ value_subscript (struct value *array, LONGEST index)
28036 error (_("not an array or string"));
28039 -/* Return the value of EXPR[IDX], expr an aggregate rvalue
28040 - (eg, a vector register). This routine used to promote floats
28041 - to doubles, but no longer does. */
28042 +/* Return the value of *((void *) ARRAY + ELEMENT), ARRAY an aggregate rvalue
28043 + (eg, a vector register). This routine used to promote floats to doubles,
28044 + but no longer does. OFFSET is zero-based with 0 for the lowermost existing
28045 + element, it must be expressed in bytes (therefore multiplied by
28046 + check_typedef (TYPE_TARGET_TYPE (array_type)). */
28049 -value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
28050 +value_subscripted_rvalue (struct value *array, CORE_ADDR offset)
28052 struct type *array_type = check_typedef (value_type (array));
28053 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
28054 - unsigned int elt_size = TYPE_LENGTH (elt_type);
28055 - unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
28058 - if (index < lowerbound || elt_offs >= TYPE_LENGTH (array_type))
28059 - error (_("no such vector element"));
28060 + /* Do not check TYPE_LENGTH (array_type) as we may have been given the
28061 + innermost dimension of a multi-dimensional Fortran array where its length
28062 + is shorter than the possibly accessed element offset. */
28064 v = allocate_value (elt_type);
28065 if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
28066 set_value_lazy (v, 1);
28068 - memcpy (value_contents_writeable (v),
28069 - value_contents (array) + elt_offs, elt_size);
28071 + unsigned int elt_size = TYPE_LENGTH (elt_type);
28072 + memcpy (value_contents_writeable (v),
28073 + value_contents (array) + offset, elt_size);
28076 set_value_component_location (v, array);
28077 VALUE_REGNUM (v) = VALUE_REGNUM (array);
28078 VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
28079 - set_value_offset (v, value_offset (array) + elt_offs);
28080 + set_value_offset (v, value_offset (array) + offset);
28084 diff --git a/gdb/valops.c b/gdb/valops.c
28085 index 012ea6a..9b4d2a8 100644
28089 #include "cp-support.h"
28091 #include "user-regs.h"
28092 +#include "dwarf2loc.h"
28095 #include "gdb_string.h"
28096 @@ -369,8 +370,6 @@ value_cast (struct type *type, struct value *arg2)
28097 new_length = val_length / element_length;
28098 if (val_length % element_length != 0)
28099 warning (_("array element type size does not divide object size in cast"));
28100 - /* FIXME-type-allocation: need a way to free this type when
28101 - we are done with it. */
28102 range_type = create_range_type ((struct type *) NULL,
28103 TYPE_TARGET_TYPE (range_type),
28105 @@ -565,6 +564,64 @@ value_one (struct type *type, enum lval_type lv)
28109 +/* object_address_set must be already called before this function. */
28112 +object_address_data_not_valid (struct type *type)
28114 + /* Attributes are present only at the target type of a typedef. Make the
28115 + call conditional as it would otherwise loop through type_length_get. */
28116 + if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
28117 + CHECK_TYPEDEF (type);
28119 + /* DW_AT_associated has a preference over DW_AT_allocated. */
28120 + if (TYPE_NOT_ASSOCIATED (type)
28121 + || (TYPE_ASSOCIATED (type) != NULL
28122 + && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
28123 + return N_("object is not associated");
28125 + if (TYPE_NOT_ALLOCATED (type)
28126 + || (TYPE_ALLOCATED (type) != NULL
28127 + && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
28128 + return N_("object is not allocated");
28133 +/* Return non-zero if the variable is valid. If it is valid the function
28134 + may store the data address (DW_AT_DATA_LOCATION) of TYPE at *ADDRESS_RETURN.
28135 + You must set *ADDRESS_RETURN from value_raw_address (VAL) before calling this
28136 + function. If no DW_AT_DATA_LOCATION is present for TYPE the address at
28137 + *ADDRESS_RETURN is left unchanged. ADDRESS_RETURN must not be NULL, use
28138 + object_address_data_not_valid () for just the data validity check. */
28141 +object_address_get_data (struct type *type, CORE_ADDR *address_return)
28143 + gdb_assert (address_return != NULL);
28145 + object_address_set (*address_return);
28147 + /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
28148 + at the target type of a typedef. */
28149 + CHECK_TYPEDEF (type);
28151 + if (object_address_data_not_valid (type) != NULL)
28153 + /* Do not try to evaluate DW_AT_data_location as it may even crash
28154 + (it would just return the value zero in the gfortran case). */
28158 + if (TYPE_DATA_LOCATION_IS_ADDR (type))
28159 + *address_return = TYPE_DATA_LOCATION_ADDR (type);
28160 + else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
28162 + = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
28167 /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */
28169 static struct value *
28170 @@ -656,15 +713,21 @@ value_fetch_lazy (struct value *val)
28172 else if (VALUE_LVAL (val) == lval_memory)
28174 - CORE_ADDR addr = value_address (val);
28175 - int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
28176 + CORE_ADDR addr = value_raw_address (val);
28179 + if (object_address_get_data (value_type (val), &addr))
28181 - if (value_stack (val))
28182 - read_stack (addr, value_contents_all_raw (val), length);
28184 - read_memory (addr, value_contents_all_raw (val), length);
28185 + struct type *type = value_enclosing_type (val);
28186 + int length = TYPE_LENGTH (check_typedef (type));
28190 + addr += value_offset (val);
28191 + if (value_stack (val))
28192 + read_stack (addr, value_contents_all_raw (val), length);
28194 + read_memory (addr, value_contents_all_raw (val), length);
28198 else if (VALUE_LVAL (val) == lval_register)
28199 @@ -1072,7 +1135,18 @@ address_of_variable (struct symbol *var, struct block *b)
28200 if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
28201 || TYPE_CODE (type) == TYPE_CODE_FUNC)
28203 - CORE_ADDR addr = value_address (val);
28206 + if (VALUE_LVAL (val) == lval_memory)
28208 + addr = value_raw_address (val);
28209 + if (!object_address_get_data (type, &addr))
28210 + error (_("Can't take address of memory lvalue \"%s\"."),
28211 + SYMBOL_PRINT_NAME (var));
28212 + set_value_address (val, addr);
28215 + addr = value_address (val);
28216 return value_from_pointer (lookup_pointer_type (type), addr);
28219 @@ -1178,6 +1252,7 @@ struct value *
28220 value_coerce_array (struct value *arg1)
28222 struct type *type = check_typedef (value_type (arg1));
28223 + CORE_ADDR address;
28225 /* If the user tries to do something requiring a pointer with an
28226 array that has not yet been pushed to the target, then this would
28227 @@ -1187,8 +1262,12 @@ value_coerce_array (struct value *arg1)
28228 if (VALUE_LVAL (arg1) != lval_memory)
28229 error (_("Attempt to take address of value not located in memory."));
28231 + address = value_raw_address (arg1);
28232 + if (!object_address_get_data (type, &address))
28233 + error (_("Attempt to take address of non-valid value."));
28235 return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
28236 - value_address (arg1));
28237 + address + value_offset (arg1));
28240 /* Given a value which is a function, return a value which is a pointer
28241 @@ -2071,12 +2150,25 @@ find_overload_match (struct type **arg_types, int nargs,
28246 + /* OBJ may be a pointer value rather than the object itself. */
28247 + obj = coerce_ref (obj);
28248 + while (TYPE_CODE (check_typedef (value_type (obj))) == TYPE_CODE_PTR)
28249 + obj = coerce_ref (value_ind (obj));
28250 obj_type_name = TYPE_NAME (value_type (obj));
28251 - /* Hack: evaluate_subexp_standard often passes in a pointer
28252 - value rather than the object itself, so try again. */
28253 - if ((!obj_type_name || !*obj_type_name)
28254 - && (TYPE_CODE (value_type (obj)) == TYPE_CODE_PTR))
28255 - obj_type_name = TYPE_NAME (TYPE_TARGET_TYPE (value_type (obj)));
28257 + /* First check whether this is a data member, e.g. a pointer to
28259 + if (TYPE_CODE (check_typedef (value_type (obj))) == TYPE_CODE_STRUCT)
28261 + *valp = search_struct_field (name, obj, 0,
28262 + check_typedef (value_type (obj)), 0);
28270 fns_ptr = value_find_oload_method_list (&temp, name,
28272 @@ -2096,16 +2188,29 @@ find_overload_match (struct type **arg_types, int nargs,
28276 - const char *qualified_name = SYMBOL_CPLUS_DEMANGLED_NAME (fsym);
28277 + const char *qualified_name = SYMBOL_NATURAL_NAME (fsym);
28279 + /* If we have a function with a C++ name, try to extract just
28280 + the function part. Do not try this for non-functions (e.g.
28281 + function pointers). */
28282 + if (qualified_name
28283 + && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym))) == TYPE_CODE_FUNC)
28285 + func_name = cp_func_name (qualified_name);
28287 - /* If we have a C++ name, try to extract just the function
28289 - if (qualified_name)
28290 - func_name = cp_func_name (qualified_name);
28291 + /* If cp_func_name did not remove anything, the name of the
28292 + symbol did not include scope or argument types - it was
28293 + probably a C-style function. */
28294 + if (func_name && strcmp (func_name, qualified_name) == 0)
28296 + xfree (func_name);
28297 + func_name = NULL;
28301 - /* If there was no C++ name, this must be a C-style function.
28302 - Just return the same symbol. Do the same if cp_func_name
28303 - fails for some reason. */
28304 + /* If there was no C++ name, this must be a C-style function or
28305 + not a function at all. Just return the same symbol. Do the
28306 + same if cp_func_name fails for some reason. */
28307 if (func_name == NULL)
28310 @@ -2536,8 +2641,8 @@ check_field (struct type *type, const char *name)
28311 the comment before value_struct_elt_for_reference. */
28314 -value_aggregate_elt (struct type *curtype,
28315 - char *name, int want_address,
28316 +value_aggregate_elt (struct type *curtype, char *name,
28317 + struct type *expect_type, int want_address,
28318 enum noside noside)
28320 switch (TYPE_CODE (curtype))
28321 @@ -2545,7 +2650,7 @@ value_aggregate_elt (struct type *curtype,
28322 case TYPE_CODE_STRUCT:
28323 case TYPE_CODE_UNION:
28324 return value_struct_elt_for_reference (curtype, 0, curtype,
28326 + name, expect_type,
28327 want_address, noside);
28328 case TYPE_CODE_NAMESPACE:
28329 return value_namespace_elt (curtype, name,
28330 @@ -2556,6 +2661,56 @@ value_aggregate_elt (struct type *curtype,
28334 +/* Compares the two method/function types T1 and T2 for "equality"
28335 + with respect to the the methods' parameters. If the types of the
28336 + two parameter lists are the same, returns 1; 0 otherwise. This
28337 + comparison may ignore any artificial parameters in T1 if
28338 + SKIP_ARTIFICIAL is non-zero. This function will ALWAYS skip
28339 + the first artificial parameter in T1, assumed to be a 'this' pointer.
28341 + The type T2 is expected to have come from make_params (in eval.c). */
28343 +compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
28347 + if (TYPE_FIELD_ARTIFICIAL (t1, 0))
28350 + /* If skipping artificial fields, find the first real field
28352 + if (skip_artificial)
28354 + while (start < TYPE_NFIELDS (t1)
28355 + && TYPE_FIELD_ARTIFICIAL (t1, start))
28359 + /* Now compare parameters */
28361 + /* Special case: a method taking void. T1 will contain no
28362 + non-artificial fields, and T2 will contain TYPE_CODE_VOID. */
28363 + if ((TYPE_NFIELDS (t1) - start) == 0 && TYPE_NFIELDS (t2) == 1
28364 + && TYPE_CODE (TYPE_FIELD_TYPE (t2, 0)) == TYPE_CODE_VOID)
28367 + if ((TYPE_NFIELDS (t1) - start) == TYPE_NFIELDS (t2))
28370 + for (i = 0; i < TYPE_NFIELDS (t2); ++i)
28372 + if (rank_one_type (TYPE_FIELD_TYPE (t1, start + i),
28373 + TYPE_FIELD_TYPE (t2, i))
28384 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
28385 return the address of this member as a "pointer to member" type.
28386 If INTYPE is non-null, then it will be the type of the member we
28387 @@ -2633,23 +2788,46 @@ value_struct_elt_for_reference (struct type *domain, int offset,
28389 if (t_field_name && strcmp (t_field_name, name) == 0)
28391 - int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
28393 + int len = TYPE_FN_FIELDLIST_LENGTH (t, i);
28394 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
28396 check_stub_method_group (t, i);
28398 - if (intype == 0 && j > 1)
28399 - error (_("non-unique member `%s' requires type instantiation"), name);
28403 - if (TYPE_FN_FIELD_TYPE (f, j) == intype)
28406 - error (_("no member function matches that type instantiation"));
28408 + for (j = 0; j < len; ++j)
28410 + if (compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 0)
28411 + || compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 1))
28416 + error (_("no member function matches that type instantiation")); }
28421 + /* Skip artificial methods. This is necessary if, for example,
28422 + the user wants to "print subclass::subclass" with only
28423 + one defined user constructor. There is no ambiguity in this
28425 + for (ii = 0; ii < TYPE_FN_FIELDLIST_LENGTH (t, i);
28428 + if (TYPE_FN_FIELD_ARTIFICIAL (f, ii))
28432 + /* Desired method is ambiguous if more than one method is
28435 + error (_("non-unique member `%s' requires type instantiation"), name);
28437 + /* This assumes, of course, that all artificial methods appear
28438 + BEFORE any concrete methods. */
28439 + j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1;
28442 if (TYPE_FN_FIELD_STATIC_P (f, j))
28444 @@ -2763,7 +2941,7 @@ value_maybe_namespace_elt (const struct type *curtype,
28445 struct symbol *sym;
28446 struct value *result;
28448 - sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
28449 + sym = cp_lookup_symbol_namespace(namespace_name, name,
28450 get_selected_block (0),
28453 @@ -2907,7 +3085,7 @@ value_of_local (const char *name, int complain)
28455 /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
28456 symbol instead of the LOC_ARG one (if both exist). */
28457 - sym = lookup_block_symbol (b, name, NULL, VAR_DOMAIN);
28458 + sym = lookup_block_symbol (b, name, VAR_DOMAIN);
28462 @@ -2961,8 +3139,6 @@ value_slice (struct value *array, int lowbound, int length)
28463 || lowbound + length - 1 > upperbound)
28464 error (_("slice out of range"));
28466 - /* FIXME-type-allocation: need a way to free this type when we are
28468 slice_range_type = create_range_type ((struct type *) NULL,
28469 TYPE_TARGET_TYPE (range_type),
28471 diff --git a/gdb/valprint.c b/gdb/valprint.c
28472 index cbb5d94..f9634ea 100644
28473 --- a/gdb/valprint.c
28474 +++ b/gdb/valprint.c
28475 @@ -236,7 +236,6 @@ scalar_type_p (struct type *type)
28476 case TYPE_CODE_STRUCT:
28477 case TYPE_CODE_UNION:
28478 case TYPE_CODE_SET:
28479 - case TYPE_CODE_STRING:
28480 case TYPE_CODE_BITSTRING:
28483 @@ -1153,6 +1152,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
28485 for (; i < len && things_printed < options->print_max; i++)
28487 + size_t elt_offset = i * eltlen;
28490 if (options->prettyprint_arrays)
28491 @@ -1172,7 +1172,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
28494 while ((rep1 < len) &&
28495 - !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen))
28496 + !memcmp (valaddr + elt_offset, valaddr + rep1 * eltlen, eltlen))
28500 diff --git a/gdb/value.c b/gdb/value.c
28501 index 589e03b..66013b7 100644
28507 #include "objfiles.h"
28508 +#include "cli/cli-decode.h"
28509 #include "valprint.h"
28510 #include "cli/cli-decode.h"
28511 +#include "observer.h"
28513 #include "python/python.h"
28515 @@ -170,6 +172,14 @@ struct value
28516 taken off this list. */
28517 struct value *next;
28519 + /* The reference count. A value that is still on the `all_values'
28520 + list will have a reference count of 0. A call to `release_value'
28521 + will increment the reference count (and remove the value from the
28522 + list, the first time). A call to `value_free' will decrement the
28523 + reference count, and will free the value when there are no more
28527 /* Register number if the value is from a register. */
28530 @@ -261,7 +271,9 @@ allocate_value_lazy (struct type *type)
28531 val->next = all_values;
28534 + type_incref (type);
28535 val->enclosing_type = type;
28536 + type_incref (type);
28537 VALUE_LVAL (val) = not_lval;
28538 val->location.address = 0;
28539 VALUE_FRAME_ID (val) = null_frame_id;
28540 @@ -346,6 +358,8 @@ value_type (struct value *value)
28542 deprecated_set_value_type (struct value *value, struct type *type)
28544 + type_incref (type);
28545 + type_decref (value->type);
28546 value->type = type;
28549 @@ -624,6 +638,9 @@ value_free (struct value *val)
28550 if (val->parent != NULL)
28551 value_free (val->parent);
28553 + type_decref (val->type);
28554 + type_decref (val->enclosing_type);
28556 if (VALUE_LVAL (val) == lval_computed)
28558 struct lval_funcs *funcs = val->location.computed.funcs;
28559 @@ -728,6 +745,9 @@ value_copy (struct value *arg)
28560 val = allocate_value_lazy (encl_type);
28562 val = allocate_value (encl_type);
28564 + type_incref (arg->type);
28565 + type_decref (val->type);
28566 val->type = arg->type;
28567 VALUE_LVAL (val) = VALUE_LVAL (arg);
28568 val->location = arg->location;
28569 @@ -763,12 +783,15 @@ value_copy (struct value *arg)
28571 set_value_component_location (struct value *component, struct value *whole)
28575 if (VALUE_LVAL (whole) == lval_internalvar)
28576 VALUE_LVAL (component) = lval_internalvar_component;
28578 VALUE_LVAL (component) = VALUE_LVAL (whole);
28580 component->location = whole->location;
28582 if (VALUE_LVAL (whole) == lval_computed)
28584 struct lval_funcs *funcs = whole->location.computed.funcs;
28585 @@ -776,6 +799,10 @@ set_value_component_location (struct value *component, struct value *whole)
28586 if (funcs->copy_closure)
28587 component->location.computed.closure = funcs->copy_closure (whole);
28590 + addr = value_raw_address (component);
28591 + object_address_get_data (value_type (whole), &addr);
28592 + set_value_address (component, addr);
28596 @@ -906,6 +933,29 @@ show_values (char *num_exp, int from_tty)
28601 +/* Sanity check for memory leaks and proper types reference counting. */
28604 +value_history_cleanup (void *unused)
28606 + while (value_history_chain)
28608 + struct value_history_chunk *chunk = value_history_chain;
28611 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
28612 + value_free (chunk->values[i]);
28614 + value_history_chain = chunk->next;
28617 + value_history_count = 0;
28619 + /* Free the unreferenced types above. */
28620 + free_all_values ();
28621 + free_all_types ();
28624 /* Internal variables. These are variables within the debugger
28625 that hold values assigned by debugger commands.
28626 @@ -1381,6 +1431,40 @@ call_internal_function (struct gdbarch *gdbarch,
28627 return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
28630 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
28633 +value_types_mark_used (void)
28635 + struct internalvar *var;
28636 + struct value_history_chunk *chunk;
28638 + for (var = internalvars; var != NULL; var = var->next)
28639 + switch (var->kind)
28641 + case INTERNALVAR_VALUE:
28642 + type_mark_used (value_type (var->u.value));
28645 + case INTERNALVAR_INTEGER:
28646 + type_mark_used (var->u.integer.type);
28649 + case INTERNALVAR_POINTER:
28650 + type_mark_used (var->u.pointer.type);
28654 + for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
28658 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
28659 + if (chunk->values[i])
28660 + type_mark_used (value_type (chunk->values[i]));
28664 /* The 'function' command. This does nothing -- it is just a
28665 placeholder to let "help function NAME" work. This is also used as
28666 the implementation of the sub-command that is created when
28667 @@ -1428,11 +1512,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
28668 htab_t copied_types)
28670 if (TYPE_OBJFILE (value->type) == objfile)
28671 - value->type = copy_type_recursive (objfile, value->type, copied_types);
28672 + value->type = copy_type_recursive (value->type, copied_types);
28674 if (TYPE_OBJFILE (value->enclosing_type) == objfile)
28675 - value->enclosing_type = copy_type_recursive (objfile,
28676 - value->enclosing_type,
28677 + value->enclosing_type = copy_type_recursive (value->enclosing_type,
28681 @@ -1447,13 +1530,13 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
28682 case INTERNALVAR_INTEGER:
28683 if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
28684 var->u.integer.type
28685 - = copy_type_recursive (objfile, var->u.integer.type, copied_types);
28686 + = copy_type_recursive (var->u.integer.type, copied_types);
28689 case INTERNALVAR_POINTER:
28690 if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
28691 var->u.pointer.type
28692 - = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
28693 + = copy_type_recursive (var->u.pointer.type, copied_types);
28696 case INTERNALVAR_VALUE:
28697 @@ -1855,6 +1938,8 @@ value_change_enclosing_type (struct value *val, struct type *new_encl_type)
28699 (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
28701 + type_incref (new_encl_type);
28702 + type_decref (val->enclosing_type);
28703 val->enclosing_type = new_encl_type;
28706 @@ -1919,6 +2004,8 @@ value_primitive_field (struct value *arg1, int offset,
28707 memcpy (value_contents_all_raw (v), value_contents_all_raw (arg1),
28708 TYPE_LENGTH (value_enclosing_type (arg1)));
28710 + type_incref (type);
28711 + type_decref (v->type);
28713 v->offset = value_offset (arg1);
28714 v->embedded_offset = (offset + value_embedded_offset (arg1)
28715 @@ -2177,6 +2264,42 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
28719 +/* Pack NUM into BUF using a target format of TYPE. */
28722 +pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
28724 + enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
28727 + type = check_typedef (type);
28728 + len = TYPE_LENGTH (type);
28730 + switch (TYPE_CODE (type))
28732 + case TYPE_CODE_INT:
28733 + case TYPE_CODE_CHAR:
28734 + case TYPE_CODE_ENUM:
28735 + case TYPE_CODE_FLAGS:
28736 + case TYPE_CODE_BOOL:
28737 + case TYPE_CODE_RANGE:
28738 + case TYPE_CODE_MEMBERPTR:
28739 + store_unsigned_integer (buf, len, byte_order, num);
28742 + case TYPE_CODE_REF:
28743 + case TYPE_CODE_PTR:
28744 + store_typed_address (buf, type, (CORE_ADDR) num);
28749 +Unexpected type (%d) encountered for unsigned integer constant."),
28750 + TYPE_CODE (type));
28755 /* Convert C numbers into newly allocated values. */
28758 @@ -2190,6 +2313,19 @@ value_from_longest (struct type *type, LONGEST num)
28762 +/* Convert C unsigned numbers into newly allocated values. */
28765 +value_from_ulongest (struct type *type, ULONGEST num)
28767 + struct value *val = allocate_value (type);
28769 + pack_unsigned_long (value_contents_raw (val), type, num);
28775 /* Create a value representing a pointer of type TYPE to the address
28778 @@ -2348,4 +2484,8 @@ VARIABLE is already initialized."));
28779 add_prefix_cmd ("function", no_class, function_command, _("\
28780 Placeholder command for showing help on convenience functions."),
28781 &functionlist, "function ", 0, &cmdlist);
28783 + make_final_cleanup (value_history_cleanup, NULL);
28785 + observer_attach_mark_used (value_types_mark_used);
28787 diff --git a/gdb/value.h b/gdb/value.h
28788 index 51e6960..48b30e4 100644
28791 @@ -342,11 +342,16 @@ extern LONGEST unpack_field_as_long (struct type *type,
28792 extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num);
28794 extern struct value *value_from_longest (struct type *type, LONGEST num);
28795 +extern struct value *value_from_ulongest (struct type *type, ULONGEST num);
28796 extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
28797 extern struct value *value_from_double (struct type *type, DOUBLEST num);
28798 extern struct value *value_from_decfloat (struct type *type,
28799 const gdb_byte *decbytes);
28801 +extern const char *object_address_data_not_valid (struct type *type);
28802 +extern int object_address_get_data (struct type *type,
28803 + CORE_ADDR *address_return);
28805 extern struct value *value_at (struct type *type, CORE_ADDR addr);
28806 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
28808 @@ -436,6 +441,7 @@ extern struct value *value_struct_elt (struct value **argp,
28810 extern struct value *value_aggregate_elt (struct type *curtype,
28812 + struct type *expect_type,
28814 enum noside noside);
28816 @@ -681,7 +687,7 @@ extern struct value *value_allocate_space_in_inferior (int);
28817 extern struct value *value_of_local (const char *name, int complain);
28819 extern struct value *value_subscripted_rvalue (struct value *array,
28820 - LONGEST index, int lowerbound);
28821 + CORE_ADDR offset);
28823 /* User function handler. */
28825 diff --git a/gdb/varobj.c b/gdb/varobj.c
28826 index 8f22156..8fe72ca 100644
28830 #include "gdbcmd.h"
28832 #include "valprint.h"
28833 +#include "objfiles.h"
28834 +#include "parser-defs.h"
28836 #include "gdb_assert.h"
28837 #include "gdb_string.h"
28838 @@ -253,6 +255,8 @@ static void free_variable (struct varobj *var);
28840 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
28842 +static struct cleanup *make_cleanup_uninstall_variable (struct varobj *var);
28844 static struct type *get_type (struct varobj *var);
28846 static struct type *get_value_type (struct varobj *var);
28847 @@ -480,6 +484,8 @@ is_root_p (struct varobj *var)
28849 varobj_ensure_python_env (struct varobj *var)
28851 + gdb_assert (var->root->is_valid);
28853 return ensure_python_env (var->root->exp->gdbarch,
28854 var->root->exp->language_defn);
28856 @@ -651,6 +657,7 @@ varobj_create (char *objname,
28857 do_cleanups (old_chain);
28860 + make_cleanup_uninstall_variable (var);
28863 discard_cleanups (old_chain);
28864 @@ -821,7 +828,12 @@ varobj_get_display_hint (struct varobj *var)
28865 char *result = NULL;
28868 - struct cleanup *back_to = varobj_ensure_python_env (var);
28869 + struct cleanup *back_to;
28871 + if (!var->root->is_valid)
28874 + back_to = varobj_ensure_python_env (var);
28876 if (var->pretty_printer)
28877 result = gdbpy_get_display_hint (var->pretty_printer);
28878 @@ -2186,6 +2198,18 @@ make_cleanup_free_variable (struct varobj *var)
28879 return make_cleanup (do_free_variable_cleanup, var);
28883 +do_uninstall_variable_cleanup (void *var)
28885 + uninstall_variable (var);
28888 +static struct cleanup *
28889 +make_cleanup_uninstall_variable (struct varobj *var)
28891 + return make_cleanup (do_uninstall_variable_cleanup, var);
28894 /* This returns the type of the variable. It also skips past typedefs
28895 to return the real type of the variable.
28897 @@ -3442,6 +3466,19 @@ java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
28898 return cplus_value_of_variable (var, format);
28901 +/* Iterate all the existing VAROBJs and call the FUNC callback for them with an
28902 + arbitrary caller supplied DATA pointer. */
28905 +all_varobjs (void (*func) (struct varobj *var, void *data), void *data)
28907 + struct vlist **vlp, *vl;
28909 + for (vlp = varobj_table; vlp < varobj_table + VAROBJ_TABLE_SIZE; vlp++)
28910 + for (vl = *vlp; vl != NULL; vl = vl->next)
28911 + (*func) (vl->var, data);
28914 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
28915 with an arbitrary caller supplied DATA pointer. */
28917 @@ -3459,6 +3496,43 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
28918 (*func) (var_root->rootvar, data);
28922 +/* Helper for varobj_types_mark_used. Call type_mark_used for any TYPEs
28923 + referenced from this VAR. */
28926 +varobj_types_mark_used_iter (struct varobj *var, void *unused)
28928 + /* Even FLOATING or IS_INVALID VARs with non-NULL TYPE references will
28929 + free them in free_variable. Still EXP may also reference TYPEs
28930 + but these belong to SYMBOLs which should be always associated with
28931 + an OBJFILE (and therefore not useful to be type_mark_used). */
28933 + type_mark_used (var->type);
28935 + type_mark_used (value_type (var->value));
28937 + /* Check VAROBJROOTs only once during the varobj_types_mark_used pass. */
28939 + if (var->root->rootvar == var)
28941 + if (var->root->exp)
28942 + exp_types_mark_used (var->root->exp);
28946 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
28949 +varobj_types_mark_used (void)
28951 + /* Check all the VAROBJs, even non-root ones. Child VAROBJs can reference
28952 + types from other OBJFILEs through TYPE_IS_OPAQUE resolutions by
28953 + check_typedef. Such types references will not be interconnected into the
28954 + same TYPE_GROUP. */
28956 + all_varobjs (varobj_types_mark_used_iter, NULL);
28959 extern void _initialize_varobj (void);
28961 diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
28962 index c56ab86..dacf913 100644
28963 --- a/gdb/xcoffread.c
28964 +++ b/gdb/xcoffread.c
28965 @@ -3038,6 +3038,7 @@ static struct sym_fns xcoff_sym_fns =
28966 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
28967 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
28968 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
28969 + NULL, /* sym_read_psymbols */
28970 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
28971 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
28972 default_symfile_segments, /* sym_segments: Get segment information from