1 http://sourceware.org/gdb/wiki/ProjectArcher
2 http://sourceware.org/gdb/wiki/ArcherBranchManagement
5 commit 7cb860f03e2437c97239334ebe240d06f45723e0
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 f5e1dde..73ee55c 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_PATH = @GDB_DATADIR_PATH@
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 4fc6dcd..6744b23 100644
200 @@ -462,6 +462,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..a6d35d7 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 VALUE 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..b0bf314 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. */
689 + bc_r = bp_location_count;
690 + while (bc_l + 1 < bc_r)
692 + struct bp_location *b;
694 - ALL_BP_LOCATIONS (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,66 @@ 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;
1629 + /* Tells if 'old_loc' is found amoung the new locations. If not, we
1631 - 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 + && bp_location_compare (*locp, old_loc) < 0)
1648 + found_object = locp < bp_location + bp_location_count && *locp == old_loc;
1650 /* If this location is no longer present, and inserted, look if there's
1651 maybe a new location at the same address. If so, mark that one
1652 @@ -7827,11 +8018,11 @@ update_global_location_list (int should_insert)
1653 don't have a time window where a breakpoint at certain location is not
1656 - if (loc->inserted)
1657 + if (old_loc->inserted)
1659 /* If the location is inserted now, we might have to remove it. */
1661 - if (found_object && should_be_inserted (loc))
1662 + if (found_object && should_be_inserted (old_loc))
1664 /* The location is still present in the location list, and still
1665 should be inserted. Don't do anything. */
1666 @@ -7842,37 +8033,46 @@ update_global_location_list (int should_insert)
1667 /* The location is either no longer present, or got disabled.
1668 See if there's another location at the same address, in which
1669 case we don't need to remove this one from the target. */
1670 - if (breakpoint_address_is_meaningful (loc->owner))
1671 - for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next)
1673 - /* For the sake of should_insert_location. The
1674 - call to check_duplicates will fix up this later. */
1675 - loc2->duplicate = 0;
1676 - if (should_be_inserted (loc2)
1677 - && loc2 != loc && loc2->address == loc->address)
1679 - loc2->inserted = 1;
1680 - loc2->target_info = loc->target_info;
1681 - keep_in_target = 1;
1686 + if (breakpoint_address_is_meaningful (old_loc->owner))
1688 + struct bp_location **loc2p;
1690 + for (loc2p = locp;
1691 + loc2p < bp_location + bp_location_count
1692 + && (*loc2p)->address == old_loc->address;
1695 + struct bp_location *loc2 = *loc2p;
1697 + /* For the sake of should_be_inserted.
1698 + Duplicates check below will fix up this later. */
1699 + loc2->duplicate = 0;
1700 + if (loc2 != old_loc && should_be_inserted (loc2))
1702 + loc2->inserted = 1;
1703 + loc2->target_info = old_loc->target_info;
1704 + keep_in_target = 1;
1711 if (!keep_in_target)
1713 - if (remove_breakpoint (loc, mark_uninserted))
1714 + if (remove_breakpoint (old_loc, mark_uninserted))
1716 /* This is just about all we can do. We could keep this
1717 location on the global list, and try to remove it next
1718 time, but there's no particular reason why we will
1721 - Note that at this point, loc->owner is still valid,
1722 + Note that at this point, old_loc->owner is still valid,
1723 as delete_breakpoint frees the breakpoint only
1724 after calling us. */
1725 printf_filtered (_("warning: Error removing breakpoint %d\n"),
1726 - loc->owner->number);
1727 + old_loc->owner->number);
1731 @@ -7894,19 +8094,59 @@ update_global_location_list (int should_insert)
1732 longer need to keep this breakpoint. This is just a
1733 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
1734 which is usability issue, but not a correctness problem. */
1735 - loc->events_till_retirement = 3 * (thread_count () + 1);
1736 - loc->owner = NULL;
1737 + old_loc->events_till_retirement = 3 * (thread_count () + 1);
1738 + old_loc->owner = NULL;
1740 - VEC_safe_push (bp_location_p, moribund_locations, loc);
1741 + VEC_safe_push (bp_location_p, moribund_locations, old_loc);
1744 - free_bp_location (loc);
1745 + free_bp_location (old_loc);
1749 - ALL_BREAKPOINTS (b)
1750 + /* Rescan breakpoints at the same address and section,
1751 + marking the first one as "first" and any others as "duplicates".
1752 + This is so that the bpt instruction is only inserted once.
1753 + If we have a permanent breakpoint at the same place as BPT, make
1754 + that one the official one, and the rest as duplicates. Permanent
1755 + breakpoints are sorted first for the same address. */
1758 + ALL_BP_LOCATIONS (loc, locp)
1760 - check_duplicates (b);
1761 + struct breakpoint *b = loc->owner;
1763 + if (b->enable_state == bp_disabled
1764 + || b->enable_state == bp_call_disabled
1765 + || b->enable_state == bp_startup_disabled
1767 + || loc->shlib_disabled
1768 + || !breakpoint_address_is_meaningful (b))
1771 + /* Permanent breakpoint should always be inserted. */
1772 + if (b->enable_state == bp_permanent && ! loc->inserted)
1773 + internal_error (__FILE__, __LINE__,
1774 + _("allegedly permanent breakpoint is not "
1775 + "actually inserted"));
1777 + if (loc_first == NULL
1778 + /* address / overlay match */
1779 + || loc->address != loc_first->address
1780 + || (overlay_debugging && loc->section != loc_first->section))
1783 + loc->duplicate = 0;
1787 + loc->duplicate = 1;
1789 + if (loc_first->owner->enable_state == bp_permanent && loc->inserted
1790 + && b->enable_state != bp_permanent)
1791 + internal_error (__FILE__, __LINE__,
1792 + _("another breakpoint was inserted on top of "
1793 + "a permanent breakpoint"));
1796 if (breakpoints_always_inserted_mode () && should_insert
1797 @@ -8083,6 +8323,7 @@ delete_command (char *arg, int from_tty)
1798 && b->type != bp_thread_event
1799 && b->type != bp_overlay_event
1800 && b->type != bp_longjmp_master
1801 + && b->type != bp_exception_master
1804 breaks_to_delete = 1;
1805 @@ -8102,6 +8343,7 @@ delete_command (char *arg, int from_tty)
1806 && b->type != bp_jit_event
1807 && b->type != bp_overlay_event
1808 && b->type != bp_longjmp_master
1809 + && b->type != bp_exception_master
1811 delete_breakpoint (b);
1813 @@ -8404,6 +8646,7 @@ breakpoint_re_set_one (void *bint)
1814 reset later by breakpoint_re_set. */
1815 case bp_overlay_event:
1816 case bp_longjmp_master:
1817 + case bp_exception_master:
1818 delete_breakpoint (b);
1821 @@ -8427,6 +8670,8 @@ breakpoint_re_set_one (void *bint)
1823 case bp_longjmp_resume:
1825 + case bp_exception:
1826 + case bp_exception_resume:
1830 @@ -8462,6 +8707,7 @@ breakpoint_re_set (void)
1831 create_longjmp_master_breakpoint ("_longjmp");
1832 create_longjmp_master_breakpoint ("siglongjmp");
1833 create_longjmp_master_breakpoint ("_siglongjmp");
1834 + create_exception_master_breakpoint ();
1837 /* Reset the thread number of this breakpoint:
1838 @@ -9327,6 +9573,22 @@ all_tracepoints ()
1842 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
1845 +breakpoint_types_mark_used (void)
1847 + struct breakpoint *b;
1849 + ALL_BREAKPOINTS (b)
1852 + exp_types_mark_used (b->exp);
1854 + type_mark_used (value_type (b->val));
1859 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
1860 It is defined as a macro to prevent duplication.
1861 @@ -9850,4 +10112,5 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
1862 automatic_hardware_breakpoints = 1;
1864 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
1865 + observer_attach_mark_used (breakpoint_types_mark_used);
1867 diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
1868 index ba499c6..80f702f 100644
1869 --- a/gdb/breakpoint.h
1870 +++ b/gdb/breakpoint.h
1871 @@ -56,6 +56,13 @@ enum bptype
1872 bp_longjmp, /* secret breakpoint to find longjmp() */
1873 bp_longjmp_resume, /* secret breakpoint to escape longjmp() */
1875 + /* An internal breakpoint that is installed on the unwinder's
1878 + /* An internal breakpoint that is set at the point where an
1879 + exception will land. */
1880 + bp_exception_resume,
1882 /* Used by wait_for_inferior for stepping over subroutine calls, for
1883 stepping over signal handlers, and for skipping prologues. */
1885 @@ -118,6 +125,9 @@ enum bptype
1889 + /* Like bp_longjmp_master, but for exceptions. */
1890 + bp_exception_master,
1895 @@ -228,10 +238,6 @@ struct bp_location
1896 the same parent breakpoint. */
1897 struct bp_location *next;
1899 - /* Pointer to the next breakpoint location, in a global
1900 - list of all breakpoint locations. */
1901 - struct bp_location *global_next;
1903 /* Type of this breakpoint location. */
1904 enum bp_loc_type loc_type;
1906 @@ -583,6 +589,10 @@ struct bpstat_what
1907 continuing from a call dummy without popping the frame is not a
1911 + /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME. True if we are
1912 + handling a longjmp, false if we are handling an exception. */
1916 /* The possible return values for print_bpstat, print_it_normal,
1917 @@ -946,6 +956,9 @@ extern int catching_syscall_number (int syscall_number);
1918 /* Tell a breakpoint to be quiet. */
1919 extern void make_breakpoint_silent (struct breakpoint *);
1921 +/* Set break condition of breakpoint B to EXP. */
1922 +extern void set_breakpoint_condition (struct breakpoint *b, char *exp, int from_tty);
1924 /* Return a tracepoint with the given number if found. */
1925 extern struct breakpoint *get_tracepoint (int num);
1927 diff --git a/gdb/c-exp.y b/gdb/c-exp.y
1928 index f8e4f12..5b47e2e 100644
1931 @@ -117,6 +117,8 @@ static int yylex (void);
1933 void yyerror (char *);
1935 +/* Cleanup for 'nonempty_typelist' */
1936 +static struct cleanup *typelist_cleanup;
1939 /* Although the yacc "value" of an expression is not used,
1940 @@ -157,6 +159,7 @@ void yyerror (char *);
1942 /* YYSTYPE gets defined by %union */
1943 static int parse_number (char *, int, int, YYSTYPE *);
1944 +static struct stoken operator_stoken (const char *);
1947 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly
1948 @@ -199,9 +202,12 @@ static int parse_number (char *, int, int, YYSTYPE *);
1950 %token <ssym> NAME_OR_INT
1953 %token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
1957 +%type <sval> operator
1959 /* Special type cases, put in to allow the parser to distinguish different
1961 @@ -401,6 +407,36 @@ arglist : arglist ',' exp %prec ABOVE_COMMA
1965 +exp : exp '(' nonempty_typelist ')' const_or_volatile
1967 + write_exp_elt_opcode (TYPE_INSTANCE);
1968 + write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
1969 + for (i = 0; i < $<ivec>3[0]; ++i)
1970 + write_exp_elt_type ($<tvec>3[i + 1]);
1971 + write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
1972 + write_exp_elt_opcode (TYPE_INSTANCE);
1973 + do_cleanups (typelist_cleanup);
1978 +exp : BLOCKNAME '(' nonempty_typelist ')'
1980 + write_exp_elt_opcode (TYPE_INSTANCE_LOOKUP);
1981 + write_exp_elt_sym ($1.sym);
1982 + write_exp_elt_opcode (TYPE_INSTANCE_LOOKUP);
1984 + write_exp_elt_opcode (TYPE_INSTANCE);
1985 + write_exp_elt_longcst ((LONGEST) $<ivec>3[0]);
1986 + for (i = 0; i < $<ivec>3[0]; ++i)
1987 + write_exp_elt_type ($<tvec>3[i + 1]);
1988 + write_exp_elt_longcst((LONGEST) $<ivec>3[0]);
1989 + write_exp_elt_opcode (TYPE_INSTANCE);
1990 + do_cleanups (typelist_cleanup);
1996 { $$ = end_arglist () - 1; }
1998 @@ -703,6 +739,7 @@ variable: block COLONCOLON name
1999 qualified_name: typebase COLONCOLON name
2001 struct type *type = $1;
2002 + CHECK_TYPEDEF (type);
2003 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2004 && TYPE_CODE (type) != TYPE_CODE_UNION
2005 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2006 @@ -718,6 +755,7 @@ qualified_name: typebase COLONCOLON name
2008 struct type *type = $1;
2009 struct stoken tmp_token;
2010 + CHECK_TYPEDEF (type);
2011 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
2012 && TYPE_CODE (type) != TYPE_CODE_UNION
2013 && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
2014 @@ -740,12 +778,13 @@ qualified_name: typebase COLONCOLON name
2017 variable: qualified_name
2018 + | COLONCOLON qualified_name
2021 char *name = copy_name ($2);
2023 struct minimal_symbol *msymbol;
2027 lookup_symbol (name, (const struct block *) NULL,
2028 VAR_DOMAIN, (int *) NULL);
2029 @@ -883,7 +922,7 @@ array_mod: '[' ']'
2032 | '(' nonempty_typelist ')'
2033 - { free ($2); $$ = 0; }
2034 + { do_cleanups (typelist_cleanup); $$ = 0; }
2037 /* We used to try to recognize pointer to member types here, but
2038 @@ -1088,12 +1127,15 @@ typename: TYPENAME
2041 { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
2042 + typelist_cleanup = make_cleanup (free, $$);
2043 $<ivec>$[0] = 1; /* Number of types in vector */
2046 | nonempty_typelist ',' type
2047 { int len = sizeof (struct type *) * (++($<ivec>1[0]) + 1);
2048 $$ = (struct type **) realloc ((char *) $1, len);
2049 + discard_cleanups (typelist_cleanup);
2050 + typelist_cleanup = make_cleanup (free, $$);
2051 $$[$<ivec>$[0]] = $3;
2054 @@ -1117,10 +1159,135 @@ const_or_volatile_noopt: const_and_volatile
2055 { push_type (tp_volatile); }
2058 +operator: OPERATOR NEW
2059 + { $$ = operator_stoken (" new"); }
2061 + { $$ = operator_stoken (" delete"); }
2062 + | OPERATOR NEW '[' ']'
2063 + { $$ = operator_stoken (" new[]"); }
2064 + | OPERATOR DELETE '[' ']'
2065 + { $$ = operator_stoken (" delete[]"); }
2067 + { $$ = operator_stoken ("+"); }
2069 + { $$ = operator_stoken ("-"); }
2071 + { $$ = operator_stoken ("*"); }
2073 + { $$ = operator_stoken ("/"); }
2075 + { $$ = operator_stoken ("%"); }
2077 + { $$ = operator_stoken ("^"); }
2079 + { $$ = operator_stoken ("&"); }
2081 + { $$ = operator_stoken ("|"); }
2083 + { $$ = operator_stoken ("~"); }
2085 + { $$ = operator_stoken ("!"); }
2087 + { $$ = operator_stoken ("="); }
2089 + { $$ = operator_stoken ("<"); }
2091 + { $$ = operator_stoken (">"); }
2092 + | OPERATOR ASSIGN_MODIFY
2093 + { const char *op = "unknown";
2117 + case BINOP_BITWISE_IOR:
2120 + case BINOP_BITWISE_AND:
2123 + case BINOP_BITWISE_XOR:
2130 + $$ = operator_stoken (op);
2133 + { $$ = operator_stoken ("<<"); }
2135 + { $$ = operator_stoken (">>"); }
2137 + { $$ = operator_stoken ("=="); }
2138 + | OPERATOR NOTEQUAL
2139 + { $$ = operator_stoken ("!="); }
2141 + { $$ = operator_stoken ("<="); }
2143 + { $$ = operator_stoken (">="); }
2145 + { $$ = operator_stoken ("&&"); }
2147 + { $$ = operator_stoken ("||"); }
2148 + | OPERATOR INCREMENT
2149 + { $$ = operator_stoken ("++"); }
2150 + | OPERATOR DECREMENT
2151 + { $$ = operator_stoken ("--"); }
2153 + { $$ = operator_stoken (","); }
2154 + | OPERATOR ARROW_STAR
2155 + { $$ = operator_stoken ("->*"); }
2157 + { $$ = operator_stoken ("->"); }
2158 + | OPERATOR '(' ')'
2159 + { $$ = operator_stoken ("()"); }
2160 + | OPERATOR '[' ']'
2161 + { $$ = operator_stoken ("[]"); }
2163 + { char *name, *canon;
2165 + struct ui_file *buf = mem_fileopen ();
2167 + c_print_type ($2, NULL, buf, -1, 0);
2168 + name = ui_file_xstrdup (buf, &length);
2169 + canon = cp_canonicalize_string (name);
2170 + if (canon != NULL)
2175 + ui_file_delete (buf);
2176 + $$ = operator_stoken (name);
2182 name : NAME { $$ = $1.stoken; }
2183 | BLOCKNAME { $$ = $1.stoken; }
2184 | TYPENAME { $$ = $1.stoken; }
2185 | NAME_OR_INT { $$ = $1.stoken; }
2186 + | operator { $$ = $1; }
2189 name_not_typename : NAME
2190 @@ -1136,6 +1303,20 @@ name_not_typename : NAME
2194 +/* Returns a stoken of the operator name given by OP (which does not
2195 + include the string "operator"). The result is xmalloc'd. */
2196 +static struct stoken
2197 +operator_stoken (const char *op)
2199 + static const char *operator_string = "operator";
2200 + struct stoken st = { NULL, 0 };
2201 + st.length = strlen (operator_string) + strlen (op);
2202 + st.ptr = xmalloc (st.length + 1);
2203 + strcpy (st.ptr, operator_string);
2204 + strcat (st.ptr, op);
2208 /* Take care of parsing a number (anything that starts with a digit).
2209 Set yylval and return the token type; update lexptr.
2210 LEN is the number of characters in it. */
2211 @@ -1714,6 +1895,9 @@ static const struct token ident_tokens[] =
2212 {"long", LONG, OP_NULL, 0},
2213 {"true", TRUEKEYWORD, OP_NULL, 1},
2214 {"int", INT_KEYWORD, OP_NULL, 0},
2215 + {"new", NEW, OP_NULL, 1},
2216 + {"delete", DELETE, OP_NULL, 1},
2217 + {"operator", OPERATOR, OP_NULL, 1},
2219 {"and", ANDAND, BINOP_END, 1},
2220 {"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, 1},
2221 @@ -1822,6 +2006,13 @@ static int last_was_structop;
2225 + /* name_prefix stores the full qualification of a variable that is
2226 + specified in the expression. It is used to eleminate confusion
2228 + static char *name_prefix = NULL;
2229 + static int name_prefix_len = 0;
2230 + static int terminate_prefix = 0;
2235 @@ -1830,9 +2021,19 @@ yylex (void)
2238 last_was_structop = 0;
2244 + if (terminate_prefix
2245 + || lexptr != name_prefix + name_prefix_len)
2247 + /* Some token was skipped, so clear name_prefix. */
2248 + name_prefix = NULL;
2249 + name_prefix_len = 0;
2252 + terminate_prefix = 1;
2254 /* Check if this is a macro invocation that we need to expand. */
2255 if (! scanning_macro_expansion ())
2257 @@ -1868,10 +2069,19 @@ yylex (void)
2258 && parse_language->la_language != language_cplus)
2261 + if (tokentab2[i].token == COLONCOLON)
2263 + name_prefix_len += 2;
2264 + terminate_prefix = 0;
2265 + if (name_prefix == NULL)
2266 + name_prefix = lexptr;
2270 yylval.opcode = tokentab2[i].opcode;
2271 if (in_parse_field && tokentab2[i].token == ARROW)
2272 last_was_structop = 1;
2274 return tokentab2[i].token;
2277 @@ -1900,6 +2110,8 @@ yylex (void)
2281 + name_prefix_len++;
2282 + terminate_prefix = 0;
2286 @@ -2057,11 +2269,13 @@ yylex (void)
2287 error ("Invalid character '%c' in expression.", c);
2289 /* It's a name. See how long it is. */
2292 for (c = tokstart[namelen];
2293 (c == '_' || c == '$' || (c >= '0' && c <= '9')
2294 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
2297 /* Template parameter lists are part of the name.
2298 FIXME: This mishandles `print $a<4&&$a>3'. */
2300 @@ -2125,14 +2339,29 @@ yylex (void)
2301 currently as names of types; NAME for other symbols.
2302 The caller is not constrained to care about the distinction. */
2306 int is_a_field_of_this = 0;
2309 - sym = lookup_symbol (copy, expression_context_block,
2310 + if (name_prefix != NULL)
2311 + tmp = savestring (name_prefix, name_prefix_len+namelen);
2313 + sym = lookup_symbol (tmp, expression_context_block,
2315 parse_language->la_language == language_cplus
2316 ? &is_a_field_of_this : (int *) NULL);
2318 + /* Keep this name as the prefix for the next name. */
2321 + if (name_prefix == NULL)
2322 + name_prefix = tokstart;
2324 + name_prefix_len += namelen;
2325 + terminate_prefix = 0;
2328 /* Call lookup_symtab, not lookup_partial_symtab, in case there are
2329 no psymtabs (coff, xcoff, or some future change to blow away the
2330 psymtabs once once symbols are read). */
2331 @@ -2191,6 +2420,7 @@ yylex (void)
2332 yylval.ssym.is_a_field_of_this = is_a_field_of_this;
2333 if (in_parse_field && *lexptr == '\0')
2334 saw_name_at_eof = 1;
2339 diff --git a/gdb/c-lang.c b/gdb/c-lang.c
2340 index d01490c..bc35a3e 100644
2343 @@ -715,7 +715,7 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
2344 If length returned from read_string was > 0, return the number of
2345 characters read by dividing the number of bytes by width. */
2347 - *length = *length / width;
2348 + *length = *length / width;
2350 *charset = target_charset ();
2352 @@ -1038,6 +1038,9 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
2353 return evaluate_subexp_standard (expect_type, exp, pos, noside);
2357 +/* Preprocessing and parsing C and C++ expressions. */
2361 /* Table mapping opcodes into strings for printing operators
2362 @@ -1138,6 +1141,7 @@ static const struct exp_descriptor exp_descriptor_c =
2364 print_subexp_standard,
2365 operator_length_standard,
2366 + operator_check_standard,
2368 dump_subexp_body_standard,
2370 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
2371 index b193080..04cf3bc 100644
2372 --- a/gdb/c-typeprint.c
2373 +++ b/gdb/c-typeprint.c
2376 #include "typeprint.h"
2378 +#include "jv-lang.h"
2380 #include "gdb_string.h"
2382 @@ -40,8 +41,6 @@ static void cp_type_print_method_args (struct type *mtype, char *prefix,
2383 char *varstring, int staticp,
2384 struct ui_file *stream);
2386 -static void c_type_print_args (struct type *, struct ui_file *);
2388 static void cp_type_print_derivation_info (struct ui_file *, struct type *);
2390 static void c_type_print_varspec_prefix (struct type *, struct ui_file *, int,
2391 @@ -199,6 +198,23 @@ cp_type_print_method_args (struct type *mtype, char *prefix, char *varstring,
2392 fprintf_filtered (stream, "void");
2394 fprintf_filtered (stream, ")");
2396 + /* For non-static methods, read qualifiers from the type of
2400 + struct type *domain;
2402 + gdb_assert (nargs > 0);
2403 + gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
2404 + domain = TYPE_TARGET_TYPE (args[0].type);
2406 + if (TYPE_CONST (domain))
2407 + fprintf_filtered (stream, " const");
2409 + if (TYPE_VOLATILE (domain))
2410 + fprintf_filtered (stream, " volatile");
2415 @@ -355,10 +371,14 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
2417 /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
2418 or TYPE_CODE_FUNC, to STREAM. Artificial arguments, such as "this"
2419 - in non-static methods, are displayed. */
2420 + in non-static methods, are displayed if SHOW_ARTIFICIAL is
2421 + non-zero. LANGUAGE is the language in which TYPE was defined. This is
2422 + a necessary evil since this code is used by the C, C++, and Java
2426 -c_type_print_args (struct type *type, struct ui_file *stream)
2428 +c_type_print_args (struct type *type, struct ui_file *stream,
2429 + int show_artificial, enum language language)
2433 @@ -370,13 +390,19 @@ c_type_print_args (struct type *type, struct ui_file *stream)
2435 for (i = 0; i < TYPE_NFIELDS (type); i++)
2437 + if (TYPE_FIELD_ARTIFICIAL (type, i) && !show_artificial)
2442 fprintf_filtered (stream, ", ");
2446 - c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2447 + if (language == language_java)
2448 + java_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2450 + c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
2454 @@ -560,7 +586,12 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2455 fprintf_filtered (stream, ")");
2457 fprintf_filtered (stream, "[");
2458 - if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
2459 + if (TYPE_ARRAY_BOUND_IS_DWARF_BLOCK (type, 1))
2461 + /* No _() - printed sources should not be locale dependent. */
2462 + fprintf_filtered (stream, "variable");
2464 + else if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
2465 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
2466 fprintf_filtered (stream, "%d",
2468 @@ -593,7 +624,7 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2470 fprintf_filtered (stream, ")");
2471 if (!demangled_args)
2472 - c_type_print_args (type, stream);
2473 + c_type_print_args (type, stream, 1, language_c);
2474 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, show,
2477 diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
2478 index ce7c2a6..6380fec 100644
2479 --- a/gdb/cli/cli-cmds.c
2480 +++ b/gdb/cli/cli-cmds.c
2482 #include "cli/cli-setshow.h"
2483 #include "cli/cli-cmds.h"
2485 +#include "python/python.h"
2488 #include "tui/tui.h" /* For tui_active et.al. */
2490 @@ -183,6 +185,7 @@ struct cmd_list_element *showchecklist;
2492 /* Command tracing state. */
2494 +static int source_python = 0;
2495 int source_verbose = 0;
2496 int trace_commands = 0;
2498 @@ -444,6 +447,7 @@ source_script (char *file, int from_tty)
2499 struct cleanup *old_cleanups;
2500 char *full_pathname = NULL;
2504 if (file == NULL || *file == 0)
2506 @@ -476,8 +480,16 @@ source_script (char *file, int from_tty)
2510 + is_python = source_python;
2511 + if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
2514 stream = fdopen (fd, FOPEN_RT);
2515 - script_from_file (stream, file);
2518 + source_python_script (stream, file);
2520 + script_from_file (stream, file);
2522 do_cleanups (old_cleanups);
2524 @@ -491,15 +503,30 @@ source_verbose_cleanup (void *old_value)
2528 +/* A helper for source_command. Look for an argument in *ARGS.
2529 + Update *ARGS by stripping leading whitespace. If an argument is
2530 + found, return it (a character). Otherwise, return 0. */
2532 +find_argument (char **args)
2535 + while (isspace ((*args)[0]))
2537 + if ((*args)[0] == '-' && isalpha ((*args)[1]))
2539 + result = (*args)[1];
2546 source_command (char *args, int from_tty)
2548 struct cleanup *old_cleanups;
2549 - char *file = args;
2550 - int *old_source_verbose = xmalloc (sizeof(int));
2552 - *old_source_verbose = source_verbose;
2553 - old_cleanups = make_cleanup (source_verbose_cleanup, old_source_verbose);
2554 + old_cleanups = make_cleanup_restore_integer (&source_verbose);
2555 + make_cleanup_restore_integer (&source_python);
2557 /* -v causes the source command to run in verbose mode.
2558 We still have to be able to handle filenames with spaces in a
2559 @@ -507,23 +534,28 @@ source_command (char *args, int from_tty)
2563 - /* Make sure leading white space does not break the comparisons. */
2564 - while (isspace(args[0]))
2567 - /* Is -v the first thing in the string? */
2568 - if (args[0] == '-' && args[1] == 'v' && isspace (args[2]))
2571 - source_verbose = 1;
2573 - /* Trim -v and whitespace from the filename. */
2575 - while (isspace (file[0]))
2577 + int arg = find_argument (&args);
2583 + source_verbose = 1;
2586 + source_python = 1;
2589 + error (_("unrecognized option -%c"), arg);
2594 - source_script (file, from_tty);
2595 + source_script (args, from_tty);
2597 + do_cleanups (old_cleanups);
2601 @@ -1307,7 +1339,9 @@ Read commands from a file named FILE.\n\
2602 Optional -v switch (before the filename) causes each command in\n\
2603 FILE to be echoed as it is executed.\n\
2604 Note that the file \"%s\" is read automatically in this way\n\
2605 -when GDB is started."), gdbinit);
2606 +when GDB is started.\n\
2607 +Optional -p switch (before the filename) causes FILE to be evaluated\n\
2608 +as Python code."), gdbinit);
2609 c = add_cmd ("source", class_support, source_command,
2610 source_help_text, &cmdlist);
2611 set_cmd_completer (c, filename_completer);
2612 diff --git a/gdb/coffread.c b/gdb/coffread.c
2613 index 888f8b4..65494b8 100644
2614 --- a/gdb/coffread.c
2615 +++ b/gdb/coffread.c
2616 @@ -346,7 +346,7 @@ coff_alloc_type (int index)
2617 We will fill it in later if we find out how. */
2620 - type = alloc_type (current_objfile);
2621 + type = alloc_type (current_objfile, NULL);
2625 @@ -2121,6 +2121,7 @@ static struct sym_fns coff_sym_fns =
2626 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2627 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2628 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2629 + NULL, /* sym_read_psymbols */
2630 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2631 default_symfile_offsets, /* sym_offsets: xlate external to internal form */
2632 default_symfile_segments, /* sym_segments: Get segment information from
2633 diff --git a/gdb/config.in b/gdb/config.in
2634 index 4716524..0745c65 100644
2638 language is requested. */
2641 -/* look for global separate data files in this path [DATADIR/gdb] */
2642 +/* Global directory for GDB data files. */
2645 -/* Define if the gdb-datadir directory should be relocated when GDB is moved.
2647 +/* Define if GDB datadir should be relocated when GDB is moved. */
2648 #undef GDB_DATADIR_RELOCATABLE
2650 /* Define to be a string naming the default host character set. */
2653 #undef PTRDIFF_T_SUFFIX
2655 +/* Define to install path for Python sources */
2658 /* Relocated directory for source files. */
2661 diff --git a/gdb/config/i386/nm-i386.h b/gdb/config/i386/nm-i386.h
2662 new file mode 100644
2663 index 0000000..5f237cc
2665 +++ b/gdb/config/i386/nm-i386.h
2667 +/* Native macro definitions for GDB on an Intel i[3456]86.
2668 + Copyright 2001, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
2670 + This file is part of GDB.
2672 + This program is free software; you can redistribute it and/or modify
2673 + it under the terms of the GNU General Public License as published by
2674 + the Free Software Foundation; either version 3 of the License, or
2675 + (at your option) any later version.
2677 + This program is distributed in the hope that it will be useful,
2678 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2679 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2680 + GNU General Public License for more details.
2682 + You should have received a copy of the GNU General Public License
2683 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
2686 +#define NM_I386_H 1
2688 +/* Hardware-assisted breakpoints and watchpoints. */
2690 +/* Targets should define this to use the generic x86 watchpoint support. */
2691 +#ifdef I386_USE_GENERIC_WATCHPOINTS
2693 +/* Add watchpoint methods to the provided target_ops. Targets which call
2694 + this should also define I386_WATCHPOINTS_IN_TARGET_VECTOR. */
2696 +void i386_use_watchpoints (struct target_ops *);
2698 +/* Clear the reference counts and forget everything we knew about DRi. */
2699 +extern void i386_cleanup_dregs (void);
2701 +/* Insert a watchpoint to watch a memory region which starts at
2702 + address ADDR and whose length is LEN bytes. Watch memory accesses
2703 + of the type TYPE. Return 0 on success, -1 on failure. */
2704 +extern int i386_insert_watchpoint (CORE_ADDR addr, int len, int type);
2706 +/* Remove a watchpoint that watched the memory region which starts at
2707 + address ADDR, whose length is LEN bytes, and for accesses of the
2708 + type TYPE. Return 0 on success, -1 on failure. */
2709 +extern int i386_remove_watchpoint (CORE_ADDR addr, int len, int type);
2711 +/* Return non-zero if we can watch a memory region that starts at
2712 + address ADDR and whose length is LEN bytes. */
2713 +extern int i386_region_ok_for_watchpoint (CORE_ADDR addr, int len);
2715 +/* Return non-zero if the inferior has some break/watchpoint that
2717 +extern int i386_stopped_by_hwbp (void);
2719 +/* If the inferior has some break/watchpoint that triggered, set
2720 + the address associated with that break/watchpoint and return
2721 + true. Otherwise, return false. */
2722 +extern int i386_stopped_data_address (struct target_ops *, CORE_ADDR *);
2724 +/* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
2725 + Return 0 on success, EBUSY on failure. */
2726 +struct bp_target_info;
2727 +extern int i386_insert_hw_breakpoint (struct bp_target_info *bp_tgt);
2729 +/* Remove a hardware-assisted breakpoint at BP_TGT->placed_address.
2730 + Return 0 on success, -1 on failure. */
2731 +extern int i386_remove_hw_breakpoint (struct bp_target_info *bp_tgt);
2733 +extern int i386_stopped_by_watchpoint (void);
2735 +#ifndef I386_WATCHPOINTS_IN_TARGET_VECTOR
2737 +/* Returns the number of hardware watchpoints of type TYPE that we can
2738 + set. Value is positive if we can set CNT watchpoints, zero if
2739 + setting watchpoints of type TYPE is not supported, and negative if
2740 + CNT is more than the maximum number of watchpoints of type TYPE
2741 + that we can support. TYPE is one of bp_hardware_watchpoint,
2742 + bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
2743 + CNT is the number of such watchpoints used so far (including this
2744 + one). OTHERTYPE is non-zero if other types of watchpoints are
2745 + currently enabled.
2747 + We always return 1 here because we don't have enough information
2748 + about possible overlap of addresses that they want to watch. As an
2749 + extreme example, consider the case where all the watchpoints watch
2750 + the same address and the same region length: then we can handle a
2751 + virtually unlimited number of watchpoints, due to debug register
2752 + sharing implemented via reference counts in i386-nat.c. */
2754 +#define TARGET_CAN_USE_HARDWARE_WATCHPOINT(type, cnt, ot) 1
2756 +/* Returns non-zero if we can use hardware watchpoints to watch a
2757 + region whose address is ADDR and whose length is LEN. */
2759 +#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(addr, len) \
2760 + i386_region_ok_for_watchpoint (addr, len)
2762 +/* After a watchpoint trap, the PC points to the instruction after the
2763 + one that caused the trap. Therefore we don't need to step over it.
2764 + But we do need to reset the status register to avoid another trap. */
2766 +#define HAVE_CONTINUABLE_WATCHPOINT 1
2768 +#define STOPPED_BY_WATCHPOINT(W) (i386_stopped_by_watchpoint () != 0)
2770 +#define target_stopped_data_address(target, x) \
2771 + i386_stopped_data_address(target, x)
2773 +/* Use these macros for watchpoint insertion/removal. */
2775 +#define target_insert_watchpoint(addr, len, type) \
2776 + i386_insert_watchpoint (addr, len, type)
2778 +#define target_remove_watchpoint(addr, len, type) \
2779 + i386_remove_watchpoint (addr, len, type)
2781 +#define target_insert_hw_breakpoint(bp_tgt) \
2782 + i386_insert_hw_breakpoint (bp_tgt)
2784 +#define target_remove_hw_breakpoint(bp_tgt) \
2785 + i386_remove_hw_breakpoint (bp_tgt)
2787 +#endif /* I386_WATCHPOINTS_IN_TARGET_VECTOR */
2789 +#endif /* I386_USE_GENERIC_WATCHPOINTS */
2791 +#endif /* NM_I386_H */
2792 diff --git a/gdb/config/i386/nm-linux64.h b/gdb/config/i386/nm-linux64.h
2793 new file mode 100644
2794 index 0000000..19d710a
2796 +++ b/gdb/config/i386/nm-linux64.h
2798 +/* Native support for GNU/Linux x86-64.
2800 + Copyright 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
2801 + Free Software Foundation, Inc.
2803 + Contributed by Jiri Smid, SuSE Labs.
2805 + This file is part of GDB.
2807 + This program is free software; you can redistribute it and/or modify
2808 + it under the terms of the GNU General Public License as published by
2809 + the Free Software Foundation; either version 3 of the License, or
2810 + (at your option) any later version.
2812 + This program is distributed in the hope that it will be useful,
2813 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2814 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2815 + GNU General Public License for more details.
2817 + You should have received a copy of the GNU General Public License
2818 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
2820 +#ifndef NM_LINUX64_H
2821 +#define NM_LINUX64_H
2823 +/* GNU/Linux supports the i386 hardware debugging registers. */
2824 +#define I386_USE_GENERIC_WATCHPOINTS
2825 +#define I386_WATCHPOINTS_IN_TARGET_VECTOR
2827 +#include "i386/nm-i386.h"
2828 +#include "config/nm-linux.h"
2830 +/* Support for 8-byte wide hardware watchpoints. */
2831 +#define TARGET_HAS_DR_LEN_8 1
2833 +/* Provide access to the i386 hardware debugging registers. */
2835 +extern void amd64_linux_dr_set_control (unsigned long control);
2836 +#define I386_DR_LOW_SET_CONTROL(control) \
2837 + amd64_linux_dr_set_control (control)
2839 +extern void amd64_linux_dr_set_addr (int regnum, CORE_ADDR addr);
2840 +#define I386_DR_LOW_SET_ADDR(regnum, addr) \
2841 + amd64_linux_dr_set_addr (regnum, addr)
2843 +extern void amd64_linux_dr_reset_addr (int regnum);
2844 +#define I386_DR_LOW_RESET_ADDR(regnum) \
2845 + amd64_linux_dr_reset_addr (regnum)
2847 +extern unsigned long amd64_linux_dr_get_status (void);
2848 +#define I386_DR_LOW_GET_STATUS() \
2849 + amd64_linux_dr_get_status ()
2851 +#endif /* nm-linux64.h */
2852 diff --git a/gdb/config/mips/nm-irix5.h b/gdb/config/mips/nm-irix5.h
2853 new file mode 100644
2854 index 0000000..49ac420
2856 +++ b/gdb/config/mips/nm-irix5.h
2858 +/* Definitions for native support of irix5.
2860 + Copyright 1993, 1996, 1998, 1999, 2000, 2007, 2008, 2009
2861 + Free Software Foundation, Inc.
2863 + This file is part of GDB.
2865 + This program is free software; you can redistribute it and/or modify
2866 + it under the terms of the GNU General Public License as published by
2867 + the Free Software Foundation; either version 3 of the License, or
2868 + (at your option) any later version.
2870 + This program is distributed in the hope that it will be useful,
2871 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2872 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2873 + GNU General Public License for more details.
2875 + You should have received a copy of the GNU General Public License
2876 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
2878 +#define TARGET_HAS_HARDWARE_WATCHPOINTS
2880 +/* TARGET_CAN_USE_HARDWARE_WATCHPOINT is now defined to go through
2881 + the target vector. For Irix5, procfs_can_use_hw_watchpoint()
2882 + should be invoked. */
2884 +/* When a hardware watchpoint fires off the PC will be left at the
2885 + instruction which caused the watchpoint. It will be necessary for
2886 + GDB to step over the watchpoint. */
2888 +#define STOPPED_BY_WATCHPOINT(W) \
2889 + procfs_stopped_by_watchpoint(inferior_ptid)
2890 +extern int procfs_stopped_by_watchpoint (ptid_t);
2892 +/* Use these macros for watchpoint insertion/deletion. */
2893 +/* type can be 0: write watch, 1: read watch, 2: access watch (read/write) */
2894 +#define target_insert_watchpoint(ADDR, LEN, TYPE) \
2895 + procfs_set_watchpoint (inferior_ptid, ADDR, LEN, TYPE, 0)
2896 +#define target_remove_watchpoint(ADDR, LEN, TYPE) \
2897 + procfs_set_watchpoint (inferior_ptid, ADDR, 0, 0, 0)
2898 +extern int procfs_set_watchpoint (ptid_t, CORE_ADDR, int, int, int);
2900 +#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(SIZE) 1
2902 diff --git a/gdb/configure b/gdb/configure
2903 index 99acc2f..a2ea1ae 100755
2906 @@ -676,6 +676,8 @@ REPORT_BUGS_TO
2915 @@ -883,6 +885,7 @@ enable_dependency_tracking
2916 with_separate_debug_dir
2918 with_relocated_sources
2923 @@ -1581,6 +1584,10 @@ Optional Packages:
2925 --with-relocated-sources=PATH
2926 automatically relocate this path for source files
2927 + --with-gdb-datadir look for global separate data files in this path
2929 + --with-pythondir install Python data files in this path
2930 + [DATADIR/gdb/python]
2931 --with-libunwind use libunwind frame unwinding support
2932 --with-curses use the curses library instead of the termcap
2934 @@ -6602,6 +6609,73 @@ _ACEOF
2938 +# GDB's datadir relocation
2940 +gdbdatadir=${datadir}/gdb
2943 +# Check whether --with-gdb-datadir was given.
2944 +if test "${with_gdb_datadir+set}" = set; then :
2945 + withval=$with_gdb_datadir; gdbdatadir="${withval}"
2950 + test "x$prefix" = xNONE && prefix="$ac_default_prefix"
2951 + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
2952 + ac_define_dir=`eval echo $gdbdatadir`
2953 + ac_define_dir=`eval echo $ac_define_dir`
2955 +cat >>confdefs.h <<_ACEOF
2956 +#define GDB_DATADIR "$ac_define_dir"
2961 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
2962 + if test "x$prefix" = xNONE; then
2963 + test_prefix=/usr/local
2965 + test_prefix=$prefix
2968 + test_prefix=$exec_prefix
2971 +case ${gdbdatadir} in
2972 + "${test_prefix}"|"${test_prefix}/"*|\
2973 + '${exec_prefix}'|'${exec_prefix}/'*)
2975 +$as_echo "#define GDB_DATADIR_RELOCATABLE 1" >>confdefs.h
2979 +GDB_DATADIR_PATH=${gdbdatadir}
2983 +# Check whether --with-pythondir was given.
2984 +if test "${with_pythondir+set}" = set; then :
2985 + withval=$with_pythondir; pythondir="${withval}"
2991 +# If the user passed in a path, define it. Otherwise, compute it at
2992 +# runtime based on the possibly-relocatable datadir.
2993 +if test "$pythondir" = "no"; then
2994 + pythondir='$(GDB_DATADIR_PATH)/python'
2997 +cat >>confdefs.h <<_ACEOF
2998 +#define PYTHONDIR "$pythondir"
3007 subdirs="$subdirs doc testsuite"
3008 @@ -9282,6 +9356,8 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
3009 CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
3010 CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
3011 CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
3012 + CONFIG_INSTALL="$CONFIG_INSTALL install-python"
3013 + CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
3014 ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
3016 # Flags needed to compile Python code (taken from python-config --cflags).
3017 diff --git a/gdb/configure.ac b/gdb/configure.ac
3018 index b31d9b7..a1969bc 100644
3019 --- a/gdb/configure.ac
3020 +++ b/gdb/configure.ac
3021 @@ -107,6 +107,51 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat
3022 [Relocated directory for source files. ])
3025 +# GDB's datadir relocation
3027 +gdbdatadir=${datadir}/gdb
3029 +AC_ARG_WITH([gdb-datadir],
3030 + [AS_HELP_STRING([--with-gdb-datadir],
3031 + [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
3033 +AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
3034 + [Global directory for GDB data files. ])
3036 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
3037 + if test "x$prefix" = xNONE; then
3038 + test_prefix=/usr/local
3040 + test_prefix=$prefix
3043 + test_prefix=$exec_prefix
3046 +case ${gdbdatadir} in
3047 + "${test_prefix}"|"${test_prefix}/"*|\
3048 + '${exec_prefix}'|'${exec_prefix}/'*)
3049 + AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
3052 +GDB_DATADIR_PATH=${gdbdatadir}
3053 +AC_SUBST(GDB_DATADIR_PATH)
3055 +AC_ARG_WITH([pythondir],
3056 + [AS_HELP_STRING([--with-pythondir],
3057 + [install Python data files in this path [DATADIR/gdb/python]])], [pythondir="${withval}"], [pythondir=no])
3059 +# If the user passed in a path, define it. Otherwise, compute it at
3060 +# runtime based on the possibly-relocatable datadir.
3061 +if test "$pythondir" = "no"; then
3062 + pythondir='$(GDB_DATADIR_PATH)/python'
3064 + AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir",
3065 + [Define to install path for Python sources])
3067 +AC_SUBST(pythondir)
3070 AC_CONFIG_SUBDIRS(doc testsuite)
3072 # Check whether to support alternative target configurations
3073 @@ -658,6 +703,8 @@ if test "${have_libpython}" = yes; then
3074 CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)"
3075 CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
3076 CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
3077 + CONFIG_INSTALL="$CONFIG_INSTALL install-python"
3078 + CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
3079 ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
3081 # Flags needed to compile Python code (taken from python-config --cflags).
3082 diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
3083 index 62800b8..97d587b 100644
3084 --- a/gdb/cp-name-parser.y
3085 +++ b/gdb/cp-name-parser.y
3087 /* YACC parser for C++ names, for GDB.
3089 - Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
3090 - Free Software Foundation, Inc.
3091 + Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
3093 Parts of the lexer are based on c-exp.y from GDB.
3095 @@ -389,7 +388,7 @@ function
3096 | colon_ext_only function_arglist start_opt
3097 { $$ = fill_comp (DEMANGLE_COMPONENT_TYPED_NAME, $1, $2.comp);
3098 if ($3) $$ = fill_comp (DEMANGLE_COMPONENT_LOCAL_NAME, $$, $3); }
3101 | conversion_op_name start_opt
3103 if ($2) $$ = fill_comp (DEMANGLE_COMPONENT_LOCAL_NAME, $$, $2); }
3104 diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
3105 index d2d8f2e..af0ba28 100644
3106 --- a/gdb/cp-namespace.c
3107 +++ b/gdb/cp-namespace.c
3108 @@ -36,14 +36,17 @@ static struct using_direct *cp_copy_usings (struct using_direct *using,
3109 struct obstack *obstack);
3111 static struct symbol *lookup_namespace_scope (const char *name,
3112 - const char *linkage_name,
3113 const struct block *block,
3114 const domain_enum domain,
3118 +static struct symbol *cp_lookup_symbol_in_namespace (const char *namespace,
3120 + const struct block *block,
3121 + const domain_enum domain);
3123 static struct symbol *lookup_symbol_file (const char *name,
3124 - const char *linkage_name,
3125 const struct block *block,
3126 const domain_enum domain,
3127 int anonymous_namespace);
3128 @@ -119,7 +122,7 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
3129 anonymous namespace. So add symbols in it to the
3130 namespace given by the previous component if there is
3131 one, or to the global namespace if there isn't. */
3132 - cp_add_using_directive (dest, src);
3133 + cp_add_using_directive (dest, src, "", "", 0);
3135 /* The "+ 2" is for the "::". */
3136 previous_component = next_component + 2;
3137 @@ -134,7 +137,8 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
3138 has already been added, don't add it twice. */
3141 -cp_add_using_directive (const char *dest, const char *src)
3142 +cp_add_using_directive (const char *dest, const char *src, const char* alias,
3143 + const char *declaration, const int line_number)
3145 struct using_direct *current;
3146 struct using_direct *new;
3147 @@ -148,7 +152,8 @@ cp_add_using_directive (const char *dest, const char *src)
3151 - using_directives = cp_add_using (dest, src, using_directives);
3152 + using_directives = cp_add_using (dest, src, alias, declaration,
3153 + line_number, using_directives);
3157 @@ -201,7 +206,10 @@ cp_is_anonymous (const char *namespace)
3160 /* Create a new struct using direct which imports the namespace SRC
3161 - into the scope DEST.
3162 + into the scope DEST. ALIAS is the name of the imported namespace
3163 + in the current scope. If ALIAS is an empty string then the
3164 + namespace is known by its original name.
3166 Set its next member in the linked list to NEXT; allocate all memory
3167 using xmalloc. It copies the strings, so NAME can be a temporary
3169 @@ -209,14 +217,21 @@ cp_is_anonymous (const char *namespace)
3170 struct using_direct *
3171 cp_add_using (const char *dest,
3173 + const char *alias,
3174 + const char *declaration,
3175 + const int line_number,
3176 struct using_direct *next)
3178 struct using_direct *retval;
3180 retval = xmalloc (sizeof (struct using_direct));
3181 - retval->import_src = savestring (src, strlen(src));
3182 - retval->import_dest = savestring (dest, strlen(dest));
3183 + retval->import_src = savestring (src, strlen (src));
3184 + retval->import_dest = savestring (dest, strlen (dest));
3185 + retval->alias = savestring (alias, strlen (alias));
3186 + retval->declaration = savestring (declaration, strlen (declaration));
3187 + retval->line_number = line_number;
3188 retval->next = next;
3189 + retval->searched = 0;
3193 @@ -241,10 +256,18 @@ cp_copy_usings (struct using_direct *using,
3195 retval->import_dest = obsavestring (using->import_dest, strlen (using->import_dest),
3197 + retval->alias = obsavestring (using->alias, strlen (using->alias),
3199 + retval->declaration = obsavestring (using->declaration, strlen (using->declaration),
3201 retval->next = cp_copy_usings (using->next, obstack);
3203 + retval->searched = using->searched;
3205 xfree (using->import_src);
3206 xfree (using->import_dest);
3207 + xfree (using->alias);
3208 + xfree (using->declaration);
3212 @@ -261,12 +284,48 @@ cp_copy_usings (struct using_direct *using,
3215 cp_lookup_symbol_nonlocal (const char *name,
3216 - const char *linkage_name,
3217 const struct block *block,
3218 const domain_enum domain)
3220 - return lookup_namespace_scope (name, linkage_name, block, domain,
3221 - block_scope (block), 0);
3222 + struct symbol *sym;
3223 + const char *scope = block_scope (block);
3225 + sym = lookup_namespace_scope (name, block, domain, scope, 0);
3229 + return cp_lookup_symbol_namespace(scope, name, block, domain);
3232 +/* Searches for NAME in the current namespace, and by applying relevant import
3233 + statements belonging to BLOCK and its parents. SCOPE is the namespace
3234 + scope of the context in which the search is being evaluated. */
3237 +cp_lookup_symbol_namespace (const char *scope,
3239 + const struct block *block,
3240 + const domain_enum domain)
3242 + struct symbol *sym;
3244 + /* First, try to find the symbol in the given namespace. */
3245 + sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
3249 + /* Search for name in namespaces imported to this and parent blocks. */
3250 + while (block != NULL)
3252 + sym = cp_lookup_symbol_imports(scope,name, block, domain,0,1);
3257 + block = BLOCK_SUPERBLOCK(block);
3263 /* Lookup NAME at namespace scope (or, in C terms, in static and
3264 @@ -284,9 +343,8 @@ cp_lookup_symbol_nonlocal (const char *name,
3265 "A::x", and if that call fails, then the first call looks for
3268 -static struct symbol *
3270 lookup_namespace_scope (const char *name,
3271 - const char *linkage_name,
3272 const struct block *block,
3273 const domain_enum domain,
3275 @@ -308,8 +366,7 @@ lookup_namespace_scope (const char *name,
3278 new_scope_len += cp_find_first_component (scope + new_scope_len);
3279 - sym = lookup_namespace_scope (name, linkage_name, block,
3280 - domain, scope, new_scope_len);
3281 + sym = lookup_namespace_scope (name, block, domain, scope, new_scope_len);
3285 @@ -320,25 +377,87 @@ lookup_namespace_scope (const char *name,
3286 namespace = alloca (scope_len + 1);
3287 strncpy (namespace, scope, scope_len);
3288 namespace[scope_len] = '\0';
3289 - return cp_lookup_symbol_namespace (namespace, name, linkage_name,
3291 + return cp_lookup_symbol_in_namespace (namespace, name,block, domain);
3294 -/* Look up NAME in the C++ namespace NAMESPACE, applying the using
3295 - directives that are active in BLOCK. Other arguments are as in
3296 +/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in
3297 cp_lookup_symbol_nonlocal. */
3299 +static struct symbol *
3300 +cp_lookup_symbol_in_namespace (const char *namespace,
3302 + const struct block *block,
3303 + const domain_enum domain)
3306 + if (namespace[0] == '\0')
3308 + return lookup_symbol_file (name, block,domain, 0);
3312 + char *concatenated_name
3313 + = alloca (strlen (namespace) + 2 + strlen (name) + 1);
3314 + strcpy (concatenated_name, namespace);
3315 + strcat (concatenated_name, "::");
3316 + strcat (concatenated_name, name);
3317 + return lookup_symbol_file (concatenated_name, block, domain,
3318 + cp_is_anonymous (namespace));
3322 +/* Search for NAME by applying all import statements belonging
3323 + to BLOCK which are applicable in SCOPE. If DECLARATION_ONLY the search
3324 + is restricted to using declarations.
3332 + If SEARCH_PARENTS the search will include imports which are applicable in
3333 + parents of scopes.
3337 + using namespace X;
3339 + using namespace Y;
3343 + If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X
3344 + and Y will be considered. If SEARCH_PARENTS is false only the import of Y
3348 -cp_lookup_symbol_namespace (const char *namespace,
3350 - const char *linkage_name,
3351 - const struct block *block,
3352 - const domain_enum domain)
3353 +cp_lookup_symbol_imports (const char *scope,
3355 + const struct block *block,
3356 + const domain_enum domain,
3357 + int declaration_only,
3358 + int search_parents)
3360 - const struct using_direct *current;
3361 - struct symbol *sym;
3362 + struct using_direct *current;
3363 + struct symbol *sym = NULL;
3364 + int directive_match;
3367 + if(!declaration_only)
3368 + /* First, try to find the symbol in the given namespace. */
3369 + sym = cp_lookup_symbol_in_namespace (scope, name, block, domain);
3371 - /* First, go through the using directives. If any of them add new
3375 + if (has_stack_frames ())
3376 + current_line = find_pc_line (get_frame_pc (get_selected_frame (NULL)),
3381 + /* Go through the using directives. If any of them add new
3382 names to the namespace we're searching in, see if we can find a
3383 match by applying them. */
3385 @@ -346,39 +465,74 @@ cp_lookup_symbol_namespace (const char *namespace,
3387 current = current->next)
3389 - if (strcmp (namespace, current->import_dest) == 0)
3391 + /* If the import destination is the current scope or one of its ancestors then
3392 + it is applicable. */
3393 + directive_match = search_parents ?
3394 + strncmp (scope, current->import_dest,
3395 + strlen(current->import_dest)) == 0 :
3396 + strcmp (scope, current->import_dest) == 0;
3398 + if (directive_match &&
3399 + current->line_number < current_line &&
3400 + !current->searched)
3402 - sym = cp_lookup_symbol_namespace (current->import_src,
3407 + current->searched = 1;
3408 + /* If there is an import of a single declaration, compare the imported
3409 + declaration with the sought out name. If there is a match pass
3410 + current->import_src as NAMESPACE to direct the search towards the
3411 + imported namespace. */
3412 + if (strcmp ("", current->declaration) != 0)
3414 + if (strcmp (name, current->declaration) == 0)
3416 + sym = cp_lookup_symbol_in_namespace (current->import_src,
3423 + if (declaration_only)
3425 + current->searched = 0;
3434 + if (strcmp (name, current->alias) == 0)
3435 + /* If the import is creating an alias and the alias matches the
3436 + sought name. Pass current->inner as the NAME to direct the
3437 + search towards the aliased namespace */
3439 + sym = cp_lookup_symbol_in_namespace (scope,
3440 + current->import_src,
3443 + } else if (strcmp ("", current->alias) == 0){
3444 + /* If this import statement creates no alias, pass current->inner as
3445 + NAMESPACE to direct the search towards the imported namespace. */
3446 + sym = cp_lookup_symbol_imports (current->import_src,
3454 + current->searched = 0;
3463 - /* We didn't find anything by applying any of the using directives
3464 - that are still applicable; so let's see if we've got a match
3465 - using the current namespace. */
3467 - if (namespace[0] == '\0')
3469 - return lookup_symbol_file (name, linkage_name, block,
3474 - char *concatenated_name
3475 - = alloca (strlen (namespace) + 2 + strlen (name) + 1);
3476 - strcpy (concatenated_name, namespace);
3477 - strcat (concatenated_name, "::");
3478 - strcat (concatenated_name, name);
3479 - sym = lookup_symbol_file (concatenated_name, linkage_name,
3481 - cp_is_anonymous (namespace));
3487 /* Look up NAME in BLOCK's static block and in global blocks. If
3488 @@ -388,17 +542,15 @@ cp_lookup_symbol_namespace (const char *namespace,
3490 static struct symbol *
3491 lookup_symbol_file (const char *name,
3492 - const char *linkage_name,
3493 const struct block *block,
3494 const domain_enum domain,
3495 int anonymous_namespace)
3497 struct symbol *sym = NULL;
3499 - sym = lookup_symbol_static (name, linkage_name, block, domain);
3500 + sym = lookup_symbol_static (name, block, domain);
3504 if (anonymous_namespace)
3506 /* Symbols defined in anonymous namespaces have external linkage
3507 @@ -408,12 +560,11 @@ lookup_symbol_file (const char *name,
3508 const struct block *global_block = block_global_block (block);
3510 if (global_block != NULL)
3511 - sym = lookup_symbol_aux_block (name, linkage_name, global_block,
3513 + sym = lookup_symbol_aux_block (name, global_block, domain);
3517 - sym = lookup_symbol_global (name, linkage_name, block, domain);
3518 + sym = lookup_symbol_global (name, block, domain);
3522 @@ -434,6 +585,7 @@ lookup_symbol_file (const char *name,
3523 sym = lookup_possible_namespace_symbol (name);
3530 @@ -461,9 +613,8 @@ cp_lookup_nested_type (struct type *parent_type,
3531 lookup_symbol_namespace works when looking them up. */
3533 const char *parent_name = TYPE_TAG_NAME (parent_type);
3534 - struct symbol *sym = cp_lookup_symbol_namespace (parent_name,
3535 + struct symbol *sym = cp_lookup_symbol_in_namespace (parent_name,
3540 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
3541 @@ -709,7 +860,7 @@ check_one_possible_namespace_symbol (const char *name, int len,
3543 memcpy (name_copy, name, len);
3544 name_copy[len] = '\0';
3545 - sym = lookup_block_symbol (block, name_copy, NULL, VAR_DOMAIN);
3546 + sym = lookup_block_symbol (block, name_copy, VAR_DOMAIN);
3550 @@ -749,7 +900,7 @@ lookup_possible_namespace_symbol (const char *name)
3553 sym = lookup_block_symbol (get_possible_namespace_block (objfile),
3554 - name, NULL, VAR_DOMAIN);
3555 + name, VAR_DOMAIN);
3559 diff --git a/gdb/cp-support.c b/gdb/cp-support.c
3560 index f12d785..23b34c1 100644
3561 --- a/gdb/cp-support.c
3562 +++ b/gdb/cp-support.c
3565 #include "complaints.h"
3566 #include "gdbtypes.h"
3567 +#include "exceptions.h"
3568 +#include "expression.h"
3571 #include "safe-ctype.h"
3573 @@ -70,6 +73,18 @@ struct cmd_list_element *maint_cplus_cmd_list = NULL;
3574 static void maint_cplus_command (char *arg, int from_tty);
3575 static void first_component_command (char *arg, int from_tty);
3577 +/* Operator validation.
3578 + NOTE: Multi-byte operators (usually the assignment variety operator)
3579 + must appear before the single byte version, i.e., "+=" before "+". */
3580 +static const char *operator_tokens[] =
3582 + "++", "+=", "+", "->*", "->", "--", "-=", "-", "*=", "*", "/=", "/",
3583 + "%=", "%", "!=", "==", "!", "&&", "<<=", "<<", ">>=", ">>",
3584 + "<=", "<", ">=", ">", "~", "&=", "&", "|=", "||", "|", "^=", "^",
3585 + "=", "()", "[]", ",", "new", "delete"
3586 + /* new[] and delete[] require special whitespace handling */
3589 /* Return 1 if STRING is clearly already in canonical form. This
3590 function is conservative; things which it does not recognize are
3591 assumed to be non-canonical, and the parser will sort them out
3592 @@ -175,7 +190,8 @@ mangled_name_to_comp (const char *mangled_name, int options,
3596 -/* Return the name of the class containing method PHYSNAME. */
3597 +/* Return the name of the class or namespace containing
3598 + function, method, or variable PHYSNAME. */
3601 cp_class_name_from_physname (const char *physname)
3602 @@ -825,9 +841,9 @@ read_in_psymtabs (const char *func_name)
3606 - if ((lookup_partial_symbol (ps, func_name, NULL, 1, VAR_DOMAIN)
3607 + if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
3609 - || (lookup_partial_symbol (ps, func_name, NULL, 0, VAR_DOMAIN)
3610 + || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
3612 psymtab_to_symtab (ps);
3614 @@ -909,6 +925,107 @@ first_component_command (char *arg, int from_tty)
3616 extern initialize_file_ftype _initialize_cp_support; /* -Wmissing-prototypes */
3618 +#define SKIP_SPACE(P) \
3621 + while (*(P) == ' ' || *(P) == '\t') \
3626 +/* Returns the length of the operator name or 0 if INPUT does not
3627 + point to a valid C++ operator. INPUT should start with "operator". */
3629 +cp_validate_operator (const char *input)
3634 + struct expression *expr;
3635 + struct value *val;
3636 + struct gdb_exception except;
3637 + struct cleanup *old_chain;
3641 + if (strncmp (p, "operator", 8) == 0)
3647 + for (i = 0; i < sizeof (operator_tokens) / sizeof (operator_tokens[0]);
3650 + int length = strlen (operator_tokens[i]);
3651 + /* By using strncmp here, we MUST have operator_tokens ordered!
3652 + See additional notes where operator_tokens is defined above. */
3653 + if (strncmp (p, operator_tokens[i], length) == 0)
3655 + const char *op = p;
3659 + if (strncmp (op, "new", 3) == 0
3660 + || strncmp (op, "delete", 6) == 0)
3663 + /* Special case: new[] and delete[]. We must be careful
3664 + to swallow whitespace before/in "[]". */
3679 + return (p - input);
3683 + /* Check input for a conversion operator. */
3685 + /* Skip past base typename */
3686 + while (*p != '*' && *p != '&' && *p != 0 && *p != ' ')
3690 + /* Add modifiers '*'/'&' */
3691 + while (*p == '*' || *p == '&')
3697 + /* Check for valid type. [Remember: input starts with
3699 + copy = savestring (input + 8, p - input - 8);
3702 + TRY_CATCH (except, RETURN_MASK_ALL)
3704 + expr = parse_expression (copy);
3705 + val = evaluate_type (expr);
3712 + if (val != NULL && value_type (val) != NULL)
3713 + return (p - input);
3720 _initialize_cp_support (void)
3722 diff --git a/gdb/cp-support.h b/gdb/cp-support.h
3723 index b5a5c5f..3f48f98 100644
3724 --- a/gdb/cp-support.h
3725 +++ b/gdb/cp-support.h
3726 @@ -38,15 +38,33 @@ struct demangle_component;
3728 /* This struct is designed to store data from using directives. It
3729 says that names from namespace IMPORT_SRC should be visible within
3730 - namespace IMPORT_DEST. IMPORT_DEST should always be a strict initial
3731 - substring of IMPORT_SRC. These form a linked list; NEXT is the next element
3733 + namespace IMPORT_DEST. IMPORT_DEST should always be a strict initial
3734 + substring of IMPORT_SRC. These form a linked list; NEXT is the next
3735 + element of the list. ALIAS is set to a non empty string if the imported
3736 + namespace has been aliased.Eg:
3739 + DECLARATION is the name of the imported declaration, if this import
3740 + statement represents one. Eg:
3742 + Where x is variable in namespace A. declaration is set to x.
3752 + char *declaration;
3756 struct using_direct *next;
3758 + /* Used during import search to temporarly mark this node as searced. */
3763 @@ -54,6 +72,7 @@ struct using_direct
3765 extern char *cp_canonicalize_string (const char *string);
3768 extern char *cp_class_name_from_physname (const char *physname);
3770 extern char *method_name_from_physname (const char *physname);
3771 @@ -72,15 +91,23 @@ extern struct symbol **make_symbol_overload_list (const char *,
3772 extern struct type *cp_lookup_rtti_type (const char *name,
3773 struct block *block);
3775 +extern int cp_validate_operator (const char *input);
3777 /* Functions/variables from cp-namespace.c. */
3779 extern int cp_is_anonymous (const char *namespace);
3781 extern void cp_add_using_directive (const char *dest,
3784 + const char *alias,
3785 + const char *declaration,
3786 + const int line_number);
3788 extern struct using_direct *cp_add_using (const char *dest,
3790 + const char *alias,
3791 + const char *declaration,
3792 + const int line_number,
3793 struct using_direct *next);
3795 extern void cp_initialize_namespace (void);
3796 @@ -97,15 +124,20 @@ extern void cp_set_block_scope (const struct symbol *symbol,
3797 extern void cp_scan_for_anonymous_namespaces (const struct symbol *symbol);
3799 extern struct symbol *cp_lookup_symbol_nonlocal (const char *name,
3800 - const char *linkage_name,
3801 const struct block *block,
3802 const domain_enum domain);
3804 +struct symbol *cp_lookup_symbol_imports (const char *scope,
3806 + const struct block *block,
3807 + const domain_enum domain,
3808 + int declaration_only,
3809 + int search_parents);
3811 extern struct symbol *cp_lookup_symbol_namespace (const char *namespace,
3813 - const char *linkage_name,
3814 - const struct block *block,
3815 - const domain_enum domain);
3817 + const struct block *block,
3818 + const domain_enum domain);
3820 extern struct type *cp_lookup_nested_type (struct type *parent_type,
3821 const char *nested_name,
3822 diff --git a/gdb/dbxread.c b/gdb/dbxread.c
3823 index 7cb016d..bb9e35a 100644
3826 @@ -3581,6 +3581,7 @@ static struct sym_fns aout_sym_fns =
3827 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
3828 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3829 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
3830 + NULL, /* sym_read_psymbols */
3831 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
3832 default_symfile_offsets, /* sym_offsets: parse user's offsets to
3834 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
3835 index f16b6e2..fe328c7 100644
3836 --- a/gdb/doc/gdb.texinfo
3837 +++ b/gdb/doc/gdb.texinfo
3838 @@ -959,8 +959,10 @@ Connect to process ID @var{number}, as with the @code{attach} command.
3839 @itemx -x @var{file}
3840 @cindex @code{--command}
3842 -Execute @value{GDBN} commands from file @var{file}. @xref{Command
3843 -Files,, Command files}.
3844 +Execute commands from file @var{file}. If @var{file} ends in
3845 +@samp{.py}, then the file is evaluated as Python code. If Python
3846 +support is not enabled in this @value{GDBN}, then an error occurs.
3847 +@xref{Command Files,, Command files}.
3849 @item -eval-command @var{command}
3850 @itemx -ex @var{command}
3851 @@ -1152,6 +1154,16 @@ for remote debugging.
3852 Run using @var{device} for your program's standard input and output.
3853 @c FIXME: kingdon thinks there is more to -tty. Investigate.
3858 +@cindex @code{--python}
3859 +Change interpretation of command line so that the argument immediately
3860 +following this switch is taken to be the name of a Python script file.
3861 +This option stops option processing; subsequent options are passed to
3862 +Python as @code{sys.argv}. This option is only available if Python
3863 +scripting support was enabled when @value{GDBN} was configured.
3865 @c resolve the situation of these eventually
3867 @cindex @code{--tui}
3868 @@ -18650,7 +18662,7 @@ command:
3871 @cindex execute commands from a file
3872 -@item source [@code{-v}] @var{filename}
3873 +@item source [@code{-v}] [@code{-p}] @var{filename}
3874 Execute the command file @var{filename}.
3877 @@ -18667,6 +18679,11 @@ If @code{-v}, for verbose mode, is given then @value{GDBN} displays
3878 each command as it is executed. The option must be given before
3879 @var{filename}, and is interpreted as part of the filename anywhere else.
3881 +If @var{filename} ends in @samp{.py}, or if @code{-p}, for Python, is
3882 +given then @value{GDBN} evaluates the contents of the file as Python
3883 +code. If Python support is not compiled in to @value{GDBN}, then an
3886 Commands that would ask for confirmation if used interactively proceed
3887 without asking when used in a command file. Many @value{GDBN} commands that
3888 normally print messages to say what they are doing omit the messages
3889 @@ -18928,8 +18945,6 @@ containing @code{end}. For example:
3892 (@value{GDBP}) python
3894 -End with a line saying just "end".
3898 @@ -18942,6 +18957,14 @@ in a Python script. This can be controlled using @code{maint set
3899 python print-stack}: if @code{on}, the default, then Python stack
3900 printing is enabled; if @code{off}, then Python stack printing is
3903 +@kindex maint set python auto-load
3904 +@item maint set python auto-load
3905 +By default, @value{GDBN} will attempt to automatically load Python
3906 +code when an object file is opened. This can be controlled using
3907 +@code{maint set python auto-load}: if @code{on}, the default, then
3908 +Python auto-loading is enabled; if @code{off}, then Python
3909 +auto-loading is disabled.
3913 @@ -18949,6 +18972,14 @@ disabled.
3915 @cindex programming in python
3917 +You can get quick online help for @value{GDBN}'s Python API by issuing
3918 +the command @w{@kbd{python help (gdb)}}.
3920 +Functions and methods which have two or more optional arguments allow
3921 +them to be specified using keyword syntax. This allows passing some
3922 +optional arguments while skipping others. Example:
3923 +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
3925 @cindex python stdout
3926 @cindex python pagination
3927 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
3928 @@ -18961,13 +18992,17 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
3929 * Basic Python:: Basic Python Functions.
3930 * Exception Handling::
3931 * Auto-loading:: Automatically loading Python code.
3932 -* Values From Inferior::
3933 +* Values From Inferior:: Python representation of values.
3934 * Types In Python:: Python representation of types.
3935 * Pretty Printing:: Pretty-printing values.
3936 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
3937 +* Inferiors In Python:: Python representation of inferiors (processes)
3938 +* Threads In Python:: Accessing inferior threads from Python.
3939 * Commands In Python:: Implementing new commands in Python.
3940 +* Parameters In Python:: Adding new @value{GDBN} parameters.
3941 * Functions In Python:: Writing new convenience functions.
3942 * Objfiles In Python:: Object files.
3943 +* Breakpoints In Python:: Manipulating breakpoints using Python.
3944 * Frames In Python:: Acessing inferior stack frames from Python.
3947 @@ -18994,6 +19029,12 @@ command as having originated from the user invoking it interactively.
3948 It must be a boolean value. If omitted, it defaults to @code{False}.
3951 +@findex gdb.breakpoints
3953 +Return a sequence holding all of @value{GDBN}'s breakpoints.
3954 +@xref{Breakpoints In Python}, for more information.
3957 @findex gdb.parameter
3958 @defun parameter parameter
3959 Return the value of a @value{GDBN} parameter. @var{parameter} is a
3960 @@ -19010,6 +19051,7 @@ a Python value of the appropriate type, and returned.
3961 @defun history number
3962 Return a value from @value{GDBN}'s value history (@pxref{Value
3963 History}). @var{number} indicates which history element to return.
3965 If @var{number} is negative, then @value{GDBN} will take its absolute value
3966 and count backward from the last element (i.e., the most recent element) to
3967 find the value to return. If @var{number} is zero, then @value{GDBN} will
3968 @@ -19021,6 +19063,28 @@ If no exception is raised, the return value is always an instance of
3969 @code{gdb.Value} (@pxref{Values From Inferior}).
3972 +@findex gdb.parse_and_eval
3973 +@defun parse_and_eval expression
3974 +Parse @var{expression} as an expression in the current language,
3975 +evaluate it, and return the result as a @code{gdb.Value}.
3976 +@var{expression} must be a string.
3979 +@findex gdb.post_event
3980 +@defun post_event event
3981 +Put @var{event}, a callable object taking no arguments, into
3982 +@value{GDBN}'s internal event queue. This callable will be invoked at
3983 +some later point, during @value{GDBN}'s event processing. Events
3984 +posted using @code{post_event} will be run in the order in which they
3985 +were posted; however, there is no way to know when they will be
3986 +processed relative to other events inside @value{GDBN}.
3988 +@value{GDBN} is not thread-safe. If your Python program uses multiple
3989 +threads, you must be careful to only call @value{GDBN}-specific
3990 +functions in the main @value{GDBN} thread. @code{post_event} ensures
3996 Print a string to @value{GDBN}'s paginated standard output stream.
3997 @@ -19035,6 +19099,11 @@ Flush @value{GDBN}'s paginated standard output stream. Flushing
4001 +@findex gdb.solib_address
4002 +@defun solib_address @var{address}
4003 +Return the name of the shared library holding the given address, or None.
4006 @node Exception Handling
4007 @subsubsection Exception Handling
4008 @cindex python exceptions
4009 @@ -19171,6 +19240,13 @@ The type of this @code{gdb.Value}. The value of this attribute is a
4010 The following methods are provided:
4013 +@defmethod Value cast type
4014 +Cast the @code{gdb.Value} to the type represented by @var{type}, and
4015 +return a new @code{gdb.Value}. @var{type} must be a @code{gdb.Type}
4016 +object. If the cast cannot be performed for some reason, an exception
4020 @defmethod Value dereference
4021 For pointer data types, this method returns a new @code{gdb.Value} object
4022 whose contents is the object pointed to by the pointer. For example, if
4023 @@ -19242,6 +19318,9 @@ module:
4024 This function looks up a type by name. @var{name} is the name of the
4025 type to look up. It must be a string.
4027 +If @var{block} is given, then @var{name} is looked up in that scope.
4028 +Otherwise, it is searched for globally.
4030 Ordinarily, this function will return an instance of @code{gdb.Type}.
4031 If the named type cannot be found, it will throw an exception.
4033 @@ -19294,6 +19373,12 @@ This is @code{True} if the field is artificial, usually meaning that
4034 it was provided by the compiler and not the user. This attribute is
4035 always provided, and is @code{False} if the field is not artificial.
4037 +@item is_base_class
4038 +This is @code{True} if the field represents a base class of a C@t{++}
4039 +structure. This attribute is always provided, and is @code{False}
4040 +if the field is not a base class of the type on which @code{fields} was
4041 +called, or if that type was not a C@t{++} class.
4044 If the field is packed, or is a bitfield, then this will have a
4045 non-zero value, which is the size of the field in bits. Otherwise,
4046 @@ -19346,7 +19431,7 @@ If the type does not have a target, this method will throw an
4050 -@defmethod Type template_argument n
4051 +@defmethod Type template_argument n [block]
4052 If this @code{gdb.Type} is an instantiation of a template, this will
4053 return a new @code{gdb.Type} which represents the type of the
4054 @var{n}th template argument.
4055 @@ -19354,7 +19439,8 @@ return a new @code{gdb.Type} which represents the type of the
4056 If this @code{gdb.Type} is not a template type, this will throw an
4057 exception. Ordinarily, only C@t{++} code will have template types.
4059 -@var{name} is searched for globally.
4060 +If @var{block} is given, then @var{name} is looked up in that scope.
4061 +Otherwise, it is searched for globally.
4065 @@ -19708,6 +19794,121 @@ import gdb.libstdcxx.v6
4066 gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
4069 +@node Inferiors In Python
4070 +@subsubsection Inferiors In Python
4072 +Programs which are being run under @value{GDBN} are called inferiors
4073 +(@pxref{Inferiors}). Python scripts can access information about and
4074 +manipulate inferiors controlled by @value{GDBN} via objects of the
4075 +@code{gdb.Inferior} class.
4077 +The following inferior-related functions are available in the @code{gdb}
4081 +Return a tuple containing all inferior objects.
4084 +A @code{gdb.Inferior} object has the following attributes:
4087 +@defivar Inferior num
4088 +ID of inferior, as assigned by GDB.
4091 +@defivar Inferior pid
4092 +Process ID of the inferior, assigned by the underlying OS.
4095 +@defivar Inferior was_attached
4096 +Boolean signaling whether the inferior was created using `attach', or
4097 +started by @value{GDBN} itself.
4101 +A @code{gdb.Inferior} object has the following methods:
4104 +@defmethod Inferior threads
4105 +This method returns a tuple holding all the threads which are valid
4106 +when it is called. If there are no valid threads, the method will
4107 +return an empty list.
4110 +@findex gdb.read_memory
4111 +@defmethod Inferior read_memory @var{address} @var{length}
4112 +Read @var{length} bytes of memory from the inferior, starting at
4113 +@var{address}. Returns a buffer object, which behaves much like an array
4114 +or a string. It can be modified and given to the @code{gdb.write_memory}
4118 +@findex gdb.write_memory
4119 +@defmethod Inferior write_memory @var{address} @var{buffer} @r{[}@var{length}@r{]}
4120 +Write the contents of @var{buffer} (a Python object which supports the
4121 +buffer protocol, i.e., a string, an array or the object returned from
4122 +@code{gdb.read_memory}) to the inferior, starting at @var{address}.
4123 +If given, @var{length} determines the number of bytes from @var{buffer} to
4127 +@findex gdb.search_memory
4128 +@defmethod Inferior search_memory @var{address} @var{length} @var{pattern} @r{[}@var{size}@r{]} @r{[}@var{max_count}@r{]}
4129 +Search a region of the inferior memory starting at @var{address} with the
4130 +given @var{length}. @var{pattern} can be a string, a byte array, a buffer
4131 +object, a number, a @code{gdb.Value} object (@pxref{Values From Inferior})
4132 +or a list or tuple with elements in any combination of those types. If
4133 +@var{size} is given and is non-zero, it specifies the size in bytes of a
4134 +Python scalar or @code{gdb.Value} in the search pattern. If @var{size} is
4135 +zero or not specified, it is taken from the value's type in the current
4136 +language. This is useful when one wants to specify the search pattern as
4137 +a mixture of types. Note that this means, for example, that in the case of
4138 +C-like languages a search for an untyped 0x42 will search for
4139 +@samp{(int) 0x42} which is typically four bytes. @var{max_count} is the
4140 +highest number of matches to search for.
4144 +@node Threads In Python
4145 +@subsubsection Threads In Python
4147 +Python scripts can access information about and manipulate inferior threads
4148 +controlled by @value{GDBN} via objects of the @code{gdb.InferiorThread} class.
4150 +The following inferior-related functions are available in the @code{gdb}
4153 +@findex gdb.selected_thread
4154 +@defun selected_thread
4155 +This function returns the thread object for the selected thread. If there
4156 +is no selected thread, this will return @code{None}.
4159 +A @code{gdb.InferiorThread} object has the following attributes:
4162 +@defivar InferiorThread num
4163 +ID of the thread, as assigned by GDB.
4167 +A @code{gdb.InferiorThread} object has the following methods:
4170 +@defmethod InferiorThread frames
4171 +Return a tuple containing all frames in the thread.
4174 +@defmethod InferiorThread newest_frame
4175 +Return the newest frame thread's stack.
4178 +@defmethod InferiorThread switch_to_thread
4179 +This changes @value{GDBN}'s currently selected thread to the one represented
4184 @node Commands In Python
4185 @subsubsection Commands In Python
4187 @@ -19960,6 +20161,135 @@ registration of the command with @value{GDBN}. Depending on how the
4188 Python code is read into @value{GDBN}, you may need to import the
4189 @code{gdb} module explicitly.
4191 +@node Parameters In Python
4192 +@subsubsection Parameters In Python
4194 +@cindex parameters in python
4195 +@cindex python parameters
4196 +@tindex gdb.Parameter
4198 +You can implement new @value{GDBN} parameters using Python. A new
4199 +parameter is implemented as an instance of the @code{gdb.Parameter}
4200 +class. Parameters are exposed to the user via the @code{set} and
4201 +@code{show} commands.
4203 +@defmethod Parameter __init__ name @var{command-class} @var{parameter-class} @r{[}@var{enum-sequence}@r{]}
4204 +The object initializer for @code{Parameter} registers the new
4205 +parameter with @value{GDBN}. This initializer is normally invoked
4206 +from the subclass' own @code{__init__} method.
4208 +@var{name} is the name of the new parameter. If @var{name} consists
4209 +of multiple words, then the initial words are looked for as prefix
4210 +commands. In this case, if one of the prefix commands does not exist,
4211 +an exception is raised.
4213 +@var{command-class} should be one of the @samp{COMMAND_} constants
4214 +(@pxref{Commands In Python}). This argument tells @value{GDBN} how to
4215 +categorize the new parameter in the help system.
4217 +@var{parameter-class} should be one of the @samp{PARAM_} constants
4218 +defined below. This argument tells @value{GDBN} the type of the new
4219 +parameter; this information is used for input validation and
4222 +If @var{parameter-class} is @code{PARAM_ENUM}, then
4223 +@var{enum-sequence} must be a sequence of strings. These strings
4224 +represent the possible values for the parameter.
4226 +If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
4227 +of a fourth argument will cause an exception to be thrown.
4229 +The help text for the new parameter is taken from the Python
4230 +documentation string for the parameter's class, if there is one. If
4231 +there is no documentation string, a default value is used.
4234 +@defivar Parameter set_doc
4235 +If this attribute exists, and is a string, then its value is used as
4236 +the help text for this parameter's @code{set} command. The value is
4237 +examined when @code{Parameter.__init__} is invoked; subsequent changes
4241 +@defivar Parameter show_doc
4242 +If this attribute exists, and is a string, then its value is used as
4243 +the help text for this parameter's @code{show} command. The value is
4244 +examined when @code{Parameter.__init__} is invoked; subsequent changes
4248 +@defivar Parameter value
4249 +The @code{value} attribute holds the underlying value of the
4250 +parameter. It can be read and assigned to just as any other
4251 +attribute. @value{GDBN} does validation when assignments are made.
4255 +When a new parameter is defined, its type must be specified. The
4256 +available types are represented by constants defined in the @code{gdb}
4260 +@findex PARAM_BOOLEAN
4261 +@findex gdb.PARAM_BOOLEAN
4262 +@item PARAM_BOOLEAN
4263 +The value is a plain boolean. The Python boolean values, @code{True}
4264 +and @code{False} are the only valid values.
4266 +@findex PARAM_AUTO_BOOLEAN
4267 +@findex gdb.PARAM_AUTO_BOOLEAN
4268 +@item PARAM_AUTO_BOOLEAN
4269 +The value has three possible states: true, false, and @samp{auto}. In
4270 +Python, true and false are represented using boolean constants, and
4271 +@samp{auto} is represented using @code{None}.
4273 +@findex PARAM_UINTEGER
4274 +@findex gdb.PARAM_UINTEGER
4275 +@item PARAM_UINTEGER
4276 +The value is an unsigned integer. The value of 0 should be
4277 +interpreted to mean ``unlimited''.
4279 +@findex PARAM_INTEGER
4280 +@findex gdb.PARAM_INTEGER
4281 +@item PARAM_INTEGER
4282 +The value is a signed integer. The value of 0 should be interpreted
4283 +to mean ``unlimited''.
4285 +@findex PARAM_STRING
4286 +@findex gdb.PARAM_STRING
4288 +The value is a string. When the user modifies the string, escapes are
4291 +@findex PARAM_STRING_NOESCAPE
4292 +@findex gdb.PARAM_STRING_NOESCAPE
4293 +@item PARAM_STRING_NOESCAPE
4294 +The value is a string. When the user modifies the string, escapes are
4295 +passed through untranslated.
4297 +@findex PARAM_OPTIONAL_FILENAME
4298 +@findex gdb.PARAM_OPTIONAL_FILENAME
4299 +@item PARAM_OPTIONAL_FILENAME
4300 +The value is a either a filename (a string), or @code{None}.
4302 +@findex PARAM_FILENAME
4303 +@findex gdb.PARAM_FILENAME
4304 +@item PARAM_FILENAME
4305 +The value is a filename (a string).
4307 +@findex PARAM_ZINTEGER
4308 +@findex gdb.PARAM_ZINTEGER
4309 +@item PARAM_ZINTEGER
4310 +The value is an integer. This is like @code{PARAM_INTEGER}, except 0
4311 +is interpreted as itself.
4314 +@findex gdb.PARAM_ENUM
4316 +The value is a string, which must be one of a collection string
4317 +constants provided when the parameter is created.
4320 @node Functions In Python
4321 @subsubsection Writing new convenience functions
4323 @@ -20064,6 +20394,82 @@ which is used to format the value. @xref{Pretty Printing}, for more
4327 +@node Breakpoints In Python
4328 +@subsubsection Manipulating breakpoints using Python
4330 +@cindex breakpoints in python
4331 +@cindex python breakpoints
4332 +@tindex gdb.Breakpoint
4334 +Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
4337 +@defmethod Breakpoint __init__ location
4338 +Create a new breakpoint. @var{location} is a string naming the
4339 +location of the breakpoint. The contents can be any location
4340 +recognized by the @code{break} command.
4343 +@defmethod Breakpoint is_valid
4344 +Return @code{True} if this @code{Breakpoint} object is valid,
4345 +@code{False} otherwise. A @code{Breakpoint} object can become invalid
4346 +if the user deletes the breakpoint. In this case, the object still
4347 +exists, but the underlying breakpoint does not.
4350 +@defivar Breakpoint enabled
4351 +This attribute is @code{True} if the breakpoint is enabled, and
4352 +@code{False} otherwise. This attribute is writable.
4355 +@defivar Breakpoint silent
4356 +This attribute is @code{True} if the breakpoint is silent, and
4357 +@code{False} otherwise. This attribute is writable.
4359 +Note that a breakpoint can also be silent if it has commands and the
4360 +first command is @code{silent}. This is not reported by the
4361 +@code{silent} attribute.
4364 +@defivar Breakpoint thread
4365 +If the breakpoint is thread-specific, this attribute holds the thread
4366 +id. If the breakpoint is not thread-specific, this attribute is
4367 +@code{None}. This attribute is writable.
4370 +@defivar Breakpoint ignore_count
4371 +This attribute holds the ignore count for the breakpoint, an integer.
4372 +This attribute is writable.
4375 +@defivar Breakpoint number
4376 +This attribute holds the breakpoint's number -- the identifier used by
4377 +the user to manipulate the breakpoint. This attribute is not writable.
4380 +@defivar Breakpoint hit_count
4381 +This attribute holds the hit count for the breakpoint, an integer.
4382 +This attribute is writable, but currently it can only be set to zero.
4385 +@defivar Breakpoint location
4386 +This attribute holds the location of the breakpoint, as specified by
4387 +the user. It is a string. This attribute is not writable.
4390 +@defivar Breakpoint condition
4391 +This attribute holds the condition of the breakpoint, as specified by
4392 +the user. It is a string. If there is no condition, this attribute's
4393 +value is @code{None}. This attribute is writable.
4396 +@defivar Breakpoint commands
4397 +This attribute holds the commands attached to the breakpoint. If
4398 +there are commands, this returns a string holding all the commands,
4399 +separated by newlines. If there are no commands, this attribute is
4400 +@code{None}. This attribute is not writable.
4403 @node Frames In Python
4404 @subsubsection Acessing inferior stack frames from Python.
4406 @@ -20128,6 +20534,14 @@ function to a string.
4407 Returns the frame's resume address.
4410 +@defmethod Frame block
4411 +Returns the frame's code block. @c (@pxref{Block,,Code Blocks and Scopes}).
4414 +@defmethod Frame function
4415 +Returns the symbol for the function corresponding to this frame. @c (@pxref{Symbols In Python}).
4418 @defmethod Frame older
4419 Return the frame that called this frame.
4421 @@ -20136,10 +20550,18 @@ Return the frame that called this frame.
4422 Return the frame called by this frame.
4425 +@defmethod Frame find_sal
4426 +Return the frame's symtab and line object. @c (@pxref{Symtab_and_line,, Symtab and line}).
4429 @defmethod Frame read_var variable
4430 Return the value of the given variable in this frame. @var{variable} must
4434 +@defmethod Frame select
4435 +Set this frame to be the user's selected frame.
4440 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
4441 index c2be3f7..a7811ab 100644
4442 --- a/gdb/doc/gdbint.texinfo
4443 +++ b/gdb/doc/gdbint.texinfo
4444 @@ -2114,6 +2114,18 @@ time, and so we attempt to handle symbols incrementally. For instance,
4445 we create @dfn{partial symbol tables} consisting of only selected
4446 symbols, and only expand them to full symbol tables when necessary.
4450 +* Partial Symbol Tables::
4452 +* Object File Formats::
4453 +* Debugging File Formats::
4454 +* Adding a New Symbol Reader to GDB::
4455 +* Memory Management for Symbol Files::
4456 +* Memory Management for Types::
4459 +@node Symbol Reading
4460 @section Symbol Reading
4462 @cindex symbol reading
4463 @@ -2206,6 +2218,7 @@ symtab. Upon return, @code{pst->readin} should have been set to 1, and
4464 zero if there were no symbols in that part of the symbol file.
4467 +@node Partial Symbol Tables
4468 @section Partial Symbol Tables
4470 @value{GDBN} has three types of symbol tables:
4471 @@ -2301,6 +2314,7 @@ and all the psymbols themselves are allocated in a pair of large arrays
4472 on an obstack, so there is little to be gained by trying to free them
4473 unless you want to do a lot more work.
4478 @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
4479 @@ -2323,6 +2337,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
4480 other members of the type struct, such as whether the type is signed
4481 or unsigned, and how many bits it uses.
4483 +@anchor{Builtin Types}
4484 @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
4486 These are instances of type structs that roughly correspond to
4487 @@ -2337,6 +2352,7 @@ only one instance exists, while @file{c-lang.c} builds as many
4488 @code{TYPE_CODE_INT} types as needed, with each one associated with
4489 some particular objfile.
4491 +@node Object File Formats
4492 @section Object File Formats
4493 @cindex object file formats
4495 @@ -2422,6 +2438,7 @@ SOM, which is a cross-language ABI).
4497 The SOM reader is in @file{somread.c}.
4499 +@node Debugging File Formats
4500 @section Debugging File Formats
4502 This section describes characteristics of debugging information that
4503 @@ -2493,6 +2510,7 @@ DWARF 3 is an improved version of DWARF 2.
4504 @cindex SOM debugging info
4505 Like COFF, the SOM definition includes debugging information.
4507 +@node Adding a New Symbol Reader to GDB
4508 @section Adding a New Symbol Reader to @value{GDBN}
4510 @cindex adding debugging info reader
4511 @@ -2515,6 +2533,7 @@ will only ever be implemented by one object file format may be called
4512 directly. This interface should be described in a file
4513 @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
4515 +@node Memory Management for Symbol Files
4516 @section Memory Management for Symbol Files
4518 Most memory associated with a loaded symbol file is stored on
4519 @@ -2526,10 +2545,45 @@ released when the objfile is unloaded or reloaded. Therefore one
4520 objfile must not reference symbol or type data from another objfile;
4521 they could be unloaded at different times.
4523 -User convenience variables, et cetera, have associated types. Normally
4524 -these types live in the associated objfile. However, when the objfile
4525 -is unloaded, those types are deep copied to global memory, so that
4526 -the values of the user variables and history items are not lost.
4527 +@node Memory Management for Types
4528 +@section Memory Management for Types
4529 +@cindex memory management for types
4531 +@findex TYPE_OBJFILE
4532 +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
4533 +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
4534 +obstack) and in such case the type remains valid till the objfile is unloaded
4535 +or reloaded. For such types with an associated objfile no reference counting
4538 +User convenience variables, et cetera, have associated types. Normally these
4539 +types live in the associated objfile. However, when the objfile is unloaded,
4540 +those types are deep copied to global memory, so that the values of the user
4541 +variables and history items are not lost. During the copy they will get their
4542 +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
4545 +Types with null @code{TYPE_OBJFILE} can be either permanent types
4546 +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
4547 +first idle @value{GDBN} moment if the last object referencing them is removed.
4548 +Permanent types are allocated by the function @code{alloc_type} (and its
4549 +derivations like @code{init_type}) specifying objfile as @code{NULL}. The
4550 +reclaimable types are created the same way but moreover they need to have
4551 +@code{type_init_group} called to start their tracking as being possibly
4554 +@findex free_all_types
4555 +When @value{GDBN} gets idle it always calls the @code{free_all_types} function
4556 +which deallocates any unused types. All types currently not owned by an
4557 +objfile must be marked as used on each @code{free_all_types} call as they would
4558 +get deallocated as unused otherwise.
4560 +@code{free_all_types} automatically checks for any cross-type references such
4561 +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
4562 +prevents early deallocation for any such existing references. Reclaimable
4563 +types may reference any other reclaimable types or even permanent types. But
4564 +permanent types must not reference reclaimable types (nor an objfile associated
4568 @node Language Support
4569 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
4570 index 4984f31..fcf1b5d 100644
4571 --- a/gdb/doc/observer.texi
4572 +++ b/gdb/doc/observer.texi
4573 @@ -206,6 +206,11 @@ Either @value{GDBN} detached from the inferior, or the inferior
4574 exited. The argument @var{pid} identifies the inferior.
4577 +@deftypefun void mark_used (void)
4578 +Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
4579 +collector pass. Currently only @code{type_mark_used} marker is supported.
4582 @deftypefun void test_notification (int @var{somearg})
4583 This observer is used for internal testing. Do not use.
4584 See testsuite/gdb.gdb/observer.exp.
4585 diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
4586 index 668c434..c29c3a5 100644
4587 --- a/gdb/dwarf2-frame.c
4588 +++ b/gdb/dwarf2-frame.c
4591 #include "complaints.h"
4592 #include "dwarf2-frame.h"
4593 +#include "addrmap.h"
4597 @@ -1574,6 +1575,14 @@ dwarf2_frame_find_fde (CORE_ADDR *pc)
4601 + if (objfile->quick_addrmap)
4603 + if (!addrmap_find (objfile->quick_addrmap, *pc))
4606 + /* FIXME: Read-in only .debug_frame/.eh_frame without .debug_info? */
4607 + require_partial_symbols (objfile);
4609 fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
4610 if (fde_table == NULL)
4612 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
4613 index 46bc9d7..e675575 100644
4614 --- a/gdb/dwarf2expr.c
4615 +++ b/gdb/dwarf2expr.c
4616 @@ -848,6 +848,13 @@ execute_stack_op (struct dwarf_expr_context *ctx,
4617 ctx->initialized = 0;
4620 + case DW_OP_push_object_address:
4621 + if (ctx->get_object_address == NULL)
4622 + error (_("DWARF-2 expression error: DW_OP_push_object_address must "
4623 + "have a value to push."));
4624 + result = (ctx->get_object_address) (ctx->baton);
4628 error (_("Unhandled dwarf expression opcode 0x%x"), op);
4630 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
4631 index a9a8a05..d449012 100644
4632 --- a/gdb/dwarf2expr.h
4633 +++ b/gdb/dwarf2expr.h
4634 @@ -102,10 +102,10 @@ struct dwarf_expr_context
4635 The result must be live until the current expression evaluation
4637 unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length);
4640 /* Return the `object address' for DW_OP_push_object_address. */
4641 CORE_ADDR (*get_object_address) (void *baton);
4644 /* The current depth of dwarf expression recursion, via DW_OP_call*,
4645 DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
4646 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
4647 index 3a81202..85f4487 100644
4648 --- a/gdb/dwarf2loc.c
4649 +++ b/gdb/dwarf2loc.c
4650 @@ -116,6 +116,9 @@ struct dwarf_expr_baton
4652 struct frame_info *frame;
4653 struct objfile *objfile;
4654 + /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
4655 + DW_AT_data_location) for DW_OP_push_object_address. */
4656 + CORE_ADDR object_address;
4659 /* Helper functions for dwarf2_evaluate_loc_desc. */
4660 @@ -177,22 +180,33 @@ dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
4661 *start = find_location_expression (symbaton, length,
4662 get_frame_address_in_block (frame));
4665 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
4667 struct dwarf2_locexpr_baton *symbaton;
4669 symbaton = SYMBOL_LOCATION_BATON (framefunc);
4670 - if (symbaton != NULL)
4672 - *length = symbaton->size;
4673 - *start = symbaton->data;
4677 + gdb_assert (symbaton != NULL);
4678 + *start = symbaton->data;
4679 + *length = symbaton->size;
4681 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
4683 + struct dwarf2_locexpr_baton *symbaton;
4685 + symbaton = SYMBOL_LOCATION_BATON (framefunc);
4686 + gdb_assert (symbaton == NULL);
4688 + *length = 0; /* unused */
4691 + internal_error (__FILE__, __LINE__,
4692 + _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
4693 + SYMBOL_COMPUTED_OPS (framefunc),
4694 + SYMBOL_PRINT_NAME (framefunc));
4697 error (_("Could not find the frame base for \"%s\"."),
4698 - SYMBOL_NATURAL_NAME (framefunc));
4699 + SYMBOL_PRINT_NAME (framefunc));
4702 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
4703 @@ -215,6 +229,129 @@ dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
4704 return target_translate_tls_address (debaton->objfile, offset);
4708 +dwarf_expr_object_address (void *baton)
4710 + struct dwarf_expr_baton *debaton = baton;
4712 + /* The message is suppressed in DWARF_BLOCK_EXEC. */
4713 + if (debaton->object_address == 0)
4714 + error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
4716 + return debaton->object_address;
4719 +/* Address of the variable we are currently referring to. It is set from
4720 + DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
4721 + DW_OP_push_object_address. */
4723 +static CORE_ADDR object_address;
4725 +/* Callers use object_address_set while their callers use the result set so we
4726 + cannot run the cleanup at the local block of our direct caller. Still we
4727 + should reset OBJECT_ADDRESS at least for the next GDB command. */
4730 +object_address_cleanup (void *prev_save_voidp)
4732 + CORE_ADDR *prev_save = prev_save_voidp;
4734 + object_address = *prev_save;
4735 + xfree (prev_save);
4738 +/* Set the base address - DW_AT_location - of a variable. It is being later
4739 + used to derive other object addresses by DW_OP_push_object_address.
4741 + It would be useful to sanity check ADDRESS - such as for some objects with
4742 + unset value_raw_address - but some valid addresses may be zero (such as first
4743 + objects in relocatable .o files). */
4746 +object_address_set (CORE_ADDR address)
4748 + CORE_ADDR *prev_save;
4750 + prev_save = xmalloc (sizeof *prev_save);
4751 + *prev_save = object_address;
4752 + make_cleanup (object_address_cleanup, prev_save);
4754 + object_address = address;
4757 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
4758 + by dwarf_expr_fetch (RETVAL, 0). FRAME parameter can be NULL to call
4759 + get_selected_frame to find it. Returned dwarf_expr_context freeing is
4760 + pushed on the cleanup chain. */
4762 +static struct dwarf_expr_context *
4763 +dwarf_expr_prep_ctx (struct frame_info *frame, gdb_byte *data,
4764 + unsigned short size, struct dwarf2_per_cu_data *per_cu)
4766 + struct dwarf_expr_context *ctx;
4767 + struct dwarf_expr_baton baton;
4770 + frame = get_selected_frame (NULL);
4772 + baton.frame = frame;
4773 + baton.objfile = dwarf2_per_cu_objfile (per_cu);
4774 + baton.object_address = object_address;
4776 + ctx = new_dwarf_expr_context ();
4777 + make_cleanup_free_dwarf_expr_context (ctx);
4779 + ctx->gdbarch = get_objfile_arch (baton.objfile);
4780 + ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4781 + ctx->baton = &baton;
4782 + ctx->read_reg = dwarf_expr_read_reg;
4783 + ctx->read_mem = dwarf_expr_read_mem;
4784 + ctx->get_frame_base = dwarf_expr_frame_base;
4785 + ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4786 + ctx->get_tls_address = dwarf_expr_tls_address;
4787 + ctx->get_object_address = dwarf_expr_object_address;
4789 + dwarf_expr_eval (ctx, data, size);
4791 + /* It was used only during dwarf_expr_eval. */
4792 + ctx->baton = NULL;
4797 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
4798 + CORE_ADDR result on the DWARF stack stack. */
4801 +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
4803 + struct dwarf_expr_context *ctx;
4805 + struct cleanup *back_to = make_cleanup (null_cleanup, 0);
4807 + ctx = dwarf_expr_prep_ctx (NULL, dlbaton->data, dlbaton->size,
4809 + if (ctx->num_pieces > 0)
4810 + error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
4812 + retval = dwarf_expr_fetch (ctx, 0);
4814 + if (ctx->location == DWARF_VALUE_REGISTER)
4816 + /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
4818 + int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
4819 + struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
4820 + struct frame_info *frame = get_selected_frame (NULL);
4822 + retval = address_from_register (type, gdb_regnum, frame);
4825 + do_cleanups (back_to);
4830 struct piece_closure
4832 /* The number of pieces used to describe this variable. */
4833 @@ -382,9 +519,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4834 struct dwarf2_per_cu_data *per_cu)
4836 struct value *retval;
4837 - struct dwarf_expr_baton baton;
4838 struct dwarf_expr_context *ctx;
4839 - struct cleanup *old_chain;
4840 + struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
4844 @@ -394,22 +530,8 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4848 - baton.frame = frame;
4849 - baton.objfile = dwarf2_per_cu_objfile (per_cu);
4850 + ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu);
4852 - ctx = new_dwarf_expr_context ();
4853 - old_chain = make_cleanup_free_dwarf_expr_context (ctx);
4855 - ctx->gdbarch = get_objfile_arch (baton.objfile);
4856 - ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
4857 - ctx->baton = &baton;
4858 - ctx->read_reg = dwarf_expr_read_reg;
4859 - ctx->read_mem = dwarf_expr_read_mem;
4860 - ctx->get_frame_base = dwarf_expr_frame_base;
4861 - ctx->get_frame_cfa = dwarf_expr_frame_cfa;
4862 - ctx->get_tls_address = dwarf_expr_tls_address;
4864 - dwarf_expr_eval (ctx, data, size);
4865 if (ctx->num_pieces > 0)
4867 struct piece_closure *c;
4868 @@ -439,6 +561,11 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
4869 CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
4870 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
4872 + /* object_address_set called here is required in ALLOCATE_VALUE's
4873 + CHECK_TYPEDEF for the object's possible
4874 + DW_OP_push_object_address. */
4875 + object_address_set (address);
4877 retval = allocate_value (SYMBOL_TYPE (var));
4878 VALUE_LVAL (retval) = lval_memory;
4879 set_value_lazy (retval, 1);
4880 @@ -815,7 +942,7 @@ static int
4881 loclist_describe_location (struct symbol *symbol, struct ui_file *stream)
4883 /* FIXME: Could print the entire list of locations. */
4884 - fprintf_filtered (stream, "a variable with multiple locations");
4885 + fprintf_filtered (stream, _("a variable with multiple locations"));
4889 @@ -831,16 +958,56 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4891 data = find_location_expression (dlbaton, &size, ax->scope);
4893 - error (_("Variable \"%s\" is not available."), SYMBOL_NATURAL_NAME (symbol));
4894 + error (_("Variable \"%s\" is not available."), SYMBOL_PRINT_NAME (symbol));
4896 dwarf2_tracepoint_var_ref (symbol, gdbarch, ax, value, data, size);
4899 -/* The set of location functions used with the DWARF-2 expression
4900 - evaluator and location lists. */
4901 +/* The set of location functions used with the DWARF-2 location lists. */
4902 const struct symbol_computed_ops dwarf2_loclist_funcs = {
4903 loclist_read_variable,
4904 loclist_read_needs_frame,
4905 loclist_describe_location,
4906 loclist_tracepoint_var_ref
4909 +static struct value *
4910 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
4912 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4914 + gdb_assert (dlbaton == NULL);
4915 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
4919 +missing_read_needs_frame (struct symbol *symbol)
4925 +missing_describe_location (struct symbol *symbol, struct ui_file *stream)
4927 + fprintf_filtered (stream, _("a variable we are unable to resolve"));
4932 +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4933 + struct agent_expr *ax, struct axs_value *value)
4935 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4937 + gdb_assert (dlbaton == NULL);
4938 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
4941 +/* The set of location functions used with the DWARF-2 evaluator when we are
4942 + unable to resolve the symbols. */
4943 +const struct symbol_computed_ops dwarf2_missing_funcs = {
4944 + missing_read_variable,
4945 + missing_read_needs_frame,
4946 + missing_describe_location,
4947 + missing_tracepoint_var_ref
4949 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
4950 index 0bfcfca..01018d6 100644
4951 --- a/gdb/dwarf2loc.h
4952 +++ b/gdb/dwarf2loc.h
4953 @@ -71,5 +71,11 @@ struct dwarf2_loclist_baton
4955 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
4956 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
4957 +extern const struct symbol_computed_ops dwarf2_missing_funcs;
4959 +extern void object_address_set (CORE_ADDR address);
4961 +extern CORE_ADDR dwarf_locexpr_baton_eval
4962 + (struct dwarf2_locexpr_baton *dlbaton);
4964 #endif /* dwarf2loc.h */
4965 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
4966 index 4cce36b..c2f5f23 100644
4967 --- a/gdb/dwarf2read.c
4968 +++ b/gdb/dwarf2read.c
4972 #include "addrmap.h"
4973 +#include "f-lang.h"
4974 +#include "c-lang.h"
4975 +#include "typeprint.h"
4976 +#include "jv-lang.h"
4981 #include "gdb_string.h"
4982 @@ -93,7 +99,7 @@ typedef struct pubnames_header
4984 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
4986 -/* .debug_pubnames header
4987 +/* .debug_aranges header
4988 Because of alignment constraints, this structure has padding and cannot
4989 be mapped directly onto the beginning of the .debug_info section. */
4990 typedef struct aranges_header
4991 @@ -150,7 +156,10 @@ struct dwarf2_section_info
4996 + /* A function to call to deallocate BUFFER. If NULL, no
4997 + deallocation is needed. A pointer to this structure is passed as
4998 + the only argument. */
4999 + void (*destructor) (struct dwarf2_section_info *);
5002 struct dwarf2_per_objfile
5003 @@ -336,6 +345,19 @@ struct dwarf2_cu
5005 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
5006 unsigned int has_ranges_offset : 1;
5008 + /* Fields are valid according to the LANGUAGE field. */
5011 + /* language_fortran */
5014 + /* Module names imported to the block being currently read in. */
5015 + struct fortran_using *use;
5019 + language_specific;
5022 /* Persistent data held for a compilation unit, even when not
5023 @@ -495,8 +517,7 @@ struct partial_die_info
5024 unsigned int has_byte_size : 1;
5026 /* The name of this DIE. Normally the value of DW_AT_name, but
5027 - sometimes DW_TAG_MIPS_linkage_name or a string computed in some
5029 + sometimes a default name for unnamed DIEs. */
5033 @@ -689,6 +710,11 @@ struct field_info
5037 +/* A vector used during linkage name generation. */
5038 +typedef struct die_info *die_info_p;
5039 +DEF_VEC_P (die_info_p);
5040 +static VEC(die_info_p) *die_list;
5042 /* One item on the queue of compilation units to read in full symbols
5044 struct dwarf2_queue_item
5045 @@ -800,7 +826,10 @@ static void scan_partial_symbols (struct partial_die_info *,
5046 static void add_partial_symbol (struct partial_die_info *,
5047 struct dwarf2_cu *);
5049 -static int pdi_needs_namespace (enum dwarf_tag tag);
5050 +static gdb_byte *read_comp_unit_head (struct comp_unit_head *, gdb_byte *,
5053 +static int die_needs_namespace (struct die_info *, struct dwarf2_cu *);
5055 static void add_partial_namespace (struct partial_die_info *pdi,
5056 CORE_ADDR *lowpc, CORE_ADDR *highpc,
5057 @@ -825,6 +854,10 @@ static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
5059 static void psymtab_to_symtab_1 (struct partial_symtab *);
5061 +static void dwarf2_read_section_1 (struct objfile *objfile,
5062 + struct obstack *obstack,
5063 + struct dwarf2_section_info *info);
5065 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
5067 static void dwarf2_free_abbrev_table (void *);
5068 @@ -945,6 +978,11 @@ static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
5070 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
5072 +static char *physname_prefix (struct die_info *die, struct dwarf2_cu *);
5074 +static void physname_prefix_1 (struct ui_file *, struct die_info *,
5075 + struct dwarf2_cu *);
5077 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
5079 static char *typename_concat (struct obstack *,
5080 @@ -964,7 +1002,8 @@ static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
5081 struct dwarf2_cu *, struct partial_symtab *);
5083 static int dwarf2_get_pc_bounds (struct die_info *,
5084 - CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
5085 + CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
5086 + struct partial_symtab *pst);
5088 static void get_scope_pc_bounds (struct die_info *,
5089 CORE_ADDR *, CORE_ADDR *,
5090 @@ -988,17 +1027,25 @@ static void dwarf2_attach_fn_fields_to_type (struct field_info *,
5092 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
5094 -static const char *determine_class_name (struct die_info *die,
5095 - struct dwarf2_cu *cu);
5097 static void read_common_block (struct die_info *, struct dwarf2_cu *);
5099 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
5101 +static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
5103 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
5105 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
5107 +static struct type *read_module_type (struct die_info *die,
5108 + struct dwarf2_cu *cu);
5110 +static void read_fortran_imported_module (struct die_info *die,
5111 + struct dwarf2_cu *cu);
5113 +static void read_fortran_imported_declaration (struct die_info *die,
5114 + struct dwarf2_cu *cu);
5116 static const char *namespace_name (struct die_info *die,
5117 int *is_anonymous, struct dwarf2_cu *);
5119 @@ -1032,7 +1079,10 @@ static gdb_byte *read_full_die (const struct die_reader_specs *reader,
5121 static void process_die (struct die_info *, struct dwarf2_cu *);
5123 -static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
5124 +static char *dwarf2_physname (struct die_info *, struct dwarf2_cu *);
5126 +static char *fortran_module_linkage_name (struct die_info *die,
5127 + struct dwarf2_cu *cu);
5129 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
5131 @@ -1076,7 +1126,7 @@ static int is_ref_attr (struct attribute *);
5133 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
5135 -static int dwarf2_get_attr_constant_value (struct attribute *, int);
5136 +static CORE_ADDR dwarf2_get_attr_constant_value (struct attribute *, CORE_ADDR);
5138 static struct die_info *follow_die_ref_or_sig (struct die_info *,
5140 @@ -1148,6 +1198,9 @@ static void age_cached_comp_units (void);
5142 static void free_one_cached_comp_unit (void *);
5144 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
5145 + struct dwarf2_cu *cu);
5147 static struct type *set_die_type (struct die_info *, struct type *,
5148 struct dwarf2_cu *);
5150 @@ -1167,22 +1220,31 @@ static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
5152 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
5154 +static void destroy_section (struct dwarf2_section_info *info);
5156 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
5157 + (struct attribute *attr, struct dwarf2_cu *cu);
5159 /* Try to locate the sections we need for DWARF 2 debugging
5160 information and return true if we have enough to do something. */
5163 dwarf2_has_info (struct objfile *objfile)
5165 - struct dwarf2_per_objfile *data;
5167 - /* Initialize per-objfile state. */
5168 - data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
5169 - memset (data, 0, sizeof (*data));
5170 - set_objfile_data (objfile, dwarf2_objfile_data_key, data);
5171 - dwarf2_per_objfile = data;
5172 + dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
5173 + if (!dwarf2_per_objfile)
5175 + /* Initialize per-objfile state. */
5176 + struct dwarf2_per_objfile *data
5177 + = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
5178 + memset (data, 0, sizeof (*data));
5179 + set_objfile_data (objfile, dwarf2_objfile_data_key, data);
5180 + dwarf2_per_objfile = data;
5182 - bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
5183 - return (data->info.asection != NULL && data->abbrev.asection != NULL);
5184 + bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
5186 + return (dwarf2_per_objfile->info.asection != NULL
5187 + && dwarf2_per_objfile->abbrev.asection != NULL);
5190 /* When loading sections, we can either look for ".<name>", or for
5191 @@ -1275,10 +1337,13 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
5194 /* Decompress a section that was compressed using zlib. Store the
5195 - decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
5196 + decompressed buffer, and its size, in OUTBUF and OUTSIZE. The
5197 + result is allocated on OBSTACK; if OBSTACK is NULL, xmalloc is
5201 -zlib_decompress_section (struct objfile *objfile, asection *sectp,
5202 +zlib_decompress_section (struct objfile *objfile, struct obstack *obstack,
5204 gdb_byte **outbuf, bfd_size_type *outsize)
5206 bfd *abfd = objfile->obfd;
5207 @@ -1295,6 +1360,7 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5210 int header_size = 12;
5211 + struct cleanup *old = NULL;
5213 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5214 || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size)
5215 @@ -1324,8 +1390,13 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5216 strm.avail_in = compressed_size - header_size;
5217 strm.next_in = (Bytef*) compressed_buffer + header_size;
5218 strm.avail_out = uncompressed_size;
5219 - uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
5220 - uncompressed_size);
5222 + uncompressed_buffer = obstack_alloc (obstack, uncompressed_size);
5225 + uncompressed_buffer = xmalloc (uncompressed_size);
5226 + old = make_cleanup (xfree, uncompressed_buffer);
5228 rc = inflateInit (&strm);
5229 while (strm.avail_in > 0)
5231 @@ -1346,26 +1417,176 @@ zlib_decompress_section (struct objfile *objfile, asection *sectp,
5232 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
5233 bfd_get_filename (abfd), rc);
5236 + discard_cleanups (old);
5237 do_cleanups (cleanup);
5238 *outbuf = uncompressed_buffer;
5239 *outsize = uncompressed_size;
5243 -/* Read the contents of the section SECTP from object file specified by
5244 - OBJFILE, store info about the section into INFO.
5245 - If the section is compressed, uncompress it before returning. */
5246 +/* A cleanup that calls destroy_section. */
5249 -dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5250 +destroy_section_cleanup (void *arg)
5252 + destroy_section (arg);
5255 +/* Read the .debug_aranges section and construct an address map. */
5258 +dwarf2_create_quick_addrmap (struct objfile *objfile)
5260 + char *aranges_buffer, *aranges_ptr;
5261 + bfd *abfd = objfile->obfd;
5262 + CORE_ADDR baseaddr;
5263 + struct cleanup *old;
5264 + struct obstack temp_obstack;
5265 + struct addrmap *mutable_map;
5267 + if (!dwarf2_per_objfile->aranges.asection)
5270 + baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5272 + dwarf2_read_section_1 (objfile, NULL, &dwarf2_per_objfile->aranges);
5273 + aranges_buffer = dwarf2_per_objfile->aranges.buffer;
5274 + aranges_ptr = aranges_buffer;
5275 + old = make_cleanup (destroy_section_cleanup, &dwarf2_per_objfile->aranges);
5277 + obstack_init (&temp_obstack);
5278 + make_cleanup_obstack_free (&temp_obstack);
5279 + mutable_map = addrmap_create_mutable (&temp_obstack);
5281 + while ((aranges_ptr - aranges_buffer) < dwarf2_per_objfile->aranges.size)
5283 + struct comp_unit_head cu_header;
5284 + unsigned int bytes_read, segment_size, delta;
5285 + LONGEST info_offset;
5286 + struct dwarf2_cu cu;
5289 + cu_header.initial_length_size = 0;
5290 + end_ptr = aranges_ptr;
5291 + aranges_ptr = read_comp_unit_head (&cu_header, aranges_ptr, abfd);
5292 + end_ptr += cu_header.initial_length_size + cu_header.length;
5294 + /* Sanity check. */
5295 + if (end_ptr - aranges_ptr >= dwarf2_per_objfile->aranges.size)
5297 + do_cleanups (old);
5298 + complaint (&symfile_complaints,
5299 + _("aranges entry runs off end of `.debug_aranges' section, ignored"));
5302 + if (cu_header.addr_size == 0)
5304 + do_cleanups (old);
5305 + complaint (&symfile_complaints,
5306 + _("aranges entry has zero addr_size, ignored"));
5310 + segment_size = read_1_byte (abfd, aranges_ptr);
5313 + /* Align the pointer to twice the pointer size. I didn't see
5314 + this in the spec but it appears to be required. */
5315 + delta = (aranges_ptr - aranges_buffer) % (2 * cu_header.addr_size);
5316 + delta = (2 * cu_header.addr_size - delta) % (2 * cu_header.addr_size);
5317 + aranges_ptr += delta;
5319 + memset (&cu, 0, sizeof (cu));
5320 + cu.header.addr_size = cu_header.addr_size;
5324 + CORE_ADDR address, length;
5326 + address = read_address (abfd, aranges_ptr, &cu, &bytes_read);
5327 + aranges_ptr += bytes_read;
5329 + length = read_address (abfd, aranges_ptr, &cu, &bytes_read);
5330 + aranges_ptr += bytes_read;
5332 + if (address == 0 && length == 0)
5337 + do_cleanups (old);
5338 + complaint (&symfile_complaints,
5339 + _("aranges entry has zero length, ignored"));
5343 + address += baseaddr;
5345 + addrmap_set_empty (mutable_map, address, address + length - 1,
5349 + /* Some older versions of GCC incorrectly started the arange
5350 + with a (0,0) pair. If we encounter any oddity while reading
5351 + the section, just abandon the attempt; falling back to the
5352 + slower code is always safe. */
5353 + if (aranges_ptr != end_ptr)
5355 + do_cleanups (old);
5356 + complaint (&symfile_complaints,
5357 + _("aranges entry ends early, ignored"));
5362 + objfile->quick_addrmap = addrmap_create_fixed (mutable_map,
5363 + &objfile->objfile_obstack);
5364 + do_cleanups (old);
5367 +/* Free a section buffer allocated with xmalloc. */
5370 +xfree_section_buffer (struct dwarf2_section_info *info)
5372 + xfree (info->buffer);
5375 +/* If section described by INFO was mmapped, munmap it now. */
5378 +munmap_section_buffer (struct dwarf2_section_info *info)
5381 + intptr_t begin = (intptr_t) info->buffer;
5382 + intptr_t map_begin = begin & ~(pagesize - 1);
5383 + size_t map_length = info->size + begin - map_begin;
5384 + gdb_assert (munmap ((void *) map_begin, map_length) == 0);
5386 + /* Without HAVE_MMAP, we should never be here to begin with. */
5391 +/* Read the contents of the section at OFFSET and of size SIZE from
5392 + the object file specified by OBJFILE into OBSTACK and store it into
5393 + INFO. If OBSTACK is NULL, xmalloc is used instead. If the section
5394 + is compressed, uncompress it before returning. */
5397 +dwarf2_read_section_1 (struct objfile *objfile,
5398 + struct obstack *obstack,
5399 + struct dwarf2_section_info *info)
5401 bfd *abfd = objfile->obfd;
5402 asection *sectp = info->asection;
5403 gdb_byte *buf, *retbuf;
5404 unsigned char header[4];
5405 + struct cleanup *old = NULL;
5407 info->buffer = NULL;
5408 - info->was_mmapped = 0;
5409 + info->destructor = 0;
5411 if (info->asection == NULL || info->size == 0)
5413 @@ -1378,7 +1599,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5414 /* Upon decompression, update the buffer and its size. */
5415 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
5417 - zlib_decompress_section (objfile, sectp, &info->buffer,
5418 + zlib_decompress_section (objfile, obstack, sectp, &info->buffer,
5422 @@ -1401,7 +1622,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5424 if (retbuf != MAP_FAILED)
5426 - info->was_mmapped = 1;
5427 + info->destructor = munmap_section_buffer;
5428 info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
5431 @@ -1409,8 +1630,15 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5434 /* If we get here, we are a normal, not-compressed section. */
5435 - info->buffer = buf
5436 - = obstack_alloc (&objfile->objfile_obstack, info->size);
5438 + buf = obstack_alloc (obstack, info->size);
5441 + buf = xmalloc (info->size);
5442 + old = make_cleanup (xfree, buf);
5443 + info->destructor = xfree_section_buffer;
5445 + info->buffer = buf;
5447 /* When debugging .o files, we may need to apply relocations; see
5448 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
5449 @@ -1419,6 +1647,8 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5450 retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
5454 + discard_cleanups (old);
5455 info->buffer = retbuf;
5458 @@ -1427,6 +1657,19 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5459 || bfd_bread (buf, info->size, abfd) != info->size)
5460 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
5461 bfd_get_filename (abfd));
5464 + discard_cleanups (old);
5467 +/* Read the contents of the section SECTP from object file specified by
5468 + OBJFILE, store info about the section into INFO.
5469 + If the section is compressed, uncompress it before returning. */
5472 +dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
5474 + dwarf2_read_section_1 (objfile, &objfile->objfile_obstack, info);
5477 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
5478 @@ -1810,6 +2053,37 @@ lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
5482 +/* Find the base address of the compilation unit for range lists and
5483 + location lists. It will normally be specified by DW_AT_low_pc.
5484 + In DWARF-3 draft 4, the base address could be overridden by
5485 + DW_AT_entry_pc. It's been removed, but GCC still uses this for
5486 + compilation units with discontinuous ranges. */
5489 +dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
5491 + struct attribute *attr;
5493 + cu->base_known = 0;
5494 + cu->base_address = 0;
5496 + attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
5499 + cu->base_address = DW_ADDR (attr);
5500 + cu->base_known = 1;
5504 + attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5507 + cu->base_address = DW_ADDR (attr);
5508 + cu->base_known = 1;
5513 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
5514 to combine the common parts.
5515 Process a compilation unit for a psymtab.
5516 @@ -2359,7 +2633,7 @@ partial_die_parent_scope (struct partial_die_info *pdi,
5518 complaint (&symfile_complaints,
5519 _("unhandled containing DIE tag %d for DIE at %d"),
5520 - parent->tag, pdi->offset);
5521 + parent->tag, real_pdi->offset);
5522 parent->scope = grandparent_scope;
5525 @@ -2374,12 +2648,22 @@ partial_die_full_name (struct partial_die_info *pdi,
5526 struct dwarf2_cu *cu)
5529 + struct partial_die_info *real_pdi;
5531 - parent_scope = partial_die_parent_scope (pdi, cu);
5532 - if (parent_scope == NULL)
5535 + /* We need to look at our parent DIE; if we have a DW_AT_specification,
5536 + then this means the parent of the specification DIE.
5537 + partial_die_parent_scope does this loop also, but we do it here
5538 + since we need to examine real_pdi->parent ourselves. */
5541 + while (real_pdi->has_specification)
5542 + real_pdi = find_partial_die (real_pdi->spec_offset, cu);
5544 + parent_scope = partial_die_parent_scope (real_pdi, cu);
5545 + if (parent_scope != NULL)
5546 return typename_concat (NULL, parent_scope, pdi->name, cu);
5552 @@ -2395,12 +2679,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5554 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5556 - if (pdi_needs_namespace (pdi->tag))
5558 - actual_name = partial_die_full_name (pdi, cu);
5560 - built_actual_name = 1;
5562 + actual_name = partial_die_full_name (pdi, cu);
5564 + built_actual_name = 1;
5566 if (actual_name == NULL)
5567 actual_name = pdi->name;
5568 @@ -2491,6 +2772,12 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5569 &objfile->global_psymbols,
5570 0, (CORE_ADDR) 0, cu->language, objfile);
5572 + case DW_TAG_module:
5573 + add_psymbol_to_list (actual_name, strlen (actual_name),
5574 + MODULE_DOMAIN, LOC_STATIC,
5575 + &objfile->global_psymbols,
5576 + 0, (CORE_ADDR) 0, cu->language, objfile);
5578 case DW_TAG_class_type:
5579 case DW_TAG_interface_type:
5580 case DW_TAG_structure_type:
5581 @@ -2532,34 +2819,17 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5585 - /* Check to see if we should scan the name for possible namespace
5586 - info. Only do this if this is C++, if we don't have namespace
5587 - debugging info in the file, if the psym is of an appropriate type
5588 - (otherwise we'll have psym == NULL), and if we actually had a
5589 - mangled name to begin with. */
5591 - /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
5592 - cases which do not set PSYM above? */
5594 - if (cu->language == language_cplus
5595 - && cu->has_namespace_info == 0
5597 - && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
5598 - cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
5601 if (built_actual_name)
5602 xfree (actual_name);
5605 -/* Determine whether a die of type TAG living in a C++ class or
5606 - namespace needs to have the name of the scope prepended to the
5607 - name listed in the die. */
5608 +/* Determine whether DIE needs to have the name of the scope prepended
5609 + to the name listed in the die. */
5612 -pdi_needs_namespace (enum dwarf_tag tag)
5613 +die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
5618 case DW_TAG_namespace:
5619 case DW_TAG_typedef:
5620 @@ -2569,7 +2839,23 @@ pdi_needs_namespace (enum dwarf_tag tag)
5621 case DW_TAG_union_type:
5622 case DW_TAG_enumeration_type:
5623 case DW_TAG_enumerator:
5624 + case DW_TAG_subprogram:
5625 + case DW_TAG_member:
5628 + case DW_TAG_variable:
5630 + struct attribute *attr;
5631 + attr = dwarf2_attr (die, DW_AT_specification, cu);
5634 + attr = dwarf2_attr (die, DW_AT_external, cu);
5635 + if (attr == NULL && die->parent->tag != DW_TAG_namespace)
5644 @@ -2602,12 +2888,12 @@ static void
5645 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
5646 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
5648 - /* Now scan partial symbols in that module.
5649 + /* Add a symbol for the module. */
5651 - FIXME: Support the separate Fortran module namespaces. */
5652 + add_partial_symbol (pdi, cu);
5654 - if (pdi->has_children)
5655 - scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
5656 + /* Partial symbols in that module are not scanned as they are never globally
5657 + visible. They get imported to the specific scopes on the full read. */
5660 /* Read a partial die corresponding to a subprogram and create a partial
5661 @@ -2698,27 +2984,6 @@ guess_structure_name (struct partial_die_info *struct_pdi,
5663 if (real_pdi->die_parent != NULL)
5666 - while (child_pdi != NULL)
5668 - if (child_pdi->tag == DW_TAG_subprogram)
5670 - char *actual_class_name
5671 - = language_class_name_from_physname (cu->language_defn,
5673 - if (actual_class_name != NULL)
5676 - = obsavestring (actual_class_name,
5677 - strlen (actual_class_name),
5678 - &cu->comp_unit_obstack);
5679 - xfree (actual_class_name);
5684 - child_pdi = child_pdi->die_sibling;
5689 @@ -3295,6 +3560,14 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
5690 case DW_TAG_imported_declaration:
5691 case DW_TAG_imported_module:
5692 processing_has_namespace_info = 1;
5693 + if (cu->language == language_fortran)
5695 + if (die->tag == DW_TAG_imported_declaration)
5696 + read_fortran_imported_declaration (die, cu);
5698 + read_fortran_imported_module (die, cu);
5701 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
5702 || cu->language != language_fortran))
5703 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
5704 @@ -3310,41 +3583,68 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
5705 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5706 If scope qualifiers are appropriate they will be added. The result
5707 will be allocated on the objfile_obstack, or NULL if the DIE does
5708 - not have a name. */
5711 + The output string will be canonicalized (if C++/Java). */
5714 dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu)
5716 - struct attribute *attr;
5717 - char *prefix, *name;
5718 - struct ui_file *buf = NULL;
5721 name = dwarf2_name (die, cu);
5725 /* These are the only languages we know how to qualify names in. */
5726 - if (cu->language != language_cplus
5727 - && cu->language != language_java)
5730 + && (cu->language == language_cplus || cu->language == language_java))
5732 + if (die_needs_namespace (die, cu))
5736 + struct ui_file *buf;
5738 - /* If no prefix is necessary for this type of DIE, return the
5739 - unqualified name. The other three tags listed could be handled
5740 - in pdi_needs_namespace, but that requires broader changes. */
5741 - if (!pdi_needs_namespace (die->tag)
5742 - && die->tag != DW_TAG_subprogram
5743 - && die->tag != DW_TAG_variable
5744 - && die->tag != DW_TAG_member)
5746 + buf = mem_fileopen ();
5747 + prefix = determine_prefix (die, cu);
5748 + if (*prefix != '\0')
5750 + char *prefixed_name = typename_concat (NULL, prefix, name, cu);
5751 + fputs_unfiltered (prefixed_name, buf);
5752 + xfree (prefixed_name);
5755 + fputs_unfiltered (name, buf);
5757 - prefix = determine_prefix (die, cu);
5758 - if (*prefix != '\0')
5759 - name = typename_concat (&cu->objfile->objfile_obstack, prefix,
5761 + name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5763 + ui_file_delete (buf);
5765 + if (cu->language == language_cplus)
5768 + = dwarf2_canonicalize_name (name, cu,
5769 + &cu->objfile->objfile_obstack);
5770 + if (cname != NULL)
5779 +/* read the given die's decl_line number. Return -1 if in case of an error */
5780 +static const int dwarf2_read_decl_line (struct die_info *die, struct dwarf2_cu *cu){
5781 + struct attribute *line_attr;
5783 + line_attr = dwarf2_attr (die, DW_AT_decl_line, cu);
5785 + return DW_UNSND (line_attr);
5791 /* Read the import statement specified by the given die and record it. */
5794 @@ -3354,9 +3654,15 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5795 struct die_info *imported_die;
5796 const char *imported_name;
5797 const char *imported_name_prefix;
5798 - const char *import_prefix;
5799 char *canonical_name;
5801 + const char *import_alias;
5802 + const char *imported_declaration = "";
5803 + const char *import_prefix;
5805 + int line_number = -1;
5807 + int is_anonymous = 0;
5809 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5810 if (import_attr == NULL)
5812 @@ -3404,17 +3710,27 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5816 - /* FIXME: dwarf2_name (die); for the local name after import. */
5818 - /* Figure out where the statement is being imported to. */
5819 + /* Figure out the local name after import. */
5820 + import_alias = dwarf2_name(die, cu);
5821 + if(import_alias == NULL){
5822 + import_alias = "";
5825 + /* Determine the line number at which the import was made */
5826 + line_number = dwarf2_read_decl_line(die, cu);
5828 + /* Figure out where the statement is being imported to */
5829 import_prefix = determine_prefix (die, cu);
5831 /* Figure out what the scope of the imported die is and prepend it
5832 to the name of the imported die. */
5833 imported_name_prefix = determine_prefix (imported_die, cu);
5835 - if (strlen (imported_name_prefix) > 0)
5838 + if(imported_die->tag != DW_TAG_namespace){
5839 + imported_declaration = imported_name;
5840 + canonical_name = (char*)imported_name_prefix;
5842 + if(strlen (imported_name_prefix) > 0){
5843 canonical_name = alloca (strlen (imported_name_prefix) + 2 + strlen (imported_name) + 1);
5844 strcpy (canonical_name, imported_name_prefix);
5845 strcat (canonical_name, "::");
5846 @@ -3425,8 +3741,14 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5847 canonical_name = alloca (strlen (imported_name) + 1);
5848 strcpy (canonical_name, imported_name);
5851 - using_directives = cp_add_using (import_prefix,canonical_name, using_directives);
5854 + using_directives = cp_add_using (import_prefix,
5857 + imported_declaration,
5859 + using_directives);
5863 @@ -3695,6 +4017,14 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5864 struct attribute *attr;
5866 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5868 + /* GCC 4.3 incorrectly uses DW_AT_specification to indicate die inheritence
5869 + in the case of import statements. The following is to accommodate
5872 + attr = dwarf2_attr (die, DW_AT_specification, cu);
5878 @@ -3793,6 +4123,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5881 struct block *block;
5882 + unsigned die_children = 0;
5883 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5886 @@ -3811,13 +4142,23 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5888 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5890 - name = dwarf2_linkage_name (die, cu);
5891 + name = dwarf2_name (die, cu);
5893 /* Ignore functions with missing or empty names and functions with
5894 missing or invalid low and high pc attributes. */
5895 - if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
5896 + if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)){
5897 + /* explore abstract origins if present. They might contain useful information
5898 + such as import statements. */
5899 + child_die = die->child;
5900 + while (child_die && child_die->tag)
5902 + child_die = sibling_die (child_die);
5905 + inherit_abstract_dies(die, cu);
5913 @@ -3844,14 +4185,19 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5915 cu->list_in_scope = &local_symbols;
5917 - if (die->child != NULL)
5918 + switch (cu->language)
5920 - child_die = die->child;
5921 - while (child_die && child_die->tag)
5923 - process_die (child_die, cu);
5924 - child_die = sibling_die (child_die);
5926 + case language_fortran:
5927 + cu->language_specific.fortran.use = NULL;
5931 + child_die = die->child;
5932 + while (child_die && child_die->tag)
5934 + process_die (child_die, cu);
5935 + child_die = sibling_die (child_die);
5939 inherit_abstract_dies (die, cu);
5940 @@ -3867,6 +4213,13 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5941 determine_prefix (die, cu),
5942 processing_has_namespace_info);
5944 + switch (cu->language)
5946 + case language_fortran:
5947 + BLOCK_FORTRAN_USE (block) = cu->language_specific.fortran.use;
5951 /* If we have address ranges, record them. */
5952 dwarf2_record_block_ranges (die, block, baseaddr, cu);
5954 @@ -3903,7 +4256,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5955 as multiple lexical blocks? Handling children in a sane way would
5956 be nasty. Might be easier to properly extend generic blocks to
5958 - if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
5959 + if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5963 @@ -3920,7 +4273,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
5965 new = pop_context ();
5967 - if (local_symbols != NULL)
5968 + if (local_symbols != NULL || using_directives != NULL)
5971 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
5972 @@ -4075,7 +4428,8 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
5973 discontinuous, i.e. derived from DW_AT_ranges information. */
5975 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5976 - CORE_ADDR *highpc, struct dwarf2_cu *cu)
5977 + CORE_ADDR *highpc, struct dwarf2_cu *cu,
5978 + struct partial_symtab *pst)
5980 struct attribute *attr;
5982 @@ -4103,7 +4457,7 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
5984 /* Value of the DW_AT_ranges attribute is the offset in the
5985 .debug_ranges section. */
5986 - if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL))
5987 + if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
5989 /* Found discontinuous range of addresses. */
5991 @@ -4142,7 +4496,7 @@ dwarf2_get_subprogram_pc_bounds (struct die_info *die,
5992 CORE_ADDR low, high;
5993 struct die_info *child = die->child;
5995 - if (dwarf2_get_pc_bounds (die, &low, &high, cu))
5996 + if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
5998 *lowpc = min (*lowpc, low);
5999 *highpc = max (*highpc, high);
6000 @@ -4179,7 +4533,7 @@ get_scope_pc_bounds (struct die_info *die,
6001 CORE_ADDR best_high = (CORE_ADDR) 0;
6002 CORE_ADDR current_low, current_high;
6004 - if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
6005 + if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
6007 best_low = current_low;
6008 best_high = current_high;
6009 @@ -4474,7 +4828,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
6012 /* Get physical name. */
6013 - physname = dwarf2_linkage_name (die, cu);
6014 + physname = dwarf2_physname (die, cu);
6016 /* The name is already allocated along with this objfile, so we don't
6017 need to duplicate it for the type. */
6018 @@ -4617,7 +4971,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6021 /* Get the mangled name. */
6022 - physname = dwarf2_linkage_name (die, cu);
6023 + physname = dwarf2_physname (die, cu);
6025 /* Look up member function name in fieldlist. */
6026 for (i = 0; i < fip->nfnfields; i++)
6027 @@ -4661,7 +5015,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6028 /* The name is already allocated along with this objfile, so we don't
6029 need to duplicate it for the type. */
6030 fnp->physname = physname ? physname : "";
6031 - fnp->type = alloc_type (objfile);
6032 + fnp->type = alloc_type (objfile, NULL);
6033 this_type = read_type_die (die, cu);
6034 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
6036 @@ -4721,18 +5075,18 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6038 /* Support the .debug_loc offsets */
6039 if (attr_form_is_block (attr))
6041 - fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6044 + fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
6046 else if (attr_form_is_section_offset (attr))
6049 dwarf2_complex_location_expr_complaint ();
6055 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6062 @@ -4845,7 +5199,7 @@ quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu)
6065 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
6066 - type = alloc_type (objfile);
6067 + type = alloc_type (objfile, NULL);
6068 smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type),
6069 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
6070 TYPE_VARARGS (pfn_type));
6071 @@ -4898,7 +5252,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6072 return set_die_type (die, type, cu);
6075 - type = alloc_type (objfile);
6076 + type = alloc_type (objfile, NULL);
6077 INIT_CPLUS_SPECIFIC (type);
6079 name = dwarf2_name (die, cu);
6080 @@ -4907,14 +5261,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
6081 if (cu->language == language_cplus
6082 || cu->language == language_java)
6084 - const char *new_prefix = determine_class_name (die, cu);
6085 - TYPE_TAG_NAME (type) = (char *) new_prefix;
6086 + TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (die, cu);
6087 + if (die->tag == DW_TAG_structure_type
6088 + || die->tag == DW_TAG_class_type)
6089 + TYPE_NAME (type) = TYPE_TAG_NAME (type);
6093 /* The name is already allocated along with this objfile, so
6094 we don't need to duplicate it for the type. */
6095 - TYPE_TAG_NAME (type) = name;
6096 + TYPE_TAG_NAME (type) = (char *) name;
6097 + if (die->tag == DW_TAG_class_type)
6098 + TYPE_NAME (type) = TYPE_TAG_NAME (type);
6102 @@ -5124,7 +5482,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6103 return set_die_type (die, type, cu);
6106 - type = alloc_type (objfile);
6107 + type = alloc_type (objfile, NULL);
6109 TYPE_CODE (type) = TYPE_CODE_ENUM;
6110 name = dwarf2_full_name (die, cu);
6111 @@ -5152,51 +5510,6 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
6112 return set_die_type (die, type, cu);
6115 -/* Determine the name of the type represented by DIE, which should be
6116 - a named C++ or Java compound type. Return the name in question,
6117 - allocated on the objfile obstack. */
6119 -static const char *
6120 -determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
6122 - const char *new_prefix = NULL;
6124 - /* If we don't have namespace debug info, guess the name by trying
6125 - to demangle the names of members, just like we did in
6126 - guess_structure_name. */
6127 - if (!processing_has_namespace_info)
6129 - struct die_info *child;
6131 - for (child = die->child;
6132 - child != NULL && child->tag != 0;
6133 - child = sibling_die (child))
6135 - if (child->tag == DW_TAG_subprogram)
6138 - = language_class_name_from_physname (cu->language_defn,
6139 - dwarf2_linkage_name
6142 - if (phys_prefix != NULL)
6145 - = obsavestring (phys_prefix, strlen (phys_prefix),
6146 - &cu->objfile->objfile_obstack);
6147 - xfree (phys_prefix);
6154 - if (new_prefix == NULL)
6155 - new_prefix = dwarf2_full_name (die, cu);
6157 - return new_prefix;
6160 /* Given a pointer to a die which begins an enumeration, process all
6161 the dies that define the members of the enumeration, and create the
6162 symbol for the enumeration type.
6163 @@ -5274,6 +5587,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
6164 new_symbol (die, this_type, cu);
6167 +/* Create a new array dimension referencing its target type TYPE.
6169 + Multidimensional arrays are internally represented as a stack of
6170 + singledimensional arrays being referenced by their TYPE_TARGET_TYPE. */
6172 +static struct type *
6173 +create_single_array_dimension (struct type *type, struct type *range_type,
6174 + struct die_info *die, struct dwarf2_cu *cu)
6176 + type = create_array_type (NULL, type, range_type);
6178 + /* These generic type attributes need to be fetched by
6179 + evaluate_subexp_standard <multi_f77_subscript>'s call of
6180 + value_subscripted_rvalue only for the innermost array type. */
6181 + fetch_die_type_attrs (die, type, cu);
6183 + /* These generic type attributes are checked for allocated/associated
6184 + validity while accessing FIELD_LOC_KIND_DWARF_BLOCK. */
6185 + fetch_die_type_attrs (die, range_type, cu);
6190 /* Extract all information from a DW_TAG_array_type DIE and put it in
6191 the DIE's type field. For now, this only handles one dimensional
6193 @@ -5287,7 +5623,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6194 struct type *element_type, *range_type, *index_type;
6195 struct type **range_types = NULL;
6196 struct attribute *attr;
6199 struct cleanup *back_to;
6202 @@ -5334,16 +5670,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
6203 type = element_type;
6205 if (read_array_order (die, cu) == DW_ORD_col_major)
6209 - type = create_array_type (NULL, type, range_types[i++]);
6213 - while (ndim-- > 0)
6214 - type = create_array_type (NULL, type, range_types[ndim]);
6216 + for (i = 0; i < ndim; i++)
6217 + type = create_single_array_dimension (type, range_types[i], die, cu);
6218 + else /* (read_array_order (die, cu) == DW_ORD_row_major) */
6219 + for (i = ndim - 1; i >= 0; i--)
6220 + type = create_single_array_dimension (type, range_types[i], die, cu);
6222 /* Understand Dwarf2 support for vector types (like they occur on
6223 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6224 @@ -5410,12 +5741,14 @@ read_set_type (struct die_info *die, struct dwarf2_cu *cu)
6225 return set_die_type (die, set_type, cu);
6228 -/* First cut: install each common block member as a global variable. */
6229 +/* Create appropriate locally-scoped variables for all the DW_TAG_common_block
6230 + entries. Create also TYPE_CODE_STRUCT listing all such variables to be
6231 + available for `info common'. COMMON_BLOCK_DOMAIN is used to sepate the
6232 + common blocks name namespace from regular variable names. */
6235 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6237 - struct die_info *child_die;
6238 struct attribute *attr;
6240 CORE_ADDR base = (CORE_ADDR) 0;
6241 @@ -5425,25 +5758,55 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6243 /* Support the .debug_loc offsets */
6244 if (attr_form_is_block (attr))
6246 - base = decode_locdesc (DW_BLOCK (attr), cu);
6249 + base = decode_locdesc (DW_BLOCK (attr), cu);
6251 else if (attr_form_is_section_offset (attr))
6254 dwarf2_complex_location_expr_complaint ();
6260 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6261 "common block member");
6265 if (die->child != NULL)
6267 + struct objfile *objfile = cu->objfile;
6268 + struct die_info *child_die;
6269 + struct type *type;
6270 + struct field *field;
6272 + struct symbol *sym;
6274 + type = alloc_type (objfile, NULL);
6275 + TYPE_CODE (type) = TYPE_CODE_STRUCT;
6276 + /* Artificial type to be used only by `info common'. */
6277 + TYPE_NAME (type) = "<common>";
6279 child_die = die->child;
6280 while (child_die && child_die->tag)
6282 + TYPE_NFIELDS (type)++;
6283 + child_die = sibling_die (child_die);
6286 + TYPE_FIELDS (type) = obstack_alloc (&objfile->objfile_obstack,
6287 + sizeof (*TYPE_FIELDS (type))
6288 + * TYPE_NFIELDS (type));
6289 + memset (TYPE_FIELDS (type), 0, sizeof (*TYPE_FIELDS (type))
6290 + * TYPE_NFIELDS (type));
6292 + field = TYPE_FIELDS (type);
6293 + child_die = die->child;
6294 + while (child_die && child_die->tag)
6296 + /* Create the symbol in the DW_TAG_common_block block in the current
6298 sym = new_symbol (child_die, NULL, cu);
6300 + /* Undocumented in DWARF3, when it can be present? */
6301 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
6304 @@ -5461,8 +5824,25 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
6305 SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset;
6306 add_symbol_to_list (sym, &global_symbols);
6309 + if (SYMBOL_CLASS (sym) == LOC_STATIC)
6310 + SET_FIELD_PHYSADDR (*field, SYMBOL_VALUE_ADDRESS (sym));
6312 + SET_FIELD_PHYSNAME (*field, SYMBOL_LINKAGE_NAME (sym));
6313 + FIELD_TYPE (*field) = SYMBOL_TYPE (sym);
6314 + FIELD_NAME (*field) = SYMBOL_NATURAL_NAME (sym);
6316 child_die = sibling_die (child_die);
6319 + /* TYPE_LENGTH (type) is left 0 - it is only a virtual structure even
6320 + with no consecutive address space. */
6322 + sym = new_symbol (die, type, cu);
6323 + /* SYMBOL_VALUE_ADDRESS never gets used as all its fields are static. */
6324 + SYMBOL_VALUE_ADDRESS (sym) = base;
6326 + set_die_type (die, type, cu);
6330 @@ -5530,7 +5910,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6333 const char *previous_prefix = determine_prefix (die, cu);
6334 - cp_add_using_directive (previous_prefix, TYPE_NAME (type));
6335 + cp_add_using_directive (previous_prefix, TYPE_NAME (type), "", "", dwarf2_read_decl_line(die, cu));
6339 @@ -5546,20 +5926,155 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
6343 -/* Read a Fortran module. */
6344 +/* Read a Fortran module as global symbol which can be later looked up by
6345 + f_lookup_symbol_nonlocal. */
6348 read_module (struct die_info *die, struct dwarf2_cu *cu)
6350 - struct die_info *child_die = die->child;
6351 + struct type *type;
6353 + type = read_module_type (die, cu);
6356 + new_symbol (die, type, cu);
6359 +/* Read a Fortran module as type.
6361 + Modules present only as declarations - being used only for DW_AT_import of
6362 + DW_TAG_imported_module - are ignored here. They are read in only in form of
6363 + the module name by read_fortran_imported_module. */
6365 +static struct type *
6366 +read_module_type (struct die_info *die, struct dwarf2_cu *cu)
6368 + struct objfile *objfile = cu->objfile;
6369 + struct die_info *child_die;
6370 + struct type *type;
6371 + char *module_name;
6372 + struct context_stack *new;
6373 + struct pending *save_file_symbols;
6374 + struct pending *save_global_symbols;
6375 + struct pending **save_list_in_scope;
6377 + if (die_is_declaration (die, cu))
6380 - /* FIXME: Support the separate Fortran module namespaces. */
6381 + module_name = dwarf2_name (die, cu);
6383 + complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"),
6385 + type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
6387 + /* Create a context for reading the module variables. */
6389 + new = push_context (0, 0);
6391 + save_file_symbols = file_symbols;
6392 + file_symbols = NULL;
6393 + save_global_symbols = global_symbols;
6394 + global_symbols = NULL;
6395 + save_list_in_scope = cu->list_in_scope;
6397 + /* Process the child DIEs. */
6399 + child_die = die->child;
6400 while (child_die && child_die->tag)
6402 + /* Any DW_TAG_subprogram will reset LIST_IN_SCOPE to LOCAL_SYMBOLS. */
6403 + cu->list_in_scope = &global_symbols;
6405 process_die (child_die, cu);
6406 child_die = sibling_die (child_die);
6409 + /* Finish this module and restore the context. */
6411 + TYPE_MODULE_BLOCK (type) = finish_block (NULL, &global_symbols,
6412 + new->old_blocks, 0, 0, objfile);
6415 + complaint (&symfile_complaints, _("DW_TAG_module contains static symbols"));
6416 + if (local_symbols)
6417 + complaint (&symfile_complaints, _("DW_TAG_module contains local symbols"));
6418 + if (param_symbols)
6419 + complaint (&symfile_complaints, _("DW_TAG_module contains function "
6422 + file_symbols = save_file_symbols;
6423 + global_symbols = save_global_symbols;
6424 + cu->list_in_scope = save_list_in_scope;
6428 + set_die_type (die, type, cu);
6433 +/* Import a Fortran module. Only store the module name for its later lookup by
6434 + f_lookup_symbol_nonlocal. */
6437 +read_fortran_imported_module (struct die_info *die, struct dwarf2_cu *cu)
6439 + struct objfile *objfile = cu->objfile;
6440 + struct attribute *attr;
6441 + struct die_info *module_die;
6442 + char *module_name;
6443 + struct fortran_using *use;
6445 + attr = dwarf2_attr (die, DW_AT_import, cu);
6449 + module_die = follow_die_ref (die, attr, &cu);
6450 + module_name = dwarf2_name (module_die, cu);
6451 + if (module_name == NULL)
6453 + complaint (&symfile_complaints,
6454 + _("Imported DIE at offset 0x%x has no name"), die->offset);
6458 + /* Fortran does not allow any duplicity between local and any of the imported
6459 + symbols. Therefore the order of the USE statements is not portant.
6461 + Error: Name 'X' at (1) is an ambiguous reference to 'X' from module 'Y' */
6463 + use = obstack_alloc (&objfile->objfile_obstack, sizeof (*use)
6464 + + strlen (module_name));
6465 + strcpy (use->module_name, module_name);
6466 + gdb_assert (cu->language == language_fortran);
6467 + use->next = cu->language_specific.fortran.use;
6468 + cu->language_specific.fortran.use = use;
6471 +/* Import a single Fortran declaration and possibly rename it. */
6474 +read_fortran_imported_declaration (struct die_info *die, struct dwarf2_cu *cu)
6476 + struct attribute *attr;
6477 + struct die_info *imported_die;
6478 + struct symbol *sym;
6479 + char *rename = dwarf2_name (die, cu);
6481 + attr = dwarf2_attr (die, DW_AT_import, cu);
6484 + complaint (&symfile_complaints,
6485 + _("Fortran DW_TAG_imported_declaration is missing "
6486 + "DW_AT_import at offset 0x%x"), die->offset);
6489 + imported_die = follow_die_ref (die, attr, &cu);
6491 + sym = new_symbol (imported_die, NULL, cu);
6493 + if (sym && rename)
6494 + (sym)->ginfo.language_specific.cplus_specific.demangled_name = rename;
6497 /* Return the name of the namespace represented by DIE. Set
6498 @@ -5724,29 +6239,113 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
6499 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6500 struct type *type, *range_type, *index_type, *char_type;
6501 struct attribute *attr;
6502 - unsigned int length;
6505 + index_type = objfile_type (objfile)->builtin_int;
6506 + /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type. */
6507 + range_type = alloc_type (objfile, NULL);
6508 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
6509 + range_type = create_range_type (range_type, index_type, 0, -1);
6511 + /* C/C++ should probably have the low bound 0 but C/C++ does not use
6512 + DW_TAG_string_type. */
6513 + TYPE_LOW_BOUND (range_type) = 1;
6515 attr = dwarf2_attr (die, DW_AT_string_length, cu);
6518 - length = DW_UNSND (attr);
6519 + if (attr && attr_form_is_block (attr))
6521 + /* Security check for a size overflow. */
6522 + if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
6523 + TYPE_HIGH_BOUND (range_type) = 1;
6524 + /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
6525 + instruction as DW_AT_string_length specifies the length location, not
6529 + struct dwarf2_locexpr_baton *length_baton = NULL;
6530 + struct dwarf_block *blk = DW_BLOCK (attr);
6532 + /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
6533 + DW_OP_deref* in such case. */
6535 + if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
6536 + && blk->data[0] <= DW_OP_reg31)
6537 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
6538 + else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
6540 + ULONGEST ulongest;
6543 + end = read_uleb128 (&blk->data[1], &blk->data[blk->size],
6545 + if (end == &blk->data[blk->size])
6546 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
6549 + if (length_baton == NULL)
6551 + struct attribute *size_attr;
6553 + length_baton = obstack_alloc (&cu->comp_unit_obstack,
6554 + sizeof (*length_baton));
6555 + length_baton->per_cu = cu->per_cu;
6556 + length_baton->size = DW_BLOCK (attr)->size + 2;
6557 + length_baton->data = obstack_alloc (&cu->comp_unit_obstack,
6558 + length_baton->size);
6559 + memcpy (length_baton->data, DW_BLOCK (attr)->data,
6560 + DW_BLOCK (attr)->size);
6562 + /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
6563 + specifies the size of an integer to fetch. */
6564 + size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6567 + length_baton->data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
6568 + length_baton->data[DW_BLOCK (attr)->size + 1] =
6569 + DW_UNSND (size_attr);
6570 + if (length_baton->data[DW_BLOCK (attr)->size + 1]
6571 + != DW_UNSND (size_attr))
6572 + complaint (&symfile_complaints,
6573 + _("DW_AT_string_length's DW_AT_byte_size "
6574 + "integer exceeds the byte size storage"));
6578 + length_baton->data[DW_BLOCK (attr)->size] = DW_OP_deref;
6579 + length_baton->data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
6583 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6584 + TYPE_FIELD_DWARF_BLOCK (range_type, 1) = length_baton;
6585 + TYPE_DYNAMIC (range_type) = 1;
6590 - /* check for the DW_AT_byte_size attribute */
6591 + if (attr && attr_form_is_constant (attr))
6593 + /* We currently do not support a constant address where the location
6594 + should be read from - attr_form_is_block is expected instead. See
6595 + DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
6600 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6603 - length = DW_UNSND (attr);
6605 + if (attr && attr_form_is_block (attr))
6607 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6608 + TYPE_FIELD_DWARF_BLOCK (range_type, 1) =
6609 + dwarf2_attr_to_locexpr_baton (attr, cu);
6610 + TYPE_DYNAMIC (range_type) = 1;
6612 + else if (attr && attr_form_is_constant (attr))
6613 + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6618 + TYPE_HIGH_BOUND (range_type) = 1;
6621 - index_type = objfile_type (objfile)->builtin_int;
6622 - range_type = create_range_type (NULL, index_type, 1, length);
6623 char_type = language_string_char_type (cu->language_defn, gdbarch);
6624 type = create_string_type (NULL, char_type, range_type);
6626 @@ -5841,7 +6440,6 @@ static struct type *
6627 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
6629 struct objfile *objfile = cu->objfile;
6630 - struct attribute *attr;
6631 const char *name = NULL;
6632 struct type *this_type;
6634 @@ -5949,8 +6547,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6635 struct type *base_type;
6636 struct type *range_type;
6637 struct attribute *attr;
6643 base_type = die_type (die, cu);
6644 @@ -5963,42 +6560,89 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
6645 0, NULL, cu->objfile);
6648 - if (cu->language == language_fortran)
6650 - /* FORTRAN implies a lower bound of 1, if not given. */
6653 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
6654 + range_type = create_range_type (NULL, base_type, 0, -1);
6656 - /* FIXME: For variable sized arrays either of these could be
6657 - a variable rather than a constant value. We'll allow it,
6658 - but we don't know how to handle it. */
6659 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
6661 - low = dwarf2_get_attr_constant_value (attr, 0);
6662 + if (attr && attr_form_is_block (attr))
6664 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 0);
6665 + TYPE_FIELD_DWARF_BLOCK (range_type, 0) = dwarf2_attr_to_locexpr_baton
6667 + TYPE_DYNAMIC (range_type) = 1;
6668 + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */
6673 + if (attr && attr_form_is_constant (attr))
6674 + low = dwarf2_get_attr_constant_value (attr, 0);
6677 + if (cu->language == language_fortran)
6679 + /* FORTRAN implies a lower bound of 1, if not given. */
6684 + /* According to DWARF we should assume the value 0 only for
6685 + LANGUAGE_C and LANGUAGE_CPLUS. */
6689 + TYPE_LOW_BOUND (range_type) = low;
6691 + TYPE_UNSIGNED (range_type) = 1;
6694 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
6697 - if (attr->form == DW_FORM_block1)
6699 - /* GCC encodes arrays with unspecified or dynamic length
6700 - with a DW_FORM_block1 attribute.
6701 - FIXME: GDB does not yet know how to handle dynamic
6702 - arrays properly, treat them as arrays with unspecified
6705 - FIXME: jimb/2003-09-22: GDB does not really know
6706 - how to handle arrays of unspecified length
6707 - either; we just represent them as zero-length
6708 - arrays. Choose an appropriate upper bound given
6709 - the lower bound we've computed above. */
6712 + if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)))
6714 + attr = dwarf2_attr (die, DW_AT_count, cu);
6715 + /* It does not hurt but it is needlessly ineffective in check_typedef. */
6716 + if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
6718 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
6719 + TYPE_DYNAMIC (range_type) = 1;
6721 + /* Pass it now as the regular DW_AT_upper_bound. */
6724 + if (attr && attr_form_is_block (attr))
6726 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 1);
6727 + TYPE_FIELD_DWARF_BLOCK (range_type, 1) = dwarf2_attr_to_locexpr_baton
6729 + TYPE_DYNAMIC (range_type) = 1;
6733 + if (attr && attr_form_is_constant (attr))
6734 + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6736 - high = dwarf2_get_attr_constant_value (attr, 1);
6738 + TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type) = 1;
6739 + TYPE_HIGH_BOUND (range_type) = low - 1;
6743 - range_type = create_range_type (NULL, base_type, low, high);
6744 + /* DW_AT_bit_stride is currently unsupported as we count in bytes. */
6745 + attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
6746 + if (attr && attr_form_is_block (attr))
6748 + TYPE_RANGE_BOUND_SET_DWARF_BLOCK (range_type, 2);
6749 + TYPE_FIELD_DWARF_BLOCK (range_type, 2) = dwarf2_attr_to_locexpr_baton
6751 + TYPE_DYNAMIC (range_type) = 1;
6753 + else if (attr && attr_form_is_constant (attr))
6755 + TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
6756 + if (TYPE_BYTE_STRIDE (range_type) == 0)
6757 + complaint (&symfile_complaints,
6758 + _("Found DW_AT_byte_stride with unsupported value 0"));
6761 name = dwarf2_name (die, cu);
6763 @@ -6469,6 +7113,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
6764 && abbrev->tag != DW_TAG_lexical_block
6765 && abbrev->tag != DW_TAG_variable
6766 && abbrev->tag != DW_TAG_namespace
6767 + && abbrev->tag != DW_TAG_module
6768 && abbrev->tag != DW_TAG_member)
6770 /* Otherwise we skip to the next sibling, if any. */
6771 @@ -6689,9 +7334,6 @@ read_partial_die (struct partial_die_info *part_die,
6772 if (part_die->dirname == NULL)
6773 part_die->dirname = DW_STRING (&attr);
6775 - case DW_AT_MIPS_linkage_name:
6776 - part_die->name = DW_STRING (&attr);
6779 has_low_pc_attr = 1;
6780 part_die->lowpc = DW_ADDR (&attr);
6781 @@ -6923,7 +7565,8 @@ fixup_partial_die (struct partial_die_info *part_die,
6782 /* If we found a reference attribute and the DIE has no name, try
6783 to find a name in the referred to DIE. */
6785 - if (part_die->name == NULL && part_die->has_specification)
6786 + if (part_die->has_specification
6787 + && (part_die->name == NULL || !part_die->is_external))
6789 struct partial_die_info *spec_die;
6791 @@ -8265,10 +8908,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
6792 (i.e. when the value of a register or memory location is
6793 referenced, or a thread-local block, etc.). Then again, it might
6794 not be worthwhile. I'm assuming that it isn't unless performance
6795 - or memory numbers show me otherwise. */
6796 + or memory numbers show me otherwise.
6798 + SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed. */
6800 - dwarf2_symbol_mark_computed (attr, sym, cu);
6801 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6802 + dwarf2_symbol_mark_computed (attr, sym, cu);
6805 /* Given a pointer to a DWARF information entry, figure out if we need
6806 @@ -8290,21 +8935,30 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6808 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6810 - if (die->tag != DW_TAG_namespace)
6811 - name = dwarf2_linkage_name (die, cu);
6813 - name = TYPE_NAME (type);
6815 + name = dwarf2_name (die, cu);
6818 + const char *linkagename;
6820 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6821 sizeof (struct symbol));
6822 OBJSTAT (objfile, n_syms++);
6823 memset (sym, 0, sizeof (struct symbol));
6824 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
6825 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
6827 - /* Cache this symbol's name and the name's demangled form (if any). */
6828 SYMBOL_LANGUAGE (sym) = cu->language;
6829 - SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6831 + /* Cache this symbol's name and the name's demangled form (if any). */
6833 + linkagename = dwarf2_physname (die, cu);
6834 + SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), objfile);
6835 + if (cu->language == language_fortran)
6837 + (sym)->ginfo.language_specific.cplus_specific.demangled_name =
6838 + SYMBOL_LINKAGE_NAME (sym);
6839 + SYMBOL_LINKAGE_NAME (sym) = fortran_module_linkage_name (die, cu);
6842 /* Default assumptions.
6843 Use the passed type or decode it from the die. */
6844 @@ -8402,9 +9056,28 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6847 var_decode_location (attr, sym, cu);
6849 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6851 + /* Fortran explicitely imports any global symbols to the local
6852 + scope by DW_TAG_common_block. */
6853 + if (cu->language == language_fortran && die->parent
6854 + && die->parent->tag == DW_TAG_common_block)
6857 if (attr2 && (DW_UNSND (attr2) != 0))
6858 - add_symbol_to_list (sym, &global_symbols);
6860 + /* Workaround gfortran PR debug/40040 - it uses
6861 + DW_AT_location for variables in -fPIC libraries which may
6862 + get overriden by other libraries/executable and get
6863 + a different address. Resolve it by .dynsym instead. */
6865 + if (cu->language == language_fortran && die->parent
6866 + && die->parent->tag == DW_TAG_module)
6867 + SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6869 + add_symbol_to_list (sym, &global_symbols);
6872 add_symbol_to_list (sym, cu->list_in_scope);
6874 @@ -8534,7 +9207,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6875 add_symbol_to_list (sym, cu->list_in_scope);
6877 case DW_TAG_enumerator:
6878 - SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu);
6879 + SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_name (die, cu);
6880 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6883 @@ -8558,6 +9231,16 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6884 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6885 add_symbol_to_list (sym, &global_symbols);
6887 + case DW_TAG_common_block:
6888 + SYMBOL_CLASS (sym) = LOC_STATIC;
6889 + SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
6890 + add_symbol_to_list (sym, cu->list_in_scope);
6892 + case DW_TAG_module:
6893 + SYMBOL_CLASS (sym) = LOC_STATIC;
6894 + SYMBOL_DOMAIN (sym) = MODULE_DOMAIN;
6895 + add_symbol_to_list (sym, &global_symbols);
6898 /* Not a tag we recognize. Hopefully we aren't processing
6899 trash data, but since we must specifically ignore things
6900 @@ -8571,8 +9254,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6901 /* For the benefit of old versions of GCC, check for anonymous
6902 namespaces based on the demangled name. */
6903 if (!processing_has_namespace_info
6904 - && cu->language == language_cplus
6905 - && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL)
6906 + && cu->language == language_cplus)
6907 cp_scan_for_anonymous_namespaces (sym);
6910 @@ -8823,12 +9505,18 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6911 case DW_TAG_namespace:
6912 this_type = read_namespace_type (die, cu);
6914 + case DW_TAG_module:
6915 + this_type = read_module_type (die, cu);
6918 complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"),
6919 dwarf_tag_name (die->tag));
6924 + finalize_type (this_type);
6929 @@ -8910,10 +9598,100 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6930 So it does not need a prefix. */
6933 - return determine_prefix (parent, cu);
6934 + return determine_prefix (parent, cu);
6938 +/* Determines the prefix for a symbol's physname. Unlike determine_prefix,
6939 + this method does not simply look at the DIE's immediate parent.
6940 + It will compute the symbol's physname by scanning through all parent
6941 + DIEs until it gets to the compilation unit's DIE. */
6944 +physname_prefix (struct die_info *die, struct dwarf2_cu *cu)
6947 + struct ui_file *buf;
6948 + struct die_info *d, *spec_die;
6949 + struct dwarf2_cu *spec_cu;
6952 + /* Construct a stack containing all of the DIE's parents. Caution
6953 + must be observed for dealing with DW_AT_specification. */
6955 + spec_die = die_specification (die, &spec_cu);
6956 + if (spec_die != NULL)
6957 + d = spec_die->parent;
6960 + while (d != NULL && d->tag != DW_TAG_compile_unit)
6962 + struct attribute *attr;
6964 + spec_die = die_specification (d, &spec_cu);
6965 + if (spec_die != NULL)
6968 + VEC_quick_push (die_info_p, die_list, d);
6972 + /* Now pop all the elements, printing their names as we go. */
6973 + buf = mem_fileopen ();
6974 + while (!VEC_empty (die_info_p, die_list))
6976 + d = VEC_pop (die_info_p, die_list);
6977 + physname_prefix_1 (buf, d, cu);
6979 + if (!VEC_empty (die_info_p, die_list))
6981 + if (cu->language == language_cplus)
6982 + fputs_unfiltered ("::", buf);
6984 + fputs_unfiltered (".", buf);
6988 + name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, &length);
6989 + ui_file_delete (buf);
6994 +physname_prefix_1 (struct ui_file *buf, struct die_info *die,
6995 + struct dwarf2_cu *cu)
6997 + const char *name = NULL;
6998 + gdb_assert (buf != NULL);
7004 + case DW_TAG_namespace:
7005 + name = dwarf2_name (die, cu);
7007 + name = "(anonymous namespace)";
7010 + case DW_TAG_class_type:
7011 + case DW_TAG_structure_type:
7012 + case DW_TAG_union_type:
7013 + case DW_TAG_enumeration_type:
7014 + case DW_TAG_interface_type:
7015 + case DW_TAG_subprogram:
7016 + name = dwarf2_name (die, cu);
7025 + fputs_unfiltered (name, buf);
7028 /* Return a newly-allocated string formed by concatenating PREFIX and
7029 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7030 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7031 @@ -8963,17 +9741,111 @@ sibling_die (struct die_info *die)
7032 return die->sibling;
7035 -/* Get linkage name of a die, return NULL if not found. */
7036 +/* Construct a physname for the given DIE in CU. */
7039 -dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7040 +dwarf2_physname (struct die_info *die, struct dwarf2_cu *cu)
7042 struct attribute *attr;
7045 + name = dwarf2_name (die, cu);
7047 + /* These are the only languages we know how to qualify names in. */
7048 + if (cu->language != language_cplus
7049 + && cu->language != language_java)
7052 + if (die_needs_namespace (die, cu))
7056 + struct ui_file *buf;
7058 + prefix = physname_prefix (die, cu);
7059 + buf = mem_fileopen ();
7060 + if (*prefix != '\0')
7062 + char *prefixed_name = typename_concat (NULL, prefix, name, cu);
7063 + fputs_unfiltered (prefixed_name, buf);
7064 + xfree (prefixed_name);
7067 + fputs_unfiltered (name ? name : "", buf);
7069 + /* For Java and C++ methods, append formal parameter type
7071 + if ((cu->language == language_cplus || cu->language == language_java)
7072 + && die->tag == DW_TAG_subprogram)
7074 + struct type *type = read_type_die (die, cu);
7076 + c_type_print_args (type, buf, 0, cu->language);
7078 + if (cu->language == language_java)
7080 + /* For java, we must append the return type to method names. */
7081 + if (die->tag == DW_TAG_subprogram)
7082 + java_print_type (TYPE_TARGET_TYPE (type), "", buf, 0, 0);
7084 + else if (cu->language == language_cplus)
7086 + /* c_type_print_args adds argument types, but it does
7087 + not add any necessary "const". */
7088 + if (TYPE_NFIELDS (type) > 0 && TYPE_FIELD_ARTIFICIAL (type, 0)
7089 + && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))))
7090 + fputs_unfiltered (" const", buf);
7094 + name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
7096 + ui_file_delete (buf);
7098 + if (cu->language == language_cplus)
7101 + = dwarf2_canonicalize_name (name, cu,
7102 + &cu->objfile->objfile_obstack);
7103 + if (cname != NULL)
7111 +/* Return the fully qualified .symtab name for symbols contained in Fortran
7112 + modules. Return DWARF2_NAME otherwise. */
7115 +fortran_module_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7119 + gdb_assert (cu->language == language_fortran);
7121 + name = dwarf2_name (die, cu);
7123 + if (name && die->parent && die->parent->tag == DW_TAG_module)
7125 + char *module_name = dwarf2_name (die->parent, cu);
7131 - attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7132 - if (attr && DW_STRING (attr))
7133 - return DW_STRING (attr);
7134 - return dwarf2_name (die, cu);
7135 + /* `__modulename_MOD_variablename0'. */
7136 + retval = obstack_alloc (&cu->objfile->objfile_obstack,
7137 + 2 + strlen (module_name) + 5 + strlen (name)
7139 + sprintf (retval, "__%s_MOD_%s", module_name, name);
7148 /* Get name of a die, return NULL if not found. */
7149 @@ -10200,11 +11072,11 @@ dwarf2_get_ref_die_offset (struct attribute *attr)
7153 -/* Return the constant value held by the given attribute. Return -1
7154 +/* Return the constant value held by the given attribute. Return DEFAULT_VALUE
7155 if the value held by the attribute is not constant. */
7158 -dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7160 +dwarf2_get_attr_constant_value (struct attribute *attr, CORE_ADDR default_value)
7162 if (attr->form == DW_FORM_sdata)
7163 return DW_SND (attr);
7164 @@ -11009,8 +11881,6 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7166 gdb_byte *mac_ptr, *mac_end;
7167 struct macro_source_file *current_file = 0;
7168 - enum dwarf_macinfo_record_type macinfo_type;
7169 - int at_commandline;
7171 if (dwarf2_per_objfile->macinfo.buffer == NULL)
7173 @@ -11018,29 +11888,19 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7177 - /* First pass: Find the name of the base filename.
7178 - This filename is needed in order to process all macros whose definition
7179 - (or undefinition) comes from the command line. These macros are defined
7180 - before the first DW_MACINFO_start_file entry, and yet still need to be
7181 - associated to the base file.
7183 - To determine the base file name, we scan the macro definitions until we
7184 - reach the first DW_MACINFO_start_file entry. We then initialize
7185 - CURRENT_FILE accordingly so that any macro definition found before the
7186 - first DW_MACINFO_start_file can still be associated to the base file. */
7188 mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
7189 mac_end = dwarf2_per_objfile->macinfo.buffer
7190 + dwarf2_per_objfile->macinfo.size;
7195 + enum dwarf_macinfo_record_type macinfo_type;
7197 /* Do we at least have room for a macinfo type byte? */
7198 if (mac_ptr >= mac_end)
7200 - /* Complaint is printed during the second pass as GDB will probably
7201 - stop the first pass earlier upon finding DW_MACINFO_start_file. */
7203 + dwarf2_macros_too_long_complaint ();
7207 macinfo_type = read_1_byte (abfd, mac_ptr);
7208 @@ -11051,92 +11911,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7209 /* A zero macinfo type indicates the end of the macro
7214 - case DW_MACINFO_define:
7215 - case DW_MACINFO_undef:
7216 - /* Only skip the data by MAC_PTR. */
7218 - unsigned int bytes_read;
7220 - read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7221 - mac_ptr += bytes_read;
7222 - read_string (abfd, mac_ptr, &bytes_read);
7223 - mac_ptr += bytes_read;
7227 - case DW_MACINFO_start_file:
7229 - unsigned int bytes_read;
7232 - line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7233 - mac_ptr += bytes_read;
7234 - file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7235 - mac_ptr += bytes_read;
7237 - current_file = macro_start_file (file, line, current_file, comp_dir,
7242 - case DW_MACINFO_end_file:
7243 - /* No data to skip by MAC_PTR. */
7246 - case DW_MACINFO_vendor_ext:
7247 - /* Only skip the data by MAC_PTR. */
7249 - unsigned int bytes_read;
7251 - read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7252 - mac_ptr += bytes_read;
7253 - read_string (abfd, mac_ptr, &bytes_read);
7254 - mac_ptr += bytes_read;
7261 - } while (macinfo_type != 0 && current_file == NULL);
7263 - /* Second pass: Process all entries.
7265 - Use the AT_COMMAND_LINE flag to determine whether we are still processing
7266 - command-line macro definitions/undefinitions. This flag is unset when we
7267 - reach the first DW_MACINFO_start_file entry. */
7269 - mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset;
7271 - /* Determines if GDB is still before first DW_MACINFO_start_file. If true
7272 - GDB is still reading the definitions from command line. First
7273 - DW_MACINFO_start_file will need to be ignored as it was already executed
7274 - to create CURRENT_FILE for the main source holding also the command line
7275 - definitions. On first met DW_MACINFO_start_file this flag is reset to
7276 - normally execute all the remaining DW_MACINFO_start_file macinfos. */
7278 - at_commandline = 1;
7282 - /* Do we at least have room for a macinfo type byte? */
7283 - if (mac_ptr >= mac_end)
7285 - dwarf2_macros_too_long_complaint ();
7289 - macinfo_type = read_1_byte (abfd, mac_ptr);
7292 - switch (macinfo_type)
7294 - /* A zero macinfo type indicates the end of the macro
7300 case DW_MACINFO_define:
7301 case DW_MACINFO_undef:
7302 @@ -11151,31 +11926,19 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7303 mac_ptr += bytes_read;
7307 - /* DWARF violation as no main source is present. */
7308 - complaint (&symfile_complaints,
7309 - _("debug info with no main source gives macro %s "
7310 - "on line %d: %s"),
7312 - DW_MACINFO_define ? _("definition") : macinfo_type ==
7313 - DW_MACINFO_undef ? _("undefinition") :
7314 - "something-or-other", line, body);
7317 - if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
7318 complaint (&symfile_complaints,
7319 - _("debug info gives %s macro %s with %s line %d: %s"),
7320 - at_commandline ? _("command-line") : _("in-file"),
7321 + _("debug info gives macro %s outside of any file: %s"),
7323 - DW_MACINFO_define ? _("definition") : macinfo_type ==
7324 - DW_MACINFO_undef ? _("undefinition") :
7325 - "something-or-other",
7326 - line == 0 ? _("zero") : _("non-zero"), line, body);
7328 - if (macinfo_type == DW_MACINFO_define)
7329 - parse_macro_definition (current_file, line, body);
7330 - else if (macinfo_type == DW_MACINFO_undef)
7331 - macro_undef (current_file, line, body);
7332 + DW_MACINFO_define ? "definition" : macinfo_type ==
7333 + DW_MACINFO_undef ? "undefinition" :
7334 + "something-or-other", body);
7337 + if (macinfo_type == DW_MACINFO_define)
7338 + parse_macro_definition (current_file, line, body);
7339 + else if (macinfo_type == DW_MACINFO_undef)
7340 + macro_undef (current_file, line, body);
7345 @@ -11189,22 +11952,9 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7346 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7347 mac_ptr += bytes_read;
7349 - if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
7350 - complaint (&symfile_complaints,
7351 - _("debug info gives source %d included "
7352 - "from %s at %s line %d"),
7353 - file, at_commandline ? _("command-line") : _("file"),
7354 - line == 0 ? _("zero") : _("non-zero"), line);
7356 - if (at_commandline)
7358 - /* This DW_MACINFO_start_file was executed in the pass one. */
7359 - at_commandline = 0;
7362 - current_file = macro_start_file (file, line,
7363 - current_file, comp_dir,
7365 + current_file = macro_start_file (file, line,
7366 + current_file, comp_dir,
7371 @@ -11258,7 +12008,7 @@ dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7375 - } while (macinfo_type != 0);
7379 /* Check if the attribute's form is a DW_FORM_block*
7380 @@ -11318,6 +12068,34 @@ attr_form_is_constant (struct attribute *attr)
7384 +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton. ATTR must be a DW_BLOCK
7385 + attribute type. */
7387 +static struct dwarf2_locexpr_baton *
7388 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
7390 + struct dwarf2_locexpr_baton *baton;
7392 + gdb_assert (attr_form_is_block (attr));
7394 + baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton));
7395 + baton->per_cu = cu->per_cu;
7396 + gdb_assert (baton->per_cu);
7398 + /* Note that we're just copying the block's data pointer
7399 + here, not the actual data. We're still pointing into the
7400 + info_buffer for SYM's objfile; right now we never release
7401 + that buffer, but when we do clean up properly this may
7402 + need to change. */
7403 + baton->size = DW_BLOCK (attr)->size;
7404 + baton->data = DW_BLOCK (attr)->data;
7405 + gdb_assert (baton->size == 0 || baton->data != NULL);
7410 +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content. */
7413 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7414 struct dwarf2_cu *cu)
7415 @@ -11347,35 +12125,25 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7416 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
7417 SYMBOL_LOCATION_BATON (sym) = baton;
7419 + else if (attr_form_is_block (attr))
7421 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
7422 + SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
7426 - struct dwarf2_locexpr_baton *baton;
7427 + dwarf2_invalid_attrib_class_complaint ("location description",
7428 + SYMBOL_NATURAL_NAME (sym));
7430 - baton = obstack_alloc (&cu->objfile->objfile_obstack,
7431 - sizeof (struct dwarf2_locexpr_baton));
7432 - baton->per_cu = cu->per_cu;
7433 - gdb_assert (baton->per_cu);
7434 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
7436 - if (attr_form_is_block (attr))
7438 - /* Note that we're just copying the block's data pointer
7439 - here, not the actual data. We're still pointing into the
7440 - info_buffer for SYM's objfile; right now we never release
7441 - that buffer, but when we do clean up properly this may
7442 - need to change. */
7443 - baton->size = DW_BLOCK (attr)->size;
7444 - baton->data = DW_BLOCK (attr)->data;
7448 - dwarf2_invalid_attrib_class_complaint ("location description",
7449 - SYMBOL_NATURAL_NAME (sym));
7451 - baton->data = NULL;
7454 - SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
7455 - SYMBOL_LOCATION_BATON (sym) = baton;
7456 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
7457 + SYMBOL_LOCATION_BATON (sym) = NULL;
7459 + /* For functions a missing DW_AT_frame_base does not optimize out the
7460 + whole function definition, only its frame base resolving. */
7461 + if (attr->name == DW_AT_location)
7462 + SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
7466 @@ -11663,6 +12431,31 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
7467 return ofs_lhs->offset == ofs_rhs->offset;
7470 +/* Fill in generic attributes applicable for type DIEs. */
7473 +fetch_die_type_attrs (struct die_info *die, struct type *type,
7474 + struct dwarf2_cu *cu)
7476 + struct attribute *attr;
7478 + attr = dwarf2_attr (die, DW_AT_data_location, cu);
7479 + if (attr_form_is_block (attr))
7480 + TYPE_DATA_LOCATION_DWARF_BLOCK (type) = dwarf2_attr_to_locexpr_baton (attr,
7482 + gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
7484 + attr = dwarf2_attr (die, DW_AT_allocated, cu);
7485 + if (attr_form_is_block (attr))
7486 + TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
7487 + gdb_assert (!TYPE_NOT_ALLOCATED (type));
7489 + attr = dwarf2_attr (die, DW_AT_associated, cu);
7490 + if (attr_form_is_block (attr))
7491 + TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
7492 + gdb_assert (!TYPE_NOT_ASSOCIATED (type));
7495 /* Set the type associated with DIE to TYPE. Save it in CU's hash
7496 table if necessary. For convenience, return TYPE. */
7498 @@ -11671,6 +12464,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
7500 struct dwarf2_offset_and_type **slot, ofs;
7502 + fetch_die_type_attrs (die, type, cu);
7504 if (cu->type_hash == NULL)
7506 gdb_assert (cu->per_cu != NULL);
7507 @@ -11813,23 +12608,13 @@ show_dwarf2_cmd (char *args, int from_tty)
7508 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
7511 -/* If section described by INFO was mmapped, munmap it now. */
7512 +/* A helper function to destroy a debug section. */
7515 -munmap_section_buffer (struct dwarf2_section_info *info)
7516 +destroy_section (struct dwarf2_section_info *info)
7518 - if (info->was_mmapped)
7521 - intptr_t begin = (intptr_t) info->buffer;
7522 - intptr_t map_begin = begin & ~(pagesize - 1);
7523 - size_t map_length = info->size + begin - map_begin;
7524 - gdb_assert (munmap ((void *) map_begin, map_length) == 0);
7526 - /* Without HAVE_MMAP, we should never be here to begin with. */
7530 + if (info->destructor)
7531 + (*info->destructor) (info);
7534 /* munmap debug sections for OBJFILE, if necessary. */
7535 @@ -11838,15 +12623,15 @@ static void
7536 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
7538 struct dwarf2_per_objfile *data = d;
7539 - munmap_section_buffer (&data->info);
7540 - munmap_section_buffer (&data->abbrev);
7541 - munmap_section_buffer (&data->line);
7542 - munmap_section_buffer (&data->str);
7543 - munmap_section_buffer (&data->macinfo);
7544 - munmap_section_buffer (&data->ranges);
7545 - munmap_section_buffer (&data->loc);
7546 - munmap_section_buffer (&data->frame);
7547 - munmap_section_buffer (&data->eh_frame);
7548 + destroy_section (&data->info);
7549 + destroy_section (&data->abbrev);
7550 + destroy_section (&data->line);
7551 + destroy_section (&data->str);
7552 + destroy_section (&data->macinfo);
7553 + destroy_section (&data->ranges);
7554 + destroy_section (&data->loc);
7555 + destroy_section (&data->frame);
7556 + destroy_section (&data->eh_frame);
7559 void _initialize_dwarf2_read (void);
7560 @@ -11854,6 +12639,7 @@ void _initialize_dwarf2_read (void);
7562 _initialize_dwarf2_read (void)
7564 + die_list = VEC_alloc (die_info_p, 32);
7565 dwarf2_objfile_data_key
7566 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
7568 diff --git a/gdb/elfread.c b/gdb/elfread.c
7569 index 6e79d4a..198bae3 100644
7572 @@ -728,10 +728,18 @@ elf_symfile_read (struct objfile *objfile, int mainline)
7574 bfd_section_size (abfd, str_sect));
7577 + if (dwarf2_has_info (objfile))
7578 + dwarf2_create_quick_addrmap (objfile);
7582 +read_psyms (struct objfile *objfile)
7584 if (dwarf2_has_info (objfile))
7586 /* DWARF 2 sections */
7587 - dwarf2_build_psymtabs (objfile, mainline);
7588 + dwarf2_build_psymtabs (objfile, 0);
7591 /* FIXME: kettenis/20030504: This still needs to be integrated with
7592 @@ -881,6 +889,7 @@ static struct sym_fns elf_sym_fns =
7593 elf_new_init, /* sym_new_init: init anything gbl to entire symtab */
7594 elf_symfile_init, /* sym_init: read initial info, setup for sym_read() */
7595 elf_symfile_read, /* sym_read: read a symbol file into symtab */
7596 + read_psyms, /* sym_read_psymbols */
7597 elf_symfile_finish, /* sym_finish: finished with file, cleanup */
7598 default_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
7599 elf_symfile_segments, /* sym_segments: Get segment information from
7600 diff --git a/gdb/eval.c b/gdb/eval.c
7601 index 2926465..4c6de78 100644
7605 #include "exceptions.h"
7606 #include "regcache.h"
7607 #include "user-regs.h"
7608 +#include "python/python.h"
7609 #include "valprint.h"
7610 +#include "gdb_obstack.h"
7611 +#include "objfiles.h"
7612 #include "python/python.h"
7613 +#include "dwarf2loc.h"
7615 #include "gdb_assert.h"
7617 @@ -651,6 +655,36 @@ ptrmath_type_p (struct type *type)
7621 +/* Constructs a fake method with the given parameter types. */
7623 +free_param_types (void *arg)
7625 + struct type *type = (struct type *) arg;
7626 + xfree (TYPE_FIELDS (type));
7627 + xfree (TYPE_MAIN_TYPE (type));
7631 +static struct type *
7632 +make_params (int num_types, struct type **param_types)
7634 + struct type *type = XZALLOC (struct type);
7635 + TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
7636 + TYPE_LENGTH (type) = 1;
7637 + TYPE_CODE (type) = TYPE_CODE_METHOD;
7638 + TYPE_VPTR_FIELDNO (type) = -1;
7639 + TYPE_CHAIN (type) = type;
7640 + TYPE_NFIELDS (type) = num_types;
7641 + TYPE_FIELDS (type) = (struct field *)
7642 + TYPE_ZALLOC (type, sizeof (struct field) * num_types);
7644 + while (num_types-- > 0)
7645 + TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
7647 + make_cleanup (free_param_types, type);
7652 evaluate_subexp_standard (struct type *expect_type,
7653 struct expression *exp, int *pos,
7654 @@ -671,6 +705,7 @@ evaluate_subexp_standard (struct type *expect_type,
7656 struct type **arg_types;
7658 + struct cleanup *old_chain;
7661 op = exp->elts[pc].opcode;
7662 @@ -684,7 +719,7 @@ evaluate_subexp_standard (struct type *expect_type,
7664 arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
7665 &exp->elts[pc + 3].string,
7667 + expect_type, 0, noside);
7669 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7671 @@ -1293,7 +1328,6 @@ evaluate_subexp_standard (struct type *expect_type,
7672 argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 3));
7673 if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
7676 /* First, evaluate the structure into arg2 */
7679 @@ -1317,21 +1351,40 @@ evaluate_subexp_standard (struct type *expect_type,
7681 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7683 - if (TYPE_CODE (check_typedef (value_type (arg1)))
7684 - != TYPE_CODE_METHODPTR)
7685 - error (_("Non-pointer-to-member value used in pointer-to-member "
7688 - if (noside == EVAL_AVOID_SIDE_EFFECTS)
7689 + type = check_typedef (value_type (arg1));
7690 + switch (TYPE_CODE (type))
7692 - struct type *method_type = check_typedef (value_type (arg1));
7693 - arg1 = value_zero (method_type, not_lval);
7694 + case TYPE_CODE_METHODPTR:
7695 + if (noside == EVAL_AVOID_SIDE_EFFECTS)
7696 + arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
7698 + arg1 = cplus_method_ptr_to_value (&arg2, arg1);
7700 + /* Now, say which argument to start evaluating from */
7706 + case TYPE_CODE_MEMBERPTR:
7707 + /* Now, convert these values to an address. */
7708 + arg2 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
7711 + mem_offset = value_as_long (arg1);
7713 + arg1 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
7714 + value_as_long (arg2) + mem_offset);
7715 + arg1 = value_ind (arg1);
7720 + error (_("Non-pointer-to-member value used in pointer-to-member "
7724 - arg1 = cplus_method_ptr_to_value (&arg2, arg1);
7726 - /* Now, say which argument to start evaluating from */
7730 else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
7732 @@ -1457,8 +1510,7 @@ evaluate_subexp_standard (struct type *expect_type,
7734 else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
7738 + /* Pointer to member. argvec is already set up. */
7740 else if (op == OP_VAR_VALUE)
7742 @@ -1549,7 +1601,10 @@ evaluate_subexp_standard (struct type *expect_type,
7744 /* First determine the type code we are dealing with. */
7745 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7746 + old_chain = make_cleanup (null_cleanup, 0);
7747 + object_address_set (value_raw_address (arg1));
7748 type = check_typedef (value_type (arg1));
7749 + do_cleanups (old_chain);
7750 code = TYPE_CODE (type);
7752 if (code == TYPE_CODE_PTR)
7753 @@ -1716,6 +1771,37 @@ evaluate_subexp_standard (struct type *expect_type,
7754 error (_("non-pointer-to-member value used in pointer-to-member construct"));
7757 + case TYPE_INSTANCE:
7758 + nargs = longest_to_int (exp->elts[pc + 1].longconst);
7759 + arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
7760 + for (ix = 0; ix < nargs; ++ix)
7761 + arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
7763 + expect_type = make_params (nargs, arg_types);
7764 + *(pos) += 3 + nargs;
7765 + return evaluate_subexp_standard (expect_type, exp, pos, noside);
7767 + case TYPE_INSTANCE_LOOKUP:
7770 + struct symbol *sym;
7771 + struct type **arg_types;
7773 + printf ("TYPE_INSTANCE_LOOKUP\n");
7774 + arg_types = (struct type **) alloca (TYPE_NFIELDS (expect_type)
7775 + * sizeof (struct type *));
7776 + for (i = 0; i < TYPE_NFIELDS (expect_type); ++i)
7777 + arg_types[i] = TYPE_FIELD_TYPE (expect_type, i);
7778 + (void) find_overload_match (arg_types, TYPE_NFIELDS (expect_type),
7779 + NULL /* no need for name */,
7780 + 0 /* not method */,
7781 + 0 /* strict match */,
7782 + NULL, exp->elts[pc + 1].symbol, NULL,
7789 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
7790 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
7791 @@ -1987,13 +2073,19 @@ evaluate_subexp_standard (struct type *expect_type,
7793 int subscript_array[MAX_FORTRAN_DIMS];
7794 int array_size_array[MAX_FORTRAN_DIMS];
7795 + int byte_stride_array[MAX_FORTRAN_DIMS];
7796 int ndimensions = 1, i;
7797 struct type *tmp_type;
7798 int offset_item; /* The array offset where the item lives */
7799 + CORE_ADDR offset_byte; /* byte_stride based offset */
7800 + unsigned element_size;
7802 if (nargs > MAX_FORTRAN_DIMS)
7803 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
7805 + old_chain = make_cleanup (null_cleanup, 0);
7806 + object_address_set (value_raw_address (arg1));
7808 tmp_type = check_typedef (value_type (arg1));
7809 ndimensions = calc_f77_array_dims (type);
7811 @@ -2023,6 +2115,9 @@ evaluate_subexp_standard (struct type *expect_type,
7812 upper = f77_get_upperbound (tmp_type);
7813 lower = f77_get_lowerbound (tmp_type);
7815 + byte_stride_array[nargs - i - 1] =
7816 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
7818 array_size_array[nargs - i - 1] = upper - lower + 1;
7820 /* Zero-normalize subscripts so that offsetting will work. */
7821 @@ -2041,13 +2136,25 @@ evaluate_subexp_standard (struct type *expect_type,
7822 tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
7825 + /* Kept for the f77_get_upperbound / f77_get_lowerbound calls above. */
7826 + do_cleanups (old_chain);
7828 /* Now let us calculate the offset for this item */
7830 - offset_item = subscript_array[ndimensions - 1];
7834 + for (i = ndimensions - 1; i >= 0; --i)
7836 + offset_item *= array_size_array[i];
7837 + if (byte_stride_array[i] == 0)
7838 + offset_item += subscript_array[i];
7840 + offset_byte += subscript_array[i] * byte_stride_array[i];
7843 - for (i = ndimensions - 1; i > 0; --i)
7845 - array_size_array[i - 1] * offset_item + subscript_array[i - 1];
7846 + element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tmp_type));
7847 + offset_byte += offset_item * element_size;
7849 /* Let us now play a dirty trick: we will take arg1
7850 which is a value node pointing to the topmost level
7851 @@ -2057,7 +2164,7 @@ evaluate_subexp_standard (struct type *expect_type,
7852 returns the correct type value */
7854 deprecated_set_value_type (arg1, tmp_type);
7855 - return value_subscripted_rvalue (arg1, offset_item, 0);
7856 + return value_subscripted_rvalue (arg1, offset_byte);
7859 case BINOP_LOGICAL_AND:
7860 @@ -2598,7 +2705,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
7861 (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
7862 x = value_aggregate_elt (exp->elts[pc + 1].type,
7863 &exp->elts[pc + 3].string,
7867 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7869 @@ -2643,7 +2750,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
7873 - struct value *val;
7874 + struct value *val = NULL;
7878 @@ -2654,12 +2761,17 @@ evaluate_subexp_with_coercion (struct expression *exp,
7881 var = exp->elts[pc + 2].symbol;
7882 + /* address_of_variable will call object_address_set for check_typedef.
7883 + Call it only if required as it can error-out on VAR in register. */
7884 + if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
7885 + val = address_of_variable (var, exp->elts[pc + 1].block);
7886 type = check_typedef (SYMBOL_TYPE (var));
7887 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
7888 && CAST_IS_CONVERSION)
7891 - val = address_of_variable (var, exp->elts[pc + 1].block);
7893 + val = address_of_variable (var, exp->elts[pc + 1].block);
7894 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
7897 @@ -2711,9 +2823,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
7901 - type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
7903 - value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
7904 + /* We do not need to call read_var_value but the object evaluation may
7905 + need to have executed object_address_set which needs valid
7906 + SYMBOL_VALUE_ADDRESS of the symbol. Still VALUE returned by
7907 + read_var_value we left as lazy. */
7908 + type = value_type (read_var_value (exp->elts[pc + 2].symbol,
7909 + deprecated_safe_get_selected_frame ()));
7910 + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
7913 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
7914 diff --git a/gdb/expression.h b/gdb/expression.h
7915 index effe1f0..3e083ca 100644
7916 --- a/gdb/expression.h
7917 +++ b/gdb/expression.h
7918 @@ -88,6 +88,16 @@ enum exp_opcode
7919 when X is a pointer instead of an aggregate. */
7922 + /* TYPE_INSTANCE is used when the user specifies a specific
7923 + type instantiation for overloaded methods/functions. The format
7924 + is: TYPE_INSTANCE num_types type0 ... typeN num_types TYPE_INSTANCE*/
7927 + /* TYPE_INSTANCE_LOOKUP is used when the user specifies a specific
7928 + type instantiation of a function (not a method). In this case,
7929 + we must toss the results of the parser and manually do the lookup. */
7930 + TYPE_INSTANCE_LOOKUP,
7934 /* For Modula-2 integer division DIV */
7935 @@ -438,4 +448,5 @@ extern char *op_string (enum exp_opcode);
7936 extern void dump_raw_expression (struct expression *, struct ui_file *, char *);
7937 extern void dump_prefix_expression (struct expression *, struct ui_file *);
7940 #endif /* !defined (EXPRESSION_H) */
7941 diff --git a/gdb/f-exp.y b/gdb/f-exp.y
7942 index c04c8f4..ddcd460 100644
7945 @@ -196,6 +196,7 @@ static int parse_number (char *, int, int, YYSTYPE *);
7946 /* Special type cases, put in to allow the parser to distinguish different
7948 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
7949 +%token LOGICAL_S8_KEYWORD
7950 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
7951 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
7952 %token BOOL_AND BOOL_OR BOOL_NOT
7953 @@ -606,6 +607,8 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */
7954 { $$ = parse_f_type->builtin_integer_s2; }
7956 { $$ = parse_f_type->builtin_character; }
7957 + | LOGICAL_S8_KEYWORD
7958 + { $$ = parse_f_type->builtin_logical_s8;}
7960 { $$ = parse_f_type->builtin_logical; }
7961 | LOGICAL_S2_KEYWORD
7962 @@ -858,6 +861,7 @@ static const struct token f77_keywords[] =
7963 { "integer_2", INT_S2_KEYWORD, BINOP_END },
7964 { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
7965 { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
7966 + { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END },
7967 { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
7968 { "integer", INT_KEYWORD, BINOP_END },
7969 { "logical", LOGICAL_KEYWORD, BINOP_END },
7970 diff --git a/gdb/f-lang.c b/gdb/f-lang.c
7971 index 19c1316..4cc2a40 100644
7976 #include "valprint.h"
7979 +#include "gdb_assert.h"
7982 /* Following is dubious stuff that had been in the xcoff reader. */
7983 @@ -55,20 +57,6 @@ typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR;
7984 /* Local functions */
7986 extern void _initialize_f_language (void);
7988 -static void clear_function_list (void);
7989 -static long get_bf_for_fcn (long);
7990 -static void clear_bf_list (void);
7991 -static void patch_all_commons_by_name (char *, CORE_ADDR, int);
7992 -static SAVED_F77_COMMON_PTR find_first_common_named (char *);
7993 -static void add_common_entry (struct symbol *);
7994 -static void add_common_block (char *, CORE_ADDR, int, char *);
7995 -static SAVED_FUNCTION *allocate_saved_function_node (void);
7996 -static SAVED_BF_PTR allocate_saved_bf_node (void);
7997 -static COMMON_ENTRY_PTR allocate_common_entry_node (void);
7998 -static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node (void);
7999 -static void patch_common_entries (SAVED_F77_COMMON_PTR, CORE_ADDR, int);
8002 static void f_printchar (int c, struct type *type, struct ui_file * stream);
8003 static void f_emit_char (int c, struct type *type,
8004 @@ -259,6 +247,7 @@ enum f_primitive_types {
8005 f_primitive_type_logical,
8006 f_primitive_type_logical_s1,
8007 f_primitive_type_logical_s2,
8008 + f_primitive_type_logical_s8,
8009 f_primitive_type_integer,
8010 f_primitive_type_integer_s2,
8011 f_primitive_type_real,
8012 @@ -289,6 +278,8 @@ f_language_arch_info (struct gdbarch *gdbarch,
8013 = builtin->builtin_logical_s1;
8014 lai->primitive_type_vector [f_primitive_type_logical_s2]
8015 = builtin->builtin_logical_s2;
8016 + lai->primitive_type_vector [f_primitive_type_logical_s8]
8017 + = builtin->builtin_logical_s8;
8018 lai->primitive_type_vector [f_primitive_type_real]
8019 = builtin->builtin_real;
8020 lai->primitive_type_vector [f_primitive_type_real_s8]
8021 @@ -306,6 +297,46 @@ f_language_arch_info (struct gdbarch *gdbarch,
8022 lai->bool_type_default = builtin->builtin_logical_s2;
8025 +/* Find if NAME is not contained in any of the Fortran modules imported by the
8026 + Fortran USE statement.
8028 + As Fortran has no nested blocks such lookup can be processed from
8029 + lookup_symbol_nonlocal - when no local blocks could satisfy the lookup. */
8031 +static struct symbol *
8032 +f_lookup_symbol_nonlocal (const char *name,
8033 + const struct block *block,
8034 + const domain_enum domain)
8036 + struct fortran_using *use;
8041 + for (use = BLOCK_FORTRAN_USE (block); use; use = use->next)
8043 + struct symbol *sym;
8044 + struct type *type;
8045 + struct symbol *retval;
8047 + sym = lookup_symbol_global (use->module_name, block, MODULE_DOMAIN);
8049 + /* Module name lookup should not fail with correct debug info. */
8053 + type = SYMBOL_TYPE (sym);
8054 + gdb_assert (TYPE_CODE (type) == TYPE_CODE_MODULE);
8055 + gdb_assert (TYPE_MODULE_BLOCK (type) != NULL);
8057 + retval = lookup_block_symbol (TYPE_MODULE_BLOCK (type), name, domain);
8065 /* This is declared in c-lang.h but it is silly to import that file for what
8066 is already just a hack. */
8067 extern int c_value_print (struct value *, struct ui_file *,
8068 @@ -333,7 +364,7 @@ const struct language_defn f_language_defn =
8069 c_value_print, /* FIXME */
8070 NULL, /* Language specific skip_trampoline */
8071 NULL, /* name_of_this */
8072 - basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8073 + f_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
8074 basic_lookup_transparent_type,/* lookup_transparent_type */
8075 NULL, /* Language specific symbol demangler */
8076 NULL, /* Language specific class_name_from_physname */
8077 @@ -372,6 +403,10 @@ build_fortran_types (struct gdbarch *gdbarch)
8078 = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1,
8081 + builtin_f_type->builtin_logical_s8
8082 + = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
8085 builtin_f_type->builtin_integer
8086 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0,
8088 @@ -418,395 +453,3 @@ _initialize_f_language (void)
8090 add_language (&f_language_defn);
8094 -static SAVED_BF_PTR
8095 -allocate_saved_bf_node (void)
8099 - new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
8103 -static SAVED_FUNCTION *
8104 -allocate_saved_function_node (void)
8106 - SAVED_FUNCTION *new;
8108 - new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
8112 -static SAVED_F77_COMMON_PTR
8113 -allocate_saved_f77_common_node (void)
8115 - SAVED_F77_COMMON_PTR new;
8117 - new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
8121 -static COMMON_ENTRY_PTR
8122 -allocate_common_entry_node (void)
8124 - COMMON_ENTRY_PTR new;
8126 - new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
8131 -SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */
8132 -SAVED_F77_COMMON_PTR tail_common_list = NULL; /* Ptr to last saved COMMON */
8133 -SAVED_F77_COMMON_PTR current_common = NULL; /* Ptr to current COMMON */
8136 -static SAVED_BF_PTR saved_bf_list = NULL; /* Ptr to (.bf,function)
8138 -static SAVED_BF_PTR saved_bf_list_end = NULL; /* Ptr to above list's end */
8139 -static SAVED_BF_PTR current_head_bf_list = NULL; /* Current head of above list
8142 -static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use
8145 -/* The following function simply enters a given common block onto
8146 - the global common block chain */
8149 -add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
8151 - SAVED_F77_COMMON_PTR tmp;
8152 - char *c, *local_copy_func_stab;
8154 - /* If the COMMON block we are trying to add has a blank
8155 - name (i.e. "#BLNK_COM") then we set it to __BLANK
8156 - because the darn "#" character makes GDB's input
8157 - parser have fits. */
8160 - if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
8161 - || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
8165 - name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
8166 - strcpy (name, BLANK_COMMON_NAME_LOCAL);
8169 - tmp = allocate_saved_f77_common_node ();
8171 - local_copy_func_stab = xmalloc (strlen (func_stab) + 1);
8172 - strcpy (local_copy_func_stab, func_stab);
8174 - tmp->name = xmalloc (strlen (name) + 1);
8176 - /* local_copy_func_stab is a stabstring, let us first extract the
8177 - function name from the stab by NULLing out the ':' character. */
8181 - c = strchr (local_copy_func_stab, ':');
8186 - error (_("Malformed function STAB found in add_common_block()"));
8189 - tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1);
8191 - strcpy (tmp->owning_function, local_copy_func_stab);
8193 - strcpy (tmp->name, name);
8194 - tmp->offset = offset;
8196 - tmp->entries = NULL;
8197 - tmp->secnum = secnum;
8199 - current_common = tmp;
8201 - if (head_common_list == NULL)
8203 - head_common_list = tail_common_list = tmp;
8207 - tail_common_list->next = tmp;
8208 - tail_common_list = tmp;
8213 -/* The following function simply enters a given common entry onto
8214 - the "current_common" block that has been saved away. */
8218 -add_common_entry (struct symbol *entry_sym_ptr)
8220 - COMMON_ENTRY_PTR tmp;
8224 - /* The order of this list is important, since
8225 - we expect the entries to appear in decl.
8226 - order when we later issue "info common" calls */
8228 - tmp = allocate_common_entry_node ();
8231 - tmp->symbol = entry_sym_ptr;
8233 - if (current_common == NULL)
8234 - error (_("Attempt to add COMMON entry with no block open!"));
8237 - if (current_common->entries == NULL)
8239 - current_common->entries = tmp;
8240 - current_common->end_of_entries = tmp;
8244 - current_common->end_of_entries->next = tmp;
8245 - current_common->end_of_entries = tmp;
8251 -/* This routine finds the first encountred COMMON block named "name" */
8254 -static SAVED_F77_COMMON_PTR
8255 -find_first_common_named (char *name)
8258 - SAVED_F77_COMMON_PTR tmp;
8260 - tmp = head_common_list;
8262 - while (tmp != NULL)
8264 - if (strcmp (tmp->name, name) == 0)
8273 -/* This routine finds the first encountred COMMON block named "name"
8274 - that belongs to function funcname */
8276 -SAVED_F77_COMMON_PTR
8277 -find_common_for_function (char *name, char *funcname)
8280 - SAVED_F77_COMMON_PTR tmp;
8282 - tmp = head_common_list;
8284 - while (tmp != NULL)
8286 - if (strcmp (tmp->name, name) == 0
8287 - && strcmp (tmp->owning_function, funcname) == 0)
8298 -/* The following function is called to patch up the offsets
8299 - for the statics contained in the COMMON block named
8303 -patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
8305 - COMMON_ENTRY_PTR entry;
8307 - blk->offset = offset; /* Keep this around for future use. */
8309 - entry = blk->entries;
8311 - while (entry != NULL)
8313 - SYMBOL_VALUE (entry->symbol) += offset;
8314 - SYMBOL_SECTION (entry->symbol) = secnum;
8316 - entry = entry->next;
8318 - blk->secnum = secnum;
8321 -/* Patch all commons named "name" that need patching.Since COMMON
8322 - blocks occur with relative infrequency, we simply do a linear scan on
8323 - the name. Eventually, the best way to do this will be a
8324 - hashed-lookup. Secnum is the section number for the .bss section
8325 - (which is where common data lives). */
8328 -patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
8331 - SAVED_F77_COMMON_PTR tmp;
8333 - /* For blank common blocks, change the canonical reprsentation
8334 - of a blank name */
8336 - if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
8337 - || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
8340 - name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
8341 - strcpy (name, BLANK_COMMON_NAME_LOCAL);
8344 - tmp = head_common_list;
8346 - while (tmp != NULL)
8348 - if (COMMON_NEEDS_PATCHING (tmp))
8349 - if (strcmp (tmp->name, name) == 0)
8350 - patch_common_entries (tmp, offset, secnum);
8357 -/* This macro adds the symbol-number for the start of the function
8358 - (the symbol number of the .bf) referenced by symnum_fcn to a
8359 - list. This list, in reality should be a FIFO queue but since
8360 - #line pragmas sometimes cause line ranges to get messed up
8361 - we simply create a linear list. This list can then be searched
8362 - first by a queueing algorithm and upon failure fall back to
8366 -#define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
8368 - if (saved_bf_list == NULL) \
8370 - tmp_bf_ptr = allocate_saved_bf_node(); \
8372 - tmp_bf_ptr->symnum_bf = (bf_sym); \
8373 - tmp_bf_ptr->symnum_fcn = (fcn_sym); \
8374 - tmp_bf_ptr->next = NULL; \
8376 - current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
8377 - saved_bf_list_end = tmp_bf_ptr; \
8381 - tmp_bf_ptr = allocate_saved_bf_node(); \
8383 - tmp_bf_ptr->symnum_bf = (bf_sym); \
8384 - tmp_bf_ptr->symnum_fcn = (fcn_sym); \
8385 - tmp_bf_ptr->next = NULL; \
8387 - saved_bf_list_end->next = tmp_bf_ptr; \
8388 - saved_bf_list_end = tmp_bf_ptr; \
8392 -/* This function frees the entire (.bf,function) list */
8396 -clear_bf_list (void)
8399 - SAVED_BF_PTR tmp = saved_bf_list;
8400 - SAVED_BF_PTR next = NULL;
8402 - while (tmp != NULL)
8408 - saved_bf_list = NULL;
8412 -int global_remote_debug;
8417 -get_bf_for_fcn (long the_function)
8422 - /* First use a simple queuing algorithm (i.e. look and see if the
8423 - item at the head of the queue is the one you want) */
8425 - if (saved_bf_list == NULL)
8426 - internal_error (__FILE__, __LINE__,
8427 - _("cannot get .bf node off empty list"));
8429 - if (current_head_bf_list != NULL)
8430 - if (current_head_bf_list->symnum_fcn == the_function)
8432 - if (global_remote_debug)
8433 - fprintf_unfiltered (gdb_stderr, "*");
8435 - tmp = current_head_bf_list;
8436 - current_head_bf_list = current_head_bf_list->next;
8437 - return (tmp->symnum_bf);
8440 - /* If the above did not work (probably because #line directives were
8441 - used in the sourcefile and they messed up our internal tables) we now do
8442 - the ugly linear scan */
8444 - if (global_remote_debug)
8445 - fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
8448 - tmp = saved_bf_list;
8449 - while (tmp != NULL)
8452 - if (tmp->symnum_fcn == the_function)
8454 - if (global_remote_debug)
8455 - fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes);
8456 - current_head_bf_list = tmp->next;
8457 - return (tmp->symnum_bf);
8465 -static SAVED_FUNCTION_PTR saved_function_list = NULL;
8466 -static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
8469 -clear_function_list (void)
8471 - SAVED_FUNCTION_PTR tmp = saved_function_list;
8472 - SAVED_FUNCTION_PTR next = NULL;
8474 - while (tmp != NULL)
8481 - saved_function_list = NULL;
8484 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
8485 index 711bdba..9d7d92b 100644
8488 @@ -28,6 +28,10 @@ extern void f_error (char *); /* Defined in f-exp.y */
8489 extern void f_print_type (struct type *, char *, struct ui_file *, int,
8492 +extern const char *f_object_address_data_valid_print_to_stream
8493 + (struct type *type, struct ui_file *stream);
8494 +extern void f_object_address_data_valid_or_error (struct type *type);
8496 extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
8497 struct ui_file *, int,
8498 const struct value_print_options *);
8499 @@ -47,41 +51,8 @@ enum f90_range_type
8500 NONE_BOUND_DEFAULT /* "(low:high)" */
8503 -struct common_entry
8505 - struct symbol *symbol; /* The symbol node corresponding
8506 - to this component */
8507 - struct common_entry *next; /* The next component */
8510 -struct saved_f77_common
8512 - char *name; /* Name of COMMON */
8513 - char *owning_function; /* Name of parent function */
8514 - int secnum; /* Section # of .bss */
8515 - CORE_ADDR offset; /* Offset from .bss for
8517 - struct common_entry *entries; /* List of block's components */
8518 - struct common_entry *end_of_entries; /* ptr. to end of components */
8519 - struct saved_f77_common *next; /* Next saved COMMON block */
8522 -typedef struct saved_f77_common SAVED_F77_COMMON, *SAVED_F77_COMMON_PTR;
8524 -typedef struct common_entry COMMON_ENTRY, *COMMON_ENTRY_PTR;
8526 -extern SAVED_F77_COMMON_PTR head_common_list; /* Ptr to 1st saved COMMON */
8527 -extern SAVED_F77_COMMON_PTR tail_common_list; /* Ptr to last saved COMMON */
8528 -extern SAVED_F77_COMMON_PTR current_common; /* Ptr to current COMMON */
8530 -extern SAVED_F77_COMMON_PTR find_common_for_function (char *, char *);
8532 -#define UNINITIALIZED_SECNUM -1
8533 -#define COMMON_NEEDS_PATCHING(blk) ((blk)->secnum == UNINITIALIZED_SECNUM)
8535 #define BLANK_COMMON_NAME_ORIGINAL "#BLNK_COM" /* XLF assigned */
8536 #define BLANK_COMMON_NAME_MF77 "__BLNK__" /* MF77 assigned */
8537 -#define BLANK_COMMON_NAME_LOCAL "__BLANK" /* Local GDB */
8539 /* When reasonable array bounds cannot be fetched, such as when
8540 you ask to 'mt print symbols' and there is no stack frame and
8541 @@ -113,6 +84,7 @@ struct builtin_f_type
8542 struct type *builtin_logical;
8543 struct type *builtin_logical_s1;
8544 struct type *builtin_logical_s2;
8545 + struct type *builtin_logical_s8;
8546 struct type *builtin_real;
8547 struct type *builtin_real_s8;
8548 struct type *builtin_real_s16;
8549 @@ -125,3 +97,10 @@ struct builtin_f_type
8550 /* Return the Fortran type table for the specified architecture. */
8551 extern const struct builtin_f_type *builtin_f_type (struct gdbarch *gdbarch);
8553 +/* List of module names being imported by a block though BLOCK_FORTRAN_USE. */
8555 +struct fortran_using
8557 + struct fortran_using *next;
8558 + char module_name[1];
8560 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
8561 index 6c9668f..852b9a8 100644
8562 --- a/gdb/f-typeprint.c
8563 +++ b/gdb/f-typeprint.c
8565 #include "gdbcore.h"
8569 +#include "dwarf2loc.h"
8570 #include "gdb_string.h"
8573 @@ -48,6 +48,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
8574 void f_type_print_base (struct type *, struct ui_file *, int, int);
8578 +f_object_address_data_valid_print_to_stream (struct type *type,
8579 + struct ui_file *stream)
8583 + msg = object_address_data_not_valid (type);
8586 + /* Assuming the content printed to STREAM should not be localized. */
8587 + fprintf_filtered (stream, "<%s>", msg);
8594 +f_object_address_data_valid_or_error (struct type *type)
8598 + msg = object_address_data_not_valid (type);
8601 + error (_("Cannot access it because the %s."), _(msg));
8605 /* LEVEL is the depth to indent lines by. */
8608 @@ -57,6 +85,9 @@ f_print_type (struct type *type, char *varstring, struct ui_file *stream,
8609 enum type_code code;
8612 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
8615 f_type_print_base (type, stream, show, level);
8616 code = TYPE_CODE (type);
8617 if ((varstring != NULL && *varstring != '\0')
8618 @@ -166,6 +197,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
8622 + if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
8623 + CHECK_TYPEDEF (type);
8625 switch (TYPE_CODE (type))
8627 case TYPE_CODE_ARRAY:
8628 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
8629 index 0a57404..a9ccc77 100644
8630 --- a/gdb/f-valprint.c
8631 +++ b/gdb/f-valprint.c
8633 #include "gdbcore.h"
8634 #include "command.h"
8638 -static int there_is_a_visible_common_named (char *);
8640 +#include "dictionary.h"
8641 +#include "gdb_assert.h"
8643 extern void _initialize_f_valprint (void);
8644 static void info_common_command (char *, int);
8645 @@ -54,15 +52,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
8646 /* The following macro gives us the size of the nth dimension, Where
8649 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
8650 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
8652 -/* The following gives us the offset for row n where n is 1-based. */
8653 +/* The following gives us the element size for row n where n is 1-based. */
8655 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
8656 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
8659 f77_get_lowerbound (struct type *type)
8661 + f_object_address_data_valid_or_error (type);
8663 if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
8664 error (_("Lower bound may not be '*' in F77"));
8666 @@ -72,14 +72,17 @@ f77_get_lowerbound (struct type *type)
8668 f77_get_upperbound (struct type *type)
8670 + f_object_address_data_valid_or_error (type);
8672 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
8674 - /* We have an assumed size array on our hands. Assume that
8675 - upper_bound == lower_bound so that we show at least 1 element.
8676 - If the user wants to see more elements, let him manually ask for 'em
8677 - and we'll subscript the array and show him. */
8678 + /* We have an assumed size array on our hands. As type_length_get
8679 + already assumes a length zero of arrays with underfined bounds VALADDR
8680 + passed to the Fortran functions does not contained the real inferior
8681 + memory content. User should request printing of specific array
8682 + elements instead. */
8684 - return f77_get_lowerbound (type);
8685 + return f77_get_lowerbound (type) - 1;
8688 return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
8689 @@ -135,24 +138,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
8690 upper = f77_get_upperbound (tmp_type);
8691 lower = f77_get_lowerbound (tmp_type);
8693 - F77_DIM_SIZE (ndimen) = upper - lower + 1;
8694 + F77_DIM_COUNT (ndimen) = upper - lower + 1;
8696 + F77_DIM_BYTE_STRIDE (ndimen) =
8697 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
8699 tmp_type = TYPE_TARGET_TYPE (tmp_type);
8703 - /* Now we multiply eltlen by all the offsets, so that later we
8704 + /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
8705 can print out array elements correctly. Up till now we
8706 - know an offset to apply to get the item but we also
8707 + know an eltlen to apply to get the item but we also
8708 have to know how much to add to get to the next item */
8711 eltlen = TYPE_LENGTH (tmp_type);
8712 - F77_DIM_OFFSET (ndimen) = eltlen;
8713 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
8714 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
8715 while (--ndimen > 0)
8717 - eltlen *= F77_DIM_SIZE (ndimen + 1);
8718 - F77_DIM_OFFSET (ndimen) = eltlen;
8719 + eltlen *= F77_DIM_COUNT (ndimen + 1);
8720 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
8721 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
8725 @@ -172,34 +180,34 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
8727 if (nss != ndimensions)
8729 - for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
8730 + for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
8732 fprintf_filtered (stream, "( ");
8733 f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
8734 - valaddr + i * F77_DIM_OFFSET (nss),
8735 - address + i * F77_DIM_OFFSET (nss),
8736 + valaddr + i * F77_DIM_BYTE_STRIDE (nss),
8737 + address + i * F77_DIM_BYTE_STRIDE (nss),
8738 stream, recurse, options, elts);
8739 fprintf_filtered (stream, ") ");
8741 - if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
8742 + if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
8743 fprintf_filtered (stream, "...");
8747 - for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
8748 + for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
8751 val_print (TYPE_TARGET_TYPE (type),
8752 - valaddr + i * F77_DIM_OFFSET (ndimensions),
8753 + valaddr + i * F77_DIM_BYTE_STRIDE (ndimensions),
8755 - address + i * F77_DIM_OFFSET (ndimensions),
8756 + address + i * F77_DIM_BYTE_STRIDE (ndimensions),
8757 stream, recurse, options, current_language);
8759 - if (i != (F77_DIM_SIZE (nss) - 1))
8760 + if (i != (F77_DIM_COUNT (nss) - 1))
8761 fprintf_filtered (stream, ", ");
8763 if ((*elts == options->print_max - 1)
8764 - && (i != (F77_DIM_SIZE (nss) - 1)))
8765 + && (i != (F77_DIM_COUNT (nss) - 1)))
8766 fprintf_filtered (stream, "...");
8769 @@ -253,6 +261,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
8773 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
8776 CHECK_TYPEDEF (type);
8777 switch (TYPE_CODE (type))
8779 @@ -467,22 +478,54 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
8784 -list_all_visible_commons (char *funname)
8786 +info_common_command_for_block (struct block *block, struct frame_info *frame,
8787 + const char *comname)
8789 - SAVED_F77_COMMON_PTR tmp;
8791 - tmp = head_common_list;
8793 - printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
8795 - while (tmp != NULL)
8797 - if (strcmp (tmp->owning_function, funname) == 0)
8798 - printf_filtered ("%s\n", tmp->name);
8802 + struct dict_iterator iter;
8803 + struct symbol *sym;
8804 + int values_printed = 0;
8806 + struct value_print_options opts;
8808 + get_user_print_options (&opts);
8810 + ALL_BLOCK_SYMBOLS (block, iter, sym)
8811 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
8813 + struct type *type = SYMBOL_TYPE (sym);
8816 + gdb_assert (SYMBOL_CLASS (sym) == LOC_STATIC);
8817 + gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
8819 + if (comname && (!SYMBOL_LINKAGE_NAME (sym)
8820 + || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
8823 + values_printed = 1;
8824 + if (SYMBOL_PRINT_NAME (sym))
8825 + printf_filtered (_("Contents of F77 COMMON block '%s':\n"),
8826 + SYMBOL_PRINT_NAME (sym));
8828 + printf_filtered (_("Contents of blank COMMON block:\n"));
8830 + for (index = 0; index < TYPE_NFIELDS (type); index++)
8832 + struct value *val;
8834 + gdb_assert (field_is_static (&TYPE_FIELD (type, index)));
8835 + val = value_static_field (type, index);
8837 + printf_filtered ("%s = ", TYPE_FIELD_NAME (type, index));
8838 + value_print (val, gdb_stdout, &opts);
8839 + putchar_filtered ('\n');
8842 + putchar_filtered ('\n');
8845 + return values_printed;
8848 /* This function is used to print out the values in a given COMMON
8849 @@ -492,11 +535,9 @@ list_all_visible_commons (char *funname)
8851 info_common_command (char *comname, int from_tty)
8853 - SAVED_F77_COMMON_PTR the_common;
8854 - COMMON_ENTRY_PTR entry;
8855 struct frame_info *fi;
8856 - char *funname = 0;
8857 - struct symbol *func;
8858 + struct block *block;
8859 + int values_printed = 0;
8861 /* We have been told to display the contents of F77 COMMON
8862 block supposedly visible in this function. Let us
8863 @@ -508,136 +549,32 @@ info_common_command (char *comname, int from_tty)
8864 /* The following is generally ripped off from stack.c's routine
8865 print_frame_info() */
8867 - func = find_pc_function (get_frame_pc (fi));
8870 - /* In certain pathological cases, the symtabs give the wrong
8871 - function (when we are in the first function in a file which
8872 - is compiled without debugging symbols, the previous function
8873 - is compiled with debugging symbols, and the "foo.o" symbol
8874 - that is supposed to tell us where the file with debugging symbols
8875 - ends has been truncated by ar because it is longer than 15
8878 - So look in the minimal symbol tables as well, and if it comes
8879 - up with a larger address for the function use that instead.
8880 - I don't think this can ever cause any problems; there shouldn't
8881 - be any minimal symbols in the middle of a function.
8882 - FIXME: (Not necessarily true. What about text labels) */
8884 - struct minimal_symbol *msymbol =
8885 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
8887 - if (msymbol != NULL
8888 - && (SYMBOL_VALUE_ADDRESS (msymbol)
8889 - > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
8890 - funname = SYMBOL_LINKAGE_NAME (msymbol);
8892 - funname = SYMBOL_LINKAGE_NAME (func);
8896 - struct minimal_symbol *msymbol =
8897 - lookup_minimal_symbol_by_pc (get_frame_pc (fi));
8899 - if (msymbol != NULL)
8900 - funname = SYMBOL_LINKAGE_NAME (msymbol);
8901 - else /* Got no 'funname', code below will fail. */
8902 - error (_("No function found for frame."));
8905 - /* If comname is NULL, we assume the user wishes to see the
8906 - which COMMON blocks are visible here and then return */
8909 + block = get_frame_block (fi, 0);
8910 + if (block == NULL)
8912 - list_all_visible_commons (funname);
8913 + printf_filtered (_("No symbol table info available.\n"));
8917 - the_common = find_common_for_function (comname, funname);
8922 - if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
8923 - printf_filtered (_("Contents of blank COMMON block:\n"));
8925 - printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
8927 - printf_filtered ("\n");
8928 - entry = the_common->entries;
8930 - while (entry != NULL)
8932 - print_variable_and_value (NULL, entry->symbol, fi, gdb_stdout, 0);
8933 - entry = entry->next;
8935 + if (info_common_command_for_block (block, fi, comname))
8936 + values_printed = 1;
8937 + /* After handling the function's top-level block, stop. Don't
8938 + continue to its superblock, the block of per-file symbols. */
8939 + if (BLOCK_FUNCTION (block))
8941 + block = BLOCK_SUPERBLOCK (block);
8944 - printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
8945 - comname, funname);
8948 -/* This function is used to determine whether there is a
8949 - F77 common block visible at the current scope called 'comname'. */
8953 -there_is_a_visible_common_named (char *comname)
8955 - SAVED_F77_COMMON_PTR the_common;
8956 - struct frame_info *fi;
8957 - char *funname = 0;
8958 - struct symbol *func;
8960 - if (comname == NULL)
8961 - error (_("Cannot deal with NULL common name!"));
8963 - fi = get_selected_frame (_("No frame selected"));
8965 - /* The following is generally ripped off from stack.c's routine
8966 - print_frame_info() */
8968 - func = find_pc_function (fi->pc);
8970 + if (!values_printed)
8972 - /* In certain pathological cases, the symtabs give the wrong
8973 - function (when we are in the first function in a file which
8974 - is compiled without debugging symbols, the previous function
8975 - is compiled with debugging symbols, and the "foo.o" symbol
8976 - that is supposed to tell us where the file with debugging symbols
8977 - ends has been truncated by ar because it is longer than 15
8980 - So look in the minimal symbol tables as well, and if it comes
8981 - up with a larger address for the function use that instead.
8982 - I don't think this can ever cause any problems; there shouldn't
8983 - be any minimal symbols in the middle of a function.
8984 - FIXME: (Not necessarily true. What about text labels) */
8986 - struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
8988 - if (msymbol != NULL
8989 - && (SYMBOL_VALUE_ADDRESS (msymbol)
8990 - > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
8991 - funname = SYMBOL_LINKAGE_NAME (msymbol);
8993 + printf_filtered (_("No common block '%s'.\n"), comname);
8995 - funname = SYMBOL_LINKAGE_NAME (func);
8996 + printf_filtered (_("No common blocks.\n"));
9000 - struct minimal_symbol *msymbol =
9001 - lookup_minimal_symbol_by_pc (fi->pc);
9003 - if (msymbol != NULL)
9004 - funname = SYMBOL_LINKAGE_NAME (msymbol);
9007 - the_common = find_common_for_function (comname, funname);
9009 - return (the_common ? 1 : 0);
9014 _initialize_f_valprint (void)
9015 diff --git a/gdb/findcmd.c b/gdb/findcmd.c
9016 index 1d28914..d176341 100644
9021 /* Copied from bfd_put_bits. */
9025 put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
9028 @@ -45,6 +45,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
9032 +/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
9033 + will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
9034 + place as *PATTERN_BUF, indicating that the buffer is initially empty. */
9037 +allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
9038 + ULONGEST *pattern_buf_size)
9040 +#define INITIAL_PATTERN_BUF_SIZE 100
9041 + *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
9042 + *pattern_buf = xmalloc (*pattern_buf_size);
9043 + *pattern_buf_end = *pattern_buf;
9046 +/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
9047 + VAL_BYTES more bytes or a 64-bit value, whichever is larger.
9048 + *PATTERN_BUF_END is updated as necessary. */
9051 +increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
9052 + ULONGEST *pattern_buf_size, int val_bytes)
9054 + /* Keep it simple and assume size == 'g' when watching for when we
9055 + need to grow the pattern buf. */
9056 + if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
9057 + > *pattern_buf_size)
9059 + size_t current_offset = *pattern_buf_end - *pattern_buf;
9061 + *pattern_buf_size *= 2;
9062 + *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
9063 + *pattern_buf_end = *pattern_buf + current_offset;
9067 /* Subroutine of find_command to simplify it.
9068 Parse the arguments of the "find" command. */
9070 @@ -61,8 +96,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
9072 /* Current size of search pattern buffer.
9073 We realloc space as needed. */
9074 -#define INITIAL_PATTERN_BUF_SIZE 100
9075 - ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
9076 + ULONGEST pattern_buf_size;
9077 /* Pointer to one past the last in-use part of pattern_buf. */
9078 char *pattern_buf_end;
9079 ULONGEST pattern_len;
9080 @@ -75,8 +109,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
9082 error (_("Missing search parameters."));
9084 - pattern_buf = xmalloc (pattern_buf_size);
9085 - pattern_buf_end = pattern_buf;
9086 + allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
9087 old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
9089 /* Get search granularity and/or max count if specified.
9090 @@ -173,16 +206,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
9091 v = parse_to_comma_and_eval (&s);
9092 val_bytes = TYPE_LENGTH (value_type (v));
9094 - /* Keep it simple and assume size == 'g' when watching for when we
9095 - need to grow the pattern buf. */
9096 - if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
9097 - > pattern_buf_size)
9099 - size_t current_offset = pattern_buf_end - pattern_buf;
9100 - pattern_buf_size *= 2;
9101 - pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
9102 - pattern_buf_end = pattern_buf + current_offset;
9104 + increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
9105 + &pattern_buf_size, val_bytes);
9109 @@ -237,6 +262,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
9110 discard_cleanups (old_cleanups);
9113 +/* Drives target_search_memory to sweep through the specified search space,
9114 + possibly in several iterations (with one call to this function for each
9115 + iteration). *START_ADDR is the address where the search starts, and is
9116 + updated to the next starting address to continue the search.
9117 + *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
9118 + updated for the next iteration. PATTERN_BUF holds the pattern to be searched
9119 + for, PATTERN_LEN is the size of the pattern in bytes. If a match is found,
9120 + it's address is put in *FOUND_ADDR.
9122 + Returns 1 if found, 0 if not found, and -1 if there was an error requiring
9123 + halting of the search (e.g. memory read error). */
9126 +search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
9127 + const char *pattern_buf, ULONGEST pattern_len,
9128 + CORE_ADDR *found_addr)
9130 + /* Offset from start of this iteration to the next iteration. */
9131 + ULONGEST next_iter_incr;
9134 + found = target_search_memory (*start_addr, *search_space_len,
9135 + pattern_buf, pattern_len, found_addr);
9139 + /* Begin next iteration at one byte past this match. */
9140 + next_iter_incr = (*found_addr - *start_addr) + 1;
9142 + /* For robustness, we don't let search_space_len go -ve here. */
9143 + if (*search_space_len >= next_iter_incr)
9144 + *search_space_len -= next_iter_incr;
9146 + *search_space_len = 0;
9147 + *start_addr += next_iter_incr;
9153 find_command (char *args, int from_tty)
9155 @@ -267,12 +331,11 @@ find_command (char *args, int from_tty)
9156 while (search_space_len >= pattern_len
9157 && found_count < max_count)
9159 - /* Offset from start of this iteration to the next iteration. */
9160 - ULONGEST next_iter_incr;
9161 CORE_ADDR found_addr;
9162 - int found = target_search_memory (start_addr, search_space_len,
9163 - pattern_buf, pattern_len, &found_addr);
9166 + found = search_memory (&start_addr, &search_space_len, pattern_buf,
9167 + pattern_len, &found_addr);
9171 @@ -280,16 +343,6 @@ find_command (char *args, int from_tty)
9172 printf_filtered ("\n");
9174 last_found_addr = found_addr;
9176 - /* Begin next iteration at one byte past this match. */
9177 - next_iter_incr = (found_addr - start_addr) + 1;
9179 - /* For robustness, we don't let search_space_len go -ve here. */
9180 - if (search_space_len >= next_iter_incr)
9181 - search_space_len -= next_iter_incr;
9183 - search_space_len = 0;
9184 - start_addr += next_iter_incr;
9187 /* Record and print the results. */
9188 diff --git a/gdb/findvar.c b/gdb/findvar.c
9189 index 8c027c9..d201f76 100644
9193 #include "user-regs.h"
9195 #include "objfiles.h"
9196 +#include "dwarf2loc.h"
9198 /* Basic byte-swapping routines. GDB has needed these for a long time...
9199 All extract a target-format integer at ADDR which is LEN bytes long. */
9200 @@ -394,27 +395,16 @@ symbol_read_needs_frame (struct symbol *sym)
9201 /* Given a struct symbol for a variable,
9202 and a stack frame id, read the value of the variable
9203 and return a (pointer to a) struct value containing the value.
9204 - If the variable cannot be found, return a zero pointer. */
9205 + If the variable cannot be found, return a zero pointer.
9206 + We have to first find the address of the variable before allocating struct
9207 + value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
9208 + used by its type. */
9211 read_var_value (struct symbol *var, struct frame_info *frame)
9214 struct type *type = SYMBOL_TYPE (var);
9218 - if (SYMBOL_CLASS (var) == LOC_COMPUTED
9219 - || SYMBOL_CLASS (var) == LOC_REGISTER)
9220 - /* These cases do not use V. */
9224 - v = allocate_value (type);
9225 - VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
9228 - len = TYPE_LENGTH (type);
9230 if (symbol_read_needs_frame (var))
9232 @@ -422,32 +412,40 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9233 switch (SYMBOL_CLASS (var))
9236 - /* Put the constant back in target format. */
9237 - store_signed_integer (value_contents_raw (v), len,
9238 - gdbarch_byte_order (get_type_arch (type)),
9239 - (LONGEST) SYMBOL_VALUE (var));
9240 - VALUE_LVAL (v) = not_lval;
9243 + /* Put the constant back in target format. */
9244 + struct value *v = allocate_value (type);
9245 + VALUE_LVAL (v) = not_lval;
9246 + store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
9247 + gdbarch_byte_order (get_type_arch (type)),
9248 + (LONGEST) SYMBOL_VALUE (var));
9253 - /* Put the constant back in target format. */
9254 - if (overlay_debugging)
9257 - = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
9258 - SYMBOL_OBJ_SECTION (var));
9259 - store_typed_address (value_contents_raw (v), type, addr);
9262 - store_typed_address (value_contents_raw (v), type,
9263 - SYMBOL_VALUE_ADDRESS (var));
9264 - VALUE_LVAL (v) = not_lval;
9267 + /* Put the constant back in target format. */
9268 + struct value *v = allocate_value (type);
9269 + VALUE_LVAL (v) = not_lval;
9270 + if (overlay_debugging)
9273 + = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
9274 + SYMBOL_OBJ_SECTION (var));
9275 + store_typed_address (value_contents_raw (v), type, addr);
9278 + store_typed_address (value_contents_raw (v), type,
9279 + SYMBOL_VALUE_ADDRESS (var));
9283 case LOC_CONST_BYTES:
9285 - memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
9286 + struct value *v = allocate_value (type);
9287 VALUE_LVAL (v) = not_lval;
9288 + memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
9289 + TYPE_LENGTH (type));
9293 @@ -489,12 +487,23 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9297 - if (overlay_debugging)
9298 - set_value_address (v, symbol_overlayed_address
9299 - (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)));
9301 - set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
9307 + if (overlay_debugging)
9308 + addr = symbol_overlayed_address
9309 + (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
9311 + addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
9312 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
9313 + DW_OP_push_object_address. */
9314 + object_address_set (addr);
9315 + v = allocate_value (type);
9316 + VALUE_LVAL (v) = lval_memory;
9317 + set_value_address (v, addr);
9322 case LOC_REGPARM_ADDR:
9323 @@ -513,7 +522,6 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9324 error (_("Value of register variable not available."));
9326 addr = value_as_address (regval);
9327 - VALUE_LVAL (v) = lval_memory;
9331 @@ -556,18 +564,33 @@ read_var_value (struct symbol *var, struct frame_info *frame)
9334 case LOC_OPTIMIZED_OUT:
9335 - VALUE_LVAL (v) = not_lval;
9336 - set_value_optimized_out (v, 1);
9339 + struct value *v = allocate_value (type);
9341 + VALUE_LVAL (v) = not_lval;
9342 + set_value_optimized_out (v, 1);
9347 error (_("Cannot look up value of a botched symbol."));
9351 - set_value_address (v, addr);
9352 - set_value_lazy (v, 1);
9357 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
9358 + DW_OP_PUSH_OBJECT_ADDRESS. */
9359 + object_address_set (addr);
9360 + v = allocate_value (type);
9361 + VALUE_LVAL (v) = lval_memory;
9362 + set_value_address (v, addr);
9364 + set_value_lazy (v, 1);
9370 /* Install default attributes for register values. */
9371 @@ -604,10 +627,11 @@ struct value *
9372 value_from_register (struct type *type, int regnum, struct frame_info *frame)
9374 struct gdbarch *gdbarch = get_frame_arch (frame);
9375 - struct type *type1 = check_typedef (type);
9378 - if (gdbarch_convert_register_p (gdbarch, regnum, type1))
9379 + type = check_typedef (type);
9381 + if (gdbarch_convert_register_p (gdbarch, regnum, type))
9383 /* The ISA/ABI need to something weird when obtaining the
9384 specified value from this register. It might need to
9385 @@ -621,7 +645,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
9386 VALUE_FRAME_ID (v) = get_frame_id (frame);
9387 VALUE_REGNUM (v) = regnum;
9388 gdbarch_register_to_value (gdbarch,
9389 - frame, regnum, type1, value_contents_raw (v));
9390 + frame, regnum, type, value_contents_raw (v));
9394 diff --git a/gdb/frame.c b/gdb/frame.c
9395 index 7932b48..4e7c434 100644
9398 @@ -1171,6 +1171,14 @@ has_stack_frames (void)
9399 if (ptid_equal (inferior_ptid, null_ptid))
9402 + /* FIXME: Workaround archer-tromey-python crash in
9403 + add_inferior_object->get_current_arch on FSF GDB update:
9404 + is_thread_state would assertion check here as
9405 + remote_start_remote->add_inferior_silent->observer_notify_new_inferior is
9406 + before remote_start_remote->add_thread_silent. */
9407 + if (find_thread_ptid (inferior_ptid) == NULL)
9410 /* Don't try to read from a dead thread. */
9411 if (is_exited (inferior_ptid))
9413 diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
9414 index ffb7f53..a2e7e94 100644
9415 --- a/gdb/gdbinit.in
9416 +++ b/gdb/gdbinit.in
9418 echo Setting up the environment for debugging gdb.\n
9420 +# Set up the Python library and "require" command.
9422 +from os.path import abspath
9423 +gdb.datadir = abspath ('@srcdir@/python/lib')
9424 +gdb.pythonlibdir = gdb.datadir
9425 +gdb.__path__ = [gdb.datadir + '/gdb']
9426 +sys.path.insert(0, gdb.datadir)
9428 +source @srcdir@/python/lib/gdb/__init__.py
9433 diff --git a/gdb/gdbserver/linux-i386-low.c b/gdb/gdbserver/linux-i386-low.c
9434 new file mode 100644
9435 index 0000000..b95c1b1
9437 +++ b/gdb/gdbserver/linux-i386-low.c
9439 +/* GNU/Linux/i386 specific low level interface, for the remote server for GDB.
9440 + Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
9441 + 2007, 2008, 2009 Free Software Foundation, Inc.
9443 + This file is part of GDB.
9445 + This program is free software; you can redistribute it and/or modify
9446 + it under the terms of the GNU General Public License as published by
9447 + the Free Software Foundation; either version 3 of the License, or
9448 + (at your option) any later version.
9450 + This program is distributed in the hope that it will be useful,
9451 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9452 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9453 + GNU General Public License for more details.
9455 + You should have received a copy of the GNU General Public License
9456 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
9458 +#include "server.h"
9459 +#include "linux-low.h"
9460 +#include "i387-fp.h"
9462 +#include "gdb_proc_service.h"
9464 +#include <sys/ptrace.h>
9466 +#ifdef HAVE_SYS_REG_H
9467 +#include <sys/reg.h>
9470 +#ifndef PTRACE_GET_THREAD_AREA
9471 +#define PTRACE_GET_THREAD_AREA 25
9474 +/* Defined in auto-generated file reg-i386-linux.c. */
9475 +void init_registers_i386_linux (void);
9478 +/* This module only supports access to the general purpose registers. */
9480 +#define i386_num_regs 16
9482 +/* This stuff comes from i386-linux-nat.c. */
9484 +/* Mapping between the general-purpose registers in `struct user'
9485 + format and GDB's register array layout. */
9486 +static int i386_regmap[] =
9488 + EAX * 4, ECX * 4, EDX * 4, EBX * 4,
9489 + UESP * 4, EBP * 4, ESI * 4, EDI * 4,
9490 + EIP * 4, EFL * 4, CS * 4, SS * 4,
9491 + DS * 4, ES * 4, FS * 4, GS * 4
9494 +/* Called by libthread_db. */
9497 +ps_get_thread_area (const struct ps_prochandle *ph,
9498 + lwpid_t lwpid, int idx, void **base)
9500 + unsigned int desc[4];
9502 + if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
9503 + (void *) idx, (unsigned long) &desc) < 0)
9506 + *(int *)base = desc[1];
9511 +i386_cannot_store_register (int regno)
9513 + return (regno >= i386_num_regs);
9517 +i386_cannot_fetch_register (int regno)
9519 + return (regno >= i386_num_regs);
9523 +#ifdef HAVE_PTRACE_GETREGS
9524 +#include <sys/procfs.h>
9525 +#include <sys/ptrace.h>
9528 +i386_fill_gregset (void *buf)
9532 + for (i = 0; i < i386_num_regs; i++)
9533 + collect_register (i, ((char *) buf) + i386_regmap[i]);
9535 + collect_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
9539 +i386_store_gregset (const void *buf)
9543 + for (i = 0; i < i386_num_regs; i++)
9544 + supply_register (i, ((char *) buf) + i386_regmap[i]);
9546 + supply_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
9550 +i386_fill_fpregset (void *buf)
9552 + i387_cache_to_fsave (buf);
9556 +i386_store_fpregset (const void *buf)
9558 + i387_fsave_to_cache (buf);
9562 +i386_fill_fpxregset (void *buf)
9564 + i387_cache_to_fxsave (buf);
9568 +i386_store_fpxregset (const void *buf)
9570 + i387_fxsave_to_cache (buf);
9573 +#endif /* HAVE_PTRACE_GETREGS */
9575 +struct regset_info target_regsets[] = {
9576 +#ifdef HAVE_PTRACE_GETREGS
9577 + { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
9579 + i386_fill_gregset, i386_store_gregset },
9580 +# ifdef HAVE_PTRACE_GETFPXREGS
9581 + { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, sizeof (elf_fpxregset_t),
9583 + i386_fill_fpxregset, i386_store_fpxregset },
9585 + { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
9587 + i386_fill_fpregset, i386_store_fpregset },
9588 +#endif /* HAVE_PTRACE_GETREGS */
9589 + { 0, 0, -1, -1, NULL, NULL }
9592 +static const unsigned char i386_breakpoint[] = { 0xCC };
9593 +#define i386_breakpoint_len 1
9595 +extern int debug_threads;
9602 + collect_register_by_name ("eip", &pc);
9604 + if (debug_threads)
9605 + fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
9610 +i386_set_pc (CORE_ADDR newpc)
9612 + if (debug_threads)
9613 + fprintf (stderr, "set pc to %08lx\n", (long) newpc);
9614 + supply_register_by_name ("eip", &newpc);
9618 +i386_breakpoint_at (CORE_ADDR pc)
9622 + read_inferior_memory (pc, &c, 1);
9629 +struct linux_target_ops the_low_target = {
9630 + init_registers_i386_linux,
9633 + i386_cannot_fetch_register,
9634 + i386_cannot_store_register,
9638 + i386_breakpoint_len,
9641 + i386_breakpoint_at,
9649 diff --git a/gdb/gdbserver/linux-x86-64-low.c b/gdb/gdbserver/linux-x86-64-low.c
9650 new file mode 100644
9651 index 0000000..b8213f5
9653 +++ b/gdb/gdbserver/linux-x86-64-low.c
9655 +/* GNU/Linux/x86-64 specific low level interface, for the remote server
9657 + Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009
9658 + Free Software Foundation, Inc.
9660 + This file is part of GDB.
9662 + This program is free software; you can redistribute it and/or modify
9663 + it under the terms of the GNU General Public License as published by
9664 + the Free Software Foundation; either version 3 of the License, or
9665 + (at your option) any later version.
9667 + This program is distributed in the hope that it will be useful,
9668 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9669 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9670 + GNU General Public License for more details.
9672 + You should have received a copy of the GNU General Public License
9673 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
9675 +#include "server.h"
9676 +#include "linux-low.h"
9677 +#include "i387-fp.h"
9679 +#include "gdb_proc_service.h"
9681 +/* Defined in auto-generated file reg-x86-64-linux.c. */
9682 +void init_registers_x86_64_linux (void);
9684 +#include <sys/reg.h>
9685 +#include <sys/procfs.h>
9686 +#include <sys/ptrace.h>
9688 +/* This definition comes from prctl.h, but some kernels may not have it. */
9689 +#ifndef PTRACE_ARCH_PRCTL
9690 +#define PTRACE_ARCH_PRCTL 30
9693 +/* The following definitions come from prctl.h, but may be absent
9694 + for certain configurations. */
9695 +#ifndef ARCH_GET_FS
9696 +#define ARCH_SET_GS 0x1001
9697 +#define ARCH_SET_FS 0x1002
9698 +#define ARCH_GET_FS 0x1003
9699 +#define ARCH_GET_GS 0x1004
9702 +static int x86_64_regmap[] = {
9703 + RAX * 8, RBX * 8, RCX * 8, RDX * 8,
9704 + RSI * 8, RDI * 8, RBP * 8, RSP * 8,
9705 + R8 * 8, R9 * 8, R10 * 8, R11 * 8,
9706 + R12 * 8, R13 * 8, R14 * 8, R15 * 8,
9707 + RIP * 8, EFLAGS * 8, CS * 8, SS * 8,
9708 + DS * 8, ES * 8, FS * 8, GS * 8,
9709 + -1, -1, -1, -1, -1, -1, -1, -1,
9710 + -1, -1, -1, -1, -1, -1, -1, -1,
9711 + -1, -1, -1, -1, -1, -1, -1, -1,
9712 + -1, -1, -1, -1, -1, -1, -1, -1, -1,
9716 +#define X86_64_NUM_GREGS (sizeof(x86_64_regmap)/sizeof(int))
9718 +/* Called by libthread_db. */
9721 +ps_get_thread_area (const struct ps_prochandle *ph,
9722 + lwpid_t lwpid, int idx, void **base)
9727 + if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
9731 + if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
9735 + return PS_BADADDR;
9741 +x86_64_fill_gregset (void *buf)
9745 + for (i = 0; i < X86_64_NUM_GREGS; i++)
9746 + if (x86_64_regmap[i] != -1)
9747 + collect_register (i, ((char *) buf) + x86_64_regmap[i]);
9751 +x86_64_store_gregset (const void *buf)
9755 + for (i = 0; i < X86_64_NUM_GREGS; i++)
9756 + if (x86_64_regmap[i] != -1)
9757 + supply_register (i, ((char *) buf) + x86_64_regmap[i]);
9761 +x86_64_fill_fpregset (void *buf)
9763 + i387_cache_to_fxsave (buf);
9767 +x86_64_store_fpregset (const void *buf)
9769 + i387_fxsave_to_cache (buf);
9772 +struct regset_info target_regsets[] = {
9773 + { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
9775 + x86_64_fill_gregset, x86_64_store_gregset },
9776 + { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
9778 + x86_64_fill_fpregset, x86_64_store_fpregset },
9779 + { 0, 0, -1, -1, NULL, NULL }
9782 +static const unsigned char x86_64_breakpoint[] = { 0xCC };
9783 +#define x86_64_breakpoint_len 1
9785 +extern int debug_threads;
9792 + collect_register_by_name ("rip", &pc);
9794 + if (debug_threads)
9795 + fprintf (stderr, "stop pc (before any decrement) is %08lx\n", pc);
9800 +x86_64_set_pc (CORE_ADDR newpc)
9802 + if (debug_threads)
9803 + fprintf (stderr, "set pc to %08lx\n", (long) newpc);
9804 + supply_register_by_name ("rip", &newpc);
9808 +x86_64_breakpoint_at (CORE_ADDR pc)
9812 + read_inferior_memory (pc, &c, 1);
9819 +struct linux_target_ops the_low_target = {
9820 + init_registers_x86_64_linux,
9827 + x86_64_breakpoint,
9828 + x86_64_breakpoint_len,
9831 + x86_64_breakpoint_at,
9839 diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
9840 index 79d33fe..d3b4fa1 100644
9841 --- a/gdb/gdbthread.h
9842 +++ b/gdb/gdbthread.h
9843 @@ -185,6 +185,10 @@ struct thread_info
9844 /* True if this thread has been explicitly requested to stop. */
9847 + /* The initiating frame of a nexting operation, used for deciding
9848 + which exceptions to intercept. */
9849 + struct frame_id initiating_frame;
9851 /* Private data used by the target vector implementation. */
9852 struct private_thread_info *private;
9854 @@ -249,6 +253,9 @@ extern struct thread_info *any_thread_of_process (int pid);
9855 /* Change the ptid of thread OLD_PTID to NEW_PTID. */
9856 void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
9858 +/* Prune dead threads from the list of threads. */
9859 +extern void prune_threads (void);
9861 /* Iterator function to call a user-provided callback function
9862 once for each known thread. */
9863 typedef int (*thread_callback_func) (struct thread_info *, void *);
9864 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
9865 index 2f77dca..90abf2c 100644
9866 --- a/gdb/gdbtypes.c
9867 +++ b/gdb/gdbtypes.c
9870 #include "gdb_assert.h"
9871 #include "hashtab.h"
9872 +#include "observer.h"
9873 +#include "dwarf2expr.h"
9874 +#include "dwarf2loc.h"
9877 /* Floatformat pairs. */
9878 @@ -118,13 +121,31 @@ static void print_arg_types (struct field *, int, int);
9879 static void dump_fn_fieldlists (struct type *, int);
9880 static void print_cplus_stuff (struct type *, int);
9882 +/* A reference count structure for the type reference count map. Each
9883 + type in a hierarchy of types is mapped to the same reference
9885 +struct type_refc_entry
9887 + /* One type in the hierarchy. Each type in the hierarchy gets its
9889 + struct type *type;
9891 + /* A pointer to the shared reference count. */
9895 +/* The hash table holding all discardable `struct type *' references. */
9896 +static htab_t type_discardable_table;
9898 +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE. */
9899 +static int type_discardable_age_current;
9901 /* Allocate a new OBJFILE-associated type structure and fill it
9902 with some defaults. Space for the type structure is allocated
9903 on the objfile's objfile_obstack. */
9906 -alloc_type (struct objfile *objfile)
9907 +alloc_type (struct objfile *objfile, struct type *parent)
9911 @@ -148,6 +169,39 @@ alloc_type (struct objfile *objfile)
9915 +/* Declare TYPE as discardable on next garbage collection by free_all_types.
9916 + You must call type_mark_used during each free_all_types to protect TYPE from
9917 + being deallocated. */
9920 +set_type_as_discardable (struct type *type)
9924 + gdb_assert (!TYPE_DISCARDABLE (type));
9926 + TYPE_DISCARDABLE (type) = 1;
9927 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
9929 + slot = htab_find_slot (type_discardable_table, type, INSERT);
9930 + gdb_assert (!*slot);
9934 +/* Allocate a new type like alloc_type but preserve for it the discardability
9935 + state of PARENT_TYPE. */
9937 +static struct type *
9938 +alloc_type_as_parent (struct type *parent_type)
9940 + struct type *new_type = alloc_type_copy (parent_type);
9942 + if (TYPE_DISCARDABLE (parent_type))
9943 + set_type_as_discardable (new_type);
9948 /* Allocate a new GDBARCH-associated type structure and fill it
9949 with some defaults. Space for the type structure is allocated
9951 @@ -184,7 +238,7 @@ struct type *
9952 alloc_type_copy (const struct type *type)
9954 if (TYPE_OBJFILE_OWNED (type))
9955 - return alloc_type (TYPE_OWNER (type).objfile);
9956 + return alloc_type (TYPE_OWNER (type).objfile, (struct type *) type);
9958 return alloc_type_arch (TYPE_OWNER (type).gdbarch);
9960 @@ -273,7 +327,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
9962 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
9964 - ntype = alloc_type_copy (type);
9965 + ntype = alloc_type_as_parent (type);
9969 @@ -350,7 +404,7 @@ make_reference_type (struct type *type, struct type **typeptr)
9971 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
9973 - ntype = alloc_type_copy (type);
9974 + ntype = alloc_type_as_parent (type);
9978 @@ -721,12 +775,13 @@ create_range_type (struct type *result_type, struct type *index_type,
9979 TYPE_TARGET_STUB (result_type) = 1;
9981 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
9982 - TYPE_NFIELDS (result_type) = 2;
9983 + TYPE_NFIELDS (result_type) = 3;
9984 TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
9985 TYPE_NFIELDS (result_type)
9986 * sizeof (struct field));
9987 TYPE_LOW_BOUND (result_type) = low_bound;
9988 TYPE_HIGH_BOUND (result_type) = high_bound;
9989 + TYPE_BYTE_STRIDE (result_type) = 0;
9992 TYPE_UNSIGNED (result_type) = 1;
9993 @@ -826,26 +881,45 @@ create_array_type (struct type *result_type,
9995 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
9996 TYPE_TARGET_TYPE (result_type) = element_type;
9997 - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
9998 - low_bound = high_bound = 0;
9999 - CHECK_TYPEDEF (element_type);
10000 - /* Be careful when setting the array length. Ada arrays can be
10001 - empty arrays with the high_bound being smaller than the low_bound.
10002 - In such cases, the array length should be zero. */
10003 - if (high_bound < low_bound)
10004 - TYPE_LENGTH (result_type) = 0;
10006 - TYPE_LENGTH (result_type) =
10007 - TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
10008 TYPE_NFIELDS (result_type) = 1;
10009 TYPE_FIELDS (result_type) =
10010 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
10011 TYPE_INDEX_TYPE (result_type) = range_type;
10012 TYPE_VPTR_FIELDNO (result_type) = -1;
10014 - /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
10015 + /* DWARF blocks may depend on runtime information like
10016 + DW_OP_PUSH_OBJECT_ADDRESS not being available during the
10017 + CREATE_ARRAY_TYPE time. */
10018 + if (TYPE_RANGE_BOUND_IS_DWARF_BLOCK (range_type, 0)
10019 + || TYPE_RANGE_BOUND_IS_DWARF_BLOCK (range_type, 1)
10020 + || TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type)
10021 + || TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (range_type)
10022 + || get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
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. TYPE_TARGET_STUB needs to
10031 + be checked as it may have dependencies on DWARF blocks depending on
10032 + runtime information not available during the CREATE_ARRAY_TYPE time. */
10033 + if (high_bound < low_bound || TYPE_TARGET_STUB (element_type))
10034 + TYPE_LENGTH (result_type) = 0;
10037 + CHECK_TYPEDEF (element_type);
10038 + TYPE_LENGTH (result_type) =
10039 + TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
10042 if (TYPE_LENGTH (result_type) == 0)
10043 - TYPE_TARGET_STUB (result_type) = 1;
10045 + /* The real size will be computed for specific instances by
10046 + CHECK_TYPEDEF. */
10047 + TYPE_TARGET_STUB (result_type) = 1;
10050 return result_type;
10052 @@ -1331,6 +1405,84 @@ stub_noname_complaint (void)
10053 complaint (&symfile_complaints, _("stub type has NULL name"));
10056 +/* Calculate the memory length of array TYPE.
10058 + TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
10059 + a performance hint. Feel free to pass NULL. Set FULL_SPAN to return the
10060 + size incl. the possible padding of the last element - it may differ from the
10061 + cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
10062 + TYPE_BYTE_STRIDE values. */
10065 +type_length_get (struct type *type, struct type *target_type, int full_span)
10067 + struct type *range_type;
10069 + CORE_ADDR byte_stride = 0; /* `= 0' for a false GCC warning. */
10070 + CORE_ADDR element_size;
10072 + if (TYPE_CODE (type) != TYPE_CODE_ARRAY
10073 + && TYPE_CODE (type) != TYPE_CODE_STRING)
10074 + return TYPE_LENGTH (type);
10076 + /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
10077 + Fortran arrays. The allocated data will never be used so they can be
10079 + if (object_address_data_not_valid (type))
10082 + range_type = TYPE_INDEX_TYPE (type);
10083 + if (TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (range_type)
10084 + || TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (range_type))
10086 + count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
10087 + /* It may happen for wrong DWARF annotations returning garbage data. */
10089 + warning (_("Range for type %s has invalid bounds %d..%d"),
10090 + TYPE_NAME (type), TYPE_LOW_BOUND (range_type),
10091 + TYPE_HIGH_BOUND (range_type));
10092 + /* The code below does not handle count == 0 right. */
10095 + if (full_span || count > 1)
10097 + /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
10098 + force FULL_SPAN to 1. */
10099 + byte_stride = TYPE_BYTE_STRIDE (range_type);
10100 + if (byte_stride == 0)
10102 + if (target_type == NULL)
10103 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
10104 + byte_stride = type_length_get (target_type, NULL, 1);
10108 + return count * byte_stride;
10109 + if (target_type == NULL)
10110 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
10111 + element_size = type_length_get (target_type, NULL, 1);
10112 + return (count - 1) * byte_stride + element_size;
10115 +/* Prepare TYPE after being read in by the backend. Currently this function
10116 + only propagates the TYPE_DYNAMIC flag. */
10119 +finalize_type (struct type *type)
10123 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
10124 + if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
10127 + /* FIXME: cplus_stuff is ignored here. */
10128 + if (i < TYPE_NFIELDS (type)
10129 + || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
10130 + || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
10131 + TYPE_DYNAMIC (type) = 1;
10134 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
10136 If this is a stubbed struct (i.e. declared as struct foo *), see if
10137 @@ -1347,7 +1499,8 @@ stub_noname_complaint (void)
10138 /* Find the real type of TYPE. This function returns the real type,
10139 after removing all layers of typedefs and completing opaque or stub
10140 types. Completion changes the TYPE argument, but stripping of
10141 - typedefs does not. */
10142 + typedefs does not. Still original passed TYPE will have TYPE_LENGTH
10143 + updated. FIXME: Remove this dependency (only ada_to_fixed_type?). */
10146 check_typedef (struct type *type)
10147 @@ -1457,34 +1610,37 @@ check_typedef (struct type *type)
10151 - if (TYPE_TARGET_STUB (type))
10152 + /* copy_type_recursive automatically makes the resulting type containing only
10153 + constant values expected by the callers of this function. */
10154 + if (TYPE_DYNAMIC (type))
10156 + htab_t copied_types;
10157 + struct type *type_old = type;
10159 + copied_types = create_copied_types_hash (NULL);
10160 + type = copy_type_recursive (type, copied_types);
10161 + htab_delete (copied_types);
10163 + gdb_assert (TYPE_DYNAMIC (type) == 0);
10166 + if (!currently_reading_symtab
10167 + && (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type)))
10169 - struct type *range_type;
10170 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
10172 + if (TYPE_DYNAMIC (type))
10173 + TYPE_TARGET_TYPE (type) = target_type;
10174 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
10178 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
10179 - && TYPE_NFIELDS (type) == 1
10180 - && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
10181 - == TYPE_CODE_RANGE))
10182 + || TYPE_CODE (type) == TYPE_CODE_STRING)
10184 /* Now recompute the length of the array type, based on its
10185 - number of elements and the target type's length.
10186 - Watch out for Ada null Ada arrays where the high bound
10187 - is smaller than the low bound. */
10188 - const int low_bound = TYPE_LOW_BOUND (range_type);
10189 - const int high_bound = TYPE_HIGH_BOUND (range_type);
10192 - if (high_bound < low_bound)
10195 - nb_elements = high_bound - low_bound + 1;
10197 - TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
10198 + number of elements and the target type's length. */
10199 + TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
10200 TYPE_TARGET_STUB (type) = 0;
10202 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
10203 @@ -1492,9 +1648,12 @@ check_typedef (struct type *type)
10204 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
10205 TYPE_TARGET_STUB (type) = 0;
10207 + TYPE_DYNAMIC (type) = 0;
10210 /* Cache TYPE_LENGTH for future use. */
10211 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
10216 @@ -1716,7 +1875,7 @@ init_type (enum type_code code, int length, int flags,
10220 - type = alloc_type (objfile);
10221 + type = alloc_type (objfile, NULL);
10222 TYPE_CODE (type) = code;
10223 TYPE_LENGTH (type) = length;
10225 @@ -1760,6 +1919,10 @@ init_type (enum type_code code, int length, int flags,
10227 INIT_CPLUS_SPECIFIC (type);
10231 + type_incref (type);
10236 @@ -2004,7 +2167,8 @@ rank_one_type (struct type *parm, struct type *arg)
10237 switch (TYPE_CODE (arg))
10239 case TYPE_CODE_PTR:
10240 - if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
10241 + if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID
10242 + && TYPE_CODE (TYPE_TARGET_TYPE (arg)) != TYPE_CODE_VOID)
10243 return VOID_PTR_CONVERSION_BADNESS;
10245 return rank_one_type (TYPE_TARGET_TYPE (parm),
10246 @@ -2820,33 +2984,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
10249 /* Allocate the hash table used by copy_type_recursive to walk
10250 - types without duplicates. We use OBJFILE's obstack, because
10251 - OBJFILE is about to be deleted. */
10252 + types without duplicates. */
10255 create_copied_types_hash (struct objfile *objfile)
10257 - return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
10258 - NULL, &objfile->objfile_obstack,
10259 - hashtab_obstack_allocate,
10260 - dummy_obstack_deallocate);
10261 + if (objfile == NULL)
10263 + /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
10264 + OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN. Table
10265 + element entries get allocated by xmalloc - so use xfree. */
10266 + return htab_create (1, type_pair_hash, type_pair_eq, xfree);
10270 + /* Use OBJFILE's obstack, because OBJFILE is about to be deleted. Table
10271 + element entries get allocated by xmalloc - so use xfree. */
10272 + return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
10273 + xfree, &objfile->objfile_obstack,
10274 + hashtab_obstack_allocate,
10275 + dummy_obstack_deallocate);
10279 -/* Recursively copy (deep copy) TYPE, if it is associated with
10280 - OBJFILE. Return a new type allocated using malloc, a saved type if
10281 - we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
10282 - not associated with OBJFILE. */
10283 +/* A helper for copy_type_recursive. This does all the work. OBJFILE is used
10284 + only for an assertion checking. */
10287 -copy_type_recursive (struct objfile *objfile,
10288 - struct type *type,
10289 - htab_t copied_types)
10290 +static struct type *
10291 +copy_type_recursive_1 (struct objfile *objfile,
10292 + struct type *type,
10293 + htab_t copied_types)
10295 struct type_pair *stored, pair;
10297 struct type *new_type;
10299 - if (! TYPE_OBJFILE_OWNED (type))
10300 + if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
10303 /* This type shouldn't be pointing to any types in other objfiles;
10304 @@ -2861,8 +3034,10 @@ copy_type_recursive (struct objfile *objfile,
10305 new_type = alloc_type_arch (get_type_arch (type));
10307 /* We must add the new type to the hash table immediately, in case
10308 - we encounter this type again during a recursive call below. */
10309 - stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
10310 + we encounter this type again during a recursive call below. Memory could
10311 + be allocated from OBJFILE in the case we will be removing OBJFILE, this
10312 + optimization is missed and xfree is called for it from COPIED_TYPES. */
10313 + stored = xmalloc (sizeof (*stored));
10314 stored->old = type;
10315 stored->new = new_type;
10317 @@ -2873,6 +3048,19 @@ copy_type_recursive (struct objfile *objfile,
10318 TYPE_OBJFILE_OWNED (new_type) = 0;
10319 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
10321 + /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
10322 + need to initialize it again. And even if TYPE was already discardable
10323 + NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE. */
10324 + TYPE_DISCARDABLE (new_type) = 0;
10325 + set_type_as_discardable (new_type);
10327 + /* Pre-clear the fields processed by delete_main_type. If DWARF block
10328 + evaluations below call error we would leave an unfreeable TYPE. */
10329 + TYPE_TARGET_TYPE (new_type) = NULL;
10330 + TYPE_VPTR_BASETYPE (new_type) = NULL;
10331 + TYPE_NFIELDS (new_type) = 0;
10332 + TYPE_FIELDS (new_type) = NULL;
10334 if (TYPE_NAME (type))
10335 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
10336 if (TYPE_TAG_NAME (type))
10337 @@ -2881,12 +3069,45 @@ copy_type_recursive (struct objfile *objfile,
10338 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
10339 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
10341 + if (TYPE_ALLOCATED (new_type))
10343 + gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
10345 + if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
10346 + TYPE_NOT_ALLOCATED (new_type) = 1;
10347 + TYPE_ALLOCATED (new_type) = NULL;
10350 + if (TYPE_ASSOCIATED (new_type))
10352 + gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
10354 + if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
10355 + TYPE_NOT_ASSOCIATED (new_type) = 1;
10356 + TYPE_ASSOCIATED (new_type) = NULL;
10359 + if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
10360 + && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
10362 + if (TYPE_NOT_ALLOCATED (new_type)
10363 + || TYPE_NOT_ASSOCIATED (new_type))
10364 + TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
10367 + TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
10368 + TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
10369 + (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
10373 /* Copy the fields. */
10374 if (TYPE_NFIELDS (type))
10378 nfields = TYPE_NFIELDS (type);
10379 + TYPE_NFIELDS (new_type) = nfields;
10380 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
10381 for (i = 0; i < nfields; i++)
10383 @@ -2895,8 +3116,8 @@ copy_type_recursive (struct objfile *objfile,
10384 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
10385 if (TYPE_FIELD_TYPE (type, i))
10386 TYPE_FIELD_TYPE (new_type, i)
10387 - = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
10389 + = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
10391 if (TYPE_FIELD_NAME (type, i))
10392 TYPE_FIELD_NAME (new_type, i) =
10393 xstrdup (TYPE_FIELD_NAME (type, i));
10394 @@ -2915,6 +3136,16 @@ copy_type_recursive (struct objfile *objfile,
10395 xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
10398 + case FIELD_LOC_KIND_DWARF_BLOCK:
10399 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
10400 + it is expected to be made constant by CHECK_TYPEDEF. */
10401 + if (TYPE_NOT_ALLOCATED (new_type)
10402 + || TYPE_NOT_ASSOCIATED (new_type))
10403 + SET_FIELD_DWARF_BLOCK (TYPE_FIELD (new_type, i), NULL);
10405 + SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
10406 + dwarf_locexpr_baton_eval (TYPE_FIELD_DWARF_BLOCK (type, i)));
10409 internal_error (__FILE__, __LINE__,
10410 _("Unexpected type field location kind: %d"),
10411 @@ -2923,17 +3154,30 @@ copy_type_recursive (struct objfile *objfile,
10415 + /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound. */
10416 + if (TYPE_CODE (type) == TYPE_CODE_RANGE
10417 + && TYPE_RANGE_HIGH_BOUND_IS_COUNT (type))
10419 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
10420 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (type)
10421 + + TYPE_HIGH_BOUND (type) - 1;
10424 + /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
10425 + possibly converted. */
10426 + TYPE_DYNAMIC (new_type) = 0;
10428 /* Copy pointers to other types. */
10429 if (TYPE_TARGET_TYPE (type))
10430 TYPE_TARGET_TYPE (new_type) =
10431 - copy_type_recursive (objfile,
10432 - TYPE_TARGET_TYPE (type),
10434 + copy_type_recursive_1 (objfile,
10435 + TYPE_TARGET_TYPE (type),
10437 if (TYPE_VPTR_BASETYPE (type))
10438 TYPE_VPTR_BASETYPE (new_type) =
10439 - copy_type_recursive (objfile,
10440 - TYPE_VPTR_BASETYPE (type),
10442 + copy_type_recursive_1 (objfile,
10443 + TYPE_VPTR_BASETYPE (type),
10445 /* Maybe copy the type_specific bits.
10447 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
10448 @@ -2951,6 +3195,17 @@ copy_type_recursive (struct objfile *objfile,
10452 +/* Recursively copy (deep copy) TYPE. Return a new type allocated using
10453 + malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
10454 + or TYPE if it is not associated with OBJFILE. */
10457 +copy_type_recursive (struct type *type,
10458 + htab_t copied_types)
10460 + return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
10463 /* Make a copy of the given TYPE, except that the pointer & reference
10464 types are not preserved.
10466 @@ -2973,6 +3228,217 @@ copy_type (const struct type *type)
10470 +/* Callback type for main_type_crawl. */
10471 +typedef int (*main_type_crawl_iter) (struct type *type, void *data);
10473 +/* Iterate all main_type structures reachable through any `struct type *' from
10474 + TYPE. ITER will be called only for one type of each main_type, use
10475 + TYPE_CHAIN traversal to find all the type instances. ITER is being called
10476 + for each main_type found. ITER returns non-zero if main_type_crawl should
10477 + depth-first enter the specific type. ITER must provide some detection for
10478 + reentering the same main_type as this function would otherwise endlessly
10482 +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
10484 + struct type *type_iter;
10490 + gdb_assert (TYPE_OBJFILE (type) == NULL);
10492 + /* `struct cplus_struct_type' handling is unsupported by this function. */
10493 + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
10494 + && TYPE_CODE (type) != TYPE_CODE_UNION)
10495 + || !HAVE_CPLUS_STRUCT (type) || !TYPE_CPLUS_SPECIFIC (type));
10497 + if (!(*iter) (type, data))
10500 + /* Iterate all the type instances of this main_type. */
10501 + type_iter = type;
10504 + gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
10506 + main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
10507 + main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
10509 + type_iter = TYPE_CHAIN (type_iter);
10511 + while (type_iter != type);
10513 + for (i = 0; i < TYPE_NFIELDS (type); i++)
10514 + main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
10516 + main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
10517 + main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
10520 +/* A helper for delete_type which deletes a main_type and the things to which
10521 + it refers. TYPE is a type whose main_type we wish to destroy. */
10524 +delete_main_type (struct type *type)
10528 + gdb_assert (TYPE_DISCARDABLE (type));
10529 + gdb_assert (TYPE_OBJFILE (type) == NULL);
10531 + xfree (TYPE_NAME (type));
10532 + xfree (TYPE_TAG_NAME (type));
10534 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
10536 + xfree (TYPE_FIELD_NAME (type, i));
10538 + if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
10539 + xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
10541 + xfree (TYPE_FIELDS (type));
10543 + /* `struct cplus_struct_type' handling is unsupported by this function. */
10544 + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
10545 + && TYPE_CODE (type) != TYPE_CODE_UNION)
10546 + || !HAVE_CPLUS_STRUCT (type) || !TYPE_CPLUS_SPECIFIC (type));
10548 + xfree (TYPE_MAIN_TYPE (type));
10551 +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
10552 + main_type. TYPE must be a reclaimable type - neither permanent nor objfile
10556 +delete_type_chain (struct type *type)
10558 + struct type *type_iter, *type_iter_to_free;
10560 + gdb_assert (TYPE_DISCARDABLE (type));
10561 + gdb_assert (TYPE_OBJFILE (type) == NULL);
10563 + delete_main_type (type);
10565 + type_iter = type;
10568 + type_iter_to_free = type_iter;
10569 + type_iter = TYPE_CHAIN (type_iter);
10570 + xfree (type_iter_to_free);
10572 + while (type_iter != type);
10575 +/* Hash function for type_discardable_table. */
10578 +type_discardable_hash (const void *p)
10580 + const struct type *type = p;
10582 + return htab_hash_pointer (TYPE_MAIN_TYPE (type));
10585 +/* Equality function for type_discardable_table. */
10588 +type_discardable_equal (const void *a, const void *b)
10590 + const struct type *left = a;
10591 + const struct type *right = b;
10593 + return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
10596 +/* A helper for type_mark_used. */
10599 +type_mark_used_crawl (struct type *type, void *unused)
10601 + if (!TYPE_DISCARDABLE (type))
10604 + if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
10607 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
10609 + /* Continue the traversal. */
10613 +/* Mark TYPE and its connected types as used in this free_all_types pass. */
10616 +type_mark_used (struct type *type)
10618 + if (type == NULL)
10621 + if (!TYPE_DISCARDABLE (type))
10624 + main_type_crawl (type, type_mark_used_crawl, NULL);
10627 +/* Increment the reference count for TYPE. */
10630 +type_incref (struct type *type)
10634 +/* Decrement the reference count for TYPE. If TYPE has no more
10635 + references, delete it. */
10638 +type_decref (struct type *type)
10642 +/* A traverse callback for type_discardable_table which removes any
10643 + type_discardable whose reference count is now zero (unused link). */
10646 +type_discardable_remove (void **slot, void *unused)
10648 + struct type *type = *slot;
10650 + gdb_assert (TYPE_DISCARDABLE (type));
10652 + if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
10654 + delete_type_chain (type);
10656 + htab_clear_slot (type_discardable_table, slot);
10662 +/* Free all the reclaimable types that have been allocated and that have
10663 + currently zero reference counter.
10665 + This function is called after each command, successful or not. Use this
10666 + cleanup only in the GDB idle state as GDB only marks those types used by
10667 + globally tracked objects (with no autovariable references tracking). */
10670 +free_all_types (void)
10672 + /* Mark a new pass. As GDB checks all the entries were visited after each
10673 + pass there cannot be any stale entries already containing the changed
10675 + type_discardable_age_current ^= 1;
10677 + observer_notify_mark_used ();
10679 + htab_traverse (type_discardable_table, type_discardable_remove, NULL);
10682 /* Helper functions to initialize architecture-specific types. */
10684 @@ -3463,6 +3929,11 @@ void
10685 _initialize_gdbtypes (void)
10687 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
10689 + type_discardable_table = htab_create_alloc (20, type_discardable_hash,
10690 + type_discardable_equal, NULL,
10693 objfile_type_data = register_objfile_data ();
10695 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
10696 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
10697 index be6ed55..6a51a4e 100644
10698 --- a/gdb/gdbtypes.h
10699 +++ b/gdb/gdbtypes.h
10700 @@ -137,6 +137,8 @@ enum type_code
10702 TYPE_CODE_DECFLOAT, /* Decimal floating point. */
10704 + TYPE_CODE_MODULE, /* Fortran module. */
10706 /* Internal function type. */
10707 TYPE_CODE_INTERNAL_FUNCTION
10709 @@ -213,6 +215,11 @@ enum type_instance_flag_value
10711 #define TYPE_TARGET_STUB(t) (TYPE_MAIN_TYPE (t)->flag_target_stub)
10713 +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
10716 +#define TYPE_DYNAMIC(t) (TYPE_MAIN_TYPE (t)->flag_dynamic)
10718 /* Static type. If this is set, the corresponding type had
10719 * a static modifier.
10720 * Note: This may be unnecessary, since static data members
10721 @@ -278,6 +285,48 @@ enum type_instance_flag_value
10722 #define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner
10723 #define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL)
10725 +/* Define this type as being reclaimable during free_all_types. Type is
10726 + required to be have TYPE_OBJFILE set to NULL. Setting this flag requires
10727 + initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable. */
10729 +#define TYPE_DISCARDABLE(t) (TYPE_MAIN_TYPE (t)->flag_discardable)
10731 +/* Marker this type has been visited by the type_mark_used by this
10732 + mark-and-sweep types garbage collecting pass. Current pass is represented
10733 + by TYPE_DISCARDABLE_AGE_CURRENT. */
10735 +#define TYPE_DISCARDABLE_AGE(t) (TYPE_MAIN_TYPE (t)->flag_discardable_age)
10737 +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)? */
10739 +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
10740 + (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
10742 +/* Not allocated. TYPE_ALLOCATED(t) must be NULL in such case. If this flag
10743 + is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated. If this
10744 + flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
10745 + determines the actual allocation state. */
10747 +#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
10749 +/* Not associated. TYPE_ASSOCIATED(t) must be NULL in such case. If this flag
10750 + is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated. If
10751 + this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
10752 + determines the actual association state. */
10754 +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
10756 +/* Address of the actual data as for DW_AT_data_location. Its dwarf block must
10757 + not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
10758 + false. If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
10759 + is the actual data address value. If unset and
10760 + TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
10761 + value_raw_address. If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
10762 + then its DWARF block determines the actual data address. */
10764 +#define TYPE_DATA_LOCATION_IS_ADDR(t) \
10765 + (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
10767 /* Constant type. If this is set, the corresponding type has a
10770 @@ -365,6 +414,13 @@ struct main_type
10771 unsigned int flag_nottext : 1;
10772 unsigned int flag_fixed_instance : 1;
10773 unsigned int flag_objfile_owned : 1;
10774 + unsigned int flag_discardable : 1;
10775 + unsigned int flag_discardable_age : 1;
10776 + unsigned int flag_dynamic : 1;
10777 + unsigned int flag_range_high_bound_is_count : 1;
10778 + unsigned int flag_not_allocated : 1;
10779 + unsigned int flag_not_associated : 1;
10780 + unsigned int flag_data_location_is_addr : 1;
10782 /* Number of fields described for this type. This field appears at
10783 this location because it packs nicely here. */
10784 @@ -431,6 +487,20 @@ struct main_type
10786 struct type *target_type;
10788 + /* For DW_AT_data_location. */
10791 + struct dwarf2_locexpr_baton *dwarf_block;
10796 + /* For DW_AT_allocated. */
10797 + struct dwarf2_locexpr_baton *allocated;
10799 + /* For DW_AT_associated. */
10800 + struct dwarf2_locexpr_baton *associated;
10802 /* For structure and union types, a description of each field.
10803 For set and pascal array types, there is one "field",
10804 whose type is the domain type of the set or array.
10805 @@ -538,6 +608,9 @@ struct main_type
10806 supporting multiple ABIs. Right now this is only fetched from
10807 the Dwarf-2 DW_AT_calling_convention attribute. */
10808 unsigned calling_convention;
10810 + /* For TYPE_CODE_MODULE, the list of symbols contained in the module. */
10811 + struct block *module_block;
10815 @@ -812,9 +885,9 @@ extern void allocate_cplus_struct_type (struct type *);
10816 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
10817 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
10818 #define TYPE_CHAIN(thistype) (thistype)->chain
10819 -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
10820 - But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
10821 - so you only have to call check_typedef once. Since allocate_value
10822 +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
10823 + check_typedef. But check_typedef does set the TYPE_LENGTH of the TYPEDEF
10824 + type, so you only have to call check_typedef once. Since allocate_value
10825 calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
10826 #define TYPE_LENGTH(thistype) (thistype)->length
10827 /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
10828 @@ -823,23 +896,44 @@ extern void allocate_cplus_struct_type (struct type *);
10829 #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
10830 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->fields
10831 #define TYPE_TEMPLATE_ARGS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->template_args
10832 +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
10833 +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
10834 +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
10835 +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
10837 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
10838 #define TYPE_LOW_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 0)
10839 #define TYPE_HIGH_BOUND(range_type) TYPE_FIELD_BITPOS (range_type, 1)
10841 -/* Moto-specific stuff for FORTRAN arrays */
10843 -#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
10844 - (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
10845 +#define TYPE_BYTE_STRIDE(range_type) TYPE_FIELD_BITPOS (range_type, 2)
10847 +/* Whether we should use TYPE_FIELD_DWARF_BLOCK (and not TYPE_FIELD_BITPOS). */
10848 +#define TYPE_RANGE_BOUND_IS_DWARF_BLOCK(range_type, fieldno) \
10849 + (TYPE_FIELD_LOC_KIND (range_type, fieldno) == FIELD_LOC_KIND_DWARF_BLOCK)
10850 +#define TYPE_RANGE_BOUND_SET_DWARF_BLOCK(range_type, fieldno) \
10851 + (TYPE_FIELD_LOC_KIND (range_type, fieldno) = FIELD_LOC_KIND_DWARF_BLOCK)
10852 +#define TYPE_ARRAY_BOUND_IS_DWARF_BLOCK(array_type, fieldno) \
10853 + TYPE_RANGE_BOUND_IS_DWARF_BLOCK (TYPE_INDEX_TYPE (array_type), fieldno)
10855 +/* Unbound arrays, such as GCC array[]; at end of struct. */
10856 +#define TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED(rangetype) \
10857 + TYPE_FIELD_ARTIFICIAL((rangetype),0)
10858 +#define TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED(rangetype) \
10859 + TYPE_FIELD_ARTIFICIAL((rangetype),1)
10860 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
10861 - (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
10863 -#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
10864 - (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
10865 + TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (TYPE_INDEX_TYPE (arraytype))
10866 +#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
10867 + TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (TYPE_INDEX_TYPE (arraytype))
10869 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
10870 - (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
10871 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
10872 +#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
10873 + TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (arraytype))
10874 +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
10875 + element size if no specific stride value is known. */
10876 +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype) \
10877 + (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \
10878 + ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype)) \
10879 + : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
10883 @@ -855,6 +949,7 @@ extern void allocate_cplus_struct_type (struct type *);
10884 #define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
10885 #define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
10886 #define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
10887 +#define TYPE_MODULE_BLOCK(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.module_block
10888 #define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
10889 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
10890 #define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
10891 @@ -1131,7 +1226,7 @@ extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN
10892 Use alloc_type_arch to allocate a type owned by an architecture.
10893 Use alloc_type_copy to allocate a type with the same owner as a
10894 pre-existing template type, no matter whether objfile or gdbarch. */
10895 -extern struct type *alloc_type (struct objfile *);
10896 +extern struct type *alloc_type (struct objfile *, struct type *);
10897 extern struct type *alloc_type_arch (struct gdbarch *);
10898 extern struct type *alloc_type_copy (const struct type *);
10900 @@ -1226,6 +1321,18 @@ extern struct type *create_array_type (struct type *, struct type *,
10902 extern struct type *lookup_array_range_type (struct type *, int, int);
10904 +extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
10907 +extern int type_range_high_bound_internal (struct type *range_type);
10909 +extern int type_range_count_bound_internal (struct type *range_type);
10911 +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
10912 + struct type *element_type);
10914 +extern void finalize_type (struct type *type);
10916 extern struct type *create_string_type (struct type *, struct type *,
10918 extern struct type *lookup_string_range_type (struct type *, int, int);
10919 @@ -1262,6 +1369,8 @@ extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
10921 extern int is_ancestor (struct type *, struct type *);
10923 +extern void type_mark_used (struct type *type);
10925 /* Overload resolution */
10927 #define LENGTH_MATCH(bv) ((bv)->rank[0])
10928 @@ -1324,10 +1433,15 @@ extern void maintenance_print_type (char *, int);
10930 extern htab_t create_copied_types_hash (struct objfile *objfile);
10932 -extern struct type *copy_type_recursive (struct objfile *objfile,
10933 - struct type *type,
10934 +extern struct type *copy_type_recursive (struct type *type,
10935 htab_t copied_types);
10937 extern struct type *copy_type (const struct type *type);
10939 +extern void free_all_types (void);
10941 +extern void type_incref (struct type *type);
10943 +extern void type_decref (struct type *type);
10945 #endif /* GDBTYPES_H */
10946 diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
10947 index 0f9d44e..c910e88 100644
10948 --- a/gdb/gnu-v3-abi.c
10949 +++ b/gdb/gnu-v3-abi.c
10951 #include "demangle.h"
10952 #include "objfiles.h"
10953 #include "valprint.h"
10954 +#include "c-lang.h"
10956 #include "gdb_assert.h"
10957 #include "gdb_string.h"
10958 @@ -459,10 +460,8 @@ gnuv3_find_method_in (struct type *domain, CORE_ADDR voffset,
10959 LONGEST adjustment)
10962 - const char *physname;
10964 /* Search this class first. */
10966 if (adjustment == 0)
10969 @@ -590,15 +589,24 @@ gnuv3_print_method_ptr (const gdb_byte *contents,
10971 char *demangled_name = cplus_demangle (physname,
10972 DMGL_ANSI | DMGL_PARAMS);
10973 - if (demangled_name != NULL)
10974 + fprintf_filtered (stream, "&virtual ");
10975 + if (demangled_name == NULL)
10976 + fputs_filtered (physname, stream);
10979 - fprintf_filtered (stream, "&virtual ");
10980 fputs_filtered (demangled_name, stream);
10981 xfree (demangled_name);
10987 + else if (ptr_value != 0)
10989 + /* Found a non-virtual function: print out the type. */
10990 + fputs_filtered ("(", stream);
10991 + c_print_type (type, "", stream, -1, 0);
10992 + fputs_filtered (") ", stream);
10995 /* We didn't find it; print the raw data. */
10997 diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
10998 index fe848ff..170e6cd 100644
10999 --- a/gdb/i386-linux-nat.c
11000 +++ b/gdb/i386-linux-nat.c
11001 @@ -586,6 +586,8 @@ i386_linux_store_inferior_registers (struct target_ops *ops,
11003 static unsigned long i386_linux_dr[DR_CONTROL + 1];
11005 +/* Get debug register REGNUM value from only the one LWP of PTID. */
11007 static unsigned long
11008 i386_linux_dr_get (ptid_t ptid, int regnum)
11010 @@ -614,6 +616,8 @@ i386_linux_dr_get (ptid_t ptid, int regnum)
11014 +/* Set debug register REGNUM to VALUE in only the one LWP of PTID. */
11017 i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
11019 @@ -630,6 +634,8 @@ i386_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
11020 perror_with_name (_("Couldn't write debug register"));
11023 +/* Set DR_CONTROL to ADDR in all LWPs of LWP_LIST. */
11026 i386_linux_dr_set_control (unsigned long control)
11028 @@ -641,6 +647,8 @@ i386_linux_dr_set_control (unsigned long control)
11029 i386_linux_dr_set (ptid, DR_CONTROL, control);
11032 +/* Set address REGNUM (zero based) to ADDR in all LWPs of LWP_LIST. */
11035 i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
11037 @@ -654,18 +662,55 @@ i386_linux_dr_set_addr (int regnum, CORE_ADDR addr)
11038 i386_linux_dr_set (ptid, DR_FIRSTADDR + regnum, addr);
11041 +/* Set address REGNUM (zero based) to zero in all LWPs of LWP_LIST. */
11044 i386_linux_dr_reset_addr (int regnum)
11046 i386_linux_dr_set_addr (regnum, 0);
11049 +/* Get DR_STATUS from only the one LWP of INFERIOR_PTID. */
11051 static unsigned long
11052 i386_linux_dr_get_status (void)
11054 return i386_linux_dr_get (inferior_ptid, DR_STATUS);
11057 +/* Unset VALUE bits in DR_STATUS in all LWPs of LWP_LIST. */
11060 +i386_linux_dr_unset_status (unsigned long mask)
11062 + struct lwp_info *lp;
11065 + ALL_LWPS (lp, ptid)
11067 + unsigned long value;
11069 + value = i386_linux_dr_get (ptid, DR_STATUS);
11071 + i386_linux_dr_set (ptid, DR_STATUS, value);
11075 +/* See i386_dr_low_type.detach. Do not use wrappers i386_linux_dr_set_control
11076 + or i386_linux_dr_reset_addr as they would modify the register cache
11077 + (i386_linux_dr). */
11080 +i386_linux_dr_detach (void)
11084 + i386_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
11085 + i386_linux_dr_unset_status (~0UL);
11086 + for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
11087 + i386_linux_dr_set (inferior_ptid, regnum, 0);
11091 i386_linux_new_thread (ptid_t ptid)
11093 @@ -837,6 +882,8 @@ _initialize_i386_linux_nat (void)
11094 i386_dr_low.set_addr = i386_linux_dr_set_addr;
11095 i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
11096 i386_dr_low.get_status = i386_linux_dr_get_status;
11097 + i386_dr_low.unset_status = i386_linux_dr_unset_status;
11098 + i386_dr_low.detach = i386_linux_dr_detach;
11099 i386_set_debug_register_length (4);
11101 /* Override the default ptrace resume method. */
11102 diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c
11103 index ab1bd8a..ee330b8 100644
11104 --- a/gdb/i386-nat.c
11105 +++ b/gdb/i386-nat.c
11106 @@ -137,8 +137,11 @@ struct i386_dr_low_type i386_dr_low;
11107 #define I386_DR_GET_RW_LEN(i) \
11108 ((dr_control_mirror >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f)
11110 +/* Mask that this I'th watchpoint has triggered. */
11111 +#define I386_DR_WATCH_MASK(i) (1 << (i))
11113 /* Did the watchpoint whose address is in the I'th register break? */
11114 -#define I386_DR_WATCH_HIT(i) (dr_status_mirror & (1 << (i)))
11115 +#define I386_DR_WATCH_HIT(i) (dr_status_mirror & I386_DR_WATCH_MASK (i))
11117 /* A macro to loop over all debug registers. */
11118 #define ALL_DEBUG_REGISTERS(i) for (i = 0; i < DR_NADDR; i++)
11119 @@ -358,6 +361,10 @@ i386_insert_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits)
11120 i386_dr_low.set_addr (i, addr);
11121 i386_dr_low.set_control (dr_control_mirror);
11123 + /* Only a sanity check for leftover bits (set possibly only by inferior). */
11124 + if (i386_dr_low.unset_status)
11125 + i386_dr_low.unset_status (I386_DR_WATCH_MASK (i));
11130 @@ -387,6 +394,11 @@ i386_remove_aligned_watchpoint (CORE_ADDR addr, unsigned len_rw_bits)
11131 i386_dr_low.set_control (dr_control_mirror);
11132 if (i386_dr_low.reset_addr)
11133 i386_dr_low.reset_addr (i);
11135 + /* Status must be already queried for each LWP. Otherwise it will
11136 + be lost in all-stop mode + breakpoint always-inserted off. */
11137 + if (i386_dr_low.unset_status)
11138 + i386_dr_low.unset_status (I386_DR_WATCH_MASK (i));
11142 @@ -520,6 +532,17 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type)
11146 +/* See target_detach_watchpoints. */
11149 +i386_detach_watchpoints (void)
11151 + if (i386_dr_low.detach)
11152 + i386_dr_low.detach ();
11157 /* Return non-zero if we can watch a memory region that starts at
11158 address ADDR and whose length is LEN bytes. */
11160 @@ -575,28 +598,7 @@ static int
11161 i386_stopped_by_watchpoint (void)
11163 CORE_ADDR addr = 0;
11164 - return i386_stopped_data_address (¤t_target, &addr);
11167 -/* Return non-zero if the inferior has some break/watchpoint that
11171 -i386_stopped_by_hwbp (void)
11175 - dr_status_mirror = i386_dr_low.get_status ();
11176 - if (maint_show_dr)
11177 - i386_show_dr ("stopped_by_hwbp", 0, 0, hw_execute);
11179 - ALL_DEBUG_REGISTERS(i)
11181 - if (I386_DR_WATCH_HIT (i))
11186 + return target_stopped_data_address (¤t_target, &addr);
11189 /* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
11190 @@ -690,6 +692,7 @@ i386_use_watchpoints (struct target_ops *t)
11191 t->to_stopped_data_address = i386_stopped_data_address;
11192 t->to_insert_watchpoint = i386_insert_watchpoint;
11193 t->to_remove_watchpoint = i386_remove_watchpoint;
11194 + t->to_detach_watchpoints = i386_detach_watchpoints;
11195 t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
11196 t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
11198 diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h
11199 index f49b9f6..cd31958 100644
11200 --- a/gdb/i386-nat.h
11201 +++ b/gdb/i386-nat.h
11202 @@ -49,16 +49,23 @@ extern void i386_use_watchpoints (struct target_ops *);
11205 set_control -- set the debug control (DR7)
11206 - register to a given value
11207 + register to a given value for all LWPs
11209 set_addr -- put an address into one debug
11211 + register for all LWPs
11213 reset_addr -- reset the address stored in
11214 - one debug register
11215 + one debug register for all LWPs
11217 get_status -- return the value of the debug
11218 - status (DR6) register.
11219 + status (DR6) register for current LWP
11221 + unset_status -- unset the specified bits of the debug
11222 + status (DR6) register for all LWPs
11224 + detach -- clear all debug registers of only the
11225 + INFERIOR_PTID task without affecting any
11228 Additionally, the native file should set the debug_register_length
11229 field to 4 or 8 depending on the number of bytes used for
11230 @@ -70,6 +77,8 @@ struct i386_dr_low_type
11231 void (*set_addr) (int, CORE_ADDR);
11232 void (*reset_addr) (int);
11233 unsigned long (*get_status) (void);
11234 + void (*unset_status) (unsigned long);
11235 + void (*detach) (void);
11236 int debug_register_length;
11239 diff --git a/gdb/infcmd.c b/gdb/infcmd.c
11240 index 9e98290..fab1892 100644
11243 @@ -801,7 +801,7 @@ nexti_command (char *count_string, int from_tty)
11244 step_1 (1, 1, count_string);
11249 delete_longjmp_breakpoint_cleanup (void *arg)
11251 int thread = * (int *) arg;
11252 @@ -841,10 +841,13 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
11254 if (!single_inst || skip_subroutines) /* leave si command alone */
11256 + struct thread_info *tp = inferior_thread ();
11258 if (in_thread_list (inferior_ptid))
11259 thread = pid_to_thread_id (inferior_ptid);
11261 set_longjmp_breakpoint (thread);
11262 + tp->initiating_frame = get_frame_id (get_current_frame ());
11264 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11266 @@ -1193,6 +1196,15 @@ signal_command (char *signum_exp, int from_tty)
11267 proceed ((CORE_ADDR) -1, oursig, 0);
11270 +/* A continuation callback for until_next_command. */
11273 +until_next_continuation (void *arg)
11275 + struct thread_info *tp = arg;
11276 + delete_longjmp_breakpoint (tp->num);
11279 /* Proceed until we reach a different source line with pc greater than
11280 our current one or exit the function. We skip calls in both cases.
11282 @@ -1209,6 +1221,8 @@ until_next_command (int from_tty)
11283 struct symbol *func;
11284 struct symtab_and_line sal;
11285 struct thread_info *tp = inferior_thread ();
11286 + int thread = tp->num;
11287 + struct cleanup *old_chain;
11289 clear_proceed_status ();
11291 @@ -1244,7 +1258,19 @@ until_next_command (int from_tty)
11293 tp->step_multi = 0; /* Only one call to proceed */
11295 + set_longjmp_breakpoint (thread);
11296 + tp->initiating_frame = get_frame_id (frame);
11297 + old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11299 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
11301 + if (target_can_async_p () && is_running (inferior_ptid))
11303 + discard_cleanups (old_chain);
11304 + add_continuation (tp, until_next_continuation, tp, NULL);
11307 + do_cleanups (old_chain);
11311 @@ -1421,6 +1447,7 @@ finish_command_continuation (void *arg)
11312 if (bs != NULL && tp->proceed_to_finish)
11313 observer_notify_normal_stop (bs, 1 /* print frame */);
11314 delete_breakpoint (a->breakpoint);
11315 + delete_longjmp_breakpoint (inferior_thread ()->num);
11319 @@ -1504,6 +1531,7 @@ finish_forward (struct symbol *function, struct frame_info *frame)
11320 struct breakpoint *breakpoint;
11321 struct cleanup *old_chain;
11322 struct finish_command_continuation_args *cargs;
11323 + int thread = tp->num;
11325 sal = find_pc_line (get_frame_pc (frame), 0);
11326 sal.pc = get_frame_pc (frame);
11327 @@ -1514,6 +1542,10 @@ finish_forward (struct symbol *function, struct frame_info *frame)
11329 old_chain = make_cleanup_delete_breakpoint (breakpoint);
11331 + set_longjmp_breakpoint (thread);
11332 + tp->initiating_frame = get_frame_id (frame);
11333 + make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
11335 tp->proceed_to_finish = 1; /* We want stop_registers, please... */
11336 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
11338 diff --git a/gdb/inferior.h b/gdb/inferior.h
11339 index f1b5d17..31add7d 100644
11340 --- a/gdb/inferior.h
11341 +++ b/gdb/inferior.h
11342 @@ -272,6 +272,8 @@ extern void interrupt_target_command (char *args, int from_tty);
11344 extern void interrupt_target_1 (int all_threads);
11346 +extern void delete_longjmp_breakpoint_cleanup (void *arg);
11348 extern void detach_command (char *, int);
11350 extern void notice_new_inferior (ptid_t, int, int);
11351 diff --git a/gdb/infrun.c b/gdb/infrun.c
11352 index 1a83a25..2ee2164 100644
11356 #include "language.h"
11359 +#include "dictionary.h"
11360 +#include "block.h"
11361 #include "gdb_assert.h"
11362 #include "mi/mi-common.h"
11363 #include "event-top.h"
11364 @@ -1782,6 +1784,8 @@ static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
11365 struct symtab_and_line sr_sal,
11366 struct frame_id sr_id);
11367 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
11368 +static void check_exception_resume (struct execution_control_state *,
11369 + struct frame_info *, struct symbol *);
11371 static void stop_stepping (struct execution_control_state *ecs);
11372 static void prepare_to_wait (struct execution_control_state *ecs);
11373 @@ -2687,6 +2691,10 @@ handle_inferior_event (struct execution_control_state *ecs)
11375 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
11377 + /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
11378 + confuse bpstat_stop_status and bpstat_explains_signal. */
11379 + watchpoints_triggered (&ecs->ws);
11381 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
11383 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
11384 @@ -2724,6 +2732,10 @@ handle_inferior_event (struct execution_control_state *ecs)
11386 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
11388 + /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
11389 + confuse bpstat_stop_status and bpstat_explains_signal. */
11390 + watchpoints_triggered (&ecs->ws);
11392 /* This causes the eventpoints and symbol table to be reset.
11393 Must do this now, before trying to determine whether to
11395 @@ -3468,23 +3480,33 @@ process_event_stop_test:
11397 ecs->event_thread->stepping_over_breakpoint = 1;
11399 - if (!gdbarch_get_longjmp_target_p (gdbarch)
11400 - || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
11401 + if (what.is_longjmp)
11403 - if (debug_infrun)
11404 - fprintf_unfiltered (gdb_stdlog, "\
11405 + if (!gdbarch_get_longjmp_target_p (gdbarch)
11406 + || !gdbarch_get_longjmp_target (gdbarch,
11407 + frame, &jmp_buf_pc))
11409 + if (debug_infrun)
11410 + fprintf_unfiltered (gdb_stdlog, "\
11411 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
11412 - keep_going (ecs);
11415 + keep_going (ecs);
11419 - /* We're going to replace the current step-resume breakpoint
11420 - with a longjmp-resume breakpoint. */
11421 - delete_step_resume_breakpoint (ecs->event_thread);
11422 + /* We're going to replace the current step-resume breakpoint
11423 + with a longjmp-resume breakpoint. */
11424 + delete_step_resume_breakpoint (ecs->event_thread);
11426 - /* Insert a breakpoint at resume address. */
11427 - insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
11428 + /* Insert a breakpoint at resume address. */
11429 + insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
11433 + struct symbol *func = get_frame_function (frame);
11436 + check_exception_resume (ecs, frame, func);
11441 @@ -3496,6 +3518,53 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
11442 gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
11443 delete_step_resume_breakpoint (ecs->event_thread);
11445 + if (!what.is_longjmp)
11447 + /* There are several cases to consider.
11449 + 1. The initiating frame no longer exists. In this case
11450 + we must stop, because the exception has gone too far.
11452 + 2. The initiating frame exists, and is the same as the
11455 + 2.1. If we are stepping, defer to the stepping logic.
11457 + 2.2. Otherwise, we are not stepping, so we are doing a
11458 + "finish" and we have reached the calling frame. So,
11461 + 3. The initiating frame exists and is different from
11462 + the current frame. This means the exception has been
11463 + caught beneath the initiating frame, so keep going. */
11464 + struct frame_info *init_frame
11465 + = frame_find_by_id (ecs->event_thread->initiating_frame);
11468 + struct frame_id current_id
11469 + = get_frame_id (get_current_frame ());
11470 + if (frame_id_eq (current_id,
11471 + ecs->event_thread->initiating_frame))
11473 + if (ecs->event_thread->step_range_start)
11480 + /* Case 2.2: fall through. */
11486 + keep_going (ecs);
11492 ecs->event_thread->stop_step = 1;
11493 print_stop_reason (END_STEPPING_RANGE, 0);
11494 stop_stepping (ecs);
11495 @@ -4500,6 +4569,96 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
11496 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
11499 +/* Insert an exception resume breakpoint. TP is the thread throwing
11500 + the exception. The block B is the block of the unwinder debug hook
11501 + function. FRAME is the frame corresponding to the call to this
11502 + function. SYM is the symbol of the function argument holding the
11503 + target PC of the exception. */
11506 +insert_exception_resume_breakpoint (struct thread_info *tp,
11508 + struct frame_info *frame,
11509 + struct symbol *sym)
11511 + struct gdb_exception e;
11513 + /* We want to ignore errors here. */
11514 + TRY_CATCH (e, RETURN_MASK_ALL)
11516 + struct symbol *vsym;
11517 + struct value *value;
11518 + CORE_ADDR handler;
11519 + struct breakpoint *bp;
11521 + vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
11522 + value = read_var_value (vsym, frame);
11523 + handler = value_as_address (value);
11525 + /* We're going to replace the current step-resume breakpoint
11526 + with an exception-resume breakpoint. */
11527 + delete_step_resume_breakpoint (tp);
11529 + if (debug_infrun)
11530 + fprintf_unfiltered (gdb_stdlog,
11531 + "infrun: exception resume at %lx\n",
11532 + (unsigned long) handler);
11534 + bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
11535 + handler, bp_exception_resume);
11536 + inferior_thread ()->step_resume_breakpoint = bp;
11540 +/* This is called when an exception has been intercepted. Check to
11541 + see whether the exception's destination is of interest, and if so,
11542 + set an exception resume breakpoint there. */
11545 +check_exception_resume (struct execution_control_state *ecs,
11546 + struct frame_info *frame, struct symbol *func)
11548 + struct gdb_exception e;
11550 + TRY_CATCH (e, RETURN_MASK_ALL)
11553 + struct dict_iterator iter;
11554 + struct symbol *sym;
11557 + /* The exception breakpoint is a thread-specific breakpoint on
11558 + the unwinder's debug hook, declared as:
11560 + void _Unwind_DebugHook (void *cfa, void *handler);
11562 + The CFA argument indicates the frame to which control is
11563 + about to be transferred. HANDLER is the destination PC.
11565 + We ignore the CFA and set a temporary breakpoint at HANDLER.
11566 + This is not extremely efficient but it avoids issues in gdb
11567 + with computing the DWARF CFA, and it also works even in weird
11568 + cases such as throwing an exception from inside a signal
11571 + b = SYMBOL_BLOCK_VALUE (func);
11572 + ALL_BLOCK_SYMBOLS (b, iter, sym)
11574 + if (!SYMBOL_IS_ARGUMENT (sym))
11581 + insert_exception_resume_breakpoint (ecs->event_thread,
11590 stop_stepping (struct execution_control_state *ecs)
11592 @@ -4568,6 +4727,8 @@ keep_going (struct execution_control_state *ecs)
11596 + if (debug_infrun)
11597 + exception_fprintf (gdb_stdlog, e, "infrun: exception while inserting breakpoints: ");
11598 stop_stepping (ecs);
11601 diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
11602 index 6b68e7d..5095180 100644
11603 --- a/gdb/jv-lang.c
11604 +++ b/gdb/jv-lang.c
11605 @@ -1121,6 +1121,7 @@ const struct exp_descriptor exp_descriptor_java =
11607 print_subexp_standard,
11608 operator_length_standard,
11609 + operator_check_standard,
11611 dump_subexp_body_standard,
11612 evaluate_subexp_java
11613 diff --git a/gdb/language.h b/gdb/language.h
11614 index c650e07..660fdf6 100644
11615 --- a/gdb/language.h
11616 +++ b/gdb/language.h
11617 @@ -237,7 +237,6 @@ struct language_defn
11620 struct symbol *(*la_lookup_symbol_nonlocal) (const char *,
11622 const struct block *,
11623 const domain_enum);
11625 diff --git a/gdb/linespec.c b/gdb/linespec.c
11626 index 3e943a1..b96d425 100644
11627 --- a/gdb/linespec.c
11628 +++ b/gdb/linespec.c
11631 #include "completer.h"
11632 #include "cp-abi.h"
11633 +#include "cp-support.h"
11634 #include "parser-defs.h"
11636 #include "objc-lang.h"
11637 @@ -839,13 +840,33 @@ decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
11639 else if (paren_pointer != NULL)
11641 - p = paren_pointer + 1;
11642 + /* We need to deal with method and function overloads
11643 + with no parameters. Gdb and gcc (and who knows about other
11644 + compilers) are very inconsistent with the keyword "void".
11645 + Canonicalizing C++ types is insufficient in this case, since
11646 + we still need to enforce the presence (or lack thereof) of
11647 + "void". For simplicity, omit the keyword "void" if present. */
11648 + if (strncmp (paren_pointer - 5, "(void)", 6) == 0)
11651 + a = paren_pointer - 4;
11652 + b = paren_pointer;
11653 + while ((*(a++) = *(b++)) != '\0') ;
11655 + p = paren_pointer - 3;
11658 + p = paren_pointer + 1;
11662 p = skip_quoted (*argptr);
11665 + /* Make sure we keep important kewords like "const" */
11666 + if (strncmp (p, " const", 6) == 0)
11669 /* Keep any template parameters */
11671 p = find_template_name_end (p);
11672 @@ -1257,6 +1278,9 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
11673 /* Move pointer ahead to next double-colon. */
11674 while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\''))
11676 + if (current_language->la_language == language_cplus)
11677 + p += cp_validate_operator (p);
11681 temp_end = find_template_name_end (p);
11682 @@ -1334,6 +1358,15 @@ decode_compound (char **argptr, int funfirstline, char ***canonical,
11683 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':')
11685 /* At this point p->"". String ended. */
11686 + /* Nope, C++ operators could have spaces in them
11687 + ("foo::operator <" or "foo::operator delete []").
11688 + I apologize, this is a bit hacky... */
11689 + if (current_language->la_language == language_cplus
11690 + && *p == ' ' && p - 8 - *argptr + 1 > 0)
11692 + /* The above loop has already swallowed "operator". */
11693 + p += cp_validate_operator (p - 8) - 8;
11697 /* Allocate our own copy of the substring between argptr and
11698 @@ -1407,6 +1440,7 @@ lookup_prefix_sym (char **argptr, char *p)
11702 + struct symbol *sym;
11704 /* Extract the class name. */
11706 @@ -1425,7 +1459,26 @@ lookup_prefix_sym (char **argptr, char *p)
11707 /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
11708 argptr->"inA::fun" */
11710 - return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
11711 + sym = lookup_symbol (copy, 0, STRUCT_DOMAIN, 0);
11714 + /* Typedefs are in VAR_DOMAIN so the above symbol lookup will
11715 + fail when the user attempts to lookup a method of a class
11716 + via a typedef'd name (NOT via the classes name, which is already
11717 + handled in symbol_matches_domain). So try the lookup again
11718 + using VAR_DOMAIN (where typedefs live) and double-check that we
11719 + found a struct/class type. */
11720 + struct symbol *s = lookup_symbol (copy, 0, VAR_DOMAIN, 0);
11723 + struct type *t = SYMBOL_TYPE (s);
11724 + CHECK_TYPEDEF (t);
11725 + if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
11733 /* This finds the method COPY in the class whose type is T and whose
11734 @@ -1474,26 +1527,16 @@ find_method (int funfirstline, char ***canonical, char *saved_arg,
11740 - if (is_operator_name (copy))
11742 - tmp = (char *) alloca (strlen (copy + 3) + 9);
11743 - strcpy (tmp, "operator ");
11744 - strcat (tmp, copy + 3);
11749 *not_found_ptr = 1;
11750 - if (tmp[0] == '~')
11751 + if (copy[0] == '~')
11752 cplusplus_error (saved_arg,
11753 "the class `%s' does not have destructor defined\n",
11754 SYMBOL_PRINT_NAME (sym_class));
11756 cplusplus_error (saved_arg,
11757 "the class %s does not have any method named %s\n",
11758 - SYMBOL_PRINT_NAME (sym_class), tmp);
11759 + SYMBOL_PRINT_NAME (sym_class), copy);
11763 @@ -1780,7 +1823,7 @@ symbol_found (int funfirstline, char ***canonical, char *copy,
11765 struct blockvector *bv = BLOCKVECTOR (SYMBOL_SYMTAB (sym));
11766 struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
11767 - if (lookup_block_symbol (b, copy, NULL, VAR_DOMAIN) != NULL)
11768 + if (lookup_block_symbol (b, copy, VAR_DOMAIN) != NULL)
11769 build_canonical_line_spec (values.sals, copy, canonical);
11772 diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
11773 index 98f6347..0907f03 100644
11774 --- a/gdb/linux-nat.c
11775 +++ b/gdb/linux-nat.c
11776 @@ -1710,6 +1710,7 @@ resume_callback (struct lwp_info *lp, void *data)
11779 memset (&lp->siginfo, 0, sizeof (lp->siginfo));
11780 + lp->watchpoint_hit_set = 0;
11782 else if (lp->stopped && debug_linux_nat)
11783 fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (has pending)\n",
11784 @@ -1847,6 +1848,7 @@ linux_nat_resume (struct target_ops *ops,
11786 linux_ops->to_resume (linux_ops, ptid, step, signo);
11787 memset (&lp->siginfo, 0, sizeof (lp->siginfo));
11788 + lp->watchpoint_hit_set = 0;
11790 if (debug_linux_nat)
11791 fprintf_unfiltered (gdb_stdlog,
11792 @@ -2286,6 +2288,78 @@ maybe_clear_ignore_sigint (struct lwp_info *lp)
11796 +/* Fetch the possible triggered data watchpoint info and store it to LP.
11797 + The hardware data watchpoint trigger gets cleared during this fetch. */
11800 +save_sigtrap (struct lwp_info *lp)
11802 + struct cleanup *old_chain;
11804 + /* linux_nat_stopped_data_address is not even installed in this case. */
11805 + if (linux_ops->to_stopped_data_address == NULL)
11808 + old_chain = save_inferior_ptid ();
11809 + inferior_ptid = lp->ptid;
11811 + lp->watchpoint_hit_set =
11812 + linux_ops->to_stopped_data_address (¤t_target, &lp->watchpoint_hit);
11814 + do_cleanups (old_chain);
11817 +/* Wrap target_stopped_data_address where the GNU/Linux native target may be
11818 + directed by the watchpoint/debug register number. Base the reported value
11819 + on the triggered data address instead. During inferior stop the assignment
11820 + of watchpoint/debug registers may change making the register number specific
11821 + trigger info stale. */
11824 +linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
11826 + struct lwp_info *lp = find_lwp_pid (inferior_ptid);
11828 + gdb_assert (lp != NULL);
11830 + *addr_p = lp->watchpoint_hit;
11832 + return lp->watchpoint_hit_set;
11835 +/* In `set follow-fork-mode child' with multithreaded parent we need to detach
11836 + watchpoints from all the LWPs. In such case INFERIOR_PTID will be the
11837 + non-threaded new child while LWP_LIST will still contain all the threads of
11838 + the parent being detached. */
11841 +linux_nat_detach_watchpoints (void)
11843 + struct lwp_info *lp;
11844 + int found = 0, retval = 0;
11845 + ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
11846 + struct cleanup *old_chain = save_inferior_ptid ();
11848 + for (lp = lwp_list; lp; lp = lp->next)
11849 + if (ptid_match (lp->ptid, filter))
11851 + inferior_ptid = lp->ptid;
11852 + retval |= linux_ops->to_detach_watchpoints ();
11856 + do_cleanups (old_chain);
11860 + gdb_assert (!is_lwp (inferior_ptid));
11862 + retval |= linux_ops->to_detach_watchpoints ();
11868 /* Wait until LP is stopped. */
11871 @@ -2337,6 +2411,8 @@ stop_wait_callback (struct lwp_info *lp, void *data)
11872 /* Save the trap's siginfo in case we need it later. */
11875 + save_sigtrap (lp);
11877 /* Now resume this LWP and get the SIGSTOP event. */
11879 ptrace (PTRACE_CONT, GET_LWP (lp->ptid), 0, 0);
11880 @@ -2701,10 +2777,14 @@ linux_nat_filter_event (int lwpid, int status, int options)
11881 add_thread (lp->ptid);
11884 - /* Save the trap's siginfo in case we need it later. */
11885 if (WIFSTOPPED (status)
11886 && (WSTOPSIG (status) == SIGTRAP || WSTOPSIG (status) == TRAP_IS_SYSCALL))
11887 - save_siginfo (lp);
11889 + /* Save the trap's siginfo in case we need it later. */
11890 + save_siginfo (lp);
11892 + save_sigtrap (lp);
11895 /* Handle GNU/Linux's extended waitstatus for trace events.
11896 It is necessary to check if WSTOPSIG is signaling that
11897 @@ -4999,6 +5079,10 @@ linux_nat_add_target (struct target_ops *t)
11898 t->to_thread_alive = linux_nat_thread_alive;
11899 t->to_pid_to_str = linux_nat_pid_to_str;
11900 t->to_has_thread_control = tc_schedlock;
11901 + if (linux_ops->to_stopped_data_address)
11902 + t->to_stopped_data_address = linux_nat_stopped_data_address;
11903 + if (linux_ops->to_detach_watchpoints)
11904 + t->to_detach_watchpoints = linux_nat_detach_watchpoints;
11906 t->to_can_async_p = linux_nat_can_async_p;
11907 t->to_is_async_p = linux_nat_is_async_p;
11908 diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
11909 index eae74f3..73204fc 100644
11910 --- a/gdb/linux-nat.h
11911 +++ b/gdb/linux-nat.h
11912 @@ -62,6 +62,12 @@ struct lwp_info
11913 be the address of a hardware watchpoint. */
11914 struct siginfo siginfo;
11916 + /* WATCHPOINT_HIT_SET is non-zero if this LWP stopped with a trap and a data
11917 + watchpoint has been found as triggered. In such case WATCHPOINT_HIT
11918 + contains data address of the triggered data watchpoint. */
11919 + unsigned watchpoint_hit_set : 1;
11920 + CORE_ADDR watchpoint_hit;
11922 /* Non-zero if we expect a duplicated SIGINT. */
11925 diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
11926 index 88c7e5e..2d0b3ca 100644
11927 --- a/gdb/m2-lang.c
11928 +++ b/gdb/m2-lang.c
11929 @@ -356,6 +356,7 @@ const struct exp_descriptor exp_descriptor_modula2 =
11931 print_subexp_standard,
11932 operator_length_standard,
11933 + operator_check_standard,
11935 dump_subexp_body_standard,
11936 evaluate_subexp_modula2
11937 diff --git a/gdb/machoread.c b/gdb/machoread.c
11938 index 5f9a0fe..66fa067 100644
11939 --- a/gdb/machoread.c
11940 +++ b/gdb/machoread.c
11941 @@ -681,6 +681,7 @@ static struct sym_fns macho_sym_fns = {
11942 macho_new_init, /* sym_new_init: init anything gbl to entire symtab */
11943 macho_symfile_init, /* sym_init: read initial info, setup for sym_read() */
11944 macho_symfile_read, /* sym_read: read a symbol file into symtab */
11945 + NULL, /* sym_read_psymbols */
11946 macho_symfile_finish, /* sym_finish: finished with file, cleanup */
11947 macho_symfile_offsets, /* sym_offsets: xlate external to internal form */
11948 NULL /* next: pointer to next struct sym_fns */
11949 diff --git a/gdb/main.c b/gdb/main.c
11950 index 55411a8..ac9a540 100644
11954 #include "interps.h"
11957 +#include "python/python.h"
11958 #include "source.h"
11960 /* If nonzero, display time usage both at startup and for each command. */
11961 @@ -259,6 +260,8 @@ captured_main (void *data)
11962 char *cdarg = NULL;
11963 char *ttyarg = NULL;
11965 + int python_script = 0;
11967 /* These are static so that we can take their address in an initializer. */
11968 static int print_help;
11969 static int print_version;
11970 @@ -434,10 +437,14 @@ captured_main (void *data)
11971 {"args", no_argument, &set_args, 1},
11972 {"l", required_argument, 0, 'l'},
11973 {"return-child-result", no_argument, &return_child_result, 1},
11975 + {"python", no_argument, 0, 'P'},
11976 + {"P", no_argument, 0, 'P'},
11978 {0, no_argument, 0, 0}
11982 + while (!python_script)
11986 @@ -455,6 +462,9 @@ captured_main (void *data)
11988 /* Long option that just sets a flag. */
11991 + python_script = 1;
11996 @@ -631,7 +641,31 @@ extern int gdbtk_test (char *);
12001 + if (python_script)
12003 + /* The first argument is a python script to evaluate, and
12004 + subsequent arguments are passed to the script for
12005 + processing there. */
12006 + if (optind >= argc)
12008 + fprintf_unfiltered (gdb_stderr,
12009 + _("%s: Python script file name required\n"),
12014 + /* FIXME: should handle inferior I/O intelligently here.
12015 + E.g., should be possible to run gdb in pipeline and have
12016 + Python (and gdb) output go to stderr or file; and if a
12017 + prompt is needed, open the tty. */
12019 + /* FIXME: should read .gdbinit if, and only if, a prompt is
12020 + requested by the script. Though... maybe this is not
12022 + /* FIXME: likewise, reading in history. */
12023 + inhibit_gdbinit = 1;
12025 + else if (set_args)
12027 /* The remaining options are the command-line options for the
12028 inferior. The first one is the sym/exec file, and the rest
12029 @@ -864,7 +898,8 @@ Can't attach to process and specify a core file at the same time."));
12032 /* Read in the old history after all the command files have been read. */
12034 + if (!python_script)
12039 @@ -893,13 +928,25 @@ Can't attach to process and specify a core file at the same time."));
12043 - /* NOTE: cagney/1999-11-07: There is probably no reason for not
12044 - moving this loop and the code found in captured_command_loop()
12045 - into the command_loop() proper. The main thing holding back that
12046 - change - SET_TOP_LEVEL() - has been eliminated. */
12049 + if (python_script)
12051 - catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
12052 + extern int pagination_enabled;
12053 + pagination_enabled = 0;
12054 + run_python_script (argc - optind, &argv[optind]);
12060 + /* NOTE: cagney/1999-11-07: There is probably no reason for not
12061 + moving this loop and the code found in captured_command_loop()
12062 + into the command_loop() proper. The main thing holding back that
12063 + change - SET_TOP_LEVEL() - has been eliminated. */
12066 + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
12069 /* No exit -- exit is through quit_command. */
12071 @@ -931,7 +978,12 @@ print_gdb_help (struct ui_file *stream)
12072 fputs_unfiltered (_("\
12073 This is the GNU debugger. Usage:\n\n\
12074 gdb [options] [executable-file [core-file or process-id]]\n\
12075 - gdb [options] --args executable-file [inferior-arguments ...]\n\n\
12076 + gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
12078 + fputs_unfiltered (_("\
12079 + gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
12081 + fputs_unfiltered (_("\n\
12084 fputs_unfiltered (_("\
12085 @@ -969,7 +1021,13 @@ Options:\n\n\
12086 --nw Do not use a window interface.\n\
12087 --nx Do not read "), stream);
12088 fputs_unfiltered (gdbinit, stream);
12089 - fputs_unfiltered (_(" file.\n\
12090 + fputs_unfiltered (_(" file.\n"), stream);
12092 + fputs_unfiltered (_("\
12093 + --python, -P Following argument is Python script file; remaining\n\
12094 + arguments are passed to script.\n"), stream);
12096 + fputs_unfiltered (_("\
12097 --quiet Do not print version number on startup.\n\
12098 --readnow Fully read symbol files on first access.\n\
12100 diff --git a/gdb/maint.c b/gdb/maint.c
12101 index ecbae12..80fc36e 100644
12104 @@ -914,4 +914,12 @@ When enabled GDB is profiled."),
12105 show_maintenance_profile_p,
12106 &maintenance_set_cmdlist,
12107 &maintenance_show_cmdlist);
12108 + add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
12109 + &gdb_datadir, _("Set GDB's datadir path."),
12110 + _("Show GDB's datadir path."),
12112 +When set, GDB uses the specified path to search for data files."),
12114 + &maintenance_set_cmdlist,
12115 + &maintenance_show_cmdlist);
12117 diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
12118 index aac82e9..626292c 100644
12119 --- a/gdb/mdebugread.c
12120 +++ b/gdb/mdebugread.c
12121 @@ -4802,7 +4802,7 @@ new_type (char *name)
12125 - t = alloc_type (current_objfile);
12126 + t = alloc_type (current_objfile, NULL);
12127 TYPE_NAME (t) = name;
12128 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
12130 diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
12131 index 0baaa83..94ebfeb 100644
12132 --- a/gdb/mi/mi-cmd-var.c
12133 +++ b/gdb/mi/mi-cmd-var.c
12134 @@ -697,7 +697,6 @@ mi_cmd_var_update (char *command, char **argv, int argc)
12138 - /* Get varobj handle, if a valid var obj name was specified */
12139 struct varobj *var = varobj_get_handle (name);
12141 varobj_update_one (var, print_values, 1 /* explicit */);
12142 diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
12143 index 857a5d5..6181002 100644
12144 --- a/gdb/mi/mi-main.c
12145 +++ b/gdb/mi/mi-main.c
12146 @@ -1130,7 +1130,7 @@ mi_cmd_list_features (char *command, char **argv, int argc)
12147 ui_out_field_string (uiout, NULL, "frozen-varobjs");
12148 ui_out_field_string (uiout, NULL, "pending-breakpoints");
12149 ui_out_field_string (uiout, NULL, "thread-info");
12153 ui_out_field_string (uiout, NULL, "python");
12155 diff --git a/gdb/mipsread.c b/gdb/mipsread.c
12156 index a84003f..924c1c5 100644
12157 --- a/gdb/mipsread.c
12158 +++ b/gdb/mipsread.c
12159 @@ -394,6 +394,7 @@ static struct sym_fns ecoff_sym_fns =
12160 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
12161 mipscoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
12162 mipscoff_symfile_read, /* sym_read: read a symbol file into symtab */
12163 + NULL, /* sym_read_psymbols */
12164 mipscoff_symfile_finish, /* sym_finish: finished with file, cleanup */
12165 default_symfile_offsets, /* sym_offsets: dummy FIXME til implem sym reloc */
12166 default_symfile_segments, /* sym_segments: Get segment information from
12167 diff --git a/gdb/objfiles.c b/gdb/objfiles.c
12168 index 8dcca70..4b25a5a 100644
12169 --- a/gdb/objfiles.c
12170 +++ b/gdb/objfiles.c
12171 @@ -731,6 +731,20 @@ have_partial_symbols (void)
12172 if (objfile_has_partial_symbols (ofp))
12176 + /* Try again, after reading partial symbols. We do this in two
12177 + passes because objfiles are always added to the head of the list,
12178 + and there might be a later objfile for which we've already read
12179 + partial symbols. */
12180 + ALL_OBJFILES (ofp)
12182 + require_partial_symbols (ofp);
12183 + if (ofp->psymtabs != NULL)
12192 diff --git a/gdb/objfiles.h b/gdb/objfiles.h
12193 index 62fa498..1fc9c6a 100644
12194 --- a/gdb/objfiles.h
12195 +++ b/gdb/objfiles.h
12196 @@ -212,6 +212,11 @@ struct objfile
12198 struct partial_symtab *psymtabs;
12200 + /* An address map that can be used to quickly determine if an
12201 + address comes from this objfile. This can be NULL. */
12203 + struct addrmap *quick_addrmap;
12205 /* Map addresses to the entries of PSYMTABS. It would be more efficient to
12206 have a map per the whole process but ADDRMAP cannot selectively remove
12207 its items during FREE_OBJFILE. This mapping is already present even for
12208 @@ -414,6 +419,15 @@ struct objfile
12210 #define OBJF_USERLOADED (1 << 3) /* User loaded */
12212 +/* Set if we have tried to read partial symtabs for this objfile.
12213 + This is used to allow lazy reading of partial symtabs. */
12215 +#define OBJF_SYMTABS_READ (1 << 6)
12217 +/* This flag is set for the main objfile. */
12219 +#define OBJF_MAIN (1 << 7)
12221 /* The object file that the main symbol table was loaded from (e.g. the
12222 argument to the "symbol-file" or "file" command). */
12224 @@ -568,6 +582,13 @@ extern void gdb_bfd_unref (struct bfd *abfd);
12225 ALL_OBJFILES (objfile) \
12226 ALL_OBJFILE_PSYMTABS (objfile, p)
12228 +/* Like ALL_PSYMTABS, but ensure that partial symbols have been read
12229 + before examining the objfile. */
12231 +#define ALL_PSYMTABS_REQUIRED(objfile, p) \
12232 + ALL_OBJFILES (objfile) \
12233 + ALL_OBJFILE_PSYMTABS (require_partial_symbols (objfile), p)
12235 /* Traverse all minimal symbols in all objfiles. */
12237 #define ALL_MSYMBOLS(objfile, m) \
12238 diff --git a/gdb/parse.c b/gdb/parse.c
12239 index ef938e3..c243bd8 100644
12242 @@ -63,6 +63,7 @@ const struct exp_descriptor exp_descriptor_standard =
12244 print_subexp_standard,
12245 operator_length_standard,
12246 + operator_check_standard,
12248 dump_subexp_body_standard,
12249 evaluate_subexp_standard
12250 @@ -837,6 +838,15 @@ operator_length_standard (struct expression *expr, int endpos,
12251 args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
12254 + case TYPE_INSTANCE:
12255 + oplen = 4 + longest_to_int (expr->elts[endpos - 2].longconst);
12259 + case TYPE_INSTANCE_LOOKUP:
12263 case OP_OBJC_MSGCALL: /* Objective C message (method) call */
12265 args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
12266 @@ -1355,6 +1365,150 @@ parser_fprintf (FILE *x, const char *y, ...)
12270 +/* Implementation of the exp_descriptor method operator_check. */
12273 +operator_check_standard (struct expression *exp, int pos,
12274 + int (*type_func) (struct type *type, void *data),
12275 + int (*objfile_func) (struct objfile *objfile,
12279 + const union exp_element *const elts = exp->elts;
12280 + struct type *type = NULL;
12281 + struct objfile *objfile = NULL;
12283 + /* Extended operators should have been already handled by exp_descriptor
12284 + iterate method of its specific language. */
12285 + gdb_assert (elts[pos].opcode < OP_EXTENDED0);
12287 + /* Track the callers of write_exp_elt_type for this table. */
12289 + switch (elts[pos].opcode)
12293 + case OP_DECFLOAT:
12300 + case UNOP_MEMVAL:
12302 + type = elts[pos + 1].type;
12305 + case UNOP_MEMVAL_TLS:
12306 + objfile = elts[pos + 1].objfile;
12307 + type = elts[pos + 2].type;
12310 + case OP_VAR_VALUE:
12312 + const struct block *const block = elts[pos + 1].block;
12313 + const struct symbol *const symbol = elts[pos + 2].symbol;
12314 + const struct obj_section *const section = SYMBOL_OBJ_SECTION (symbol);
12316 + /* Check objfile where the variable itself is placed. */
12317 + if (section && objfile_func && (*objfile_func) (section->objfile, data))
12320 + /* Check objfile where is placed the code touching the variable. */
12321 + objfile = block_objfile (block);
12323 + type = SYMBOL_TYPE (symbol);
12328 + /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
12330 + if (type && type_func && (*type_func) (type, data))
12332 + if (type && TYPE_OBJFILE (type) && objfile_func
12333 + && (*objfile_func) (TYPE_OBJFILE (type), data))
12335 + if (objfile && objfile_func && (*objfile_func) (objfile, data))
12341 +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
12342 + referenced by EXP. The functions are never called with NULL TYPE or NULL
12343 + OBJFILE. Functions get passed an arbitrary caller supplied DATA pointer.
12344 + If any of the functions returns non-zero value then (any other) non-zero
12345 + value is immediately returned to the caller. Otherwise zero is returned
12346 + after iterating through whole EXP. */
12349 +exp_iterate (struct expression *exp,
12350 + int (*type_func) (struct type *type, void *data),
12351 + int (*objfile_func) (struct objfile *objfile, void *data),
12355 + const union exp_element *const elts = exp->elts;
12357 + for (endpos = exp->nelts; endpos > 0; )
12359 + int pos, args, oplen = 0;
12361 + exp->language_defn->la_exp_desc->operator_length (exp, endpos,
12363 + gdb_assert (oplen > 0);
12365 + pos = endpos - oplen;
12366 + if (exp->language_defn->la_exp_desc->operator_check (exp, pos, type_func,
12367 + objfile_func, data))
12376 +/* Helper for exp_uses_objfile. */
12379 +exp_uses_objfile_iter (struct objfile *exp_objfile, void *objfile_voidp)
12381 + struct objfile *objfile = objfile_voidp;
12383 + return exp_objfile == objfile;
12386 +/* Return 1 if EXP uses OBJFILE (and will become dangling when OBJFILE
12387 + is unloaded), otherwise return 0. */
12390 +exp_uses_objfile (struct expression *exp, struct objfile *objfile)
12392 + return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
12395 +/* Helper for exp_types_mark_used. */
12398 +exp_types_mark_used_iter (struct type *type, void *unused)
12400 + type_mark_used (type);
12402 + /* Continue the traversal. */
12406 +/* Call type_mark_used for any TYPE contained in EXP. */
12409 +exp_types_mark_used (struct expression *exp)
12411 + exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
12415 _initialize_parse (void)
12417 diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
12418 index cbda9c3..a07e6f2 100644
12419 --- a/gdb/parser-defs.h
12420 +++ b/gdb/parser-defs.h
12421 @@ -189,6 +189,13 @@ extern void operator_length (struct expression *, int, int *, int *);
12423 extern void operator_length_standard (struct expression *, int, int *, int *);
12425 +extern int operator_check_standard (struct expression *exp, int pos,
12426 + int (*type_func) (struct type *type,
12428 + int (*objfile_func)
12429 + (struct objfile *objfile, void *data),
12432 extern char *op_name_standard (enum exp_opcode);
12434 extern struct type *follow_types (struct type *);
12435 @@ -267,6 +274,20 @@ struct exp_descriptor
12436 the number of subexpressions it takes. */
12437 void (*operator_length) (struct expression*, int, int*, int *);
12439 + /* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
12440 + referenced by the single operator of EXP at position POS. Operator
12441 + parameters are located at positive (POS + number) offsets in EXP.
12442 + The functions should never be called with NULL TYPE or NULL OBJFILE.
12443 + Functions should get passed an arbitrary caller supplied DATA pointer.
12444 + If any of the functions returns non-zero value then (any other) non-zero
12445 + value should be immediately returned to the caller. Otherwise zero
12446 + should be returned. */
12447 + int (*operator_check) (struct expression *exp, int pos,
12448 + int (*type_func) (struct type *type, void *data),
12449 + int (*objfile_func) (struct objfile *objfile,
12453 /* Name of this operator for dumping purposes. */
12454 char *(*op_name) (enum exp_opcode);
12456 @@ -299,4 +320,8 @@ extern void print_subexp_standard (struct expression *, int *,
12458 extern void parser_fprintf (FILE *, const char *, ...) ATTR_FORMAT (printf, 2 ,3);
12460 +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
12462 +extern void exp_types_mark_used (struct expression *exp);
12464 #endif /* PARSER_DEFS_H */
12465 diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
12466 index 47b74ad..22fb2fc 100644
12467 --- a/gdb/ppc-linux-nat.c
12468 +++ b/gdb/ppc-linux-nat.c
12469 @@ -1391,6 +1391,24 @@ ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw)
12473 +/* See target_detach_watchpoints. Do not use wrapper
12474 + ppc_linux_remove_watchpoint as it would modify the register cache
12475 + (saved_dabr_value). */
12478 +ppc_linux_detach_watchpoints (void)
12482 + tid = TIDGET (inferior_ptid);
12484 + tid = PIDGET (inferior_ptid);
12486 + if (ptrace (PTRACE_SET_DEBUGREG, tid, NULL, NULL) < 0)
12492 ppc_linux_new_thread (ptid_t ptid)
12494 @@ -1648,6 +1666,7 @@ _initialize_ppc_linux_nat (void)
12495 t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
12496 t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
12497 t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
12498 + t->to_detach_watchpoints = ppc_linux_detach_watchpoints;
12499 t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
12500 t->to_stopped_data_address = ppc_linux_stopped_data_address;
12501 t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
12502 diff --git a/gdb/printcmd.c b/gdb/printcmd.c
12503 index 5d8b936..fb0a455 100644
12504 --- a/gdb/printcmd.c
12505 +++ b/gdb/printcmd.c
12507 #include "exceptions.h"
12508 #include "observer.h"
12509 #include "solist.h"
12510 -#include "solib.h"
12511 #include "parser-defs.h"
12512 #include "charset.h"
12514 @@ -900,6 +899,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
12516 val = access_value_history (0);
12518 + /* Do not try to OBJECT_ADDRESS_SET here anything. We are interested in the
12519 + source variable base addresses as found by READ_VAR_VALUE. The value here
12520 + can be already a calculated expression address inappropriate for
12521 + DW_OP_push_object_address. */
12523 if (voidprint || (val && value_type (val) &&
12524 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
12526 @@ -1396,6 +1400,22 @@ x_command (char *exp, int from_tty)
12527 set_internalvar (lookup_internalvar ("__"), last_examine_value);
12531 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
12534 +print_types_mark_used (void)
12536 + struct display *d;
12538 + if (last_examine_value)
12539 + type_mark_used (value_type (last_examine_value));
12541 + for (d = display_chain; d; d = d->next)
12543 + exp_types_mark_used (d->exp);
12548 /* Add an expression to the auto-display chain.
12549 @@ -1798,50 +1818,6 @@ disable_display_command (char *args, int from_tty)
12553 -/* Return 1 if D uses SOLIB (and will become dangling when SOLIB
12554 - is unloaded), otherwise return 0. */
12557 -display_uses_solib_p (const struct display *d,
12558 - const struct so_list *solib)
12561 - struct expression *const exp = d->exp;
12562 - const union exp_element *const elts = exp->elts;
12564 - if (d->block != NULL
12565 - && solib_contains_address_p (solib, d->block->startaddr))
12568 - for (endpos = exp->nelts; endpos > 0; )
12570 - int i, args, oplen = 0;
12572 - exp->language_defn->la_exp_desc->operator_length (exp, endpos,
12574 - gdb_assert (oplen > 0);
12576 - i = endpos - oplen;
12577 - if (elts[i].opcode == OP_VAR_VALUE)
12579 - const struct block *const block = elts[i + 1].block;
12580 - const struct symbol *const symbol = elts[i + 2].symbol;
12581 - const struct obj_section *const section =
12582 - SYMBOL_OBJ_SECTION (symbol);
12584 - if (block != NULL
12585 - && solib_contains_address_p (solib, block->startaddr))
12588 - if (section && section->objfile == solib->objfile)
12597 /* display_chain items point to blocks and expressions. Some expressions in
12598 turn may point to symbols.
12599 Both symbols and blocks are obstack_alloc'd on objfile_stack, and are
12600 @@ -1853,18 +1829,20 @@ display_uses_solib_p (const struct display *d,
12602 clear_dangling_display_expressions (struct so_list *solib)
12604 + struct objfile *objfile = solib->objfile;
12606 - struct objfile *objfile = NULL;
12608 - for (d = display_chain; d; d = d->next)
12610 - if (d->exp && display_uses_solib_p (d, solib))
12617 + if (objfile == NULL)
12620 + for (d = display_chain; d != NULL; d = d->next)
12621 + if (block_objfile (d->block) == objfile
12622 + || (d->exp && exp_uses_objfile (d->exp, objfile)))
12631 @@ -2749,4 +2727,6 @@ Show printing of source filename and line number with <symbol>."), NULL,
12633 show_print_symbol_filename,
12634 &setprintlist, &showprintlist);
12636 + observer_attach_mark_used (print_types_mark_used);
12638 diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
12639 new file mode 100644
12640 index 0000000..5654546
12642 +++ b/gdb/python/lib/gdb/FrameIterator.py
12644 +# Iterator over frames.
12646 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12648 +# This program is free software; you can redistribute it and/or modify
12649 +# it under the terms of the GNU General Public License as published by
12650 +# the Free Software Foundation; either version 3 of the License, or
12651 +# (at your option) any later version.
12653 +# This program is distributed in the hope that it will be useful,
12654 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12655 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12656 +# GNU General Public License for more details.
12658 +# You should have received a copy of the GNU General Public License
12659 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12661 +class FrameIterator:
12662 + """An iterator that iterates over frames."""
12664 + def __init__ (self, frame):
12665 + "Initialize a FrameIterator. FRAME is the starting frame."
12666 + self.frame = frame
12668 + def __iter__ (self):
12672 + result = self.frame
12673 + if result is None:
12674 + raise StopIteration
12675 + self.frame = result.older ()
12677 diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
12678 new file mode 100644
12679 index 0000000..b790a54
12681 +++ b/gdb/python/lib/gdb/FrameWrapper.py
12683 +# Wrapper API for frames.
12685 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12687 +# This program is free software; you can redistribute it and/or modify
12688 +# it under the terms of the GNU General Public License as published by
12689 +# the Free Software Foundation; either version 3 of the License, or
12690 +# (at your option) any later version.
12692 +# This program is distributed in the hope that it will be useful,
12693 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12694 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12695 +# GNU General Public License for more details.
12697 +# You should have received a copy of the GNU General Public License
12698 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12702 +# FIXME: arguably all this should be on Frame somehow.
12703 +class FrameWrapper:
12704 + def __init__ (self, frame):
12705 + self.frame = frame;
12707 + def write_symbol (self, stream, sym, block):
12708 + if len (sym.linkage_name):
12709 + nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
12710 + if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
12713 + stream.write (sym.print_name + "=")
12715 + val = self.read_var (sym)
12718 + # FIXME: would be nice to have a more precise exception here.
12719 + except RuntimeError, text:
12722 + stream.write ("???")
12724 + stream.write (str (val))
12726 + def print_frame_locals (self, stream, func):
12731 + block = func.value
12733 + for sym in block:
12734 + if sym.is_argument:
12737 + self.write_symbol (stream, sym, block)
12738 + stream.write ('\n')
12740 + def print_frame_args (self, stream, func):
12745 + block = func.value
12747 + for sym in block:
12748 + if not sym.is_argument:
12752 + stream.write (", ")
12754 + self.write_symbol (stream, sym, block)
12757 + # FIXME: this should probably just be a method on gdb.Frame.
12758 + # But then we need stream wrappers.
12759 + def describe (self, stream, full):
12760 + if self.type () == gdb.DUMMY_FRAME:
12761 + stream.write (" <function called from gdb>\n")
12762 + elif self.type () == gdb.SIGTRAMP_FRAME:
12763 + stream.write (" <signal handler called>\n")
12765 + sal = self.find_sal ()
12767 + name = self.name ()
12770 + if pc != sal.pc or not sal.symtab:
12771 + stream.write (" 0x%08x in" % pc)
12772 + stream.write (" " + name + " (")
12774 + func = self.function ()
12775 + self.print_frame_args (stream, func)
12777 + stream.write (")")
12779 + if sal.symtab and sal.symtab.filename:
12780 + stream.write (" at " + sal.symtab.filename)
12781 + stream.write (":" + str (sal.line))
12783 + if not self.name () or (not sal.symtab or not sal.symtab.filename):
12784 + lib = gdb.solib_address (pc)
12786 + stream.write (" from " + lib)
12788 + stream.write ("\n")
12791 + self.print_frame_locals (stream, func)
12793 + def __getattr__ (self, name):
12794 + return getattr (self.frame, name)
12795 diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
12796 new file mode 100644
12797 index 0000000..b375c68
12799 +++ b/gdb/python/lib/gdb/__init__.py
12803 +# Copyright (C) 2008 Free Software Foundation, Inc.
12805 +# This program is free software; you can redistribute it and/or modify
12806 +# it under the terms of the GNU General Public License as published by
12807 +# the Free Software Foundation; either version 3 of the License, or
12808 +# (at your option) any later version.
12810 +# This program is distributed in the hope that it will be useful,
12811 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12812 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12813 +# GNU General Public License for more details.
12815 +# You should have received a copy of the GNU General Public License
12816 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12818 +# Load the require command by default.
12819 +import gdb.command.require
12820 diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
12821 new file mode 100644
12822 index 0000000..2baab5f
12824 +++ b/gdb/python/lib/gdb/backtrace.py
12826 +# Filtering backtrace.
12828 +# Copyright (C) 2008 Free Software Foundation, Inc.
12830 +# This program is free software; you can redistribute it and/or modify
12831 +# it under the terms of the GNU General Public License as published by
12832 +# the Free Software Foundation; either version 3 of the License, or
12833 +# (at your option) any later version.
12835 +# This program is distributed in the hope that it will be useful,
12836 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12837 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12838 +# GNU General Public License for more details.
12840 +# You should have received a copy of the GNU General Public License
12841 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12846 +# Our only exports.
12847 +__all__ = ['push_frame_filter', 'create_frame_filter']
12849 +frame_filter = None
12851 +def push_frame_filter (constructor):
12852 + """Register a new backtrace filter class with the 'backtrace' command.
12853 +The filter will be passed an iterator as an argument. The iterator
12854 +will return gdb.Frame-like objects. The filter should in turn act as
12855 +an iterator returning such objects."""
12856 + global frame_filter
12857 + if frame_filter == None:
12858 + frame_filter = constructor
12860 + frame_filter = lambda iterator: constructor (frame_filter (iterator))
12862 +def create_frame_filter (iter):
12863 + global frame_filter
12864 + if frame_filter is None:
12866 + return frame_filter (iter)
12868 diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
12869 new file mode 100644
12870 index 0000000..8b13789
12872 +++ b/gdb/python/lib/gdb/command/__init__.py
12875 diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
12876 new file mode 100644
12877 index 0000000..96b6618
12879 +++ b/gdb/python/lib/gdb/command/alias.py
12883 +# Copyright (C) 2008 Free Software Foundation, Inc.
12885 +# This program is free software; you can redistribute it and/or modify
12886 +# it under the terms of the GNU General Public License as published by
12887 +# the Free Software Foundation; either version 3 of the License, or
12888 +# (at your option) any later version.
12890 +# This program is distributed in the hope that it will be useful,
12891 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12892 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12893 +# GNU General Public License for more details.
12895 +# You should have received a copy of the GNU General Public License
12896 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12900 +class AliasImplementation (gdb.Command):
12901 + def __init__ (self, name, real, doc):
12902 + # Have to set __doc__ before the super init call.
12903 + # It would be nice if gdb's help looked up __doc__ dynamically.
12904 + self.__doc__ = doc
12905 + # Note: no good way to complete :(
12906 + super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE)
12909 + def invoke(self, arg, from_tty):
12910 + gdb.execute (self.real + ' ' + arg, from_tty)
12912 +class AliasCommand (gdb.Command):
12913 + """Alias one command to another.
12914 +In the simplest form, the first word is the name of the alias, and
12915 +the remaining words are the the expansion.
12916 +An '=' by itself can be used to define a multi-word alias; words
12917 +before the '=' are the name of the new command."""
12919 + def __init__ (self):
12920 + # Completion is not quite right here.
12921 + super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE,
12922 + gdb.COMPLETE_COMMAND)
12924 + def invoke (self, arg, from_tty):
12925 + self.dont_repeat ()
12926 + # Without some form of quoting we can't alias a multi-word
12927 + # command to another command.
12928 + args = arg.split()
12930 + start = args.index ('=')
12932 + except ValueError:
12935 + target = " ".join(args[end:])
12936 + AliasImplementation (" ".join (args[0:start]), target,
12937 + "This command is an alias for '%s'." % target)
12940 diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
12941 new file mode 100644
12942 index 0000000..ec9a527
12944 +++ b/gdb/python/lib/gdb/command/backtrace.py
12946 +# New backtrace command.
12948 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
12950 +# This program is free software; you can redistribute it and/or modify
12951 +# it under the terms of the GNU General Public License as published by
12952 +# the Free Software Foundation; either version 3 of the License, or
12953 +# (at your option) any later version.
12955 +# This program is distributed in the hope that it will be useful,
12956 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12957 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12958 +# GNU General Public License for more details.
12960 +# You should have received a copy of the GNU General Public License
12961 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12964 +import gdb.backtrace
12966 +from gdb.FrameIterator import FrameIterator
12967 +from gdb.FrameWrapper import FrameWrapper
12970 +class ReverseBacktraceParameter (gdb.Parameter):
12971 + """The new-backtrace command can show backtraces in 'reverse' order.
12972 +This means that the innermost frame will be printed last.
12973 +Note that reverse backtraces are more expensive to compute."""
12975 + set_doc = "Enable or disable reverse backtraces."
12976 + show_doc = "Show whether backtraces will be printed in reverse order."
12978 + def __init__(self):
12979 + gdb.Parameter.__init__ (self, "reverse-backtrace",
12980 + gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
12981 + # Default to compatibility with gdb.
12982 + self.value = False
12984 +class FilteringBacktrace (gdb.Command):
12985 + """Print backtrace of all stack frames, or innermost COUNT frames.
12986 +With a negative argument, print outermost -COUNT frames.
12987 +Use of the 'full' qualifier also prints the values of the local variables.
12988 +Use of the 'raw' qualifier avoids any filtering by loadable modules.
12991 + def __init__ (self):
12992 + # FIXME: this is not working quite well enough to replace
12993 + # "backtrace" yet.
12994 + gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
12995 + self.reverse = ReverseBacktraceParameter()
12997 + def reverse_iter (self, iter):
12999 + for item in iter:
13000 + result.append (item)
13004 + def final_n (self, iter, x):
13006 + for item in iter:
13007 + result.append (item)
13008 + return result[x:]
13010 + def invoke (self, arg, from_tty):
13016 + for word in arg.split (" "):
13019 + elif word == 'raw':
13021 + elif word == 'full':
13024 + count = int (word)
13026 + # FIXME: provide option to start at selected frame
13027 + # However, should still number as if starting from newest
13028 + newest_frame = gdb.selected_thread ().newest_frame ()
13029 + iter = itertools.imap (FrameWrapper,
13030 + FrameIterator (newest_frame))
13032 + iter = gdb.backtrace.create_frame_filter (iter)
13034 + # Now wrap in an iterator that numbers the frames.
13035 + iter = itertools.izip (itertools.count (0), iter)
13037 + # Reverse if the user wanted that.
13038 + if self.reverse.value:
13039 + iter = self.reverse_iter (iter)
13041 + # Extract sub-range user wants.
13043 + iter = self.final_n (iter, count)
13045 + iter = itertools.islice (iter, 0, count)
13047 + for pair in iter:
13048 + sys.stdout.write ("#%-2d" % pair[0])
13049 + pair[1].describe (sys.stdout, full)
13051 +FilteringBacktrace()
13052 diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
13053 new file mode 100644
13054 index 0000000..6fa48ff
13056 +++ b/gdb/python/lib/gdb/command/ignore_errors.py
13058 +# Ignore errors in user commands.
13060 +# Copyright (C) 2008 Free Software Foundation, Inc.
13062 +# This program is free software; you can redistribute it and/or modify
13063 +# it under the terms of the GNU General Public License as published by
13064 +# the Free Software Foundation; either version 3 of the License, or
13065 +# (at your option) any later version.
13067 +# This program is distributed in the hope that it will be useful,
13068 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13069 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13070 +# GNU General Public License for more details.
13072 +# You should have received a copy of the GNU General Public License
13073 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13077 +class IgnoreErrorsCommand (gdb.Command):
13078 + """Execute a single command, ignoring all errors.
13079 +Only one-line commands are supported.
13080 +This is primarily useful in scripts."""
13082 + def __init__ (self):
13083 + super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
13084 + gdb.COMMAND_OBSCURE,
13086 + gdb.COMPLETE_COMMAND)
13088 + def invoke (self, arg, from_tty):
13090 + gdb.execute (arg, from_tty)
13094 +IgnoreErrorsCommand ()
13095 diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
13096 new file mode 100644
13097 index 0000000..21a0bf0
13099 +++ b/gdb/python/lib/gdb/command/pahole.py
13101 +# pahole command for gdb
13103 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13105 +# This program is free software; you can redistribute it and/or modify
13106 +# it under the terms of the GNU General Public License as published by
13107 +# the Free Software Foundation; either version 3 of the License, or
13108 +# (at your option) any later version.
13110 +# This program is distributed in the hope that it will be useful,
13111 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13112 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13113 +# GNU General Public License for more details.
13115 +# You should have received a copy of the GNU General Public License
13116 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13120 +class Pahole (gdb.Command):
13121 + """Show the holes in a structure.
13122 +This command takes a single argument, a type name.
13123 +It prints the type and displays comments showing where holes are."""
13125 + def __init__ (self):
13126 + super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
13127 + gdb.COMPLETE_SYMBOL)
13129 + def pahole (self, type, level, name):
13135 + print '%sstruct %s {' % (' ' * (2 * level), tag)
13137 + for field in type.fields ():
13138 + # Skip static fields.
13139 + if not hasattr (field, ('bitpos')):
13142 + ftype = field.type.strip_typedefs()
13144 + if bitpos != field.bitpos:
13145 + hole = field.bitpos - bitpos
13146 + print ' /* XXX %d bit hole, try to pack */' % hole
13147 + bitpos = field.bitpos
13148 + if field.bitsize > 0:
13149 + fieldsize = field.bitsize
13151 + # TARGET_CHAR_BIT here...
13152 + fieldsize = 8 * ftype.sizeof
13154 + # TARGET_CHAR_BIT
13155 + print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
13156 + bitpos = bitpos + fieldsize
13158 + if ftype.code == gdb.TYPE_CODE_STRUCT:
13159 + self.pahole (ftype, level + 1, field.name)
13161 + print ' ' * (2 + 2 * level),
13162 + print '%s %s' % (str (ftype), field.name)
13164 + print ' ' * (14 + 2 * level),
13165 + print '} %s' % name
13167 + def invoke (self, arg, from_tty):
13168 + type = gdb.lookup_type (arg)
13169 + type = type.strip_typedefs ()
13170 + if type.code != gdb.TYPE_CODE_STRUCT:
13171 + raise TypeError, '%s is not a struct type' % arg
13173 + self.pahole (type, 0, '')
13176 diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
13177 new file mode 100644
13178 index 0000000..1fbc1e8
13180 +++ b/gdb/python/lib/gdb/command/require.py
13182 +# Demand-loading commands.
13184 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13186 +# This program is free software; you can redistribute it and/or modify
13187 +# it under the terms of the GNU General Public License as published by
13188 +# the Free Software Foundation; either version 3 of the License, or
13189 +# (at your option) any later version.
13191 +# This program is distributed in the hope that it will be useful,
13192 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13193 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13194 +# GNU General Public License for more details.
13196 +# You should have received a copy of the GNU General Public License
13197 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13202 +class RequireCommand (gdb.Command):
13203 + """Prefix command for requiring features."""
13205 + def __init__ (self):
13206 + super (RequireCommand, self).__init__ ("require",
13207 + gdb.COMMAND_SUPPORT,
13208 + gdb.COMPLETE_NONE,
13211 +class RequireSubcommand (gdb.Command):
13212 + """Demand-load a command by name."""
13214 + def __init__ (self, name):
13215 + self.__doc__ = "Demand-load a %s by name." % name
13216 + super (RequireSubcommand, self).__init__ ("require %s" % name,
13217 + gdb.COMMAND_SUPPORT)
13220 + def invoke (self, arg, from_tty):
13221 + for cmd in arg.split():
13222 + exec ('import gdb.' + self.name + '.' + cmd, globals ())
13224 + def complete (self, text, word):
13225 + dir = gdb.pythondir + '/gdb/' + self.name
13227 + for file in os.listdir(dir):
13228 + if not file.startswith (word) or not file.endswith ('.py'):
13230 + feature = file[0:-3]
13231 + if feature == 'require' or feature == '__init__':
13233 + result.append (feature)
13237 +RequireSubcommand("command")
13238 +RequireSubcommand("function")
13239 diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
13240 new file mode 100644
13241 index 0000000..6143187
13243 +++ b/gdb/python/lib/gdb/command/save_breakpoints.py
13245 +# Save breakpoints.
13247 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13249 +# This program is free software; you can redistribute it and/or modify
13250 +# it under the terms of the GNU General Public License as published by
13251 +# the Free Software Foundation; either version 3 of the License, or
13252 +# (at your option) any later version.
13254 +# This program is distributed in the hope that it will be useful,
13255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13257 +# GNU General Public License for more details.
13259 +# You should have received a copy of the GNU General Public License
13260 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13262 +from __future__ import with_statement
13265 +class SavePrefixCommand (gdb.Command):
13266 + "Prefix command for saving things."
13268 + def __init__ (self):
13269 + super (SavePrefixCommand, self).__init__ ("save",
13270 + gdb.COMMAND_SUPPORT,
13271 + gdb.COMPLETE_NONE, True)
13273 +class SaveBreakpointsCommand (gdb.Command):
13274 + """Save the current breakpoints to a file.
13275 +This command takes a single argument, a file name.
13276 +The breakpoints can be restored using the 'source' command."""
13278 + def __init__ (self):
13279 + super (SaveBreakpointsCommand, self).__init__ ("save breakpoints",
13280 + gdb.COMMAND_SUPPORT,
13281 + gdb.COMPLETE_FILENAME)
13283 + def invoke (self, arg, from_tty):
13284 + self.dont_repeat ()
13285 + bps = gdb.breakpoints ()
13287 + raise RuntimeError, 'No breakpoints to save'
13288 + with open (arg.strip (), 'w') as f:
13290 + print >> f, "break", bp.location,
13291 + if bp.thread is not None:
13292 + print >> f, " thread", bp.thread,
13293 + if bp.condition is not None:
13294 + print >> f, " if", bp.condition,
13296 + if not bp.enabled:
13297 + print >> f, "disable $bpnum"
13298 + # Note: we don't save the ignore count; there doesn't
13299 + # seem to be much point.
13300 + commands = bp.commands
13301 + if commands is not None:
13302 + print >> f, "commands"
13303 + # Note that COMMANDS has a trailing newline.
13304 + print >> f, commands,
13305 + print >> f, "end"
13308 +SavePrefixCommand ()
13309 +SaveBreakpointsCommand ()
13310 diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
13311 new file mode 100644
13312 index 0000000..faf54ed
13314 +++ b/gdb/python/lib/gdb/command/upto.py
13318 +# Copyright (C) 2009 Free Software Foundation, Inc.
13320 +# This program is free software; you can redistribute it and/or modify
13321 +# it under the terms of the GNU General Public License as published by
13322 +# the Free Software Foundation; either version 3 of the License, or
13323 +# (at your option) any later version.
13325 +# This program is distributed in the hope that it will be useful,
13326 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13327 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13328 +# GNU General Public License for more details.
13330 +# You should have received a copy of the GNU General Public License
13331 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13335 +from gdb.FrameIterator import FrameIterator
13336 +from gdb.FrameWrapper import FrameWrapper
13338 +class UptoPrefix (gdb.Command):
13339 + def __init__ (self):
13340 + super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
13343 +class UptoImplementation (gdb.Command):
13344 + def __init__ (self, subcommand):
13345 + super (UptoImplementation, self).__init__ ("upto " + subcommand,
13346 + gdb.COMMAND_STACK)
13348 + def search (self):
13349 + saved = gdb.selected_frame ()
13350 + iter = FrameIterator (saved)
13353 + for frame in iter:
13356 + if self.filter (frame):
13357 + wrapper = FrameWrapper (frame)
13358 + wrapper.describe (sys.stdout, False)
13365 + raise RuntimeError, 'Could not find a matching frame'
13367 + def invoke (self, arg, from_tty):
13368 + self.rx = re.compile (arg)
13371 +class UptoSymbolCommand (UptoImplementation):
13372 + """Select and print some calling stack frame, based on symbol.
13373 +The argument is a regular expression. This command moves up the
13374 +stack, stopping at the first frame whose symbol matches the regular
13377 + def __init__ (self):
13378 + super (UptoSymbolCommand, self).__init__ ("symbol")
13380 + def filter (self, frame):
13381 + name = frame.name ()
13382 + if name is not None:
13383 + if self.rx.search (name) is not None:
13387 +class UptoSourceCommand (UptoImplementation):
13388 + """Select and print some calling stack frame, based on source file.
13389 +The argument is a regular expression. This command moves up the
13390 +stack, stopping at the first frame whose source file name matches the
13391 +regular expression."""
13393 + def __init__ (self):
13394 + super (UptoSourceCommand, self).__init__ ("source")
13396 + def filter (self, frame):
13397 + name = frame.find_sal ().symtab.filename
13398 + if name is not None:
13399 + if self.rx.search (name) is not None:
13403 +class UptoObjectCommand (UptoImplementation):
13404 + """Select and print some calling stack frame, based on object file.
13405 +The argument is a regular expression. This command moves up the
13406 +stack, stopping at the first frame whose object file name matches the
13407 +regular expression."""
13409 + def __init__ (self):
13410 + super (UptoObjectCommand, self).__init__ ("object")
13412 + def filter (self, frame):
13413 + name = frame.find_sal ().symtab.objfile.filename
13414 + if name is not None:
13415 + if self.rx.search (name) is not None:
13419 +class UptoWhereCommand (UptoImplementation):
13420 + """Select and print some calling stack frame, based on expression.
13421 +The argument is an expression. This command moves up the stack,
13422 +parsing and evaluating the expression in each frame. This stops when
13423 +the expression evaluates to a non-zero (true) value."""
13425 + def __init__ (self):
13426 + super (UptoWhereCommand, self).__init__ ("where")
13428 + def filter (self, frame):
13430 + if gdb.parse_and_eval (self.expression):
13436 + def invoke (self, arg, from_tty):
13437 + self.expression = arg
13441 +UptoSymbolCommand ()
13442 +UptoSourceCommand ()
13443 +UptoObjectCommand ()
13444 +UptoWhereCommand ()
13445 diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
13446 new file mode 100644
13447 index 0000000..8b13789
13449 +++ b/gdb/python/lib/gdb/function/__init__.py
13452 diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
13453 new file mode 100644
13454 index 0000000..2b9c5c7
13456 +++ b/gdb/python/lib/gdb/function/caller_is.py
13458 +# Caller-is functions.
13460 +# Copyright (C) 2008 Free Software Foundation, Inc.
13462 +# This program is free software; you can redistribute it and/or modify
13463 +# it under the terms of the GNU General Public License as published by
13464 +# the Free Software Foundation; either version 3 of the License, or
13465 +# (at your option) any later version.
13467 +# This program is distributed in the hope that it will be useful,
13468 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13469 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13470 +# GNU General Public License for more details.
13472 +# You should have received a copy of the GNU General Public License
13473 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13478 +class CallerIs (gdb.Function):
13479 + """Return True if the calling function's name is equal to a string.
13480 +This function takes one or two arguments.
13481 +The first argument is the name of a function; if the calling function's
13482 +name is equal to this argument, this function returns True.
13483 +The optional second argument tells this function how many stack frames
13484 +to traverse to find the calling function. The default is 1."""
13486 + def __init__ (self):
13487 + super (CallerIs, self).__init__ ("caller_is")
13489 + def invoke (self, name, nframes = 1):
13490 + frame = gdb.selected_frame ()
13491 + while nframes > 0:
13492 + frame = frame.older ()
13493 + nframes = nframes - 1
13494 + return frame.name () == name.string ()
13496 +class CallerMatches (gdb.Function):
13497 + """Return True if the calling function's name matches a string.
13498 +This function takes one or two arguments.
13499 +The first argument is a regular expression; if the calling function's
13500 +name is matched by this argument, this function returns True.
13501 +The optional second argument tells this function how many stack frames
13502 +to traverse to find the calling function. The default is 1."""
13504 + def __init__ (self):
13505 + super (CallerMatches, self).__init__ ("caller_matches")
13507 + def invoke (self, name, nframes = 1):
13508 + frame = gdb.selected_frame ()
13509 + while nframes > 0:
13510 + frame = frame.older ()
13511 + nframes = nframes - 1
13512 + return re.match (name.string (), frame.name ()) is not None
13516 diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
13517 new file mode 100644
13518 index 0000000..debb3bb
13520 +++ b/gdb/python/lib/gdb/function/in_scope.py
13522 +# In-scope function.
13524 +# Copyright (C) 2008 Free Software Foundation, Inc.
13526 +# This program is free software; you can redistribute it and/or modify
13527 +# it under the terms of the GNU General Public License as published by
13528 +# the Free Software Foundation; either version 3 of the License, or
13529 +# (at your option) any later version.
13531 +# This program is distributed in the hope that it will be useful,
13532 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13533 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13534 +# GNU General Public License for more details.
13536 +# You should have received a copy of the GNU General Public License
13537 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13541 +class InScope (gdb.Function):
13542 + """Return True if all the given variables or macros are in scope.
13543 +Takes one argument for each variable name to be checked."""
13545 + def __init__ (self):
13546 + super (InScope, self).__init__ ("in_scope")
13548 + def invoke (self, *vars):
13549 + if len (vars) == 0:
13550 + raise TypeError, "in_scope takes at least one argument"
13552 + # gdb.Value isn't hashable so it can't be put in a map.
13553 + # Convert to string first.
13554 + wanted = set (map (lambda x: x.string (), vars))
13556 + block = gdb.selected_frame ().block ()
13558 + for sym in block:
13559 + if (sym.is_argument or sym.is_constant
13560 + or sym.is_function or sym.is_variable):
13561 + if sym.name in wanted:
13562 + found.add (sym.name)
13564 + block = block.superblock
13566 + return wanted == found
13569 diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
13570 new file mode 100644
13571 index 0000000..8019e9d
13573 +++ b/gdb/python/py-block.c
13575 +/* Python interface to blocks.
13577 + Copyright (C) 2008 Free Software Foundation, Inc.
13579 + This file is part of GDB.
13581 + This program is free software; you can redistribute it and/or modify
13582 + it under the terms of the GNU General Public License as published by
13583 + the Free Software Foundation; either version 3 of the License, or
13584 + (at your option) any later version.
13586 + This program is distributed in the hope that it will be useful,
13587 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13588 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13589 + GNU General Public License for more details.
13591 + You should have received a copy of the GNU General Public License
13592 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13595 +#include "block.h"
13596 +#include "dictionary.h"
13597 +#include "symtab.h"
13598 +#include "python-internal.h"
13602 + struct block *block;
13607 + struct dictionary *dict;
13608 + struct dict_iterator iter;
13609 + int initialized_p;
13610 +} block_syms_iterator_object;
13612 +static PyTypeObject block_syms_iterator_object_type;
13615 +blpy_iter (PyObject *self)
13617 + block_syms_iterator_object *block_iter_obj;
13619 + block_iter_obj = PyObject_New (block_syms_iterator_object,
13620 + &block_syms_iterator_object_type);
13621 + if (block_iter_obj == NULL)
13623 + PyErr_SetString (PyExc_MemoryError,
13624 + "Could not allocate iterator object.");
13628 + block_iter_obj->dict = BLOCK_DICT (((block_object *) self)->block);
13629 + block_iter_obj->initialized_p = 0;
13631 + return (PyObject *) block_iter_obj;
13635 +blpy_get_start (PyObject *self, void *closure)
13637 + block_object *self_block = (block_object *) self;
13639 + return PyLong_FromUnsignedLongLong (BLOCK_START (self_block->block));
13643 +blpy_get_end (PyObject *self, void *closure)
13645 + block_object *self_block = (block_object *) self;
13647 + return PyLong_FromUnsignedLongLong (BLOCK_END (self_block->block));
13651 +blpy_get_function (PyObject *self, void *closure)
13653 + block_object *self_block = (block_object *) self;
13654 + struct symbol *sym;
13656 + sym = BLOCK_FUNCTION (self_block->block);
13658 + return symbol_to_symbol_object (sym);
13664 +blpy_get_superblock (PyObject *self, void *closure)
13666 + block_object *self_block = (block_object *) self;
13667 + struct block *block;
13669 + block = BLOCK_SUPERBLOCK (self_block->block);
13671 + return block_to_block_object (block);
13677 +block_to_block_object (struct block *block)
13679 + block_object *block_obj;
13681 + block_obj = PyObject_New (block_object, &block_object_type);
13682 + if (block_obj == NULL)
13684 + PyErr_SetString (PyExc_MemoryError, "Could not allocate block object.");
13688 + block_obj->block = block;
13690 + return (PyObject *) block_obj;
13694 +block_object_to_block (PyObject *obj)
13696 + if (! PyObject_TypeCheck (obj, &block_object_type))
13698 + return ((block_object *) obj)->block;
13702 +blpy_block_syms_iter (PyObject *self)
13708 +blpy_block_syms_iternext (PyObject *self)
13710 + block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self;
13711 + struct symbol *sym;
13713 + if (!iter_obj->initialized_p)
13715 + sym = dict_iterator_first (iter_obj->dict, &(iter_obj->iter));
13716 + iter_obj->initialized_p = 1;
13719 + sym = dict_iterator_next (&(iter_obj->iter));
13721 + return (sym == NULL)? NULL : symbol_to_symbol_object (sym);
13724 +/* Return the innermost lexical block containing the specified pc value,
13725 + or 0 if there is none. */
13728 +gdbpy_block_for_pc (PyObject *self, PyObject *args)
13730 + unsigned PY_LONG_LONG pc;
13731 + struct block *block;
13732 + PyObject *sym_obj;
13734 + if (!PyArg_ParseTuple (args, "K", &pc))
13737 + block = block_for_pc (pc);
13739 + return block_to_block_object (block);
13745 +gdbpy_initialize_blocks (void)
13747 + block_object_type.tp_new = PyType_GenericNew;
13748 + if (PyType_Ready (&block_object_type) < 0)
13751 + block_syms_iterator_object_type.tp_new = PyType_GenericNew;
13752 + if (PyType_Ready (&block_syms_iterator_object_type) < 0)
13755 + Py_INCREF (&block_object_type);
13756 + PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
13758 + Py_INCREF (&block_syms_iterator_object_type);
13759 + PyModule_AddObject (gdb_module, "BlockIterator",
13760 + (PyObject *) &block_syms_iterator_object_type);
13765 +static PyGetSetDef block_object_getset[] = {
13766 + { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
13767 + { "end", blpy_get_end, NULL, "End address of the block.", NULL },
13768 + { "function", blpy_get_function, NULL,
13769 + "Symbol that names the block, or None.", NULL },
13770 + { "superblock", blpy_get_superblock, NULL,
13771 + "Block containing the block, or None.", NULL },
13772 + { NULL } /* Sentinel */
13775 +PyTypeObject block_object_type = {
13776 + PyObject_HEAD_INIT (NULL)
13778 + "gdb.Block", /*tp_name*/
13779 + sizeof (block_object), /*tp_basicsize*/
13780 + 0, /*tp_itemsize*/
13781 + 0, /*tp_dealloc*/
13783 + 0, /*tp_getattr*/
13784 + 0, /*tp_setattr*/
13785 + 0, /*tp_compare*/
13787 + 0, /*tp_as_number*/
13788 + 0, /*tp_as_sequence*/
13789 + 0, /*tp_as_mapping*/
13793 + 0, /*tp_getattro*/
13794 + 0, /*tp_setattro*/
13795 + 0, /*tp_as_buffer*/
13796 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
13797 + "GDB block object", /* tp_doc */
13798 + 0, /* tp_traverse */
13799 + 0, /* tp_clear */
13800 + 0, /* tp_richcompare */
13801 + 0, /* tp_weaklistoffset */
13802 + blpy_iter, /* tp_iter */
13803 + 0, /* tp_iternext */
13804 + 0, /* tp_methods */
13805 + 0, /* tp_members */
13806 + block_object_getset /* tp_getset */
13809 +static PyTypeObject block_syms_iterator_object_type = {
13810 + PyObject_HEAD_INIT (NULL)
13812 + "gdb.BlockIterator", /*tp_name*/
13813 + sizeof (block_syms_iterator_object), /*tp_basicsize*/
13814 + 0, /*tp_itemsize*/
13815 + 0, /*tp_dealloc*/
13817 + 0, /*tp_getattr*/
13818 + 0, /*tp_setattr*/
13819 + 0, /*tp_compare*/
13821 + 0, /*tp_as_number*/
13822 + 0, /*tp_as_sequence*/
13823 + 0, /*tp_as_mapping*/
13827 + 0, /*tp_getattro*/
13828 + 0, /*tp_setattro*/
13829 + 0, /*tp_as_buffer*/
13830 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
13831 + "GDB block syms iterator object", /* tp_doc */
13832 + 0, /* tp_traverse */
13833 + 0, /* tp_clear */
13834 + 0, /* tp_richcompare */
13835 + 0, /* tp_weaklistoffset */
13836 + blpy_block_syms_iter, /* tp_iter */
13837 + blpy_block_syms_iternext, /* tp_iternext */
13838 + 0 /* tp_methods */
13840 diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
13841 new file mode 100644
13842 index 0000000..afa9526
13844 +++ b/gdb/python/py-breakpoint.c
13846 +/* Python interface to breakpoints
13848 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
13850 + This file is part of GDB.
13852 + This program is free software; you can redistribute it and/or modify
13853 + it under the terms of the GNU General Public License as published by
13854 + the Free Software Foundation; either version 3 of the License, or
13855 + (at your option) any later version.
13857 + This program is distributed in the hope that it will be useful,
13858 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13859 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13860 + GNU General Public License for more details.
13862 + You should have received a copy of the GNU General Public License
13863 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13866 +#include "value.h"
13867 +#include "exceptions.h"
13868 +#include "python-internal.h"
13869 +#include "charset.h"
13870 +#include "breakpoint.h"
13871 +#include "gdbcmd.h"
13872 +#include "gdbthread.h"
13873 +#include "observer.h"
13876 +/* From breakpoint.c. */
13877 +extern struct breakpoint *breakpoint_chain;
13880 +typedef struct breakpoint_object breakpoint_object;
13882 +static PyTypeObject breakpoint_object_type;
13884 +/* A dynamically allocated vector of breakpoint objects. Each
13885 + breakpoint has a number. A breakpoint is valid if its slot in this
13886 + vector is non-null. When a breakpoint is deleted, we drop our
13887 + reference to it and zero its slot; this is how we let the Python
13888 + object have a lifetime which is independent from that of the gdb
13890 +static breakpoint_object **bppy_breakpoints;
13892 +/* Number of slots in bppy_breakpoints. */
13893 +static int bppy_slots;
13895 +/* Number of live breakpoints. */
13896 +static int bppy_live;
13898 +/* Variables used to pass information between the Breakpoint
13899 + constructor and the breakpoint-created hook function. */
13900 +static breakpoint_object *bppy_pending_object;
13902 +struct breakpoint_object
13906 + /* The breakpoint number according to gdb. */
13909 + /* The gdb breakpoint object, or NULL if the breakpoint has been
13911 + struct breakpoint *bp;
13914 +/* Evaluate to true if the breakpoint NUM is valid, false otherwise. */
13915 +#define BPPY_VALID_P(Num) \
13917 + && (Num) < bppy_slots \
13918 + && bppy_breakpoints[Num] != NULL)
13920 +/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
13921 + exception if it is invalid. */
13922 +#define BPPY_REQUIRE_VALID(Breakpoint) \
13924 + if (! BPPY_VALID_P ((Breakpoint)->number)) \
13925 + return PyErr_Format (PyExc_RuntimeError, "breakpoint %d is invalid", \
13926 + (Breakpoint)->number); \
13929 +/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
13930 + exception if it is invalid. This macro is for use in setter functions. */
13931 +#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
13933 + if (! BPPY_VALID_P ((Breakpoint)->number)) \
13935 + PyErr_Format (PyExc_RuntimeError, "breakpoint %d is invalid", \
13936 + (Breakpoint)->number); \
13941 +/* Python function which checks the validity of a breakpoint object. */
13943 +bppy_is_valid (PyObject *self, PyObject *args)
13945 + if (((breakpoint_object *) self)->bp)
13950 +/* Python function to test whether or not the breakpoint is enabled. */
13952 +bppy_get_enabled (PyObject *self, void *closure)
13954 + if (! ((breakpoint_object *) self)->bp)
13956 + /* Not clear what we really want here. */
13957 + if (((breakpoint_object *) self)->bp->enable_state == bp_enabled)
13962 +/* Python function to test whether or not the breakpoint is silent. */
13964 +bppy_get_silent (PyObject *self, void *closure)
13966 + BPPY_REQUIRE_VALID ((breakpoint_object *) self);
13967 + if (((breakpoint_object *) self)->bp->silent)
13972 +/* Python function to set the enabled state of a breakpoint. */
13974 +bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
13976 + breakpoint_object *self_bp = (breakpoint_object *) self;
13979 + BPPY_SET_REQUIRE_VALID (self_bp);
13981 + if (newvalue == NULL)
13983 + PyErr_SetString (PyExc_TypeError, "cannot delete `enabled' attribute");
13986 + else if (! PyBool_Check (newvalue))
13988 + PyErr_SetString (PyExc_TypeError,
13989 + "the value of `enabled' must be a boolean");
13993 + cmp = PyObject_IsTrue (newvalue);
13996 + else if (cmp == 1)
13997 + enable_breakpoint (self_bp->bp);
13999 + disable_breakpoint (self_bp->bp);
14003 +/* Python function to set the 'silent' state of a breakpoint. */
14005 +bppy_set_silent (PyObject *self, PyObject *newvalue, void *closure)
14007 + breakpoint_object *self_bp = (breakpoint_object *) self;
14010 + BPPY_SET_REQUIRE_VALID (self_bp);
14012 + if (newvalue == NULL)
14014 + PyErr_SetString (PyExc_TypeError, "cannot delete `silent' attribute");
14017 + else if (! PyBool_Check (newvalue))
14019 + PyErr_SetString (PyExc_TypeError,
14020 + "the value of `silent' must be a boolean");
14024 + cmp = PyObject_IsTrue (newvalue);
14028 + self_bp->bp->silent = cmp;
14033 +/* Python function to set the thread of a breakpoint. */
14035 +bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
14037 + breakpoint_object *self_bp = (breakpoint_object *) self;
14040 + BPPY_SET_REQUIRE_VALID (self_bp);
14042 + if (newvalue == NULL)
14044 + PyErr_SetString (PyExc_TypeError, "cannot delete `thread' attribute");
14047 + else if (PyInt_Check (newvalue))
14049 + id = (int) PyInt_AsLong (newvalue);
14050 + if (! valid_thread_id (id))
14052 + PyErr_SetString (PyExc_RuntimeError, "invalid thread id");
14056 + else if (newvalue == Py_None)
14060 + PyErr_SetString (PyExc_TypeError,
14061 + "the value of `thread' must be an integer or None");
14065 + self_bp->bp->thread = id;
14070 +/* Python function to set the ignore count of a breakpoint. */
14072 +bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
14074 + breakpoint_object *self_bp = (breakpoint_object *) self;
14077 + BPPY_SET_REQUIRE_VALID (self_bp);
14079 + if (newvalue == NULL)
14081 + PyErr_SetString (PyExc_TypeError,
14082 + "cannot delete `ignore_count' attribute");
14085 + else if (! PyInt_Check (newvalue))
14087 + PyErr_SetString (PyExc_TypeError,
14088 + "the value of `ignore_count' must be an integer");
14092 + value = PyInt_AsLong (newvalue);
14095 + set_ignore_count (self_bp->number, (int) value, 0);
14100 +/* Python function to set the hit count of a breakpoint. */
14102 +bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
14104 + breakpoint_object *self_bp = (breakpoint_object *) self;
14106 + BPPY_SET_REQUIRE_VALID (self_bp);
14108 + if (newvalue == NULL)
14110 + PyErr_SetString (PyExc_TypeError, "cannot delete `hit_count' attribute");
14113 + else if (! PyInt_Check (newvalue) || PyInt_AsLong (newvalue) != 0)
14115 + PyErr_SetString (PyExc_AttributeError,
14116 + "the value of `hit_count' must be zero");
14120 + self_bp->bp->hit_count = 0;
14125 +/* Python function to get the location of a breakpoint. */
14127 +bppy_get_location (PyObject *self, void *closure)
14131 + BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14132 + str = ((breakpoint_object *) self)->bp->addr_string;
14133 + /* FIXME: watchpoints? tracepoints? */
14136 + return PyString_Decode (str, strlen (str), host_charset (), NULL);
14139 +/* Python function to get the condition expression of a breakpoint. */
14141 +bppy_get_condition (PyObject *self, void *closure)
14144 + BPPY_REQUIRE_VALID ((breakpoint_object *) self);
14146 + str = ((breakpoint_object *) self)->bp->cond_string;
14149 + return PyString_Decode (str, strlen (str), host_charset (), NULL);
14153 +bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
14156 + breakpoint_object *self_bp = (breakpoint_object *) self;
14157 + volatile struct gdb_exception except;
14159 + BPPY_SET_REQUIRE_VALID (self_bp);
14161 + if (newvalue == NULL)
14163 + PyErr_SetString (PyExc_TypeError, "cannot delete `condition' attribute");
14166 + else if (newvalue == Py_None)
14170 + exp = python_string_to_host_string (newvalue);
14175 + TRY_CATCH (except, RETURN_MASK_ALL)
14177 + set_breakpoint_condition (self_bp->bp, exp, 0);
14179 + GDB_PY_SET_HANDLE_EXCEPTION (except);
14184 +/* Python function to get the commands attached to a breakpoint. */
14186 +bppy_get_commands (PyObject *self, void *closure)
14188 + breakpoint_object *self_bp = (breakpoint_object *) self;
14190 + volatile struct gdb_exception except;
14191 + struct ui_file *string_file;
14192 + struct cleanup *chain;
14193 + PyObject *result;
14196 + BPPY_REQUIRE_VALID (self_bp);
14198 + if (! self_bp->bp->commands)
14201 + string_file = mem_fileopen ();
14202 + chain = make_cleanup_ui_file_delete (string_file);
14204 + TRY_CATCH (except, RETURN_MASK_ALL)
14206 + /* FIXME: this can fail. Maybe we need to be making a new
14207 + ui_out object here? */
14208 + ui_out_redirect (uiout, string_file);
14209 + print_command_lines (uiout, self_bp->bp->commands, 0);
14210 + ui_out_redirect (uiout, NULL);
14212 + cmdstr = ui_file_xstrdup (string_file, &length);
14213 + GDB_PY_HANDLE_EXCEPTION (except);
14215 + result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
14216 + do_cleanups (chain);
14221 +/* Python function to get the breakpoint's number. */
14223 +bppy_get_number (PyObject *self, void *closure)
14225 + breakpoint_object *self_bp = (breakpoint_object *) self;
14227 + BPPY_REQUIRE_VALID (self_bp);
14229 + return PyInt_FromLong (self_bp->number);
14232 +/* Python function to get the breakpoint's thread ID. */
14234 +bppy_get_thread (PyObject *self, void *closure)
14236 + breakpoint_object *self_bp = (breakpoint_object *) self;
14238 + BPPY_REQUIRE_VALID (self_bp);
14240 + if (self_bp->bp->thread == -1)
14243 + return PyInt_FromLong (self_bp->bp->thread);
14246 +/* Python function to get the breakpoint's hit count. */
14248 +bppy_get_hit_count (PyObject *self, void *closure)
14250 + breakpoint_object *self_bp = (breakpoint_object *) self;
14252 + BPPY_REQUIRE_VALID (self_bp);
14254 + return PyInt_FromLong (self_bp->bp->hit_count);
14257 +/* Python function to get the breakpoint's ignore count. */
14259 +bppy_get_ignore_count (PyObject *self, void *closure)
14261 + breakpoint_object *self_bp = (breakpoint_object *) self;
14263 + BPPY_REQUIRE_VALID (self_bp);
14265 + return PyInt_FromLong (self_bp->bp->ignore_count);
14268 +/* Python function to create a new breakpoint. */
14270 +bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
14272 + PyObject *result;
14274 + volatile struct gdb_exception except;
14276 + /* FIXME: allow condition, thread, temporary, ... ? */
14277 + if (! PyArg_ParseTuple (args, "s", &spec))
14279 + result = subtype->tp_alloc (subtype, 0);
14282 + bppy_pending_object = (breakpoint_object *) result;
14283 + bppy_pending_object->number = -1;
14284 + bppy_pending_object->bp = NULL;
14286 + TRY_CATCH (except, RETURN_MASK_ALL)
14288 + set_breakpoint (python_gdbarch, spec, NULL, 0, 0, -1, 0,
14289 + AUTO_BOOLEAN_TRUE, 1);
14291 + if (except.reason < 0)
14293 + subtype->tp_free (result);
14294 + return PyErr_Format (except.reason == RETURN_QUIT
14295 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
14296 + "%s", except.message);
14299 + BPPY_REQUIRE_VALID ((breakpoint_object *) result);
14305 +/* Static function to return a tuple holding all breakpoints. */
14308 +gdbpy_breakpoints (PyObject *self, PyObject *args)
14310 + PyObject *result;
14312 + if (bppy_live == 0)
14315 + result = PyTuple_New (bppy_live);
14319 + for (i = 0; out < bppy_live; ++i)
14321 + if (! bppy_breakpoints[i])
14323 + Py_INCREF (bppy_breakpoints[i]);
14324 + PyTuple_SetItem (result, out, (PyObject *) bppy_breakpoints[i]);
14333 +/* Event callback functions. */
14335 +/* Callback that is used when a breakpoint is created. This function
14336 + will create a new Python breakpoint object. */
14338 +gdbpy_breakpoint_created (int num)
14340 + breakpoint_object *newbp;
14341 + struct breakpoint *bp;
14342 + PyGILState_STATE state;
14347 + for (bp = breakpoint_chain; bp; bp = bp->next)
14348 + if (bp->number == num)
14353 + if (num >= bppy_slots)
14355 + int old = bppy_slots;
14356 + bppy_slots = bppy_slots * 2 + 10;
14358 + = (breakpoint_object **) xrealloc (bppy_breakpoints,
14360 + * sizeof (breakpoint_object *)));
14361 + memset (&bppy_breakpoints[old], 0,
14362 + (bppy_slots - old) * sizeof (PyObject *));
14367 + state = PyGILState_Ensure ();
14369 + if (bppy_pending_object)
14371 + newbp = bppy_pending_object;
14372 + bppy_pending_object = NULL;
14375 + newbp = PyObject_New (breakpoint_object, &breakpoint_object_type);
14378 + PyObject *hookfn;
14380 + newbp->number = num;
14382 + bppy_breakpoints[num] = newbp;
14384 + hookfn = gdbpy_get_hook_function ("new_breakpoint");
14387 + PyObject *result;
14388 + result = PyObject_CallFunctionObjArgs (hookfn, newbp, NULL);
14391 + Py_DECREF (result);
14393 + Py_DECREF (hookfn);
14397 + /* Just ignore errors here. */
14400 + PyGILState_Release (state);
14403 +/* Callback that is used when a breakpoint is deleted. This will
14404 + invalidate the corresponding Python object. */
14406 +gdbpy_breakpoint_deleted (int num)
14408 + PyGILState_STATE state;
14410 + state = PyGILState_Ensure ();
14411 + if (BPPY_VALID_P (num))
14413 + bppy_breakpoints[num]->bp = NULL;
14414 + Py_DECREF (bppy_breakpoints[num]);
14415 + bppy_breakpoints[num] = NULL;
14418 + PyGILState_Release (state);
14423 +/* Initialize the Python breakpoint code. */
14425 +gdbpy_initialize_breakpoints (void)
14427 + breakpoint_object_type.tp_new = bppy_new;
14428 + if (PyType_Ready (&breakpoint_object_type) < 0)
14431 + Py_INCREF (&breakpoint_object_type);
14432 + PyModule_AddObject (gdb_module, "Breakpoint",
14433 + (PyObject *) &breakpoint_object_type);
14435 + observer_attach_breakpoint_created (gdbpy_breakpoint_created);
14436 + observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
14441 +static PyGetSetDef breakpoint_object_getset[] = {
14442 + { "enabled", bppy_get_enabled, bppy_set_enabled,
14443 + "Boolean telling whether the breakpoint is enabled.", NULL },
14444 + { "silent", bppy_get_silent, bppy_set_silent,
14445 + "Boolean telling whether the breakpoint is silent.", NULL },
14446 + { "thread", bppy_get_thread, bppy_set_thread,
14447 + "Thread ID for the breakpoint.\n\
14448 +If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
14449 +If the value is None, then this breakpoint not thread-specific.\n\
14450 +No other type of value can be used.", NULL },
14451 + { "ignore_count", bppy_get_ignore_count, bppy_set_ignore_count,
14452 + "Number of times this breakpoint should be automatically continued.",
14454 + { "number", bppy_get_number, NULL,
14455 + "Breakpoint's number assigned by GDB.", NULL },
14456 + { "hit_count", bppy_get_hit_count, bppy_set_hit_count,
14457 + "Number of times the breakpoint has been hit.\n\
14458 +Can be set to zero to clear the count. No other value is valid\n\
14459 +when setting this property.", NULL },
14460 + { "location", bppy_get_location, NULL,
14461 + "Location of the breakpoint, as specified by the user.", NULL},
14462 + { "condition", bppy_get_condition, bppy_set_condition,
14463 + "Condition of the breakpoint, as specified by the user,\
14464 +or None if no condition set."},
14465 + { "commands", bppy_get_commands, NULL,
14466 + "Commands of the breakpoint, as specified by the user."},
14467 + { NULL } /* Sentinel. */
14470 +static PyMethodDef breakpoint_object_methods[] =
14472 + { "is_valid", bppy_is_valid, METH_NOARGS,
14473 + "Return true if this breakpoint is valid, false if not." },
14474 + { NULL } /* Sentinel. */
14477 +static PyTypeObject breakpoint_object_type =
14479 + PyObject_HEAD_INIT (NULL)
14481 + "gdb.Breakpoint", /*tp_name*/
14482 + sizeof (breakpoint_object), /*tp_basicsize*/
14483 + 0, /*tp_itemsize*/
14484 + 0, /*tp_dealloc*/
14486 + 0, /*tp_getattr*/
14487 + 0, /*tp_setattr*/
14488 + 0, /*tp_compare*/
14490 + 0, /*tp_as_number*/
14491 + 0, /*tp_as_sequence*/
14492 + 0, /*tp_as_mapping*/
14496 + 0, /*tp_getattro*/
14497 + 0, /*tp_setattro*/
14498 + 0, /*tp_as_buffer*/
14499 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
14500 + "GDB breakpoint object", /* tp_doc */
14501 + 0, /* tp_traverse */
14502 + 0, /* tp_clear */
14503 + 0, /* tp_richcompare */
14504 + 0, /* tp_weaklistoffset */
14506 + 0, /* tp_iternext */
14507 + breakpoint_object_methods, /* tp_methods */
14508 + 0, /* tp_members */
14509 + breakpoint_object_getset /* tp_getset */
14511 diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
14512 index 528aca6..04b3fd1 100644
14513 --- a/gdb/python/py-cmd.c
14514 +++ b/gdb/python/py-cmd.c
14515 @@ -49,8 +49,7 @@ static struct cmdpy_completer completers[] =
14517 #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
14519 -/* A gdb command. For the time being only ordinary commands (not
14520 - set/show commands) are allowed. */
14521 +/* A gdb command. */
14522 struct cmdpy_object
14525 @@ -70,7 +69,6 @@ typedef struct cmdpy_object cmdpy_object;
14527 static PyTypeObject cmdpy_object_type;
14530 /* Constants used by this module. */
14531 static PyObject *invoke_cst;
14532 static PyObject *complete_cst;
14533 @@ -263,10 +261,13 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
14534 *BASE_LIST is set to the final prefix command's list of
14537 + START_LIST is the list in which the search starts.
14539 This function returns the xmalloc()d name of the new command. On
14540 error sets the Python error and returns NULL. */
14542 -parse_command_name (char *text, struct cmd_list_element ***base_list)
14544 +gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
14545 + struct cmd_list_element **start_list)
14547 struct cmd_list_element *elt;
14548 int len = strlen (text);
14549 @@ -299,7 +300,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
14553 - *base_list = &cmdlist;
14554 + *base_list = start_list;
14558 @@ -308,7 +309,7 @@ parse_command_name (char *text, struct cmd_list_element ***base_list)
14559 prefix_text[i + 1] = '\0';
14561 text = prefix_text;
14562 - elt = lookup_cmd_1 (&text, cmdlist, NULL, 1);
14563 + elt = lookup_cmd_1 (&text, *start_list, NULL, 1);
14564 if (!elt || elt == (struct cmd_list_element *) -1)
14566 PyErr_Format (PyExc_RuntimeError, _("could not find command prefix %s"),
14567 @@ -399,7 +400,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
14571 - cmd_name = parse_command_name (name, &cmd_list);
14572 + cmd_name = gdbpy_parse_command_name (name, &cmd_list, &cmdlist);
14576 diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
14577 index 279415c..5d8ce0a 100644
14578 --- a/gdb/python/py-frame.c
14579 +++ b/gdb/python/py-frame.c
14580 @@ -202,10 +202,59 @@ frapy_pc (PyObject *self, PyObject *args)
14581 return PyLong_FromUnsignedLongLong (pc);
14584 +/* Implementation of gdb.Frame.block (self) -> gdb.Block.
14585 + Returns the frame's code block. */
14588 +frapy_block (PyObject *self, PyObject *args)
14590 + struct frame_info *frame;
14591 + struct block *block = NULL;
14592 + volatile struct gdb_exception except;
14594 + TRY_CATCH (except, RETURN_MASK_ALL)
14596 + FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14598 + block = block_for_pc (get_frame_address_in_block (frame));
14600 + GDB_PY_HANDLE_EXCEPTION (except);
14603 + return block_to_block_object (block);
14609 +/* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
14610 + Returns the symbol for the function corresponding to this frame. */
14613 +frapy_function (PyObject *self, PyObject *args)
14615 + struct symbol *sym = NULL;
14616 + struct frame_info *frame;
14617 + volatile struct gdb_exception except;
14619 + TRY_CATCH (except, RETURN_MASK_ALL)
14621 + FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14623 + sym = find_pc_function (get_frame_address_in_block (frame));
14625 + GDB_PY_HANDLE_EXCEPTION (except);
14628 + return symbol_to_symbol_object (sym);
14633 /* Convert a frame_info struct to a Python Frame object.
14634 Sets a Python exception and returns NULL on error. */
14636 -static frame_object *
14638 frame_info_to_frame_object (struct frame_info *frame)
14640 frame_object *frame_obj;
14641 @@ -235,7 +284,7 @@ frame_info_to_frame_object (struct frame_info *frame)
14643 frame_obj->gdbarch = get_frame_arch (frame);
14645 - return frame_obj;
14646 + return (PyObject *) frame_obj;
14649 /* Implementation of gdb.Frame.older (self) -> gdb.Frame.
14650 @@ -296,7 +345,30 @@ frapy_newer (PyObject *self, PyObject *args)
14654 -/* Implementation of gdb.Frame.read_var_value (self, variable) -> gdb.Value.
14655 +/* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line.
14656 + Returns the frame's symtab and line. */
14659 +frapy_find_sal (PyObject *self, PyObject *args)
14661 + struct frame_info *frame;
14662 + struct symtab_and_line sal;
14663 + volatile struct gdb_exception except;
14664 + PyObject *sal_obj = NULL; /* Initialize to appease gcc warning. */
14666 + TRY_CATCH (except, RETURN_MASK_ALL)
14668 + FRAPY_REQUIRE_VALID ((frame_object *) self, frame);
14670 + find_frame_sal (frame, &sal);
14671 + sal_obj = symtab_and_line_to_sal_object (sal);
14673 + GDB_PY_HANDLE_EXCEPTION (except);
14678 +/* Implementation of gdb.Frame.read_var (self, variable) -> gdb.Value.
14679 Returns the value of the given variable in this frame. The argument must be
14680 a string. Returns None if GDB can't find the specified variable. */
14682 @@ -312,7 +384,9 @@ frapy_read_var (PyObject *self, PyObject *args)
14683 if (!PyArg_ParseTuple (args, "O", &sym_obj))
14686 - if (gdbpy_is_string (sym_obj))
14687 + if (PyObject_TypeCheck (sym_obj, &symbol_object_type))
14688 + var = symbol_object_to_symbol (sym_obj);
14689 + else if (gdbpy_is_string (sym_obj))
14692 struct block *block = NULL;
14693 @@ -365,6 +439,25 @@ frapy_read_var (PyObject *self, PyObject *args)
14697 +/* Select this frame. */
14700 +frapy_select (PyObject *self, PyObject *args)
14702 + struct frame_info *fi;
14703 + frame_object *frame = (frame_object *) self;
14704 + volatile struct gdb_exception except;
14706 + TRY_CATCH (except, RETURN_MASK_ALL)
14708 + FRAPY_REQUIRE_VALID (frame, fi);
14709 + select_frame (fi);
14711 + GDB_PY_HANDLE_EXCEPTION (except);
14716 /* Implementation of gdb.selected_frame () -> gdb.Frame.
14717 Returns the selected frame object. */
14719 @@ -372,7 +465,7 @@ PyObject *
14720 gdbpy_selected_frame (PyObject *self, PyObject *args)
14722 struct frame_info *frame;
14723 - frame_object *frame_obj = NULL; /* Initialize to appease gcc warning. */
14724 + PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */
14725 volatile struct gdb_exception except;
14727 TRY_CATCH (except, RETURN_MASK_ALL)
14728 @@ -382,7 +475,7 @@ gdbpy_selected_frame (PyObject *self, PyObject *args)
14730 GDB_PY_HANDLE_EXCEPTION (except);
14732 - return (PyObject *) frame_obj;
14733 + return frame_obj;
14736 /* Implementation of gdb.stop_reason_string (Integer) -> String.
14737 @@ -484,15 +577,26 @@ Return the reason why it's not possible to find frames older than this." },
14738 { "pc", frapy_pc, METH_NOARGS,
14740 Return the frame's resume address." },
14741 + { "block", frapy_block, METH_NOARGS,
14742 + "block () -> gdb.Block.\n\
14743 +Return the frame's code block." },
14744 + { "function", frapy_function, METH_NOARGS,
14745 + "function () -> gdb.Symbol.\n\
14746 +Returns the symbol for the function corresponding to this frame." },
14747 { "older", frapy_older, METH_NOARGS,
14748 "older () -> gdb.Frame.\n\
14749 Return the frame that called this frame." },
14750 { "newer", frapy_newer, METH_NOARGS,
14751 "newer () -> gdb.Frame.\n\
14752 Return the frame called by this frame." },
14753 + { "find_sal", frapy_find_sal, METH_NOARGS,
14754 + "find_sal () -> gdb.Symtab_and_line.\n\
14755 +Return the frame's symtab and line." },
14756 { "read_var", frapy_read_var, METH_VARARGS,
14757 "read_var (variable) -> gdb.Value.\n\
14758 Return the value of the variable in this frame." },
14759 + { "select", frapy_select, METH_NOARGS,
14760 + "Select this frame as the user's current frame." },
14761 {NULL} /* Sentinel */
14764 diff --git a/gdb/python/py-hooks.c b/gdb/python/py-hooks.c
14765 new file mode 100644
14766 index 0000000..a3140bc
14768 +++ b/gdb/python/py-hooks.c
14770 +/* Notifications from gdb to Python
14772 + Copyright (C) 2008 Free Software Foundation, Inc.
14774 + This file is part of GDB.
14776 + This program is free software; you can redistribute it and/or modify
14777 + it under the terms of the GNU General Public License as published by
14778 + the Free Software Foundation; either version 3 of the License, or
14779 + (at your option) any later version.
14781 + This program is distributed in the hope that it will be useful,
14782 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14783 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14784 + GNU General Public License for more details.
14786 + You should have received a copy of the GNU General Public License
14787 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
14790 +#include "cli/cli-decode.h"
14791 +#include "charset.h"
14792 +#include "python.h"
14793 +#include "python-internal.h"
14794 +#include "observer.h"
14797 +gdbpy_get_hook_function (const char *name)
14800 + PyObject *result;
14802 + if (! PyObject_HasAttrString (gdb_module, "hooks"))
14804 + hooks = PyObject_GetAttrString (gdb_module, "hooks");
14807 + /* The cast is because the Python function doesn't declare const argument.
14808 + This is a problem in Python version 2.4, but not in 2.5. */
14809 + if (! PyObject_HasAttrString (hooks, (char *) name))
14811 + Py_DECREF (hooks);
14814 + /* The cast is because the Python function doesn't declare const argument.
14815 + This is a problem in Python version 2.4, but not in 2.5. */
14816 + result = PyObject_GetAttrString (hooks, (char *) name);
14817 + Py_DECREF (hooks);
14820 diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
14821 new file mode 100644
14822 index 0000000..5e90cc2
14824 +++ b/gdb/python/py-inferior.c
14826 +/* Python interface to inferiors.
14828 + Copyright (C) 2009 Free Software Foundation, Inc.
14830 + This file is part of GDB.
14832 + This program is free software; you can redistribute it and/or modify
14833 + it under the terms of the GNU General Public License as published by
14834 + the Free Software Foundation; either version 3 of the License, or
14835 + (at your option) any later version.
14837 + This program is distributed in the hope that it will be useful,
14838 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14839 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14840 + GNU General Public License for more details.
14842 + You should have received a copy of the GNU General Public License
14843 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
14846 +#include "exceptions.h"
14847 +#include "gdbcore.h"
14848 +#include "gdbthread.h"
14849 +#include "inferior.h"
14850 +#include "observer.h"
14851 +#include "python-internal.h"
14852 +#include "arch-utils.h"
14853 +#include "language.h"
14855 +struct threadlist_entry {
14856 + thread_object *thread_obj;
14857 + struct threadlist_entry *next;
14864 + /* The inferior we represent. */
14865 + struct inferior *inferior;
14867 + /* thread_object instances under this inferior. This list owns a reference
14868 + to each object it contains. */
14869 + struct threadlist_entry *threads;
14871 + /* Number of threads in the list. */
14873 +} inferior_object;
14875 +static PyTypeObject inferior_object_type;
14881 + /* These are kept just for mbpy_str. */
14883 + CORE_ADDR length;
14886 +static PyTypeObject membuf_object_type;
14888 +/* Require that INFERIOR be a valid inferior ID. */
14889 +#define INFPY_REQUIRE_VALID(Inferior) \
14891 + if (!Inferior->inferior) \
14893 + PyErr_SetString (PyExc_RuntimeError, \
14894 + "inferior no longer exists"); \
14899 +struct inflist_entry {
14900 + inferior_object *inf_obj;
14901 + struct inflist_entry *next;
14906 +/* Inferior objects list. */
14908 +/* List containing inferior_objects. This list owns a reference to each
14909 + object it contains. */
14910 +static struct inflist_entry *inferior_list;
14912 +static int ninferiors;
14915 +/* An observer callback function that is called when an inferior has
14916 + been created. Creates a corresponding Python object for the inferior
14917 + and adds it to the list. */
14919 +add_inferior_object (int pid)
14921 + struct inferior *inf = find_inferior_pid (pid);
14922 + inferior_object *inf_obj;
14923 + struct inflist_entry *entry;
14924 + struct cleanup *cleanup;
14928 + warning (_("Can't create Python Inferior object."));
14932 + cleanup = ensure_python_env (get_current_arch (), current_language);
14934 + inf_obj = PyObject_New (inferior_object, &inferior_object_type);
14937 + warning (_("Can't create Python Inferior object."));
14938 + gdbpy_print_stack ();
14939 + do_cleanups (cleanup);
14943 + inf_obj->inferior = inf;
14944 + inf_obj->threads = NULL;
14945 + inf_obj->nthreads = 0;
14947 + entry = xmalloc (sizeof (struct inflist_entry));
14948 + entry->inf_obj = inf_obj;
14949 + entry->next = inferior_list;
14951 + inferior_list = entry;
14955 + do_cleanups (cleanup);
14958 +/* An observer callback function that is called when an inferior has
14959 + been deleted. Removes the corresponding Python object from the
14960 + inferior list, and removes the list's reference to the object. */
14962 +delete_inferior_object (int pid)
14964 + PyGILState_STATE state;
14965 + struct inflist_entry **inf_entry, *inf_tmp;
14966 + struct threadlist_entry *th_entry, *th_tmp;
14968 + /* Find inferior_object for the given PID. */
14969 + for (inf_entry = &inferior_list; *inf_entry != NULL;
14970 + inf_entry = &(*inf_entry)->next)
14971 + if ((*inf_entry)->inf_obj->inferior->pid == pid)
14977 + state = PyGILState_Ensure ();
14979 + inf_tmp = *inf_entry;
14980 + inf_tmp->inf_obj->inferior = NULL;
14982 + /* Deallocate threads list. */
14983 + for (th_entry = inf_tmp->inf_obj->threads; th_entry != NULL;)
14985 + Py_DECREF (th_entry->thread_obj);
14987 + th_tmp = th_entry;
14988 + th_entry = th_entry->next;
14992 + inf_tmp->inf_obj->nthreads = 0;
14994 + *inf_entry = (*inf_entry)->next;
14995 + Py_DECREF (inf_tmp->inf_obj);
15000 + PyGILState_Release (state);
15003 +/* Finds the Python Inferior object for the given pid. Returns a borrowed
15006 +find_inferior_object (int pid)
15008 + struct inflist_entry *p;
15010 + for (p = inferior_list; p != NULL; p = p->next)
15011 + if (p->inf_obj->inferior->pid == pid)
15012 + return (PyObject *) p->inf_obj;
15017 +/* Finds the Python InferiorThread object for the given ptid. Returns a
15018 + borrowed reference. */
15020 +find_thread_object (ptid_t ptid)
15023 + struct inflist_entry *p;
15024 + struct threadlist_entry *q;
15026 + pid = PIDGET (ptid);
15027 + for (p = inferior_list; p != NULL; p = p->next)
15028 + if (p->inf_obj->inferior->pid == pid)
15029 + for (q = p->inf_obj->threads; q != NULL; q = q->next)
15030 + if (ptid_equal (q->thread_obj->thread->ptid, ptid))
15031 + return q->thread_obj;
15038 +/* Inferior object. */
15041 +add_thread_object (struct thread_info *tp)
15043 + PyGILState_STATE state;
15044 + thread_object *thread_obj;
15045 + inferior_object *inf_obj;
15046 + struct threadlist_entry *entry;
15048 + state = PyGILState_Ensure ();
15050 + thread_obj = create_thread_object (tp);
15053 + warning (_("Can't create Python InferiorThread object."));
15054 + gdbpy_print_stack ();
15055 + PyGILState_Release (state);
15059 + inf_obj = (inferior_object *) thread_obj->inf_obj;
15061 + entry = xmalloc (sizeof (struct threadlist_entry));
15062 + entry->thread_obj = thread_obj;
15063 + entry->next = inf_obj->threads;
15065 + inf_obj->threads = entry;
15066 + inf_obj->nthreads++;
15068 + PyGILState_Release (state);
15072 +delete_thread_object (struct thread_info *tp, int ignore)
15074 + PyGILState_STATE state;
15075 + inferior_object *inf_obj;
15076 + thread_object *thread_obj;
15077 + struct threadlist_entry **entry, *tmp;
15079 + inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
15083 + /* Find thread entry in its inferior's thread_list. */
15084 + for (entry = &inf_obj->threads; *entry != NULL; entry = &(*entry)->next)
15085 + if ((*entry)->thread_obj->thread == tp)
15091 + state = PyGILState_Ensure ();
15094 + tmp->thread_obj->thread = NULL;
15096 + *entry = (*entry)->next;
15097 + inf_obj->nthreads--;
15099 + Py_DECREF (tmp->thread_obj);
15103 + PyGILState_Release (state);
15107 +infpy_threads (PyObject *self, PyObject *args)
15110 + struct threadlist_entry *entry;
15111 + inferior_object *inf_obj = (inferior_object *) self;
15114 + INFPY_REQUIRE_VALID (inf_obj);
15117 + tuple = PyTuple_New (inf_obj->nthreads);
15121 + /* The list is in reverse order of thread age (i.e., newest comes first),
15122 + is this a problem? */
15123 + for (i = 0, entry = inf_obj->threads; i < inf_obj->nthreads;
15124 + i++, entry = entry->next)
15126 + Py_INCREF (entry->thread_obj);
15127 + PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->thread_obj);
15134 +infpy_get_num (PyObject *self, void *closure)
15136 + inferior_object *inf = (inferior_object *) self;
15138 + INFPY_REQUIRE_VALID (inf);
15140 + return PyLong_FromLong (inf->inferior->num);
15144 +infpy_get_pid (PyObject *self, void *closure)
15146 + inferior_object *inf = (inferior_object *) self;
15148 + INFPY_REQUIRE_VALID (inf);
15150 + return PyLong_FromLong (inf->inferior->pid);
15154 +infpy_get_was_attached (PyObject *self, void *closure)
15156 + inferior_object *inf = (inferior_object *) self;
15157 + INFPY_REQUIRE_VALID (inf);
15158 + if (inf->inferior->attach_flag)
15165 +/* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
15166 + Returns a list of all inferiors. */
15169 +gdbpy_inferiors (PyObject *unused, PyObject *unused2)
15172 + struct inflist_entry *entry;
15175 + tuple = PyTuple_New (ninferiors);
15179 + /* The list is in reverse order of inferior age (i.e., newest comes first),
15180 + is this a problem? */
15181 + for (i = 0, entry = inferior_list; i < ninferiors; i++, entry = entry->next)
15183 + Py_INCREF (entry->inf_obj);
15184 + PyTuple_SET_ITEM (tuple, i, (PyObject *) entry->inf_obj);
15192 +/* Membuf and memory manipulation. */
15194 +/* Implementation of gdb.read_memory (address, length).
15195 + Returns a Python buffer object with LENGTH bytes of the inferior's memory
15196 + at ADDRESS. Both arguments are integers. */
15199 +infpy_read_memory (PyObject *self, PyObject *args)
15202 + CORE_ADDR addr, length;
15203 + void *buffer = NULL;
15204 + membuf_object *membuf_obj;
15205 + PyObject *addr_obj, *length_obj;
15206 + struct cleanup *cleanups;
15207 + volatile struct gdb_exception except;
15209 + if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
15212 + cleanups = make_cleanup (null_cleanup, NULL);
15214 + TRY_CATCH (except, RETURN_MASK_ALL)
15216 + if (!get_addr_from_python (addr_obj, &addr)
15217 + || !get_addr_from_python (length_obj, &length))
15223 + buffer = xmalloc (length);
15224 + make_cleanup (xfree, buffer);
15226 + read_memory (addr, buffer, length);
15228 + GDB_PY_HANDLE_EXCEPTION (except);
15232 + do_cleanups (cleanups);
15236 + membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
15237 + if (membuf_obj == NULL)
15239 + PyErr_SetString (PyExc_MemoryError,
15240 + "Could not allocate memory buffer object.");
15241 + do_cleanups (cleanups);
15245 + discard_cleanups (cleanups);
15247 + membuf_obj->buffer = buffer;
15248 + membuf_obj->addr = addr;
15249 + membuf_obj->length = length;
15251 + return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
15252 + Py_END_OF_BUFFER);
15255 +/* Implementation of gdb.write_memory (address, buffer [, length]).
15256 + Writes the contents of BUFFER (a Python object supporting the read buffer
15257 + protocol) at ADDRESS in the inferior's memory. Write LENGTH bytes from
15258 + BUFFER, or its entire contents if the argument is not provided. The
15259 + function returns nothing. */
15262 +infpy_write_memory (PyObject *self, PyObject *args)
15264 + int buf_len, error = 0;
15265 + const char *buffer;
15266 + CORE_ADDR addr, length;
15267 + PyObject *addr_obj, *length_obj = NULL;
15268 + volatile struct gdb_exception except;
15270 + if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
15274 + TRY_CATCH (except, RETURN_MASK_ALL)
15276 + if (!get_addr_from_python (addr_obj, &addr))
15283 + length = buf_len;
15284 + else if (!get_addr_from_python (length_obj, &length))
15290 + write_memory (addr, buffer, length);
15292 + GDB_PY_HANDLE_EXCEPTION (except);
15300 +/* Destructor of Membuf objects. */
15303 +mbpy_dealloc (PyObject *self)
15305 + xfree (((membuf_object *) self)->buffer);
15306 + self->ob_type->tp_free (self);
15309 +/* Return a description of the Membuf object. */
15312 +mbpy_str (PyObject *self)
15314 + membuf_object *membuf_obj = (membuf_object *) self;
15316 + return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
15317 + paddress (python_gdbarch, membuf_obj->addr),
15318 + pulongest (membuf_obj->length));
15322 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
15324 + membuf_object *membuf_obj = (membuf_object *) self;
15328 + PyErr_SetString (PyExc_SystemError,
15329 + "The memory buffer supports only one segment.");
15333 + *ptrptr = membuf_obj->buffer;
15335 + return membuf_obj->length;
15339 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
15341 + return get_read_buffer (self, segment, ptrptr);
15345 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
15348 + *lenp = ((membuf_object *) self)->length;
15354 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
15356 + void *ptr = NULL;
15359 + ret = get_read_buffer (self, segment, &ptr);
15360 + *ptrptr = (char *) ptr;
15365 +/* Adds GDB value V to the pattern buffer in *PATTERN_BUF. If SIZE is not zero,
15366 + it specifies the number of bytes from V to copy to *PATTERN_BUF. The
15367 + function increases the size of *PATTERN_BUF as necessary, adjusting
15368 + *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process. */
15371 +add_value_pattern (struct value *v, int size, char **pattern_buf,
15372 + char **pattern_buf_end, ULONGEST *pattern_buf_size)
15378 + LONGEST x = value_as_long (v);
15381 + *(*pattern_buf_end)++ = x;
15384 + put_bits (x, *pattern_buf_end, size * 8,
15385 + gdbarch_byte_order (python_gdbarch) == BFD_ENDIAN_BIG);
15386 + *pattern_buf_end += size;
15391 + val_bytes = TYPE_LENGTH (value_type (v));
15393 + increase_pattern_buffer (pattern_buf, pattern_buf_end,
15394 + pattern_buf_size, val_bytes);
15396 + memcpy (*pattern_buf_end, value_contents_raw (v), val_bytes);
15397 + *pattern_buf_end += val_bytes;
15401 +/* This function does the actual work of constructing the pattern buffer from
15402 + OBJ. If OBJ is an object which implements the read buffer protocol (such
15403 + as a string, a byte array or gdb.Membuf), then its contents are directly
15404 + copied to *PATTERN_BUF. If it is a list, then this function is recursively
15405 + called for each of its elements. If OBJ is an object which can be converted
15406 + to a GDB value, then the contents of the value are copied to PATTERN_BUF.
15407 + If SIZE is different than zero, then it limits the number of bytes which
15408 + are copied to the buffer in case OBJ is converted to a GDB value. That
15409 + means that SIZE influences only Python scalars and gdb.Value objects.
15410 + The function increases the size of *PATTERN_BUF as necessary, adjusting
15411 + *PATTERN_BUF_END and *PATTERN_BUF_SIZE in the process.
15413 + Returns 1 on success or 0 on failure, with a Python exception set. This
15414 + function can also throw GDB exceptions. */
15417 +add_pattern_element (PyObject *obj, int size, char **pattern_buf,
15418 + char **pattern_buf_end, ULONGEST *pattern_buf_size)
15420 + if (PyObject_CheckReadBuffer (obj))
15422 + /* Handle string, Unicode string, byte array, gdb.Membuf and any other
15423 + object implementing the buffer protocol. The SIZE parameter is
15424 + ignored in this case. */
15426 + Py_ssize_t val_bytes;
15427 + const void *buffer;
15429 + if (PyObject_AsReadBuffer (obj, &buffer, &val_bytes) == -1)
15432 + increase_pattern_buffer (pattern_buf, pattern_buf_end,
15433 + pattern_buf_size, val_bytes);
15435 + memcpy (*pattern_buf_end, buffer, val_bytes);
15436 + *pattern_buf_end += val_bytes;
15438 + else if (gdbpy_is_value_object (obj))
15439 + add_value_pattern (value_object_to_value (obj), size, pattern_buf,
15440 + pattern_buf_end, pattern_buf_size);
15441 + else if (PySequence_Check (obj))
15443 + /* Handle lists and tuples. */
15445 + Py_ssize_t i, num_objs;
15447 + num_objs = PySequence_Size (obj);
15448 + for (i = 0; i < num_objs; i++)
15449 + if (!add_pattern_element (PySequence_GetItem (obj, i), size,
15450 + pattern_buf, pattern_buf_end,
15451 + pattern_buf_size))
15456 + /* See if we can convert from a Python object to a GDB value. */
15458 + struct value *v = convert_value_from_python (obj);
15461 + add_value_pattern (v, size, pattern_buf, pattern_buf_end,
15462 + pattern_buf_size);
15470 +/* Constructs the search pattern from OBJ, putting it in *PATTERN_BUFP, and its
15471 + size in *PATTERN_LENP. See the function add_pattern_element to learn how
15472 + the search pattern is obtained from OBJ.
15474 + Returns 1 on success or 0 on failure, with a Python exception set. This
15475 + function can also throw GDB exceptions. */
15478 +get_search_pattern (PyObject *obj, int size, char **pattern_bufp,
15479 + ULONGEST *pattern_lenp)
15481 + /* Buffer to hold the search pattern. */
15482 + char *pattern_buf;
15483 + /* Current size of search pattern buffer.
15484 + We realloc space as needed. */
15485 + ULONGEST pattern_buf_size;
15486 + /* Pointer to one past the last in-use part of pattern_buf. */
15487 + char *pattern_buf_end;
15488 + struct cleanup *old_cleanups;
15490 + allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
15491 + old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
15493 + if (!add_pattern_element (obj, size, &pattern_buf, &pattern_buf_end,
15494 + &pattern_buf_size))
15496 + do_cleanups (old_cleanups);
15501 + *pattern_bufp = pattern_buf;
15502 + *pattern_lenp = pattern_buf_end - pattern_buf;
15504 + discard_cleanups (old_cleanups);
15509 +/* Implementation of
15510 + gdb.search_memory (address, length, pattern [, size] [, max_count]).
15511 + The third argument may be either a pattern, or a list or tupple of patterns
15512 + to be searched. Size is the size in bytes of each search query value, either
15513 + 1, 2, 4 or 8. Returns a list of the addresses where matches were found. */
15516 +infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
15519 + unsigned int found_count = 0;
15520 + long max_count = 0;
15521 + CORE_ADDR start_addr, length;
15522 + char *pattern_buf;
15523 + static char *keywords[] = { "address", "length", "pattern", "size",
15524 + "max_count", NULL };
15525 + ULONGEST pattern_len, search_space_len;
15526 + PyObject *pattern, *list = NULL, *start_addr_obj, *length_obj;
15527 + volatile struct gdb_exception except;
15529 + if (! PyArg_ParseTupleAndKeywords (args, kw, "OOO|il", keywords,
15530 + &start_addr_obj, &length_obj, &pattern,
15531 + &size, &max_count))
15535 + max_count = LONG_MAX;
15537 + if (size != 0 && size != 1 && size != 2 && size != 4 && size != 8)
15539 + PyErr_SetString (PyExc_ValueError, "invalid pattern size");
15543 + TRY_CATCH (except, RETURN_MASK_ALL)
15545 + if (get_addr_from_python (start_addr_obj, &start_addr)
15546 + && get_addr_from_python (length_obj, &length))
15550 + PyErr_SetString (PyExc_ValueError, "empty search range");
15553 + /* Watch for overflows. */
15554 + else if (length > CORE_ADDR_MAX
15555 + || (start_addr + length - 1) < start_addr)
15557 + PyErr_SetString (PyExc_ValueError, "search range too large");
15561 + search_space_len = length;
15563 + if (get_search_pattern (pattern, size, &pattern_buf, &pattern_len))
15565 + /* Any cleanups get automatically executed on an exception. */
15566 + struct cleanup *cleanups = make_cleanup (xfree, pattern_buf);
15568 + list = PyList_New (0);
15570 + while (search_space_len >= pattern_len && found_count < max_count)
15572 + CORE_ADDR found_addr;
15575 + found = search_memory (&start_addr, &search_space_len,
15576 + pattern_buf, pattern_len, &found_addr);
15580 + PyList_Append (list, PyLong_FromUnsignedLong (found_addr));
15584 + do_cleanups (cleanups);
15588 + GDB_PY_HANDLE_EXCEPTION (except);
15596 +gdbpy_initialize_inferior (void)
15598 + if (PyType_Ready (&inferior_object_type) < 0)
15601 + Py_INCREF (&inferior_object_type);
15602 + PyModule_AddObject (gdb_module, "Inferior",
15603 + (PyObject *) &inferior_object_type);
15605 + inferior_list = NULL;
15608 + observer_attach_new_inferior (add_inferior_object);
15609 + observer_attach_inferior_exit (delete_inferior_object);
15610 + observer_attach_new_thread (add_thread_object);
15611 + observer_attach_thread_exit (delete_thread_object);
15613 + if (PyType_Ready (&membuf_object_type) < 0)
15616 + Py_INCREF (&membuf_object_type);
15617 + PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
15622 +static PyGetSetDef inferior_object_getset[] =
15624 + { "num", infpy_get_num, NULL, "ID of inferior, as assigned by GDB.", NULL },
15625 + { "pid", infpy_get_pid, NULL, "PID of inferior, as assigned by the OS.",
15627 + { "was_attached", infpy_get_was_attached, NULL,
15628 + "True if the inferior was created using 'attach'.", NULL },
15633 +static PyMethodDef inferior_object_methods[] =
15635 + { "threads", infpy_threads, METH_NOARGS,
15636 + "Return all the threads of this inferior." },
15638 + { "read_memory", infpy_read_memory, METH_VARARGS,
15639 + "read_memory (address, length) -> buffer\n\
15640 +Return a buffer object for reading from the inferior's memory." },
15641 + { "write_memory", infpy_write_memory, METH_VARARGS,
15642 + "write_memory (address, buffer [, length])\n\
15643 +Write the given buffer object to the inferior's memory." },
15644 + { "search_memory", (PyCFunction) infpy_search_memory, METH_VARARGS | METH_KEYWORDS,
15645 + "search_memory (address, length, pattern [, size] [, max_count]) -> list\n\
15646 +Return a list with the addresses where matches were found." },
15651 +static PyTypeObject inferior_object_type =
15653 + PyObject_HEAD_INIT (NULL)
15655 + "gdb.Inferior", /* tp_name */
15656 + sizeof (inferior_object), /* tp_basicsize */
15657 + 0, /* tp_itemsize */
15658 + 0, /* tp_dealloc */
15659 + 0, /* tp_print */
15660 + 0, /* tp_getattr */
15661 + 0, /* tp_setattr */
15662 + 0, /* tp_compare */
15664 + 0, /* tp_as_number */
15665 + 0, /* tp_as_sequence */
15666 + 0, /* tp_as_mapping */
15670 + 0, /* tp_getattro */
15671 + 0, /* tp_setattro */
15672 + 0, /* tp_as_buffer */
15673 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /* tp_flags */
15674 + "GDB inferior object", /* tp_doc */
15675 + 0, /* tp_traverse */
15676 + 0, /* tp_clear */
15677 + 0, /* tp_richcompare */
15678 + 0, /* tp_weaklistoffset */
15680 + 0, /* tp_iternext */
15681 + inferior_object_methods, /* tp_methods */
15682 + 0, /* tp_members */
15683 + inferior_object_getset, /* tp_getset */
15686 + 0, /* tp_descr_get */
15687 + 0, /* tp_descr_set */
15688 + 0, /* tp_dictoffset */
15695 +/* Python doesn't provide a decent way to get compatibility here. */
15696 +#if HAVE_LIBPYTHON2_4
15697 +#define CHARBUFFERPROC_NAME getcharbufferproc
15699 +#define CHARBUFFERPROC_NAME charbufferproc
15702 +static PyBufferProcs buffer_procs = {
15704 + get_write_buffer,
15706 + /* The cast here works around a difference between Python 2.4 and
15708 + (CHARBUFFERPROC_NAME) get_char_buffer
15711 +static PyTypeObject membuf_object_type = {
15712 + PyObject_HEAD_INIT (NULL)
15714 + "gdb.Membuf", /*tp_name*/
15715 + sizeof (membuf_object), /*tp_basicsize*/
15716 + 0, /*tp_itemsize*/
15717 + mbpy_dealloc, /*tp_dealloc*/
15719 + 0, /*tp_getattr*/
15720 + 0, /*tp_setattr*/
15721 + 0, /*tp_compare*/
15723 + 0, /*tp_as_number*/
15724 + 0, /*tp_as_sequence*/
15725 + 0, /*tp_as_mapping*/
15728 + mbpy_str, /*tp_str*/
15729 + 0, /*tp_getattro*/
15730 + 0, /*tp_setattro*/
15731 + &buffer_procs, /*tp_as_buffer*/
15732 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
15733 + "GDB memory buffer object", /*tp_doc*/
15734 + 0, /* tp_traverse */
15735 + 0, /* tp_clear */
15736 + 0, /* tp_richcompare */
15737 + 0, /* tp_weaklistoffset */
15739 + 0, /* tp_iternext */
15740 + 0, /* tp_methods */
15741 + 0, /* tp_members */
15742 + 0, /* tp_getset */
15745 + 0, /* tp_descr_get */
15746 + 0, /* tp_descr_set */
15747 + 0, /* tp_dictoffset */
15749 + 0, /* tp_alloc */
15750 + PyType_GenericNew /* tp_new */
15752 diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
15753 new file mode 100644
15754 index 0000000..21e4eab
15756 +++ b/gdb/python/py-infthread.c
15758 +/* Python interface to inferior threads.
15760 + Copyright (C) 2009 Free Software Foundation, Inc.
15762 + This file is part of GDB.
15764 + This program is free software; you can redistribute it and/or modify
15765 + it under the terms of the GNU General Public License as published by
15766 + the Free Software Foundation; either version 3 of the License, or
15767 + (at your option) any later version.
15769 + This program is distributed in the hope that it will be useful,
15770 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15771 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15772 + GNU General Public License for more details.
15774 + You should have received a copy of the GNU General Public License
15775 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
15778 +#include "exceptions.h"
15779 +#include "gdbthread.h"
15780 +#include "inferior.h"
15781 +#include "python-internal.h"
15783 +static PyTypeObject thread_object_type;
15785 +/* Require that INFERIOR be a valid inferior ID. */
15786 +#define THPY_REQUIRE_VALID(Thread) \
15788 + if (!Thread->thread) \
15790 + PyErr_SetString (PyExc_RuntimeError, \
15791 + "thread no longer exists"); \
15799 +create_thread_object (struct thread_info *tp)
15801 + thread_object *thread_obj;
15803 + thread_obj = PyObject_New (thread_object, &thread_object_type);
15807 + thread_obj->thread = tp;
15808 + thread_obj->inf_obj = find_inferior_object (PIDGET (tp->ptid));
15809 + Py_INCREF (thread_obj->inf_obj);
15811 + return thread_obj;
15817 +thpy_dealloc (PyObject *self)
15819 + Py_DECREF (((thread_object *) self)->inf_obj);
15820 + self->ob_type->tp_free (self);
15824 +thpy_get_num (PyObject *self, void *closure)
15826 + thread_object *thread_obj = (thread_object *) self;
15828 + THPY_REQUIRE_VALID (thread_obj);
15830 + return PyLong_FromLong (thread_obj->thread->num);
15835 +/* Implementation of Inferior.frames () -> (gdb.Frame, ...).
15836 + Returns a tuple of all frame objects. */
15838 +thpy_frames (PyObject *self, PyObject *args)
15841 + struct frame_info *frame;
15842 + PyObject *frame_obj;
15843 + PyObject *list, *tuple;
15844 + thread_object *thread_obj = (thread_object *) self;
15845 + struct cleanup *cleanup;
15846 + volatile struct gdb_exception except;
15848 + THPY_REQUIRE_VALID (thread_obj);
15850 + list = PyList_New (0);
15851 + if (list == NULL)
15853 + PyErr_SetString (PyExc_MemoryError, "Could not allocate frames list.");
15857 + cleanup = make_cleanup_restore_current_thread ();
15859 + TRY_CATCH (except, RETURN_MASK_ALL)
15861 + switch_to_thread (thread_obj->thread->ptid);
15863 + for (frame = get_current_frame (); frame; frame = get_prev_frame (frame))
15865 + frame_obj = frame_info_to_frame_object (frame);
15866 + if (frame_obj == NULL)
15868 + Py_DECREF (list);
15873 + PyList_Append (list, frame_obj);
15876 + if (except.reason < 0)
15878 + Py_DECREF (list);
15879 + return PyErr_Format (except.reason == RETURN_QUIT
15880 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
15881 + "%s", except.message);
15884 + do_cleanups (cleanup);
15888 + tuple = PyList_AsTuple (list);
15889 + Py_DECREF (list);
15897 +/* Implementation of InferiorThread.newest_frame () -> gdb.Frame.
15898 + Returns the newest frame object. */
15900 +thpy_newest_frame (PyObject *self, PyObject *args)
15902 + struct frame_info *frame;
15903 + PyObject *frame_obj = NULL; /* Initialize to appease gcc warning. */
15904 + thread_object *thread_obj = (thread_object *) self;
15905 + struct cleanup *cleanup;
15906 + volatile struct gdb_exception except;
15908 + THPY_REQUIRE_VALID (thread_obj);
15910 + cleanup = make_cleanup_restore_current_thread ();
15912 + TRY_CATCH (except, RETURN_MASK_ALL)
15914 + switch_to_thread (thread_obj->thread->ptid);
15916 + frame = get_current_frame ();
15917 + frame_obj = frame_info_to_frame_object (frame);
15919 + GDB_PY_HANDLE_EXCEPTION (except);
15921 + do_cleanups (cleanup);
15923 + return frame_obj;
15926 +/* Implementation of InferiorThread.switch ().
15927 + Makes this the GDB selected thread. */
15929 +thpy_switch (PyObject *self, PyObject *args)
15931 + thread_object *thread_obj = (thread_object *) self;
15932 + struct cleanup *cleanup;
15933 + volatile struct gdb_exception except;
15935 + THPY_REQUIRE_VALID (thread_obj);
15937 + TRY_CATCH (except, RETURN_MASK_ALL)
15939 + switch_to_thread (thread_obj->thread->ptid);
15941 + GDB_PY_HANDLE_EXCEPTION (except);
15948 +/* Implementation of gdb.selected_thread () -> gdb.InferiorThread.
15949 + Returns the selected thread object. */
15951 +gdbpy_selected_thread (PyObject *self, PyObject *args)
15953 + PyObject *thread_obj;
15955 + thread_obj = (PyObject *) find_thread_object (inferior_ptid);
15958 + Py_INCREF (thread_obj);
15959 + return thread_obj;
15968 +gdbpy_initialize_thread (void)
15970 + if (PyType_Ready (&thread_object_type) < 0)
15973 + Py_INCREF (&thread_object_type);
15974 + PyModule_AddObject (gdb_module, "InferiorThread",
15975 + (PyObject *) &thread_object_type);
15980 +static PyGetSetDef thread_object_getset[] =
15982 + { "num", thpy_get_num, NULL, "ID of the thread, as assigned by GDB.", NULL },
15987 +static PyMethodDef thread_object_methods[] =
15989 + { "frames", thpy_frames, METH_NOARGS,
15990 + "frames () -> (gdb.Frame, ...)\n\
15991 +Return a tuple containing all frames in the thread." },
15992 + { "newest_frame", thpy_newest_frame, METH_NOARGS,
15993 + "newest_frame () -> gdb.Frame\n\
15994 +Return the newest frame in the thread." },
15995 + { "switch", thpy_switch, METH_NOARGS,
15997 +Makes this the GDB selected thread." },
16002 +static PyTypeObject thread_object_type =
16004 + PyObject_HEAD_INIT (NULL)
16006 + "gdb.InferiorThread", /*tp_name*/
16007 + sizeof (thread_object), /*tp_basicsize*/
16008 + 0, /*tp_itemsize*/
16009 + thpy_dealloc, /*tp_dealloc*/
16011 + 0, /*tp_getattr*/
16012 + 0, /*tp_setattr*/
16013 + 0, /*tp_compare*/
16015 + 0, /*tp_as_number*/
16016 + 0, /*tp_as_sequence*/
16017 + 0, /*tp_as_mapping*/
16021 + 0, /*tp_getattro*/
16022 + 0, /*tp_setattro*/
16023 + 0, /*tp_as_buffer*/
16024 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
16025 + "GDB thread object", /* tp_doc */
16026 + 0, /* tp_traverse */
16027 + 0, /* tp_clear */
16028 + 0, /* tp_richcompare */
16029 + 0, /* tp_weaklistoffset */
16031 + 0, /* tp_iternext */
16032 + thread_object_methods, /* tp_methods */
16033 + 0, /* tp_members */
16034 + thread_object_getset, /* tp_getset */
16037 + 0, /* tp_descr_get */
16038 + 0, /* tp_descr_set */
16039 + 0, /* tp_dictoffset */
16043 diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
16044 new file mode 100644
16045 index 0000000..7bc294c
16047 +++ b/gdb/python/py-membuf.c
16049 +/* Python interface to the inferior memory.
16051 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16053 + This file is part of GDB.
16055 + This program is free software; you can redistribute it and/or modify
16056 + it under the terms of the GNU General Public License as published by
16057 + the Free Software Foundation; either version 3 of the License, or
16058 + (at your option) any later version.
16060 + This program is distributed in the hope that it will be useful,
16061 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16062 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16063 + GNU General Public License for more details.
16065 + You should have received a copy of the GNU General Public License
16066 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
16069 +#include "exceptions.h"
16070 +#include "gdbcore.h"
16071 +#include "python-internal.h"
16077 + /* These are kept just for mbpy_str. */
16079 + CORE_ADDR length;
16082 +static PyTypeObject membuf_object_type;
16084 +/* Implementation of gdb.read_memory (address, length).
16085 + Returns a Python buffer object with LENGTH bytes of the inferior's memory
16086 + at ADDRESS. Both arguments are integers. */
16089 +gdbpy_read_memory (PyObject *self, PyObject *args)
16092 + CORE_ADDR addr, length;
16093 + void *buffer = NULL;
16094 + membuf_object *membuf_obj;
16095 + PyObject *addr_obj, *length_obj;
16096 + struct cleanup *cleanups = NULL;
16097 + volatile struct gdb_exception except;
16099 + if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
16102 + TRY_CATCH (except, RETURN_MASK_ALL)
16104 + if (!get_addr_from_python (addr_obj, &addr)
16105 + || !get_addr_from_python (length_obj, &length))
16111 + buffer = xmalloc (length);
16112 + cleanups = make_cleanup (xfree, buffer);
16114 + read_memory (addr, buffer, length);
16116 + GDB_PY_HANDLE_EXCEPTION (except);
16121 + discard_cleanups (cleanups);
16123 + membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
16124 + if (membuf_obj == NULL)
16127 + PyErr_SetString (PyExc_MemoryError,
16128 + "Could not allocate memory buffer object.");
16132 + membuf_obj->buffer = buffer;
16133 + membuf_obj->addr = addr;
16134 + membuf_obj->length = length;
16136 + return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
16137 + Py_END_OF_BUFFER);
16140 +/* Implementation of gdb.write_memory (address, buffer [, length]).
16141 + Writes the contents of BUFFER (a Python object supporting the read buffer
16142 + protocol) at ADDRESS in the inferior's memory. Write LENGTH bytes from
16143 + BUFFER, or its entire contents if the argument is not provided. The
16144 + function returns nothing. */
16147 +gdbpy_write_memory (PyObject *self, PyObject *args)
16149 + int buf_len, error = 0;
16150 + const char *buffer;
16151 + CORE_ADDR addr, length;
16152 + PyObject *addr_obj, *length_obj = NULL;
16153 + volatile struct gdb_exception except;
16155 + if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
16159 + TRY_CATCH (except, RETURN_MASK_ALL)
16161 + if (!get_addr_from_python (addr_obj, &addr))
16168 + length = buf_len;
16169 + else if (!get_addr_from_python (length_obj, &length))
16175 + write_memory (addr, buffer, length);
16177 + GDB_PY_HANDLE_EXCEPTION (except);
16185 +/* Destructor of Membuf objects. */
16188 +mbpy_dealloc (PyObject *self)
16190 + xfree (((membuf_object *) self)->buffer);
16191 + self->ob_type->tp_free (self);
16194 +/* Return a description of the Membuf object. */
16197 +mbpy_str (PyObject *self)
16199 + membuf_object *membuf_obj = (membuf_object *) self;
16201 + return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
16202 + paddress (membuf_obj->addr),
16203 + pulongest (membuf_obj->length));
16207 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
16209 + membuf_object *membuf_obj = (membuf_object *) self;
16213 + PyErr_SetString (PyExc_SystemError,
16214 + "The memory buffer supports only one segment.");
16218 + *ptrptr = membuf_obj->buffer;
16220 + return membuf_obj->length;
16224 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
16226 + return get_read_buffer (self, segment, ptrptr);
16230 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
16233 + *lenp = ((membuf_object *) self)->length;
16239 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
16241 + void *ptr = NULL;
16244 + ret = get_read_buffer (self, segment, &ptr);
16245 + *ptrptr = (char *) ptr;
16250 +/* Python doesn't provide a decent way to get compatibility here. */
16251 +#if HAVE_LIBPYTHON2_4
16252 +#define CHARBUFFERPROC_NAME getcharbufferproc
16254 +#define CHARBUFFERPROC_NAME charbufferproc
16257 +static PyBufferProcs buffer_procs = {
16259 + get_write_buffer,
16261 + /* The cast here works around a difference between Python 2.4 and
16263 + (CHARBUFFERPROC_NAME) get_char_buffer
16266 +static PyTypeObject membuf_object_type = {
16267 + PyObject_HEAD_INIT (NULL)
16269 + "gdb.Membuf", /*tp_name*/
16270 + sizeof (membuf_object), /*tp_basicsize*/
16271 + 0, /*tp_itemsize*/
16272 + mbpy_dealloc, /*tp_dealloc*/
16274 + 0, /*tp_getattr*/
16275 + 0, /*tp_setattr*/
16276 + 0, /*tp_compare*/
16278 + 0, /*tp_as_number*/
16279 + 0, /*tp_as_sequence*/
16280 + 0, /*tp_as_mapping*/
16283 + mbpy_str, /*tp_str*/
16284 + 0, /*tp_getattro*/
16285 + 0, /*tp_setattro*/
16286 + &buffer_procs, /*tp_as_buffer*/
16287 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
16288 + "GDB memory buffer object", /*tp_doc*/
16289 + 0, /* tp_traverse */
16290 + 0, /* tp_clear */
16291 + 0, /* tp_richcompare */
16292 + 0, /* tp_weaklistoffset */
16294 + 0, /* tp_iternext */
16295 + 0, /* tp_methods */
16296 + 0, /* tp_members */
16297 + 0, /* tp_getset */
16300 + 0, /* tp_descr_get */
16301 + 0, /* tp_descr_set */
16302 + 0, /* tp_dictoffset */
16304 + 0, /* tp_alloc */
16305 + PyType_GenericNew /* tp_new */
16309 +gdbpy_initialize_membuf (void)
16311 + if (PyType_Ready (&membuf_object_type) < 0)
16314 + Py_INCREF (&membuf_object_type);
16315 + PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
16317 diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
16318 new file mode 100644
16319 index 0000000..1f591a8
16321 +++ b/gdb/python/py-param.c
16323 +/* gdb parameters implemented in Python
16325 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16327 + This file is part of GDB.
16329 + This program is free software; you can redistribute it and/or modify
16330 + it under the terms of the GNU General Public License as published by
16331 + the Free Software Foundation; either version 3 of the License, or
16332 + (at your option) any later version.
16334 + This program is distributed in the hope that it will be useful,
16335 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16336 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16337 + GNU General Public License for more details.
16339 + You should have received a copy of the GNU General Public License
16340 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
16344 +#include "value.h"
16345 +#include "exceptions.h"
16346 +#include "python-internal.h"
16347 +#include "charset.h"
16348 +#include "gdbcmd.h"
16349 +#include "cli/cli-decode.h"
16350 +#include "completer.h"
16352 +/* Parameter constants and their values. */
16353 +struct parm_constant
16359 +struct parm_constant parm_constants[] =
16361 + { "PARAM_BOOLEAN", var_boolean },
16362 + { "PARAM_AUTO_BOOLEAN", var_auto_boolean },
16363 + { "PARAM_UINTEGER", var_uinteger },
16364 + { "PARAM_INTEGER", var_integer },
16365 + { "PARAM_STRING", var_string },
16366 + { "PARAM_STRING_NOESCAPE", var_string_noescape },
16367 + { "PARAM_OPTIONAL_FILENAME", var_optional_filename },
16368 + { "PARAM_FILENAME", var_filename },
16369 + { "PARAM_ZINTEGER", var_zinteger },
16370 + { "PARAM_ENUM", var_enum },
16374 +/* A union that can hold anything described by enum var_types. */
16375 +union parmpy_variable
16377 + /* Hold an integer value, for boolean and integer types. */
16380 + /* Hold an auto_boolean. */
16381 + enum auto_boolean autoboolval;
16383 + /* Hold an unsigned integer value, for uinteger. */
16384 + unsigned int uintval;
16386 + /* Hold a string, for the various string types. */
16389 + /* Hold a string, for enums. */
16390 + const char *cstringval;
16393 +/* A gdb parameter. */
16394 +struct parmpy_object
16398 + /* The type of the parameter. */
16399 + enum var_types type;
16401 + /* The value of the parameter. */
16402 + union parmpy_variable value;
16404 + /* For an enum command, the possible values. The vector is
16405 + allocated with xmalloc, as is each element. It is
16406 + NULL-terminated. */
16407 + const char **enumeration;
16410 +typedef struct parmpy_object parmpy_object;
16412 +static PyTypeObject parmpy_object_type;
16414 +/* Some handy string constants. */
16415 +static PyObject *set_doc_cst;
16416 +static PyObject *show_doc_cst;
16420 +/* Get an attribute. */
16422 +get_attr (PyObject *obj, PyObject *attr_name)
16424 + if (PyString_Check (attr_name)
16425 + && ! strcmp (PyString_AsString (attr_name), "value"))
16427 + parmpy_object *self = (parmpy_object *) obj;
16428 + return gdbpy_parameter_value (self->type, &self->value);
16431 + return PyObject_GenericGetAttr (obj, attr_name);
16434 +/* Set a parameter value from a Python value. Return 0 on success, -1
16437 +set_parameter_value (parmpy_object *self, PyObject *value)
16441 + switch (self->type)
16444 + case var_string_noescape:
16445 + case var_optional_filename:
16446 + case var_filename:
16447 + if (! gdbpy_is_string (value)
16448 + && (self->type == var_filename
16449 + || value != Py_None))
16451 + PyErr_SetString (PyExc_RuntimeError, "string required");
16454 + if (self->value.stringval)
16455 + xfree (self->value.stringval);
16456 + if (value == Py_None)
16458 + if (self->type == var_optional_filename)
16459 + self->value.stringval = xstrdup ("");
16461 + self->value.stringval = NULL;
16464 + self->value.stringval = python_string_to_host_string (value);
16472 + if (! gdbpy_is_string (value))
16474 + PyErr_SetString (PyExc_RuntimeError, "string required");
16478 + str = python_string_to_host_string (value);
16479 + for (i = 0; self->enumeration[i]; ++i)
16480 + if (! strcmp (self->enumeration[i], str))
16483 + if (! self->enumeration[i])
16485 + PyErr_SetString (PyExc_RuntimeError,
16486 + "value must be member of enumeration");
16489 + self->value.cstringval = self->enumeration[i];
16493 + case var_boolean:
16494 + if (! PyBool_Check (value))
16496 + PyErr_SetString (PyExc_RuntimeError, "boolean required");
16499 + cmp = PyObject_IsTrue (value);
16502 + self->value.intval = cmp;
16505 + case var_auto_boolean:
16506 + if (! PyBool_Check (value) && value != Py_None)
16508 + PyErr_SetString (PyExc_RuntimeError,
16509 + "boolean or None required");
16513 + if (value == Py_None)
16514 + self->value.autoboolval = AUTO_BOOLEAN_AUTO;
16517 + cmp = PyObject_IsTrue (value);
16521 + self->value.autoboolval = AUTO_BOOLEAN_TRUE;
16523 + self->value.autoboolval = AUTO_BOOLEAN_FALSE;
16528 + case var_integer:
16529 + case var_zinteger:
16530 + case var_uinteger:
16535 + if (! PyInt_Check (value))
16537 + PyErr_SetString (PyExc_RuntimeError, "value must be integer");
16541 + l = PyInt_AsLong (value);
16542 + if (self->type == var_uinteger)
16544 + ok = (l >= 0 && l <= UINT_MAX);
16548 + else if (self->type == var_integer)
16550 + ok = (l >= INT_MIN && l <= INT_MAX);
16555 + ok = (l >= INT_MIN && l <= INT_MAX);
16559 + PyErr_SetString (PyExc_RuntimeError, "range exceeded");
16563 + self->value.intval = (int) l;
16568 + PyErr_SetString (PyExc_RuntimeError, "programmer error: unhandled type");
16575 +/* Set an attribute. */
16577 +set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
16579 + if (PyString_Check (attr_name)
16580 + && ! strcmp (PyString_AsString (attr_name), "value"))
16584 + PyErr_SetString (PyExc_RuntimeError,
16585 + "cannot delete a parameter's value");
16588 + return set_parameter_value ((parmpy_object *) obj, val);
16591 + return PyObject_GenericSetAttr (obj, attr_name, val);
16596 +/* A helper function that dispatches to the appropriate add_setshow
16599 +add_setshow_generic (int parmclass, enum command_class cmdclass,
16600 + char *cmd_name, parmpy_object *self,
16601 + char *set_doc, char *show_doc, char *help_doc,
16602 + struct cmd_list_element **set_list,
16603 + struct cmd_list_element **show_list)
16605 + switch (parmclass)
16607 + case var_boolean:
16608 + add_setshow_boolean_cmd (cmd_name, cmdclass, &self->value.intval,
16609 + set_doc, show_doc, help_doc,
16610 + NULL, NULL, set_list, show_list);
16613 + case var_auto_boolean:
16614 + add_setshow_auto_boolean_cmd (cmd_name, cmdclass,
16615 + &self->value.autoboolval,
16616 + set_doc, show_doc, help_doc,
16617 + NULL, NULL, set_list, show_list);
16620 + case var_uinteger:
16621 + add_setshow_uinteger_cmd (cmd_name, cmdclass, &self->value.uintval,
16622 + set_doc, show_doc, help_doc,
16623 + NULL, NULL, set_list, show_list);
16626 + case var_integer:
16627 + add_setshow_integer_cmd (cmd_name, cmdclass, &self->value.intval,
16628 + set_doc, show_doc, help_doc,
16629 + NULL, NULL, set_list, show_list);
16633 + add_setshow_string_cmd (cmd_name, cmdclass, &self->value.stringval,
16634 + set_doc, show_doc, help_doc,
16635 + NULL, NULL, set_list, show_list);
16638 + case var_string_noescape:
16639 + add_setshow_string_noescape_cmd (cmd_name, cmdclass,
16640 + &self->value.stringval,
16641 + set_doc, show_doc, help_doc,
16642 + NULL, NULL, set_list, show_list);
16645 + case var_optional_filename:
16646 + add_setshow_optional_filename_cmd (cmd_name, cmdclass,
16647 + &self->value.stringval,
16648 + set_doc, show_doc, help_doc,
16649 + NULL, NULL, set_list, show_list);
16652 + case var_filename:
16653 + add_setshow_filename_cmd (cmd_name, cmdclass, &self->value.stringval,
16654 + set_doc, show_doc, help_doc,
16655 + NULL, NULL, set_list, show_list);
16658 + case var_zinteger:
16659 + add_setshow_zinteger_cmd (cmd_name, cmdclass, &self->value.intval,
16660 + set_doc, show_doc, help_doc,
16661 + NULL, NULL, set_list, show_list);
16665 + add_setshow_enum_cmd (cmd_name, cmdclass, self->enumeration,
16666 + &self->value.cstringval,
16667 + set_doc, show_doc, help_doc,
16668 + NULL, NULL, set_list, show_list);
16669 + /* Initialize the value, just in case. */
16670 + self->value.cstringval = self->enumeration[0];
16675 +/* A helper which computes enum values. Returns 1 on success, 0 on
16678 +compute_enum_values (parmpy_object *self, PyObject *enum_values)
16680 + Py_ssize_t size, i;
16682 + if (! enum_values)
16684 + PyErr_SetString (PyExc_RuntimeError,
16685 + "enumeration required for PARAM_ENUM");
16689 + if (! PySequence_Check (enum_values))
16691 + PyErr_SetString (PyExc_RuntimeError, "enumeration is not a sequence");
16695 + size = PySequence_Size (enum_values);
16700 + PyErr_SetString (PyExc_RuntimeError, "empty enumeration");
16704 + self->enumeration = xmalloc ((size + 1) * sizeof (char *));
16705 + memset (self->enumeration, 0, (size + 1) * sizeof (char *));
16707 + for (i = 0; i < size; ++i)
16709 + PyObject *item = PySequence_GetItem (enum_values, i);
16712 + if (! gdbpy_is_string (item))
16714 + PyErr_SetString (PyExc_RuntimeError, "enumeration item not a string");
16717 + self->enumeration[i] = python_string_to_host_string (item);
16723 +/* A helper function which returns a documentation string for an
16726 +get_doc_string (PyObject *object, PyObject *attr)
16728 + char *result = NULL;
16729 + if (PyObject_HasAttr (object, attr))
16731 + PyObject *ds_obj = PyObject_GetAttr (object, attr);
16732 + if (ds_obj && gdbpy_is_string (ds_obj))
16733 + result = python_string_to_host_string (ds_obj);
16736 + result = xstrdup ("This command is not documented.");
16740 +/* Object initializer; sets up gdb-side structures for command.
16742 + Use: __init__(NAME, CMDCLASS, PARMCLASS, [ENUM])
16744 + NAME is the name of the parameter. It may consist of multiple
16745 + words, in which case the final word is the name of the new command,
16746 + and earlier words must be prefix commands.
16748 + CMDCLASS is the kind of command. It should be one of the COMMAND_*
16749 + constants defined in the gdb module.
16751 + PARMCLASS is the type of the parameter. It should be one of the
16752 + PARAM_* constants defined in the gdb module.
16754 + If PARMCLASS is PARAM_ENUM, then the final argument should be a
16755 + collection of strings. These strings are the valid values for this
16758 + The documentation for the parameter is taken from the doc string
16759 + for the python class.
16763 +parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
16765 + parmpy_object *obj = (parmpy_object *) self;
16767 + char *set_doc, *show_doc, *doc;
16769 + int parmclass, cmdtype;
16770 + PyObject *enum_values = NULL;
16771 + struct cmd_list_element *cmd_list;
16772 + struct cmd_list_element **set_list, **show_list;
16773 + volatile struct gdb_exception except;
16775 + if (! PyArg_ParseTuple (args, "sii|O", &name, &cmdtype, &parmclass,
16779 + if (cmdtype != no_class && cmdtype != class_run
16780 + && cmdtype != class_vars && cmdtype != class_stack
16781 + && cmdtype != class_files && cmdtype != class_support
16782 + && cmdtype != class_info && cmdtype != class_breakpoint
16783 + && cmdtype != class_trace && cmdtype != class_obscure
16784 + && cmdtype != class_maintenance)
16786 + PyErr_Format (PyExc_RuntimeError, "invalid command class argument");
16790 + if (parmclass != var_boolean && parmclass != var_auto_boolean
16791 + && parmclass != var_uinteger && parmclass != var_integer
16792 + && parmclass != var_string && parmclass != var_string_noescape
16793 + && parmclass != var_optional_filename && parmclass != var_filename
16794 + && parmclass != var_zinteger && parmclass != var_enum)
16796 + PyErr_SetString (PyExc_RuntimeError, "invalid parameter class argument");
16800 + if (enum_values && parmclass != var_enum)
16802 + PyErr_SetString (PyExc_RuntimeError,
16803 + "only PARAM_ENUM accepts a fourth argument");
16806 + if (parmclass == var_enum)
16808 + if (! compute_enum_values (obj, enum_values))
16812 + obj->type = (enum var_types) parmclass;
16813 + memset (&obj->value, 0, sizeof (obj->value));
16814 + obj->enumeration = NULL;
16816 + cmd_name = gdbpy_parse_command_name (name, &set_list, &setlist);
16819 + xfree (cmd_name);
16820 + cmd_name = gdbpy_parse_command_name (name, &show_list, &showlist);
16824 + /* FIXME: there is no way to register a destructor function for
16825 + set/show commands. So, these are leaked. */
16826 + set_doc = get_doc_string (self, set_doc_cst);
16827 + show_doc = get_doc_string (self, show_doc_cst);
16828 + doc = get_doc_string (self, gdbpy_doc_cst);
16830 + Py_INCREF (self);
16832 + TRY_CATCH (except, RETURN_MASK_ALL)
16834 + add_setshow_generic (parmclass, (enum command_class) cmdtype,
16836 + set_doc, show_doc,
16837 + doc, set_list, show_list);
16839 + if (except.reason < 0)
16841 + xfree (cmd_name);
16843 + xfree (show_doc);
16845 + Py_DECREF (self);
16846 + PyErr_Format (except.reason == RETURN_QUIT
16847 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError,
16848 + "%s", except.message);
16856 +/* Initialize the 'parameters' module. */
16858 +gdbpy_initialize_parameters (void)
16862 + if (PyType_Ready (&parmpy_object_type) < 0)
16865 + set_doc_cst = PyString_FromString ("set_doc");
16866 + if (! set_doc_cst)
16868 + show_doc_cst = PyString_FromString ("show_doc");
16869 + if (! show_doc_cst)
16872 + for (i = 0; parm_constants[i].name; ++i)
16874 + if (PyModule_AddIntConstant (gdb_module,
16875 + parm_constants[i].name,
16876 + parm_constants[i].value) < 0)
16880 + Py_INCREF (&parmpy_object_type);
16881 + PyModule_AddObject (gdb_module, "Parameter",
16882 + (PyObject *) &parmpy_object_type);
16887 +static PyTypeObject parmpy_object_type =
16889 + PyObject_HEAD_INIT (NULL)
16891 + "gdb.Parameter", /*tp_name*/
16892 + sizeof (parmpy_object), /*tp_basicsize*/
16893 + 0, /*tp_itemsize*/
16894 + 0, /*tp_dealloc*/
16896 + 0, /*tp_getattr*/
16897 + 0, /*tp_setattr*/
16898 + 0, /*tp_compare*/
16900 + 0, /*tp_as_number*/
16901 + 0, /*tp_as_sequence*/
16902 + 0, /*tp_as_mapping*/
16906 + get_attr, /*tp_getattro*/
16907 + set_attr, /*tp_setattro*/
16908 + 0, /*tp_as_buffer*/
16909 + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
16910 + "GDB parameter object", /* tp_doc */
16911 + 0, /* tp_traverse */
16912 + 0, /* tp_clear */
16913 + 0, /* tp_richcompare */
16914 + 0, /* tp_weaklistoffset */
16916 + 0, /* tp_iternext */
16917 + 0, /* tp_methods */
16918 + 0, /* tp_members */
16919 + 0, /* tp_getset */
16922 + 0, /* tp_descr_get */
16923 + 0, /* tp_descr_set */
16924 + 0, /* tp_dictoffset */
16925 + parmpy_init, /* tp_init */
16926 + 0, /* tp_alloc */
16927 + PyType_GenericNew /* tp_new */
16929 diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
16930 index 5d696c8..a6348ba 100644
16931 --- a/gdb/python/py-prettyprint.c
16932 +++ b/gdb/python/py-prettyprint.c
16933 @@ -121,6 +121,7 @@ find_pretty_printer (PyObject *value)
16938 /* Pretty-print a single value, via the printer object PRINTER.
16939 If the function returns a string, a PyObject containing the string
16940 is returned. Otherwise, if the function returns a value,
16941 @@ -141,10 +142,15 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
16942 if (! gdbpy_is_string (result))
16944 *out_value = convert_value_from_python (result);
16945 - if (PyErr_Occurred ())
16946 - *out_value = NULL;
16947 - Py_DECREF (result);
16949 + if (PyErr_Occurred ())
16950 + *out_value = NULL;
16952 + /* We must increment the value's refcount, because we
16953 + are about to decref RESULT, and this may result in
16954 + the value being destroyed. */
16955 + value_incref (*out_value);
16956 + Py_DECREF (result);
16961 @@ -556,14 +562,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
16964 PyObject *pretty_printer = NULL;
16965 - volatile struct gdb_exception except;
16967 - TRY_CATCH (except, RETURN_MASK_ALL)
16969 - value = value_copy (value);
16971 - GDB_PY_HANDLE_EXCEPTION (except);
16973 val_obj = value_to_value_object (value);
16976 diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
16977 new file mode 100644
16978 index 0000000..03d43c1
16980 +++ b/gdb/python/py-symbol.c
16982 +/* Python interface to symbols.
16984 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
16986 + This file is part of GDB.
16988 + This program is free software; you can redistribute it and/or modify
16989 + it under the terms of the GNU General Public License as published by
16990 + the Free Software Foundation; either version 3 of the License, or
16991 + (at your option) any later version.
16993 + This program is distributed in the hope that it will be useful,
16994 + but WITHOUT ANY WARRANTY; without even the implied warranty of
16995 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16996 + GNU General Public License for more details.
16998 + You should have received a copy of the GNU General Public License
16999 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
17002 +#include "block.h"
17003 +#include "exceptions.h"
17004 +#include "frame.h"
17005 +#include "symtab.h"
17006 +#include "python-internal.h"
17010 + struct symbol *symbol;
17015 +sympy_str (PyObject *self)
17019 + PyObject *result;
17021 + ret = asprintf (&s, "symbol for %s",
17022 + SYMBOL_PRINT_NAME (((symbol_object *) self)->symbol));
17026 + result = PyString_FromString (s);
17033 +sympy_get_value (PyObject *self, void *closure)
17035 + symbol_object *self_sym = (symbol_object *) self;
17037 + switch (SYMBOL_CLASS (self_sym->symbol))
17040 + return block_to_block_object (SYMBOL_BLOCK_VALUE (self_sym->symbol));
17043 + PyErr_SetString (PyExc_NotImplementedError,
17044 + "Symbol type not yet supported in Python scripts.");
17049 +sympy_get_symtab (PyObject *self, void *closure)
17051 + symbol_object *self_sym = (symbol_object *) self;
17053 + return symtab_to_symtab_object (SYMBOL_SYMTAB (self_sym->symbol));
17057 +sympy_get_name (PyObject *self, void *closure)
17059 + symbol_object *self_sym = (symbol_object *) self;
17061 + return PyString_FromString (SYMBOL_NATURAL_NAME (self_sym->symbol));
17065 +sympy_get_linkage_name (PyObject *self, void *closure)
17067 + symbol_object *self_sym = (symbol_object *) self;
17069 + return PyString_FromString (SYMBOL_LINKAGE_NAME (self_sym->symbol));
17073 +sympy_get_print_name (PyObject *self, void *closure)
17075 + symbol_object *self_sym = (symbol_object *) self;
17077 + return PyString_FromString (SYMBOL_PRINT_NAME (self_sym->symbol));
17081 +sympy_get_addr_class (PyObject *self, void *closure)
17083 + symbol_object *self_sym = (symbol_object *) self;
17085 + return PyInt_FromLong (SYMBOL_CLASS (self_sym->symbol));
17089 +sympy_is_argument (PyObject *self, void *closure)
17091 + symbol_object *self_sym = (symbol_object *) self;
17093 + return PyBool_FromLong (SYMBOL_IS_ARGUMENT (self_sym->symbol));
17097 +sympy_is_constant (PyObject *self, void *closure)
17099 + symbol_object *self_sym = (symbol_object *) self;
17100 + enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17102 + return PyBool_FromLong (class == LOC_CONST || class == LOC_CONST_BYTES);
17106 +sympy_is_function (PyObject *self, void *closure)
17108 + symbol_object *self_sym = (symbol_object *) self;
17109 + enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17111 + return PyBool_FromLong (class == LOC_BLOCK);
17115 +sympy_is_variable (PyObject *self, void *closure)
17117 + symbol_object *self_sym = (symbol_object *) self;
17118 + enum address_class class = SYMBOL_CLASS (self_sym->symbol);
17120 + return PyBool_FromLong (!SYMBOL_IS_ARGUMENT (self_sym->symbol)
17121 + && (class == LOC_LOCAL || class == LOC_REGISTER || class == LOC_STATIC
17122 + || class == LOC_COMPUTED || class == LOC_OPTIMIZED_OUT));
17126 +symbol_to_symbol_object (struct symbol *sym)
17128 + symbol_object *sym_obj;
17130 + sym_obj = PyObject_New (symbol_object, &symbol_object_type);
17131 + if (sym_obj == NULL)
17133 + PyErr_SetString (PyExc_MemoryError, "Could not allocate symbol object.");
17137 + sym_obj->symbol = sym;
17139 + return (PyObject *) sym_obj;
17143 +symbol_object_to_symbol (PyObject *obj)
17145 + if (! PyObject_TypeCheck (obj, &symbol_object_type))
17147 + return ((symbol_object *) obj)->symbol;
17150 +/* Implementation of
17151 + gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)
17152 + A tuple with 2 elements is always returned. The first is the symbol
17153 + object or None, the second is a boolean with the value of
17154 + is_a_field_of_this (see comment in lookup_symbol_in_language). */
17156 +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
17158 + int domain = VAR_DOMAIN, is_a_field_of_this = 0;
17159 + const char *name;
17160 + static char *keywords[] = { "name", "block", "domain", NULL };
17161 + struct symbol *symbol;
17162 + PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
17163 + struct block *block = NULL;
17165 + if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
17166 + &block_object_type, &block_obj, &domain))
17170 + block = block_object_to_block (block_obj);
17173 + struct frame_info *selected_frame;
17174 + volatile struct gdb_exception except;
17176 + TRY_CATCH (except, RETURN_MASK_ALL)
17178 + selected_frame = get_selected_frame (_("No frame selected."));
17179 + block = block_for_pc (get_frame_address_in_block (selected_frame));
17181 + GDB_PY_HANDLE_EXCEPTION (except);
17184 + symbol = lookup_symbol (name, block, domain, &is_a_field_of_this);
17186 + ret_tuple = PyTuple_New (2);
17189 + PyErr_SetString (PyExc_MemoryError, "Could not allocate tuple object.");
17195 + sym_obj = symbol_to_symbol_object (symbol);
17198 + Py_DECREF (ret_tuple);
17204 + sym_obj = Py_None;
17205 + Py_INCREF (Py_None);
17207 + PyTuple_SET_ITEM (ret_tuple, 0, sym_obj);
17209 + bool_obj = is_a_field_of_this? Py_True : Py_False;
17210 + Py_INCREF (bool_obj);
17211 + PyTuple_SET_ITEM (ret_tuple, 1, bool_obj);
17213 + return ret_tuple;
17217 +gdbpy_initialize_symbols (void)
17219 + if (PyType_Ready (&symbol_object_type) < 0)
17222 + /* FIXME: These would probably be best exposed as class attributes of Symbol,
17223 + but I don't know how to do it except by messing with the type's dictionary.
17224 + That seems too messy. */
17225 + /* FIXME 2: Some of these were removed from GDB since I first wrote this code,
17226 + so it's probably a good idea not to expose them to Python. */
17227 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
17228 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
17229 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
17230 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
17231 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
17232 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
17233 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
17234 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
17235 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
17236 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
17237 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
17238 + LOC_CONST_BYTES);
17239 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED", LOC_UNRESOLVED);
17240 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
17241 + LOC_OPTIMIZED_OUT);
17242 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
17243 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
17244 + LOC_REGPARM_ADDR);
17245 + PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
17246 + PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
17247 + PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
17248 + PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
17249 + PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
17250 + VARIABLES_DOMAIN);
17251 + PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
17252 + FUNCTIONS_DOMAIN);
17253 + PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
17255 + Py_INCREF (&symbol_object_type);
17256 + PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
17261 +static PyGetSetDef symbol_object_getset[] = {
17262 + { "value", sympy_get_value, NULL, "Value of the symbol.", NULL },
17263 + { "symtab", sympy_get_symtab, NULL,
17264 + "Symbol table in which the symbol appears.", NULL },
17265 + { "name", sympy_get_name, NULL,
17266 + "Name of the symbol, as it appears in the source code.", NULL },
17267 + { "linkage_name", sympy_get_linkage_name, NULL,
17268 + "Name of the symbol, as used by the linker (i.e., may be mangled).", NULL },
17269 + { "print_name", sympy_get_print_name, NULL,
17270 + "Name of the symbol in a form suitable for output.\n\
17271 +This is either name or linkage_name, depending on whether the user asked GDB\n\
17272 +to display demangled or mangled names.", NULL },
17273 + { "addr_class", sympy_get_addr_class, NULL, "Address class of the symbol." },
17274 + { "is_argument", sympy_is_argument, NULL,
17275 + "True if the symbol is an argument of a function." },
17276 + { "is_constant", sympy_is_constant, NULL,
17277 + "True if the symbol is a constant." },
17278 + { "is_function", sympy_is_function, NULL,
17279 + "True if the symbol is a function or method." },
17280 + { "is_variable", sympy_is_variable, NULL,
17281 + "True if the symbol is a variable." },
17282 + { NULL } /* Sentinel */
17285 +PyTypeObject symbol_object_type = {
17286 + PyObject_HEAD_INIT (NULL)
17288 + "gdb.Symbol", /*tp_name*/
17289 + sizeof (symbol_object), /*tp_basicsize*/
17290 + 0, /*tp_itemsize*/
17291 + 0, /*tp_dealloc*/
17293 + 0, /*tp_getattr*/
17294 + 0, /*tp_setattr*/
17295 + 0, /*tp_compare*/
17297 + 0, /*tp_as_number*/
17298 + 0, /*tp_as_sequence*/
17299 + 0, /*tp_as_mapping*/
17302 + sympy_str, /*tp_str*/
17303 + 0, /*tp_getattro*/
17304 + 0, /*tp_setattro*/
17305 + 0, /*tp_as_buffer*/
17306 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
17307 + "GDB symbol object", /* tp_doc */
17308 + 0, /* tp_traverse */
17309 + 0, /* tp_clear */
17310 + 0, /* tp_richcompare */
17311 + 0, /* tp_weaklistoffset */
17313 + 0, /* tp_iternext */
17314 + 0, /* tp_methods */
17315 + 0, /* tp_members */
17316 + symbol_object_getset /* tp_getset */
17318 diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
17319 new file mode 100644
17320 index 0000000..830e586
17322 +++ b/gdb/python/py-symtab.c
17324 +/* Python interface to symbol tables.
17326 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
17328 + This file is part of GDB.
17330 + This program is free software; you can redistribute it and/or modify
17331 + it under the terms of the GNU General Public License as published by
17332 + the Free Software Foundation; either version 3 of the License, or
17333 + (at your option) any later version.
17335 + This program is distributed in the hope that it will be useful,
17336 + but WITHOUT ANY WARRANTY; without even the implied warranty of
17337 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17338 + GNU General Public License for more details.
17340 + You should have received a copy of the GNU General Public License
17341 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
17344 +#include "charset.h"
17345 +#include "symtab.h"
17346 +#include "source.h"
17347 +#include "python-internal.h"
17351 + struct symtab *symtab;
17354 +static PyTypeObject symtab_object_type;
17358 + symtab_object *symtab;
17359 + struct symtab_and_line *sal;
17362 +static PyTypeObject sal_object_type;
17366 +stpy_str (PyObject *self)
17370 + PyObject *result;
17372 + ret = asprintf (&s, "symbol table for %s",
17373 + ((symtab_object *) self)->symtab->filename);
17377 + result = PyString_FromString (s);
17384 +stpy_get_filename (PyObject *self, void *closure)
17386 + symtab_object *self_symtab = (symtab_object *) self;
17387 + PyObject *str_obj;
17389 + /* FIXME: Can symtab->filename really be NULL? */
17390 + if (self_symtab->symtab->filename)
17391 + str_obj = PyString_Decode (self_symtab->symtab->filename,
17392 + strlen (self_symtab->symtab->filename),
17393 + host_charset (), NULL);
17396 + str_obj = Py_None;
17397 + Py_INCREF (Py_None);
17404 +stpy_get_objfile (PyObject *self, void *closure)
17406 + symtab_object *self_symtab = (symtab_object *) self;
17407 + PyObject *result = objfile_to_objfile_object (self_symtab->symtab->objfile);
17408 + Py_INCREF (result);
17413 +stpy_fullname (PyObject *self, PyObject *args)
17417 + fullname = symtab_to_fullname (((symtab_object *) self)->symtab);
17419 + return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
17425 +salpy_str (PyObject *self)
17428 + char *s, *filename;
17429 + sal_object *sal_obj;
17430 + PyObject *result;
17432 + sal_obj = (sal_object *) self;
17433 + filename = (sal_obj->symtab == (symtab_object *) Py_None)? "<unknown>" :
17434 + sal_obj->symtab->symtab->filename;
17435 + ret = asprintf (&s, "symbol and line for %s, line %d", filename,
17436 + sal_obj->sal->line);
17440 + result = PyString_FromString (s);
17447 +salpy_get_pc (PyObject *self, void *closure)
17449 + return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->pc);
17453 +salpy_get_line (PyObject *self, void *closure)
17455 + return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->line);
17459 +salpy_get_symtab (PyObject *self, void *closure)
17461 + sal_object *self_sal = (sal_object *) self;
17463 + Py_INCREF (self_sal->symtab);
17465 + return (PyObject *) self_sal->symtab;
17469 +salpy_dealloc (PyObject *self)
17471 + sal_object *self_sal = (sal_object *) self;
17473 + Py_DECREF (self_sal->symtab);
17474 + xfree (self_sal->sal);
17475 + self_sal->ob_type->tp_free (self);
17479 +symtab_and_line_to_sal_object (struct symtab_and_line sal)
17481 + sal_object *sal_obj;
17482 + symtab_object *symtab_obj;
17484 + sal_obj = PyObject_New (sal_object, &sal_object_type);
17485 + if (sal_obj == NULL)
17487 + PyErr_SetString (PyExc_MemoryError,
17488 + "Could not allocate Symtab_and_line object.");
17494 + symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab);
17495 + if (symtab_obj == NULL)
17497 + Py_DECREF (sal_obj);
17501 + symtab_obj->symtab = sal.symtab;
17505 + symtab_obj = (symtab_object *) Py_None;
17506 + Py_INCREF (Py_None);
17509 + sal_obj->sal = (struct symtab_and_line *)
17510 + xmalloc (sizeof (struct symtab_and_line));
17511 + *(sal_obj->sal) = sal;
17512 + sal_obj->symtab = symtab_obj;
17514 + return (PyObject *) sal_obj;
17518 +symtab_to_symtab_object (struct symtab *symtab)
17520 + symtab_object *symtab_obj;
17522 + symtab_obj = PyObject_New (symtab_object, &symtab_object_type);
17523 + if (symtab_obj == NULL)
17525 + PyErr_SetString (PyExc_MemoryError,
17526 + "Could not allocate Symtab object.");
17531 + symtab_obj->symtab = symtab;
17533 + return (PyObject *) symtab_obj;
17537 +gdbpy_initialize_symtabs (void)
17539 + symtab_object_type.tp_new = PyType_GenericNew;
17540 + if (PyType_Ready (&symtab_object_type) < 0)
17543 + sal_object_type.tp_new = PyType_GenericNew;
17544 + if (PyType_Ready (&sal_object_type) < 0)
17547 + Py_INCREF (&symtab_object_type);
17548 + PyModule_AddObject (gdb_module, "Symtab", (PyObject *) &symtab_object_type);
17550 + Py_INCREF (&sal_object_type);
17551 + PyModule_AddObject (gdb_module, "Symtab_and_line",
17552 + (PyObject *) &sal_object_type);
17557 +static PyGetSetDef symtab_object_getset[] = {
17558 + { "filename", stpy_get_filename, NULL,
17559 + "The symbol table's source filename.", NULL },
17560 + { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.",
17562 + {NULL} /* Sentinel */
17565 +static PyMethodDef symtab_object_methods[] = {
17566 + { "fullname", stpy_fullname, METH_NOARGS,
17567 + "Return the symtab's full source filename." },
17568 + {NULL} /* Sentinel */
17571 +static PyTypeObject symtab_object_type = {
17572 + PyObject_HEAD_INIT (NULL)
17574 + "gdb.Symtab", /*tp_name*/
17575 + sizeof (symtab_object), /*tp_basicsize*/
17576 + 0, /*tp_itemsize*/
17577 + 0, /*tp_dealloc*/
17579 + 0, /*tp_getattr*/
17580 + 0, /*tp_setattr*/
17581 + 0, /*tp_compare*/
17583 + 0, /*tp_as_number*/
17584 + 0, /*tp_as_sequence*/
17585 + 0, /*tp_as_mapping*/
17588 + stpy_str, /*tp_str*/
17589 + 0, /*tp_getattro*/
17590 + 0, /*tp_setattro*/
17591 + 0, /*tp_as_buffer*/
17592 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
17593 + "GDB symtab object", /* tp_doc */
17594 + 0, /* tp_traverse */
17595 + 0, /* tp_clear */
17596 + 0, /* tp_richcompare */
17597 + 0, /* tp_weaklistoffset */
17599 + 0, /* tp_iternext */
17600 + symtab_object_methods, /* tp_methods */
17601 + 0, /* tp_members */
17602 + symtab_object_getset /* tp_getset */
17605 +static PyGetSetDef sal_object_getset[] = {
17606 + { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
17607 + { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
17608 + { "line", salpy_get_line, NULL,
17609 + "Return the symtab_and_line's line.", NULL },
17610 + {NULL} /* Sentinel */
17613 +static PyTypeObject sal_object_type = {
17614 + PyObject_HEAD_INIT (NULL)
17616 + "gdb.Symtab_and_line", /*tp_name*/
17617 + sizeof (sal_object), /*tp_basicsize*/
17618 + 0, /*tp_itemsize*/
17619 + salpy_dealloc, /*tp_dealloc*/
17621 + 0, /*tp_getattr*/
17622 + 0, /*tp_setattr*/
17623 + 0, /*tp_compare*/
17625 + 0, /*tp_as_number*/
17626 + 0, /*tp_as_sequence*/
17627 + 0, /*tp_as_mapping*/
17630 + salpy_str, /*tp_str*/
17631 + 0, /*tp_getattro*/
17632 + 0, /*tp_setattro*/
17633 + 0, /*tp_as_buffer*/
17634 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
17635 + "GDB symtab_and_line object", /* tp_doc */
17636 + 0, /* tp_traverse */
17637 + 0, /* tp_clear */
17638 + 0, /* tp_richcompare */
17639 + 0, /* tp_weaklistoffset */
17641 + 0, /* tp_iternext */
17642 + 0, /* tp_methods */
17643 + 0, /* tp_members */
17644 + sal_object_getset /* tp_getset */
17646 diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
17647 index 590d90a..f512248 100644
17648 --- a/gdb/python/py-type.c
17649 +++ b/gdb/python/py-type.c
17651 #include "demangle.h"
17652 #include "objfiles.h"
17653 #include "language.h"
17654 +#include "observer.h"
17655 +#include "gdb_assert.h"
17657 typedef struct pyty_type_object
17659 @@ -35,11 +37,17 @@ typedef struct pyty_type_object
17661 /* If a Type object is associated with an objfile, it is kept on a
17662 doubly-linked list, rooted in the objfile. This lets us copy the
17663 - underlying struct type when the objfile is deleted. */
17664 + underlying struct type when the objfile is deleted.
17666 + With NULL objfile Type still can be doubly-linked in the list
17667 + PYTY_OBJECTS_DISCARDABLE. */
17668 struct pyty_type_object *prev;
17669 struct pyty_type_object *next;
17672 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types. */
17673 +static type_object *pyty_objects_discardable;
17675 static PyTypeObject type_object_type;
17677 /* A Field object. */
17678 @@ -169,6 +177,11 @@ convert_field (struct type *type, int field)
17679 if (PyObject_SetAttrString (result, "artificial", arg) < 0)
17682 + arg = field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False;
17684 + if (PyObject_SetAttrString (result, "is_base_class", arg) < 0)
17687 arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
17690 @@ -361,7 +374,7 @@ typy_get_sizeof (PyObject *self, void *closure)
17693 static struct type *
17694 -typy_lookup_typename (char *type_name)
17695 +typy_lookup_typename (char *type_name, struct block *block)
17697 struct type *type = NULL;
17698 volatile struct gdb_exception except;
17699 @@ -375,7 +388,7 @@ typy_lookup_typename (char *type_name)
17700 type = lookup_enum (type_name + 5, NULL);
17702 type = lookup_typename (python_language, python_gdbarch,
17703 - type_name, NULL, 0);
17704 + type_name, block, 0);
17706 if (except.reason < 0)
17708 @@ -389,7 +402,8 @@ typy_lookup_typename (char *type_name)
17711 static struct type *
17712 -typy_lookup_type (struct demangle_component *demangled)
17713 +typy_lookup_type (struct demangle_component *demangled,
17714 + struct block *block)
17718 @@ -404,7 +418,7 @@ typy_lookup_type (struct demangle_component *demangled)
17719 || demangled_type == DEMANGLE_COMPONENT_CONST
17720 || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
17722 - type = typy_lookup_type (demangled->u.s_binary.left);
17723 + type = typy_lookup_type (demangled->u.s_binary.left, block);
17727 @@ -422,7 +436,7 @@ typy_lookup_type (struct demangle_component *demangled)
17730 type_name = cp_comp_to_string (demangled, 10);
17731 - type = typy_lookup_typename (type_name);
17732 + type = typy_lookup_typename (type_name, block);
17736 @@ -436,10 +450,23 @@ typy_template_argument (PyObject *self, PyObject *args)
17737 struct demangle_component *demangled;
17739 struct type *argtype;
17740 + struct block *block = NULL;
17741 + PyObject *block_obj = NULL;
17743 - if (! PyArg_ParseTuple (args, "i", &argno))
17744 + if (! PyArg_ParseTuple (args, "i|O", &argno, &block_obj))
17749 + block = block_object_to_block (block_obj);
17752 + PyErr_SetString (PyExc_RuntimeError,
17753 + "second argument must be block");
17758 type = check_typedef (type);
17759 if (TYPE_CODE (type) == TYPE_CODE_REF)
17760 type = check_typedef (TYPE_TARGET_TYPE (type));
17761 @@ -482,7 +509,7 @@ typy_template_argument (PyObject *self, PyObject *args)
17765 - argtype = typy_lookup_type (demangled->u.s_binary.left);
17766 + argtype = typy_lookup_type (demangled->u.s_binary.left, block);
17770 @@ -524,8 +551,59 @@ typy_str (PyObject *self)
17774 +/* Key associated with each objfile pointing to the first element of
17775 + a doubly-linked list of Types associated with this objfile. */
17776 static const struct objfile_data *typy_objfile_data_key;
17778 +/* Link TYPE_OBJ to its appropriate list. Either to its objfile associated one
17779 + or at least to the global list for TYPE_DISCARDABLE Types. Permanent types
17780 + do not get linked anywhere. */
17782 +typy_link (type_object *type_obj)
17784 + type_obj->prev = NULL;
17786 + if (type_obj->type && TYPE_OBJFILE (type_obj->type))
17788 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
17790 + type_obj->next = objfile_data (objfile, typy_objfile_data_key);
17791 + if (type_obj->next)
17792 + type_obj->next->prev = type_obj;
17793 + set_objfile_data (objfile, typy_objfile_data_key, type_obj);
17795 + else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
17797 + type_obj->next = pyty_objects_discardable;
17798 + if (type_obj->next)
17799 + type_obj->next->prev = type_obj;
17800 + pyty_objects_discardable = type_obj;
17803 + type_obj->next = NULL;
17806 +/* Unlink TYPE_OBJ from its current list. Permanent types are not linked
17807 + anywhere and this function has no effect on them. */
17809 +typy_unlink (type_object *type_obj)
17811 + if (type_obj->prev)
17812 + type_obj->prev->next = type_obj->next;
17813 + else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
17815 + /* Must reset head of list. */
17816 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
17818 + set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
17820 + else if (pyty_objects_discardable == type_obj)
17821 + pyty_objects_discardable = type_obj->next;
17823 + if (type_obj->next)
17824 + type_obj->next->prev = type_obj->prev;
17828 save_objfile_types (struct objfile *objfile, void *datum)
17830 @@ -543,12 +621,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
17832 type_object *next = obj->next;
17834 - htab_empty (copied_types);
17835 + gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
17836 + typy_unlink (obj);
17838 - obj->type = copy_type_recursive (objfile, obj->type, copied_types);
17839 + obj->type = copy_type_recursive (obj->type, copied_types);
17841 - obj->next = NULL;
17842 - obj->prev = NULL;
17843 + gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
17848 @@ -559,41 +638,25 @@ save_objfile_types (struct objfile *objfile, void *datum)
17852 -set_type (type_object *obj, struct type *type)
17853 +typy_dealloc (PyObject *obj)
17855 - obj->type = type;
17856 - obj->prev = NULL;
17857 - if (type && TYPE_OBJFILE (type))
17859 - struct objfile *objfile = TYPE_OBJFILE (type);
17860 + type_object *type_obj = (type_object *) obj;
17862 - obj->next = objfile_data (objfile, typy_objfile_data_key);
17864 - obj->next->prev = obj;
17865 - set_objfile_data (objfile, typy_objfile_data_key, obj);
17868 - obj->next = NULL;
17869 + typy_unlink (type_obj);
17871 + type_obj->ob_type->tp_free (obj);
17874 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
17876 -typy_dealloc (PyObject *obj)
17877 +typy_types_mark_used (void)
17879 - type_object *type = (type_object *) obj;
17882 - type->prev->next = type->next;
17883 - else if (type->type && TYPE_OBJFILE (type->type))
17885 - /* Must reset head of list. */
17886 - struct objfile *objfile = TYPE_OBJFILE (type->type);
17888 - set_objfile_data (objfile, typy_objfile_data_key, type->next);
17891 - type->next->prev = type->prev;
17892 + type_object *type_obj;
17894 - type->ob_type->tp_free (type);
17895 + for (type_obj = pyty_objects_discardable;
17896 + type_obj != NULL;
17897 + type_obj = type_obj->next)
17898 + type_mark_used (type_obj->type);
17901 /* Create a new Type referring to TYPE. */
17902 @@ -604,7 +667,10 @@ type_to_type_object (struct type *type)
17904 type_obj = PyObject_New (type_object, &type_object_type);
17906 - set_type (type_obj, type);
17908 + type_obj->type = type;
17909 + typy_link (type_obj);
17912 return (PyObject *) type_obj;
17914 @@ -623,14 +689,28 @@ type_object_to_type (PyObject *obj)
17916 gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
17918 - static char *keywords[] = { "name", NULL };
17919 + static char *keywords[] = { "name", "block", NULL };
17920 char *type_name = NULL;
17921 struct type *type = NULL;
17922 + PyObject *block_obj = NULL;
17923 + struct block *block = NULL;
17925 - if (! PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &type_name))
17926 + if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O", keywords,
17927 + &type_name, &block_obj))
17930 - type = typy_lookup_typename (type_name);
17933 + block = block_object_to_block (block_obj);
17936 + PyErr_SetString (PyExc_RuntimeError,
17937 + "'block' argument must be a Block");
17942 + type = typy_lookup_typename (type_name, block);
17946 @@ -664,6 +744,8 @@ gdbpy_initialize_types (void)
17948 Py_INCREF (&field_object_type);
17949 PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
17951 + observer_attach_mark_used (typy_types_mark_used);
17955 diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
17956 index 49c0437..84a476e 100644
17957 --- a/gdb/python/py-utils.c
17958 +++ b/gdb/python/py-utils.c
17962 #include "charset.h"
17963 +#include "value.h"
17964 #include "python-internal.h"
17967 @@ -219,3 +220,48 @@ gdbpy_is_string (PyObject *obj)
17969 return PyString_Check (obj) || PyUnicode_Check (obj);
17972 +/* Converts OBJ to a CORE_ADDR value.
17974 + Returns 1 on success or 0 on failure, with a Python exception set. This
17975 + function can also throw GDB exceptions. */
17978 +get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
17980 + if (gdbpy_is_value_object (obj))
17981 + *addr = value_as_address (value_object_to_value (obj));
17982 + else if (PyLong_Check (obj))
17984 + /* Assume CORE_ADDR corresponds to unsigned long. */
17985 + *addr = PyLong_AsUnsignedLong (obj);
17986 + if (PyErr_Occurred () != NULL)
17989 + else if (PyInt_Check (obj))
17993 + /* Assume CORE_ADDR corresponds to unsigned long. */
17994 + val = PyInt_AsLong (obj);
18000 + /* If no error ocurred, VAL is indeed negative. */
18001 + if (PyErr_Occurred () != NULL)
18004 + PyErr_SetString (PyExc_ValueError, "negative address");
18010 + PyErr_SetString (PyExc_TypeError, "invalid type for address");
18016 diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
18017 index 58bcee3..b2e7b7d 100644
18018 --- a/gdb/python/py-value.c
18019 +++ b/gdb/python/py-value.c
18021 #include "language.h"
18023 #include "valprint.h"
18024 +#include "observer.h"
18029 /* Python's long type corresponds to C's long long type. */
18030 #define builtin_type_pylong builtin_type (python_gdbarch)->builtin_long_long
18032 +/* Python's long type corresponds to C's long long type. Unsigned version. */
18033 +#define builtin_type_upylong builtin_type \
18034 + (python_gdbarch)->builtin_unsigned_long_long
18036 #define builtin_type_pybool \
18037 language_bool_type (python_language, python_gdbarch)
18039 @@ -913,7 +918,34 @@ convert_value_from_python (PyObject *obj)
18041 LONGEST l = PyLong_AsLongLong (obj);
18043 - if (! PyErr_Occurred ())
18044 + if (PyErr_Occurred ())
18046 + /* If the error was an overflow, we can try converting to
18047 + ULONGEST instead. */
18048 + if (PyErr_ExceptionMatches (PyExc_OverflowError))
18050 + PyObject *etype, *evalue, *etraceback, *zero;
18052 + PyErr_Fetch (&etype, &evalue, &etraceback);
18053 + zero = PyInt_FromLong (0);
18055 + /* Check whether obj is positive. */
18056 + if (PyObject_RichCompareBool (obj, zero, Py_GT) > 0)
18060 + ul = PyLong_AsUnsignedLongLong (obj);
18061 + if (! PyErr_Occurred ())
18062 + value = value_from_ulongest (builtin_type_upylong, ul);
18065 + /* There's nothing we can do. */
18066 + PyErr_Restore (etype, evalue, etraceback);
18068 + Py_DECREF (zero);
18072 value = value_from_longest (builtin_type_pylong, l);
18074 else if (PyFloat_Check (obj))
18075 @@ -972,6 +1004,25 @@ gdbpy_history (PyObject *self, PyObject *args)
18076 return value_to_value_object (res_val);
18079 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
18082 +python_types_mark_used (void)
18084 + value_object *iter;
18086 + for (iter = values_in_python; iter; iter = iter->next)
18087 + type_mark_used (value_type (iter->value));
18090 +/* Returns 1 in OBJ is a gdb.Value object, 0 otherwise. */
18093 +gdbpy_is_value_object (PyObject *obj)
18095 + return PyObject_TypeCheck (obj, &value_object_type);
18099 gdbpy_initialize_values (void)
18101 @@ -982,6 +1033,8 @@ gdbpy_initialize_values (void)
18102 PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
18104 values_in_python = NULL;
18106 + observer_attach_mark_used (python_types_mark_used);
18110 diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
18111 index 67a78af..47662d9 100644
18112 --- a/gdb/python/python-internal.h
18113 +++ b/gdb/python/python-internal.h
18114 @@ -61,33 +61,76 @@ typedef int Py_ssize_t;
18115 #define PyEval_ReleaseLock() 0
18118 +#include "command.h"
18122 +struct symtab_and_line;
18124 struct language_defn;
18126 extern PyObject *gdb_module;
18127 +extern PyTypeObject block_object_type;
18128 extern PyTypeObject value_object_type;
18129 +extern PyTypeObject symbol_object_type;
18131 +/* Used in python-inferior.c. */
18136 + /* The thread we represent. */
18137 + struct thread_info *thread;
18139 + /* The Inferior object to which this thread belongs. */
18140 + PyObject *inf_obj;
18143 PyObject *gdbpy_history (PyObject *self, PyObject *args);
18144 +PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
18145 PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
18146 +PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
18147 PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
18148 +PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
18149 PyObject *gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw);
18150 +PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
18151 +PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
18153 +PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
18154 +PyObject *symtab_to_symtab_object (struct symtab *symtab);
18155 +PyObject *symbol_to_symbol_object (struct symbol *sym);
18156 +PyObject *block_to_block_object (struct block *block);
18157 PyObject *value_to_value_object (struct value *v);
18158 PyObject *type_to_type_object (struct type *);
18159 PyObject *objfile_to_objfile_object (struct objfile *);
18160 +PyObject *frame_info_to_frame_object (struct frame_info *frame);
18161 +thread_object *create_thread_object (struct thread_info *tp);
18162 +thread_object *find_thread_object (ptid_t ptid);
18163 +PyObject *find_inferior_object (int pid);
18165 PyObject *objfpy_get_printers (PyObject *, void *);
18167 +struct block *block_object_to_block (PyObject *obj);
18168 +struct symbol *symbol_object_to_symbol (PyObject *obj);
18169 struct value *value_object_to_value (PyObject *self);
18170 struct value *convert_value_from_python (PyObject *obj);
18171 struct type *type_object_to_type (PyObject *obj);
18173 +PyObject *gdbpy_get_hook_function (const char *);
18175 void gdbpy_initialize_values (void);
18176 +void gdbpy_initialize_breakpoints (void);
18177 void gdbpy_initialize_frames (void);
18178 +void gdbpy_initialize_symtabs (void);
18179 void gdbpy_initialize_commands (void);
18180 +void gdbpy_initialize_symbols (void);
18181 void gdbpy_initialize_types (void);
18182 +void gdbpy_initialize_blocks (void);
18183 void gdbpy_initialize_functions (void);
18184 void gdbpy_initialize_objfile (void);
18185 +void gdbpy_initialize_parameters (void);
18186 +void gdbpy_initialize_thread (void);
18187 +void gdbpy_initialize_inferior (void);
18189 struct cleanup *make_cleanup_py_decref (PyObject *py);
18191 @@ -97,6 +140,12 @@ struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
18192 extern struct gdbarch *python_gdbarch;
18193 extern const struct language_defn *python_language;
18195 +char *gdbpy_parse_command_name (char *text,
18196 + struct cmd_list_element ***base_list,
18197 + struct cmd_list_element **start_list);
18199 +PyObject *gdbpy_parameter_value (enum var_types, void *);
18201 /* Use this after a TRY_EXCEPT to throw the appropriate Python
18203 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
18204 @@ -107,6 +156,19 @@ extern const struct language_defn *python_language;
18205 "%s", Exception.message); \
18208 +/* Use this after a TRY_EXCEPT to throw the appropriate Python
18209 + exception. This macro is for use inside setter functions. */
18210 +#define GDB_PY_SET_HANDLE_EXCEPTION(Exception) \
18212 + if (Exception.reason < 0) \
18214 + PyErr_Format (Exception.reason == RETURN_QUIT \
18215 + ? PyExc_KeyboardInterrupt : PyExc_RuntimeError, \
18216 + "%s", Exception.message); \
18222 void gdbpy_print_stack (void);
18224 @@ -118,17 +180,22 @@ char *python_string_to_host_string (PyObject *obj);
18225 PyObject *target_string_to_unicode (const gdb_byte *str, int length);
18226 int gdbpy_is_string (PyObject *obj);
18228 +int gdbpy_is_value_object (PyObject *obj);
18230 /* Note that these are declared here, and not in python.h with the
18231 other pretty-printer functions, because they refer to PyObject. */
18232 PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
18233 struct value **replacement);
18234 PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
18235 +PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
18236 char *gdbpy_get_display_hint (PyObject *printer);
18237 PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
18239 -extern PyObject *gdbpy_doc_cst;
18240 extern PyObject *gdbpy_children_cst;
18241 extern PyObject *gdbpy_to_string_cst;
18242 extern PyObject *gdbpy_display_hint_cst;
18243 +extern PyObject *gdbpy_doc_cst;
18245 +int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
18247 #endif /* GDB_PYTHON_INTERNAL_H */
18248 diff --git a/gdb/python/python.c b/gdb/python/python.c
18249 index 254bd28..5a2a9ae 100644
18250 --- a/gdb/python/python.c
18251 +++ b/gdb/python/python.c
18253 #include "observer.h"
18255 #include "language.h"
18256 +#include "event-loop.h"
18260 @@ -45,11 +46,18 @@ static int gdbpy_auto_load = 1;
18261 #include "cli/cli-decode.h"
18262 #include "charset.h"
18264 +#include "solib.h"
18265 #include "exceptions.h"
18266 #include "python-internal.h"
18267 +#include "linespec.h"
18268 +#include "symtab.h"
18269 +#include "source.h"
18270 #include "version.h"
18271 +#include "inferior.h"
18272 +#include "gdbthread.h"
18273 #include "target.h"
18274 #include "gdbthread.h"
18275 +#include "event-top.h"
18277 static PyMethodDef GdbMethods[];
18279 @@ -197,10 +205,10 @@ python_command (char *arg, int from_tty)
18280 NULL (and set a Python exception) on error. Helper function for
18284 -parameter_to_python (struct cmd_list_element *cmd)
18286 +gdbpy_parameter_value (enum var_types type, void *var)
18288 - switch (cmd->var_type)
18292 case var_string_noescape:
18293 @@ -208,7 +216,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18297 - char *str = * (char **) cmd->var;
18298 + char *str = * (char **) var;
18301 return PyString_Decode (str, strlen (str), host_charset (), NULL);
18302 @@ -216,7 +224,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18306 - if (* (int *) cmd->var)
18307 + if (* (int *) var)
18311 @@ -224,7 +232,7 @@ parameter_to_python (struct cmd_list_element *cmd)
18313 case var_auto_boolean:
18315 - enum auto_boolean ab = * (enum auto_boolean *) cmd->var;
18316 + enum auto_boolean ab = * (enum auto_boolean *) var;
18317 if (ab == AUTO_BOOLEAN_TRUE)
18319 else if (ab == AUTO_BOOLEAN_FALSE)
18320 @@ -234,15 +242,15 @@ parameter_to_python (struct cmd_list_element *cmd)
18324 - if ((* (int *) cmd->var) == INT_MAX)
18325 + if ((* (int *) var) == INT_MAX)
18327 /* Fall through. */
18329 - return PyLong_FromLong (* (int *) cmd->var);
18330 + return PyLong_FromLong (* (int *) var);
18334 - unsigned int val = * (unsigned int *) cmd->var;
18335 + unsigned int val = * (unsigned int *) var;
18336 if (val == UINT_MAX)
18338 return PyLong_FromUnsignedLong (val);
18339 @@ -280,7 +288,7 @@ gdbpy_parameter (PyObject *self, PyObject *args)
18342 return PyErr_Format (PyExc_RuntimeError, "`%s' is not a parameter", arg);
18343 - return parameter_to_python (cmd);
18344 + return gdbpy_parameter_value (cmd->var_type, cmd->var);
18347 /* A Python function which evaluates a string using the gdb CLI. */
18348 @@ -319,6 +327,233 @@ execute_gdb_command (PyObject *self, PyObject *args)
18352 +/* Implementation of gdb.solib_address (Long) -> String.
18353 + Returns the name of the shared library holding a given address, or None. */
18356 +gdbpy_solib_address (PyObject *self, PyObject *args)
18358 + unsigned long long pc;
18360 + PyObject *str_obj;
18362 + if (!PyArg_ParseTuple (args, "K", &pc))
18365 + soname = solib_name_from_address (pc);
18367 + str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
18370 + str_obj = Py_None;
18371 + Py_INCREF (Py_None);
18377 +/* A Python function which is a wrapper for decode_line_1. */
18380 +gdbpy_decode_line (PyObject *self, PyObject *args)
18382 + struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc. */
18383 + struct symtab_and_line sal;
18384 + char *arg = NULL;
18385 + int free_sals = 0, i;
18386 + PyObject *result = NULL;
18387 + volatile struct gdb_exception except;
18389 + if (! PyArg_ParseTuple (args, "|s", &arg))
18392 + TRY_CATCH (except, RETURN_MASK_ALL)
18398 + arg = strdup (arg);
18401 + sals = decode_line_1 (©, 0, 0, 0, 0, 0);
18406 + set_default_source_symtab_and_line ();
18407 + sal = get_current_source_symtab_and_line ();
18408 + sals.sals = &sal;
18415 + if (except.reason < 0)
18418 + xfree (sals.sals);
18419 + /* We know this will always throw. */
18420 + GDB_PY_HANDLE_EXCEPTION (except);
18425 + result = PyTuple_New (sals.nelts);
18426 + for (i = 0; i < sals.nelts; ++i)
18431 + obj = symtab_and_line_to_sal_object (sals.sals[i]);
18434 + Py_DECREF (result);
18439 + PyTuple_SetItem (result, i, obj);
18444 + xfree (sals.sals);
18451 +/* Parse a string and evaluate it as an expression. */
18453 +gdbpy_parse_and_eval (PyObject *self, PyObject *args)
18456 + struct value *result = NULL;
18457 + volatile struct gdb_exception except;
18459 + if (!PyArg_ParseTuple (args, "s", &expr_str))
18462 + TRY_CATCH (except, RETURN_MASK_ALL)
18464 + result = parse_and_eval (expr_str);
18466 + GDB_PY_HANDLE_EXCEPTION (except);
18468 + return value_to_value_object (result);
18473 +/* Posting and handling events. */
18475 +/* A single event. */
18476 +struct gdbpy_event
18478 + /* The Python event. This is just a callable object. */
18480 + /* The next event. */
18481 + struct gdbpy_event *next;
18484 +/* All pending events. */
18485 +static struct gdbpy_event *gdbpy_event_list;
18486 +/* The final link of the event list. */
18487 +static struct gdbpy_event **gdbpy_event_list_end;
18489 +/* We use a file handler, and not an async handler, so that we can
18490 + wake up the main thread even when it is blocked in poll(). */
18491 +static int gdbpy_event_fds[2];
18493 +/* The file handler callback. This reads from the internal pipe, and
18494 + then processes the Python event queue. This will always be run in
18495 + the main gdb thread. */
18497 +gdbpy_run_events (int err, gdb_client_data ignore)
18499 + PyGILState_STATE state;
18500 + char buffer[100];
18503 + state = PyGILState_Ensure ();
18505 + /* Just read whatever is available on the fd. It is relatively
18506 + harmless if there are any bytes left over. */
18507 + r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
18509 + while (gdbpy_event_list)
18511 + /* Dispatching the event might push a new element onto the event
18512 + loop, so we update here "atomically enough". */
18513 + struct gdbpy_event *item = gdbpy_event_list;
18514 + gdbpy_event_list = gdbpy_event_list->next;
18515 + if (gdbpy_event_list == NULL)
18516 + gdbpy_event_list_end = &gdbpy_event_list;
18518 + /* Ignore errors. */
18519 + PyObject_CallObject (item->event, NULL);
18521 + Py_DECREF (item->event);
18525 + PyGILState_Release (state);
18528 +/* Submit an event to the gdb thread. */
18530 +gdbpy_post_event (PyObject *self, PyObject *args)
18532 + struct gdbpy_event *event;
18536 + if (!PyArg_ParseTuple (args, "O", &func))
18539 + if (!PyCallable_Check (func))
18541 + PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
18545 + Py_INCREF (func);
18547 + /* From here until the end of the function, we have the GIL, so we
18548 + can operate on our global data structures without worrying. */
18549 + wakeup = gdbpy_event_list == NULL;
18551 + event = XNEW (struct gdbpy_event);
18552 + event->event = func;
18553 + event->next = NULL;
18554 + *gdbpy_event_list_end = event;
18555 + gdbpy_event_list_end = &event->next;
18557 + /* Wake up gdb when needed. */
18560 + char c = 'q'; /* Anything. */
18561 + if (write (gdbpy_event_fds[1], &c, 1) != 1)
18562 + return PyErr_SetFromErrno (PyExc_IOError);
18568 +/* Initialize the Python event handler. */
18570 +gdbpy_initialize_events (void)
18572 + if (!pipe (gdbpy_event_fds))
18574 + gdbpy_event_list_end = &gdbpy_event_list;
18575 + add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
18582 @@ -357,6 +592,69 @@ gdbpy_print_stack (void)
18586 +/* Script interface. */
18588 +/* True if 'gdb -P' was used, false otherwise. */
18589 +static int running_python_script;
18591 +/* True if we are currently in a call to 'gdb.cli', false otherwise. */
18592 +static int in_cli;
18594 +/* Enter the command loop. */
18597 +gdbpy_cli (PyObject *unused1, PyObject *unused2)
18599 + if (! running_python_script || in_cli)
18600 + return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
18603 + cli_command_loop ();
18609 +/* Set up the Python argument vector and evaluate a script. This is
18610 + used to implement 'gdb -P'. */
18613 +run_python_script (int argc, char **argv)
18616 + PyGILState_STATE state;
18618 + /* We never free this, since we plan to exit at the end. */
18619 + state = PyGILState_Ensure ();
18621 + running_python_script = 1;
18622 + PySys_SetArgv (argc - 1, argv + 1);
18623 + input = fopen (argv[0], "r");
18626 + fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
18629 + PyRun_SimpleFile (input, argv[0]);
18635 +source_python_script (FILE *stream, char *file)
18637 + PyGILState_STATE state;
18639 + state = PyGILState_Ensure ();
18641 + PyRun_SimpleFile (stream, file);
18644 + PyGILState_Release (state);
18649 /* The "current" objfile. This is set when gdb detects that a new
18650 objfile has been loaded. It is only set for the duration of a call
18651 to gdbpy_new_objfile; it is NULL at other times. */
18652 @@ -501,6 +799,13 @@ eval_python_from_control_command (struct command_line *cmd)
18653 error (_("Python scripting is not supported in this copy of GDB."));
18657 +source_python_script (FILE *stream)
18660 + error (_("Python scripting is not supported in this copy of GDB."));
18663 #endif /* HAVE_PYTHON */
18666 @@ -592,13 +897,27 @@ Enables or disables auto-loading of Python code when an object is opened."),
18667 PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
18668 PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
18669 PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
18671 + PyModule_AddStringConstant (gdb_module, "pythondir", PYTHONDIR);
18674 + PyModule_AddStringConstant (gdb_module, "datadir", gdb_datadir);
18677 gdbpy_initialize_values ();
18678 + gdbpy_initialize_breakpoints ();
18679 gdbpy_initialize_frames ();
18680 + gdbpy_initialize_symtabs ();
18681 gdbpy_initialize_commands ();
18682 + gdbpy_initialize_symbols ();
18683 + gdbpy_initialize_blocks ();
18684 gdbpy_initialize_functions ();
18685 gdbpy_initialize_types ();
18686 + gdbpy_initialize_parameters ();
18687 gdbpy_initialize_objfile ();
18688 + gdbpy_initialize_thread ();
18689 + gdbpy_initialize_inferior ();
18690 + gdbpy_initialize_events ();
18692 PyRun_SimpleString ("import gdb");
18693 PyRun_SimpleString ("gdb.pretty_printers = []");
18694 @@ -634,6 +953,15 @@ class GdbOutputFile:\n\
18696 sys.stderr = GdbOutputFile()\n\
18697 sys.stdout = GdbOutputFile()\n\
18698 +if hasattr (gdb, 'datadir'):\n\
18699 + gdb.pythondir = gdb.datadir + '/python'\n\
18700 +if hasattr (gdb, 'pythondir'):\n\
18701 + sys.path.insert(0, gdb.pythondir)\n\
18702 + gdb.__path__ = [gdb.pythondir + '/gdb']\n\
18703 + from os.path import exists\n\
18704 + ipy = gdb.pythondir + '/gdb/__init__.py'\n\
18705 + if exists (ipy):\n\
18706 + execfile (ipy)\n\
18709 /* Release the GIL while gdb runs. */
18710 @@ -653,9 +981,14 @@ static PyMethodDef GdbMethods[] =
18711 "Get a value from history" },
18712 { "execute", execute_gdb_command, METH_VARARGS,
18713 "Execute a gdb command" },
18714 + { "cli", gdbpy_cli, METH_NOARGS,
18715 + "Enter the gdb CLI" },
18716 { "parameter", gdbpy_parameter, METH_VARARGS,
18717 "Return a gdb parameter's value" },
18719 + { "breakpoints", gdbpy_breakpoints, METH_NOARGS,
18720 + "Return a tuple of all breakpoint objects" },
18722 { "default_visualizer", gdbpy_default_visualizer, METH_VARARGS,
18723 "Find the default visualizer for a Value." },
18725 @@ -676,6 +1009,37 @@ Return a string explaining unwind stop reason." },
18726 "lookup_type (name [, block]) -> type\n\
18727 Return a Type corresponding to the given name." },
18729 + { "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
18730 + METH_VARARGS | METH_KEYWORDS,
18731 + "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
18732 +Return a tuple with the symbol corresponding to the given name (or None) and\n\
18733 +a boolean indicating if name is a field of the current implied argument\n\
18734 +`this' (when the current language is object-oriented)." },
18735 + { "solib_address", gdbpy_solib_address, METH_VARARGS,
18736 + "solib_address (Long) -> String.\n\
18737 +Return the name of the shared library holding a given address, or None." },
18739 + { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
18740 + "Return the block containing the given pc value, or None." },
18742 + { "decode_line", gdbpy_decode_line, METH_VARARGS,
18743 + "Decode a string argument the way that 'break' or 'edit' does.\n\
18744 +Return a tuple holding the file name (or None) and line number (or None).\n\
18745 +Note: may later change to return an object." },
18747 + { "selected_thread", gdbpy_selected_thread, METH_NOARGS,
18748 + "selected_thread () -> gdb.InferiorThread.\n\
18749 +Return the selected thread object." },
18750 + { "inferiors", gdbpy_inferiors, METH_NOARGS,
18751 + "inferiors () -> (gdb.Inferior, ...).\n\
18752 +Return a tuple containing all inferiors." },
18754 + { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
18755 + "Parse a string as an expression, evaluate it, and return the result." },
18757 + { "post_event", gdbpy_post_event, METH_VARARGS,
18758 + "Post an event into gdb's event loop." },
18760 { "write", gdbpy_write, METH_VARARGS,
18761 "Write a string using gdb's filtered stream." },
18762 { "flush", gdbpy_flush, METH_NOARGS,
18763 diff --git a/gdb/python/python.h b/gdb/python/python.h
18764 index e970180..bbb6184 100644
18765 --- a/gdb/python/python.h
18766 +++ b/gdb/python/python.h
18769 void eval_python_from_control_command (struct command_line *);
18771 +void source_python_script (FILE *stream, char *file);
18773 +void run_python_script (int argc, char **argv);
18775 int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
18776 int embedded_offset, CORE_ADDR address,
18777 struct ui_file *stream, int recurse,
18778 diff --git a/gdb/scm-lang.c b/gdb/scm-lang.c
18779 index de34894..07518b0 100644
18780 --- a/gdb/scm-lang.c
18781 +++ b/gdb/scm-lang.c
18782 @@ -233,6 +233,7 @@ const struct exp_descriptor exp_descriptor_scm =
18784 print_subexp_standard,
18785 operator_length_standard,
18786 + operator_check_standard,
18788 dump_subexp_body_standard,
18790 diff --git a/gdb/scm-valprint.c b/gdb/scm-valprint.c
18791 index cc3319a..d0d4702 100644
18792 --- a/gdb/scm-valprint.c
18793 +++ b/gdb/scm-valprint.c
18794 @@ -62,9 +62,9 @@ scm_inferior_print (struct type *type, LONGEST value, struct ui_file *stream,
18796 /* XXX: Should we cache these symbols? */
18798 - lookup_symbol_global ("gdb_output", NULL, NULL, VAR_DOMAIN);
18799 + lookup_symbol_global ("gdb_output", NULL, VAR_DOMAIN);
18800 gdb_output_len_sym =
18801 - lookup_symbol_global ("gdb_output_length", NULL, NULL, VAR_DOMAIN);
18802 + lookup_symbol_global ("gdb_output_length", NULL, VAR_DOMAIN);
18804 if ((gdb_output_sym == NULL) || (gdb_output_len_sym == NULL))
18806 diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
18807 index 8b96a6f..9428d92 100644
18808 --- a/gdb/solib-darwin.c
18809 +++ b/gdb/solib-darwin.c
18810 @@ -389,7 +389,6 @@ darwin_relocate_section_addresses (struct so_list *so,
18811 static struct symbol *
18812 darwin_lookup_lib_symbol (const struct objfile *objfile,
18814 - const char *linkage_name,
18815 const domain_enum domain)
18818 diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
18819 index 19e3212..9f06fa9 100644
18820 --- a/gdb/solib-spu.c
18821 +++ b/gdb/solib-spu.c
18822 @@ -334,16 +334,13 @@ spu_bfd_open (char *pathname)
18823 static struct symbol *
18824 spu_lookup_lib_symbol (const struct objfile *objfile,
18826 - const char *linkage_name,
18827 const domain_enum domain)
18829 if (bfd_get_arch (objfile->obfd) == bfd_arch_spu)
18830 - return lookup_global_symbol_from_objfile (objfile, name, linkage_name,
18832 + return lookup_global_symbol_from_objfile (objfile, name, domain);
18834 if (svr4_so_ops.lookup_lib_global_symbol != NULL)
18835 - return svr4_so_ops.lookup_lib_global_symbol (objfile, name, linkage_name,
18837 + return svr4_so_ops.lookup_lib_global_symbol (objfile, name, domain);
18841 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
18842 index 6cfaa85..68aadc0 100644
18843 --- a/gdb/solib-svr4.c
18844 +++ b/gdb/solib-svr4.c
18845 @@ -1908,15 +1908,13 @@ struct target_so_ops svr4_so_ops;
18846 static struct symbol *
18847 elf_lookup_lib_symbol (const struct objfile *objfile,
18849 - const char *linkage_name,
18850 const domain_enum domain)
18852 if (objfile->obfd == NULL
18853 || scan_dyntag (DT_SYMBOLIC, objfile->obfd, NULL) != 1)
18856 - return lookup_global_symbol_from_objfile
18857 - (objfile, name, linkage_name, domain);
18858 + return lookup_global_symbol_from_objfile (objfile, name, domain);
18861 extern initialize_file_ftype _initialize_svr4_solib; /* -Wmissing-prototypes */
18862 diff --git a/gdb/solib.c b/gdb/solib.c
18863 index a2ad0c4..3574e62 100644
18866 @@ -1127,13 +1127,12 @@ show_auto_solib_add (struct ui_file *file, int from_tty,
18868 solib_global_lookup (const struct objfile *objfile,
18870 - const char *linkage_name,
18871 const domain_enum domain)
18873 struct target_so_ops *ops = solib_ops (target_gdbarch);
18875 if (ops->lookup_lib_global_symbol != NULL)
18876 - return ops->lookup_lib_global_symbol (objfile, name, linkage_name, domain);
18877 + return ops->lookup_lib_global_symbol (objfile, name, domain);
18881 diff --git a/gdb/solist.h b/gdb/solist.h
18882 index 63a6ba0..005e8f7 100644
18885 @@ -114,7 +114,6 @@ struct target_so_ops
18886 /* Hook for looking up global symbols in a library-specific way. */
18887 struct symbol * (*lookup_lib_global_symbol) (const struct objfile *objfile,
18889 - const char *linkage_name,
18890 const domain_enum domain);
18892 /* Given two so_list objects, one from the GDB thread list
18893 @@ -146,7 +145,6 @@ extern struct target_so_ops *current_target_so_ops;
18894 /* Handler for library-specific global symbol lookup in solib.c. */
18895 struct symbol *solib_global_lookup (const struct objfile *objfile,
18897 - const char *linkage_name,
18898 const domain_enum domain);
18901 diff --git a/gdb/somread.c b/gdb/somread.c
18902 index 36a2b28..4d5bda9 100644
18903 --- a/gdb/somread.c
18904 +++ b/gdb/somread.c
18905 @@ -435,6 +435,7 @@ static struct sym_fns som_sym_fns =
18906 som_new_init, /* sym_new_init: init anything gbl to entire symtab */
18907 som_symfile_init, /* sym_init: read initial info, setup for sym_read() */
18908 som_symfile_read, /* sym_read: read a symbol file into symtab */
18909 + NULL, /* sym_read_psymbols */
18910 som_symfile_finish, /* sym_finish: finished with file, cleanup */
18911 som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
18912 default_symfile_segments, /* sym_segments: Get segment information from
18913 diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
18914 index 7e7ab9c..a014b7a 100644
18915 --- a/gdb/spu-tdep.c
18916 +++ b/gdb/spu-tdep.c
18917 @@ -1839,7 +1839,7 @@ spu_catch_start (struct objfile *objfile)
18918 struct symbol *sym;
18919 struct symtab_and_line sal;
18921 - sym = lookup_block_symbol (block, "main", NULL, VAR_DOMAIN);
18922 + sym = lookup_block_symbol (block, "main", VAR_DOMAIN);
18925 fixup_symbol_section (sym, objfile);
18926 diff --git a/gdb/stabsread.c b/gdb/stabsread.c
18927 index e62bb15..ad6568e 100644
18928 --- a/gdb/stabsread.c
18929 +++ b/gdb/stabsread.c
18930 @@ -322,7 +322,7 @@ dbx_alloc_type (int typenums[2], struct objfile *objfile)
18932 if (typenums[0] == -1)
18934 - return (alloc_type (objfile));
18935 + return (alloc_type (objfile, NULL));
18938 type_addr = dbx_lookup_type (typenums, objfile);
18939 @@ -332,7 +332,7 @@ dbx_alloc_type (int typenums[2], struct objfile *objfile)
18940 We will fill it in later if we find out how. */
18941 if (*type_addr == 0)
18943 - *type_addr = alloc_type (objfile);
18944 + *type_addr = alloc_type (objfile, NULL);
18947 return (*type_addr);
18948 diff --git a/gdb/stack.c b/gdb/stack.c
18949 index 1c37801..594eb16 100644
18952 @@ -1308,24 +1308,24 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
18956 - if (info_verbose)
18958 - struct partial_symtab *ps;
18960 - /* Read in symbols for all of the frames. Need to do this in a
18961 - separate pass so that "Reading in symbols for xxx" messages
18962 - don't screw up the appearance of the backtrace. Also if
18963 - people have strong opinions against reading symbols for
18964 - backtrace this may have to be an option. */
18966 - for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
18969 - ps = find_pc_psymtab (get_frame_address_in_block (fi));
18971 - PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in. */
18975 + struct partial_symtab *ps;
18977 + /* Read in symbols for all of the frames. Need to do this
18978 + unconditionally to ensure that psymbols are read. Also need to
18979 + do this in a separate pass so that "Reading in symbols for xxx"
18980 + messages don't screw up the appearance of the backtrace. Also
18981 + if people have strong opinions against reading symbols for
18982 + backtrace this may have to be an option. */
18984 + for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
18987 + ps = find_pc_psymtab (get_frame_address_in_block (fi));
18988 + if (info_verbose && ps)
18989 + PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in. */
18993 for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
18995 @@ -1473,6 +1473,8 @@ print_block_frame_locals (struct block *b, struct frame_info *frame,
18997 if (SYMBOL_IS_ARGUMENT (sym))
18999 + if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
19001 values_printed = 1;
19002 print_variable_and_value (NULL, sym, frame, stream, 4 * num_tabs);
19004 diff --git a/gdb/symfile.c b/gdb/symfile.c
19005 index 2458201..c31b72a 100644
19006 --- a/gdb/symfile.c
19007 +++ b/gdb/symfile.c
19008 @@ -921,6 +921,17 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
19009 clear_complaints (&symfile_complaints, 0, add_flags & SYMFILE_VERBOSE);
19012 +/* A helper function which returns true if OBJFILE has any debug
19013 + symbols, and false otherwise. */
19015 +has_any_debug_symbols (struct objfile *objfile)
19017 + return (objfile->psymtabs || objfile->quick_addrmap
19018 + || (objfile->separate_debug_objfile
19019 + && (objfile->separate_debug_objfile->psymtabs
19020 + || objfile->separate_debug_objfile->quick_addrmap)));
19023 /* Process a symbol file, as either the main file or as a dynamically
19026 @@ -958,13 +969,16 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19027 /* Give user a chance to burp if we'd be
19028 interactively wiping out any existing symbols. */
19030 - if ((have_full_symbols () || have_partial_symbols ())
19031 - && (add_flags & SYMFILE_MAINLINE)
19032 + if ((add_flags & SYMFILE_MAINLINE)
19033 + && (have_full_symbols () || have_partial_symbols ())
19035 + && (have_full_symbols () || have_partial_symbols ())
19036 && !query (_("Load new symbol table from \"%s\"? "), name))
19037 error (_("Not confirmed."));
19039 objfile = allocate_objfile (abfd, flags);
19040 + if (add_flags & SYMFILE_MAINLINE)
19041 + objfile->flags |= OBJF_MAIN;
19042 discard_cleanups (my_cleanups);
19045 @@ -997,6 +1011,8 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19047 if ((flags & OBJF_READNOW) || readnow_symbol_files)
19049 + require_partial_symbols (objfile);
19051 if (from_tty || info_verbose)
19053 printf_unfiltered (_("expanding to full symbols..."));
19054 @@ -1015,7 +1031,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19055 /* If the file has its own symbol tables it has no separate debug info.
19056 `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
19057 `.gnu_debuglink' may no longer be present with `.note.gnu.build-id'. */
19058 - if (objfile->psymtabs == NULL)
19059 + if (!has_any_debug_symbols (objfile))
19060 debugfile = find_separate_debug_file (objfile);
19063 @@ -1039,9 +1055,10 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
19067 + /* has_any_debug_symbols is not fully compatible with the former calls which
19068 + would just be needlessly expensive here. */
19069 if ((from_tty || info_verbose)
19070 - && !objfile_has_partial_symbols (objfile)
19071 - && !objfile_has_full_symbols (objfile))
19072 + && !has_any_debug_symbols (objfile))
19075 printf_unfiltered (_("(no debugging symbols found)..."));
19076 @@ -2422,14 +2439,15 @@ reread_symbols (void)
19077 zero is OK since dbxread.c also does what it needs to do if
19078 objfile->global_psymbols.size is 0. */
19079 (*objfile->sf->sym_read) (objfile, 0);
19080 - if (!objfile_has_partial_symbols (objfile)
19081 - && !objfile_has_full_symbols (objfile))
19082 + if (!has_any_debug_symbols (objfile))
19085 printf_unfiltered (_("(no debugging symbols found)\n"));
19089 + objfile->flags &= ~OBJF_SYMTABS_READ;
19091 /* We're done reading the symbol file; finish off complaints. */
19092 clear_complaints (&symfile_complaints, 0, 1);
19094 @@ -2727,7 +2745,7 @@ allocate_symtab (char *filename, struct objfile *objfile)
19097 struct partial_symtab *
19098 -allocate_psymtab (char *filename, struct objfile *objfile)
19099 +allocate_psymtab (const char *filename, struct objfile *objfile)
19101 struct partial_symtab *psymtab;
19103 @@ -3041,7 +3059,8 @@ again2:
19105 struct partial_symtab *
19106 start_psymtab_common (struct objfile *objfile,
19107 - struct section_offsets *section_offsets, char *filename,
19108 + struct section_offsets *section_offsets,
19109 + const char *filename,
19110 CORE_ADDR textlow, struct partial_symbol **global_syms,
19111 struct partial_symbol **static_syms)
19113 diff --git a/gdb/symfile.h b/gdb/symfile.h
19114 index 8c9249c..bf9d9e7 100644
19115 --- a/gdb/symfile.h
19116 +++ b/gdb/symfile.h
19117 @@ -140,6 +140,12 @@ struct sym_fns
19119 void (*sym_read) (struct objfile *, int);
19121 + /* Read the partial symbols for an objfile. This may be NULL, in
19122 + which case gdb assumes that sym_read already read the partial
19125 + void (*sym_read_psymbols) (struct objfile *);
19127 /* Called when we are finished with an objfile. Should do all
19128 cleanup that is specific to the object file format for the
19129 particular objfile. */
19130 @@ -266,7 +272,7 @@ extern void free_section_addr_info (struct section_addr_info *);
19132 extern struct partial_symtab *start_psymtab_common (struct objfile *,
19133 struct section_offsets *,
19134 - char *, CORE_ADDR,
19135 + const char *, CORE_ADDR,
19136 struct partial_symbol **,
19137 struct partial_symbol **);
19139 @@ -309,7 +315,7 @@ extern int auto_solib_limit;
19141 extern void set_initial_language (void);
19143 -extern struct partial_symtab *allocate_psymtab (char *, struct objfile *);
19144 +extern struct partial_symtab *allocate_psymtab (const char *, struct objfile *);
19146 extern void discard_psymtab (struct partial_symtab *);
19148 @@ -378,7 +384,7 @@ void free_symfile_segment_data (struct symfile_segment_data *data);
19149 /* From dwarf2read.c */
19151 extern int dwarf2_has_info (struct objfile *);
19153 +extern void dwarf2_create_quick_addrmap (struct objfile *);
19154 extern void dwarf2_build_psymtabs (struct objfile *, int);
19155 extern void dwarf2_build_frame_info (struct objfile *);
19157 diff --git a/gdb/symmisc.c b/gdb/symmisc.c
19158 index eb35369..dfd8c8c 100644
19159 --- a/gdb/symmisc.c
19160 +++ b/gdb/symmisc.c
19161 @@ -1128,7 +1128,7 @@ maintenance_check_symtabs (char *ignore, int from_tty)
19164 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
19165 - NULL, SYMBOL_DOMAIN (*psym));
19166 + SYMBOL_DOMAIN (*psym));
19169 printf_filtered ("Static symbol `");
19170 @@ -1145,7 +1145,7 @@ maintenance_check_symtabs (char *ignore, int from_tty)
19173 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
19174 - NULL, SYMBOL_DOMAIN (*psym));
19175 + SYMBOL_DOMAIN (*psym));
19178 printf_filtered ("Global symbol `");
19179 diff --git a/gdb/symtab.c b/gdb/symtab.c
19180 index 8d9d72c..82e0163 100644
19184 #include "ada-lang.h"
19185 #include "p-lang.h"
19186 #include "addrmap.h"
19187 +#include "cp-support.h"
19189 #include "hashtab.h"
19191 @@ -85,7 +86,6 @@ static int find_line_common (struct linetable *, int, int *);
19192 char *operator_chars (char *p, char **end);
19194 static struct symbol *lookup_symbol_aux (const char *name,
19195 - const char *linkage_name,
19196 const struct block *block,
19197 const domain_enum domain,
19198 enum language language,
19199 @@ -93,20 +93,19 @@ static struct symbol *lookup_symbol_aux (const char *name,
19202 struct symbol *lookup_symbol_aux_local (const char *name,
19203 - const char *linkage_name,
19204 const struct block *block,
19205 - const domain_enum domain);
19206 + const domain_enum domain,
19207 + enum language language,
19208 + int *is_a_field_of_this);
19211 struct symbol *lookup_symbol_aux_symtabs (int block_index,
19213 - const char *linkage_name,
19214 const domain_enum domain);
19217 struct symbol *lookup_symbol_aux_psymtabs (int block_index,
19219 - const char *linkage_name,
19220 const domain_enum domain);
19222 static int file_matches (char *, char **, int);
19223 @@ -271,7 +270,7 @@ lookup_partial_symtab (const char *name)
19224 make_cleanup (xfree, real_path);
19227 - ALL_PSYMTABS (objfile, pst)
19228 + ALL_PSYMTABS_REQUIRED (objfile, pst)
19230 if (FILENAME_CMP (name, pst->filename) == 0)
19232 @@ -414,7 +413,8 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
19233 gsymbol->language = language;
19234 if (gsymbol->language == language_cplus
19235 || gsymbol->language == language_java
19236 - || gsymbol->language == language_objc)
19237 + || gsymbol->language == language_objc
19238 + || gsymbol->language == language_fortran)
19240 gsymbol->language_specific.cplus_specific.demangled_name = NULL;
19242 @@ -474,7 +474,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
19243 || gsymbol->language == language_auto)
19246 - cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
19247 + cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
19248 if (demangled != NULL)
19250 gsymbol->language = language_cplus;
19251 @@ -633,6 +633,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
19252 case language_cplus:
19253 case language_java:
19254 case language_objc:
19255 + case language_fortran:
19256 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
19257 return gsymbol->language_specific.cplus_specific.demangled_name;
19259 @@ -658,6 +659,7 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
19260 case language_cplus:
19261 case language_java:
19262 case language_objc:
19263 + case language_fortran:
19264 if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
19265 return gsymbol->language_specific.cplus_specific.demangled_name;
19267 @@ -868,7 +870,13 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
19268 than the later used TEXTLOW/TEXTHIGH one. */
19270 ALL_OBJFILES (objfile)
19271 - if (objfile->psymtabs_addrmap != NULL)
19273 + if (objfile->quick_addrmap)
19275 + if (!addrmap_find (objfile->quick_addrmap, pc))
19278 + if (require_partial_symbols (objfile)->psymtabs_addrmap != NULL)
19280 struct partial_symtab *pst;
19282 @@ -901,6 +909,7 @@ find_pc_sect_psymtab (CORE_ADDR pc, struct obj_section *section)
19288 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
19289 which still have no corresponding full SYMTABs read. But it is not
19290 @@ -1168,6 +1177,22 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
19294 +/* Ensure that the partial symbols for OBJFILE have been loaded. This
19295 + function always returns its argument, as a convenience. */
19298 +require_partial_symbols (struct objfile *objfile)
19300 + if ((objfile->flags & OBJF_SYMTABS_READ) == 0)
19302 + objfile->flags |= OBJF_SYMTABS_READ;
19304 + if (objfile->sf->sym_read_psymbols)
19305 + (*objfile->sf->sym_read_psymbols) (objfile);
19310 /* Find the definition for a specified symbol name NAME
19311 in domain DOMAIN, visible from lexical block BLOCK.
19312 Returns the struct symbol pointer, or zero if no symbol is found.
19313 @@ -1194,10 +1219,14 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19315 char *demangled_name = NULL;
19316 const char *modified_name = NULL;
19317 - const char *mangled_name = NULL;
19318 struct symbol *returnval;
19319 struct cleanup *cleanup = make_cleanup (null_cleanup, 0);
19321 + if(strncmp(name, "::", 2) == 0){/* this must be a global name */
19326 modified_name = name;
19328 /* If we are using C++ or Java, demangle the name before doing a lookup, so
19329 @@ -1207,7 +1236,6 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19330 demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
19331 if (demangled_name)
19333 - mangled_name = name;
19334 modified_name = demangled_name;
19335 make_cleanup (xfree, demangled_name);
19337 @@ -1229,7 +1257,6 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19338 DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA);
19339 if (demangled_name)
19341 - mangled_name = name;
19342 modified_name = demangled_name;
19343 make_cleanup (xfree, demangled_name);
19345 @@ -1248,8 +1275,8 @@ lookup_symbol_in_language (const char *name, const struct block *block,
19346 modified_name = copy;
19349 - returnval = lookup_symbol_aux (modified_name, mangled_name, block,
19350 - domain, lang, is_a_field_of_this);
19351 + returnval = lookup_symbol_aux (modified_name, block, domain, lang,
19352 + is_a_field_of_this);
19353 do_cleanups (cleanup);
19356 @@ -1273,9 +1300,9 @@ lookup_symbol (const char *name, const struct block *block,
19359 static struct symbol *
19360 -lookup_symbol_aux (const char *name, const char *linkage_name,
19361 - const struct block *block, const domain_enum domain,
19362 - enum language language, int *is_a_field_of_this)
19363 +lookup_symbol_aux (const char *name, const struct block *block,
19364 + const domain_enum domain, enum language language,
19365 + int *is_a_field_of_this)
19367 struct symbol *sym;
19368 const struct language_defn *langdef;
19369 @@ -1291,55 +1318,19 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19370 /* Search specified block and its superiors. Don't search
19371 STATIC_BLOCK or GLOBAL_BLOCK. */
19373 - sym = lookup_symbol_aux_local (name, linkage_name, block, domain);
19374 + sym = lookup_symbol_aux_local (name, block, domain, language, is_a_field_of_this);
19378 - /* If requested to do so by the caller and if appropriate for LANGUAGE,
19379 - check to see if NAME is a field of `this'. */
19381 - langdef = language_def (language);
19383 - if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL
19384 - && block != NULL)
19386 - struct symbol *sym = NULL;
19387 - /* 'this' is only defined in the function's block, so find the
19388 - enclosing function block. */
19389 - for (; block && !BLOCK_FUNCTION (block);
19390 - block = BLOCK_SUPERBLOCK (block));
19392 - if (block && !dict_empty (BLOCK_DICT (block)))
19393 - sym = lookup_block_symbol (block, langdef->la_name_of_this,
19394 - NULL, VAR_DOMAIN);
19397 - struct type *t = sym->type;
19399 - /* I'm not really sure that type of this can ever
19400 - be typedefed; just be safe. */
19401 - CHECK_TYPEDEF (t);
19402 - if (TYPE_CODE (t) == TYPE_CODE_PTR
19403 - || TYPE_CODE (t) == TYPE_CODE_REF)
19404 - t = TYPE_TARGET_TYPE (t);
19406 - if (TYPE_CODE (t) != TYPE_CODE_STRUCT
19407 - && TYPE_CODE (t) != TYPE_CODE_UNION)
19408 - error (_("Internal error: `%s' is not an aggregate"),
19409 - langdef->la_name_of_this);
19411 - if (check_field (t, name))
19413 - *is_a_field_of_this = 1;
19418 + /* this symbol was found to be a member variable
19419 + do not perform the global search. */
19420 + if (is_a_field_of_this && *is_a_field_of_this)
19423 /* Now do whatever is appropriate for LANGUAGE to look
19424 up static and global variables. */
19426 - sym = langdef->la_lookup_symbol_nonlocal (name, linkage_name, block, domain);
19427 + langdef = language_def (language);
19428 + sym = langdef->la_lookup_symbol_nonlocal (name, block, domain);
19432 @@ -1349,11 +1340,11 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19433 desired name as a file-level static, then do psymtab-to-symtab
19434 conversion on the fly and return the found symbol. */
19436 - sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, linkage_name, domain);
19437 + sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
19441 - sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, linkage_name, domain);
19442 + sym = lookup_symbol_aux_psymtabs (STATIC_BLOCK, name, domain);
19446 @@ -1364,30 +1355,81 @@ lookup_symbol_aux (const char *name, const char *linkage_name,
19447 Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
19449 static struct symbol *
19450 -lookup_symbol_aux_local (const char *name, const char *linkage_name,
19451 - const struct block *block,
19452 - const domain_enum domain)
19453 +lookup_symbol_aux_local (const char *name, const struct block *block,
19454 + const domain_enum domain, enum language language,
19455 + int *is_a_field_of_this)
19457 struct symbol *sym;
19458 - const struct block *static_block = block_static_block (block);
19459 + const struct block *global_block = block_global_block (block);
19460 + const struct block *block_iterator = block;
19461 + const struct language_defn *langdef;
19463 + langdef = language_def (language);
19465 /* Check if either no block is specified or it's a global block. */
19467 - if (static_block == NULL)
19468 + if (global_block == NULL)
19471 - while (block != static_block)
19472 + while (block_iterator != global_block)
19474 - sym = lookup_symbol_aux_block (name, linkage_name, block, domain);
19476 + sym = lookup_symbol_aux_block (name, block_iterator, domain);
19481 - if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block))
19483 - block = BLOCK_SUPERBLOCK (block);
19485 + if (language == language_cplus )
19487 + sym = cp_lookup_symbol_imports (block_scope (block_iterator), name,
19488 + block_iterator, domain, 1, 1);
19494 + if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL
19495 + && BLOCK_FUNCTION (block_iterator))
19497 + if (!dict_empty (BLOCK_DICT (block_iterator)))
19499 + sym = lookup_block_symbol (block_iterator,
19500 + langdef->la_name_of_this,
19506 + struct type *t = sym->type;
19508 + /* I'm not really sure that type of this can ever
19509 + be typedefed; just be safe. */
19510 + CHECK_TYPEDEF (t);
19511 + if (TYPE_CODE (t) == TYPE_CODE_PTR
19512 + || TYPE_CODE (t) == TYPE_CODE_REF)
19513 + t = TYPE_TARGET_TYPE (t);
19515 + if (TYPE_CODE (t) != TYPE_CODE_STRUCT
19516 + && TYPE_CODE (t) != TYPE_CODE_UNION)
19517 + error (_("Internal error: `%s' is not an aggregate"),
19518 + langdef->la_name_of_this);
19520 + if (check_field (t, name))
19522 + *is_a_field_of_this = 1;
19529 + if (BLOCK_FUNCTION (block_iterator) != NULL && block_inlined_p (block_iterator))
19532 + block_iterator = BLOCK_SUPERBLOCK (block_iterator);
19535 - /* We've reached the edge of the function without finding a result. */
19536 + /* We've reached the global block without finding a result. */
19540 @@ -1416,13 +1458,12 @@ lookup_objfile_from_block (const struct block *block)
19541 block_found appropriately. */
19544 -lookup_symbol_aux_block (const char *name, const char *linkage_name,
19545 - const struct block *block,
19546 +lookup_symbol_aux_block (const char *name, const struct block *block,
19547 const domain_enum domain)
19549 struct symbol *sym;
19551 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19552 + sym = lookup_block_symbol (block, name, domain);
19555 block_found = block;
19556 @@ -1438,7 +1479,6 @@ lookup_symbol_aux_block (const char *name, const char *linkage_name,
19558 lookup_global_symbol_from_objfile (const struct objfile *objfile,
19560 - const char *linkage_name,
19561 const domain_enum domain)
19563 struct symbol *sym;
19564 @@ -1452,7 +1492,7 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19566 bv = BLOCKVECTOR (s);
19567 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19568 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19569 + sym = lookup_block_symbol (block, name, domain);
19572 block_found = block;
19573 @@ -1461,23 +1501,23 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19576 /* Now go through psymtabs. */
19577 + require_partial_symbols ((struct objfile *) objfile);
19578 ALL_OBJFILE_PSYMTABS (objfile, ps)
19581 - && lookup_partial_symbol (ps, name, linkage_name,
19583 + && lookup_partial_symbol (ps, name, 1, domain))
19585 s = PSYMTAB_TO_SYMTAB (ps);
19586 bv = BLOCKVECTOR (s);
19587 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19588 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19589 + sym = lookup_block_symbol (block, name, domain);
19590 return fixup_symbol_section (sym, (struct objfile *)objfile);
19594 if (objfile->separate_debug_objfile)
19595 return lookup_global_symbol_from_objfile (objfile->separate_debug_objfile,
19596 - name, linkage_name, domain);
19601 @@ -1488,8 +1528,7 @@ lookup_global_symbol_from_objfile (const struct objfile *objfile,
19604 static struct symbol *
19605 -lookup_symbol_aux_symtabs (int block_index,
19606 - const char *name, const char *linkage_name,
19607 +lookup_symbol_aux_symtabs (int block_index, const char *name,
19608 const domain_enum domain)
19610 struct symbol *sym;
19611 @@ -1502,7 +1541,7 @@ lookup_symbol_aux_symtabs (int block_index,
19613 bv = BLOCKVECTOR (s);
19614 block = BLOCKVECTOR_BLOCK (bv, block_index);
19615 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19616 + sym = lookup_block_symbol (block, name, domain);
19619 block_found = block;
19620 @@ -1520,7 +1559,6 @@ lookup_symbol_aux_symtabs (int block_index,
19622 static struct symbol *
19623 lookup_symbol_aux_psymtabs (int block_index, const char *name,
19624 - const char *linkage_name,
19625 const domain_enum domain)
19627 struct symbol *sym;
19628 @@ -1531,16 +1569,15 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19630 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
19632 - ALL_PSYMTABS (objfile, ps)
19633 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19636 - && lookup_partial_symbol (ps, name, linkage_name,
19637 - psymtab_index, domain))
19638 + && lookup_partial_symbol (ps, name, psymtab_index, domain))
19640 s = PSYMTAB_TO_SYMTAB (ps);
19641 bv = BLOCKVECTOR (s);
19642 block = BLOCKVECTOR_BLOCK (bv, block_index);
19643 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19644 + sym = lookup_block_symbol (block, name, domain);
19647 /* This shouldn't be necessary, but as a last resort try
19648 @@ -1557,7 +1594,7 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19649 block = BLOCKVECTOR_BLOCK (bv,
19650 block_index == GLOBAL_BLOCK ?
19651 STATIC_BLOCK : GLOBAL_BLOCK);
19652 - sym = lookup_block_symbol (block, name, linkage_name, domain);
19653 + sym = lookup_block_symbol (block, name, domain);
19655 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>)."),
19656 block_index == GLOBAL_BLOCK ? "global" : "static",
19657 @@ -1576,7 +1613,6 @@ lookup_symbol_aux_psymtabs (int block_index, const char *name,
19660 basic_lookup_symbol_nonlocal (const char *name,
19661 - const char *linkage_name,
19662 const struct block *block,
19663 const domain_enum domain)
19665 @@ -1610,11 +1646,11 @@ basic_lookup_symbol_nonlocal (const char *name,
19666 than that one, so I don't think we should worry about that for
19669 - sym = lookup_symbol_static (name, linkage_name, block, domain);
19670 + sym = lookup_symbol_static (name, block, domain);
19674 - return lookup_symbol_global (name, linkage_name, block, domain);
19675 + return lookup_symbol_global (name, block, domain);
19678 /* Lookup a symbol in the static block associated to BLOCK, if there
19679 @@ -1622,14 +1658,13 @@ basic_lookup_symbol_nonlocal (const char *name,
19682 lookup_symbol_static (const char *name,
19683 - const char *linkage_name,
19684 const struct block *block,
19685 const domain_enum domain)
19687 const struct block *static_block = block_static_block (block);
19689 if (static_block != NULL)
19690 - return lookup_symbol_aux_block (name, linkage_name, static_block, domain);
19691 + return lookup_symbol_aux_block (name, static_block, domain);
19695 @@ -1639,7 +1674,6 @@ lookup_symbol_static (const char *name,
19698 lookup_symbol_global (const char *name,
19699 - const char *linkage_name,
19700 const struct block *block,
19701 const domain_enum domain)
19703 @@ -1649,15 +1683,15 @@ lookup_symbol_global (const char *name,
19704 /* Call library-specific lookup procedure. */
19705 objfile = lookup_objfile_from_block (block);
19706 if (objfile != NULL)
19707 - sym = solib_global_lookup (objfile, name, linkage_name, domain);
19708 + sym = solib_global_lookup (objfile, name, domain);
19712 - sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, linkage_name, domain);
19713 + sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain);
19717 - return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, linkage_name, domain);
19718 + return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK, name, domain);
19722 @@ -1681,14 +1715,11 @@ symbol_matches_domain (enum language symbol_language,
19725 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
19726 - If LINKAGE_NAME is non-NULL, check in addition that the symbol's
19727 - linkage name matches it. Check the global symbols if GLOBAL, the
19728 - static symbols if not */
19729 + Check the global symbols if GLOBAL, the static symbols if not. */
19731 struct partial_symbol *
19732 lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19733 - const char *linkage_name, int global,
19734 - domain_enum domain)
19735 + int global, domain_enum domain)
19737 struct partial_symbol *temp;
19738 struct partial_symbol **start, **psym;
19739 @@ -1740,9 +1771,7 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19740 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
19742 while (top <= real_top
19743 - && (linkage_name != NULL
19744 - ? strcmp (SYMBOL_LINKAGE_NAME (*top), linkage_name) == 0
19745 - : SYMBOL_MATCHES_SEARCH_NAME (*top,name)))
19746 + && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
19748 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
19749 SYMBOL_DOMAIN (*top), domain))
19750 @@ -1759,15 +1788,9 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
19751 for (psym = start; psym < start + length; psym++)
19753 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
19754 - SYMBOL_DOMAIN (*psym), domain))
19756 - if (linkage_name != NULL
19757 - ? strcmp (SYMBOL_LINKAGE_NAME (*psym), linkage_name) == 0
19758 - : SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
19763 + SYMBOL_DOMAIN (*psym), domain)
19764 + && SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
19769 @@ -1809,22 +1832,25 @@ basic_lookup_transparent_type (const char *name)
19771 bv = BLOCKVECTOR (s);
19772 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19773 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19774 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19775 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
19777 return SYMBOL_TYPE (sym);
19781 - ALL_PSYMTABS (objfile, ps)
19782 + /* FIXME: .debug_pubnames should be read in.
19784 + One may also try to the first pass without the require_partial_symbols
19785 + call but that would behave nondeterministically. */
19786 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19788 - if (!ps->readin && lookup_partial_symbol (ps, name, NULL,
19789 - 1, STRUCT_DOMAIN))
19790 + if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_DOMAIN))
19792 s = PSYMTAB_TO_SYMTAB (ps);
19793 bv = BLOCKVECTOR (s);
19794 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19795 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19796 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19799 /* This shouldn't be necessary, but as a last resort
19800 @@ -1833,7 +1859,7 @@ basic_lookup_transparent_type (const char *name)
19801 * the psymtab gets it wrong in some cases.
19803 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19804 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19805 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19807 error (_("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
19808 %s may be an inlined function, or may be a template function\n\
19809 @@ -1857,21 +1883,26 @@ basic_lookup_transparent_type (const char *name)
19811 bv = BLOCKVECTOR (s);
19812 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19813 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19814 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19815 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
19817 return SYMBOL_TYPE (sym);
19821 - ALL_PSYMTABS (objfile, ps)
19822 + /* FIXME: Something like .debug_pubnames containing also static symbols
19823 + should be read in. Compiler needs to be taught to generate it first.
19825 + One may also try to the first pass without the require_partial_symbols
19826 + call but that would behave nondeterministically. */
19827 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19829 - if (!ps->readin && lookup_partial_symbol (ps, name, NULL, 0, STRUCT_DOMAIN))
19830 + if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_DOMAIN))
19832 s = PSYMTAB_TO_SYMTAB (ps);
19833 bv = BLOCKVECTOR (s);
19834 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
19835 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19836 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19839 /* This shouldn't be necessary, but as a last resort
19840 @@ -1880,7 +1911,7 @@ basic_lookup_transparent_type (const char *name)
19841 * the psymtab gets it wrong in some cases.
19843 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
19844 - sym = lookup_block_symbol (block, name, NULL, STRUCT_DOMAIN);
19845 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
19847 error (_("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
19848 %s may be an inlined function, or may be a template function\n\
19849 @@ -1905,9 +1936,23 @@ find_main_psymtab (void)
19850 struct partial_symtab *pst;
19851 struct objfile *objfile;
19853 - ALL_PSYMTABS (objfile, pst)
19854 + ALL_OBJFILES (objfile)
19856 + if ((objfile->flags & OBJF_MAIN) == 0)
19858 + require_partial_symbols (objfile);
19859 + ALL_OBJFILE_PSYMTABS (objfile, pst)
19861 + if (lookup_partial_symbol (pst, main_name (), 1, VAR_DOMAIN))
19868 + ALL_PSYMTABS_REQUIRED (objfile, pst)
19870 - if (lookup_partial_symbol (pst, main_name (), NULL, 1, VAR_DOMAIN))
19871 + if (lookup_partial_symbol (pst, main_name (), 1, VAR_DOMAIN))
19875 @@ -1925,14 +1970,10 @@ find_main_psymtab (void)
19876 search on the symbols. Each symbol which is marked as being a ObjC/C++
19877 symbol (language_cplus or language_objc set) has both the encoded and
19878 non-encoded names tested for a match.
19880 - If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
19881 - particular mangled name.
19885 lookup_block_symbol (const struct block *block, const char *name,
19886 - const char *linkage_name,
19887 const domain_enum domain)
19889 struct dict_iterator iter;
19890 @@ -1945,9 +1986,7 @@ lookup_block_symbol (const struct block *block, const char *name,
19891 sym = dict_iter_name_next (name, &iter))
19893 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
19894 - SYMBOL_DOMAIN (sym), domain)
19895 - && (linkage_name != NULL
19896 - ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
19897 + SYMBOL_DOMAIN (sym), domain))
19901 @@ -1967,9 +2006,7 @@ lookup_block_symbol (const struct block *block, const char *name,
19902 sym = dict_iter_name_next (name, &iter))
19904 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
19905 - SYMBOL_DOMAIN (sym), domain)
19906 - && (linkage_name != NULL
19907 - ? strcmp (SYMBOL_LINKAGE_NAME (sym), linkage_name) == 0 : 1))
19908 + SYMBOL_DOMAIN (sym), domain))
19911 if (!SYMBOL_IS_ARGUMENT (sym))
19912 @@ -3172,7 +3209,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
19913 matching the regexp. That way we don't have to reproduce all of
19914 the machinery below. */
19916 - ALL_PSYMTABS (objfile, ps)
19917 + ALL_PSYMTABS_REQUIRED (objfile, ps)
19919 struct partial_symbol **bound, **gbound, **sbound;
19920 int keep_going = 1;
19921 diff --git a/gdb/symtab.h b/gdb/symtab.h
19922 index 740d4e0..461ff95 100644
19925 @@ -171,9 +171,6 @@ extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
19926 #define SYMBOL_SECTION(symbol) (symbol)->ginfo.section
19927 #define SYMBOL_OBJ_SECTION(symbol) (symbol)->ginfo.obj_section
19929 -#define SYMBOL_CPLUS_DEMANGLED_NAME(symbol) \
19930 - (symbol)->ginfo.language_specific.cplus_specific.demangled_name
19932 /* Initializes the language dependent portion of a symbol
19933 depending upon the language for the symbol. */
19934 #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language) \
19935 @@ -394,7 +391,13 @@ typedef enum domain_enum_tag
19938 /* All defined types */
19942 + /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. */
19943 + COMMON_BLOCK_DOMAIN,
19945 + /* Fortran module. Their naming must be separate. */
19950 @@ -990,7 +993,6 @@ extern struct symbol *lookup_symbol (const char *, const struct block *,
19951 that can't think of anything better to do. */
19953 extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
19955 const struct block *,
19956 const domain_enum);
19958 @@ -1001,7 +1003,6 @@ extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
19959 is one; do nothing if BLOCK is NULL or a global block. */
19961 extern struct symbol *lookup_symbol_static (const char *name,
19962 - const char *linkage_name,
19963 const struct block *block,
19964 const domain_enum domain);
19966 @@ -1009,7 +1010,6 @@ extern struct symbol *lookup_symbol_static (const char *name,
19969 extern struct symbol *lookup_symbol_global (const char *name,
19970 - const char *linkage_name,
19971 const struct block *block,
19972 const domain_enum domain);
19974 @@ -1018,21 +1018,18 @@ extern struct symbol *lookup_symbol_global (const char *name,
19975 will fix up the symbol if necessary. */
19977 extern struct symbol *lookup_symbol_aux_block (const char *name,
19978 - const char *linkage_name,
19979 const struct block *block,
19980 const domain_enum domain);
19982 /* Lookup a partial symbol. */
19984 extern struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
19989 /* lookup a symbol by name, within a specified block */
19991 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
19993 const domain_enum);
19995 /* lookup a [struct, union, enum] by name, within a specified block */
19996 @@ -1062,6 +1059,8 @@ extern void clear_pc_function_cache (void);
19998 /* from symtab.c: */
20000 +struct objfile *require_partial_symbols (struct objfile *);
20002 /* lookup partial symbol table by filename */
20004 extern struct partial_symtab *lookup_partial_symtab (const char *);
20005 @@ -1356,7 +1355,6 @@ extern /*const */ char *main_name (void);
20006 /* Check global symbols in objfile. */
20007 struct symbol *lookup_global_symbol_from_objfile (const struct objfile *objfile,
20009 - const char *linkage_name,
20010 const domain_enum domain);
20012 extern struct symtabs_and_lines
20013 diff --git a/gdb/target.c b/gdb/target.c
20014 index e5d14fd..37fab72 100644
20017 @@ -124,6 +124,8 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
20019 static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
20021 +static int debug_to_detach_watchpoints (void);
20023 static int debug_to_stopped_by_watchpoint (void);
20025 static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
20026 @@ -622,6 +624,7 @@ update_current_target (void)
20027 INHERIT (to_remove_hw_breakpoint, t);
20028 INHERIT (to_insert_watchpoint, t);
20029 INHERIT (to_remove_watchpoint, t);
20030 + INHERIT (to_detach_watchpoints, t);
20031 INHERIT (to_stopped_data_address, t);
20032 INHERIT (to_have_steppable_watchpoint, t);
20033 INHERIT (to_have_continuable_watchpoint, t);
20034 @@ -733,6 +736,9 @@ update_current_target (void)
20035 de_fault (to_remove_watchpoint,
20036 (int (*) (CORE_ADDR, int, int))
20038 + de_fault (to_detach_watchpoints,
20041 de_fault (to_stopped_by_watchpoint,
20044 @@ -3173,6 +3179,19 @@ debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
20049 +debug_to_detach_watchpoints (void)
20053 + retval = debug_target.to_detach_watchpoints ();
20055 + fprintf_unfiltered (gdb_stdlog,
20056 + "target_detach_watchpoints () = %ld\n",
20057 + (unsigned long) retval);
20062 debug_to_terminal_init (void)
20064 @@ -3420,6 +3439,7 @@ setup_target_debug (void)
20065 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
20066 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
20067 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
20068 + current_target.to_detach_watchpoints = debug_to_detach_watchpoints;
20069 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
20070 current_target.to_stopped_data_address = debug_to_stopped_data_address;
20071 current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
20072 diff --git a/gdb/target.h b/gdb/target.h
20073 index b1cb852..adff946 100644
20076 @@ -395,6 +395,7 @@ struct target_ops
20077 int (*to_remove_hw_breakpoint) (struct gdbarch *, struct bp_target_info *);
20078 int (*to_remove_watchpoint) (CORE_ADDR, int, int);
20079 int (*to_insert_watchpoint) (CORE_ADDR, int, int);
20080 + int (*to_detach_watchpoints) (void);
20081 int (*to_stopped_by_watchpoint) (void);
20082 int to_have_steppable_watchpoint;
20083 int to_have_continuable_watchpoint;
20084 @@ -1166,6 +1167,15 @@ extern char *normal_pid_to_str (ptid_t ptid);
20085 #define target_remove_watchpoint(addr, len, type) \
20086 (*current_target.to_remove_watchpoint) (addr, len, type)
20088 +/* Clear all debug registers without affecting any register caches. Function
20089 + acts on INFERIOR_PTID which should be the forked-off process, either the
20090 + non-threaded child one or the threaded parent one, depending on `set
20091 + follow-fork-mode'. Both watchpoints and hardware breakpoints get removed.
20092 + Return 0 on success, -1 on failure. */
20094 +#define target_detach_watchpoints() \
20095 + (*current_target.to_detach_watchpoints) ()
20097 #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
20098 (*current_target.to_insert_hw_breakpoint) (gdbarch, bp_tgt)
20100 @@ -1203,6 +1213,20 @@ extern int target_search_memory (CORE_ADDR start_addr,
20101 ULONGEST pattern_len,
20102 CORE_ADDR *found_addrp);
20104 +/* Utility functions which can be used by search_memory implementations. */
20106 +void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
20107 + ULONGEST *pattern_buf_size);
20109 +void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
20110 + ULONGEST *pattern_buf_size, int val_bytes);
20112 +int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
20113 + const char *pattern_buf, ULONGEST pattern_len,
20114 + CORE_ADDR *found_addr);
20116 +void put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p);
20118 /* Command logging facility. */
20120 #define target_log_command(p) \
20121 @@ -1322,6 +1346,14 @@ extern struct target_ops *find_target_beneath (struct target_ops *);
20123 extern char *target_get_osdata (const char *type);
20125 +/* Read OS data object of type TYPE from the target, and return it in
20126 + XML format. The result is NUL-terminated and returned as a string,
20127 + allocated using xmalloc. If an error occurs or the transfer is
20128 + unsupported, NULL is returned. Empty objects are returned as
20129 + allocated but empty strings. */
20131 +extern char *target_get_osdata (const char *type);
20134 /* Stuff that should be shared among the various remote targets. */
20136 diff --git a/gdb/testsuite/gdb.arch/powerpc-power7.exp b/gdb/testsuite/gdb.arch/powerpc-power7.exp
20137 new file mode 100644
20138 index 0000000..ae301db
20140 +++ b/gdb/testsuite/gdb.arch/powerpc-power7.exp
20142 +# Copyright 2009 Free Software Foundation, Inc.
20144 +# This program is free software; you can redistribute it and/or modify
20145 +# it under the terms of the GNU General Public License as published by
20146 +# the Free Software Foundation; either version 2 of the License, or
20147 +# (at your option) any later version.
20149 +# This program is distributed in the hope that it will be useful,
20150 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
20151 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20152 +# GNU General Public License for more details.
20154 +# You should have received a copy of the GNU General Public License
20155 +# along with this program; if not, write to the Free Software
20156 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20158 +# Test PowerPC Power7 instructions disassembly.
20160 +if {![istarget "powerpc*-*-*"]} then {
20161 + verbose "Skipping PowerPC Power7 instructions disassembly."
20165 +set testfile "powerpc-power7"
20166 +set srcfile ${testfile}.s
20167 +set objfile ${objdir}/${subdir}/${testfile}.o
20169 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug}] != "" } {
20170 + untested "PowerPC Power7 instructions disassembly"
20177 +gdb_reinitialize_dir $srcdir/$subdir
20178 +gdb_load ${objfile}
20181 +# Disassemble the function.
20183 +set test "disass func"
20184 +gdb_test_multiple $test $test {
20185 + -re "\r\nDump of assembler code for function func:(\r\n.*\r\n)End of assembler dump.\r\n$gdb_prompt $" {
20186 + set func $expect_out(1,string)
20191 +proc instr_to_patt {offset instr} {
20192 + # 0x0000000000000018 <func+24>: stxvd2x vs43,r4,r5
20193 + return ".*\r\n[string map {0x 0x0*} $offset] <func\\+?\[0-9\]*>:\[ \t\]*[string map [list { } "\[ \t\]+" . {\.}] $instr]\[ \t\]*\r\n.*"
20196 +# KFAIL strings would not exist if -Many would print the same as -Mpower7.
20197 +# That means the power7 form should be the preferred one.
20198 +# http://sourceware.org/ml/gdb-patches/2009-03/threads.html#00020
20200 +proc func_check {offset instr {kfail ""}} {
20203 + set test "Found $offset: $instr"
20204 + if [regexp -nocase -line [instr_to_patt $offset $instr] $func] {
20206 + } elseif {$kfail != "" && [regexp -nocase -line [instr_to_patt $offset $kfail] $func]} {
20207 + kfail gdb/NNNN $test
20213 +func_check 0x0 "lxvd2x vs3,r4,r5"
20214 +func_check 0x4 "lxvd2ux vs3,r4,r5"
20215 +func_check 0x8 "lxvd2x vs43,r4,r5"
20216 +func_check 0xc "lxvd2ux vs43,r4,r5"
20217 +func_check 0x10 "stxvd2x vs3,r4,r5"
20218 +func_check 0x14 "stxvd2ux vs3,r4,r5"
20219 +func_check 0x18 "stxvd2x vs43,r4,r5"
20220 +func_check 0x1c "stxvd2ux vs43,r4,r5"
20221 +func_check 0x20 "xxmrghd vs3,vs4,vs5"
20222 +func_check 0x24 "xxmrghd vs43,vs44,vs45"
20223 +func_check 0x28 "xxmrgld vs3,vs4,vs5"
20224 +func_check 0x2c "xxmrgld vs43,vs44,vs45"
20225 +func_check 0x30 "xxmrghd vs3,vs4,vs5"
20226 +func_check 0x34 "xxmrghd vs43,vs44,vs45"
20227 +func_check 0x38 "xxmrgld vs3,vs4,vs5"
20228 +func_check 0x3c "xxmrgld vs43,vs44,vs45"
20229 +func_check 0x40 "xxpermdi vs3,vs4,vs5,1"
20230 +func_check 0x44 "xxpermdi vs43,vs44,vs45,1"
20231 +func_check 0x48 "xxpermdi vs3,vs4,vs5,2"
20232 +func_check 0x4c "xxpermdi vs43,vs44,vs45,2"
20233 +func_check 0x50 "xvmovdp vs3,vs4"
20234 +func_check 0x54 "xvmovdp vs43,vs44"
20235 +func_check 0x58 "xvmovdp vs3,vs4"
20236 +func_check 0x5c "xvmovdp vs43,vs44"
20237 +func_check 0x60 "xvcpsgndp vs3,vs4,vs5"
20238 +func_check 0x64 "xvcpsgndp vs43,vs44,vs45"
20239 +func_check 0x68 "wait"
20240 +func_check 0x6c "wait"
20241 +func_check 0x70 "waitrsv"
20242 +func_check 0x74 "waitrsv"
20243 +func_check 0x78 "waitimpl"
20244 +func_check 0x7c "waitimpl"
20245 +func_check 0x80 "doze"
20246 +func_check 0x84 "nap"
20247 +func_check 0x88 "sleep"
20248 +func_check 0x8c "rvwinkle"
20249 +func_check 0x90 "prtyw r3,r4"
20250 +func_check 0x94 "prtyd r13,r14"
20251 +func_check 0x98 "mfcfar r10" "mfspr r10,28"
20252 +func_check 0x9c "mtcfar r11" "mtspr 28,r11"
20253 +func_check 0xa0 "cmpb r3,r4,r5"
20254 +func_check 0xa4 "lwzcix r10,r11,r12"
20255 +func_check 0xa8 "dadd f16,f17,f18"
20256 +func_check 0xac "daddq f20,f22,f24"
20257 +func_check 0xb0 "dss 3"
20258 +func_check 0xb4 "dssall"
20259 +func_check 0xb8 "dst r5,r4,1"
20260 +func_check 0xbc "dstt r8,r7,0"
20261 +func_check 0xc0 "dstst r5,r6,3"
20262 +func_check 0xc4 "dststt r4,r5,2"
20263 +func_check 0xc8 "divwe r10,r11,r12"
20264 +func_check 0xcc "divwe. r11,r12,r13"
20265 +func_check 0xd0 "divweo r12,r13,r14"
20266 +func_check 0xd4 "divweo. r13,r14,r15"
20267 +func_check 0xd8 "divweu r10,r11,r12"
20268 +func_check 0xdc "divweu. r11,r12,r13"
20269 +func_check 0xe0 "divweuo r12,r13,r14"
20270 +func_check 0xe4 "divweuo. r13,r14,r15"
20271 +func_check 0xe8 "bpermd r7,r17,r27"
20272 +func_check 0xec "popcntw r10,r20"
20273 +func_check 0xf0 "popcntd r10,r20"
20274 +func_check 0xf4 "ldbrx r20,r21,r22"
20275 +func_check 0xf8 "stdbrx r20,r21,r22"
20276 +func_check 0xfc "lfiwzx f10,0,r10"
20277 +func_check 0x100 "lfiwzx f10,r9,r10"
20278 +func_check 0x104 "fcfids f4,f5"
20279 +func_check 0x108 "fcfids. f4,f5"
20280 +func_check 0x10c "fcfidus f4,f5"
20281 +func_check 0x110 "fcfidus. f4,f5"
20282 +func_check 0x114 "fctiwu f4,f5"
20283 +func_check 0x118 "fctiwu. f4,f5"
20284 +func_check 0x11c "fctiwuz f4,f5"
20285 +func_check 0x120 "fctiwuz. f4,f5"
20286 +func_check 0x124 "fctidu f4,f5"
20287 +func_check 0x128 "fctidu. f4,f5"
20288 +func_check 0x12c "fctiduz f4,f5"
20289 +func_check 0x130 "fctiduz. f4,f5"
20290 +func_check 0x134 "fcfidu f4,f5"
20291 +func_check 0x138 "fcfidu. f4,f5"
20292 +func_check 0x13c "ftdiv cr0,f10,f11"
20293 +func_check 0x140 "ftdiv cr7,f10,f11"
20294 +func_check 0x144 "ftsqrt cr0,f10"
20295 +func_check 0x148 "ftsqrt cr7,f10"
20296 +func_check 0x14c "dcbtt r8,r9" "dcbt 16,r8,r9"
20297 +func_check 0x150 "dcbtstt r8,r9" "dcbtst 16,r8,r9"
20298 +func_check 0x154 "dcffix f10,f12"
20299 +func_check 0x158 "dcffix. f20,f22"
20300 +func_check 0x15c "lbarx r10,r11,r12"
20301 +func_check 0x160 "lbarx r10,r11,r12"
20302 +func_check 0x164 "lbarx r10,r11,r12,1"
20303 +func_check 0x168 "lharx r20,r21,r22"
20304 +func_check 0x16c "lharx r20,r21,r22"
20305 +func_check 0x170 "lharx r20,r21,r22,1"
20306 +func_check 0x174 "stbcx. r10,r11,r12"
20307 +func_check 0x178 "sthcx. r10,r11,r12"
20308 +func_check 0x17c "fre f14,f15"
20309 +func_check 0x180 "fre. f14,f15"
20310 +func_check 0x184 "fres f14,f15"
20311 +func_check 0x188 "fres. f14,f15"
20312 +func_check 0x18c "frsqrte f14,f15"
20313 +func_check 0x190 "frsqrte. f14,f15"
20314 +func_check 0x194 "frsqrtes f14,f15"
20315 +func_check 0x198 "frsqrtes. f14,f15"
20316 +func_check 0x19c "isel r2,r3,r4,28"
20317 diff --git a/gdb/testsuite/gdb.arch/powerpc-power7.s b/gdb/testsuite/gdb.arch/powerpc-power7.s
20318 new file mode 100644
20319 index 0000000..98b2e79
20321 +++ b/gdb/testsuite/gdb.arch/powerpc-power7.s
20326 + .long 0x7c642e98 /* 0: lxvd2x vs3,r4,r5 */
20327 + .long 0x7c642ed8 /* 4: lxvd2ux vs3,r4,r5 */
20328 + .long 0x7d642e99 /* 8: lxvd2x vs43,r4,r5 */
20329 + .long 0x7d642ed9 /* c: lxvd2ux vs43,r4,r5 */
20330 + .long 0x7c642f98 /* 10: stxvd2x vs3,r4,r5 */
20331 + .long 0x7c642fd8 /* 14: stxvd2ux vs3,r4,r5 */
20332 + .long 0x7d642f99 /* 18: stxvd2x vs43,r4,r5 */
20333 + .long 0x7d642fd9 /* 1c: stxvd2ux vs43,r4,r5 */
20334 + .long 0xf0642850 /* 20: xxmrghd vs3,vs4,vs5 */
20335 + .long 0xf16c6857 /* 24: xxmrghd vs43,vs44,vs45 */
20336 + .long 0xf0642b50 /* 28: xxmrgld vs3,vs4,vs5 */
20337 + .long 0xf16c6b57 /* 2c: xxmrgld vs43,vs44,vs45 */
20338 + .long 0xf0642850 /* 30: xxmrghd vs3,vs4,vs5 */
20339 + .long 0xf16c6857 /* 34: xxmrghd vs43,vs44,vs45 */
20340 + .long 0xf0642b50 /* 38: xxmrgld vs3,vs4,vs5 */
20341 + .long 0xf16c6b57 /* 3c: xxmrgld vs43,vs44,vs45 */
20342 + .long 0xf0642950 /* 40: xxpermdi vs3,vs4,vs5,1 */
20343 + .long 0xf16c6957 /* 44: xxpermdi vs43,vs44,vs45,1 */
20344 + .long 0xf0642a50 /* 48: xxpermdi vs3,vs4,vs5,2 */
20345 + .long 0xf16c6a57 /* 4c: xxpermdi vs43,vs44,vs45,2 */
20346 + .long 0xf0642780 /* 50: xvmovdp vs3,vs4 */
20347 + .long 0xf16c6787 /* 54: xvmovdp vs43,vs44 */
20348 + .long 0xf0642780 /* 58: xvmovdp vs3,vs4 */
20349 + .long 0xf16c6787 /* 5c: xvmovdp vs43,vs44 */
20350 + .long 0xf0642f80 /* 60: xvcpsgndp vs3,vs4,vs5 */
20351 + .long 0xf16c6f87 /* 64: xvcpsgndp vs43,vs44,vs45 */
20352 + .long 0x7c00007c /* 68: wait */
20353 + .long 0x7c00007c /* 6c: wait */
20354 + .long 0x7c20007c /* 70: waitrsv */
20355 + .long 0x7c20007c /* 74: waitrsv */
20356 + .long 0x7c40007c /* 78: waitimpl */
20357 + .long 0x7c40007c /* 7c: waitimpl */
20358 + .long 0x4c000324 /* 80: doze */
20359 + .long 0x4c000364 /* 84: nap */
20360 + .long 0x4c0003a4 /* 88: sleep */
20361 + .long 0x4c0003e4 /* 8c: rvwinkle */
20362 + .long 0x7c830134 /* 90: prtyw r3,r4 */
20363 + .long 0x7dcd0174 /* 94: prtyd r13,r14 */
20364 + .long 0x7d5c02a6 /* 98: mfcfar r10 */
20365 + .long 0x7d7c03a6 /* 9c: mtcfar r11 */
20366 + .long 0x7c832bf8 /* a0: cmpb r3,r4,r5 */
20367 + .long 0x7d4b662a /* a4: lwzcix r10,r11,r12 */
20368 + .long 0xee119004 /* a8: dadd f16,f17,f18 */
20369 + .long 0xfe96c004 /* ac: daddq f20,f22,f24 */
20370 + .long 0x7c60066c /* b0: dss 3 */
20371 + .long 0x7e00066c /* b4: dssall */
20372 + .long 0x7c2522ac /* b8: dst r5,r4,1 */
20373 + .long 0x7e083aac /* bc: dstt r8,r7,0 */
20374 + .long 0x7c6532ec /* c0: dstst r5,r6,3 */
20375 + .long 0x7e442aec /* c4: dststt r4,r5,2 */
20376 + .long 0x7d4b6356 /* c8: divwe r10,r11,r12 */
20377 + .long 0x7d6c6b57 /* cc: divwe. r11,r12,r13 */
20378 + .long 0x7d8d7756 /* d0: divweo r12,r13,r14 */
20379 + .long 0x7dae7f57 /* d4: divweo. r13,r14,r15 */
20380 + .long 0x7d4b6316 /* d8: divweu r10,r11,r12 */
20381 + .long 0x7d6c6b17 /* dc: divweu. r11,r12,r13 */
20382 + .long 0x7d8d7716 /* e0: divweuo r12,r13,r14 */
20383 + .long 0x7dae7f17 /* e4: divweuo. r13,r14,r15 */
20384 + .long 0x7e27d9f8 /* e8: bpermd r7,r17,r27 */
20385 + .long 0x7e8a02f4 /* ec: popcntw r10,r20 */
20386 + .long 0x7e8a03f4 /* f0: popcntd r10,r20 */
20387 + .long 0x7e95b428 /* f4: ldbrx r20,r21,r22 */
20388 + .long 0x7e95b528 /* f8: stdbrx r20,r21,r22 */
20389 + .long 0x7d4056ee /* fc: lfiwzx f10,0,r10 */
20390 + .long 0x7d4956ee /* 100: lfiwzx f10,r9,r10 */
20391 + .long 0xec802e9c /* 104: fcfids f4,f5 */
20392 + .long 0xec802e9d /* 108: fcfids. f4,f5 */
20393 + .long 0xec802f9c /* 10c: fcfidus f4,f5 */
20394 + .long 0xec802f9d /* 110: fcfidus. f4,f5 */
20395 + .long 0xfc80291c /* 114: fctiwu f4,f5 */
20396 + .long 0xfc80291d /* 118: fctiwu. f4,f5 */
20397 + .long 0xfc80291e /* 11c: fctiwuz f4,f5 */
20398 + .long 0xfc80291f /* 120: fctiwuz. f4,f5 */
20399 + .long 0xfc802f5c /* 124: fctidu f4,f5 */
20400 + .long 0xfc802f5d /* 128: fctidu. f4,f5 */
20401 + .long 0xfc802f5e /* 12c: fctiduz f4,f5 */
20402 + .long 0xfc802f5f /* 130: fctiduz. f4,f5 */
20403 + .long 0xfc802f9c /* 134: fcfidu f4,f5 */
20404 + .long 0xfc802f9d /* 138: fcfidu. f4,f5 */
20405 + .long 0xfc0a5900 /* 13c: ftdiv cr0,f10,f11 */
20406 + .long 0xff8a5900 /* 140: ftdiv cr7,f10,f11 */
20407 + .long 0xfc005140 /* 144: ftsqrt cr0,f10 */
20408 + .long 0xff805140 /* 148: ftsqrt cr7,f10 */
20409 + .long 0x7e084a2c /* 14c: dcbtt r8,r9 */
20410 + .long 0x7e0849ec /* 150: dcbtstt r8,r9 */
20411 + .long 0xed406644 /* 154: dcffix f10,f12 */
20412 + .long 0xee80b645 /* 158: dcffix. f20,f22 */
20413 + .long 0x7d4b6068 /* 15c: lbarx r10,r11,r12 */
20414 + .long 0x7d4b6068 /* 160: lbarx r10,r11,r12 */
20415 + .long 0x7d4b6069 /* 164: lbarx r10,r11,r12,1 */
20416 + .long 0x7e95b0e8 /* 168: lharx r20,r21,r22 */
20417 + .long 0x7e95b0e8 /* 16c: lharx r20,r21,r22 */
20418 + .long 0x7e95b0e9 /* 170: lharx r20,r21,r22,1 */
20419 + .long 0x7d4b656d /* 174: stbcx. r10,r11,r12 */
20420 + .long 0x7d4b65ad /* 178: sthcx. r10,r11,r12 */
20421 + .long 0xfdc07830 /* 17c: fre f14,f15 */
20422 + .long 0xfdc07831 /* 180: fre. f14,f15 */
20423 + .long 0xedc07830 /* 184: fres f14,f15 */
20424 + .long 0xedc07831 /* 188: fres. f14,f15 */
20425 + .long 0xfdc07834 /* 18c: frsqrte f14,f15 */
20426 + .long 0xfdc07835 /* 190: frsqrte. f14,f15 */
20427 + .long 0xedc07834 /* 194: frsqrtes f14,f15 */
20428 + .long 0xedc07835 /* 198: frsqrtes. f14,f15 */
20429 + .long 0x7c43271e /* 19c: isel r2,r3,r4,28 */
20430 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
20431 new file mode 100644
20432 index 0000000..66f7a39
20434 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
20436 + .file "x86_64-vla-typedef.c"
20437 + .section .debug_abbrev,"",@progbits
20439 + .section .debug_info,"",@progbits
20441 + .section .debug_line,"",@progbits
20446 + .type foo, @function
20449 + .file 1 "x86_64-vla-typedef.c"
20457 + movl %edi, -36(%rbp)
20460 + movq %rax, -48(%rbp)
20462 + movl -36(%rbp), %edx
20465 + movq %rax, -24(%rbp)
20473 + movq %rsp, -56(%rbp)
20474 + movq -56(%rbp), %rax
20478 + movq %rax, -56(%rbp)
20479 + movq -56(%rbp), %rax
20480 + movq %rax, -16(%rbp)
20482 + movl $0, -4(%rbp)
20486 + movl -4(%rbp), %esi
20487 + movl -4(%rbp), %eax
20489 + movq -16(%rbp), %rdx
20491 + movb %cl, (%rdx,%rax)
20493 + addl $1, -4(%rbp)
20495 + movl -4(%rbp), %eax
20496 + cmpl -36(%rbp), %eax
20499 + .globl break_here
20501 + movq -16(%rbp), %rax
20503 + movq -48(%rbp), %rsp
20509 + .section .debug_frame,"",@progbits
20511 + .long .LECIE0-.LSCIE0
20527 + .long .LEFDE0-.LASFDE0
20531 + .quad .LFE2-.LFB2
20533 + .long .LCFI0-.LFB2
20539 + .long .LCFI1-.LCFI0
20544 + .section .eh_frame,"a",@progbits
20546 + .long .LECIE1-.LSCIE1
20564 + .long .LEFDE1-.LASFDE1
20566 + .long .LASFDE1-.Lframe1
20568 + .long .LFE2-.LFB2
20571 + .long .LCFI0-.LFB2
20577 + .long .LCFI1-.LCFI0
20584 + .section .debug_loc,"",@progbits
20587 + .quad .LFB2-.Ltext0
20588 + .quad .LCFI0-.Ltext0
20592 + .quad .LCFI0-.Ltext0
20593 + .quad .LCFI1-.Ltext0
20597 + .quad .LCFI1-.Ltext0
20598 + .quad .LFE2-.Ltext0
20604 + .section .debug_info
20605 + .long .Ldebug_end - .Ldebug_start
20608 + .long .Ldebug_abbrev0
20617 + .long .Ldebug_line0
20641 + .long .Ltag_array_type - .debug_info
20642 + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */
20647 + .long .Ltag_typedef - .debug_info
20649 + /* Debugging only: Skip the typedef indirection. */
20650 + .long .Ltag_array_type - .debug_info
20652 + /* DW_AT_location: DW_FORM_block1: start */
20657 + .byte 0x6 /* DW_OP_deref */
20659 + .byte 0x96 /* DW_OP_nop */
20661 + /* DW_AT_location: DW_FORM_block1: end */
20676 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
20677 + .long 0xa0 + (2f - 1f) /* DW_AT_type: DW_FORM_ref4 */
20678 + .long 0x9d + (2f - 1f) /* DW_AT_sibling: DW_FORM_ref4 */
20679 +1: /* DW_AT_data_location: DW_FORM_block1: start */
20680 + .byte 2f - 3f /* length */
20682 + .byte 0x97 /* DW_OP_push_object_address */
20683 + .byte 0x6 /* DW_OP_deref */
20684 +2: /* DW_AT_data_location: DW_FORM_block1: end */
20686 + .long 0x9d + (2b - 1b) /* DW_AT_type: DW_FORM_ref4 */
20701 + .section .debug_abbrev
20813 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
20816 + .uleb128 0x49 /* DW_AT_type */
20817 + .uleb128 0x13 /* DW_FORM_ref4 */
20818 + .uleb128 0x1 /* DW_AT_sibling */
20819 + .uleb128 0x13 /* DW_FORM_ref4 */
20820 + .uleb128 0x50 /* DW_AT_data_location */
20821 + .uleb128 0xa /* DW_FORM_block1 */
20827 + .uleb128 0x49 /* DW_AT_type */
20828 + .uleb128 0x13 /* DW_FORM_ref4 */
20854 + .section .debug_pubnames,"",@progbits
20857 + .long .Ldebug_info0
20862 + .section .debug_aranges,"",@progbits
20865 + .long .Ldebug_info0
20871 + .quad .Letext0-.Ltext0
20874 + .section .debug_str,"MS",@progbits,1
20880 + .string "x86_64-vla-typedef.c"
20882 + .string "array_t"
20886 + .string "gdb.arch"
20888 + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
20889 + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
20890 + .section .note.GNU-stack,"",@progbits
20891 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
20892 new file mode 100644
20893 index 0000000..b809c4e
20895 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
20897 +/* This testcase is part of GDB, the GNU debugger.
20899 + Copyright 2008 Free Software Foundation, Inc.
20901 + This program is free software; you can redistribute it and/or modify
20902 + it under the terms of the GNU General Public License as published by
20903 + the Free Software Foundation; either version 3 of the License, or
20904 + (at your option) any later version.
20906 + This program is distributed in the hope that it will be useful,
20907 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20908 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20909 + GNU General Public License for more details.
20911 + You should have received a copy of the GNU General Public License
20912 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
20919 + typedef char array_t[size];
20923 + for (i = 0; i < size; i++)
20926 + array[0] = 0; /* break-here */
20940 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
20941 new file mode 100644
20942 index 0000000..b05411e
20944 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
20946 +# Copyright 2009 Free Software Foundation, Inc.
20948 +# This program is free software; you can redistribute it and/or modify
20949 +# it under the terms of the GNU General Public License as published by
20950 +# the Free Software Foundation; either version 3 of the License, or
20951 +# (at your option) any later version.
20953 +# This program is distributed in the hope that it will be useful,
20954 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
20955 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20956 +# GNU General Public License for more details.
20958 +# You should have received a copy of the GNU General Public License
20959 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
20961 +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
20963 +if ![istarget "x86_64-*-*"] then {
20964 + verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
20968 +set testfile x86_64-vla-typedef
20969 +set srcasmfile ${testfile}-foo.S
20970 +set srcfile ${testfile}.c
20971 +set binfile ${objdir}/${subdir}/${testfile}
20972 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
20973 +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
20974 + untested "Couldn't compile test program"
20977 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
20978 + untested "Couldn't compile test program"
20984 +gdb_reinitialize_dir $srcdir/$subdir
20985 +gdb_load ${binfile}
20987 +if ![runto_main] {
20988 + untested x86_64-vla-typedef
20992 +gdb_breakpoint "break_here"
20994 +gdb_continue_to_breakpoint "break_here"
20996 +gdb_test "whatis array" "type = array_t" "first: whatis array"
20998 +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
21000 +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
21001 +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
21002 +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
21003 +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
21005 +gdb_continue_to_breakpoint "break_here"
21007 +gdb_test "whatis array" "type = array_t" "second: whatis array"
21009 +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
21010 diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
21011 index 98d4d35..f98a656 100644
21012 --- a/gdb/testsuite/gdb.base/arrayidx.c
21013 +++ b/gdb/testsuite/gdb.base/arrayidx.c
21016 int array[] = {1, 2, 3, 4};
21028 diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
21029 index 71ce4aa..af0e5f8 100644
21030 --- a/gdb/testsuite/gdb.base/arrayidx.exp
21031 +++ b/gdb/testsuite/gdb.base/arrayidx.exp
21032 @@ -59,4 +59,12 @@ gdb_test "print array" \
21033 "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
21034 "Print array with array-indexes on"
21037 +set test "p unbound.a == &unbound.a\[0\]"
21038 +gdb_test_multiple $test $test {
21039 + -re " = 1\r\n$gdb_prompt $" {
21042 + -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
21043 + unsupported "$test (no GCC)"
21046 diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
21047 index d76cc36..496ff18 100644
21048 --- a/gdb/testsuite/gdb.base/help.exp
21049 +++ b/gdb/testsuite/gdb.base/help.exp
21050 @@ -606,7 +606,7 @@ gdb_test "help stepi" "Step one instruction exactly\.\[\r\n\]+Argument N means d
21051 gdb_test "help signal" "Continue program giving it signal.*" "help signal"
21053 # vxgdb reads .vxgdbinit
21054 -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"
21055 +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"
21057 test_class_help "stack" {
21058 "Examining the stack\..*\[\r\n\]+"
21059 diff --git a/gdb/testsuite/gdb.base/lineno-makeup-func.c b/gdb/testsuite/gdb.base/lineno-makeup-func.c
21060 new file mode 100644
21061 index 0000000..1a0220e
21063 +++ b/gdb/testsuite/gdb.base/lineno-makeup-func.c
21065 +/* This testcase is part of GDB, the GNU debugger.
21067 + Copyright 2009 Free Software Foundation, Inc.
21069 + This program is free software; you can redistribute it and/or modify
21070 + it under the terms of the GNU General Public License as published by
21071 + the Free Software Foundation; either version 3 of the License, or
21072 + (at your option) any later version.
21074 + This program is distributed in the hope that it will be useful,
21075 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21076 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21077 + GNU General Public License for more details.
21079 + You should have received a copy of the GNU General Public License
21080 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21086 diff --git a/gdb/testsuite/gdb.base/lineno-makeup.c b/gdb/testsuite/gdb.base/lineno-makeup.c
21087 new file mode 100644
21088 index 0000000..bb20e98
21090 +++ b/gdb/testsuite/gdb.base/lineno-makeup.c
21092 +/* This testcase is part of GDB, the GNU debugger.
21094 + Copyright 2009 Free Software Foundation, Inc.
21096 + This program is free software; you can redistribute it and/or modify
21097 + it under the terms of the GNU General Public License as published by
21098 + the Free Software Foundation; either version 3 of the License, or
21099 + (at your option) any later version.
21101 + This program is distributed in the hope that it will be useful,
21102 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21103 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21104 + GNU General Public License for more details.
21106 + You should have received a copy of the GNU General Public License
21107 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21109 +/* DW_AT_low_pc-DW_AT_high_pc should cover the function without line number
21110 + information (.debug_line) so we cannot use an external object file.
21112 + It must not be just a label as it would alias on the next function even for
21113 + correct GDB. Therefore some stub data must be placed there.
21115 + We need to provide a real stub function body as at least s390
21116 + (s390_analyze_prologue) would skip the whole body till reaching `main'. */
21118 +extern void func (void);
21119 +asm ("func: .incbin \"gdb.base/lineno-makeup-func.bin\"");
21127 diff --git a/gdb/testsuite/gdb.base/lineno-makeup.exp b/gdb/testsuite/gdb.base/lineno-makeup.exp
21128 new file mode 100644
21129 index 0000000..0c75b84
21131 +++ b/gdb/testsuite/gdb.base/lineno-makeup.exp
21133 +# Copyright 2009 Free Software Foundation, Inc.
21135 +# This program is free software; you can redistribute it and/or modify
21136 +# it under the terms of the GNU General Public License as published by
21137 +# the Free Software Foundation; either version 3 of the License, or
21138 +# (at your option) any later version.
21140 +# This program is distributed in the hope that it will be useful,
21141 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21142 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21143 +# GNU General Public License for more details.
21145 +# You should have received a copy of the GNU General Public License
21146 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21148 +set testfile "lineno-makeup"
21149 +set srcfuncfile ${testfile}-func.c
21150 +set srcfile ${testfile}.c
21151 +set objfuncfile ${objdir}/${subdir}/${testfile}-func.o
21152 +set binfuncfile ${objdir}/${subdir}/${testfile}-func.bin
21153 +set binfile ${objdir}/${subdir}/${testfile}
21155 +if { [gdb_compile "${srcdir}/${subdir}/${srcfuncfile}" "${objfuncfile}" object {}] != "" } {
21156 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21159 +set objcopy [catch "exec objcopy -O binary --only-section .text ${objfuncfile} ${binfuncfile}" output]
21160 +verbose -log "objcopy=$objcopy: $output"
21161 +if { $objcopy != 0 } {
21162 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21164 +set binfuncfilesize [file size $binfuncfile]
21165 +verbose -log "file size $binfuncfile = $binfuncfilesize"
21167 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21168 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
21173 +gdb_reinitialize_dir $srcdir/$subdir
21174 +gdb_load ${binfile}
21177 +set test "break func"
21178 +gdb_test_multiple $test $test {
21179 + -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
21180 + set b_addr $expect_out(1,string)
21183 + -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+): .*\r\n$gdb_prompt $" {
21184 + set b_addr $expect_out(1,string)
21188 +verbose -log "b_addr=<$b_addr>"
21191 +set test "print func"
21192 +gdb_test_multiple $test $test {
21193 + -re "\\$\[0-9\]+ = {<text variable, no debug info>} (0x\[0-9a-f\]+) <func>\r\n$gdb_prompt $" {
21194 + set p_addr $expect_out(1,string)
21198 +verbose -log "p_addr=<$p_addr>"
21200 +set test "break address belongs to func"
21201 +if {$b_addr == $p_addr} {
21202 + pass "$test (exact match)"
21204 + set skip [expr $b_addr - $p_addr]
21205 + if {$skip > 0 && $skip < $binfuncfilesize} {
21206 + pass "$test (prologue skip by $skip bytes)"
21211 diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
21212 index 55c4d31..df25d3c 100644
21213 --- a/gdb/testsuite/gdb.base/macscp.exp
21214 +++ b/gdb/testsuite/gdb.base/macscp.exp
21215 @@ -33,6 +33,14 @@ if [test_compiler_info gcc*] {
21216 lappend options additional_flags=-g3
21219 +# Workaround ccache making lineno non-zero for command-line definitions.
21220 +if {[find_gcc] == "gcc" && [file executable "/usr/bin/gcc"]} {
21221 + set result [catch "exec which gcc" output]
21222 + if {$result == 0 && [string first "/ccache/" $output] >= -1} {
21223 + lappend options "compiler=/usr/bin/gcc"
21227 # Generate the intermediate object file. This is required by Darwin to
21228 # have access to the .debug_macinfo section.
21229 if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \
21230 diff --git a/gdb/testsuite/gdb.base/radix.exp b/gdb/testsuite/gdb.base/radix.exp
21231 index 750fd23..dfdb929 100644
21232 --- a/gdb/testsuite/gdb.base/radix.exp
21233 +++ b/gdb/testsuite/gdb.base/radix.exp
21234 @@ -162,13 +162,6 @@ gdb_test "set radix" \
21235 "Input and output radices now set to decimal 10, hex a, octal 12\." \
21238 -gdb_test "set input-radix 0" \
21239 - "Nonsense input radix ``decimal 0''; input radix unchanged\\." \
21240 - "Reject input-radix 0"
21241 -gdb_test "show input-radix" \
21242 - "Default input radix for entering numbers is 10\\." \
21243 - "Input radix unchanged after rejecting 0"
21245 gdb_test "set input-radix 1" \
21246 "Nonsense input radix ``decimal 1''; input radix unchanged\\." \
21247 "Reject input-radix 1"
21248 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.c b/gdb/testsuite/gdb.base/valgrind-attach.c
21249 new file mode 100644
21250 index 0000000..84b57db
21252 +++ b/gdb/testsuite/gdb.base/valgrind-attach.c
21254 +/* This testcase is part of GDB, the GNU debugger.
21256 + Copyright 2009 Free Software Foundation, Inc.
21258 + This program is free software; you can redistribute it and/or modify
21259 + it under the terms of the GNU General Public License as published by
21260 + the Free Software Foundation; either version 3 of the License, or
21261 + (at your option) any later version.
21263 + This program is distributed in the hope that it will be useful,
21264 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21265 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21266 + GNU General Public License for more details.
21268 + You should have received a copy of the GNU General Public License
21269 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21271 +#include <stdlib.h>
21276 + int *a = malloc (1);
21278 + a[10] = 0; /* crash-here */
21282 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.exp b/gdb/testsuite/gdb.base/valgrind-attach.exp
21283 new file mode 100644
21284 index 0000000..1f9b26e
21286 +++ b/gdb/testsuite/gdb.base/valgrind-attach.exp
21288 +# Copyright 2009 Free Software Foundation, Inc.
21290 +# This program is free software; you can redistribute it and/or modify
21291 +# it under the terms of the GNU General Public License as published by
21292 +# the Free Software Foundation; either version 3 of the License, or
21293 +# (at your option) any later version.
21295 +# This program is distributed in the hope that it will be useful,
21296 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21297 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21298 +# GNU General Public License for more details.
21300 +# You should have received a copy of the GNU General Public License
21301 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21303 +set testfile valgrind-attach
21304 +set shfile ${testfile}.sh
21305 +set srcfile ${testfile}.c
21306 +set binfile ${objdir}/${subdir}/${testfile}
21307 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21308 + untested "Couldn't compile test program"
21313 +gdb_stop_suppressing_tests;
21315 +set VALGRIND "valgrind"
21317 +# Syntax for ${shfile} is: <binfile> <valgrind> <db-command-arguments>
21318 +set VALGRIND_SPAWN "sh ${srcdir}/${subdir}/${shfile} $binfile $VALGRIND $GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"
21320 +set test "spawn valgrind"
21321 +verbose "Spawning $VALGRIND_SPAWN"
21323 +if [info exists gdb_spawn_id] {
21328 +if ![is_remote host] {
21329 + if { [which $VALGRIND] == 0 } then {
21330 + untested "Couldn't find $VALGRIND"
21334 +set res [remote_spawn host "$VALGRIND_SPAWN"]
21335 +if { $res < 0 || $res == "" } {
21336 + perror "Spawning $VALGRIND_SPAWN failed."
21339 +set gdb_spawn_id -1;
21342 + -re "---- Attach to debugger \\? --- \\\[Return/N/n/Y/y/C/c\\\] ---- $" {
21346 + perror "(eof) $VALGRIND never initialized"
21347 + remote_close host
21351 + perror "(timeout) $VALGRIND never initialized"
21352 + remote_close host
21358 +set test "spawn gdb"
21359 +set test2 "crash line caught"
21361 + -re "starting debugger with cmd:.* in main .* crash-here .*\[\r\n\]$gdb_prompt $" {
21365 + -re "starting debugger with cmd:.*\[\r\n\]$gdb_prompt $" {
21370 + perror "(eof) $GDB never initialized"
21371 + remote_close host
21375 + perror "(timeout) $GDB never initialized"
21376 + remote_close host
21382 diff --git a/gdb/testsuite/gdb.base/valgrind-attach.sh b/gdb/testsuite/gdb.base/valgrind-attach.sh
21383 new file mode 100755
21384 index 0000000..f02c6f7
21386 +++ b/gdb/testsuite/gdb.base/valgrind-attach.sh
21390 +# Copyright 2009 Free Software Foundation, Inc.
21392 +# This program is free software; you can redistribute it and/or modify
21393 +# it under the terms of the GNU General Public License as published by
21394 +# the Free Software Foundation; either version 3 of the License, or
21395 +# (at your option) any later version.
21397 +# This program is distributed in the hope that it will be useful,
21398 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21399 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21400 +# GNU General Public License for more details.
21402 +# You should have received a copy of the GNU General Public License
21403 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21405 +BINFILE="$1"; shift
21406 +VALGRIND="$1"; shift
21407 +"$VALGRIND" --db-attach=yes --db-command="$* %f %p" "$BINFILE"
21408 diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
21409 new file mode 100644
21410 index 0000000..c5d5ee0
21412 +++ b/gdb/testsuite/gdb.base/vla-overflow.c
21414 +/* This testcase is part of GDB, the GNU debugger.
21416 + Copyright 2008 Free Software Foundation, Inc.
21418 + This program is free software; you can redistribute it and/or modify
21419 + it under the terms of the GNU General Public License as published by
21420 + the Free Software Foundation; either version 3 of the License, or
21421 + (at your option) any later version.
21423 + This program is distributed in the hope that it will be useful,
21424 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21425 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21426 + GNU General Public License for more details.
21428 + You should have received a copy of the GNU General Public License
21429 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21431 +#include <stdlib.h>
21434 +main (int argc, char **argv)
21438 + array[0] = array[0];
21444 diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
21445 new file mode 100644
21446 index 0000000..7203a48
21448 +++ b/gdb/testsuite/gdb.base/vla-overflow.exp
21450 +# Copyright 2008 Free Software Foundation, Inc.
21452 +# This program is free software; you can redistribute it and/or modify
21453 +# it under the terms of the GNU General Public License as published by
21454 +# the Free Software Foundation; either version 3 of the License, or
21455 +# (at your option) any later version.
21457 +# This program is distributed in the hope that it will be useful,
21458 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21459 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21460 +# GNU General Public License for more details.
21462 +# You should have received a copy of the GNU General Public License
21463 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21465 +# We could crash in:
21466 +# #0 block_linkage_function (bl=0x0) at ../../gdb/block.c:69
21467 +# #1 in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
21468 +# 97 framefunc = block_linkage_function (get_frame_block (frame, NULL));
21469 +# #2 in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
21470 +# #3 in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
21471 +# #4 dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
21472 +# #5 in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
21473 +# #6 in create_array_type (...) at ../../gdb/gdbtypes.c:840
21475 +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
21477 +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
21479 +set testfile vla-overflow
21480 +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
21481 +set srcfile ${testfile}.c
21482 +set binfile ${objdir}/${subdir}/${testfile}
21483 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21484 + untested "Couldn't compile test program"
21488 +set f [open "|getconf PAGESIZE" "r"]
21494 +gdb_reinitialize_dir $srcdir/$subdir
21495 +gdb_load ${binfile}
21497 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
21499 +if { [runto_main] < 0 } {
21500 + untested vla-overflow
21504 +# Get the GDB memory size when we stay at main.
21506 +proc memory_v_pages_get {} {
21507 + global pid_of_gdb pagesize
21508 + set fd [open "/proc/$pid_of_gdb/statm"]
21511 + # number of pages of virtual memory
21512 + scan $line "%d" drs
21516 +set pages_found [memory_v_pages_get]
21519 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
21520 +set kb_found [expr $pages_found * $pagesize / 1024]
21521 +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
21522 +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
21524 +# Create the ulimit wrapper.
21525 +set f [open $shfile "w"]
21526 +puts $f "#! /bin/sh"
21527 +puts $f "ulimit -v $kb_permit"
21528 +puts $f "exec $GDB \"\$@\""
21530 +remote_exec host "chmod +x $shfile"
21538 +gdb_reinitialize_dir $srcdir/$subdir
21539 +gdb_load ${binfile}
21541 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
21543 +# Check the size again after the second run.
21544 +# We must not stop in main as it would cache `array' and never crash later.
21548 +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21550 +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
21552 +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21554 +# `abort' can get expressed as `*__GI_abort'.
21555 +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
21557 +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
21558 diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
21559 new file mode 100644
21560 index 0000000..e1f3ed1
21562 +++ b/gdb/testsuite/gdb.base/vla.c
21564 +/* This testcase is part of GDB, the GNU debugger.
21566 + Copyright 2008 Free Software Foundation, Inc.
21568 + This program is free software; you can redistribute it and/or modify
21569 + it under the terms of the GNU General Public License as published by
21570 + the Free Software Foundation; either version 3 of the License, or
21571 + (at your option) any later version.
21573 + This program is distributed in the hope that it will be useful,
21574 + but WITHOUT ANY WARRANTY; without even the implied warranty of
21575 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21576 + GNU General Public License for more details.
21578 + You should have received a copy of the GNU General Public License
21579 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
21581 +#include <string.h>
21589 +bar (char *a, char *b, char *c, int size)
21591 + memset (a, '1', size);
21592 + memset (b, '2', size);
21593 + memset (c, '3', 48);
21599 + char temp1[size];
21602 + temp1[size - 1] = '\0';
21604 + char temp2[size];
21606 + bar (temp1, temp2, temp3, size);
21608 + marker (); /* break-here */
21619 diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
21620 new file mode 100644
21621 index 0000000..5da7378
21623 +++ b/gdb/testsuite/gdb.base/vla.exp
21625 +# Copyright 2008 Free Software Foundation, Inc.
21627 +# This program is free software; you can redistribute it and/or modify
21628 +# it under the terms of the GNU General Public License as published by
21629 +# the Free Software Foundation; either version 3 of the License, or
21630 +# (at your option) any later version.
21632 +# This program is distributed in the hope that it will be useful,
21633 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21634 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21635 +# GNU General Public License for more details.
21637 +# You should have received a copy of the GNU General Public License
21638 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
21641 +set srcfile ${testfile}.c
21642 +set binfile ${objdir}/${subdir}/${testfile}
21643 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21644 + untested "Couldn't compile test program"
21650 +gdb_reinitialize_dir $srcdir/$subdir
21651 +gdb_load ${binfile}
21653 +if ![runto_main] {
21658 +gdb_breakpoint [gdb_get_line_number "break-here"]
21660 +gdb_continue_to_breakpoint "break-here"
21662 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
21663 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
21664 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
21666 +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
21667 +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
21668 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
21670 +gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
21671 +gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
21672 +gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
21674 +gdb_continue_to_breakpoint "break-here"
21676 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
21677 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
21678 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
21680 +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
21681 +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
21682 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
21684 +gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
21685 +gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
21686 +gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
21687 diff --git a/gdb/testsuite/gdb.base/watchpoint-hw.c b/gdb/testsuite/gdb.base/watchpoint-hw.c
21688 index 8da9af5..e2de53a 100644
21689 --- a/gdb/testsuite/gdb.base/watchpoint-hw.c
21690 +++ b/gdb/testsuite/gdb.base/watchpoint-hw.c
21691 @@ -20,5 +20,11 @@ int watchee;
21695 + volatile int dummy;
21699 + dummy = 2; /* break-at-exit */
21703 diff --git a/gdb/testsuite/gdb.base/watchpoint-hw.exp b/gdb/testsuite/gdb.base/watchpoint-hw.exp
21704 index a2bb731..d74d6c7 100644
21705 --- a/gdb/testsuite/gdb.base/watchpoint-hw.exp
21706 +++ b/gdb/testsuite/gdb.base/watchpoint-hw.exp
21707 @@ -21,19 +21,12 @@ if {(![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"]
21711 -set testfile watchpoint-hw
21712 -set srcfile ${testfile}.c
21713 -set binfile ${objdir}/${subdir}/${testfile}
21714 -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
21715 - untested "Couldn't compile test program"
21716 +set test watchpoint-hw
21717 +set srcfile ${test}.c
21718 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile}] } {
21724 -gdb_reinitialize_dir $srcdir/$subdir
21725 -gdb_load ${binfile}
21727 # Create the watchpoint before the inferior gets started. Now the native CPU
21728 # target is still not active and its `to_can_use_hw_breakpoint' is not
21729 # installed, therefore only a software watchpoint gets created.
21730 @@ -43,10 +36,40 @@ gdb_test "watch watchee" "atchpoint 1: watchee"
21731 # `runto_main' or `runto main' would delete the watchpoint created above.
21733 if { [gdb_start_cmd] < 0 } {
21735 + untested ${test}.exp
21738 gdb_test "" "main .* at .*" "start"
21740 # Check it is really a `hw'-watchpoint.
21741 gdb_test "info watchpoints" "1 *hw watchpoint .* watchee"
21743 +# Before the inferior gets started we would get:
21744 +# Target does not support this type of hardware watchpoint.
21745 +gdb_test "delete 1"
21746 +gdb_test "rwatch watchee"
21748 +set breakline [gdb_get_line_number "break-at-exit"]
21749 +gdb_breakpoint $breakline
21751 +gdb_test "continue" "Continuing.\r\nHardware read watchpoint 3: watchee\r\n\r\nValue = 0\r\n.*"
21753 +# Here should be no repeated notification of the read watchpoint.
21754 +gdb_test "continue" \
21755 + "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \
21756 + "continue to break-at-exit after rwatch"
21758 +clean_restart ${test}
21760 +if ![runto_main] {
21761 + untested ${test}.exp
21765 +gdb_test "hbreak ${srcfile}:${breakline}" \
21766 + "Hardware assisted breakpoint 2 at 0x\[0-9a-f\]+: file .*${srcfile}, line ${breakline}\\." \
21769 +gdb_test "continue" \
21770 + "Continuing\\.\[ \r\n\]+Breakpoint \[0-9\]+, .*break-at-exit.*" \
21771 + "continue to break-at-exit after hbreak"
21772 diff --git a/gdb/testsuite/gdb.cp/Makefile.in b/gdb/testsuite/gdb.cp/Makefile.in
21773 index 0a087c7..b4880f2 100644
21774 --- a/gdb/testsuite/gdb.cp/Makefile.in
21775 +++ b/gdb/testsuite/gdb.cp/Makefile.in
21776 @@ -4,7 +4,7 @@ srcdir = @srcdir@
21777 EXECUTABLES = ambiguous annota2 anon-union cplusfuncs cttiadd \
21778 derivation inherit local member-ptr method misc \
21779 overload ovldbreak ref-typ ref-typ2 templates userdef virtfunc namespace \
21780 - ref-types ref-params method2 pr9594 gdb2495
21781 + ref-types ref-params method2 pr9594 gdb2495 gdb9593
21783 all info install-info dvi install uninstall installcheck check:
21784 @echo "Nothing to be done for $@..."
21785 diff --git a/gdb/testsuite/gdb.cp/cp-relocate.exp b/gdb/testsuite/gdb.cp/cp-relocate.exp
21786 index 4095ccf..03c07d5 100644
21787 --- a/gdb/testsuite/gdb.cp/cp-relocate.exp
21788 +++ b/gdb/testsuite/gdb.cp/cp-relocate.exp
21789 @@ -30,7 +30,7 @@ proc get_func_address { func } {
21790 global gdb_prompt hex
21792 set rfunc [string_to_regexp $func]
21793 - gdb_test_multiple "print '${func}'" "get address of ${func}" {
21794 + gdb_test_multiple "print ${func}" "get address of ${func}" {
21795 -re "\\\$\[0-9\]+ = \\{.*\\} (0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
21796 # $1 = {int ()} 0x24 <function_bar>
21797 # But if the function is at zero, the name may be omitted.
21798 @@ -130,7 +130,7 @@ gdb_test "add-symbol-file ${binfile} 0 -s ${func1_sec} 0x10000 -s ${func2_sec} 0
21801 # Make sure the function addresses were updated.
21802 -gdb_test "break *'$func1_name'" \
21803 +gdb_test "break *$func1_name" \
21804 "Breakpoint $decimal at 0x1....: file .*"
21805 -gdb_test "break *'$func2_name'" \
21806 +gdb_test "break *$func2_name" \
21807 "Breakpoint $decimal at 0x2....: file .*"
21808 diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.cc b/gdb/testsuite/gdb.cp/cplusfuncs.cc
21809 index 7f033d6..11dba06 100644
21810 --- a/gdb/testsuite/gdb.cp/cplusfuncs.cc
21811 +++ b/gdb/testsuite/gdb.cp/cplusfuncs.cc
21812 @@ -46,7 +46,9 @@ public:
21813 void operator [] (foo&);
21814 void operator () (foo&);
21815 void* operator new (size_t) throw ();
21816 + void* operator new[] (size_t) throw ();
21817 void operator delete (void *);
21818 + void operator delete[] (void *);
21819 /**/ operator int ();
21820 /**/ operator char* ();
21822 @@ -115,7 +117,9 @@ void foo::operator ->* (foo& afoo) { afoo.ifoo = 0; }
21823 void foo::operator [] (foo& afoo) { afoo.ifoo = 0; }
21824 void foo::operator () (foo& afoo) { afoo.ifoo = 0; }
21825 void* foo::operator new (size_t ival) throw () { ival = 0; return 0; }
21826 +void* foo::operator new[] (size_t ival) throw () { ival = 0; return 0; }
21827 void foo::operator delete (void *ptr) { ptr = 0; }
21828 +void foo::operator delete[] (void *ptr) { ptr = 0; }
21829 /**/ foo::operator int () { return 0; }
21830 /**/ foo::operator char* () { return 0; }
21832 @@ -191,6 +195,12 @@ char * dm_type_char_star (char * p) { return p; }
21833 int dm_type_foo_ref (foo & foo) { return foo.ifoo; }
21834 int * dm_type_int_star (int * p) { return p; }
21835 long * dm_type_long_star (long * p) { return p; }
21836 +int dm_type_short (short i) { return i; }
21837 +int dm_type_long (long i) { return i; }
21838 int dm_type_unsigned_int (unsigned int i) { return i; }
21839 +int dm_type_unsigned_short (unsigned short i) { return i; }
21840 +int dm_type_unsigned_long (unsigned long i) { return i; }
21841 int dm_type_void (void) { return 0; }
21842 void * dm_type_void_star (void * p) { return p; }
21843 +typedef int myint;
21844 +int dm_type_typedef (myint i) { return i; }
21845 diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp
21846 index 5e08768..2ec50ca 100644
21847 --- a/gdb/testsuite/gdb.cp/cplusfuncs.exp
21848 +++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp
21849 @@ -63,12 +63,28 @@ set dm_type_foo_ref "foo&"
21850 set dm_type_int_star "int*"
21851 set dm_type_long_star "long*"
21852 set dm_type_unsigned_int "unsigned"
21853 -set dm_type_void ""
21854 +set dm_type_void "void"
21855 set dm_type_void_star "void*"
21857 +# Some other vagaries of GDB's type printing machinery. The integer types
21858 +# may have unsigned before or after their length, and may have "int"
21859 +# appended. The char* conversion operator may have name "char*" even if
21860 +# the type is "char *", because the name comes from the debug information
21861 +# and the type from GDB. Function types may not see through typedefs.
21863 +set dm_type_short "short"
21864 +set dm_type_long "long"
21865 +set dm_type_unsigned_short "unsigned short"
21866 +set dm_type_unsigned_long "unsigned long"
21867 +set dm_operator_char_star "char*"
21868 +set dm_operator_char_star_quoted "char\\*"
21869 +set dm_type_typedef 0
21871 proc probe_demangler { } {
21873 global dm_operator_comma
21874 + global dm_operator_char_star
21875 + global dm_operator_char_star_quoted
21876 global dm_type_char_star
21877 global dm_type_char_star_quoted
21878 global dm_type_foo_ref
21879 @@ -77,8 +93,13 @@ proc probe_demangler { } {
21880 global dm_type_unsigned_int
21881 global dm_type_void
21882 global dm_type_void_star
21883 + global dm_type_short
21884 + global dm_type_unsigned_short
21885 + global dm_type_long
21886 + global dm_type_unsigned_long
21887 + global dm_type_typedef
21889 - send_gdb "print &'foo::operator,(foo&)'\n"
21890 + send_gdb "print &foo::operator,(foo&)\n"
21892 -re ".*foo::operator, \\(.*foo.*&.*\\).*\r\n$gdb_prompt $" {
21894 @@ -97,6 +118,26 @@ proc probe_demangler { } {
21898 + send_gdb "print &foo::operator char*($dm_type_void)\n"
21900 + -re ".*foo::operator char \\*\\(void\\).*\r\n$gdb_prompt $" {
21901 + # v2 demangler or GDB type printer
21902 + set dm_operator_char_star "char *"
21903 + set dm_operator_char_star_quoted "char \\*"
21904 + pass "detect dm_operator_char_star"
21906 + -re ".*foo::operator char\\*\\(\\).*\r\n$gdb_prompt $" {
21908 + pass "detect dm_operator_char_star"
21910 + -re ".*$gdb_prompt $" {
21911 + fail "detect dm_operator_char_star"
21914 + fail "detect dm_operator_char_star"
21918 send_gdb "print &'dm_type_char_star'\n"
21920 -re ".*dm_type_char_star\\(char \\*\\).*\r\n$gdb_prompt $" {
21921 @@ -166,6 +207,11 @@ proc probe_demangler { } {
21923 pass "detect dm_type_long_star"
21925 + -re ".*dm_type_long_star\\(long int \\*\\).*\r\n$gdb_prompt $" {
21926 + # GCC v3 and GDB's type printer
21927 + set dm_type_long_star "long int *"
21928 + pass "detect dm_type_long_star"
21930 -re ".*$gdb_prompt $" {
21931 fail "detect dm_type_long_star"
21933 @@ -230,6 +276,101 @@ proc probe_demangler { } {
21934 fail "detect dm_type_void_star (timeout)"
21938 + send_gdb "print &'dm_type_short'\n"
21940 + -re ".*dm_type_short\\(short\\).*\r\n$gdb_prompt $" {
21941 + # v2 and v3 demanglers
21942 + pass "detect dm_type_short"
21944 + -re ".*dm_type_short\\(short int\\).*\r\n$gdb_prompt $" {
21945 + # GDB type printer
21946 + set dm_type_short "short int"
21947 + pass "detect dm_type_short"
21949 + -re ".*$gdb_prompt $" {
21950 + fail "detect dm_type_short"
21953 + fail "detect dm_type_short (timeout)"
21957 + send_gdb "print &'dm_type_unsigned_short'\n"
21959 + -re ".*dm_type_unsigned_short\\(unsigned short\\).*\r\n$gdb_prompt $" {
21960 + # v2 and v3 demanglers
21961 + pass "detect dm_type_unsigned_short"
21963 + -re ".*dm_type_unsigned_short\\(short unsigned int\\).*\r\n$gdb_prompt $" {
21964 + # GDB type printer
21965 + set dm_type_unsigned_short "short unsigned int"
21966 + pass "detect dm_type_unsigned_short"
21968 + -re ".*$gdb_prompt $" {
21969 + fail "detect dm_type_unsigned_short"
21972 + fail "detect dm_type_unsigned_short (timeout)"
21976 + send_gdb "print &'dm_type_long'\n"
21978 + -re ".*dm_type_long\\(long\\).*\r\n$gdb_prompt $" {
21979 + # v2 and v3 demanglers
21980 + pass "detect dm_type_long"
21982 + -re ".*dm_type_long\\(long int\\).*\r\n$gdb_prompt $" {
21983 + # GDB type printer
21984 + set dm_type_long "long int"
21985 + pass "detect dm_type_long"
21987 + -re ".*$gdb_prompt $" {
21988 + fail "detect dm_type_long"
21991 + fail "detect dm_type_long (timeout)"
21995 + send_gdb "print &'dm_type_unsigned_long'\n"
21997 + -re ".*dm_type_unsigned_long\\(unsigned long\\).*\r\n$gdb_prompt $" {
21998 + # v2 and v3 demanglers
21999 + pass "detect dm_type_unsigned_long"
22001 + -re ".*dm_type_unsigned_long\\(long unsigned int\\).*\r\n$gdb_prompt $" {
22002 + # GDB type printer
22003 + set dm_type_unsigned_long "long unsigned int"
22004 + pass "detect dm_type_unsigned_long"
22006 + -re ".*$gdb_prompt $" {
22007 + fail "detect dm_type_unsigned_long"
22010 + fail "detect dm_type_unsigned_long (timeout)"
22014 + send_gdb "print &'dm_type_typedef'\n"
22016 + -re ".*dm_type_typedef\\(int\\).*\r\n$gdb_prompt $" {
22017 + # v2 and v3 demanglers
22018 + pass "detect dm_type_typedef"
22020 + -re ".*dm_type_typedef\\(myint\\).*\r\n$gdb_prompt $" {
22021 + # GDB type printer
22022 + set dm_type_typedef 1
22023 + pass "detect dm_type_typedef"
22025 + -re ".*$gdb_prompt $" {
22026 + fail "detect dm_type_typedef"
22029 + fail "detect dm_type_typedef (timeout)"
22035 @@ -241,6 +382,7 @@ proc info_func_regexp { name demangled } {
22038 send_gdb "info function $name\n"
22039 + set demangled [regsub {\\\(void\\\)} $demangled {\(\)}]
22041 -re ".*File .*:\r\n(class |)$demangled\r\n.*$gdb_prompt $" {
22042 pass "info function for \"$name\""
22043 @@ -277,16 +419,16 @@ proc print_addr_2 { name good } {
22045 set good_pattern [string_to_regexp $good]
22047 - send_gdb "print &'$name'\n"
22048 + send_gdb "print &$name\n"
22050 -re ".* = .* $hex <$good_pattern>\r\n$gdb_prompt $" {
22051 - pass "print &'$name'"
22052 + pass "print &$name"
22054 -re ".*$gdb_prompt $" {
22055 - fail "print &'$name'"
22056 + fail "print &$name"
22059 - fail "print &'$name' (timeout)"
22060 + fail "print &$name (timeout)"
22064 @@ -327,7 +469,12 @@ proc print_addr_2_kfail { name good bad bugid } {
22067 proc print_addr { name } {
22068 - print_addr_2 "$name" "$name"
22069 + set expected [regsub {\(void\)} $name {()}]
22070 + if {[string first "::" $name] == -1} {
22071 + # C function -- must be qutoed
22072 + set name "'$name'"
22074 + print_addr_2 "$name" $expected
22078 @@ -345,8 +492,9 @@ proc print_addr { name } {
22080 proc test_lookup_operator_functions {} {
22081 global dm_operator_comma
22082 + global dm_operator_char_star
22083 global dm_type_char_star
22084 - global dm_type_char_star_quoted
22085 + global dm_operator_char_star_quoted
22086 global dm_type_foo_ref
22087 global dm_type_void
22088 global dm_type_void_star
22089 @@ -404,8 +552,8 @@ proc test_lookup_operator_functions {} {
22091 info_func "operator int(" "int foo::operator int($dm_type_void);"
22092 info_func "operator()(" "void foo::operator()($dm_type_foo_ref);"
22093 - info_func "operator $dm_type_char_star_quoted\(" \
22094 - "char *foo::operator $dm_type_char_star\($dm_type_void);"
22095 + info_func "operator $dm_operator_char_star_quoted\(" \
22096 + "char *foo::operator $dm_operator_char_star\($dm_type_void);"
22100 @@ -420,6 +568,7 @@ proc test_paddr_operator_functions {} {
22101 global dm_type_unsigned_int
22102 global dm_type_void
22103 global dm_type_void_star
22104 + global dm_operator_char_star
22106 print_addr "foo::operator*($dm_type_foo_ref)"
22107 print_addr "foo::operator%($dm_type_foo_ref)"
22108 @@ -460,17 +609,20 @@ proc test_paddr_operator_functions {} {
22109 print_addr "foo::operator\[\]($dm_type_foo_ref)"
22110 print_addr "foo::operator()($dm_type_foo_ref)"
22112 - gdb_test "print &'foo::operator new'" \
22113 + gdb_test "print &foo::operator new" \
22114 " = .* $hex <foo::operator new\\(.*\\)(| static)>"
22115 + gdb_test "print &foo::operator new\[\]" \
22116 + " = .* $hex <foo::operator new\\\[\\\]\\(.*\\)(| static)>"
22117 if { !$hp_aCC_compiler } {
22118 print_addr "foo::operator delete($dm_type_void_star)"
22119 + print_addr "foo::operator delete[]($dm_type_void_star)"
22121 gdb_test "print &'foo::operator delete($dm_type_void_star) static'" \
22122 " = .*(0x\[0-9a-f\]+|) <foo::operator delete.*>"
22125 print_addr "foo::operator int($dm_type_void)"
22126 - print_addr "foo::operator $dm_type_char_star\($dm_type_void)"
22127 + print_addr "foo::operator $dm_operator_char_star\($dm_type_void)"
22131 @@ -480,17 +632,21 @@ proc test_paddr_operator_functions {} {
22132 proc test_paddr_overloaded_functions {} {
22133 global dm_type_unsigned_int
22134 global dm_type_void
22135 + global dm_type_short
22136 + global dm_type_unsigned_short
22137 + global dm_type_long
22138 + global dm_type_unsigned_long
22140 print_addr "overload1arg($dm_type_void)"
22141 print_addr "overload1arg(char)"
22142 print_addr "overload1arg(signed char)"
22143 print_addr "overload1arg(unsigned char)"
22144 - print_addr "overload1arg(short)"
22145 - print_addr "overload1arg(unsigned short)"
22146 + print_addr "overload1arg($dm_type_short)"
22147 + print_addr "overload1arg($dm_type_unsigned_short)"
22148 print_addr "overload1arg(int)"
22149 print_addr "overload1arg($dm_type_unsigned_int)"
22150 - print_addr "overload1arg(long)"
22151 - print_addr "overload1arg(unsigned long)"
22152 + print_addr "overload1arg($dm_type_long)"
22153 + print_addr "overload1arg($dm_type_unsigned_long)"
22154 print_addr "overload1arg(float)"
22155 print_addr "overload1arg(double)"
22157 @@ -513,17 +669,31 @@ proc test_paddr_hairy_functions {} {
22158 global dm_type_char_star
22159 global dm_type_int_star
22160 global dm_type_long_star
22161 + global dm_type_typedef
22163 print_addr_2 "hairyfunc1" "hairyfunc1(int)"
22164 - print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
22165 - print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
22166 - print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
22168 - # gdb-gnats bug gdb/19:
22169 - # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22170 - print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
22171 - print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
22172 - print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
22174 + if {$dm_type_typedef == 0} {
22175 + print_addr_2 "hairyfunc2" "hairyfunc2(int (*)($dm_type_char_star))"
22176 + print_addr_2 "hairyfunc3" "hairyfunc3(int (*)(short (*)($dm_type_long_star)))"
22177 + print_addr_2 "hairyfunc4" "hairyfunc4(int (*)(short (*)($dm_type_char_star)))"
22179 + # gdb-gnats bug gdb/19:
22180 + # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22181 + print_addr_2_kfail "hairyfunc5" "hairyfunc5(int (*(*)($dm_type_char_star))(long))" "hairyfunc5(int (*)(long) (*)(char*))" "gdb/19"
22182 + print_addr_2_kfail "hairyfunc6" "hairyfunc6(int (*(*)($dm_type_int_star))(long))" "hairyfunc6(int (*)(long) (*)(int*))" "gdb/19"
22183 + print_addr_2_kfail "hairyfunc7" "hairyfunc7(int (*(*)(int (*)($dm_type_char_star)))(long))" "hairyfunc7(int (*)(long) (*)(int (*)(char*)))" "gdb/19"
22185 + print_addr_2 "hairyfunc2" "hairyfunc2(PFPc_i)"
22186 + print_addr_2 "hairyfunc3" "hairyfunc3(PFPFPl_s_i)"
22187 + print_addr_2 "hairyfunc4" "hairyfunc4(PFPFPc_s_i)"
22189 + # gdb-gnats bug gdb/19:
22190 + # "gdb v3 demangler fails on hairyfunc5 hairyfunc6 hairyfunc7"
22191 + print_addr_2 "hairyfunc5" "hairyfunc5(PFPc_PFl_i)"
22192 + print_addr_2 "hairyfunc6" "hairyfunc6(PFPi_PFl_i)"
22193 + print_addr_2 "hairyfunc7" "hairyfunc7(PFPFPc_i_PFl_i)"
22198 @@ -534,6 +704,7 @@ proc do_tests {} {
22202 + global dm_type_int_star
22206 @@ -557,6 +728,10 @@ proc do_tests {} {
22207 test_paddr_operator_functions
22208 test_paddr_hairy_functions
22209 test_lookup_operator_functions
22211 + # A regression test on errors involving operators
22212 + gdb_test "list foo::operator $dm_type_int_star" \
22213 + ".*the class foo does not have any method named operator $dm_type_int_star.*"
22217 diff --git a/gdb/testsuite/gdb.cp/expand-sals.exp b/gdb/testsuite/gdb.cp/expand-sals.exp
22218 index 3c302c3..cd0496d 100644
22219 --- a/gdb/testsuite/gdb.cp/expand-sals.exp
22220 +++ b/gdb/testsuite/gdb.cp/expand-sals.exp
22221 @@ -48,7 +48,7 @@ gdb_continue_to_breakpoint "caller" ".*caller-line.*"
22223 # Test GDB caught this return call and not the next one through B::B()
22225 - "#0 \[^\r\n\]* A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
22226 + "#0 \[^\r\n\]* (A::)?A \[^\r\n\]*\r\n#1 \[^\r\n\]* main \[^\r\n\]*" \
22229 gdb_continue_to_breakpoint "next caller func" ".*func-line.*"
22230 diff --git a/gdb/testsuite/gdb.cp/gdb9593.cc b/gdb/testsuite/gdb.cp/gdb9593.cc
22231 new file mode 100644
22232 index 0000000..783c962
22234 +++ b/gdb/testsuite/gdb.cp/gdb9593.cc
22236 +/* This testcase is part of GDB, the GNU debugger.
22238 + Copyright 2008, 2009 Free Software Foundation, Inc.
22240 + This program is free software; you can redistribute it and/or modify
22241 + it under the terms of the GNU General Public License as published by
22242 + the Free Software Foundation; either version 3 of the License, or
22243 + (at your option) any later version.
22245 + This program is distributed in the hope that it will be useful,
22246 + but WITHOUT ANY WARRANTY; without even the implied warranty of
22247 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22248 + GNU General Public License for more details.
22250 + You should have received a copy of the GNU General Public License
22251 + along with this program. If not, see <http://www.gnu.org/licenses/>.
22253 +#include <iostream>
22255 +using namespace std;
22257 +class NextOverThrowDerivates
22263 + // Single throw an exception in this function.
22269 + // Throw an exception in another function.
22275 + // Throw an exception in another function, but handle it
22277 + void function3 ()
22286 + cout << "Caught and handled function1 exception" << endl;
22305 + // We use this to test that a "finish" here does not end up in
22306 + // this frame, but in the one above.
22314 + function1 (); // marker for until
22320 + function1 (); // until here
22324 +NextOverThrowDerivates next_cases;
22331 + next_cases.function1 ();
22340 + next_cases.function2 ();
22349 + // This is duplicated so we can next over one but step into
22351 + next_cases.function2 ();
22358 + next_cases.function3 ();
22362 + next_cases.rethrow ();
22371 + // Another duplicate so we can test "finish".
22372 + next_cases.function2 ();
22379 + // Another test for "finish".
22382 + next_cases.finish ();
22388 + // Test of "until".
22391 + next_cases.finish ();
22397 + // Test of "until" with an argument.
22400 + next_cases.until ();
22406 + // Test of "advance".
22409 + next_cases.until ();
22416 diff --git a/gdb/testsuite/gdb.cp/gdb9593.exp b/gdb/testsuite/gdb.cp/gdb9593.exp
22417 new file mode 100644
22418 index 0000000..ee9aeff
22420 +++ b/gdb/testsuite/gdb.cp/gdb9593.exp
22422 +# Copyright 2008, 2009 Free Software Foundation, Inc.
22424 +# This program is free software; you can redistribute it and/or modify
22425 +# it under the terms of the GNU General Public License as published by
22426 +# the Free Software Foundation; either version 3 of the License, or
22427 +# (at your option) any later version.
22429 +# This program is distributed in the hope that it will be useful,
22430 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22431 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22432 +# GNU General Public License for more details.
22434 +# You should have received a copy of the GNU General Public License
22435 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22438 +if $tracelevel then {
22439 + strace $tracelevel
22442 +if { [skip_cplus_tests] } { continue }
22447 +set testfile "gdb9593"
22448 +set srcfile ${testfile}.cc
22449 +set binfile $objdir/$subdir/$testfile
22451 +# Create and source the file that provides information about the compiler
22452 +# used to compile the test case.
22453 +if [get_compiler_info ${binfile} "c++"] {
22454 + untested gdb9593.exp
22458 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22459 + untested gdb9593.exp
22463 +# Some targets can't do function calls, so don't even bother with this
22465 +if [target_info exists gdb,cannot_call_functions] {
22466 + setup_xfail "*-*-*" 9593
22467 + fail "This target can not call functions"
22473 +gdb_reinitialize_dir $srcdir/$subdir
22474 +gdb_load ${binfile}
22476 +if ![runto_main] then {
22477 + perror "couldn't run to main"
22481 +# See whether we have the needed unwinder hooks.
22483 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
22484 + -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
22485 + pass "check for unwinder hook"
22487 + -re "No symbol .* in current context.\r\n$gdb_prompt $" {
22488 + # Pass the test so we don't get bogus fails in the results.
22489 + pass "check for unwinder hook"
22494 + untested gdb9593.exp
22498 +# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
22501 + ".*catch (...).*" \
22502 + "next over a throw 1"
22505 + ".*next_cases.function2.*" \
22506 + "next past catch 1"
22509 + ".*catch (...).*" \
22510 + "next over a throw 2"
22513 + ".*next_cases.function2.*" \
22514 + "next past catch 2"
22517 + ".*function1().*" \
22518 + "step into function2 1"
22521 + ".*catch (...).*" \
22522 + "next over a throw 3"
22525 + ".*next_cases.function3.*" \
22526 + "next past catch 3"
22529 + ".*next_cases.rethrow.*" \
22530 + "next over a throw 4"
22533 + ".*catch (...).*" \
22534 + "next over a rethrow"
22537 + ".*next_cases.function2.*" \
22538 + "next after a rethrow"
22541 + ".*function1().*" \
22542 + "step into function2 2"
22544 +gdb_test "finish" \
22545 + ".*catch (...).*" \
22549 + ".*next_cases.finish ().*" \
22550 + "next past catch 4"
22553 + ".*function1 ().*" \
22554 + "step into finish method"
22556 +gdb_test "finish" \
22557 + ".*catch (...).*" \
22561 + ".*next_cases.finish ().*" \
22562 + "next past catch 5"
22565 + ".*function1 ().*" \
22566 + "step into finish, for until"
22568 +gdb_test "until" \
22569 + ".*catch .int x.*" \
22570 + "until with no argument 1"
22572 +set line [gdb_get_line_number "marker for until" $testfile.cc]
22574 +gdb_test "until $line" \
22575 + ".*function1 ().*" \
22576 + "next past catch 6"
22578 +gdb_test "until" \
22579 + ".*catch (...).*" \
22580 + "until with no argument 2"
22582 +set line [gdb_get_line_number "until here" $testfile.cc]
22585 + ".*next_cases.until ().*" \
22586 + "next past catch 6"
22589 + ".*function1 ().*" \
22590 + "step into until"
22592 +gdb_test "until $line" \
22593 + ".*catch (...).*" \
22594 + "until-over-throw"
22597 + ".*next_cases.until ().*" \
22598 + "next past catch 7"
22601 + ".*function1 ().*" \
22602 + "step into until, for advance"
22604 +gdb_test "advance $line" \
22605 + ".*catch (...).*" \
22606 + "advance-over-throw"
22607 diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
22608 index 1dff70a..648b2af 100644
22609 --- a/gdb/testsuite/gdb.cp/member-ptr.cc
22610 +++ b/gdb/testsuite/gdb.cp/member-ptr.cc
22611 @@ -138,6 +138,7 @@ class Diamond : public Padding, public Left, public Right
22614 virtual int vget_base ();
22615 + int (*func_ptr) (int);
22618 int Diamond::vget_base ()
22619 @@ -145,6 +146,12 @@ int Diamond::vget_base ()
22620 return this->Left::x + 2000;
22632 @@ -162,6 +169,7 @@ int main ()
22633 int (Diamond::*right_vpmf) ();
22634 int (Base::*base_vpmf) ();
22635 int Diamond::*diamond_pmi;
22636 + int (* Diamond::*diamond_pfunc_ptr) (int);
22640 @@ -179,6 +187,7 @@ int main ()
22642 diamond.Left::x = 77;
22643 diamond.Right::x = 88;
22644 + diamond.func_ptr = func;
22646 /* Some valid pointer to members from a base class. */
22647 left_pmf = (int (Diamond::*) ()) (int (Left::*) ()) (&Base::get_x);
22648 @@ -193,11 +202,19 @@ int main ()
22649 /* A pointer to data member from a base class. */
22650 diamond_pmi = (int Diamond::*) (int Left::*) &Base::x;
22652 + /* A pointer to data member, where the member is itself a pointer to
22654 + diamond_pfunc_ptr = (int (* Diamond::*) (int)) &Diamond::func_ptr;
22659 pmi = NULL; /* Breakpoint 1 here. */
22661 + // Invalid (uses diamond_pfunc_ptr as a function):
22662 + // diamond.*diamond_pfunc_ptr (20);
22663 + (diamond.*diamond_pfunc_ptr) (20);
22668 diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
22669 index b69d4ad..83dd0d5 100644
22670 --- a/gdb/testsuite/gdb.cp/member-ptr.exp
22671 +++ b/gdb/testsuite/gdb.cp/member-ptr.exp
22672 @@ -390,6 +390,33 @@ gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
22676 +# Check pointers to data members, which are themselves pointers to
22677 +# functions. These behave like data members, not like pointers to
22678 +# member functions.
22680 +gdb_test "ptype diamond_pfunc_ptr" \
22681 + "type = int \\(\\*Diamond::\\*\\)\\(int\\)"
22683 +gdb_test "ptype diamond.*diamond_pfunc_ptr" \
22684 + "type = int \\(\\*\\)\\(int\\)"
22686 +# This one is invalid; () binds more tightly than .*, so it tries to
22687 +# call the member pointer as a normal pointer-to-function.
22689 +gdb_test "print diamond.*diamond_pfunc_ptr (20)" \
22690 + "Invalid data type for function to be called."
22692 +# With parentheses, it is valid.
22694 +gdb_test "print (diamond.*diamond_pfunc_ptr) (20)" \
22697 +# Make sure that we do not interpret this as either a member pointer
22698 +# call or a member function call.
22700 +gdb_test "print diamond.func_ptr (20)" \
22703 # ==========================
22704 # pointer to member function
22705 # ==========================
22706 @@ -420,7 +447,7 @@ gdb_test_multiple "ptype pmf" $name {
22708 set name "print pmf"
22709 gdb_test_multiple "print pmf" $name {
22710 - -re "$vhn = $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
22711 + -re "$vhn = \\(int \\(A::\\*\\)\\(A \\*, int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
22714 -re "$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
22715 @@ -608,6 +635,9 @@ gdb_test_multiple "print (a.*pmf)(3)" $name {
22719 +gdb_test "ptype a.*pmf" "type = int \\(A \\*, int\\)"
22720 +gdb_test "ptype (a.*pmf)(3)" "type = int"
22722 # Print out a pointer to data member which requires looking into
22724 gdb_test "print diamond_pmi" "$vhn = &Base::x"
22725 @@ -658,5 +688,5 @@ gdb_test "print null_pmi = &A::j" "$vhn = &A::j"
22726 gdb_test "print null_pmi = 0" "$vhn = NULL"
22728 gdb_test "print null_pmf" "$vhn = NULL"
22729 -gdb_test "print null_pmf = &A::foo" "$vhn = $hex <A::foo ?\\(int\\)>"
22730 +gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*, int\\)\\) $hex <A::foo ?\\(int\\)>"
22731 gdb_test "print null_pmf = 0" "$vhn = NULL"
22732 diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
22733 new file mode 100644
22734 index 0000000..6b180d6
22736 +++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.cc
22745 +using namespace A;
22758 diff --git a/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
22759 new file mode 100644
22760 index 0000000..e4bb9f8
22762 +++ b/gdb/testsuite/gdb.cp/namespace-multiple-imports.exp
22764 +# Copyright 2008 Free Software Foundation, Inc.
22766 +# This program is free software; you can redistribute it and/or modify
22767 +# it under the terms of the GNU General Public License as published by
22768 +# the Free Software Foundation; either version 3 of the License, or
22769 +# (at your option) any later version.
22771 +# This program is distributed in the hope that it will be useful,
22772 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22773 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22774 +# GNU General Public License for more details.
22776 +# You should have received a copy of the GNU General Public License
22777 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22779 +if $tracelevel then {
22780 + strace $tracelevel
22786 +set testfile namespace-multiple-imports
22787 +set srcfile ${testfile}.cc
22788 +set binfile ${objdir}/${subdir}/${testfile}
22789 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22790 + untested "Couldn't compile test program"
22794 +# Get things started.
22798 +gdb_reinitialize_dir $srcdir/$subdir
22799 +gdb_load ${binfile}
22801 +############################################
22802 +# test printing of namespace imported within
22805 +if ![runto_main] then {
22806 + perror "couldn't run to breakpoint main"
22810 +gdb_test "print x" "\\$\[0-9\].* = 11"
22811 +gdb_test "print xx" "\\$\[0-9\].* = 22"
22812 +gdb_test "print xxx" "\\$\[0-9\].* = 33"
22813 diff --git a/gdb/testsuite/gdb.cp/namespace-nested-imports.cc b/gdb/testsuite/gdb.cp/namespace-nested-imports.cc
22814 new file mode 100644
22815 index 0000000..9723f87
22817 +++ b/gdb/testsuite/gdb.cp/namespace-nested-imports.cc
22831 + using namespace A::B;
22845 + return D::second();
22853 + return C::first();
22855 diff --git a/gdb/testsuite/gdb.cp/namespace-nested-imports.exp b/gdb/testsuite/gdb.cp/namespace-nested-imports.exp
22856 new file mode 100644
22857 index 0000000..d279fb5
22859 +++ b/gdb/testsuite/gdb.cp/namespace-nested-imports.exp
22861 +# Copyright 2008 Free Software Foundation, Inc.
22863 +# This program is free software; you can redistribute it and/or modify
22864 +# it under the terms of the GNU General Public License as published by
22865 +# the Free Software Foundation; either version 3 of the License, or
22866 +# (at your option) any later version.
22868 +# This program is distributed in the hope that it will be useful,
22869 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22870 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22871 +# GNU General Public License for more details.
22873 +# You should have received a copy of the GNU General Public License
22874 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22876 +if $tracelevel then {
22877 + strace $tracelevel
22883 +set testfile namespace-nested-imports
22884 +set srcfile ${testfile}.cc
22885 +set binfile ${objdir}/${subdir}/${testfile}
22886 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22887 + untested "Couldn't compile test program"
22891 +# Get things started.
22895 +gdb_reinitialize_dir $srcdir/$subdir
22896 +gdb_load ${binfile}
22898 +############################################
22899 +if ![runto_main] then {
22900 + perror "couldn't run to breakpoint main"
22904 +gdb_test "print ab" "No symbol .* in current context."
22906 +############################################
22907 +gdb_breakpoint C::first
22908 +gdb_continue_to_breakpoint "C::first"
22910 +gdb_test "print ab" "No symbol .* in current context."
22911 +gdb_test "print C::D::ab" "= 11"
22913 +############################################
22914 +gdb_breakpoint C::D::second
22915 +gdb_continue_to_breakpoint "C::D::second"
22917 +gdb_test "print ab" "= 11"
22918 diff --git a/gdb/testsuite/gdb.cp/namespace-no-imports.cc b/gdb/testsuite/gdb.cp/namespace-no-imports.cc
22919 new file mode 100644
22920 index 0000000..d1c68ab
22922 +++ b/gdb/testsuite/gdb.cp/namespace-no-imports.cc
22947 + return C::second();
22959 + return A::B::first();
22961 diff --git a/gdb/testsuite/gdb.cp/namespace-no-imports.exp b/gdb/testsuite/gdb.cp/namespace-no-imports.exp
22962 new file mode 100644
22963 index 0000000..e508103
22965 +++ b/gdb/testsuite/gdb.cp/namespace-no-imports.exp
22967 +# Copyright 2008 Free Software Foundation, Inc.
22969 +# This program is free software; you can redistribute it and/or modify
22970 +# it under the terms of the GNU General Public License as published by
22971 +# the Free Software Foundation; either version 3 of the License, or
22972 +# (at your option) any later version.
22974 +# This program is distributed in the hope that it will be useful,
22975 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
22976 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22977 +# GNU General Public License for more details.
22979 +# You should have received a copy of the GNU General Public License
22980 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
22982 +if $tracelevel then {
22983 + strace $tracelevel
22989 +set testfile namespace-no-imports
22990 +set srcfile ${testfile}.cc
22991 +set binfile ${objdir}/${subdir}/${testfile}
22992 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
22993 + untested "Couldn't compile test program"
22997 +# Get things started.
23001 +gdb_reinitialize_dir $srcdir/$subdir
23002 +gdb_load ${binfile}
23004 +############################################
23005 +if ![runto_main] then {
23006 + perror "couldn't run to breakpoint main"
23010 +gdb_test "print A::_a" "= 11"
23011 +gdb_test "print A::B::ab" "= 22"
23012 +gdb_test "print A::B::C::abc" "= 33"
23014 +gdb_test "print _a" "No symbol .* in current context."
23015 +gdb_test "print ab" "No symbol .* in current context."
23016 +gdb_test "print abc" "No symbol .* in current context."
23018 +############################################
23019 +gdb_breakpoint A::B::first
23020 +gdb_continue_to_breakpoint "A::B::first"
23022 +gdb_test "print A::_a" "= 11"
23023 +gdb_test "print A::B::ab" "= 22"
23024 +gdb_test "print A::B::C::abc" "= 33"
23026 +gdb_test "print _a" "= 11"
23027 +gdb_test "print ab" "= 22"
23028 +gdb_test "print C::abc" "= 33"
23030 +gdb_test "print abc" "No symbol .* in current context."
23032 +############################################
23033 +gdb_breakpoint A::B::C::second
23034 +gdb_continue_to_breakpoint "A::B::C::second"
23036 +gdb_test "print A::_a" "= 11"
23037 +gdb_test "print A::B::ab" "= 22"
23038 +gdb_test "print A::B::C::abc" "= 33"
23040 +gdb_test "print _a" "= 11"
23041 +gdb_test "print ab" "= 22"
23042 +gdb_test "print abc" "= 33"
23043 diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.cc b/gdb/testsuite/gdb.cp/namespace-recursive.cc
23044 new file mode 100644
23045 index 0000000..46d4c18
23047 +++ b/gdb/testsuite/gdb.cp/namespace-recursive.cc
23054 + using namespace A;
23058 + using namespace B;
23061 +using namespace C;
23065 + using namespace D;
23068 +using namespace D;
23083 + namespace FE = E;
23087 + namespace GF = F;
23090 +//----------------
23092 + using namespace D;
23093 + namespace GX = G;
23094 + return ax + dx + xx + G::GF::FE::ex;
23096 diff --git a/gdb/testsuite/gdb.cp/namespace-recursive.exp b/gdb/testsuite/gdb.cp/namespace-recursive.exp
23097 new file mode 100644
23098 index 0000000..5543757
23100 +++ b/gdb/testsuite/gdb.cp/namespace-recursive.exp
23102 +# Copyright 2008 Free Software Foundation, Inc.
23104 +# This program is free software; you can redistribute it and/or modify
23105 +# it under the terms of the GNU General Public License as published by
23106 +# the Free Software Foundation; either version 3 of the License, or
23107 +# (at your option) any later version.
23109 +# This program is distributed in the hope that it will be useful,
23110 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23111 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23112 +# GNU General Public License for more details.
23114 +# You should have received a copy of the GNU General Public License
23115 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23117 +if $tracelevel then {
23118 + strace $tracelevel
23124 +set testfile namespace-recursive
23125 +set srcfile ${testfile}.cc
23126 +set binfile ${objdir}/${subdir}/${testfile}
23127 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23128 + untested "Couldn't compile test program"
23132 +if [get_compiler_info ${binfile}] {
23137 +# Get things started.
23141 +gdb_reinitialize_dir $srcdir/$subdir
23142 +gdb_load ${binfile}
23144 +if ![runto_main] then {
23145 + perror "couldn't run to breakpoint main"
23149 +############################################
23150 +# test printing from namespace imported into
23151 +# imported namespace
23153 +gdb_test "print ax" "= 9"
23155 +############################################
23156 +# test that gdb can print without falling
23157 +# into search loop
23159 +gdb_test "print dx" "= 99"
23161 +############################################
23162 +# test printing from namespace imported into
23163 +# imported namespace where imports are implicit
23164 +# anonymous namespace imports.
23166 +gdb_test "print xx" "= 999"
23168 +############################################
23169 +# Test printing using recursive namespace
23172 +setup_kfail "gdb/10541" "*-*-*"
23173 +gdb_test "ptype G::GF" "= namespace F"
23175 +setup_kfail "gdb/10541" "*-*-*"
23176 +gdb_test "print G::GF::FE::ex" "= 9999"
23177 diff --git a/gdb/testsuite/gdb.cp/namespace-stress.cc b/gdb/testsuite/gdb.cp/namespace-stress.cc
23178 new file mode 100644
23179 index 0000000..f34083e
23181 +++ b/gdb/testsuite/gdb.cp/namespace-stress.cc
23184 +namespace A{ int x; }
23185 +namespace B{ int x; }
23186 +namespace C{ int x; }
23187 +namespace D{ int x; }
23188 +namespace E{ int x; }
23189 +namespace F{ int x; }
23190 +namespace G{ int x; }
23191 +namespace H{ int x; }
23192 +namespace I{ int x; }
23193 +namespace J{ int x; }
23194 +namespace K{ int x; }
23195 +namespace L{ int x; }
23196 +namespace M{ int x; }
23197 +namespace N{ int x; }
23198 +namespace O{ int x; }
23199 +namespace P{ int x; }
23200 +namespace Q{ int x; }
23201 +namespace R{ int x; }
23202 +namespace S{ int x; }
23203 +namespace T{ int x; }
23204 +namespace U{ int x; }
23205 +namespace V{ int x; }
23206 +namespace W{ int x; }
23207 +namespace X{ int x; }
23208 +namespace Y{ int x; }
23209 +namespace Z{ int x; }
23214 + using namespace A;
23215 + using namespace B;
23216 + using namespace C;
23217 + using namespace D;
23218 + using namespace E;
23219 + using namespace F;
23220 + using namespace G;
23221 + using namespace H;
23222 + using namespace I;
23223 + using namespace J;
23224 + using namespace K;
23225 + using namespace L;
23226 + using namespace M;
23227 + using namespace N;
23228 + using namespace O;
23229 + using namespace P;
23230 + using namespace Q;
23231 + using namespace R;
23232 + using namespace S;
23233 + using namespace T;
23234 + using namespace U;
23235 + using namespace V;
23236 + using namespace W;
23237 + using namespace X;
23238 + using namespace Y;
23239 + using namespace Z;
23243 \ No newline at end of file
23244 diff --git a/gdb/testsuite/gdb.cp/namespace-stress.exp b/gdb/testsuite/gdb.cp/namespace-stress.exp
23245 new file mode 100644
23246 index 0000000..1806523
23248 +++ b/gdb/testsuite/gdb.cp/namespace-stress.exp
23250 +# Copyright 2008 Free Software Foundation, Inc.
23252 +# This program is free software; you can redistribute it and/or modify
23253 +# it under the terms of the GNU General Public License as published by
23254 +# the Free Software Foundation; either version 3 of the License, or
23255 +# (at your option) any later version.
23257 +# This program is distributed in the hope that it will be useful,
23258 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23259 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23260 +# GNU General Public License for more details.
23262 +# You should have received a copy of the GNU General Public License
23263 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23265 +if $tracelevel then {
23266 + strace $tracelevel
23272 +set testfile namespace-stress
23273 +set srcfile ${testfile}.cc
23274 +set binfile ${objdir}/${subdir}/${testfile}
23275 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23276 + untested "Couldn't compile test program"
23280 +if [get_compiler_info ${binfile}] {
23284 +# Get things started.
23288 +gdb_reinitialize_dir $srcdir/$subdir
23289 +gdb_load ${binfile}
23291 +if ![runto_main] then {
23292 + perror "couldn't run to breakpoint main"
23296 +############################################
23297 +# Test that the search can fail efficiently
23299 +gdb_test "print y" "No symbol \"y\" in current context."
23300 diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc b/gdb/testsuite/gdb.cp/namespace-using.cc
23301 index 4786fd5..8ff5622 100644
23302 --- a/gdb/testsuite/gdb.cp/namespace-using.cc
23303 +++ b/gdb/testsuite/gdb.cp/namespace-using.cc
23317 + using namespace M;
23318 + int y = x + 1; // marker10 stop
23319 + using namespace N;
23334 + return marker10 ();
23340 + using namespace J;
23345 + return K::marker9 ();
23362 + using namespace G::H;
23364 + return L::marker8 ();
23376 +using namespace E::F;
23381 + return I::marker7 ();
23403 +using namespace C;
23408 + return marker6 ();
23415 + return marker5 ();
23419 - return marker4();
23423 + return marker4 ();
23432 - return marker3();
23433 + return marker3 ();
23442 @@ -29,17 +132,18 @@ int marker1()
23447 - total = _a + b + c + d + marker2(); // marker1 stop
23449 + total = _a + b + c + d + marker2 (); // marker1 stop
23462 - return marker1();
23463 + return marker1 ();
23465 diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp b/gdb/testsuite/gdb.cp/namespace-using.exp
23466 index f24973f..fc23115 100644
23467 --- a/gdb/testsuite/gdb.cp/namespace-using.exp
23468 +++ b/gdb/testsuite/gdb.cp/namespace-using.exp
23469 @@ -28,6 +28,11 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
23473 +if [get_compiler_info ${binfile}] {
23478 # Get things started.
23481 @@ -46,42 +51,155 @@ if ![runto_main] then {
23483 gdb_test "print _a" "= 1"
23485 +# Test that names are not printed when they
23486 +# are not imported
23488 +gdb_breakpoint marker3
23489 +gdb_continue_to_breakpoint "marker3"
23491 +#send_gdb "break marker3\n"
23492 +#send_gdb "continue\n"
23494 +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import"
23498 +gdb_reinitialize_dir $srcdir/$subdir
23499 +gdb_load ${binfile}
23502 ############################################
23503 # test printing of namespace imported into
23504 # a scope containing the pc.
23506 +if ![runto_main] then {
23507 + perror "couldn't run to breakpoint main"
23511 gdb_breakpoint [gdb_get_line_number "marker1 stop"]
23512 gdb_continue_to_breakpoint "marker1 stop"
23514 gdb_test "print _a" "= 1" "print _a in a nested scope"
23519 +gdb_reinitialize_dir $srcdir/$subdir
23520 +gdb_load ${binfile}
23522 +############################################
23523 +# test printing of namespace imported into
23527 +if ![runto marker5] then {
23528 + perror "couldn't run to breakpoint marker5"
23532 +gdb_test "print cc" "= 3"
23536 +gdb_reinitialize_dir $srcdir/$subdir
23537 +gdb_load ${binfile}
23540 ############################################
23541 # Test printing of namespace aliases
23543 -setup_kfail "gdb/7935" "*-*-*"
23544 if ![runto marker2] then {
23545 perror "couldn't run to breakpoint marker2"
23549 -gdb_test "print B::a" "= 1"
23550 +gdb_test "print B::_a" "= 1"
23552 +gdb_test "print _a" "No symbol \"_a\" in current context." "print _a in namespace alias scope"
23553 +gdb_test "print x" "No symbol \"x\" in current context." "print x in namespace alias scope"
23557 +gdb_reinitialize_dir $srcdir/$subdir
23558 +gdb_load ${binfile}
23561 ############################################
23562 # Test that names are not printed when they
23565 -gdb_breakpoint "marker3"
23566 -gdb_continue_to_breakpoint "marker3"
23567 +if {![runto marker3]} {
23568 + perror "couldn't run to breakpoint marker3"
23571 -gdb_test "print _a" "No symbol \"_a\" in current context." "Print a without import"
23572 +# gcc-4-3 puts import statements for aliases in
23573 +# the global scope instead of the corresponding
23574 +# function scope. These wrong import statements throw
23575 +# this test off. This is fixed in gcc-4-4.
23576 +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
23578 +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import"
23580 ############################################
23581 # Test printing of individually imported elements
23583 -setup_kfail "gdb/7936" "*-*-*"
23584 if ![runto marker4] then {
23585 perror "couldn't run to breakpoint marker4"
23589 -gdb_test "print x" "= 2"
23590 +gdb_test "print dx" "= 4"
23592 +############################################
23593 +# Test printing of namespace aliases
23595 +if ![runto marker5] then {
23596 + perror "couldn't run to marker5"
23600 +gdb_test "print efx" "= 5"
23602 +############################################
23603 +# Test printing of variables imported from
23604 +# nested namespaces
23606 +if ![runto I::marker7] then {
23607 + perror "couldn't run to breakpoint I::marker7"
23611 +gdb_test "print ghx" "= 6"
23613 +############################################
23614 +# Test that variables are not printed in a namespace
23615 +# that is sibling to the namespace containing an import
23617 +if ![runto L::marker8] then {
23618 + perror "couldn't run to breakpoint L::marker8"
23622 +gdb_test "print jx" "= 44"
23624 +gdb_breakpoint "K::marker9"
23625 +gdb_continue_to_breakpoint "K::marker9"
23627 +gdb_test "print jx" "No symbol \"jx\" in current context."
23629 +############################################
23630 +# Test that variables are only printed after the line
23631 +# containing the import
23633 +if ![runto_main] then {
23634 + perror "couldn't run to breakpoint main"
23638 +gdb_breakpoint [gdb_get_line_number "marker10 stop"]
23639 +gdb_continue_to_breakpoint "marker10 stop"
23641 +# Assert that M::x is printed and not N::x
23642 +gdb_test "print x" "= 911" "print x (from M::x)"
23644 diff --git a/gdb/testsuite/gdb.cp/namespace.exp b/gdb/testsuite/gdb.cp/namespace.exp
23645 index 76b1b82..2042db2 100644
23646 --- a/gdb/testsuite/gdb.cp/namespace.exp
23647 +++ b/gdb/testsuite/gdb.cp/namespace.exp
23650 # Note: As of 2000-06-03, they passed under g++ - djb
23652 +load_lib "cp-support.exp"
23654 if $tracelevel then {
23656 @@ -259,11 +260,16 @@ gdb_test "ptype E" "type = namespace C::D::E"
23657 gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
23658 gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
23659 gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
23660 -setup_kfail "gdb/1448" "*-*-*"
23661 -gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
23662 -setup_kfail "gdb/1448" "*-*-*"
23663 -gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
23664 -setup_kfail "gdb/1448" "*-*-*"
23665 +cp_test_ptype_class \
23666 + "ptype ::C::CClass" "" "class" "C::CClass" \
23668 + { field public "int x;" }
23670 +cp_test_ptype_class \
23671 + "ptype ::C::CClass::NestedClass" "" "class" "C::CClass::NestedClass" \
23673 + { field public "int y;" }
23675 gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
23676 gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
23677 gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
23678 @@ -273,8 +279,11 @@ gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"
23680 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
23681 gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}"
23682 -setup_kfail "gdb/1448" "*-*-*"
23683 -gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
23684 +cp_test_ptype_class \
23685 + "ptype ::C::OtherFileClass" "" "class" "C::OtherFileClass" \
23687 + { field public "int z;" }
23689 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
23691 # Some anonymous namespace tests.
23692 diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp
23693 index 24025a2..a72932e 100644
23694 --- a/gdb/testsuite/gdb.cp/overload.exp
23695 +++ b/gdb/testsuite/gdb.cp/overload.exp
23696 @@ -74,12 +74,12 @@ set re_methods "${re_methods}${ws}int overload1arg\\((void|)\\);"
23697 set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
23698 set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
23699 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
23700 -set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
23701 -set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
23702 +set re_methods "${re_methods}${ws}int overload1arg\\(short( int)?\\);"
23703 +set re_methods "${re_methods}${ws}int overload1arg\\((unsigned short|short unsigned)( int)?\\);"
23704 set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
23705 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
23706 -set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
23707 -set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
23708 +set re_methods "${re_methods}${ws}int overload1arg\\(long( int)?\\);"
23709 +set re_methods "${re_methods}${ws}int overload1arg\\((unsigned long|long unsigned)( int)?\\);"
23710 set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
23711 set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
23712 set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
23713 diff --git a/gdb/testsuite/gdb.cp/ovldbreak.exp b/gdb/testsuite/gdb.cp/ovldbreak.exp
23714 index 8a6b795..9997a45 100644
23715 --- a/gdb/testsuite/gdb.cp/ovldbreak.exp
23716 +++ b/gdb/testsuite/gdb.cp/ovldbreak.exp
23717 @@ -127,10 +127,24 @@ proc set_bp_overloaded {name expectedmenu mychoice bpnumber linenumber} {
23720 # This is the expected menu for overload1arg.
23721 -# Note the arg type variations on lines 6 and 13.
23722 +# Note the arg type variations for void and integer types.
23723 # This accommodates different versions of g++.
23725 -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> $"
23726 +set menu_overload1arg "\\\[0\\\] cancel\r\n"
23727 +append menu_overload1arg "\\\[1\\\] all\r\n"
23728 +append menu_overload1arg "\\\[2\\\] foo::overload1arg\\(double\\) at.*$srcfile:121\r\n"
23729 +append menu_overload1arg "\\\[3\\\] foo::overload1arg\\(float\\) at.*$srcfile:120\r\n"
23730 +append menu_overload1arg "\\\[4\\\] foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r\n"
23731 +append menu_overload1arg "\\\[5\\\] foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r\n"
23732 +append menu_overload1arg "\\\[6\\\] foo::overload1arg\\((unsigned int|unsigned)\\) at.*$srcfile:117\r\n"
23733 +append menu_overload1arg "\\\[7\\\] foo::overload1arg\\(int\\) at.*$srcfile:116\r\n"
23734 +append menu_overload1arg "\\\[8\\\] foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r\n"
23735 +append menu_overload1arg "\\\[9\\\] foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r\n"
23736 +append menu_overload1arg "\\\[10\\\] foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r\n"
23737 +append menu_overload1arg "\\\[11\\\] foo::overload1arg\\(signed char\\) at.*$srcfile:112\r\n"
23738 +append menu_overload1arg "\\\[12\\\] foo::overload1arg\\(char\\) at.*$srcfile:111\r\n"
23739 +append menu_overload1arg "\\\[13\\\] foo::overload1arg\\((void|)\\) at.*$srcfile:110\r\n"
23740 +append menu_overload1arg "> $"
23742 # Set multiple-symbols to "ask", to allow us to test the use
23743 # of the multiple-choice menu when breaking on an overloaded method.
23744 @@ -157,17 +171,17 @@ set_bp_overloaded "foo::overload1arg" "$menu_overload1arg" 13 13 110
23746 gdb_test "info break" \
23747 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
23748 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
23749 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
23750 \[\t \]+breakpoint already hit 1 time\r
23751 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
23752 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
23753 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
23754 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
23755 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
23756 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
23757 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
23758 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
23759 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
23760 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
23761 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
23762 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
23763 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
23764 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
23765 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
23766 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
23767 @@ -215,17 +229,17 @@ gdb_expect {
23769 gdb_test "info break" \
23770 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
23771 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main at.*$srcfile:49\r
23772 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in main(\\((|void)\\))? at.*$srcfile:49\r
23773 \[\t \]+breakpoint already hit 1 time\r
23774 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
23775 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
23776 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
23777 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
23778 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
23779 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
23780 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
23781 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
23782 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
23783 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
23784 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
23785 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
23786 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
23787 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
23788 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
23789 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((void|)\\) at.*$srcfile:110" \
23790 @@ -296,12 +310,12 @@ gdb_test "info break" \
23791 "Num Type\[\t \]+Disp Enb Address\[\t \]+What.*
23792 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(double\\) at.*$srcfile:121\r
23793 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(float\\) at.*$srcfile:120\r
23794 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned long\\) at.*$srcfile:119\r
23795 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long\\) at.*$srcfile:118\r
23796 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned long|long unsigned)( int)?\\) at.*$srcfile:119\r
23797 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(long( int)?\\) at.*$srcfile:118\r
23798 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned|unsigned int)\\) at.*$srcfile:117\r
23799 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(int\\) at.*$srcfile:116\r
23800 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned short\\) at.*$srcfile:115\r
23801 -\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short\\) at.*$srcfile:114\r
23802 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\((unsigned short|short unsigned)( int)?\\) at.*$srcfile:115\r
23803 +\[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(short( int)?\\) at.*$srcfile:114\r
23804 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(unsigned char\\) at.*$srcfile:113\r
23805 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(signed char\\) at.*$srcfile:112\r
23806 \[0-9\]+\[\t \]+breakpoint keep y\[\t \]+$hex\[\t \]+in foo::overload1arg\\(char\\) at.*$srcfile:111\r
23807 diff --git a/gdb/testsuite/gdb.cp/shadowing.cc b/gdb/testsuite/gdb.cp/shadowing.cc
23808 new file mode 100644
23809 index 0000000..6d9c2f1
23811 +++ b/gdb/testsuite/gdb.cp/shadowing.cc
23841 + int z = x; //prevent gcc from optimizing away this scope
23842 + using namespace A;
23859 + return theB.func();
23861 diff --git a/gdb/testsuite/gdb.cp/shadowing.exp b/gdb/testsuite/gdb.cp/shadowing.exp
23862 new file mode 100644
23863 index 0000000..6922eed
23865 +++ b/gdb/testsuite/gdb.cp/shadowing.exp
23867 +# Copyright 2008 Free Software Foundation, Inc.
23869 +# This program is free software; you can redistribute it and/or modify
23870 +# it under the terms of the GNU General Public License as published by
23871 +# the Free Software Foundation; either version 3 of the License, or
23872 +# (at your option) any later version.
23874 +# This program is distributed in the hope that it will be useful,
23875 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
23876 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23877 +# GNU General Public License for more details.
23879 +# You should have received a copy of the GNU General Public License
23880 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
23882 +if $tracelevel then {
23883 + strace $tracelevel
23889 +set testfile shadowing
23890 +set srcfile ${testfile}.cc
23891 +set binfile ${objdir}/${subdir}/${testfile}
23892 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
23893 + untested "Couldn't compile test program"
23897 +if [get_compiler_info ${binfile}] {
23901 +# Get things started.
23905 +gdb_reinitialize_dir $srcdir/$subdir
23906 +gdb_load ${binfile}
23908 +if ![runto_main] then {
23909 + perror "couldn't run to breakpoint main"
23913 +############################################
23914 +# Test printing of class variable is not shadowed
23915 +# by global variable
23917 +gdb_breakpoint [gdb_get_line_number "marker1"]
23918 +gdb_continue_to_breakpoint "marker1"
23920 +gdb_test "print x" "= 33" "Print class x shadowing global x"
23923 +############################################
23924 +# Test printing local variable is not shadowed
23925 +# by class variable
23927 +gdb_breakpoint [gdb_get_line_number "marker2"]
23928 +gdb_continue_to_breakpoint "marker2"
23930 +gdb_test "print x" "= 44" "Print local x shadowing class x"
23932 +############################################
23933 +# Test inner scope x is printed not outer scope
23935 +gdb_breakpoint [gdb_get_line_number "marker3"]
23936 +gdb_continue_to_breakpoint "marker3"
23938 +gdb_test "print x" "= 55" "Print inner scope x"
23940 +############################################
23941 +# Test printing local variable is not shadowed
23942 +# by namespace variable
23944 +gdb_breakpoint [gdb_get_line_number "marker4"]
23945 +gdb_continue_to_breakpoint "marker4"
23947 +gdb_test "print x" "= 55" "Print local x not namespace x"
23949 +############################################
23950 +# Test imported namespace element is printed
23952 +gdb_breakpoint [gdb_get_line_number "marker5"]
23953 +gdb_continue_to_breakpoint "marker5"
23955 +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
23957 +gdb_test "print x" "= 11" "Print imported namespace x"
23958 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.S b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
23959 new file mode 100644
23960 index 0000000..d5b9ca5
23962 +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
23964 +/* This testcase is part of GDB, the GNU debugger.
23966 + Copyright 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
23968 + This program is free software; you can redistribute it and/or modify
23969 + it under the terms of the GNU General Public License as published by
23970 + the Free Software Foundation; either version 3 of the License, or
23971 + (at your option) any later version.
23973 + This program is distributed in the hope that it will be useful,
23974 + but WITHOUT ANY WARRANTY; without even the implied warranty of
23975 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23976 + GNU General Public License for more details.
23978 + You should have received a copy of the GNU General Public License
23979 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
23981 +/* Test .debug_aranges containing zero address_size. */
23983 +/* Dummy function to provide debug information for. */
23988 + .type main, %function
23993 + .size main, .-main
23996 +/* Debug information */
23998 + .section .debug_info
24001 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
24003 + .2byte 2 /* DWARF Version */
24004 + .4byte .Labbrev1_begin /* Offset into abbrev section */
24005 + .byte 4 /* Pointer size */
24008 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
24009 + .4byte .Lend_text1 /* DW_AT_high_pc */
24010 + .4byte .Lbegin_text1 /* DW_AT_low_pc */
24011 + .ascii "file1.txt\0" /* DW_AT_name */
24012 + .ascii "GNU C 3.3.3\0" /* DW_AT_producer */
24013 + .byte 1 /* DW_AT_language (C) */
24016 + .uleb128 2 /* Abbrev: DW_TAG_subprogram */
24017 + .byte 1 /* DW_AT_external */
24018 + .byte 1 /* DW_AT_decl_file */
24019 + .byte 2 /* DW_AT_decl_line */
24020 + .ascii "main\0" /* DW_AT_name */
24021 + .4byte .Ltype_int-.Lcu1_begin /* DW_AT_type */
24022 + .4byte .Lbegin_main /* DW_AT_low_pc */
24023 + .4byte .Lend_main /* DW_AT_high_pc */
24024 + .byte 1 /* DW_AT_frame_base: length */
24025 + .byte 0x55 /* DW_AT_frame_base: DW_OP_reg5 */
24028 + .uleb128 3 /* Abbrev: DW_TAG_base_type */
24029 + .ascii "int\0" /* DW_AT_name */
24030 + .byte 4 /* DW_AT_byte_size */
24031 + .byte 5 /* DW_AT_encoding */
24033 + .byte 0 /* End of children of CU */
24037 +/* Abbrev table */
24038 + .section .debug_abbrev
24040 + .uleb128 1 /* Abbrev code */
24041 + .uleb128 0x11 /* DW_TAG_compile_unit */
24042 + .byte 1 /* has_children */
24043 + .uleb128 0x12 /* DW_AT_high_pc */
24044 + .uleb128 0x1 /* DW_FORM_addr */
24045 + .uleb128 0x11 /* DW_AT_low_pc */
24046 + .uleb128 0x1 /* DW_FORM_addr */
24047 + .uleb128 0x3 /* DW_AT_name */
24048 + .uleb128 0x8 /* DW_FORM_string */
24049 + .uleb128 0x25 /* DW_AT_producer */
24050 + .uleb128 0x8 /* DW_FORM_string */
24051 + .uleb128 0x13 /* DW_AT_language */
24052 + .uleb128 0xb /* DW_FORM_data1 */
24053 + .byte 0x0 /* Terminator */
24054 + .byte 0x0 /* Terminator */
24056 + .uleb128 2 /* Abbrev code */
24057 + .uleb128 0x2e /* DW_TAG_subprogram */
24058 + .byte 0 /* has_children */
24059 + .uleb128 0x3f /* DW_AT_external */
24060 + .uleb128 0xc /* DW_FORM_flag */
24061 + .uleb128 0x3a /* DW_AT_decl_file */
24062 + .uleb128 0xb /* DW_FORM_data1 */
24063 + .uleb128 0x3b /* DW_AT_decl_line */
24064 + .uleb128 0xb /* DW_FORM_data1 */
24065 + .uleb128 0x3 /* DW_AT_name */
24066 + .uleb128 0x8 /* DW_FORM_string */
24067 + .uleb128 0x49 /* DW_AT_type */
24068 + .uleb128 0x13 /* DW_FORM_ref4 */
24069 + .uleb128 0x11 /* DW_AT_low_pc */
24070 + .uleb128 0x1 /* DW_FORM_addr */
24071 + .uleb128 0x12 /* DW_AT_high_pc */
24072 + .uleb128 0x1 /* DW_FORM_addr */
24073 + .uleb128 0x40 /* DW_AT_frame_base */
24074 + .uleb128 0xa /* DW_FORM_block1 */
24075 + .byte 0x0 /* Terminator */
24076 + .byte 0x0 /* Terminator */
24078 + .uleb128 3 /* Abbrev code */
24079 + .uleb128 0x24 /* DW_TAG_base_type */
24080 + .byte 0 /* has_children */
24081 + .uleb128 0x3 /* DW_AT_name */
24082 + .uleb128 0x8 /* DW_FORM_string */
24083 + .uleb128 0xb /* DW_AT_byte_size */
24084 + .uleb128 0xb /* DW_FORM_data1 */
24085 + .uleb128 0x3e /* DW_AT_encoding */
24086 + .uleb128 0xb /* DW_FORM_data1 */
24087 + .byte 0x0 /* Terminator */
24088 + .byte 0x0 /* Terminator */
24090 + .byte 0x0 /* Terminator */
24091 + .byte 0x0 /* Terminator */
24093 +/* aranges table */
24094 + .section .debug_aranges
24095 + .long .Laranges_end - 1f
24097 + .2byte 2 /* aranges Version */
24098 + .4byte .Lcu1_begin - .debug_info /* Offset into .debug_info section */
24099 + /* The GDB crasher is this zero value. */
24100 + .byte 0 /* aranges address_size */
24101 + .byte 0 /* aranges segment_size */
24104 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
24105 new file mode 100644
24106 index 0000000..39632d5
24108 +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp
24110 +# Copyright 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
24112 +# This program is free software; you can redistribute it and/or modify
24113 +# it under the terms of the GNU General Public License as published by
24114 +# the Free Software Foundation; either version 3 of the License, or
24115 +# (at your option) any later version.
24117 +# This program is distributed in the hope that it will be useful,
24118 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24119 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24120 +# GNU General Public License for more details.
24122 +# You should have received a copy of the GNU General Public License
24123 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
24125 +# Test .debug_aranges containing zero address_size.
24127 +# This test can only be run on targets which support DWARF-2 and use gas.
24128 +# For now pick a sampling of likely targets.
24129 +if {![istarget *-*-linux*]
24130 + && ![istarget *-*-gnu*]
24131 + && ![istarget *-*-elf*]
24132 + && ![istarget *-*-openbsd*]
24133 + && ![istarget arm-*-eabi*]
24134 + && ![istarget powerpc-*-eabi*]} {
24138 +set testfile "dw2-aranges"
24139 +set srcfile ${testfile}.S
24140 +set binfile ${objdir}/${subdir}/${testfile}
24142 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {nodebug}] != "" } {
24146 +clean_restart $testfile
24148 +# Failed gdb_load would abort the testcase execution earlier.
24149 +pass "file loaded"
24150 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
24151 new file mode 100644
24152 index 0000000..1f02d90
24154 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
24156 +/* This testcase is part of GDB, the GNU debugger.
24158 + Copyright 2004 Free Software Foundation, Inc.
24160 + This program is free software; you can redistribute it and/or modify
24161 + it under the terms of the GNU General Public License as published by
24162 + the Free Software Foundation; either version 2 of the License, or
24163 + (at your option) any later version.
24165 + This program is distributed in the hope that it will be useful,
24166 + but WITHOUT ANY WARRANTY; without even the implied warranty of
24167 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24168 + GNU General Public License for more details.
24170 + You should have received a copy of the GNU General Public License
24171 + along with this program; if not, write to the Free Software
24172 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
24176 +/* The function `func1' traced into must have debug info on offset > 0;
24177 + (DW_UNSND (attr)). This is the reason of `func0' existence. */
24180 +func0(int a, int b)
24184 +/* `func1' being traced into must have some arguments to dump. */
24187 +func1(int a, int b)
24198 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
24199 new file mode 100644
24200 index 0000000..1c6e84a
24202 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
24204 +# Copyright 2006 Free Software Foundation, Inc.
24206 +# This program is free software; you can redistribute it and/or modify
24207 +# it under the terms of the GNU General Public License as published by
24208 +# the Free Software Foundation; either version 2 of the License, or
24209 +# (at your option) any later version.
24211 +# This program is distributed in the hope that it will be useful,
24212 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24213 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24214 +# GNU General Public License for more details.
24216 +# You should have received a copy of the GNU General Public License
24217 +# along with this program; if not, write to the Free Software
24218 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24220 +# Minimal DWARF-2 unit test
24222 +# This test can only be run on targets which support DWARF-2.
24223 +# For now pick a sampling of likely targets.
24224 +if {![istarget *-*-linux*]
24225 + && ![istarget *-*-gnu*]
24226 + && ![istarget *-*-elf*]
24227 + && ![istarget *-*-openbsd*]
24228 + && ![istarget arm-*-eabi*]
24229 + && ![istarget powerpc-*-eabi*]} {
24233 +set testfile "dw2-stripped"
24234 +set srcfile ${testfile}.c
24235 +set binfile ${objdir}/${subdir}/${testfile}.x
24237 +remote_exec build "rm -f ${binfile}"
24239 +# get the value of gcc_compiled
24240 +if [get_compiler_info ${binfile}] {
24244 +# This test can only be run on gcc as we use additional_flags=FIXME
24245 +if {$gcc_compiled == 0} {
24249 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
24253 +remote_exec build "objcopy -R .debug_loc ${binfile}"
24254 +set strip_output [remote_exec build "objdump -h ${binfile}"]
24256 +set test "stripping test file preservation"
24257 +if [ regexp ".debug_info " $strip_output] {
24258 + pass "$test (.debug_info preserved)"
24260 + fail "$test (.debug_info got also stripped)"
24263 +set test "stripping test file functionality"
24264 +if [ regexp ".debug_loc " $strip_output] {
24265 + fail "$test (.debug_loc still present)"
24267 + pass "$test (.debug_loc stripped)"
24272 +gdb_reinitialize_dir $srcdir/$subdir
24273 +gdb_load ${binfile}
24275 +# For C programs, "start" should stop in main().
24277 +gdb_test "start" \
24278 + ".*main \\(\\) at .*" \
24281 + "func.* \\(.*\\) at .*" \
24283 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
24284 new file mode 100644
24285 index 0000000..5fcdd84
24287 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
24289 +/* This testcase is part of GDB, the GNU debugger.
24291 + Copyright 2009 Free Software Foundation, Inc.
24293 + This program is free software; you can redistribute it and/or modify
24294 + it under the terms of the GNU General Public License as published by
24295 + the Free Software Foundation; either version 3 of the License, or
24296 + (at your option) any later version.
24298 + This program is distributed in the hope that it will be useful,
24299 + but WITHOUT ANY WARRANTY; without even the implied warranty of
24300 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24301 + GNU General Public License for more details.
24303 + You should have received a copy of the GNU General Public License
24304 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
24306 +/* Debug information */
24308 + .section .debug_info
24311 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
24313 + .2byte 2 /* DWARF Version */
24314 + .4byte .Labbrev1_begin /* Offset into abbrev section */
24315 + .byte 4 /* Pointer size */
24318 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
24319 + .ascii "dw2-struct-member-data-location.c\0" /* DW_AT_name */
24320 + .ascii "GNU C 4.3.2\0" /* DW_AT_producer */
24321 + .byte 1 /* DW_AT_language (C) */
24324 + .uleb128 2 /* Abbrev: DW_TAG_structure_type */
24325 + .ascii "some_struct\0" /* DW_AT_name */
24327 + .uleb128 3 /* Abbrev: DW_TAG_member */
24328 + .ascii "field\0" /* DW_AT_name */
24329 + .byte 0 /* DW_AT_data_member_location */
24331 + .byte 0 /* End of children of some_struct */
24333 + .byte 0 /* End of children of CU */
24337 +/* Abbrev table */
24338 + .section .debug_abbrev
24340 + .uleb128 1 /* Abbrev code */
24341 + .uleb128 0x11 /* DW_TAG_compile_unit */
24342 + .byte 1 /* has_children */
24343 + .uleb128 0x3 /* DW_AT_name */
24344 + .uleb128 0x8 /* DW_FORM_string */
24345 + .uleb128 0x25 /* DW_AT_producer */
24346 + .uleb128 0x8 /* DW_FORM_string */
24347 + .uleb128 0x13 /* DW_AT_language */
24348 + .uleb128 0xb /* DW_FORM_data1 */
24349 + .byte 0x0 /* Terminator */
24350 + .byte 0x0 /* Terminator */
24352 + .uleb128 2 /* Abbrev code */
24353 + .uleb128 0x13 /* DW_TAG_structure_type */
24354 + .byte 1 /* has_children */
24355 + .uleb128 0x3 /* DW_AT_name */
24356 + .uleb128 0x8 /* DW_FORM_string */
24357 + .byte 0x0 /* Terminator */
24358 + .byte 0x0 /* Terminator */
24360 + .uleb128 3 /* Abbrev code */
24361 + .uleb128 0x0d /* DW_TAG_member */
24362 + .byte 0 /* has_children */
24363 + .uleb128 0x3 /* DW_AT_name */
24364 + .uleb128 0x8 /* DW_FORM_string */
24365 + .uleb128 0x38 /* DW_AT_data_member_location */
24366 + .uleb128 0x0b /* DW_FORM_data1 */
24367 + .byte 0x0 /* Terminator */
24368 + .byte 0x0 /* Terminator */
24370 + .byte 0x0 /* Terminator */
24371 + .byte 0x0 /* Terminator */
24372 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
24373 new file mode 100644
24374 index 0000000..c41151c
24376 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
24378 +# Copyright 2009 Free Software Foundation, Inc.
24380 +# This program is free software; you can redistribute it and/or modify
24381 +# it under the terms of the GNU General Public License as published by
24382 +# the Free Software Foundation; either version 3 of the License, or
24383 +# (at your option) any later version.
24385 +# This program is distributed in the hope that it will be useful,
24386 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24387 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24388 +# GNU General Public License for more details.
24390 +# You should have received a copy of the GNU General Public License
24391 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
24393 +# This test can only be run on targets which support DWARF-2 and use gas.
24394 +# For now pick a sampling of likely targets.
24395 +if {![istarget *-*-linux*]
24396 + && ![istarget *-*-gnu*]
24397 + && ![istarget *-*-elf*]
24398 + && ![istarget *-*-openbsd*]
24399 + && ![istarget arm-*-eabi*]
24400 + && ![istarget powerpc-*-eabi*]} {
24404 +set testfile "dw2-struct-member-data-location"
24405 +set srcfile ${testfile}.S
24406 +set binfile ${testfile}.x
24408 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
24412 +clean_restart $binfile
24414 +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
24415 diff --git a/gdb/testsuite/gdb.fortran/common-block.exp b/gdb/testsuite/gdb.fortran/common-block.exp
24416 new file mode 100644
24417 index 0000000..888f6c3
24419 +++ b/gdb/testsuite/gdb.fortran/common-block.exp
24421 +# Copyright 2008 Free Software Foundation, Inc.
24423 +# This program is free software; you can redistribute it and/or modify
24424 +# it under the terms of the GNU General Public License as published by
24425 +# the Free Software Foundation; either version 2 of the License, or
24426 +# (at your option) any later version.
24428 +# This program is distributed in the hope that it will be useful,
24429 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24430 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24431 +# GNU General Public License for more details.
24433 +# You should have received a copy of the GNU General Public License
24434 +# along with this program; if not, write to the Free Software
24435 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24437 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24439 +set testfile "common-block"
24440 +set srcfile ${testfile}.f90
24441 +set binfile ${objdir}/${subdir}/${testfile}
24443 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
24444 + untested "Couldn't compile ${srcfile}"
24450 +gdb_reinitialize_dir $srcdir/$subdir
24451 +gdb_load ${binfile}
24453 +if ![runto MAIN__] then {
24454 + perror "couldn't run to breakpoint MAIN__"
24458 +gdb_breakpoint [gdb_get_line_number "stop-here-out"]
24459 +gdb_continue_to_breakpoint "stop-here-out"
24461 +# Common block naming with source name /foo/:
24462 +# .symtab DW_TAG_common_block's DW_AT_name
24463 +# Intel Fortran foo_ foo_
24464 +# GNU Fortran foo_ foo
24468 +set int4 {(integer\(kind=4\)|INTEGER\(4\))}
24469 +set real4 {(real\(kind=4\)|REAL\(4\))}
24470 +set real8 {(real\(kind=8\)|REAL\(8\))}
24472 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context."
24473 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context."
24474 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context."
24475 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24476 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24477 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context."
24479 +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"
24480 +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"
24482 +gdb_test "ptype ix" "type = $int4" "ptype ix out"
24483 +gdb_test "ptype iy" "type = $real4" "ptype iy out"
24484 +gdb_test "ptype iz" "type = $real8" "ptype iz out"
24485 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x out"
24486 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y out"
24487 +gdb_test "ptype iz_z" "type = $real8" "ptype iz_z out"
24489 +gdb_test "p ix" " = 1 *" "p ix out"
24490 +gdb_test "p iy" " = 2 *" "p iy out"
24491 +gdb_test "p iz" " = 3 *" "p iz out"
24492 +gdb_test "p ix_x" " = 11 *" "p ix_x out"
24493 +gdb_test "p iy_y" " = 22 *" "p iy_y out"
24494 +gdb_test "p iz_z" " = 33 *" "p iz_z out"
24496 +gdb_breakpoint [gdb_get_line_number "stop-here-in"]
24497 +gdb_continue_to_breakpoint "stop-here-in"
24499 +gdb_test "whatis foo$suffix" "No symbol \"foo$suffix\" in current context." "whatis foo$suffix in"
24500 +gdb_test "ptype foo$suffix" "No symbol \"foo$suffix\" in current context." "ptype foo$suffix in"
24501 +gdb_test "p foo$suffix" "No symbol \"foo$suffix\" in current context." "p foo$suffix in"
24502 +gdb_test "whatis fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "whatis fo_o$suffix in"
24503 +gdb_test "ptype fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "ptype fo_o$suffix in"
24504 +gdb_test "p fo_o$suffix" "No symbol \"fo_o$suffix\" in current context." "p fo_o$suffix in"
24506 +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"
24507 +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"
24509 +gdb_test "ptype ix" "type = $int4" "ptype ix in"
24510 +gdb_test "ptype iy2" "type = $real4" "ptype iy2 in"
24511 +gdb_test "ptype iz" "type = $real8" "ptype iz in"
24512 +gdb_test "ptype ix_x" "type = $int4" "ptype ix_x in"
24513 +gdb_test "ptype iy_y" "type = $real4" "ptype iy_y in"
24514 +gdb_test "ptype iz_z2" "type = $real8" "ptype iz_z2 in"
24516 +gdb_test "p ix" " = 11 *" "p ix in"
24517 +gdb_test "p iy2" " = 22 *" "p iy2 in"
24518 +gdb_test "p iz" " = 33 *" "p iz in"
24519 +gdb_test "p ix_x" " = 1 *" "p ix_x in"
24520 +gdb_test "p iy_y" " = 2 *" "p iy_y in"
24521 +gdb_test "p iz_z2" " = 3 *" "p iz_z2 in"
24522 diff --git a/gdb/testsuite/gdb.fortran/common-block.f90 b/gdb/testsuite/gdb.fortran/common-block.f90
24523 new file mode 100644
24524 index 0000000..b614e8a
24526 +++ b/gdb/testsuite/gdb.fortran/common-block.f90
24528 +! Copyright 2008 Free Software Foundation, Inc.
24530 +! This program is free software; you can redistribute it and/or modify
24531 +! it under the terms of the GNU General Public License as published by
24532 +! the Free Software Foundation; either version 2 of the License, or
24533 +! (at your option) any later version.
24535 +! This program is distributed in the hope that it will be useful,
24536 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24537 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24538 +! GNU General Public License for more details.
24540 +! You should have received a copy of the GNU General Public License
24541 +! along with this program; if not, write to the Free Software
24542 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24544 +! Ihis file is the Fortran source file for dynamic.exp.
24545 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
24546 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
24558 + common /fo_o/ix,iy2,iz
24559 + common /foo/ix_x,iy_y,iz_z2
24564 + if (ix .ne. 11 .or. iy2 .ne. 22.0 .or. iz .ne. 33.0) call abort
24565 + if (ix_x .ne. 1 .or. iy_y .ne. 2.0 .or. iz_z2 .ne. 3.0) call abort
24567 + ix = 0 ! stop-here-in
24571 +program common_test
24581 + common /foo/ix,iy,iz
24582 + common /fo_o/ix_x,iy_y,iz_z
24592 + call in ! stop-here-out
24594 +end program common_test
24595 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
24596 new file mode 100644
24597 index 0000000..cd3486b
24599 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
24601 +# Copyright 2009 Free Software Foundation, Inc.
24603 +# This program is free software; you can redistribute it and/or modify
24604 +# it under the terms of the GNU General Public License as published by
24605 +# the Free Software Foundation; either version 2 of the License, or
24606 +# (at your option) any later version.
24608 +# This program is distributed in the hope that it will be useful,
24609 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24610 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24611 +# GNU General Public License for more details.
24613 +# You should have received a copy of the GNU General Public License
24614 +# along with this program; if not, write to the Free Software
24615 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24617 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24619 +# This file is part of the gdb testsuite. Array element stride must not be
24620 +# specified in the number of elements but in a number of bytes instead.
24621 +# Original problem:
24622 +# (gdb) p c40pt(1)
24623 +# $1 = '0-hello', ' ' <repeats 33 times>
24624 +# (gdb) p c40pt(2)
24625 +# warning: Fortran array stride not divisible by the element size
24627 +set testfile dwarf-stride
24628 +set srcfile ${testfile}.f90
24630 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } {
24634 +if ![runto MAIN__] then {
24635 + perror "couldn't run to breakpoint MAIN__"
24639 +gdb_breakpoint [gdb_get_line_number "break-here"]
24640 +gdb_continue_to_breakpoint "break-here" ".*break-here.*"
24641 +gdb_test "p c40pt(1)" " = '0-hello.*"
24642 +gdb_test "p c40pt(2)" " = '1-hello.*"
24643 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
24644 new file mode 100644
24645 index 0000000..e492b3a
24647 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
24649 +! Copyright 2009 Free Software Foundation, Inc.
24651 +! This program is free software; you can redistribute it and/or modify
24652 +! it under the terms of the GNU General Public License as published by
24653 +! the Free Software Foundation; either version 2 of the License, or
24654 +! (at your option) any later version.
24656 +! This program is distributed in the hope that it will be useful,
24657 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24658 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24659 +! GNU General Public License for more details.
24661 +! You should have received a copy of the GNU General Public License
24662 +! along with this program; if not, write to the Free Software
24663 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24665 +! File written by Alan Matsuoka.
24669 + type small_stride
24670 + character*40 long_string
24671 + integer small_pad
24672 + end type small_stride
24674 + type(small_stride), dimension (20), target :: unpleasant
24675 + character*40, pointer, dimension(:):: c40pt
24680 + unpleasant(i+1)%small_pad = i+1
24681 + unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
24684 + c40pt => unpleasant%long_string
24686 + print *, c40pt ! break-here
24689 diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
24690 new file mode 100644
24691 index 0000000..0ccebe0
24693 +++ b/gdb/testsuite/gdb.fortran/dynamic.exp
24695 +# Copyright 2007 Free Software Foundation, Inc.
24697 +# This program is free software; you can redistribute it and/or modify
24698 +# it under the terms of the GNU General Public License as published by
24699 +# the Free Software Foundation; either version 2 of the License, or
24700 +# (at your option) any later version.
24702 +# This program is distributed in the hope that it will be useful,
24703 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
24704 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24705 +# GNU General Public License for more details.
24707 +# You should have received a copy of the GNU General Public License
24708 +# along with this program; if not, write to the Free Software
24709 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24711 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
24713 +# This file is part of the gdb testsuite. It contains tests for dynamically
24714 +# allocated Fortran arrays.
24715 +# It depends on the GCC dynamic Fortran arrays DWARF support:
24716 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
24718 +set testfile "dynamic"
24719 +set srcfile ${testfile}.f90
24720 +set binfile ${objdir}/${subdir}/${testfile}
24722 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
24723 + untested "Couldn't compile ${srcfile}"
24729 +gdb_reinitialize_dir $srcdir/$subdir
24730 +gdb_load ${binfile}
24732 +if ![runto MAIN__] then {
24733 + perror "couldn't run to breakpoint MAIN__"
24737 +gdb_breakpoint [gdb_get_line_number "varx-init"]
24738 +gdb_continue_to_breakpoint "varx-init"
24739 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
24740 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
24741 +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"
24742 +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"
24743 +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"
24745 +gdb_breakpoint [gdb_get_line_number "varx-allocated"]
24746 +gdb_continue_to_breakpoint "varx-allocated"
24747 +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
24748 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
24749 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
24750 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
24752 +gdb_breakpoint [gdb_get_line_number "varx-filled"]
24753 +gdb_continue_to_breakpoint "varx-filled"
24754 +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
24755 +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
24756 +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
24757 +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
24758 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
24759 +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"
24760 +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"
24762 +gdb_breakpoint [gdb_get_line_number "varv-associated"]
24763 +gdb_continue_to_breakpoint "varv-associated"
24764 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
24765 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
24766 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
24767 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
24768 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
24769 +# Intel Fortran Compiler 10.1.008 uses the pointer type.
24770 +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
24772 +gdb_breakpoint [gdb_get_line_number "varv-filled"]
24773 +gdb_continue_to_breakpoint "varv-filled"
24774 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
24775 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
24777 +gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
24778 +gdb_continue_to_breakpoint "varv-deassociated"
24779 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
24780 +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"
24781 +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"
24782 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
24783 +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
24784 +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
24786 +gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
24787 +gdb_continue_to_breakpoint "varx-deallocated"
24788 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
24789 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
24790 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
24791 +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"
24792 +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"
24794 +gdb_breakpoint [gdb_get_line_number "vary-passed"]
24795 +gdb_continue_to_breakpoint "vary-passed"
24796 +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
24797 +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
24799 +gdb_breakpoint [gdb_get_line_number "vary-filled"]
24800 +gdb_continue_to_breakpoint "vary-filled"
24801 +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
24802 +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
24803 +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
24804 +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
24805 +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
24806 +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
24808 +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
24809 +gdb_continue_to_breakpoint "varw-almostfilled"
24810 +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
24811 +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
24812 +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
24813 +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
24814 +# "up" works with GCC but other Fortran compilers may copy the values into the
24815 +# outer function only on the exit of the inner function.
24816 +# We need both variants as depending on the arch we optionally may still be
24817 +# executing the caller line or not after `finish'.
24818 +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
24819 +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
24820 +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
24821 +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
24822 +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
24824 +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
24825 +gdb_continue_to_breakpoint "varz-almostfilled"
24826 +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
24827 +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
24828 +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
24829 +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
24830 +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
24831 +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
24832 +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
24833 +gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
24834 +# maps to foo::vary(1,1)
24835 +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
24836 +# maps to foo::vary(2,2)
24837 +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
24838 +# maps to foo::vary(1,3)
24839 +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
24840 diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
24841 new file mode 100644
24842 index 0000000..0f43564
24844 +++ b/gdb/testsuite/gdb.fortran/dynamic.f90
24846 +! Copyright 2007 Free Software Foundation, Inc.
24848 +! This program is free software; you can redistribute it and/or modify
24849 +! it under the terms of the GNU General Public License as published by
24850 +! the Free Software Foundation; either version 2 of the License, or
24851 +! (at your option) any later version.
24853 +! This program is distributed in the hope that it will be useful,
24854 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24855 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24856 +! GNU General Public License for more details.
24858 +! You should have received a copy of the GNU General Public License
24859 +! along with this program; if not, write to the Free Software
24860 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24862 +! Ihis file is the Fortran source file for dynamic.exp.
24863 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
24864 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
24867 + real, target, allocatable :: varx (:, :, :)
24868 + real, pointer :: varv (:, :, :)
24869 + real, target :: varu (1, 2, 3)
24871 + allocate (varx (1:6, 5:15, 17:28)) ! varx-init
24872 + l = allocated (varx)
24873 + varx(:, :, :) = 6 ! varx-allocated
24874 + varx(1, 5, 17) = 7
24875 + varx(2, 6, 18) = 8
24876 + varx(6, 15, 28) = 9
24877 + varv => varx ! varx-filled
24878 + l = associated (varv)
24879 + varv(3, 7, 19) = 10 ! varv-associated
24880 + varv => null () ! varv-filled
24881 + l = associated (varv)
24882 + deallocate (varx) ! varv-deassociated
24883 + l = allocated (varx)
24884 + varu(:, :, :) = 10 ! varx-deallocated
24885 + allocate (varv (1:6, 5:15, 17:28))
24886 + l = associated (varv)
24887 + varv(:, :, :) = 6
24888 + varv(1, 5, 17) = 7
24889 + varv(2, 6, 18) = 8
24890 + varv(6, 15, 28) = 9
24891 + deallocate (varv)
24892 + l = associated (varv)
24894 + varv(1, 1, 1) = 6
24895 + varv(1, 2, 3) = 7
24896 + l = associated (varv)
24897 +end subroutine baz
24898 +subroutine foo (vary, varw)
24899 + real :: vary (:, :)
24900 + real :: varw (:, :, :)
24901 + vary(:, :) = 4 ! vary-passed
24905 + varw(:, :, :) = 5 ! vary-filled
24906 + varw(1, 1, 1) = 6
24907 + varw(2, 2, 2) = 7 ! varw-almostfilled
24908 +end subroutine foo
24909 +subroutine bar (varz, vart)
24911 + real :: vart (2:11, 7:*)
24913 + varz(2) = 5 ! varz-almostfilled
24914 + vart(2,7) = vart(2,7)
24915 +end subroutine bar
24918 + subroutine foo (vary, varw)
24919 + real :: vary (:, :)
24920 + real :: varw (:, :, :)
24924 + subroutine bar (varz, vart)
24926 + real :: vart (2:11, 7:*)
24929 + real :: x (10, 10), y (5), z(8, 8, 8)
24934 + call foo (x, z(2:6, 4:7, 6:8))
24936 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
24937 + if (x (1, 3) .ne. 10) call abort
24938 + if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
24939 + if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
24940 + call foo (transpose (x), z)
24941 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
24942 + if (x (3, 1) .ne. 10) call abort
24944 diff --git a/gdb/testsuite/gdb.fortran/library-module-lib.f90 b/gdb/testsuite/gdb.fortran/library-module-lib.f90
24945 new file mode 100644
24946 index 0000000..6369d34
24948 +++ b/gdb/testsuite/gdb.fortran/library-module-lib.f90
24950 +! Copyright 2009 Free Software Foundation, Inc.
24952 +! This program is free software; you can redistribute it and/or modify
24953 +! it under the terms of the GNU General Public License as published by
24954 +! the Free Software Foundation; either version 3 of the License, or
24955 +! (at your option) any later version.
24957 +! This program is distributed in the hope that it will be useful,
24958 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24959 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24960 +! GNU General Public License for more details.
24962 +! You should have received a copy of the GNU General Public License
24963 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
24966 + integer :: var_i = 1
24968 + subroutine lib_func
24969 + if (var_i .ne. 1) call abort
24971 + end subroutine lib_func
24975 + integer :: var_j = 3
24976 + integer :: var_k = 4
24977 +end module libmany
24978 diff --git a/gdb/testsuite/gdb.fortran/library-module-main.f90 b/gdb/testsuite/gdb.fortran/library-module-main.f90
24979 new file mode 100644
24980 index 0000000..de63a65
24982 +++ b/gdb/testsuite/gdb.fortran/library-module-main.f90
24984 +! Copyright 2009 Free Software Foundation, Inc.
24986 +! This program is free software; you can redistribute it and/or modify
24987 +! it under the terms of the GNU General Public License as published by
24988 +! the Free Software Foundation; either version 3 of the License, or
24989 +! (at your option) any later version.
24991 +! This program is distributed in the hope that it will be useful,
24992 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
24993 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24994 +! GNU General Public License for more details.
24996 +! You should have received a copy of the GNU General Public License
24997 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
25000 + use libmany, only: var_j
25001 + if (var_i .ne. 1) call abort
25003 + if (var_i .ne. 2) call abort
25004 + if (var_j .ne. 3) call abort
25005 + var_i = var_i ! i-is-2
25007 diff --git a/gdb/testsuite/gdb.fortran/library-module.exp b/gdb/testsuite/gdb.fortran/library-module.exp
25008 new file mode 100644
25009 index 0000000..4b4ea4c
25011 +++ b/gdb/testsuite/gdb.fortran/library-module.exp
25013 +# Copyright 2009 Free Software Foundation, Inc.
25015 +# This program is free software; you can redistribute it and/or modify
25016 +# it under the terms of the GNU General Public License as published by
25017 +# the Free Software Foundation; either version 3 of the License, or
25018 +# (at your option) any later version.
25020 +# This program is distributed in the hope that it will be useful,
25021 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25022 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25023 +# GNU General Public License for more details.
25025 +# You should have received a copy of the GNU General Public License
25026 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
25028 +set testfile "library-module"
25029 +set srcfile ${testfile}-main.f90
25030 +set srclibfile ${testfile}-lib.f90
25031 +set libfile ${testfile}-lib.so
25032 +set binfile ${testfile}
25034 +# Required for -fPIC by gdb_compile_shlib.
25035 +if [get_compiler_info not-used] {
25036 + warning "Could not get compiler info"
25040 +if { [gdb_compile_shlib "${srcdir}/${subdir}/${srclibfile}" $objdir/$subdir/$libfile {debug f77}] != "" } {
25041 + untested "Couldn't compile ${srclibfile}"
25045 +# prepare_for_testing cannot be used as linking with $libfile cannot be passed
25046 +# just for the linking phase (and not the source compilation phase). And any
25047 +# warnings on ignored $libfile abort the process.
25049 +if { [gdb_compile [list $srcdir/$subdir/$srcfile $objdir/$subdir/$libfile] $objdir/$subdir/$binfile executable {debug f77}] != "" } {
25050 + untested "Couldn't compile ${srcfile}"
25054 +clean_restart $binfile
25056 +if ![runto MAIN__] then {
25057 + perror "couldn't run to breakpoint MAIN__"
25061 +gdb_breakpoint [gdb_get_line_number "i-is-2"]
25062 +gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
25063 +gdb_test "print var_i" " = 2"
25064 +gdb_test "print var_j" " = 3"
25065 +gdb_test "print var_k" "No symbol \"var_k\" in current context\\."
25066 diff --git a/gdb/testsuite/gdb.fortran/logical.exp b/gdb/testsuite/gdb.fortran/logical.exp
25067 new file mode 100644
25068 index 0000000..ef76f43
25070 +++ b/gdb/testsuite/gdb.fortran/logical.exp
25072 +# Copyright 2007 Free Software Foundation, Inc.
25074 +# This program is free software; you can redistribute it and/or modify
25075 +# it under the terms of the GNU General Public License as published by
25076 +# the Free Software Foundation; either version 2 of the License, or
25077 +# (at your option) any later version.
25079 +# This program is distributed in the hope that it will be useful,
25080 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25081 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25082 +# GNU General Public License for more details.
25084 +# You should have received a copy of the GNU General Public License
25085 +# along with this program; if not, write to the Free Software
25086 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25088 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25090 +set testfile "logical"
25091 +set srcfile ${testfile}.f90
25092 +set binfile ${objdir}/${subdir}/${testfile}
25094 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25095 + untested "Couldn't compile ${srcfile}"
25101 +gdb_reinitialize_dir $srcdir/$subdir
25102 +gdb_load ${binfile}
25104 +if ![runto MAIN__] then {
25105 + perror "couldn't run to breakpoint MAIN__"
25109 +gdb_breakpoint [gdb_get_line_number "stop-here"]
25110 +gdb_continue_to_breakpoint "stop-here"
25111 +gdb_test "p l" " = \\.TRUE\\."
25112 +gdb_test "p l1" " = \\.TRUE\\."
25113 +gdb_test "p l2" " = \\.TRUE\\."
25114 +gdb_test "p l4" " = \\.TRUE\\."
25115 +gdb_test "p l8" " = \\.TRUE\\."
25116 diff --git a/gdb/testsuite/gdb.fortran/logical.f90 b/gdb/testsuite/gdb.fortran/logical.f90
25117 new file mode 100644
25118 index 0000000..4229304
25120 +++ b/gdb/testsuite/gdb.fortran/logical.f90
25122 +! Copyright 2008 Free Software Foundation, Inc.
25124 +! This program is free software; you can redistribute it and/or modify
25125 +! it under the terms of the GNU General Public License as published by
25126 +! the Free Software Foundation; either version 2 of the License, or
25127 +! (at your option) any later version.
25129 +! This program is distributed in the hope that it will be useful,
25130 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25131 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25132 +! GNU General Public License for more details.
25134 +! You should have received a copy of the GNU General Public License
25135 +! along with this program; if not, write to the Free Software
25136 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25138 +! Ihis file is the Fortran source file for dynamic.exp.
25139 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25140 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25144 + logical (kind=1) :: l1
25145 + logical (kind=2) :: l2
25146 + logical (kind=4) :: l4
25147 + logical (kind=8) :: l8
25153 + l = .FALSE. ! stop-here
25155 diff --git a/gdb/testsuite/gdb.fortran/module.exp b/gdb/testsuite/gdb.fortran/module.exp
25156 index 342ccee..c836c3c 100644
25157 --- a/gdb/testsuite/gdb.fortran/module.exp
25158 +++ b/gdb/testsuite/gdb.fortran/module.exp
25159 @@ -15,21 +15,31 @@
25161 set testfile "module"
25162 set srcfile ${testfile}.f90
25163 -set binfile ${objdir}/${subdir}/${testfile}
25165 -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25166 - untested "Couldn't compile ${srcfile}"
25167 +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f77}] } {
25173 -gdb_reinitialize_dir $srcdir/$subdir
25174 -gdb_load ${binfile}
25176 if ![runto MAIN__] then {
25177 perror "couldn't run to breakpoint MAIN__"
25181 -gdb_test "print i" " = 42"
25182 +# Do not use simple single-letter names as GDB would pick up for expectedly
25183 +# nonexisting symbols some static variables from system libraries debuginfos.
25185 +gdb_breakpoint [gdb_get_line_number "i-is-1"]
25186 +gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
25187 +gdb_test "print var_i" " = 1" "print var_i value 1"
25189 +gdb_breakpoint [gdb_get_line_number "i-is-2"]
25190 +gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
25191 +gdb_test "print var_i" " = 2" "print var_i value 2"
25193 +gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
25194 +gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
25195 +gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
25196 +gdb_test "print var_b" " = 11"
25197 +gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
25198 +gdb_test "print var_d" " = 12"
25199 +gdb_test "print var_i" " = 14" "print var_i value 14"
25200 diff --git a/gdb/testsuite/gdb.fortran/module.f90 b/gdb/testsuite/gdb.fortran/module.f90
25201 index 501ccc8..118931d 100644
25202 --- a/gdb/testsuite/gdb.fortran/module.f90
25203 +++ b/gdb/testsuite/gdb.fortran/module.f90
25204 @@ -13,10 +13,37 @@
25205 ! You should have received a copy of the GNU General Public License
25206 ! along with this program. If not, see <http://www.gnu.org/licenses/>.
25209 - integer :: i = 42
25212 + integer :: var_i = 1
25218 + integer :: var_i = 2
25222 + integer :: var_a = 10, var_b = 11, var_c = 12, var_i = 14
25223 +end module modmany
25227 + if (var_i .ne. 1) call abort
25228 + var_i = var_i ! i-is-1
25233 + if (var_i .ne. 2) call abort
25234 + var_i = var_i ! i-is-2
25237 + use modmany, only: var_b, var_d => var_c, var_i
25242 + if (var_b .ne. 11) call abort
25243 + if (var_d .ne. 12) call abort
25244 + if (var_i .ne. 14) call abort
25245 + var_b = var_b ! a-b-c-d
25247 diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
25248 new file mode 100644
25249 index 0000000..b1120c3
25251 +++ b/gdb/testsuite/gdb.fortran/string.exp
25253 +# Copyright 2008 Free Software Foundation, Inc.
25255 +# This program is free software; you can redistribute it and/or modify
25256 +# it under the terms of the GNU General Public License as published by
25257 +# the Free Software Foundation; either version 2 of the License, or
25258 +# (at your option) any later version.
25260 +# This program is distributed in the hope that it will be useful,
25261 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25262 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25263 +# GNU General Public License for more details.
25265 +# You should have received a copy of the GNU General Public License
25266 +# along with this program; if not, write to the Free Software
25267 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25269 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25271 +# This file is part of the gdb testsuite. It contains tests for Fortran
25272 +# strings with dynamic length.
25274 +set testfile "string"
25275 +set srcfile ${testfile}.f90
25276 +set binfile ${objdir}/${subdir}/${testfile}
25278 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
25279 + untested "Couldn't compile ${srcfile}"
25285 +gdb_reinitialize_dir $srcdir/$subdir
25286 +gdb_load ${binfile}
25288 +if ![runto MAIN__] then {
25289 + perror "couldn't run to breakpoint MAIN__"
25293 +gdb_breakpoint [gdb_get_line_number "var-init"]
25294 +gdb_continue_to_breakpoint "var-init"
25295 +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
25296 +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
25297 +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
25298 +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
25299 +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
25300 +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
25301 +gdb_test "p c" "\\$\[0-9\]* = 'c'"
25302 +gdb_test "p d" "\\$\[0-9\]* = 'd '"
25303 +gdb_test "p e" "\\$\[0-9\]* = 'g '"
25304 +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 '\\) \\)"
25305 +gdb_test "p *e" "Attempt to take contents of a non-pointer value."
25306 +gdb_test "p *f" "Attempt to take contents of a non-pointer value."
25308 +gdb_breakpoint [gdb_get_line_number "var-finish"]
25309 +gdb_continue_to_breakpoint "var-finish"
25310 +gdb_test "p e" "\\$\[0-9\]* = 'e '" "p e re-set"
25311 +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"
25312 diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
25313 new file mode 100644
25314 index 0000000..226dc5d
25316 +++ b/gdb/testsuite/gdb.fortran/string.f90
25318 +! Copyright 2008 Free Software Foundation, Inc.
25320 +! This program is free software; you can redistribute it and/or modify
25321 +! it under the terms of the GNU General Public License as published by
25322 +! the Free Software Foundation; either version 2 of the License, or
25323 +! (at your option) any later version.
25325 +! This program is distributed in the hope that it will be useful,
25326 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
25327 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25328 +! GNU General Public License for more details.
25330 +! You should have received a copy of the GNU General Public License
25331 +! along with this program; if not, write to the Free Software
25332 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25334 +! Ihis file is the Fortran source file for dynamic.exp.
25335 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25336 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25338 +subroutine foo (e, f)
25339 + character (len=1) :: c
25340 + character (len=8) :: d
25341 + character (len=*) :: e
25342 + character (len=*) :: f (1:7, 8:10)
25345 + e = 'e' ! var-init
25348 + c = 'c' ! var-finish
25349 +end subroutine foo
25350 + character (len=4) :: g, h (1:7, 8:10)
25355 diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
25356 index 495ae45..d08d7a4 100644
25357 --- a/gdb/testsuite/gdb.gdb/selftest.exp
25358 +++ b/gdb/testsuite/gdb.gdb/selftest.exp
25359 @@ -95,6 +95,10 @@ proc do_steps_and_nexts {} {
25360 set description "step over ttyarg initialization"
25363 + -re ".*python_script = 0.*$gdb_prompt $" {
25364 + set description "step over python_script initialization"
25365 + set command "step"
25367 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
25368 set description "next over get_run_time and everything it calls"
25370 diff --git a/gdb/testsuite/gdb.java/jnpe.exp b/gdb/testsuite/gdb.java/jnpe.exp
25371 new file mode 100644
25372 index 0000000..74d4d58
25374 +++ b/gdb/testsuite/gdb.java/jnpe.exp
25376 +# Copyright 2009 Free Software Foundation, Inc.
25378 +# This program is free software; you can redistribute it and/or modify
25379 +# it under the terms of the GNU General Public License as published by
25380 +# the Free Software Foundation; either version 3 of the License, or
25381 +# (at your option) any later version.
25383 +# This program is distributed in the hope that it will be useful,
25384 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25385 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25386 +# GNU General Public License for more details.
25388 +# You should have received a copy of the GNU General Public License
25389 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
25391 +if $tracelevel then {
25392 + strace $tracelevel
25395 +load_lib "java.exp"
25397 +set testfile "jnpe"
25398 +set srcfile ${srcdir}/$subdir/${testfile}.java
25399 +set binfile ${objdir}/${subdir}/${testfile}
25400 +if { [compile_java_from_source ${srcfile} ${binfile} "-g"] != "" } {
25401 + untested "Couldn't compile ${srcfile}"
25408 +# Start with a fresh gdb.
25412 +gdb_reinitialize_dir $srcdir/$subdir
25413 +gdb_load ${binfile}
25415 +set line [gdb_get_line_number "break here" $testfile.java]
25416 +gdb_test "break $testfile.java:$line" ""
25419 + "Current language.*java" \
25420 + "run java next-over-throw"
25422 +# See whether we have the needed unwinder hooks.
25424 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook in java" {
25425 + -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
25426 + pass "check for unwinder hook in java"
25428 + -re "No symbol .* in current context.\r\n$gdb_prompt $" {
25429 + # Pass the test so we don't get bogus fails in the results.
25430 + pass "check for unwinder hook in java"
25435 + untested jnpe.exp
25439 +gdb_test "handle SIGSEGV nostop noprint" \
25440 + "SIGSEGV.*fault" \
25441 + "disable SIGSEGV for next-over-NPE"
25443 +# We sometimes stop at line 37, not line 35. This seems to be a gcj
25444 +# oddity -- another next will solve it.
25448 diff --git a/gdb/testsuite/gdb.java/jnpe.java b/gdb/testsuite/gdb.java/jnpe.java
25449 new file mode 100644
25450 index 0000000..ffca3ab
25452 +++ b/gdb/testsuite/gdb.java/jnpe.java
25454 +// Test next-over-NPE.
25455 +/* This testcase is part of GDB, the GNU debugger.
25457 + Copyright 2009 Free Software Foundation, Inc.
25459 + This program is free software; you can redistribute it and/or modify
25460 + it under the terms of the GNU General Public License as published by
25461 + the Free Software Foundation; either version 3 of the License, or
25462 + (at your option) any later version.
25464 + This program is distributed in the hope that it will be useful,
25465 + but WITHOUT ANY WARRANTY; without even the implied warranty of
25466 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25467 + GNU General Public License for more details.
25469 + You should have received a copy of the GNU General Public License
25470 + along with this program. If not, see <http://www.gnu.org/licenses/>.
25475 + public static String npe ()
25477 + return ((Object) null).toString();
25480 + public static void main (String[] args)
25484 + System.out.println (npe ()); // break here
25486 + catch (NullPointerException n)
25488 + System.out.println ("success");
25492 diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
25493 new file mode 100644
25494 index 0000000..729f457
25496 +++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
25498 +/* This file is part of GDB, the GNU debugger.
25500 + Copyright 2009 Free Software Foundation, Inc.
25502 + This program is free software; you can redistribute it and/or modify
25503 + it under the terms of the GNU General Public License as published by
25504 + the Free Software Foundation; either version 3 of the License, or
25505 + (at your option) any later version.
25507 + This program is distributed in the hope that it will be useful,
25508 + but WITHOUT ANY WARRANTY; without even the implied warranty of
25509 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25510 + GNU General Public License for more details.
25512 + You should have received a copy of the GNU General Public License
25513 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
25520 diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
25521 new file mode 100644
25522 index 0000000..3090e7e
25524 +++ b/gdb/testsuite/gdb.opt/array-from-register.c
25526 +/* This file is part of GDB, the GNU debugger.
25528 + Copyright 2009 Free Software Foundation, Inc.
25530 + This program is free software; you can redistribute it and/or modify
25531 + it under the terms of the GNU General Public License as published by
25532 + the Free Software Foundation; either version 3 of the License, or
25533 + (at your option) any later version.
25535 + This program is distributed in the hope that it will be useful,
25536 + but WITHOUT ANY WARRANTY; without even the implied warranty of
25537 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25538 + GNU General Public License for more details.
25540 + You should have received a copy of the GNU General Public License
25541 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
25543 +extern int func (int *arr);
25548 + int arr[] = { 42 };
25554 diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
25555 new file mode 100644
25556 index 0000000..f2de718
25558 +++ b/gdb/testsuite/gdb.opt/array-from-register.exp
25560 +# Copyright 2009 Free Software Foundation, Inc.
25562 +# This program is free software; you can redistribute it and/or modify
25563 +# it under the terms of the GNU General Public License as published by
25564 +# the Free Software Foundation; either version 2 of the License, or
25565 +# (at your option) any later version.
25567 +# This program is distributed in the hope that it will be useful,
25568 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25569 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25570 +# GNU General Public License for more details.
25572 +# You should have received a copy of the GNU General Public License
25573 +# along with this program; if not, write to the Free Software
25574 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25576 +# This file is part of the gdb testsuite.
25578 +if { [prepare_for_testing array-from-register.exp "array-from-register" \
25579 + {array-from-register.c array-from-register-func.c} \
25580 + {debug optimize=-O2}] } {
25584 +if ![runto func] then {
25588 +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
25590 +# Seen regression:
25591 +# Address requested for identifier "arr" which is in register $rdi
25592 +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
25593 diff --git a/gdb/testsuite/gdb.opt/fortran-string.exp b/gdb/testsuite/gdb.opt/fortran-string.exp
25594 new file mode 100644
25595 index 0000000..f997eec
25597 +++ b/gdb/testsuite/gdb.opt/fortran-string.exp
25599 +# Copyright 2009 Free Software Foundation, Inc.
25601 +# This program is free software; you can redistribute it and/or modify
25602 +# it under the terms of the GNU General Public License as published by
25603 +# the Free Software Foundation; either version 2 of the License, or
25604 +# (at your option) any later version.
25606 +# This program is distributed in the hope that it will be useful,
25607 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25608 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25609 +# GNU General Public License for more details.
25611 +# You should have received a copy of the GNU General Public License
25612 +# along with this program; if not, write to the Free Software
25613 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25615 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
25617 +# Test GDB can cope with Fortran strings having their length present in a CPU
25618 +# register. With -O0 the string length is passed on the stack. To make this
25619 +# test meaningful the follow assertion should pass. It is not being checked
25620 +# here as the "_s" symbol is compiler dependent:
25621 +# (gdb) info address _s
25622 +# Symbol "_s" is a variable in register XX.
25624 +set test fortran-string
25625 +set srcfile ${test}.f90
25626 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile} {debug f77 additional_flags=-O2}] } {
25630 +if ![runto MAIN__] then {
25631 + perror "couldn't run to breakpoint MAIN__"
25635 +gdb_breakpoint [gdb_get_line_number "s = s"]
25636 +gdb_continue_to_breakpoint "s = s"
25637 +gdb_test "frame" ".*s='foo'.*"
25638 +gdb_test "ptype s" "type = character\\*3"
25639 +gdb_test "p s" "\\$\[0-9\]* = 'foo'"
25640 diff --git a/gdb/testsuite/gdb.opt/fortran-string.f90 b/gdb/testsuite/gdb.opt/fortran-string.f90
25641 new file mode 100644
25642 index 0000000..e48d520
25644 +++ b/gdb/testsuite/gdb.opt/fortran-string.f90
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 2 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, write to the Free Software
25660 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25662 +! Ihis file is the Fortran source file for dynamic.exp.
25663 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
25664 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
25674 diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
25675 index f6ef938..1032a2d 100644
25676 --- a/gdb/testsuite/gdb.python/py-cmd.exp
25677 +++ b/gdb/testsuite/gdb.python/py-cmd.exp
25678 @@ -20,36 +20,15 @@ if $tracelevel then {
25682 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
25683 -# Run a test named NAME, consisting of multiple lines of input.
25684 -# After each input line INPUT, search for result line RESULT.
25685 -# Succeed if all results are seen; fail otherwise.
25686 -proc gdb_py_test_multiple {name args} {
25687 - global gdb_prompt
25688 - foreach {input result} $args {
25689 - if {[gdb_test_multiple $input "$name - $input" {
25690 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
25691 - pass "$name - $input"
25700 # Start with a fresh gdb.
25704 gdb_reinitialize_dir $srcdir/$subdir
25706 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25707 - -re "not supported.*$gdb_prompt $" {
25708 - unsupported "python support is disabled"
25711 - -re "$gdb_prompt $" {}
25712 +if ![python_supported] then {
25713 + unsupported "python support is disabled"
25717 # Test a simple command.
25718 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
25719 index a67eaa3..5380c0f 100644
25720 --- a/gdb/testsuite/gdb.python/py-frame.exp
25721 +++ b/gdb/testsuite/gdb.python/py-frame.exp
25722 @@ -20,40 +20,28 @@ if $tracelevel then {
25726 +# Start with a fresh gdb.
25730 +gdb_reinitialize_dir $srcdir/$subdir
25732 +if ![python_supported] then {
25733 + unsupported "python support is disabled"
25737 set testfile "py-frame"
25738 set srcfile ${testfile}.c
25739 set binfile ${objdir}/${subdir}/${testfile}
25741 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
25742 untested "Couldn't compile ${srcfile}"
25746 -# Run a command in GDB, and report a failure if a Python exception is thrown.
25747 -# If report_pass is true, report a pass if no exception is thrown.
25748 -proc gdb_py_test_silent_cmd {cmd name report_pass} {
25749 - global gdb_prompt
25751 - gdb_test_multiple $cmd $name {
25752 - -re "Traceback.*$gdb_prompt $" { fail $name }
25753 - -re "$gdb_prompt $" { if $report_pass { pass $name } }
25757 -# Start with a fresh gdb.
25761 -gdb_reinitialize_dir $srcdir/$subdir
25762 gdb_load ${binfile}
25764 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25765 - -re "not supported.*$gdb_prompt $" {
25766 - unsupported "python support is disabled"
25769 - -re "$gdb_prompt $" {}
25772 # The following tests require execution.
25774 if ![runto_main] then {
25775 @@ -65,19 +53,20 @@ gdb_breakpoint "f2"
25776 gdb_continue_to_breakpoint "breakpoint at f2"
25777 gdb_test "up" "" ""
25779 -gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
25780 -gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
25781 +gdb_py_test_silent_cmd "python frames = gdb.selected_thread ().frames ()" "get frames list" 1
25782 +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"
25783 +gdb_py_test_silent_cmd "python f0 = frames\[0\]" "get first frame" 0
25784 +gdb_py_test_silent_cmd "python f1 = frames\[1\]" "get second frame" 0
25786 gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
25787 gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
25788 -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
25789 -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
25790 gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
25791 gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
25792 gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
25793 gdb_test "python print 'result =', f0.unwind_stop_reason () == gdb.FRAME_UNWIND_NO_REASON" " = True" "test Frame.type"
25794 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"
25795 gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
25796 +gdb_test "python print 'result =', f0.function ()" " = symbol for f2" "test Frame.function"
25797 gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older"
25798 gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer"
25799 gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \
25800 @@ -85,4 +74,7 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
25801 "test Frame.read_var - error"
25802 gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
25804 +gdb_test "python print 'result =', gdb.selected_thread ().newest_frame () == f0" " = True" "test gdb.newest_frame"
25805 gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
25807 +gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
25808 diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
25809 index 30fde7d..14cd90c 100644
25810 --- a/gdb/testsuite/gdb.python/py-function.exp
25811 +++ b/gdb/testsuite/gdb.python/py-function.exp
25812 @@ -20,36 +20,15 @@ if $tracelevel then {
25816 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
25817 -# Run a test named NAME, consisting of multiple lines of input.
25818 -# After each input line INPUT, search for result line RESULT.
25819 -# Succeed if all results are seen; fail otherwise.
25820 -proc gdb_py_test_multiple {name args} {
25821 - global gdb_prompt
25822 - foreach {input result} $args {
25823 - if {[gdb_test_multiple $input "$name - $input" {
25824 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
25825 - pass "$name - $input"
25834 # Start with a fresh gdb.
25838 gdb_reinitialize_dir $srcdir/$subdir
25840 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
25841 - -re "not supported.*$gdb_prompt $" {
25842 - unsupported "python support is disabled"
25845 - -re "$gdb_prompt $" {}
25846 +if ![python_supported] then {
25847 + unsupported "python support is disabled"
25851 gdb_py_test_multiple "input convenience function" \
25852 diff --git a/gdb/testsuite/gdb.python/py-inferior.c b/gdb/testsuite/gdb.python/py-inferior.c
25853 new file mode 100644
25854 index 0000000..0b48299
25856 +++ b/gdb/testsuite/gdb.python/py-inferior.c
25858 +#include <stdio.h>
25859 +#include <stdlib.h>
25860 +#include <stdint.h>
25861 +#include <string.h>
25863 +#define CHUNK_SIZE 16000 /* same as findcmd.c's */
25864 +#define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */
25866 +static int8_t int8_search_buf[100];
25867 +static int16_t int16_search_buf[100];
25868 +static int32_t int32_search_buf[100];
25869 +static int64_t int64_search_buf[100];
25871 +static char *search_buf;
25872 +static int search_buf_size;
25879 + char *str = "hello, testsuite";
25881 + puts (str); /* Break here. */
25886 +int f1 (int a, int b)
25888 + return f2(a) + b;
25894 + search_buf_size = BUF_SIZE;
25895 + search_buf = malloc (search_buf_size);
25896 + if (search_buf == NULL)
25898 + memset (search_buf, 'x', search_buf_size);
25901 +int main (int argc, char *argv[])
25905 + return f1 (1, 2);
25907 diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
25908 new file mode 100644
25909 index 0000000..719b178
25911 +++ b/gdb/testsuite/gdb.python/py-inferior.exp
25913 +# Copyright (C) 2009 Free Software Foundation, Inc.
25915 +# This program is free software; you can redistribute it and/or modify
25916 +# it under the terms of the GNU General Public License as published by
25917 +# the Free Software Foundation; either version 3 of the License, or
25918 +# (at your option) any later version.
25920 +# This program is distributed in the hope that it will be useful,
25921 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
25922 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25923 +# GNU General Public License for more details.
25925 +# You should have received a copy of the GNU General Public License
25926 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
25928 +# This file is part of the GDB testsuite. It tests the mechanism
25929 +# exposing inferiors to Python.
25931 +if $tracelevel then {
25932 + strace $tracelevel
25935 +# Start with a fresh gdb.
25939 +gdb_reinitialize_dir $srcdir/$subdir
25941 +if ![python_supported] then {
25942 + unsupported "python support is disabled"
25946 +set testfile "py-inferior"
25947 +set srcfile ${testfile}.c
25948 +set binfile ${objdir}/${subdir}/${testfile}
25950 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
25951 + untested "Couldn't compile ${srcfile}"
25955 +gdb_load ${binfile}
25957 +# The following tests require execution.
25959 +if ![runto_main] then {
25960 + fail "Can't run to main"
25964 +runto [gdb_get_line_number "Break here."]
25966 +# Test basic gdb.Inferior attributes and methods.
25968 +gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
25969 +gdb_test "python print inferiors" "\\(<gdb.Inferior object at 0x\[\[:xdigit:\]\]+>,\\)" "verify inferiors list"
25970 +gdb_py_test_silent_cmd "python i0 = inferiors\[0\]" "get first inferior" 0
25972 +gdb_test "python print 'result =', i0 == inferiors\[0\]" " = True" "test equality comparison (true)"
25973 +gdb_test "python print 'result =', i0.num" " = \[0-9\]+" "test Inferior.num"
25974 +gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid"
25975 +gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached"
25976 +gdb_test "python print i0.threads ()" "\\(<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>,\\)" "test Inferior.threads"
25978 +# Test memory read and write operations.
25980 +gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
25981 + "read str address" 0
25982 +gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5)" \
25983 + "read str contents" 1
25984 +gdb_py_test_silent_cmd "python str\[1\] = 'a'" "change str" 0
25985 +gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
25987 +gdb_test "print str" " = 0x\[\[:xdigit:\]\]+ \"hallo, testsuite\"" \
25988 + "ensure str was changed in the inferior"
25990 +# Test memory search.
25992 +set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
25993 +set dec_number {[0-9]+}
25994 +set history_prefix {[$][0-9]* = }
25995 +set newline {[\r\n]+}
25996 +set pattern_not_found "${newline}.]"
25997 +set one_pattern_found "${newline}.${dec_number}L]"
25998 +set two_patterns_found "${newline}.${dec_number}L, ${dec_number}L]"
26000 +# Test string pattern.
26002 +gdb_test "set *(int32_t*) &int8_search_buf\[10\] = 0x61616161" "" ""
26003 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int8_search_buf')" "" ""
26004 +gdb_test "py start_addr = search_buf.address" "" ""
26005 +gdb_test "py length = search_buf.type.sizeof" "" ""
26007 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa')" \
26008 + "${two_patterns_found}" "find string pattern"
26010 +# Test not finding pattern because search range too small, with
26011 +# potential find at the edge of the range.
26013 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3, 'aaaa')" \
26014 + "${pattern_not_found}" "pattern not found at end of range"
26016 +# Increase the search range by 1 and we should find the pattern.
26018 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 10+3+1, \['a', 'a', 'a', 'a'\])" \
26019 + "${one_pattern_found}" "pattern found at end of range"
26021 +# Test max-count with size, with different parameter position
26023 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], 1, 1)" \
26024 + "${one_pattern_found}" "size = 1, max_count = 1"
26026 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], 1, 2)" \
26027 + "${two_patterns_found}" "size = 1, max_count = 2, normal ordering"
26029 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], size = 1, max_count = 2)" \
26030 + "${two_patterns_found}" "size = 1, max_count = 2, normal ordering, with keywords"
26032 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \[0x61, 0x61\], max_count = 2, size = 1)" \
26033 + "${two_patterns_found}" "size = 1, max_count = 2, inverted ordering"
26035 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, \['a', 'a'\], max_count = 2)" \
26036 + "${two_patterns_found}" "max_count = 2, with keyword"
26038 +# Test 16-bit pattern.
26040 +gdb_test "set int16_search_buf\[10\] = 0x1234" "" ""
26041 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int16_search_buf')" "" ""
26042 +gdb_test "py start_addr = search_buf.address" "" ""
26043 +gdb_test "py length = search_buf.type.sizeof" "" ""
26044 +gdb_test "py pattern = gdb.parse_and_eval ('(int16_t) 0x1234')" "" ""
26046 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x1234, 2)" \
26047 + "${one_pattern_found}" "find 16-bit pattern, with python pattern"
26049 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26050 + "${one_pattern_found}" "find 16-bit pattern, with value pattern"
26052 +# Test 32-bit pattern.
26054 +gdb_test "set int32_search_buf\[10\] = 0x12345678" "" ""
26055 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int32_search_buf')" "" ""
26056 +gdb_test "py start_addr = search_buf.address" "" ""
26057 +gdb_test "py length = search_buf.type.sizeof" "" ""
26058 +gdb_test "py pattern = gdb.parse_and_eval ('(int32_t) 0x12345678')" "" ""
26060 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x12345678, 4)" \
26061 + "${one_pattern_found}" "find 32-bit pattern, with python pattern"
26062 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26063 + "${one_pattern_found}" "find 32-bit pattern, with value pattern"
26065 +# Test 64-bit pattern.
26067 +gdb_test "set int64_search_buf\[10\] = 0xfedcba9876543210LL" "" ""
26068 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('int64_search_buf')" "" ""
26069 +gdb_test "py start_addr = search_buf.address" "" ""
26070 +gdb_test "py length = search_buf.type.sizeof" "" ""
26071 +gdb_test "py pattern = gdb.parse_and_eval ('(int64_t) 0xfedcba9876543210LL')" "" ""
26073 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0xfedcba9876543210, 8)" \
26074 + "${one_pattern_found}" "find 64-bit pattern, with python pattern"
26075 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, pattern)" \
26076 + "${one_pattern_found}" "find 64-bit pattern, with value pattern"
26078 +# Test mixed-sized patterns.
26080 +gdb_test "set *(int8_t*) &search_buf\[10\] = 0x62" "" ""
26081 +gdb_test "set *(int16_t*) &search_buf\[11\] = 0x6363" "" ""
26082 +gdb_test "set *(int32_t*) &search_buf\[13\] = 0x64646464" "" ""
26083 +gdb_test "py search_buf = gdb.selected_frame ().read_var ('search_buf')" "" ""
26084 +gdb_test "py start_addr = search_buf\[0\].address" "" ""
26085 +gdb_test "py pattern1 = gdb.parse_and_eval ('(int8_t) 0x62')" "" ""
26086 +gdb_test "py pattern2 = gdb.parse_and_eval ('(int16_t) 0x6363')" "" ""
26087 +gdb_test "py pattern3 = gdb.parse_and_eval ('(int32_t) 0x64646464')" "" ""
26089 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, 100, \[pattern1, pattern2, pattern3\])" \
26090 + "${one_pattern_found}" "find mixed-sized pattern"
26092 +# Test search spanning a large range, in the particular case of native
26093 +# targets, test the search spanning multiple chunks.
26094 +# Remote targets may implement the search differently.
26096 +set CHUNK_SIZE 16000 ;
26098 +gdb_test "set *(int32_t*) &search_buf\[0*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
26099 +gdb_test "set *(int32_t*) &search_buf\[1*${CHUNK_SIZE}+100\] = 0x12345678" "" ""
26100 +gdb_test "py start_addr = gdb.selected_frame ().read_var ('search_buf')" "" ""
26101 +gdb_test "py length = gdb.selected_frame ().read_var ('search_buf_size')" "" ""
26103 +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0x12345678, 4)" \
26104 + "${two_patterns_found}" "search spanning large range"
26106 +# For native targets, test a pattern straddling a chunk boundary.
26109 + gdb_test "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531" "" ""
26111 + gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, length, 0xfdb97531, 4)" \
26112 + "${one_pattern_found}" "find pattern straddling chunk boundary"
26114 diff --git a/gdb/testsuite/gdb.python/py-infthread.c b/gdb/testsuite/gdb.python/py-infthread.c
26115 new file mode 100644
26116 index 0000000..22eb9f2
26118 +++ b/gdb/testsuite/gdb.python/py-infthread.c
26125 +int f1 (int a, int b)
26127 + return f2(a) + b;
26130 +int main (int argc, char *argv[])
26132 + return f1 (1, 2);
26134 diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
26135 new file mode 100644
26136 index 0000000..e9d18b7
26138 +++ b/gdb/testsuite/gdb.python/py-infthread.exp
26140 +# Copyright (C) 2009 Free Software Foundation, Inc.
26142 +# This program is free software; you can redistribute it and/or modify
26143 +# it under the terms of the GNU General Public License as published by
26144 +# the Free Software Foundation; either version 3 of the License, or
26145 +# (at your option) any later version.
26147 +# This program is distributed in the hope that it will be useful,
26148 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
26149 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26150 +# GNU General Public License for more details.
26152 +# You should have received a copy of the GNU General Public License
26153 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
26155 +# This file is part of the GDB testsuite. It tests the mechanism
26156 +# exposing inferior threads to Python.
26158 +if $tracelevel then {
26159 + strace $tracelevel
26162 +# Start with a fresh gdb.
26166 +gdb_reinitialize_dir $srcdir/$subdir
26168 +if ![python_supported] then {
26169 + unsupported "python support is disabled"
26173 +set testfile "py-infthread"
26174 +set srcfile ${testfile}.c
26175 +set binfile ${objdir}/${subdir}/${testfile}
26177 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26178 + untested "Couldn't compile ${srcfile}"
26182 +gdb_load ${binfile}
26184 +# The following tests require execution.
26186 +if ![runto_main] then {
26187 + fail "Can't run to main"
26191 +runto [gdb_get_line_number "Break here."]
26193 +# Test basic gdb.Inferior attributes and methods.
26195 +gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1
26196 +gdb_test "python print t0" "\\<gdb.InferiorThread object at 0x\[\[:xdigit:\]\]+>" "verify InferiorThread object"
26197 +gdb_test "python print 'result =', t0.num" " = \[0-9\]+" "test Inferior.num"
26198 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
26199 index b4b3776..359c4ed 100644
26200 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp
26201 +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
26202 @@ -27,12 +27,20 @@ set binfile ${objdir}/${subdir}/${testfile}
26203 # Start with a fresh gdb.
26206 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26207 - -re "not supported.*$gdb_prompt $" {
26208 - unsupported "python support is disabled"
26211 - -re "$gdb_prompt $" {}
26212 +if ![python_supported] then {
26213 + unsupported "python support is disabled"
26217 +# Run a command in GDB, and report a failure if a Python exception is thrown.
26218 +# If report_pass is true, report a pass if no exception is thrown.
26219 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
26220 + global gdb_prompt
26222 + gdb_test_multiple $cmd $name {
26223 + -re "Traceback.*$gdb_prompt $" { fail $name }
26224 + -re "$gdb_prompt $" { if $report_pass { pass $name } }
26228 # Run a command in GDB, and report a failure if a Python exception is thrown.
26229 @@ -102,6 +110,8 @@ proc run_lang_tests {lang} {
26231 gdb_test "print c" " = container $hex \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
26233 + gdb_test "print nullstr" "RuntimeError: Error reading string from inferior.*"
26235 gdb_test "continue" "Program exited normally\."
26238 diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp
26239 index cea6ae0..c9a63d4 100644
26240 --- a/gdb/testsuite/gdb.python/py-template.exp
26241 +++ b/gdb/testsuite/gdb.python/py-template.exp
26242 @@ -20,6 +20,17 @@ if $tracelevel then {
26246 +# Start with a fresh gdb.
26250 +gdb_reinitialize_dir $srcdir/$subdir
26252 +if ![python_supported] then {
26253 + unsupported "python support is disabled"
26257 set testfile "py-template"
26258 set srcfile ${testfile}.cc
26259 set binfile ${objdir}/${subdir}/${testfile}
26260 @@ -29,20 +40,6 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
26264 -# Start with a fresh gdb.
26268 -gdb_reinitialize_dir $srcdir/$subdir
26270 -gdb_test_multiple "python print 23" "verify python support" {
26271 - -re "not supported.*$gdb_prompt $" {
26272 - unsupported "python support is disabled"
26275 - -re "$gdb_prompt $" {}
26278 proc test_template_arg {type} {
26279 global testfile srcdir subdir srcfile binfile
26280 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
26281 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
26282 index 2958233..0de1cae 100644
26283 --- a/gdb/testsuite/gdb.python/py-value.exp
26284 +++ b/gdb/testsuite/gdb.python/py-value.exp
26285 @@ -292,6 +292,15 @@ proc test_value_after_death {} {
26286 "print value's type"
26289 +# Regression test for a cast failure. The bug was that if we cast a
26290 +# value to its own type, gdb could crash. This happened because we
26291 +# could end up double-freeing a struct value.
26292 +proc test_cast_regression {} {
26293 + gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
26294 + gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
26295 + gdb_test "python print v" "5" "print value for cast test"
26298 # Regression test for invalid subscript operations. The bug was that
26299 # the type of the value was not being checked before allowing a
26300 # subscript operation to proceed.
26301 @@ -366,16 +375,23 @@ proc test_subscript_regression {lang} {
26304 gdb_reinitialize_dir $srcdir/$subdir
26305 -gdb_load ${binfile}
26307 -gdb_test_multiple "python print 'hello, world!'" "verify python support" {
26308 - -re "not supported.*$gdb_prompt $" {
26309 - unsupported "python support is disabled"
26312 - -re "$gdb_prompt $" {}
26313 +if ![python_supported] then {
26314 + unsupported "python support is disabled"
26318 +set testfile "py-value"
26319 +set srcfile ${testfile}.c
26320 +set binfile ${objdir}/${subdir}/${testfile}
26322 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26323 + untested "Couldn't compile ${srcfile}"
26327 +gdb_load ${binfile}
26329 test_value_creation
26330 test_value_numeric_ops
26332 @@ -391,6 +407,7 @@ if ![runto_main] then {
26334 test_value_in_inferior
26335 test_value_after_death
26336 +test_cast_regression
26338 # The following test recompiles the binary to test either C or C++
26340 diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
26341 index 5223fc8..03e1eab 100644
26342 --- a/gdb/testsuite/gdb.python/python.exp
26343 +++ b/gdb/testsuite/gdb.python/python.exp
26344 @@ -26,30 +26,9 @@ gdb_exit
26346 gdb_reinitialize_dir $srcdir/$subdir
26348 -gdb_test_multiple "python print 23" "verify python support" {
26349 - -re "not supported.*$gdb_prompt $" {
26350 - unsupported "python support is disabled"
26353 - -re "$gdb_prompt $" {}
26356 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
26357 -# Run a test named NAME, consisting of multiple lines of input.
26358 -# After each input line INPUT, search for result line RESULT.
26359 -# Succeed if all results are seen; fail otherwise.
26360 -proc gdb_py_test_multiple {name args} {
26361 - global gdb_prompt
26362 - foreach {input result} $args {
26363 - if {[gdb_test_multiple $input "$name - $input" {
26364 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
26365 - pass "$name - $input"
26372 +if ![python_supported] then {
26373 + unsupported "python support is disabled"
26377 gdb_py_test_multiple "multi-line python command" \
26378 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
26379 new file mode 100644
26380 index 0000000..4dc308b
26382 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
26384 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26386 + Copyright 2008, 2009 Free Software Foundation, Inc.
26388 + This file is part of GDB.
26390 + This program is free software; you can redistribute it and/or modify
26391 + it under the terms of the GNU General Public License as published by
26392 + the Free Software Foundation; either version 2 of the License, or
26393 + (at your option) any later version.
26395 + This program is distributed in the hope that it will be useful,
26396 + but WITHOUT ANY WARRANTY; without even the implied warranty of
26397 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26398 + GNU General Public License for more details.
26400 + You should have received a copy of the GNU General Public License
26401 + along with this program; if not, write to the Free Software
26402 + Foundation, Inc., 59 Temple Place - Suite 330,
26403 + Boston, MA 02111-1307, USA. */
26405 +#include <string.h>
26406 +#include <errno.h>
26411 + int i = usleep (1000000 / 100);
26412 + assert (i == 0 || errno == EINTR);
26415 +#if defined FOLLOW_PARENT
26420 + pid_t child, pid_got;
26421 + int exit_code = 42 + nr;
26430 + printf ("child%d: %d\n", nr, (int) getpid ());
26431 + /* Delay to get both the "child%d" and "parent%d" message printed without
26432 + a race breaking expect by its endless wait on `$gdb_prompt$':
26433 + Breakpoint 3, breakpoint () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
26435 + (gdb) parent2: 14223 */
26439 + /* We must not get caught here (against a forgotten breakpoint). */
26443 + _exit (exit_code);
26445 + printf ("parent%d: %d\n", nr, (int) child);
26446 + /* Delay to get both the "child%d" and "parent%d" message printed, see
26451 + pid_got = wait (&status);
26452 + assert (pid_got == child);
26453 + assert (WIFEXITED (status));
26454 + assert (WEXITSTATUS (status) == exit_code);
26456 + /* We must get caught here (against a false watchpoint removal). */
26461 +#elif defined FOLLOW_CHILD
26463 +static volatile int usr1_got;
26466 +handler_usr1 (int signo)
26476 + struct sigaction act, oldact;
26478 + void *thread_result;
26481 + memset (&act, 0, sizeof act);
26482 + act.sa_flags = SA_RESTART;
26483 + act.sa_handler = handler_usr1;
26484 + sigemptyset (&act.sa_mask);
26485 + i = sigaction (SIGUSR1, &act, &oldact);
26494 + printf ("parent%d: %d\n", nr, (int) child);
26496 + /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB
26497 + tracing the child fork with no longer valid thread/lwp entries of the
26503 + /* We must not get caught here (against a forgotten breakpoint). */
26509 + /* And neither got caught our thread. */
26512 + i = pthread_join (thread, &thread_result);
26514 + assert (thread_result == (void *) 99UL);
26517 + /* Be sure our child knows we did not get caught above. */
26519 + i = kill (child, SIGUSR1);
26522 + /* Sleep for a while to check GDB's `info threads' no longer tracks us in
26523 + the child fork. */
26530 + printf ("child%d: %d\n", nr, (int) getpid ());
26532 + /* Let the parent signal us about its success. Be careful of races. */
26534 + for (loop = 0; loop < 1000; loop++)
26536 + /* Parent either died (and USR1_GOT is zero) or it succeeded. */
26537 + if (kill (getppid (), 0) != 0)
26539 + /* Parent succeeded? */
26545 + assert (usr1_got);
26547 + /* We must get caught here (against a false watchpoint removal). */
26552 + i = sigaction (SIGUSR1, &oldact, NULL);
26557 +# error "!FOLLOW_PARENT && !FOLLOW_CHILD"
26559 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
26560 new file mode 100644
26561 index 0000000..edacfc0
26563 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
26565 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26567 + Copyright 2008, 2009 Free Software Foundation, Inc.
26569 + This file is part of GDB.
26571 + This program is free software; you can redistribute it and/or modify
26572 + it under the terms of the GNU General Public License as published by
26573 + the Free Software Foundation; either version 2 of the License, or
26574 + (at your option) any later version.
26576 + This program is distributed in the hope that it will be useful,
26577 + but WITHOUT ANY WARRANTY; without even the implied warranty of
26578 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26579 + GNU General Public License for more details.
26581 + You should have received a copy of the GNU General Public License
26582 + along with this program; if not, write to the Free Software
26583 + Foundation, Inc., 59 Temple Place - Suite 330,
26584 + Boston, MA 02111-1307, USA. */
26586 +#include <assert.h>
26587 +#include <unistd.h>
26588 +#include <sys/wait.h>
26589 +#include <stdio.h>
26590 +#include <stdlib.h>
26591 +#include <pthread.h>
26593 +#include <asm/unistd.h>
26594 +#include <unistd.h>
26595 +#define gettid() syscall (__NR_gettid)
26597 +/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
26598 + variable. Hit-comments need to be duplicite there to catch both at-stops
26599 + and behind-stops, depending on the target. */
26601 +static volatile int var;
26613 +/* Include here the functions:
26614 + static void forkoff (int nr);
26615 + static void delay (void); */
26617 +static pthread_t thread;
26618 +static volatile int step;
26621 +#include "watchpoint-fork-forkoff.c"
26629 + while (step != 1)
26632 + var++; /* validity-thread-B */
26633 + dummy (); /* validity-thread-B */
26635 + while (step != 3)
26646 + var++; /* after-fork1-B */
26647 + dummy (); /* after-fork1-B */
26649 + while (step != 5)
26657 + var++; /* after-fork2-B */
26658 + dummy (); /* after-fork2-B */
26659 + return (void *) 5UL;
26662 + /* We must not get caught here (against a forgotten breakpoint). */
26665 + return (void *) 99UL;
26672 + void *thread_result;
26674 + setbuf (stdout, NULL);
26675 + printf ("main: %d\n", (int) gettid ());
26677 + /* General watchpoints validity. */
26678 + var++; /* validity-first */
26679 + dummy (); /* validity-first */
26681 + i = pthread_create (&thread, NULL, start, NULL);
26684 + var++; /* validity-thread-A */
26685 + dummy (); /* validity-thread-A */
26687 + while (step != 2)
26690 + /* Hardware watchpoints got disarmed here. */
26693 + var++; /* after-fork1-A */
26694 + dummy (); /* after-fork1-A */
26696 +#ifdef FOLLOW_CHILD
26697 + /* Spawn new thread as it was deleted in the child of FORK. */
26698 + i = pthread_create (&thread, NULL, start, NULL);
26701 + while (step != 4)
26704 + /* A sanity check for double hardware watchpoints removal. */
26707 + var++; /* after-fork2-A */
26708 + dummy (); /* after-fork2-A */
26710 +#ifdef FOLLOW_CHILD
26711 + /* Spawn new thread as it was deleted in the child of FORK. */
26712 + i = pthread_create (&thread, NULL, start, NULL);
26716 + i = pthread_join (thread, &thread_result);
26718 + assert (thread_result == (void *) 5UL);
26722 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.c b/gdb/testsuite/gdb.threads/watchpoint-fork.c
26723 new file mode 100644
26724 index 0000000..5f62e7f
26726 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.c
26728 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
26730 + Copyright 2008, 2009 Free Software Foundation, Inc.
26732 + This file is part of GDB.
26734 + This program is free software; you can redistribute it and/or modify
26735 + it under the terms of the GNU General Public License as published by
26736 + the Free Software Foundation; either version 2 of the License, or
26737 + (at your option) any later version.
26739 + This program is distributed in the hope that it will be useful,
26740 + but WITHOUT ANY WARRANTY; without even the implied warranty of
26741 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26742 + GNU General Public License for more details.
26744 + You should have received a copy of the GNU General Public License
26745 + along with this program; if not, write to the Free Software
26746 + Foundation, Inc., 59 Temple Place - Suite 330,
26747 + Boston, MA 02111-1307, USA. */
26749 +#include <assert.h>
26750 +#include <unistd.h>
26751 +#include <sys/wait.h>
26752 +#include <stdio.h>
26753 +#include <stdlib.h>
26755 +static volatile int var;
26762 +/* Include here the function:
26763 + static void forkoff (int nr); */
26765 +#include "watchpoint-fork-forkoff.c"
26770 + setbuf (stdout, NULL);
26771 + printf ("main: %d\n", (int) getpid ());
26773 + /* General watchpoints validity. */
26775 + /* Hardware watchpoints got disarmed here. */
26777 + /* This watchpoint got lost before. */
26779 + /* A sanity check for double hardware watchpoints removal. */
26785 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
26786 new file mode 100644
26787 index 0000000..1dc93ab
26789 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
26791 +# Copyright 2008, 2009 Free Software Foundation, Inc.
26793 +# This program is free software; you can redistribute it and/or modify
26794 +# it under the terms of the GNU General Public License as published by
26795 +# the Free Software Foundation; either version 3 of the License, or
26796 +# (at your option) any later version.
26798 +# This program is distributed in the hope that it will be useful,
26799 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
26800 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26801 +# GNU General Public License for more details.
26803 +# You should have received a copy of the GNU General Public License
26804 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
26806 +# Test case for forgotten hw-watchpoints after fork()-off of a process.
26808 +proc test {type symbol} {
26809 + global objdir subdir srcdir
26811 + set test watchpoint-fork
26814 + set prefix_test $pf_prefix
26815 + lappend pf_prefix "$type:"
26816 + set prefix_mt $pf_prefix
26820 + set pf_prefix $prefix_mt
26821 + lappend pf_prefix "singlethreaded:"
26823 + set executable ${test}-${type}
26824 + if { [gdb_compile ${srcdir}/${subdir}/${test}.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
26825 + untested ${test}.exp
26828 + clean_restart $executable
26830 + gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on."
26831 + gdb_test "set follow-fork-mode $type"
26832 + gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"."
26833 + # Testcase uses it for the `follow-fork-mode child' type.
26834 + gdb_test "handle SIGUSR1 nostop noprint pass"
26836 + if { ![runto_main] } then {
26837 + gdb_suppress_tests
26841 + # Install the watchpoint only after getting into MAIN - workaround some PPC
26843 + gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
26845 + # It is never hit but it should not be left over in the fork()ed-off child.
26846 + gdb_breakpoint "breakpoint"
26848 + gdb_test "continue" \
26849 + "atchpoint 2: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
26850 + gdb_test "continue" \
26851 + "reakpoint 3, breakpoint.*" "breakpoint after the first fork"
26852 + gdb_test "continue" \
26853 + "atchpoint 2: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
26854 + gdb_test "continue" \
26855 + "reakpoint 3, breakpoint.*" "breakpoint after the second fork"
26856 + gdb_test "continue" \
26857 + "atchpoint 2: var.*Old value = 2.*New value = 3.*return *0;" "watchpoint after the second fork"
26858 + gdb_test "continue" "Continuing..*Program exited normally." "finish"
26863 + set pf_prefix $prefix_mt
26864 + lappend pf_prefix "multithreaded:"
26866 + set executable ${test}-mt-${type}
26867 + if { [gdb_compile_pthreads ${srcdir}/${subdir}/${test}-mt.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
26868 + untested ${test}.exp
26871 + clean_restart $executable
26873 + gdb_test "set follow-fork-mode $type"
26874 + # Testcase uses it for the `follow-fork-mode child' type.
26875 + gdb_test "handle SIGUSR1 nostop noprint pass"
26877 + if { ![runto_main] } then {
26878 + gdb_suppress_tests
26882 + # Install the watchpoint only after getting into MAIN - workaround some PPC
26884 + gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
26886 + # It is never hit but it should not be left over in the fork()ed-off child.
26887 + gdb_breakpoint "breakpoint"
26889 + gdb_test "continue" \
26890 + "atchpoint 2: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
26891 + gdb_test "continue" \
26892 + "atchpoint 2: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
26893 + gdb_test "continue" \
26894 + "atchpoint 2: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
26895 + gdb_test "continue" \
26896 + "reakpoint 3, breakpoint.*" "breakpoint (A) after the first fork"
26897 + gdb_test "continue" \
26898 + "atchpoint 2: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
26899 + gdb_test "continue" \
26900 + "atchpoint 2: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
26901 + gdb_test "continue" \
26902 + "reakpoint 3, breakpoint.*" "breakpoint (A) after the second fork"
26903 + gdb_test "continue" \
26904 + "atchpoint 2: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
26905 + gdb_test "continue" \
26906 + "atchpoint 2: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
26907 + gdb_test "continue" "Continuing..*Program exited normally." "finish"
26912 + set pf_prefix $prefix_test
26915 +test parent FOLLOW_PARENT
26917 +# Only GNU/Linux is known to support `set follow-fork-mode child'.
26918 +if {[istarget "*-*-linux*"]} {
26919 + test child FOLLOW_CHILD
26921 diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.c b/gdb/testsuite/gdb.threads/watchthreads-reorder.c
26922 new file mode 100644
26923 index 0000000..14f42d6
26925 +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.c
26927 +/* This testcase is part of GDB, the GNU debugger.
26929 + Copyright 2009 Free Software Foundation, Inc.
26931 + This program is free software; you can redistribute it and/or modify
26932 + it under the terms of the GNU General Public License as published by
26933 + the Free Software Foundation; either version 3 of the License, or
26934 + (at your option) any later version.
26936 + This program is distributed in the hope that it will be useful,
26937 + but WITHOUT ANY WARRANTY; without even the implied warranty of
26938 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26939 + GNU General Public License for more details.
26941 + You should have received a copy of the GNU General Public License
26942 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
26944 +#define _GNU_SOURCE
26945 +#include <pthread.h>
26946 +#include <stdio.h>
26947 +#include <limits.h>
26948 +#include <errno.h>
26949 +#include <stdlib.h>
26950 +#include <string.h>
26951 +#include <assert.h>
26952 +#include <sys/types.h>
26953 +#include <signal.h>
26954 +#include <unistd.h>
26955 +#include <asm/unistd.h>
26957 +#define gettid() syscall (__NR_gettid)
26959 +/* Terminate always in the main task, it can lock up with SIGSTOPped GDB
26961 +#define TIMEOUT (gettid () == getpid() ? 10 : 15)
26963 +static pthread_mutex_t gdbstop_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26965 +static pid_t thread1_tid;
26966 +static pthread_cond_t thread1_tid_cond = PTHREAD_COND_INITIALIZER;
26967 +static pthread_mutex_t thread1_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26969 +static pid_t thread2_tid;
26970 +static pthread_cond_t thread2_tid_cond = PTHREAD_COND_INITIALIZER;
26971 +static pthread_mutex_t thread2_tid_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26973 +static pthread_mutex_t terminate_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
26975 +static volatile int thread1_rwatch;
26976 +static volatile int thread2_rwatch;
26978 +static int unused1_rwatch;
26979 +static int unused2_rwatch;
26981 +/* Do not use alarm as it would create a ptrace event which would hang up us if
26982 + * we are being traced by GDB which we stopped ourselves. */
26984 +static void timed_mutex_lock (pthread_mutex_t *mutex)
26987 + struct timespec start, now;
26989 + i = clock_gettime (CLOCK_MONOTONIC, &start);
26994 + i = pthread_mutex_trylock (mutex);
26997 + assert (i == EBUSY);
26999 + i = clock_gettime (CLOCK_MONOTONIC, &now);
27001 + assert (now.tv_sec >= start.tv_sec);
27003 + while (now.tv_sec - start.tv_sec < TIMEOUT);
27005 + fprintf (stderr, "Timed out waiting for internal lock!\n");
27006 + exit (EXIT_FAILURE);
27010 +thread1_func (void *unused)
27013 + volatile int rwatch_store;
27015 + thread1_tid = gettid ();
27016 + i = pthread_cond_signal (&thread1_tid_cond);
27019 + /* Be sure GDB is already stopped before continuing. */
27020 + timed_mutex_lock (&gdbstop_mutex);
27021 + i = pthread_mutex_unlock (&gdbstop_mutex);
27024 + rwatch_store = thread1_rwatch;
27026 + /* Be sure the "T (tracing stop)" test can proceed for both threads. */
27027 + timed_mutex_lock (&terminate_mutex);
27028 + i = pthread_mutex_unlock (&terminate_mutex);
27035 +thread2_func (void *unused)
27038 + volatile int rwatch_store;
27040 + thread2_tid = gettid ();
27041 + i = pthread_cond_signal (&thread2_tid_cond);
27044 + /* Be sure GDB is already stopped before continuing. */
27045 + timed_mutex_lock (&gdbstop_mutex);
27046 + i = pthread_mutex_unlock (&gdbstop_mutex);
27049 + rwatch_store = thread2_rwatch;
27051 + /* Be sure the "T (tracing stop)" test can proceed for both threads. */
27052 + timed_mutex_lock (&terminate_mutex);
27053 + i = pthread_mutex_unlock (&terminate_mutex);
27059 +static const char *
27060 +proc_string (const char *filename, const char *line)
27063 + static char buf[LINE_MAX];
27064 + size_t line_len = strlen (line);
27066 + f = fopen (filename, "r");
27069 + fprintf (stderr, "fopen (\"%s\") for \"%s\": %s\n", filename, line,
27070 + strerror (errno));
27071 + exit (EXIT_FAILURE);
27073 + while (errno = 0, fgets (buf, sizeof (buf), f))
27077 + s = strchr (buf, '\n');
27078 + assert (s != NULL);
27081 + if (strncmp (buf, line, line_len) != 0)
27086 + fprintf (stderr, "fclose (\"%s\") for \"%s\": %s\n", filename, line,
27087 + strerror (errno));
27088 + exit (EXIT_FAILURE);
27091 + return &buf[line_len];
27095 + fprintf (stderr, "fgets (\"%s\": %s\n", filename, strerror (errno));
27096 + exit (EXIT_FAILURE);
27098 + fprintf (stderr, "\"%s\": No line \"%s\" found.\n", filename, line);
27099 + exit (EXIT_FAILURE);
27102 +static unsigned long
27103 +proc_ulong (const char *filename, const char *line)
27105 + const char *s = proc_string (filename, line);
27110 + retval = strtol (s, &end, 10);
27111 + if (retval < 0 || retval >= LONG_MAX || (end && *end))
27113 + fprintf (stderr, "\"%s\":\"%s\": %ld, %s\n", filename, line, retval,
27114 + strerror (errno));
27115 + exit (EXIT_FAILURE);
27121 +state_wait (pid_t process, const char *wanted)
27125 + struct timespec start, now;
27126 + const char *state;
27128 + i = asprintf (&filename, "/proc/%lu/status", (unsigned long) process);
27131 + i = clock_gettime (CLOCK_MONOTONIC, &start);
27136 + state = proc_string (filename, "State:\t");
27137 + if (strcmp (state, wanted) == 0)
27143 + if (sched_yield ())
27145 + perror ("sched_yield()");
27146 + exit (EXIT_FAILURE);
27149 + i = clock_gettime (CLOCK_MONOTONIC, &now);
27151 + assert (now.tv_sec >= start.tv_sec);
27153 + while (now.tv_sec - start.tv_sec < TIMEOUT);
27155 + fprintf (stderr, "Timed out waiting for PID %lu \"%s\" (now it is \"%s\")!\n",
27156 + (unsigned long) process, wanted, state);
27157 + exit (EXIT_FAILURE);
27160 +static volatile pid_t tracer = 0;
27161 +static pthread_t thread1, thread2;
27166 + printf ("Resuming GDB PID %lu.\n", (unsigned long) tracer);
27171 + int tracer_save = tracer;
27175 + i = kill (tracer_save, SIGCONT);
27181 +main (int argc, char **argv)
27184 + int standalone = 0;
27186 + if (argc == 2 && strcmp (argv[1], "-s") == 0)
27189 + assert (argc == 1);
27191 + setbuf (stdout, NULL);
27193 + timed_mutex_lock (&gdbstop_mutex);
27195 + timed_mutex_lock (&terminate_mutex);
27197 + i = pthread_create (&thread1, NULL, thread1_func, NULL);
27200 + i = pthread_create (&thread2, NULL, thread2_func, NULL);
27205 + tracer = proc_ulong ("/proc/self/status", "TracerPid:\t");
27208 + fprintf (stderr, "The testcase must be run by GDB!\n");
27209 + exit (EXIT_FAILURE);
27211 + if (tracer != getppid ())
27213 + fprintf (stderr, "The testcase parent must be our GDB tracer!\n");
27214 + exit (EXIT_FAILURE);
27218 + /* SIGCONT our debugger in the case of our crash as we would deadlock
27221 + atexit (cleanup);
27223 + printf ("Stopping GDB PID %lu.\n", (unsigned long) tracer);
27227 + i = kill (tracer, SIGSTOP);
27229 + state_wait (tracer, "T (stopped)");
27232 + timed_mutex_lock (&thread1_tid_mutex);
27233 + timed_mutex_lock (&thread2_tid_mutex);
27235 + /* Let the threads start. */
27236 + i = pthread_mutex_unlock (&gdbstop_mutex);
27239 + printf ("Waiting till the threads initialize their TIDs.\n");
27241 + if (thread1_tid == 0)
27243 + i = pthread_cond_wait (&thread1_tid_cond, &thread1_tid_mutex);
27246 + assert (thread1_tid > 0);
27249 + if (thread2_tid == 0)
27251 + i = pthread_cond_wait (&thread2_tid_cond, &thread2_tid_mutex);
27254 + assert (thread2_tid > 0);
27257 + printf ("Thread 1 TID = %lu, thread 2 TID = %lu, PID = %lu.\n",
27258 + (unsigned long) thread1_tid, (unsigned long) thread2_tid,
27259 + (unsigned long) getpid ());
27261 + printf ("Waiting till the threads get trapped by the watchpoints.\n");
27265 + /* s390x-unknown-linux-gnu will fail with "R (running)". */
27267 + state_wait (thread1_tid, "T (tracing stop)");
27269 + state_wait (thread2_tid, "T (tracing stop)");
27274 + printf ("Joining the threads.\n");
27276 + i = pthread_mutex_unlock (&terminate_mutex);
27279 + i = pthread_join (thread1, NULL);
27282 + i = pthread_join (thread2, NULL);
27285 + printf ("Exiting.\n"); /* break-at-exit */
27287 + /* Just prevent compiler `warning:
\e$B!F
\e(BunusedX_rwatch
\e$B!G
\e(B defined but not used'. */
27288 + unused1_rwatch = 1;
27289 + unused2_rwatch = 2;
27291 + return EXIT_SUCCESS;
27293 diff --git a/gdb/testsuite/gdb.threads/watchthreads-reorder.exp b/gdb/testsuite/gdb.threads/watchthreads-reorder.exp
27294 new file mode 100644
27295 index 0000000..8f65364
27297 +++ b/gdb/testsuite/gdb.threads/watchthreads-reorder.exp
27299 +# This testcase is part of GDB, the GNU debugger.
27301 +# Copyright 2009 Free Software Foundation, Inc.
27303 +# This program is free software; you can redistribute it and/or modify
27304 +# it under the terms of the GNU General Public License as published by
27305 +# the Free Software Foundation; either version 3 of the License, or
27306 +# (at your option) any later version.
27308 +# This program is distributed in the hope that it will be useful,
27309 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
27310 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27311 +# GNU General Public License for more details.
27313 +# You should have received a copy of the GNU General Public License
27314 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
27316 +# Test GDB can cope with two watchpoints being hit by different threads at the
27317 +# same time, GDB reports one of them and after "continue" to report the other
27318 +# one GDB should not be confused by differently set watchpoints that time.
27319 +# This is the goal of "reorder1". "reorder0" tests the basic functionality of
27320 +# two watchpoint being hit at the same time, without reordering them during the
27321 +# stop. The formerly broken functionality is due to the all-stop mode default
27322 +# "show breakpoint always-inserted" being "off". Formerly the remembered hit
27323 +# could be assigned during continuation of a thread with pending SIGTRAP to the
27324 +# different/new watchpoint, just based on the watchpoint/debug register number.
27326 +if {[target_info exists gdb,no_hardware_watchpoints]
27327 + || ![istarget *-*-linux*]} {
27331 +set testfile "watchthreads-reorder"
27332 +set srcfile ${testfile}.c
27333 +set binfile ${objdir}/${subdir}/${testfile}
27334 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" ${binfile} executable [list debug additional_flags=-lrt]] != "" } {
27338 +foreach reorder {0 1} {
27341 + set prefix_test $pf_prefix
27342 + lappend pf_prefix "reorder$reorder:"
27344 + clean_restart $testfile
27346 + gdb_test "set can-use-hw-watchpoints 1"
27348 + if ![runto_main] {
27349 + gdb_suppress_tests
27352 + # Use "rwatch" as "watch" would report the watchpoint changed just based on its
27353 + # read memory value during a stop by unrelated event. We are interested to not
27354 + # to lose the hardware watchpoint trigger.
27356 + gdb_test "rwatch thread1_rwatch" "Hardware read watchpoint \[0-9\]+: thread1_rwatch"
27357 + gdb_test {set $rwatch1=$bpnum}
27358 + set test "rwatch thread2_rwatch"
27359 + gdb_test_multiple $test $test {
27360 + -re "Target does not support this type of hardware watchpoint\\.\r\n$gdb_prompt $" {
27361 + # ppc64 supports at most 1 hw watchpoints.
27362 + unsupported $test
27365 + -re "Hardware read watchpoint \[0-9\]+: thread2_rwatch\r\n$gdb_prompt $" {
27369 + gdb_test {set $rwatch2=$bpnum}
27370 + gdb_breakpoint [gdb_get_line_number "break-at-exit"]
27372 + # The watchpoints can happen in arbitrary order depending on random:
27373 + # SEL: Found 2 SIGTRAP events, selecting #[01]
27374 + # As GDB contains no srand() on the specific host/OS it will behave always the
27375 + # same. Such order cannot be guaranteed for GDB in general.
27377 + gdb_test "continue" \
27378 + "Hardware read watchpoint \[0-9\]+: thread\[12\]_rwatch\r\n\r\nValue = 0\r\n0x\[0-9a-f\]+ in thread\[12\]_func .*" \
27382 + gdb_test {delete $rwatch1}
27383 + gdb_test {delete $rwatch2}
27385 + gdb_test "rwatch unused1_rwatch" "Hardware read watchpoint \[0-9\]+: unused1_rwatch"
27386 + gdb_test "rwatch unused2_rwatch" "Hardware read watchpoint \[0-9\]+: unused2_rwatch"
27388 + gdb_test "rwatch thread1_rwatch" "Hardware read watchpoint \[0-9\]+: thread1_rwatch"
27389 + gdb_test "rwatch thread2_rwatch" "Hardware read watchpoint \[0-9\]+: thread2_rwatch"
27392 + gdb_test "continue" \
27393 + "Hardware read watchpoint \[0-9\]+: thread\[12\]_rwatch\r\n\r\nValue = 0\r\n0x\[0-9a-f\]+ in thread\[12\]_func .*" \
27396 + gdb_continue_to_breakpoint "break-at-exit" ".*break-at-exit.*"
27398 + set pf_prefix $prefix_test
27400 diff --git a/gdb/testsuite/lib/cp-support.exp b/gdb/testsuite/lib/cp-support.exp
27401 index dbd2f59..44e1b51 100644
27402 --- a/gdb/testsuite/lib/cp-support.exp
27403 +++ b/gdb/testsuite/lib/cp-support.exp
27404 @@ -222,7 +222,7 @@ proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table {
27407 gdb_test_multiple "$in_command" "$in_testname // parse failed" {
27408 - -re "type = (struct|class)${wsopt}(\[A-Za-z0-9_\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" {
27409 + -re "type = (struct|class)${wsopt}(\[A-Za-z0-9_:\]*)${wsopt}((:\[^\{\]*)?)${wsopt}\{(.*)\}${wsopt}(\[^\r\n\]*)\[\r\n\]+$gdb_prompt $" {
27411 set actual_key $expect_out(1,string)
27412 set actual_tag $expect_out(2,string)
27413 @@ -231,6 +231,7 @@ proc cp_test_ptype_class { in_command in_testname in_key in_tag in_class_table {
27414 set actual_tail $expect_out(6,string)
27418 if { ! $parse_okay } then { return }
27420 # Check the actual key. It would be nice to require that it match
27421 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
27422 index 0c93a73..d0c3493 100644
27423 --- a/gdb/testsuite/lib/gdb.exp
27424 +++ b/gdb/testsuite/lib/gdb.exp
27425 @@ -27,6 +27,7 @@ if {$tool == ""} {
27428 load_lib libgloss.exp
27429 +load_lib python-support.exp
27433 diff --git a/gdb/testsuite/lib/python-support.exp b/gdb/testsuite/lib/python-support.exp
27434 new file mode 100644
27435 index 0000000..b8e9836
27437 +++ b/gdb/testsuite/lib/python-support.exp
27439 +global python_supported_saved
27441 +# Return 1 if Python scripting is supported in GDB, 0 if not.
27442 +proc python_supported { } {
27443 + global gdb_prompt
27444 + global python_supported_saved
27446 + if [info exists python_supported_saved] {
27447 + verbose "python_supported: returning saved $python_supported_saved" 2
27448 + return $python_supported_saved
27451 + gdb_test_multiple "python print 'hello, world!'" "verify python support" {
27452 + -re "not supported.*$gdb_prompt $" {
27453 + return [set python_supported_saved 0]
27455 + -re "$gdb_prompt $" {
27456 + return [set python_supported_saved 1]
27460 + return [set python_supported_saved 0]
27463 +# Run a command in GDB, and report a failure if a Python exception is thrown.
27464 +# If report_pass is true, report a pass if no exception is thrown.
27465 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
27466 + global gdb_prompt
27468 + gdb_test_multiple $cmd $name {
27469 + -re "Traceback.*$gdb_prompt $" { fail $name }
27470 + -re "$gdb_prompt $" { if $report_pass { pass $name } }
27474 +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
27475 +# Run a test named NAME, consisting of multiple lines of input.
27476 +# After each input line INPUT, search for result line RESULT.
27477 +# Succeed if all results are seen; fail otherwise.
27478 +proc gdb_py_test_multiple {name args} {
27479 + global gdb_prompt
27481 + foreach {input result} $args {
27482 + if {[gdb_test_multiple $input "$name - $input" {
27483 + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
27484 + pass "$name - $input"
27492 diff --git a/gdb/thread.c b/gdb/thread.c
27493 index 55b4b96..e0ad2d3 100644
27496 @@ -61,7 +61,6 @@ static int thread_alive (struct thread_info *);
27497 static void info_threads_command (char *, int);
27498 static void thread_apply_command (char *, int);
27499 static void restore_current_thread (ptid_t);
27500 -static void prune_threads (void);
27502 /* Frontend view of the thread state. Possible extensions: stepping,
27503 finishing, until(ling),... */
27504 @@ -497,16 +496,23 @@ thread_alive (struct thread_info *tp)
27510 prune_threads (void)
27512 - struct thread_info *tp, *next;
27513 + struct thread_info *tp;
27514 + struct thread_info **prevp = &thread_list;
27516 - for (tp = thread_list; tp; tp = next)
27517 + for (tp = *prevp; tp; tp = *prevp)
27520 + /* If the thread has died, free it and unlink it from the list.
27521 + Otherwise, advance to the next thread. */
27522 if (!thread_alive (tp))
27523 - delete_thread (tp->ptid);
27525 + *prevp = tp->next;
27526 + free_thread (tp);
27529 + prevp = &tp->next;
27533 diff --git a/gdb/top.c b/gdb/top.c
27534 index 1b4aa9d..3cfe57e 100644
27537 @@ -349,6 +349,7 @@ void
27538 prepare_execute_command (void)
27540 free_all_values ();
27541 + free_all_types ();
27543 /* With multiple threads running while the one we're examining is stopped,
27544 the dcache can get stale without us being able to detect it.
27545 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
27546 index f090231..fc15ec1 100644
27547 --- a/gdb/typeprint.c
27548 +++ b/gdb/typeprint.c
27550 #include "gdb_string.h"
27551 #include "exceptions.h"
27552 #include "valprint.h"
27553 +#include "dwarf2loc.h"
27557 extern void _initialize_typeprint (void);
27558 @@ -76,6 +78,9 @@ void
27559 type_print (struct type *type, char *varstring, struct ui_file *stream,
27563 + type = check_typedef (type);
27565 LA_PRINT_TYPE (type, varstring, stream, show, 0);
27568 @@ -114,7 +119,8 @@ whatis_exp (char *exp, int show)
27570 struct expression *expr;
27572 - struct cleanup *old_chain = NULL;
27573 + /* Required at least for the object_address_set call. */
27574 + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
27575 struct type *real_type = NULL;
27578 @@ -125,12 +131,13 @@ whatis_exp (char *exp, int show)
27581 expr = parse_expression (exp);
27582 - old_chain = make_cleanup (free_current_contents, &expr);
27583 + make_cleanup (free_current_contents, &expr);
27584 val = evaluate_type (expr);
27587 val = access_value_history (0);
27589 + object_address_set (value_raw_address (val));
27590 type = value_type (val);
27592 get_user_print_options (&opts);
27593 @@ -167,8 +174,7 @@ whatis_exp (char *exp, int show)
27594 type_print (type, "", gdb_stdout, show);
27595 printf_filtered ("\n");
27598 - do_cleanups (old_chain);
27599 + do_cleanups (old_chain);
27603 diff --git a/gdb/typeprint.h b/gdb/typeprint.h
27604 index f561310..d261c79 100644
27605 --- a/gdb/typeprint.h
27606 +++ b/gdb/typeprint.h
27607 @@ -20,10 +20,13 @@
27608 #ifndef TYPEPRINT_H
27609 #define TYPEPRINT_H
27614 void print_type_scalar (struct type * type, LONGEST, struct ui_file *);
27616 void c_type_print_varspec_suffix (struct type *, struct ui_file *, int,
27619 +void c_type_print_args (struct type *, struct ui_file *, int, enum language);
27621 diff --git a/gdb/ui-file.c b/gdb/ui-file.c
27622 index 527917c..07d959a 100644
27623 --- a/gdb/ui-file.c
27624 +++ b/gdb/ui-file.c
27628 #include "ui-file.h"
27629 +#include "gdb_obstack.h"
27630 #include "gdb_string.h"
27633 @@ -263,7 +264,7 @@ set_ui_file_data (struct ui_file *file, void *data,
27636 /* ui_file utility function for converting a ``struct ui_file'' into
27637 - a memory buffer''. */
27638 + a memory buffer. */
27640 struct accumulated_ui_file
27642 @@ -297,6 +298,23 @@ ui_file_xstrdup (struct ui_file *file, long *length)
27643 *length = acc.length;
27648 +do_ui_file_obsavestring (void *context, const char *buffer, long length)
27650 + struct obstack *obstack = (struct obstack *) context;
27651 + obstack_grow (obstack, buffer, length);
27655 +ui_file_obsavestring (struct ui_file *file, struct obstack *obstack,
27658 + ui_file_put (file, do_ui_file_obsavestring, obstack);
27659 + *length = obstack_object_size (obstack);
27660 + obstack_1grow (obstack, '\0');
27661 + return obstack_finish (obstack);
27664 /* A pure memory based ``struct ui_file'' that can be used an output
27665 buffer. The buffers accumulated contents are available via
27666 diff --git a/gdb/ui-file.h b/gdb/ui-file.h
27667 index bf9915c..233206c 100644
27668 --- a/gdb/ui-file.h
27669 +++ b/gdb/ui-file.h
27677 /* Create a generic ui_file object with null methods. */
27678 @@ -77,7 +78,10 @@ extern void ui_file_put (struct ui_file *src, ui_file_put_method_ftype *write, v
27679 minus that appended NUL. */
27680 extern char *ui_file_xstrdup (struct ui_file *file, long *length);
27683 +/* Similar to ui_file_xstrdup, but return a new string allocated on
27685 +extern char *ui_file_obsavestring (struct ui_file *file,
27686 + struct obstack *obstack, long *length);
27688 extern long ui_file_read (struct ui_file *file, char *buf, long length_buf);
27690 diff --git a/gdb/utils.c b/gdb/utils.c
27691 index 16ad084..3021a43 100644
27694 @@ -2610,7 +2610,10 @@ fprintf_symbol_filtered (struct ui_file *stream, char *name,
27695 As an extra hack, string1=="FOO(ARGS)" matches string2=="FOO".
27696 This "feature" is useful when searching for matching C++ function names
27697 (such as if the user types 'break FOO', where FOO is a mangled C++
27701 + As an extra-special hack, we do the same with ' ', so that
27702 + "FOO(ARGS) const" can match "FOO", too. */
27705 strcmp_iw (const char *string1, const char *string2)
27706 @@ -2635,7 +2638,7 @@ strcmp_iw (const char *string1, const char *string2)
27710 - return (*string1 != '\0' && *string1 != '(') || (*string2 != '\0');
27711 + return (*string1 != ' ' && *string1 != '\0' && *string1 != '(') || (*string2 != '\0' && *string2 != '(');
27714 /* This is like strcmp except that it ignores whitespace and treats
27715 diff --git a/gdb/valarith.c b/gdb/valarith.c
27716 index a9c875d..12f6f07 100644
27717 --- a/gdb/valarith.c
27718 +++ b/gdb/valarith.c
27719 @@ -139,7 +139,6 @@ an integer nor a pointer of the same type."));
27721 value_subscript (struct value *array, LONGEST index)
27723 - struct value *bound;
27724 int c_style = current_language->c_style_arrays;
27725 struct type *tarray;
27727 @@ -154,12 +153,26 @@ value_subscript (struct value *array, LONGEST index)
27728 get_discrete_bounds (range_type, &lowerbound, &upperbound);
27730 if (VALUE_LVAL (array) != lval_memory)
27731 - return value_subscripted_rvalue (array, index, lowerbound);
27733 + if (index >= lowerbound && index <= upperbound)
27735 + CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
27736 + CORE_ADDR offset = (index - lowerbound) * element_size;
27738 + return value_subscripted_rvalue (array, offset);
27740 + error (_("array or string index out of range"));
27745 if (index >= lowerbound && index <= upperbound)
27746 - return value_subscripted_rvalue (array, index, lowerbound);
27748 + CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
27749 + CORE_ADDR offset = (index - lowerbound) * element_size;
27751 + return value_subscripted_rvalue (array, offset);
27753 /* Emit warning unless we have an array of unknown size.
27754 An array of unknown size has lowerbound 0 and upperbound -1. */
27755 if (upperbound > -1)
27756 @@ -178,33 +191,37 @@ value_subscript (struct value *array, LONGEST index)
27757 error (_("not an array or string"));
27760 -/* Return the value of EXPR[IDX], expr an aggregate rvalue
27761 - (eg, a vector register). This routine used to promote floats
27762 - to doubles, but no longer does. */
27763 +/* Return the value of *((void *) ARRAY + ELEMENT), ARRAY an aggregate rvalue
27764 + (eg, a vector register). This routine used to promote floats to doubles,
27765 + but no longer does. OFFSET is zero-based with 0 for the lowermost existing
27766 + element, it must be expressed in bytes (therefore multiplied by
27767 + check_typedef (TYPE_TARGET_TYPE (array_type)). */
27770 -value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
27771 +value_subscripted_rvalue (struct value *array, CORE_ADDR offset)
27773 struct type *array_type = check_typedef (value_type (array));
27774 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
27775 - unsigned int elt_size = TYPE_LENGTH (elt_type);
27776 - unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
27779 - if (index < lowerbound || elt_offs >= TYPE_LENGTH (array_type))
27780 - error (_("no such vector element"));
27781 + /* Do not check TYPE_LENGTH (array_type) as we may have been given the
27782 + innermost dimension of a multi-dimensional Fortran array where its length
27783 + is shorter than the possibly accessed element offset. */
27785 v = allocate_value (elt_type);
27786 if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
27787 set_value_lazy (v, 1);
27789 - memcpy (value_contents_writeable (v),
27790 - value_contents (array) + elt_offs, elt_size);
27792 + unsigned int elt_size = TYPE_LENGTH (elt_type);
27793 + memcpy (value_contents_writeable (v),
27794 + value_contents (array) + offset, elt_size);
27797 set_value_component_location (v, array);
27798 VALUE_REGNUM (v) = VALUE_REGNUM (array);
27799 VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
27800 - set_value_offset (v, value_offset (array) + elt_offs);
27801 + set_value_offset (v, value_offset (array) + offset);
27805 diff --git a/gdb/valops.c b/gdb/valops.c
27806 index b64cb21..b7d31cc 100644
27810 #include "cp-support.h"
27812 #include "user-regs.h"
27813 +#include "dwarf2loc.h"
27816 #include "gdb_string.h"
27817 @@ -369,8 +370,6 @@ value_cast (struct type *type, struct value *arg2)
27818 new_length = val_length / element_length;
27819 if (val_length % element_length != 0)
27820 warning (_("array element type size does not divide object size in cast"));
27821 - /* FIXME-type-allocation: need a way to free this type when
27822 - we are done with it. */
27823 range_type = create_range_type ((struct type *) NULL,
27824 TYPE_TARGET_TYPE (range_type),
27826 @@ -565,6 +564,64 @@ value_one (struct type *type, enum lval_type lv)
27830 +/* object_address_set must be already called before this function. */
27833 +object_address_data_not_valid (struct type *type)
27835 + /* Attributes are present only at the target type of a typedef. Make the
27836 + call conditional as it would otherwise loop through type_length_get. */
27837 + if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
27838 + CHECK_TYPEDEF (type);
27840 + /* DW_AT_associated has a preference over DW_AT_allocated. */
27841 + if (TYPE_NOT_ASSOCIATED (type)
27842 + || (TYPE_ASSOCIATED (type) != NULL
27843 + && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
27844 + return N_("object is not associated");
27846 + if (TYPE_NOT_ALLOCATED (type)
27847 + || (TYPE_ALLOCATED (type) != NULL
27848 + && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
27849 + return N_("object is not allocated");
27854 +/* Return non-zero if the variable is valid. If it is valid the function
27855 + may store the data address (DW_AT_DATA_LOCATION) of TYPE at *ADDRESS_RETURN.
27856 + You must set *ADDRESS_RETURN from value_raw_address (VAL) before calling this
27857 + function. If no DW_AT_DATA_LOCATION is present for TYPE the address at
27858 + *ADDRESS_RETURN is left unchanged. ADDRESS_RETURN must not be NULL, use
27859 + object_address_data_not_valid () for just the data validity check. */
27862 +object_address_get_data (struct type *type, CORE_ADDR *address_return)
27864 + gdb_assert (address_return != NULL);
27866 + object_address_set (*address_return);
27868 + /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
27869 + at the target type of a typedef. */
27870 + CHECK_TYPEDEF (type);
27872 + if (object_address_data_not_valid (type) != NULL)
27874 + /* Do not try to evaluate DW_AT_data_location as it may even crash
27875 + (it would just return the value zero in the gfortran case). */
27879 + if (TYPE_DATA_LOCATION_IS_ADDR (type))
27880 + *address_return = TYPE_DATA_LOCATION_ADDR (type);
27881 + else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
27883 + = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
27888 /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */
27890 static struct value *
27891 @@ -656,15 +713,21 @@ value_fetch_lazy (struct value *val)
27893 else if (VALUE_LVAL (val) == lval_memory)
27895 - CORE_ADDR addr = value_address (val);
27896 - int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
27897 + CORE_ADDR addr = value_raw_address (val);
27900 + if (object_address_get_data (value_type (val), &addr))
27902 - if (value_stack (val))
27903 - read_stack (addr, value_contents_all_raw (val), length);
27905 - read_memory (addr, value_contents_all_raw (val), length);
27906 + struct type *type = value_enclosing_type (val);
27907 + int length = TYPE_LENGTH (check_typedef (type));
27911 + addr += value_offset (val);
27912 + if (value_stack (val))
27913 + read_stack (addr, value_contents_all_raw (val), length);
27915 + read_memory (addr, value_contents_all_raw (val), length);
27919 else if (VALUE_LVAL (val) == lval_register)
27920 @@ -1070,7 +1133,18 @@ address_of_variable (struct symbol *var, struct block *b)
27921 if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
27922 || TYPE_CODE (type) == TYPE_CODE_FUNC)
27924 - CORE_ADDR addr = value_address (val);
27927 + if (VALUE_LVAL (val) == lval_memory)
27929 + addr = value_raw_address (val);
27930 + if (!object_address_get_data (type, &addr))
27931 + error (_("Can't take address of memory lvalue \"%s\"."),
27932 + SYMBOL_PRINT_NAME (var));
27933 + set_value_address (val, addr);
27936 + addr = value_address (val);
27937 return value_from_pointer (lookup_pointer_type (type), addr);
27940 @@ -1176,6 +1250,7 @@ struct value *
27941 value_coerce_array (struct value *arg1)
27943 struct type *type = check_typedef (value_type (arg1));
27944 + CORE_ADDR address;
27946 /* If the user tries to do something requiring a pointer with an
27947 array that has not yet been pushed to the target, then this would
27948 @@ -1185,8 +1260,12 @@ value_coerce_array (struct value *arg1)
27949 if (VALUE_LVAL (arg1) != lval_memory)
27950 error (_("Attempt to take address of value not located in memory."));
27952 + address = value_raw_address (arg1);
27953 + if (!object_address_get_data (type, &address))
27954 + error (_("Attempt to take address of non-valid value."));
27956 return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
27957 - value_address (arg1));
27958 + address + value_offset (arg1));
27961 /* Given a value which is a function, return a value which is a pointer
27962 @@ -2069,12 +2148,25 @@ find_overload_match (struct type **arg_types, int nargs,
27967 + /* OBJ may be a pointer value rather than the object itself. */
27968 + obj = coerce_ref (obj);
27969 + while (TYPE_CODE (check_typedef (value_type (obj))) == TYPE_CODE_PTR)
27970 + obj = coerce_ref (value_ind (obj));
27971 obj_type_name = TYPE_NAME (value_type (obj));
27972 - /* Hack: evaluate_subexp_standard often passes in a pointer
27973 - value rather than the object itself, so try again. */
27974 - if ((!obj_type_name || !*obj_type_name)
27975 - && (TYPE_CODE (value_type (obj)) == TYPE_CODE_PTR))
27976 - obj_type_name = TYPE_NAME (TYPE_TARGET_TYPE (value_type (obj)));
27978 + /* First check whether this is a data member, e.g. a pointer to
27980 + if (TYPE_CODE (check_typedef (value_type (obj))) == TYPE_CODE_STRUCT)
27982 + *valp = search_struct_field (name, obj, 0,
27983 + check_typedef (value_type (obj)), 0);
27991 fns_ptr = value_find_oload_method_list (&temp, name,
27993 @@ -2094,16 +2186,29 @@ find_overload_match (struct type **arg_types, int nargs,
27997 - const char *qualified_name = SYMBOL_CPLUS_DEMANGLED_NAME (fsym);
27998 + const char *qualified_name = SYMBOL_NATURAL_NAME (fsym);
28000 + /* If we have a function with a C++ name, try to extract just
28001 + the function part. Do not try this for non-functions (e.g.
28002 + function pointers). */
28003 + if (qualified_name
28004 + && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym))) == TYPE_CODE_FUNC)
28006 + func_name = cp_func_name (qualified_name);
28008 - /* If we have a C++ name, try to extract just the function
28010 - if (qualified_name)
28011 - func_name = cp_func_name (qualified_name);
28012 + /* If cp_func_name did not remove anything, the name of the
28013 + symbol did not include scope or argument types - it was
28014 + probably a C-style function. */
28015 + if (func_name && strcmp (func_name, qualified_name) == 0)
28017 + xfree (func_name);
28018 + func_name = NULL;
28022 - /* If there was no C++ name, this must be a C-style function.
28023 - Just return the same symbol. Do the same if cp_func_name
28024 - fails for some reason. */
28025 + /* If there was no C++ name, this must be a C-style function or
28026 + not a function at all. Just return the same symbol. Do the
28027 + same if cp_func_name fails for some reason. */
28028 if (func_name == NULL)
28031 @@ -2534,8 +2639,8 @@ check_field (struct type *type, const char *name)
28032 the comment before value_struct_elt_for_reference. */
28035 -value_aggregate_elt (struct type *curtype,
28036 - char *name, int want_address,
28037 +value_aggregate_elt (struct type *curtype, char *name,
28038 + struct type *expect_type, int want_address,
28039 enum noside noside)
28041 switch (TYPE_CODE (curtype))
28042 @@ -2543,7 +2648,7 @@ value_aggregate_elt (struct type *curtype,
28043 case TYPE_CODE_STRUCT:
28044 case TYPE_CODE_UNION:
28045 return value_struct_elt_for_reference (curtype, 0, curtype,
28047 + name, expect_type,
28048 want_address, noside);
28049 case TYPE_CODE_NAMESPACE:
28050 return value_namespace_elt (curtype, name,
28051 @@ -2554,6 +2659,56 @@ value_aggregate_elt (struct type *curtype,
28055 +/* Compares the two method/function types T1 and T2 for "equality"
28056 + with respect to the the methods' parameters. If the types of the
28057 + two parameter lists are the same, returns 1; 0 otherwise. This
28058 + comparison may ignore any artificial parameters in T1 if
28059 + SKIP_ARTIFICIAL is non-zero. This function will ALWAYS skip
28060 + the first artificial parameter in T1, assumed to be a 'this' pointer.
28062 + The type T2 is expected to have come from make_params (in eval.c). */
28064 +compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
28068 + if (TYPE_FIELD_ARTIFICIAL (t1, 0))
28071 + /* If skipping artificial fields, find the first real field
28073 + if (skip_artificial)
28075 + while (start < TYPE_NFIELDS (t1)
28076 + && TYPE_FIELD_ARTIFICIAL (t1, start))
28080 + /* Now compare parameters */
28082 + /* Special case: a method taking void. T1 will contain no
28083 + non-artificial fields, and T2 will contain TYPE_CODE_VOID. */
28084 + if ((TYPE_NFIELDS (t1) - start) == 0 && TYPE_NFIELDS (t2) == 1
28085 + && TYPE_CODE (TYPE_FIELD_TYPE (t2, 0)) == TYPE_CODE_VOID)
28088 + if ((TYPE_NFIELDS (t1) - start) == TYPE_NFIELDS (t2))
28091 + for (i = 0; i < TYPE_NFIELDS (t2); ++i)
28093 + if (rank_one_type (TYPE_FIELD_TYPE (t1, start + i),
28094 + TYPE_FIELD_TYPE (t2, i))
28105 /* C++: Given an aggregate type CURTYPE, and a member name NAME,
28106 return the address of this member as a "pointer to member" type.
28107 If INTYPE is non-null, then it will be the type of the member we
28108 @@ -2631,23 +2786,46 @@ value_struct_elt_for_reference (struct type *domain, int offset,
28110 if (t_field_name && strcmp (t_field_name, name) == 0)
28112 - int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
28114 + int len = TYPE_FN_FIELDLIST_LENGTH (t, i);
28115 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
28117 check_stub_method_group (t, i);
28119 - if (intype == 0 && j > 1)
28120 - error (_("non-unique member `%s' requires type instantiation"), name);
28124 - if (TYPE_FN_FIELD_TYPE (f, j) == intype)
28127 - error (_("no member function matches that type instantiation"));
28129 + for (j = 0; j < len; ++j)
28131 + if (compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 0)
28132 + || compare_parameters (TYPE_FN_FIELD_TYPE (f, j), intype, 1))
28137 + error (_("no member function matches that type instantiation")); }
28142 + /* Skip artificial methods. This is necessary if, for example,
28143 + the user wants to "print subclass::subclass" with only
28144 + one defined user constructor. There is no ambiguity in this
28146 + for (ii = 0; ii < TYPE_FN_FIELDLIST_LENGTH (t, i);
28149 + if (TYPE_FN_FIELD_ARTIFICIAL (f, ii))
28153 + /* Desired method is ambiguous if more than one method is
28156 + error (_("non-unique member `%s' requires type instantiation"), name);
28158 + /* This assumes, of course, that all artificial methods appear
28159 + BEFORE any concrete methods. */
28160 + j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1;
28163 if (TYPE_FN_FIELD_STATIC_P (f, j))
28165 @@ -2761,7 +2939,7 @@ value_maybe_namespace_elt (const struct type *curtype,
28166 struct symbol *sym;
28167 struct value *result;
28169 - sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
28170 + sym = cp_lookup_symbol_namespace(namespace_name, name,
28171 get_selected_block (0),
28174 @@ -2905,7 +3083,7 @@ value_of_local (const char *name, int complain)
28176 /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
28177 symbol instead of the LOC_ARG one (if both exist). */
28178 - sym = lookup_block_symbol (b, name, NULL, VAR_DOMAIN);
28179 + sym = lookup_block_symbol (b, name, VAR_DOMAIN);
28183 @@ -2959,8 +3137,6 @@ value_slice (struct value *array, int lowbound, int length)
28184 || lowbound + length - 1 > upperbound)
28185 error (_("slice out of range"));
28187 - /* FIXME-type-allocation: need a way to free this type when we are
28189 slice_range_type = create_range_type ((struct type *) NULL,
28190 TYPE_TARGET_TYPE (range_type),
28192 diff --git a/gdb/valprint.c b/gdb/valprint.c
28193 index cbb5d94..f9634ea 100644
28194 --- a/gdb/valprint.c
28195 +++ b/gdb/valprint.c
28196 @@ -236,7 +236,6 @@ scalar_type_p (struct type *type)
28197 case TYPE_CODE_STRUCT:
28198 case TYPE_CODE_UNION:
28199 case TYPE_CODE_SET:
28200 - case TYPE_CODE_STRING:
28201 case TYPE_CODE_BITSTRING:
28204 @@ -1153,6 +1152,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
28206 for (; i < len && things_printed < options->print_max; i++)
28208 + size_t elt_offset = i * eltlen;
28211 if (options->prettyprint_arrays)
28212 @@ -1172,7 +1172,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
28215 while ((rep1 < len) &&
28216 - !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen))
28217 + !memcmp (valaddr + elt_offset, valaddr + rep1 * eltlen, eltlen))
28221 diff --git a/gdb/value.c b/gdb/value.c
28222 index 589e03b..66013b7 100644
28228 #include "objfiles.h"
28229 +#include "cli/cli-decode.h"
28230 #include "valprint.h"
28231 #include "cli/cli-decode.h"
28232 +#include "observer.h"
28234 #include "python/python.h"
28236 @@ -170,6 +172,14 @@ struct value
28237 taken off this list. */
28238 struct value *next;
28240 + /* The reference count. A value that is still on the `all_values'
28241 + list will have a reference count of 0. A call to `release_value'
28242 + will increment the reference count (and remove the value from the
28243 + list, the first time). A call to `value_free' will decrement the
28244 + reference count, and will free the value when there are no more
28248 /* Register number if the value is from a register. */
28251 @@ -261,7 +271,9 @@ allocate_value_lazy (struct type *type)
28252 val->next = all_values;
28255 + type_incref (type);
28256 val->enclosing_type = type;
28257 + type_incref (type);
28258 VALUE_LVAL (val) = not_lval;
28259 val->location.address = 0;
28260 VALUE_FRAME_ID (val) = null_frame_id;
28261 @@ -346,6 +358,8 @@ value_type (struct value *value)
28263 deprecated_set_value_type (struct value *value, struct type *type)
28265 + type_incref (type);
28266 + type_decref (value->type);
28267 value->type = type;
28270 @@ -624,6 +638,9 @@ value_free (struct value *val)
28271 if (val->parent != NULL)
28272 value_free (val->parent);
28274 + type_decref (val->type);
28275 + type_decref (val->enclosing_type);
28277 if (VALUE_LVAL (val) == lval_computed)
28279 struct lval_funcs *funcs = val->location.computed.funcs;
28280 @@ -728,6 +745,9 @@ value_copy (struct value *arg)
28281 val = allocate_value_lazy (encl_type);
28283 val = allocate_value (encl_type);
28285 + type_incref (arg->type);
28286 + type_decref (val->type);
28287 val->type = arg->type;
28288 VALUE_LVAL (val) = VALUE_LVAL (arg);
28289 val->location = arg->location;
28290 @@ -763,12 +783,15 @@ value_copy (struct value *arg)
28292 set_value_component_location (struct value *component, struct value *whole)
28296 if (VALUE_LVAL (whole) == lval_internalvar)
28297 VALUE_LVAL (component) = lval_internalvar_component;
28299 VALUE_LVAL (component) = VALUE_LVAL (whole);
28301 component->location = whole->location;
28303 if (VALUE_LVAL (whole) == lval_computed)
28305 struct lval_funcs *funcs = whole->location.computed.funcs;
28306 @@ -776,6 +799,10 @@ set_value_component_location (struct value *component, struct value *whole)
28307 if (funcs->copy_closure)
28308 component->location.computed.closure = funcs->copy_closure (whole);
28311 + addr = value_raw_address (component);
28312 + object_address_get_data (value_type (whole), &addr);
28313 + set_value_address (component, addr);
28317 @@ -906,6 +933,29 @@ show_values (char *num_exp, int from_tty)
28322 +/* Sanity check for memory leaks and proper types reference counting. */
28325 +value_history_cleanup (void *unused)
28327 + while (value_history_chain)
28329 + struct value_history_chunk *chunk = value_history_chain;
28332 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
28333 + value_free (chunk->values[i]);
28335 + value_history_chain = chunk->next;
28338 + value_history_count = 0;
28340 + /* Free the unreferenced types above. */
28341 + free_all_values ();
28342 + free_all_types ();
28345 /* Internal variables. These are variables within the debugger
28346 that hold values assigned by debugger commands.
28347 @@ -1381,6 +1431,40 @@ call_internal_function (struct gdbarch *gdbarch,
28348 return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
28351 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
28354 +value_types_mark_used (void)
28356 + struct internalvar *var;
28357 + struct value_history_chunk *chunk;
28359 + for (var = internalvars; var != NULL; var = var->next)
28360 + switch (var->kind)
28362 + case INTERNALVAR_VALUE:
28363 + type_mark_used (value_type (var->u.value));
28366 + case INTERNALVAR_INTEGER:
28367 + type_mark_used (var->u.integer.type);
28370 + case INTERNALVAR_POINTER:
28371 + type_mark_used (var->u.pointer.type);
28375 + for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
28379 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
28380 + if (chunk->values[i])
28381 + type_mark_used (value_type (chunk->values[i]));
28385 /* The 'function' command. This does nothing -- it is just a
28386 placeholder to let "help function NAME" work. This is also used as
28387 the implementation of the sub-command that is created when
28388 @@ -1428,11 +1512,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
28389 htab_t copied_types)
28391 if (TYPE_OBJFILE (value->type) == objfile)
28392 - value->type = copy_type_recursive (objfile, value->type, copied_types);
28393 + value->type = copy_type_recursive (value->type, copied_types);
28395 if (TYPE_OBJFILE (value->enclosing_type) == objfile)
28396 - value->enclosing_type = copy_type_recursive (objfile,
28397 - value->enclosing_type,
28398 + value->enclosing_type = copy_type_recursive (value->enclosing_type,
28402 @@ -1447,13 +1530,13 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
28403 case INTERNALVAR_INTEGER:
28404 if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
28405 var->u.integer.type
28406 - = copy_type_recursive (objfile, var->u.integer.type, copied_types);
28407 + = copy_type_recursive (var->u.integer.type, copied_types);
28410 case INTERNALVAR_POINTER:
28411 if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
28412 var->u.pointer.type
28413 - = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
28414 + = copy_type_recursive (var->u.pointer.type, copied_types);
28417 case INTERNALVAR_VALUE:
28418 @@ -1855,6 +1938,8 @@ value_change_enclosing_type (struct value *val, struct type *new_encl_type)
28420 (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
28422 + type_incref (new_encl_type);
28423 + type_decref (val->enclosing_type);
28424 val->enclosing_type = new_encl_type;
28427 @@ -1919,6 +2004,8 @@ value_primitive_field (struct value *arg1, int offset,
28428 memcpy (value_contents_all_raw (v), value_contents_all_raw (arg1),
28429 TYPE_LENGTH (value_enclosing_type (arg1)));
28431 + type_incref (type);
28432 + type_decref (v->type);
28434 v->offset = value_offset (arg1);
28435 v->embedded_offset = (offset + value_embedded_offset (arg1)
28436 @@ -2177,6 +2264,42 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
28440 +/* Pack NUM into BUF using a target format of TYPE. */
28443 +pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
28445 + enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
28448 + type = check_typedef (type);
28449 + len = TYPE_LENGTH (type);
28451 + switch (TYPE_CODE (type))
28453 + case TYPE_CODE_INT:
28454 + case TYPE_CODE_CHAR:
28455 + case TYPE_CODE_ENUM:
28456 + case TYPE_CODE_FLAGS:
28457 + case TYPE_CODE_BOOL:
28458 + case TYPE_CODE_RANGE:
28459 + case TYPE_CODE_MEMBERPTR:
28460 + store_unsigned_integer (buf, len, byte_order, num);
28463 + case TYPE_CODE_REF:
28464 + case TYPE_CODE_PTR:
28465 + store_typed_address (buf, type, (CORE_ADDR) num);
28470 +Unexpected type (%d) encountered for unsigned integer constant."),
28471 + TYPE_CODE (type));
28476 /* Convert C numbers into newly allocated values. */
28479 @@ -2190,6 +2313,19 @@ value_from_longest (struct type *type, LONGEST num)
28483 +/* Convert C unsigned numbers into newly allocated values. */
28486 +value_from_ulongest (struct type *type, ULONGEST num)
28488 + struct value *val = allocate_value (type);
28490 + pack_unsigned_long (value_contents_raw (val), type, num);
28496 /* Create a value representing a pointer of type TYPE to the address
28499 @@ -2348,4 +2484,8 @@ VARIABLE is already initialized."));
28500 add_prefix_cmd ("function", no_class, function_command, _("\
28501 Placeholder command for showing help on convenience functions."),
28502 &functionlist, "function ", 0, &cmdlist);
28504 + make_final_cleanup (value_history_cleanup, NULL);
28506 + observer_attach_mark_used (value_types_mark_used);
28508 diff --git a/gdb/value.h b/gdb/value.h
28509 index 51e6960..48b30e4 100644
28512 @@ -342,11 +342,16 @@ extern LONGEST unpack_field_as_long (struct type *type,
28513 extern void pack_long (gdb_byte *buf, struct type *type, LONGEST num);
28515 extern struct value *value_from_longest (struct type *type, LONGEST num);
28516 +extern struct value *value_from_ulongest (struct type *type, ULONGEST num);
28517 extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
28518 extern struct value *value_from_double (struct type *type, DOUBLEST num);
28519 extern struct value *value_from_decfloat (struct type *type,
28520 const gdb_byte *decbytes);
28522 +extern const char *object_address_data_not_valid (struct type *type);
28523 +extern int object_address_get_data (struct type *type,
28524 + CORE_ADDR *address_return);
28526 extern struct value *value_at (struct type *type, CORE_ADDR addr);
28527 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
28529 @@ -436,6 +441,7 @@ extern struct value *value_struct_elt (struct value **argp,
28531 extern struct value *value_aggregate_elt (struct type *curtype,
28533 + struct type *expect_type,
28535 enum noside noside);
28537 @@ -681,7 +687,7 @@ extern struct value *value_allocate_space_in_inferior (int);
28538 extern struct value *value_of_local (const char *name, int complain);
28540 extern struct value *value_subscripted_rvalue (struct value *array,
28541 - LONGEST index, int lowerbound);
28542 + CORE_ADDR offset);
28544 /* User function handler. */
28546 diff --git a/gdb/varobj.c b/gdb/varobj.c
28547 index 8f22156..8fe72ca 100644
28551 #include "gdbcmd.h"
28553 #include "valprint.h"
28554 +#include "objfiles.h"
28555 +#include "parser-defs.h"
28557 #include "gdb_assert.h"
28558 #include "gdb_string.h"
28559 @@ -253,6 +255,8 @@ static void free_variable (struct varobj *var);
28561 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
28563 +static struct cleanup *make_cleanup_uninstall_variable (struct varobj *var);
28565 static struct type *get_type (struct varobj *var);
28567 static struct type *get_value_type (struct varobj *var);
28568 @@ -480,6 +484,8 @@ is_root_p (struct varobj *var)
28570 varobj_ensure_python_env (struct varobj *var)
28572 + gdb_assert (var->root->is_valid);
28574 return ensure_python_env (var->root->exp->gdbarch,
28575 var->root->exp->language_defn);
28577 @@ -651,6 +657,7 @@ varobj_create (char *objname,
28578 do_cleanups (old_chain);
28581 + make_cleanup_uninstall_variable (var);
28584 discard_cleanups (old_chain);
28585 @@ -821,7 +828,12 @@ varobj_get_display_hint (struct varobj *var)
28586 char *result = NULL;
28589 - struct cleanup *back_to = varobj_ensure_python_env (var);
28590 + struct cleanup *back_to;
28592 + if (!var->root->is_valid)
28595 + back_to = varobj_ensure_python_env (var);
28597 if (var->pretty_printer)
28598 result = gdbpy_get_display_hint (var->pretty_printer);
28599 @@ -2186,6 +2198,18 @@ make_cleanup_free_variable (struct varobj *var)
28600 return make_cleanup (do_free_variable_cleanup, var);
28604 +do_uninstall_variable_cleanup (void *var)
28606 + uninstall_variable (var);
28609 +static struct cleanup *
28610 +make_cleanup_uninstall_variable (struct varobj *var)
28612 + return make_cleanup (do_uninstall_variable_cleanup, var);
28615 /* This returns the type of the variable. It also skips past typedefs
28616 to return the real type of the variable.
28618 @@ -3442,6 +3466,19 @@ java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
28619 return cplus_value_of_variable (var, format);
28622 +/* Iterate all the existing VAROBJs and call the FUNC callback for them with an
28623 + arbitrary caller supplied DATA pointer. */
28626 +all_varobjs (void (*func) (struct varobj *var, void *data), void *data)
28628 + struct vlist **vlp, *vl;
28630 + for (vlp = varobj_table; vlp < varobj_table + VAROBJ_TABLE_SIZE; vlp++)
28631 + for (vl = *vlp; vl != NULL; vl = vl->next)
28632 + (*func) (vl->var, data);
28635 /* Iterate all the existing _root_ VAROBJs and call the FUNC callback for them
28636 with an arbitrary caller supplied DATA pointer. */
28638 @@ -3459,6 +3496,43 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data)
28639 (*func) (var_root->rootvar, data);
28643 +/* Helper for varobj_types_mark_used. Call type_mark_used for any TYPEs
28644 + referenced from this VAR. */
28647 +varobj_types_mark_used_iter (struct varobj *var, void *unused)
28649 + /* Even FLOATING or IS_INVALID VARs with non-NULL TYPE references will
28650 + free them in free_variable. Still EXP may also reference TYPEs
28651 + but these belong to SYMBOLs which should be always associated with
28652 + an OBJFILE (and therefore not useful to be type_mark_used). */
28654 + type_mark_used (var->type);
28656 + type_mark_used (value_type (var->value));
28658 + /* Check VAROBJROOTs only once during the varobj_types_mark_used pass. */
28660 + if (var->root->rootvar == var)
28662 + if (var->root->exp)
28663 + exp_types_mark_used (var->root->exp);
28667 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
28670 +varobj_types_mark_used (void)
28672 + /* Check all the VAROBJs, even non-root ones. Child VAROBJs can reference
28673 + types from other OBJFILEs through TYPE_IS_OPAQUE resolutions by
28674 + check_typedef. Such types references will not be interconnected into the
28675 + same TYPE_GROUP. */
28677 + all_varobjs (varobj_types_mark_used_iter, NULL);
28680 extern void _initialize_varobj (void);
28682 diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
28683 index c56ab86..dacf913 100644
28684 --- a/gdb/xcoffread.c
28685 +++ b/gdb/xcoffread.c
28686 @@ -3038,6 +3038,7 @@ static struct sym_fns xcoff_sym_fns =
28687 xcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
28688 xcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
28689 xcoff_initial_scan, /* sym_read: read a symbol file into symtab */
28690 + NULL, /* sym_read_psymbols */
28691 xcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
28692 xcoff_symfile_offsets, /* sym_offsets: xlate offsets ext->int form */
28693 default_symfile_segments, /* sym_segments: Get segment information from