1 http://sourceware.org/gdb/wiki/ProjectArcher
2 http://sourceware.org/gdb/wiki/ArcherBranchManagement
5 commit 74fff58d0076fe97c6c99d65fa58126315266646
7 branch `archer' - the merge of branches:
8 archer-jankratochvil-vla
9 archer-jankratochvil-watchpoint3
10 archer-jankratochvil-ifunc
11 archer-pmuldoon-next-over-throw2
12 archer-tromey-python (not a merge)
13 archer-tromey-optional-psymtab (cherry-picked from post-7.2 master)
14 #TODO:archer-tromey-threaded-dwarf
17 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
18 index f07bc8b..3703dca 100644
21 @@ -169,6 +169,12 @@ TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@
22 TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
24 # Did the user give us a --with-gdb-datadir option?
25 +GDB_DATADIR_PATH = @GDB_DATADIR_PATH@
27 +# The argument to --with-pythondir. If not given, this is
28 +# GDB_DATADIR_PATH/python.
29 +pythondir = @pythondir@
31 GDB_DATADIR = @GDB_DATADIR@
33 # Helper code from gnulib.
34 @@ -295,13 +301,13 @@ SUBDIR_PYTHON_SRCS = \
37 python/py-function.c \
39 python/py-inferior.c \
40 python/py-infthread.c \
41 python/py-lazy-string.c \
44 python/py-prettyprint.c \
45 - python/py-progspace.c \
49 @@ -780,8 +786,8 @@ config/rs6000/nm-rs6000.h top.h bsd-kvm.h gdb-stabs.h reggroups.h \
50 annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h \
51 remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
52 sentinel-frame.h bcache.h symfile.h windows-tdep.h linux-tdep.h \
53 -gdb_usleep.h jit.h xml-syscall.h ada-operator.inc microblaze-tdep.h \
55 +gdb_usleep.h jit.h python/python.h python/python-internal.h \
56 +xml-syscall.h ada-operator.inc microblaze-tdep.h
58 # Header files that already have srcdir in them, or which are in objdir.
60 @@ -1301,6 +1307,12 @@ stamp-h: $(srcdir)/config.in config.status
62 $(SHELL) config.status
64 +.gdbinit: $(srcdir)/gdbinit.in config.status
65 + CONFIG_FILES=".gdbinit:gdbinit.in" \
68 + $(SHELL) config.status
70 config.status: $(srcdir)/configure configure.tgt configure.host
71 $(SHELL) config.status --recheck
73 @@ -2024,6 +2036,10 @@ py-function.o: $(srcdir)/python/py-function.c
74 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-function.c
77 +py-hooks.o: $(srcdir)/python/py-hooks.c
78 + $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-hooks.c
81 py-inferior.o: $(srcdir)/python/py-inferior.c
82 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-inferior.c
84 @@ -2072,6 +2088,36 @@ py-value.o: $(srcdir)/python/py-value.c
85 $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c
88 +# All python library files, with the "python/lib" stripped off.
89 +# Note that we should only install files in the "gdb" module.
90 +PY_FILES = gdb/FrameIterator.py gdb/FrameWrapper.py gdb/command/alias.py \
91 + gdb/command/backtrace.py gdb/command/require.py \
92 + gdb/command/pahole.py gdb/command/upto.py gdb/command/__init__.py \
93 + gdb/command/ignore_errors.py gdb/command/save_breakpoints.py \
94 + gdb/function/caller_is.py gdb/function/in_scope.py \
95 + gdb/function/__init__.py gdb/backtrace.py gdb/__init__.py
97 +# Install the Python library. Python library files go under
100 + files='$(PY_FILES)'; for file in $$files; do \
101 + dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
102 + $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(pythondir)/$$dir; \
103 + $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(pythondir)/$$file; \
106 +# Other packages may have their files installed in $(pythondir).
108 + files='$(PY_FILES)'; for file in $$files; do \
109 + slashdir=`echo "/$$file" | sed 's,/[^/]*$$,,'`; \
110 + rm -f $(DESTDIR)$(pythondir)/$$file; \
111 + while test "x$$file" != "x$$slashdir"; do \
112 + rmdir 2>/dev/null "$(DESTDIR)$(pythondir)$$slashdir"; \
113 + file="$$slashdir"; \
114 + slashdir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
119 # Dependency tracking. Most of this is conditional on GNU Make being
120 # found by configure; if GNU Make is not found, we fall back to a
121 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
122 index 1d4c38b..cafb88e 100644
125 @@ -11114,6 +11114,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
128 ada_operator_check (struct expression *exp, int pos,
129 + int (*type_func) (struct type *type, void *data),
130 int (*objfile_func) (struct objfile *objfile, void *data),
133 @@ -11128,12 +11129,15 @@ ada_operator_check (struct expression *exp, int pos,
137 - return operator_check_standard (exp, pos, objfile_func, data);
138 + return operator_check_standard (exp, pos, type_func, objfile_func,
142 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
144 - if (type && TYPE_OBJFILE (type)
145 + if (type && type_func && (*type_func) (type, data))
147 + if (type && TYPE_OBJFILE (type) && objfile_func
148 && (*objfile_func) (TYPE_OBJFILE (type), data))
151 diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
152 index c0edc10..17d36b5 100644
153 --- a/gdb/amd64-linux-nat.c
154 +++ b/gdb/amd64-linux-nat.c
155 @@ -375,6 +375,20 @@ amd64_linux_dr_unset_status (unsigned long mask)
159 +/* See i386_dr_low_type.detach. Do not use wrappers amd64_linux_dr_set_control
160 + or amd64_linux_dr_reset_addr as they would modify the register cache
161 + (amd64_linux_dr). */
164 +amd64_linux_dr_detach (void)
168 + amd64_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
169 + amd64_linux_dr_unset_status (~0UL);
170 + for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
171 + amd64_linux_dr_set (inferior_ptid, regnum, 0);
175 amd64_linux_new_thread (ptid_t ptid)
176 @@ -796,6 +810,7 @@ _initialize_amd64_linux_nat (void)
177 i386_dr_low.reset_addr = amd64_linux_dr_reset_addr;
178 i386_dr_low.get_status = amd64_linux_dr_get_status;
179 i386_dr_low.unset_status = amd64_linux_dr_unset_status;
180 + i386_dr_low.detach = amd64_linux_dr_detach;
181 i386_set_debug_register_length (8);
183 /* Override the GNU/Linux inferior startup hook. */
184 diff --git a/gdb/block.c b/gdb/block.c
185 index 48ac21b..ffcc97f 100644
188 @@ -321,3 +321,21 @@ allocate_block (struct obstack *obstack)
193 +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
194 + whatever reason. */
197 +block_objfile (const struct block *block)
199 + struct symbol *func;
204 + func = block_linkage_function (block);
208 + return SYMBOL_SYMTAB (func)->objfile;
210 diff --git a/gdb/block.h b/gdb/block.h
211 index 7eedb6c..a517e80 100644
214 @@ -166,4 +166,6 @@ extern const struct block *block_global_block (const struct block *block);
216 extern struct block *allocate_block (struct obstack *obstack);
218 +extern struct objfile *block_objfile (const struct block *block);
221 diff --git a/gdb/blockframe.c b/gdb/blockframe.c
222 index 0348bf4..f01d0ee 100644
223 --- a/gdb/blockframe.c
224 +++ b/gdb/blockframe.c
227 #include "inline-frame.h"
229 +#include "elf-bfd.h"
231 /* Return the innermost lexical block in execution
232 in a specified stack frame. The frame address is assumed valid.
233 @@ -159,6 +160,7 @@ static CORE_ADDR cache_pc_function_low = 0;
234 static CORE_ADDR cache_pc_function_high = 0;
235 static char *cache_pc_function_name = 0;
236 static struct obj_section *cache_pc_function_section = NULL;
237 +static int cache_pc_function_is_gnu_ifunc = 0;
239 /* Clear cache, e.g. when symbol table is discarded. */
241 @@ -169,6 +171,7 @@ clear_pc_function_cache (void)
242 cache_pc_function_high = 0;
243 cache_pc_function_name = (char *) 0;
244 cache_pc_function_section = NULL;
245 + cache_pc_function_is_gnu_ifunc = 0;
248 /* Finds the "function" (text symbol) that is smaller than PC but
249 @@ -184,7 +187,7 @@ clear_pc_function_cache (void)
251 /* Backward compatibility, no section argument. */
254 +enum find_pc_partial_function_type
255 find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
258 @@ -236,6 +239,7 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
259 cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
260 cache_pc_function_name = SYMBOL_LINKAGE_NAME (f);
261 cache_pc_function_section = section;
262 + cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f));
263 goto return_cached_value;
266 @@ -258,12 +262,13 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
271 + return FIND_PC_PARTIAL_FUNCTION_NOT_FOUND;
274 cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
275 cache_pc_function_name = SYMBOL_LINKAGE_NAME (msymbol);
276 cache_pc_function_section = section;
277 + cache_pc_function_is_gnu_ifunc = MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
279 /* If the minimal symbol has a size, use it for the cache.
280 Otherwise use the lesser of the next minimal symbol in the same
281 @@ -323,7 +328,8 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
282 *endaddr = cache_pc_function_high;
286 + return cache_pc_function_is_gnu_ifunc ? FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
287 + : FIND_PC_PARTIAL_FUNCTION_NORMAL;
290 /* Return the innermost stack frame executing inside of BLOCK,
291 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
292 index 6a6864c..5df336d 100644
293 --- a/gdb/breakpoint.c
294 +++ b/gdb/breakpoint.c
297 #include "xml-syscall.h"
298 #include "parser-defs.h"
299 +#include "regcache.h"
301 /* readline include files */
302 #include "readline/readline.h"
303 @@ -92,6 +93,9 @@ static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
305 static void ignore_command (char *, int);
307 +static void update_breakpoint_locations (struct breakpoint *b,
308 + struct symtabs_and_lines sals);
310 static int breakpoint_re_set_one (void *);
312 static void clear_command (char *, int);
313 @@ -106,6 +110,9 @@ static void break_command_1 (char *, int, int);
315 static void mention (struct breakpoint *);
317 +static struct bp_location *add_location_to_breakpoint (struct breakpoint *b,
318 + const struct symtab_and_line *sal);
320 /* This function is used in gdbtk sources and thus can not be made static. */
321 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
322 struct symtab_and_line,
323 @@ -230,6 +237,10 @@ static void disable_trace_command (char *, int);
325 static void trace_pass_command (char *, int);
327 +static void gnu_ifunc_resolver_stop (struct breakpoint *b);
329 +static void gnu_ifunc_resolver_return_stop (struct breakpoint *b);
331 /* Assuming we're creating a static tracepoint, does S look like a
332 static tracepoint marker spec ("-m MARKER_ID")? */
333 #define is_marker_spec(s) \
334 @@ -430,7 +441,7 @@ static int tracepoint_count;
336 static struct cmd_list_element *breakpoint_set_cmdlist;
337 static struct cmd_list_element *breakpoint_show_cmdlist;
338 -static struct cmd_list_element *save_cmdlist;
339 +struct cmd_list_element *save_cmdlist;
341 /* Return whether a breakpoint is an active enabled breakpoint. */
343 @@ -1252,6 +1263,22 @@ watchpoint_in_thread_scope (struct breakpoint *b)
344 && !is_executing (inferior_ptid)));
348 +watchpoint_del_at_next_stop (struct breakpoint *b)
350 + gdb_assert (is_watchpoint (b));
352 + if (b->related_breakpoint != b)
354 + gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
355 + gdb_assert (b->related_breakpoint->related_breakpoint == b);
356 + b->related_breakpoint->disposition = disp_del_at_next_stop;
357 + b->related_breakpoint->related_breakpoint = b->related_breakpoint;
358 + b->related_breakpoint = b;
360 + b->disposition = disp_del_at_next_stop;
363 /* Assuming that B is a watchpoint:
364 - Reparse watchpoint expression, if REPARSE is non-zero
365 - Evaluate expression and store the result in B->val
366 @@ -1307,6 +1334,8 @@ update_watchpoint (struct breakpoint *b, int reparse)
367 struct frame_id saved_frame_id;
370 + gdb_assert (is_watchpoint (b));
372 /* If this is a local watchpoint, we only want to check if the
373 watchpoint frame is in scope if the current thread is the thread
374 that was used to create the watchpoint. */
375 @@ -1510,13 +1539,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
376 Watchpoint %d deleted because the program has left the block\n\
377 in which its expression is valid.\n"),
379 - if (b->related_breakpoint)
381 - b->related_breakpoint->disposition = disp_del_at_next_stop;
382 - b->related_breakpoint->related_breakpoint = NULL;
383 - b->related_breakpoint= NULL;
385 - b->disposition = disp_del_at_next_stop;
386 + watchpoint_del_at_next_stop (b);
389 /* Restore the selected frame. */
390 @@ -2201,6 +2224,33 @@ create_std_terminate_master_breakpoint (const char *func_name)
391 do_cleanups (old_chain);
394 +/* Install a master breakpoint on the unwinder's debug hook. */
397 +create_exception_master_breakpoint (void)
399 + struct objfile *objfile;
401 + ALL_OBJFILES (objfile)
403 + struct minimal_symbol *debug_hook;
405 + debug_hook = lookup_minimal_symbol_text ("_Unwind_DebugHook", objfile);
406 + if (debug_hook != NULL)
408 + struct breakpoint *b;
410 + b = create_internal_breakpoint (get_objfile_arch (objfile),
411 + SYMBOL_VALUE_ADDRESS (debug_hook),
412 + bp_exception_master);
413 + b->addr_string = xstrdup ("_Unwind_DebugHook");
414 + b->enable_state = bp_disabled;
418 + update_global_location_list (1);
422 update_breakpoints_after_exec (void)
424 @@ -2242,7 +2292,8 @@ update_breakpoints_after_exec (void)
425 /* Thread event breakpoints must be set anew after an exec(),
426 as must overlay event and longjmp master breakpoints. */
427 if (b->type == bp_thread_event || b->type == bp_overlay_event
428 - || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
429 + || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
430 + || b->type == bp_exception_master)
432 delete_breakpoint (b);
434 @@ -2257,7 +2308,8 @@ update_breakpoints_after_exec (void)
436 /* Longjmp and longjmp-resume breakpoints are also meaningless
438 - if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
439 + if (b->type == bp_longjmp || b->type == bp_longjmp_resume
440 + || b->type == bp_exception || b->type == bp_exception_resume)
442 delete_breakpoint (b);
444 @@ -2319,6 +2371,7 @@ update_breakpoints_after_exec (void)
445 create_longjmp_master_breakpoint ("siglongjmp");
446 create_longjmp_master_breakpoint ("_siglongjmp");
447 create_std_terminate_master_breakpoint ("std::terminate()");
448 + create_exception_master_breakpoint ();
452 @@ -2346,6 +2399,8 @@ detach_breakpoints (int pid)
453 /* Detach single-step breakpoints as well. */
454 detach_single_step_breakpoints ();
456 + val |= target_detach_watchpoints ();
458 do_cleanups (old_chain);
461 @@ -2447,9 +2502,11 @@ remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
463 b->inserted = (is == mark_inserted);
465 - else if (b->loc_type == bp_loc_hardware_watchpoint)
466 + /* bp_loc_hardware_watchpoint with mark_inserted is being handled by
467 + target_detach_watchpoints. */
468 + else if (b->loc_type == bp_loc_hardware_watchpoint && is == mark_uninserted)
470 - b->inserted = (is == mark_inserted);
472 val = target_remove_watchpoint (b->address, b->length,
473 b->watchpoint_type, b->owner->cond_exp);
475 @@ -3237,6 +3294,12 @@ print_it_typical (bpstat bs)
476 result = PRINT_NOTHING;
479 + case bp_exception_master:
480 + /* These should never be enabled. */
481 + printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
482 + result = PRINT_NOTHING;
486 case bp_hardware_watchpoint:
487 annotate_watchpoint (b->number);
488 @@ -3324,6 +3387,8 @@ print_it_typical (bpstat bs)
491 case bp_longjmp_resume:
493 + case bp_exception_resume:
495 case bp_watchpoint_scope:
497 @@ -3331,6 +3396,8 @@ print_it_typical (bpstat bs)
499 case bp_fast_tracepoint:
501 + case bp_gnu_ifunc_resolver:
502 + case bp_gnu_ifunc_resolver_return:
504 result = PRINT_UNKNOWN;
506 @@ -3549,6 +3616,8 @@ watchpoint_check (void *p)
507 gdb_assert (bs->breakpoint_at->owner != NULL);
508 b = bs->breakpoint_at->owner;
510 + gdb_assert (is_watchpoint (b));
512 /* If this is a local watchpoint, we only want to check if the
513 watchpoint frame is in scope if the current thread is the thread
514 that was used to create the watchpoint. */
515 @@ -3655,13 +3724,7 @@ watchpoint_check (void *p)
516 ui_out_text (uiout, " deleted because the program has left the block in\n\
517 which its expression is valid.\n");
519 - if (b->related_breakpoint)
521 - b->related_breakpoint->disposition = disp_del_at_next_stop;
522 - b->related_breakpoint->related_breakpoint = NULL;
523 - b->related_breakpoint = NULL;
525 - b->disposition = disp_del_at_next_stop;
526 + watchpoint_del_at_next_stop (b);
530 @@ -3730,8 +3793,12 @@ bpstat_check_location (const struct bp_location *bl,
532 /* If BS refers to a watchpoint, determine if the watched values
533 has actually changed, and we should stop. If not, set BS->stop
537 + Return 0 for watchpoints which could not be the cause of this trap.
538 + In such case PRINT_IT will be print_it_noop and STOP will be 0.
539 + Otherwise return 1 but in such case it is not guaranteed whether this
540 + breakpoint did or did not trigger this trap. */
542 bpstat_check_watchpoint (bpstat bs)
544 const struct bp_location *bl;
545 @@ -3865,9 +3932,7 @@ bpstat_check_watchpoint (bpstat bs)
547 /* Error from catch_errors. */
548 printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
549 - if (b->related_breakpoint)
550 - b->related_breakpoint->disposition = disp_del_at_next_stop;
551 - b->disposition = disp_del_at_next_stop;
552 + watchpoint_del_at_next_stop (b);
553 /* We've already printed what needs to be printed. */
554 bs->print_it = print_it_done;
556 @@ -3881,8 +3946,10 @@ bpstat_check_watchpoint (bpstat bs)
557 anything for this watchpoint. */
558 bs->print_it = print_it_noop;
567 @@ -3914,7 +3981,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
568 watchpoint as triggered so that we will handle the
569 out-of-scope event. We'll get to the watchpoint next
571 - if (b->type == bp_watchpoint_scope)
572 + if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
573 b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
575 if (is_watchpoint (b))
576 @@ -4045,6 +4112,8 @@ bpstat_stop_status (struct address_space *aspace,
578 for (bl = b->loc; bl != NULL; bl = bl->next)
580 + bpstat bs_prev = bs;
582 /* For hardware watchpoints, we look only at the first location.
583 The watchpoint_check function will work on the entire expression,
584 not the individual locations. For read watchpoints, the
585 @@ -4062,6 +4131,7 @@ bpstat_stop_status (struct address_space *aspace,
586 /* Come here if it's a watchpoint, or if the break address matches */
588 bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */
589 + gdb_assert (bs_prev->next == bs);
591 /* Assume we stop. Should we find watchpoint that is not actually
592 triggered, or if condition of breakpoint is false, we'll reset
593 @@ -4069,13 +4139,23 @@ bpstat_stop_status (struct address_space *aspace,
597 - bpstat_check_watchpoint (bs);
600 + if (!bpstat_check_watchpoint (bs))
602 + /* Ensure bpstat_explains_signal stays false if this BL could not be
603 + the cause of this trap. */
605 + gdb_assert (bs->print_it == print_it_noop);
606 + gdb_assert (!bs->stop);
613 if (b->type == bp_thread_event || b->type == bp_overlay_event
614 || b->type == bp_longjmp_master
615 - || b->type == bp_std_terminate_master)
616 + || b->type == bp_std_terminate_master
617 + || b->type == bp_exception_master)
618 /* We do not stop for these. */
621 @@ -4176,7 +4256,7 @@ handle_jit_event (void)
622 /* Decide what infrun needs to do with this bpstat. */
625 -bpstat_what (bpstat bs)
626 +bpstat_what (bpstat bs_head)
628 struct bpstat_what retval;
629 /* We need to defer calling `solib_add', as adding new symbols
630 @@ -4184,11 +4264,13 @@ bpstat_what (bpstat bs)
631 and hence may clear unprocessed entries in the BS chain. */
636 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
637 retval.call_dummy = STOP_NONE;
638 + retval.is_longjmp = 0;
640 - for (; bs != NULL; bs = bs->next)
641 + for (bs = bs_head; bs != NULL; bs = bs->next)
643 /* Extract this BS's action. After processing each BS, we check
644 if its action overrides all we've seem so far. */
645 @@ -4242,10 +4324,15 @@ bpstat_what (bpstat bs)
650 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
651 + retval.is_longjmp = bs->breakpoint_at->owner->type == bp_longjmp;
653 case bp_longjmp_resume:
654 + case bp_exception_resume:
655 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
657 + = bs->breakpoint_at->owner->type == bp_longjmp_resume;
661 @@ -4261,6 +4348,7 @@ bpstat_what (bpstat bs)
662 case bp_overlay_event:
663 case bp_longjmp_master:
664 case bp_std_terminate_master:
665 + case bp_exception_master:
666 this_action = BPSTAT_WHAT_SINGLE;
669 @@ -4313,6 +4401,20 @@ bpstat_what (bpstat bs)
671 internal_error (__FILE__, __LINE__,
672 _("bpstat_what: tracepoint encountered"));
674 + case bp_gnu_ifunc_resolver:
675 + /* Skip the current breakpoint but otherwise nothing happens. GDB is
676 + inserting new bp_gnu_ifunc_resolver_return at this point but
677 + bp_gnu_ifunc_resolver is being kept there as another
678 + bp_gnu_ifunc_resolver_return may be inserted in the meantime. */
679 + this_action = BPSTAT_WHAT_SINGLE;
681 + case bp_gnu_ifunc_resolver_return:
682 + /* The whole bp_gnu_ifunc_resolver with its associated
683 + bp_gnu_ifunc_resolver_return related_breakpoint's has been
684 + resolved now, all these helper breakpoints are being removed and
685 + new final bp_breakpoint is being put at the target location. */
688 internal_error (__FILE__, __LINE__,
689 _("bpstat_what: unhandled bptype %d"), (int) bptype);
690 @@ -4350,6 +4452,23 @@ bpstat_what (bpstat bs)
694 + for (bs = bs_head; bs != NULL; bs = bs->next)
696 + if (bs->breakpoint_at == NULL)
698 + if (bs->breakpoint_at->owner == NULL)
700 + switch (bs->breakpoint_at->owner->type)
702 + case bp_gnu_ifunc_resolver:
703 + gnu_ifunc_resolver_stop (bs->breakpoint_at->owner);
705 + case bp_gnu_ifunc_resolver_return:
706 + gnu_ifunc_resolver_return_stop (bs->breakpoint_at->owner);
714 @@ -4461,6 +4580,8 @@ print_one_breakpoint_location (struct breakpoint *b,
715 {bp_access_watchpoint, "acc watchpoint"},
716 {bp_longjmp, "longjmp"},
717 {bp_longjmp_resume, "longjmp resume"},
718 + {bp_exception, "exception"},
719 + {bp_exception_resume, "exception resume"},
720 {bp_step_resume, "step resume"},
721 {bp_watchpoint_scope, "watchpoint scope"},
722 {bp_call_dummy, "call dummy"},
723 @@ -4470,11 +4591,14 @@ print_one_breakpoint_location (struct breakpoint *b,
724 {bp_overlay_event, "overlay events"},
725 {bp_longjmp_master, "longjmp master"},
726 {bp_std_terminate_master, "std::terminate master"},
727 + {bp_exception_master, "exception master"},
728 {bp_catchpoint, "catchpoint"},
729 {bp_tracepoint, "tracepoint"},
730 {bp_fast_tracepoint, "fast tracepoint"},
731 {bp_static_tracepoint, "static tracepoint"},
732 {bp_jit_event, "jit events"},
733 + {bp_gnu_ifunc_resolver, "gnu-ifunc resolver"},
734 + {bp_gnu_ifunc_resolver_return, "gnu-func resolver return"},
737 static char bpenables[] = "nynny";
738 @@ -4595,6 +4719,8 @@ print_one_breakpoint_location (struct breakpoint *b,
741 case bp_longjmp_resume:
743 + case bp_exception_resume:
745 case bp_watchpoint_scope:
747 @@ -4604,10 +4730,13 @@ print_one_breakpoint_location (struct breakpoint *b,
748 case bp_overlay_event:
749 case bp_longjmp_master:
750 case bp_std_terminate_master:
751 + case bp_exception_master:
753 case bp_fast_tracepoint:
754 case bp_static_tracepoint:
756 + case bp_gnu_ifunc_resolver:
757 + case bp_gnu_ifunc_resolver_return:
758 if (opts.addressprint)
761 @@ -4888,7 +5017,8 @@ user_settable_breakpoint (const struct breakpoint *b)
762 || b->type == bp_catchpoint
763 || b->type == bp_hardware_breakpoint
765 - || is_watchpoint (b));
766 + || is_watchpoint (b)
767 + || b->type == bp_gnu_ifunc_resolver);
770 /* Print information on user settable breakpoint (watchpoint, etc)
771 @@ -5334,6 +5464,8 @@ allocate_bp_location (struct breakpoint *bpt)
774 case bp_longjmp_resume:
776 + case bp_exception_resume:
778 case bp_watchpoint_scope:
780 @@ -5344,6 +5476,9 @@ allocate_bp_location (struct breakpoint *bpt)
782 case bp_longjmp_master:
783 case bp_std_terminate_master:
784 + case bp_gnu_ifunc_resolver:
785 + case bp_gnu_ifunc_resolver_return:
786 + case bp_exception_master:
787 loc->loc_type = bp_loc_software_breakpoint;
789 case bp_hardware_breakpoint:
790 @@ -5420,6 +5555,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
791 b->syscalls_to_be_caught = NULL;
793 b->condition_not_parsed = 0;
794 + b->related_breakpoint = b;
796 /* Add this breakpoint to the end of the chain
797 so that a list of breakpoints will come out in order
798 @@ -5439,7 +5575,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
800 /* Initialize loc->function_name. */
802 -set_breakpoint_location_function (struct bp_location *loc)
803 +set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
805 gdb_assert (loc->owner != NULL);
807 @@ -5447,8 +5583,29 @@ set_breakpoint_location_function (struct bp_location *loc)
808 || loc->owner->type == bp_hardware_breakpoint
809 || is_tracepoint (loc->owner))
811 - find_pc_partial_function (loc->address, &(loc->function_name),
813 + if (find_pc_partial_function (loc->address, &(loc->function_name), NULL,
814 + NULL) == FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
817 + struct breakpoint *b = loc->owner;
819 + gdb_assert (loc->pspace == current_program_space);
820 + if (resolve_gnu_ifunc (loc->function_name, &loc->requested_address))
822 + /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
823 + loc->address = adjust_breakpoint_address (loc->gdbarch,
824 + loc->requested_address,
827 + else if (b->type == bp_breakpoint && b->loc == loc
828 + && loc->next == NULL && b->related_breakpoint == b)
830 + /* Create only the whole new breakpoint of this type but do not
831 + mess more complicated breakpoints with multiple locations. */
832 + b->type = bp_gnu_ifunc_resolver;
836 if (loc->function_name)
837 loc->function_name = xstrdup (loc->function_name);
839 @@ -5521,7 +5678,8 @@ set_raw_breakpoint (struct gdbarch *gdbarch,
840 b->loc->section = sal.section;
841 b->line_number = sal.line;
843 - set_breakpoint_location_function (b->loc);
844 + set_breakpoint_location_function (b->loc,
845 + sal.explicit_pc || sal.explicit_line);
847 breakpoints_changed ();
849 @@ -5548,8 +5706,7 @@ make_breakpoint_permanent (struct breakpoint *b)
852 /* Call this routine when stepping and nexting to enable a breakpoint
853 - if we do a longjmp() in THREAD. When we hit that breakpoint, call
854 - set_longjmp_resume_breakpoint() to figure out where we are going. */
855 + if we do a longjmp() or 'throw' in THREAD. */
858 set_longjmp_breakpoint (int thread)
859 @@ -5562,11 +5719,12 @@ set_longjmp_breakpoint (int thread)
860 clones of those and enable them for the requested thread. */
861 ALL_BREAKPOINTS_SAFE (b, temp)
862 if (b->pspace == current_program_space
863 - && b->type == bp_longjmp_master)
864 + && (b->type == bp_longjmp_master
865 + || b->type == bp_exception_master))
867 struct breakpoint *clone = clone_momentary_breakpoint (b);
869 - clone->type = bp_longjmp;
870 + clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
871 clone->thread = thread;
874 @@ -5578,7 +5736,7 @@ delete_longjmp_breakpoint (int thread)
875 struct breakpoint *b, *temp;
877 ALL_BREAKPOINTS_SAFE (b, temp)
878 - if (b->type == bp_longjmp)
879 + if (b->type == bp_longjmp || b->type == bp_exception)
881 if (b->thread == thread)
882 delete_breakpoint (b);
883 @@ -6595,7 +6753,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
885 copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
886 copy->loc = allocate_bp_location (copy);
887 - set_breakpoint_location_function (copy->loc);
888 + set_breakpoint_location_function (copy->loc, 1);
890 copy->loc->gdbarch = orig->loc->gdbarch;
891 copy->loc->requested_address = orig->loc->requested_address;
892 @@ -6694,6 +6852,7 @@ mention (struct breakpoint *b)
893 do_cleanups (ui_out_chain);
896 + case bp_gnu_ifunc_resolver:
897 if (ui_out_is_mi_like_p (uiout))
900 @@ -6704,6 +6863,8 @@ mention (struct breakpoint *b)
902 printf_filtered (_("Breakpoint"));
903 printf_filtered (_(" %d"), b->number);
904 + if (b->type == bp_gnu_ifunc_resolver)
905 + printf_filtered (_(" at gnu-indirect-function resolver"));
908 case bp_hardware_breakpoint:
909 @@ -6750,6 +6911,8 @@ mention (struct breakpoint *b)
912 case bp_longjmp_resume:
914 + case bp_exception_resume:
917 case bp_std_terminate:
918 @@ -6760,6 +6923,8 @@ mention (struct breakpoint *b)
920 case bp_longjmp_master:
921 case bp_std_terminate_master:
922 + case bp_gnu_ifunc_resolver_return:
923 + case bp_exception_master:
927 @@ -6820,7 +6985,8 @@ add_location_to_breakpoint (struct breakpoint *b,
928 gdb_assert (loc->pspace != NULL);
929 loc->section = sal->section;
931 - set_breakpoint_location_function (loc);
932 + set_breakpoint_location_function (loc,
933 + sal->explicit_pc || sal->explicit_line);
937 @@ -8346,6 +8512,7 @@ struct until_break_command_continuation_args
939 struct breakpoint *breakpoint;
940 struct breakpoint *breakpoint2;
944 /* This function is called by fetch_inferior_event via the
945 @@ -8360,6 +8527,7 @@ until_break_command_continuation (void *arg)
946 delete_breakpoint (a->breakpoint);
948 delete_breakpoint (a->breakpoint2);
949 + delete_longjmp_breakpoint (a->thread_num);
953 @@ -8371,6 +8539,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
954 struct breakpoint *breakpoint;
955 struct breakpoint *breakpoint2 = NULL;
956 struct cleanup *old_chain;
958 + struct thread_info *tp;
960 clear_proceed_status ();
962 @@ -8409,6 +8579,9 @@ until_break_command (char *arg, int from_tty, int anywhere)
964 old_chain = make_cleanup_delete_breakpoint (breakpoint);
966 + tp = inferior_thread ();
969 /* Keep within the current frame, or in frames called by the current
972 @@ -8421,6 +8594,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
973 frame_unwind_caller_id (frame),
975 make_cleanup_delete_breakpoint (breakpoint2);
977 + set_longjmp_breakpoint (thread);
978 + tp->initiating_frame = frame_unwind_caller_id (frame);
979 + make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
982 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
983 @@ -8437,6 +8614,7 @@ until_break_command (char *arg, int from_tty, int anywhere)
985 args->breakpoint = breakpoint;
986 args->breakpoint2 = breakpoint2;
987 + args->thread_num = thread;
989 discard_cleanups (old_chain);
990 add_continuation (inferior_thread (),
991 @@ -9564,12 +9742,22 @@ delete_breakpoint (struct breakpoint *bpt)
993 /* At least avoid this stale reference until the reference counting of
994 breakpoints gets resolved. */
995 - if (bpt->related_breakpoint != NULL)
996 + if (bpt->related_breakpoint != bpt)
998 - gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
999 - bpt->related_breakpoint->disposition = disp_del_at_next_stop;
1000 - bpt->related_breakpoint->related_breakpoint = NULL;
1001 - bpt->related_breakpoint = NULL;
1002 + if (bpt->type == bp_watchpoint_scope)
1003 + watchpoint_del_at_next_stop (bpt->related_breakpoint);
1004 + else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
1005 + watchpoint_del_at_next_stop (bpt);
1008 + struct breakpoint *related;
1010 + /* Unlink bpt from the bpt->related_breakpoint ring. */
1011 + for (related = bpt; related->related_breakpoint != bpt;
1012 + related = related->related_breakpoint);
1013 + related->related_breakpoint = bpt->related_breakpoint;
1014 + bpt->related_breakpoint = bpt;
1018 observer_notify_breakpoint_deleted (bpt->number);
1019 @@ -9658,6 +9846,7 @@ delete_command (char *arg, int from_tty)
1020 && b->type != bp_overlay_event
1021 && b->type != bp_longjmp_master
1022 && b->type != bp_std_terminate_master
1023 + && b->type != bp_exception_master
1026 breaks_to_delete = 1;
1027 @@ -9679,6 +9868,7 @@ delete_command (char *arg, int from_tty)
1028 && b->type != bp_overlay_event
1029 && b->type != bp_longjmp_master
1030 && b->type != bp_std_terminate_master
1031 + && b->type != bp_exception_master
1033 delete_breakpoint (b);
1035 @@ -9887,6 +10077,9 @@ update_breakpoint_locations (struct breakpoint *b,
1039 + xfree (b->source_file);
1040 + b->source_file = NULL;
1041 + b->line_number = 0;
1043 for (i = 0; i < sals.nelts; ++i)
1045 @@ -9913,11 +10106,7 @@ update_breakpoint_locations (struct breakpoint *b,
1049 - if (b->source_file != NULL)
1050 - xfree (b->source_file);
1051 - if (sals.sals[i].symtab == NULL)
1052 - b->source_file = NULL;
1054 + if (sals.sals[i].symtab != NULL && b->source_file == NULL)
1055 b->source_file = xstrdup (sals.sals[i].symtab->filename);
1057 if (b->line_number == 0)
1058 @@ -9999,6 +10188,7 @@ breakpoint_re_set_one (void *bint)
1060 case bp_fast_tracepoint:
1061 case bp_static_tracepoint:
1062 + case bp_gnu_ifunc_resolver:
1063 /* Do not attempt to re-set breakpoints disabled during startup. */
1064 if (b->enable_state == bp_startup_disabled)
1066 @@ -10139,6 +10329,7 @@ breakpoint_re_set_one (void *bint)
1067 case bp_overlay_event:
1068 case bp_longjmp_master:
1069 case bp_std_terminate_master:
1070 + case bp_exception_master:
1071 delete_breakpoint (b);
1074 @@ -10162,7 +10353,10 @@ breakpoint_re_set_one (void *bint)
1075 case bp_step_resume:
1077 case bp_longjmp_resume:
1078 + case bp_exception:
1079 + case bp_exception_resume:
1081 + case bp_gnu_ifunc_resolver_return:
1085 @@ -10205,6 +10399,7 @@ breakpoint_re_set (void)
1086 create_longjmp_master_breakpoint ("siglongjmp");
1087 create_longjmp_master_breakpoint ("_siglongjmp");
1088 create_std_terminate_master_breakpoint ("std::terminate()");
1089 + create_exception_master_breakpoint ();
1092 /* Reset the thread number of this breakpoint:
1093 @@ -10334,11 +10529,20 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
1094 ALL_BREAKPOINTS_SAFE (b, tmp)
1095 if (b->number == num)
1097 - struct breakpoint *related_breakpoint = b->related_breakpoint;
1098 + struct breakpoint *related_breakpoint;
1101 - function (b, data);
1102 - if (related_breakpoint)
1103 - function (related_breakpoint, data);
1104 + related_breakpoint = b;
1107 + struct breakpoint *next_related_b;
1109 + /* FUNCTION can be also delete_breakpoint. */
1110 + next_related_b = related_breakpoint->related_breakpoint;
1111 + function (related_breakpoint, data);
1112 + related_breakpoint = next_related_b;
1114 + while (related_breakpoint != b);
1118 @@ -11428,6 +11632,22 @@ all_tracepoints ()
1122 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
1125 +breakpoint_types_mark_used (void)
1127 + struct breakpoint *b;
1129 + ALL_BREAKPOINTS (b)
1132 + exp_types_mark_used (b->exp);
1134 + type_mark_used (value_type (b->val));
1139 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
1140 It is defined as a macro to prevent duplication.
1141 @@ -11497,6 +11717,107 @@ save_command (char *arg, int from_tty)
1142 help_list (save_cmdlist, "save ", -1, gdb_stdout);
1146 +gnu_ifunc_resolver_stop (struct breakpoint *b)
1148 + struct breakpoint *b_return;
1149 + struct frame_info *prev_frame = get_prev_frame (get_current_frame ());
1150 + struct frame_id prev_frame_id = get_stack_frame_id (prev_frame);
1151 + CORE_ADDR prev_pc = get_frame_pc (prev_frame);
1152 + int thread_id = pid_to_thread_id (inferior_ptid);
1154 + gdb_assert (b->type == bp_gnu_ifunc_resolver);
1156 + for (b_return = b->related_breakpoint; b_return != b;
1157 + b_return = b_return->related_breakpoint)
1159 + gdb_assert (b_return->type == bp_gnu_ifunc_resolver_return);
1160 + gdb_assert (b_return->loc != NULL && b_return->loc->next == NULL);
1161 + gdb_assert (frame_id_p (b_return->frame_id));
1163 + if (b_return->thread == thread_id
1164 + && b_return->loc->requested_address == prev_pc
1165 + && frame_id_eq (b_return->frame_id, prev_frame_id))
1169 + if (b_return == b)
1171 + struct symtab_and_line sal;
1173 + /* No need to call find_pc_line for symbols resolving as this is only
1174 + a helper breakpointer never shown to the user. */
1177 + sal.pspace = current_inferior ()->pspace;
1179 + sal.section = find_pc_overlay (sal.pc);
1180 + sal.explicit_pc = 1;
1181 + b_return = set_momentary_breakpoint (get_frame_arch (prev_frame), sal,
1183 + bp_gnu_ifunc_resolver_return);
1185 + /* Add new b_return to the ring list b->related_breakpoint. */
1186 + gdb_assert (b_return->related_breakpoint == b_return);
1187 + b_return->related_breakpoint = b->related_breakpoint;
1188 + b->related_breakpoint = b_return;
1193 +gnu_ifunc_resolver_return_stop (struct breakpoint *b)
1195 + struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
1196 + struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
1197 + struct type *value_type = TYPE_TARGET_TYPE (func_func_type);
1198 + struct regcache *regcache = get_thread_regcache (inferior_ptid);
1199 + struct value *value;
1200 + CORE_ADDR resolved_address, resolved_pc;
1201 + struct symtab_and_line sal;
1202 + struct symtabs_and_lines sals;
1204 + gdb_assert (b->type == bp_gnu_ifunc_resolver_return);
1206 + value = allocate_value (value_type);
1207 + gdbarch_return_value (gdbarch, func_func_type, value_type, regcache,
1208 + value_contents_raw (value), NULL);
1209 + resolved_address = value_as_address (value);
1210 + resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
1214 + while (b->related_breakpoint != b)
1216 + struct breakpoint *b_next = b->related_breakpoint;
1220 + case bp_gnu_ifunc_resolver:
1222 + case bp_gnu_ifunc_resolver_return:
1223 + delete_breakpoint (b);
1226 + internal_error (__FILE__, __LINE__,
1227 + _("handle_inferior_event: Invalid "
1228 + "gnu-indirect-function breakpoint type %d"),
1233 + gdb_assert (b->type == bp_gnu_ifunc_resolver);
1235 + gdb_assert (current_program_space == b->pspace);
1236 + gnu_ifunc_record_cache (gdbarch, b->addr_string, resolved_pc);
1238 + sal = find_pc_line (resolved_pc, 0);
1242 + b->type = bp_breakpoint;
1243 + update_breakpoint_locations (b, sals);
1247 _initialize_breakpoint (void)
1249 @@ -12022,4 +12343,5 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
1250 automatic_hardware_breakpoints = 1;
1252 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
1253 + observer_attach_mark_used (breakpoint_types_mark_used);
1255 diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
1256 index 6f5d050..d0c3cc1 100644
1257 --- a/gdb/breakpoint.h
1258 +++ b/gdb/breakpoint.h
1259 @@ -56,6 +56,13 @@ enum bptype
1260 bp_longjmp, /* secret breakpoint to find longjmp() */
1261 bp_longjmp_resume, /* secret breakpoint to escape longjmp() */
1263 + /* An internal breakpoint that is installed on the unwinder's
1266 + /* An internal breakpoint that is set at the point where an
1267 + exception will land. */
1268 + bp_exception_resume,
1270 /* Used by wait_for_inferior for stepping over subroutine calls, for
1271 stepping over signal handlers, and for skipping prologues. */
1273 @@ -125,6 +132,9 @@ enum bptype
1274 /* Master copies of std::terminate breakpoints. */
1275 bp_std_terminate_master,
1277 + /* Like bp_longjmp_master, but for exceptions. */
1278 + bp_exception_master,
1283 @@ -133,6 +143,9 @@ enum bptype
1285 /* Event for JIT compiled code generation or deletion. */
1288 + bp_gnu_ifunc_resolver,
1289 + bp_gnu_ifunc_resolver_return,
1292 /* States of enablement of breakpoint. */
1293 @@ -653,6 +666,10 @@ struct bpstat_what
1294 continuing from a call dummy without popping the frame is not a
1296 enum stop_stack_kind call_dummy;
1298 + /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME. True if we are
1299 + handling a longjmp, false if we are handling an exception. */
1303 /* The possible return values for print_bpstat, print_it_normal,
1304 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
1305 index 926ae2f..a59b965 100644
1306 --- a/gdb/c-typeprint.c
1307 +++ b/gdb/c-typeprint.c
1308 @@ -585,7 +585,13 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
1309 fprintf_filtered (stream, ")");
1311 fprintf_filtered (stream, "[");
1312 - if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
1313 + if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind
1314 + != RANGE_BOUND_KIND_CONSTANT)
1316 + /* No _() - printed sources should not be locale dependent. */
1317 + fprintf_filtered (stream, "variable");
1319 + else if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
1320 && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
1321 fprintf_filtered (stream, "%d",
1323 diff --git a/gdb/config.in b/gdb/config.in
1324 index 1fc457d..f4c846a 100644
1328 language is requested. */
1331 -/* look for global separate data files in this path [DATADIR/gdb] */
1332 +/* Global directory for GDB data files. */
1335 -/* Define if the gdb-datadir directory should be relocated when GDB is moved.
1337 +/* Define if GDB datadir should be relocated when GDB is moved. */
1338 #undef GDB_DATADIR_RELOCATABLE
1340 /* Define to be a string naming the default host character set. */
1343 #undef PTRDIFF_T_SUFFIX
1345 +/* Define to install path for Python sources */
1348 /* Define if the python directory should be relocated when GDB is moved. */
1349 #undef PYTHON_PATH_RELOCATABLE
1351 diff --git a/gdb/configure b/gdb/configure
1352 index 041ffc1..8243abb 100755
1355 @@ -679,6 +679,8 @@ REPORT_BUGS_TO
1364 @@ -945,6 +947,7 @@ enable_dependency_tracking
1365 with_separate_debug_dir
1367 with_relocated_sources
1372 @@ -1646,6 +1649,10 @@ Optional Packages:
1374 --with-relocated-sources=PATH
1375 automatically relocate this path for source files
1376 + --with-gdb-datadir look for global separate data files in this path
1378 + --with-pythondir install Python data files in this path
1379 + [DATADIR/gdb/python]
1380 --with-libunwind use libunwind frame unwinding support
1381 --with-curses use the curses library instead of the termcap
1383 @@ -7878,6 +7885,73 @@ _ACEOF
1387 +# GDB's datadir relocation
1389 +gdbdatadir=${datadir}/gdb
1392 +# Check whether --with-gdb-datadir was given.
1393 +if test "${with_gdb_datadir+set}" = set; then :
1394 + withval=$with_gdb_datadir; gdbdatadir="${withval}"
1399 + test "x$prefix" = xNONE && prefix="$ac_default_prefix"
1400 + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
1401 + ac_define_dir=`eval echo $gdbdatadir`
1402 + ac_define_dir=`eval echo $ac_define_dir`
1404 +cat >>confdefs.h <<_ACEOF
1405 +#define GDB_DATADIR "$ac_define_dir"
1410 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
1411 + if test "x$prefix" = xNONE; then
1412 + test_prefix=/usr/local
1414 + test_prefix=$prefix
1417 + test_prefix=$exec_prefix
1420 +case ${gdbdatadir} in
1421 + "${test_prefix}"|"${test_prefix}/"*|\
1422 + '${exec_prefix}'|'${exec_prefix}/'*)
1424 +$as_echo "#define GDB_DATADIR_RELOCATABLE 1" >>confdefs.h
1428 +GDB_DATADIR_PATH=${gdbdatadir}
1432 +# Check whether --with-pythondir was given.
1433 +if test "${with_pythondir+set}" = set; then :
1434 + withval=$with_pythondir; pythondir="${withval}"
1440 +# If the user passed in a path, define it. Otherwise, compute it at
1441 +# runtime based on the possibly-relocatable datadir.
1442 +if test "$pythondir" = "no"; then
1443 + pythondir='$(GDB_DATADIR_PATH)/python'
1446 +cat >>confdefs.h <<_ACEOF
1447 +#define PYTHONDIR "$pythondir"
1456 subdirs="$subdirs doc testsuite"
1457 @@ -10919,6 +10993,7 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
1458 CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
1459 CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
1460 CONFIG_INSTALL="$CONFIG_INSTALL install-python"
1461 + CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
1462 ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
1464 # Flags needed to compile Python code (taken from python-config --cflags).
1465 diff --git a/gdb/configure.ac b/gdb/configure.ac
1466 index b69c3b6..4e89558 100644
1467 --- a/gdb/configure.ac
1468 +++ b/gdb/configure.ac
1469 @@ -108,6 +108,51 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat
1470 [Relocated directory for source files. ])
1473 +# GDB's datadir relocation
1475 +gdbdatadir=${datadir}/gdb
1477 +AC_ARG_WITH([gdb-datadir],
1478 + [AS_HELP_STRING([--with-gdb-datadir],
1479 + [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
1481 +AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
1482 + [Global directory for GDB data files. ])
1484 +if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
1485 + if test "x$prefix" = xNONE; then
1486 + test_prefix=/usr/local
1488 + test_prefix=$prefix
1491 + test_prefix=$exec_prefix
1494 +case ${gdbdatadir} in
1495 + "${test_prefix}"|"${test_prefix}/"*|\
1496 + '${exec_prefix}'|'${exec_prefix}/'*)
1497 + AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
1500 +GDB_DATADIR_PATH=${gdbdatadir}
1501 +AC_SUBST(GDB_DATADIR_PATH)
1503 +AC_ARG_WITH([pythondir],
1504 + [AS_HELP_STRING([--with-pythondir],
1505 + [install Python data files in this path [DATADIR/gdb/python]])], [pythondir="${withval}"], [pythondir=no])
1507 +# If the user passed in a path, define it. Otherwise, compute it at
1508 +# runtime based on the possibly-relocatable datadir.
1509 +if test "$pythondir" = "no"; then
1510 + pythondir='$(GDB_DATADIR_PATH)/python'
1512 + AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir",
1513 + [Define to install path for Python sources])
1515 +AC_SUBST(pythondir)
1518 AC_CONFIG_SUBDIRS(doc testsuite)
1520 # Check whether to support alternative target configurations
1521 @@ -833,6 +878,7 @@ if test "${have_libpython}" != no; then
1522 CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
1523 CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
1524 CONFIG_INSTALL="$CONFIG_INSTALL install-python"
1525 + CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
1526 ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
1528 # Flags needed to compile Python code (taken from python-config --cflags).
1529 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
1530 index 65d4899..96767b0 100644
1531 --- a/gdb/doc/gdb.texinfo
1532 +++ b/gdb/doc/gdb.texinfo
1533 @@ -1162,6 +1162,16 @@ for remote debugging.
1534 Run using @var{device} for your program's standard input and output.
1535 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1540 +@cindex @code{--python}
1541 +Change interpretation of command line so that the argument immediately
1542 +following this switch is taken to be the name of a Python script file.
1543 +This option stops option processing; subsequent options are passed to
1544 +Python as @code{sys.argv}. This option is only available if Python
1545 +scripting support was enabled when @value{GDBN} was configured.
1547 @c resolve the situation of these eventually
1549 @cindex @code{--tui}
1550 @@ -14308,6 +14318,7 @@ program. To debug a core dump of a previous run, you must also tell
1552 * Files:: Commands to specify files
1553 * Separate Debug Files:: Debugging information in separate files
1554 +* Index Files:: Index files speed up GDB
1555 * Symbol Errors:: Errors reading symbol files
1556 * Data Files:: GDB data files
1558 @@ -15197,6 +15208,46 @@ gnu_debuglink_crc32 (unsigned long crc,
1559 This computation does not apply to the ``build ID'' method.
1563 +@section Index Files Speed Up @value{GDBN}
1564 +@cindex index files
1565 +@cindex @samp{.gdb_index} section
1567 +When @value{GDBN} finds a symbol file, it scans the symbols in the
1568 +file in order to construct an internal symbol table. This lets most
1569 +@value{GDBN} operations work quickly---at the cost of a delay early
1570 +on. For large programs, this delay can be quite lengthy, so
1571 +@value{GDBN} provides a way to build an index, which speeds up
1574 +The index is stored as a section in the symbol file. @value{GDBN} can
1575 +write the index to a file, then you can put it into the symbol file
1576 +using @command{objcopy}.
1578 +To create an index file, use the @code{save gdb-index} command:
1581 +@item save gdb-index @var{directory}
1582 +@kindex save gdb-index
1583 +Create an index file for each symbol file currently known by
1584 +@value{GDBN}. Each file is named after its corresponding symbol file,
1585 +with @samp{.gdb-index} appended, and is written into the given
1589 +Once you have created an index file you can merge it into your symbol
1590 +file, here named @file{symfile}, using @command{objcopy}:
1593 +$ objcopy --add-section .gdb_index=symfile.gdb-index \
1594 + --set-section-flags .gdb_index=readonly symfile symfile
1597 +There are currently some limitation on indices. They only work when
1598 +for DWARF debugging information, not stabs. And, they do not
1599 +currently work for programs using Ada.
1603 @section Errors Reading Symbol Files
1605 @@ -20349,8 +20400,6 @@ containing @code{end}. For example:
1608 (@value{GDBP}) python
1610 -End with a line saying just "end".
1614 @@ -20363,6 +20412,14 @@ in a Python script. This can be controlled using @code{maint set
1615 python print-stack}: if @code{on}, the default, then Python stack
1616 printing is enabled; if @code{off}, then Python stack printing is
1619 +@kindex maint set python auto-load
1620 +@item maint set python auto-load
1621 +By default, @value{GDBN} will attempt to automatically load Python
1622 +code when an object file is opened. This can be controlled using
1623 +@code{maint set python auto-load}: if @code{on}, the default, then
1624 +Python auto-loading is enabled; if @code{off}, then Python
1625 +auto-loading is disabled.
1628 It is also possible to execute a Python script from the @value{GDBN}
1629 @@ -20384,6 +20441,14 @@ and thus is always available.
1631 @cindex programming in python
1633 +You can get quick online help for @value{GDBN}'s Python API by issuing
1634 +the command @w{@kbd{python help (gdb)}}.
1636 +Functions and methods which have two or more optional arguments allow
1637 +them to be specified using keyword syntax. This allows passing some
1638 +optional arguments while skipping others. Example:
1639 +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
1641 @cindex python stdout
1642 @cindex python pagination
1643 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
1644 @@ -20395,7 +20460,7 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
1646 * Basic Python:: Basic Python Functions.
1647 * Exception Handling::
1648 -* Values From Inferior::
1649 +* Values From Inferior:: Python representation of values.
1650 * Types In Python:: Python representation of types.
1651 * Pretty Printing API:: Pretty-printing values.
1652 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
1653 @@ -20456,6 +20521,12 @@ Return a sequence holding all of @value{GDBN}'s breakpoints.
1654 @xref{Breakpoints In Python}, for more information.
1657 +@findex gdb.breakpoints
1659 +Return a sequence holding all of @value{GDBN}'s breakpoints.
1660 +@xref{Breakpoints In Python}, for more information.
1663 @findex gdb.parameter
1664 @defun parameter parameter
1665 Return the value of a @value{GDBN} parameter. @var{parameter} is a
1666 @@ -20472,6 +20543,7 @@ a Python value of the appropriate type, and returned.
1667 @defun history number
1668 Return a value from @value{GDBN}'s value history (@pxref{Value
1669 History}). @var{number} indicates which history element to return.
1671 If @var{number} is negative, then @value{GDBN} will take its absolute value
1672 and count backward from the last element (i.e., the most recent element) to
1673 find the value to return. If @var{number} is zero, then @value{GDBN} will
1674 @@ -20496,6 +20568,21 @@ compute values, for example, it is the only way to get the value of a
1675 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
1678 +@findex gdb.post_event
1679 +@defun post_event event
1680 +Put @var{event}, a callable object taking no arguments, into
1681 +@value{GDBN}'s internal event queue. This callable will be invoked at
1682 +some later point, during @value{GDBN}'s event processing. Events
1683 +posted using @code{post_event} will be run in the order in which they
1684 +were posted; however, there is no way to know when they will be
1685 +processed relative to other events inside @value{GDBN}.
1687 +@value{GDBN} is not thread-safe. If your Python program uses multiple
1688 +threads, you must be careful to only call @value{GDBN}-specific
1689 +functions in the main @value{GDBN} thread. @code{post_event} ensures
1695 Print a string to @value{GDBN}'s paginated standard output stream.
1696 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
1697 index 54187dd..320b501 100644
1698 --- a/gdb/doc/gdbint.texinfo
1699 +++ b/gdb/doc/gdbint.texinfo
1700 @@ -2102,6 +2102,18 @@ time, and so we attempt to handle symbols incrementally. For instance,
1701 we create @dfn{partial symbol tables} consisting of only selected
1702 symbols, and only expand them to full symbol tables when necessary.
1706 +* Partial Symbol Tables::
1708 +* Object File Formats::
1709 +* Debugging File Formats::
1710 +* Adding a New Symbol Reader to GDB::
1711 +* Memory Management for Symbol Files::
1712 +* Memory Management for Types::
1715 +@node Symbol Reading
1716 @section Symbol Reading
1718 @cindex symbol reading
1719 @@ -2194,6 +2206,7 @@ symtab. Upon return, @code{pst->readin} should have been set to 1, and
1720 zero if there were no symbols in that part of the symbol file.
1723 +@node Partial Symbol Tables
1724 @section Partial Symbol Tables
1726 @value{GDBN} has three types of symbol tables:
1727 @@ -2295,6 +2308,7 @@ and partial symbol tables behind a set of function pointers known as
1728 the @dfn{quick symbol functions}. These are documented in
1734 @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
1735 @@ -2317,6 +2331,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
1736 other members of the type struct, such as whether the type is signed
1737 or unsigned, and how many bits it uses.
1739 +@anchor{Builtin Types}
1740 @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
1742 These are instances of type structs that roughly correspond to
1743 @@ -2331,6 +2346,7 @@ only one instance exists, while @file{c-lang.c} builds as many
1744 @code{TYPE_CODE_INT} types as needed, with each one associated with
1745 some particular objfile.
1747 +@node Object File Formats
1748 @section Object File Formats
1749 @cindex object file formats
1751 @@ -2416,6 +2432,7 @@ SOM, which is a cross-language ABI).
1753 The SOM reader is in @file{somread.c}.
1755 +@node Debugging File Formats
1756 @section Debugging File Formats
1758 This section describes characteristics of debugging information that
1759 @@ -2487,6 +2504,7 @@ DWARF 3 is an improved version of DWARF 2.
1760 @cindex SOM debugging info
1761 Like COFF, the SOM definition includes debugging information.
1763 +@node Adding a New Symbol Reader to GDB
1764 @section Adding a New Symbol Reader to @value{GDBN}
1766 @cindex adding debugging info reader
1767 @@ -2509,6 +2527,7 @@ will only ever be implemented by one object file format may be called
1768 directly. This interface should be described in a file
1769 @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
1771 +@node Memory Management for Symbol Files
1772 @section Memory Management for Symbol Files
1774 Most memory associated with a loaded symbol file is stored on
1775 @@ -2520,10 +2539,45 @@ released when the objfile is unloaded or reloaded. Therefore one
1776 objfile must not reference symbol or type data from another objfile;
1777 they could be unloaded at different times.
1779 -User convenience variables, et cetera, have associated types. Normally
1780 -these types live in the associated objfile. However, when the objfile
1781 -is unloaded, those types are deep copied to global memory, so that
1782 -the values of the user variables and history items are not lost.
1783 +@node Memory Management for Types
1784 +@section Memory Management for Types
1785 +@cindex memory management for types
1787 +@findex TYPE_OBJFILE
1788 +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
1789 +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
1790 +obstack) and in such case the type remains valid till the objfile is unloaded
1791 +or reloaded. For such types with an associated objfile no reference counting
1794 +User convenience variables, et cetera, have associated types. Normally these
1795 +types live in the associated objfile. However, when the objfile is unloaded,
1796 +those types are deep copied to global memory, so that the values of the user
1797 +variables and history items are not lost. During the copy they will get their
1798 +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
1801 +Types with null @code{TYPE_OBJFILE} can be either permanent types
1802 +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
1803 +first idle @value{GDBN} moment if the last object referencing them is removed.
1804 +Permanent types are allocated by the function @code{alloc_type} (and its
1805 +derivations like @code{init_type}) specifying objfile as @code{NULL}. The
1806 +reclaimable types are created the same way but moreover they need to have
1807 +@code{type_init_group} called to start their tracking as being possibly
1810 +@findex free_all_types
1811 +When @value{GDBN} gets idle it always calls the @code{free_all_types} function
1812 +which deallocates any unused types. All types currently not owned by an
1813 +objfile must be marked as used on each @code{free_all_types} call as they would
1814 +get deallocated as unused otherwise.
1816 +@code{free_all_types} automatically checks for any cross-type references such
1817 +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
1818 +prevents early deallocation for any such existing references. Reclaimable
1819 +types may reference any other reclaimable types or even permanent types. But
1820 +permanent types must not reference reclaimable types (nor an objfile associated
1824 @node Language Support
1825 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
1826 index e19b8ed..343e160 100644
1827 --- a/gdb/doc/observer.texi
1828 +++ b/gdb/doc/observer.texi
1829 @@ -223,6 +223,11 @@ Bytes from @var{data} to @var{data} + @var{len} have been written
1830 to the current inferior at @var{addr}.
1833 +@deftypefun void mark_used (void)
1834 +Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
1835 +collector pass. Currently only @code{type_mark_used} marker is supported.
1838 @deftypefun void test_notification (int @var{somearg})
1839 This observer is used for internal testing. Do not use.
1840 See testsuite/gdb.gdb/observer.exp.
1841 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
1842 index b9ae108..2555908 100644
1843 --- a/gdb/dwarf2expr.c
1844 +++ b/gdb/dwarf2expr.c
1845 @@ -875,6 +875,13 @@ execute_stack_op (struct dwarf_expr_context *ctx,
1846 ctx->dwarf_call (ctx, result);
1849 + case DW_OP_push_object_address:
1850 + if (ctx->get_object_address == NULL)
1851 + error (_("DWARF-2 expression error: DW_OP_push_object_address must "
1852 + "have a value to push."));
1853 + result = (ctx->get_object_address) (ctx->baton);
1857 error (_("Unhandled dwarf expression opcode 0x%x"), op);
1859 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
1860 index 61b8f00..d94c03c 100644
1861 --- a/gdb/dwarf2expr.h
1862 +++ b/gdb/dwarf2expr.h
1863 @@ -108,9 +108,15 @@ struct dwarf_expr_context
1865 /* Not yet implemented. */
1867 + /* Return the location expression for the dwarf expression
1868 + subroutine in the die at OFFSET in the current compilation unit.
1869 + The result must be live until the current expression evaluation
1871 + unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length);
1874 /* Return the `object address' for DW_OP_push_object_address. */
1875 CORE_ADDR (*get_object_address) (void *baton);
1878 /* The current depth of dwarf expression recursion, via DW_OP_call*,
1879 DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
1880 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
1881 index f59bc40..7ff0ef9 100644
1882 --- a/gdb/dwarf2loc.c
1883 +++ b/gdb/dwarf2loc.c
1884 @@ -48,6 +48,12 @@ static void
1885 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
1886 const gdb_byte **start, size_t *length);
1888 +static struct value *dwarf2_evaluate_loc_desc (struct type *type,
1889 + struct frame_info *frame,
1890 + const gdb_byte *data,
1891 + unsigned short size,
1892 + struct dwarf2_per_cu_data *per_cu);
1894 /* A helper function for dealing with location lists. Given a
1895 symbol baton (BATON) and a pc value (PC), find the appropriate
1896 location expression, set *LOCEXPR_LENGTH, and return a pointer
1897 @@ -127,6 +133,9 @@ struct dwarf_expr_baton
1899 struct frame_info *frame;
1900 struct dwarf2_per_cu_data *per_cu;
1901 + /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
1902 + DW_AT_data_location) for DW_OP_push_object_address. */
1903 + CORE_ADDR object_address;
1906 /* Helper functions for dwarf2_evaluate_loc_desc. */
1907 @@ -195,23 +204,33 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
1908 symbaton = SYMBOL_LOCATION_BATON (framefunc);
1909 *start = find_location_expression (symbaton, length, pc);
1912 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
1914 struct dwarf2_locexpr_baton *symbaton;
1916 symbaton = SYMBOL_LOCATION_BATON (framefunc);
1917 - if (symbaton != NULL)
1919 - *length = symbaton->size;
1920 - *start = symbaton->data;
1924 + gdb_assert (symbaton != NULL);
1925 + *start = symbaton->data;
1926 + *length = symbaton->size;
1928 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
1930 + struct dwarf2_locexpr_baton *symbaton;
1932 + symbaton = SYMBOL_LOCATION_BATON (framefunc);
1933 + gdb_assert (symbaton == NULL);
1935 + *length = 0; /* unused */
1938 + internal_error (__FILE__, __LINE__,
1939 + _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
1940 + SYMBOL_COMPUTED_OPS (framefunc),
1941 + SYMBOL_PRINT_NAME (framefunc));
1944 error (_("Could not find the frame base for \"%s\"."),
1945 - SYMBOL_NATURAL_NAME (framefunc));
1946 + SYMBOL_PRINT_NAME (framefunc));
1949 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
1950 @@ -263,6 +282,158 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
1951 return per_cu_dwarf_call (ctx, die_offset, debaton->per_cu);
1955 +dwarf_expr_object_address (void *baton)
1957 + struct dwarf_expr_baton *debaton = baton;
1959 + /* The message is suppressed in DWARF_BLOCK_EXEC. */
1960 + if (debaton->object_address == 0)
1961 + error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
1963 + return debaton->object_address;
1966 +/* Address of the variable we are currently referring to. It is set from
1967 + DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
1968 + DW_OP_push_object_address. */
1970 +static CORE_ADDR object_address;
1972 +/* Callers use object_address_set while their callers use the result set so we
1973 + cannot run the cleanup at the local block of our direct caller. Still we
1974 + should reset OBJECT_ADDRESS at least for the next GDB command. */
1977 +object_address_cleanup (void *prev_save_voidp)
1979 + CORE_ADDR *prev_save = prev_save_voidp;
1981 + object_address = *prev_save;
1982 + xfree (prev_save);
1985 +/* Set the base address - DW_AT_location - of a variable. It is being later
1986 + used to derive other object addresses by DW_OP_push_object_address.
1988 + It would be useful to sanity check ADDRESS - such as for some objects with
1989 + unset value_raw_address - but some valid addresses may be zero (such as first
1990 + objects in relocatable .o files). */
1993 +object_address_set (CORE_ADDR address)
1995 + CORE_ADDR *prev_save;
1997 + prev_save = xmalloc (sizeof *prev_save);
1998 + *prev_save = object_address;
1999 + make_cleanup (object_address_cleanup, prev_save);
2001 + object_address = address;
2004 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
2005 + by dwarf_expr_fetch (RETVAL, 0). FRAME parameter can be NULL to call
2006 + get_selected_frame to find it. Returned dwarf_expr_context freeing is
2007 + pushed on the cleanup chain. */
2009 +static struct dwarf_expr_context *
2010 +dwarf_expr_prep_ctx (struct frame_info *frame, const gdb_byte *data,
2011 + size_t size, struct dwarf2_per_cu_data *per_cu)
2013 + struct dwarf_expr_context *ctx;
2014 + struct dwarf_expr_baton baton;
2015 + struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2017 + baton.frame = frame;
2018 + baton.per_cu = per_cu;
2019 + baton.object_address = object_address;
2021 + ctx = new_dwarf_expr_context ();
2022 + make_cleanup_free_dwarf_expr_context (ctx);
2024 + ctx->gdbarch = get_objfile_arch (objfile);
2025 + ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2026 + ctx->offset = dwarf2_per_cu_text_offset (per_cu);
2027 + ctx->baton = &baton;
2028 + ctx->read_reg = dwarf_expr_read_reg;
2029 + ctx->read_mem = dwarf_expr_read_mem;
2030 + ctx->get_frame_base = dwarf_expr_frame_base;
2031 + ctx->get_frame_cfa = dwarf_expr_frame_cfa;
2032 + ctx->get_tls_address = dwarf_expr_tls_address;
2033 + ctx->dwarf_call = dwarf_expr_dwarf_call;
2034 + ctx->get_object_address = dwarf_expr_object_address;
2036 + dwarf_expr_eval (ctx, data, size);
2038 + /* It was used only during dwarf_expr_eval. */
2039 + ctx->baton = NULL;
2044 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
2045 + CORE_ADDR result on the DWARF stack stack. */
2048 +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
2050 + struct dwarf_expr_context *ctx;
2052 + struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2054 + ctx = dwarf_expr_prep_ctx (get_selected_frame (NULL), dlbaton->data,
2055 + dlbaton->size, dlbaton->per_cu);
2056 + if (ctx->num_pieces > 0)
2057 + error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
2059 + retval = dwarf_expr_fetch (ctx, 0);
2061 + if (ctx->location == DWARF_VALUE_REGISTER)
2063 + /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
2065 + int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
2066 + struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
2067 + struct frame_info *frame = get_selected_frame (NULL);
2069 + retval = address_from_register (type, gdb_regnum, frame);
2072 + do_cleanups (back_to);
2077 +/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one
2078 + CORE_ADDR result stored to *ADDRP on the DWARF stack stack. If the result
2079 + could not be found return zero and keep *ADDRP unchanged. */
2082 +dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
2083 + struct type *type, CORE_ADDR *addrp)
2085 + struct frame_info *frame = get_selected_frame (NULL);
2086 + const gdb_byte *data;
2088 + struct value *val;
2093 + data = find_location_expression (dllbaton, &size,
2094 + get_frame_address_in_block (frame));
2098 + val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu);
2099 + if (value_optimized_out (val))
2102 + *addrp = value_as_address (val);
2106 struct piece_closure
2108 /* Reference count. */
2109 @@ -887,10 +1058,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2110 struct dwarf2_per_cu_data *per_cu)
2112 struct value *retval;
2113 - struct dwarf_expr_baton baton;
2114 struct dwarf_expr_context *ctx;
2115 - struct cleanup *old_chain;
2116 - struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2117 + struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
2121 @@ -900,24 +1069,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2125 - baton.frame = frame;
2126 - baton.per_cu = per_cu;
2127 + ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu);
2129 - ctx = new_dwarf_expr_context ();
2130 - old_chain = make_cleanup_free_dwarf_expr_context (ctx);
2132 - ctx->gdbarch = get_objfile_arch (objfile);
2133 - ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2134 - ctx->offset = dwarf2_per_cu_text_offset (per_cu);
2135 - ctx->baton = &baton;
2136 - ctx->read_reg = dwarf_expr_read_reg;
2137 - ctx->read_mem = dwarf_expr_read_mem;
2138 - ctx->get_frame_base = dwarf_expr_frame_base;
2139 - ctx->get_frame_cfa = dwarf_expr_frame_cfa;
2140 - ctx->get_tls_address = dwarf_expr_tls_address;
2141 - ctx->dwarf_call = dwarf_expr_dwarf_call;
2143 - dwarf_expr_eval (ctx, data, size);
2144 if (ctx->num_pieces > 0)
2146 struct piece_closure *c;
2147 @@ -951,6 +1104,11 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2148 CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
2149 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
2151 + /* object_address_set called here is required in ALLOCATE_VALUE's
2152 + CHECK_TYPEDEF for the object's possible
2153 + DW_OP_push_object_address. */
2154 + object_address_set (address);
2156 retval = allocate_value (type);
2157 VALUE_LVAL (retval) = lval_memory;
2158 set_value_lazy (retval, 1);
2159 @@ -2590,11 +2748,51 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2163 -/* The set of location functions used with the DWARF-2 expression
2164 - evaluator and location lists. */
2165 +/* The set of location functions used with the DWARF-2 location lists. */
2166 const struct symbol_computed_ops dwarf2_loclist_funcs = {
2167 loclist_read_variable,
2168 loclist_read_needs_frame,
2169 loclist_describe_location,
2170 loclist_tracepoint_var_ref
2173 +static struct value *
2174 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
2176 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2178 + gdb_assert (dlbaton == NULL);
2179 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
2183 +missing_read_needs_frame (struct symbol *symbol)
2189 +missing_describe_location (struct symbol *symbol, CORE_ADDR addr,
2190 + struct ui_file *stream)
2192 + fprintf_filtered (stream, _("a variable we are unable to resolve"));
2196 +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2197 + struct agent_expr *ax, struct axs_value *value)
2199 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2201 + gdb_assert (dlbaton == NULL);
2202 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
2205 +/* The set of location functions used with the DWARF-2 evaluator when we are
2206 + unable to resolve the symbols. */
2207 +const struct symbol_computed_ops dwarf2_missing_funcs = {
2208 + missing_read_variable,
2209 + missing_read_needs_frame,
2210 + missing_describe_location,
2211 + missing_tracepoint_var_ref
2213 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
2214 index 826bc45..1e7d8dc 100644
2215 --- a/gdb/dwarf2loc.h
2216 +++ b/gdb/dwarf2loc.h
2217 @@ -86,5 +86,14 @@ struct dwarf2_loclist_baton
2219 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
2220 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
2221 +extern const struct symbol_computed_ops dwarf2_missing_funcs;
2223 +extern void object_address_set (CORE_ADDR address);
2225 +extern CORE_ADDR dwarf_locexpr_baton_eval
2226 + (struct dwarf2_locexpr_baton *dlbaton);
2228 +extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
2229 + struct type *type, CORE_ADDR *addrp);
2231 #endif /* dwarf2loc.h */
2232 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
2233 index 1e75235..d54e266 100644
2234 --- a/gdb/dwarf2read.c
2235 +++ b/gdb/dwarf2read.c
2237 #include "typeprint.h"
2238 #include "jv-lang.h"
2239 #include "psympriv.h"
2240 +#include "exceptions.h"
2241 +#include "gdb_stat.h"
2242 +#include "completer.h"
2245 #include "gdb_string.h"
2246 @@ -129,6 +132,33 @@ struct dwarf2_section_info
2250 +/* All offsets in the index are of this type. It must be
2251 + architecture-independent. */
2252 +typedef uint32_t offset_type;
2254 +DEF_VEC_I (offset_type);
2256 +/* A description of the mapped index. The file format is described in
2257 + a comment by the code that writes the index. */
2258 +struct mapped_index
2260 + /* The total length of the buffer. */
2262 + /* A pointer to the address table data. */
2263 + const gdb_byte *address_table;
2264 + /* Size of the address table data in bytes. */
2265 + offset_type address_table_size;
2266 + /* The hash table. */
2267 + const offset_type *index_table;
2268 + /* Size in slots, each slot is 2 offset_types. */
2269 + offset_type index_table_slots;
2270 + /* A pointer to the constant pool. */
2271 + const char *constant_pool;
2274 +typedef struct dwarf2_per_cu_data *dwarf2_per_cu_data_ptr;
2275 +DEF_VEC_P (dwarf2_per_cu_data_ptr);
2277 struct dwarf2_per_objfile
2279 struct dwarf2_section_info info;
2280 @@ -141,6 +171,7 @@ struct dwarf2_per_objfile
2281 struct dwarf2_section_info types;
2282 struct dwarf2_section_info frame;
2283 struct dwarf2_section_info eh_frame;
2284 + struct dwarf2_section_info gdb_index;
2287 struct objfile *objfile;
2288 @@ -163,6 +194,12 @@ struct dwarf2_per_objfile
2289 /* A flag indicating wether this objfile has a section loaded at a
2291 int has_section_at_zero;
2293 + /* True if we are using the mapped index. */
2294 + unsigned char using_index;
2296 + /* The mapped index. */
2297 + struct mapped_index *index_table;
2300 static struct dwarf2_per_objfile *dwarf2_per_objfile;
2301 @@ -182,6 +219,7 @@ static struct dwarf2_per_objfile *dwarf2_per_objfile;
2302 #define TYPES_SECTION "debug_types"
2303 #define FRAME_SECTION "debug_frame"
2304 #define EH_FRAME_SECTION "eh_frame"
2305 +#define GDB_INDEX_SECTION "gdb_index"
2307 /* local data types */
2309 @@ -307,6 +345,32 @@ struct dwarf2_cu
2310 unsigned int has_namespace_info : 1;
2313 +/* When using the index (and thus not using psymtabs), each CU has an
2314 + object of this type. This is used to hold information needed by
2315 + the various "quick" methods. */
2316 +struct dwarf2_per_cu_quick_data
2318 + /* The line table. This can be NULL if there was no line table. */
2319 + struct line_header *lines;
2321 + /* The file names from the line table. */
2322 + const char **file_names;
2323 + /* The file names from the line table after being run through
2325 + const char **full_names;
2327 + /* The corresponding symbol table. This is NULL if symbols for this
2328 + CU have not yet been read. */
2329 + struct symtab *symtab;
2331 + /* A temporary mark bit used when iterating over all CUs in
2332 + expand_symtabs_matching. */
2333 + unsigned int mark : 1;
2335 + /* True if we've tried to read the line table. */
2336 + unsigned int read_lines : 1;
2339 /* Persistent data held for a compilation unit, even when not
2340 processing it. We put a pointer to this structure in the
2341 read_symtab_private field of the psymtab. If we encounter
2342 @@ -347,10 +411,21 @@ struct dwarf2_per_cu_data
2346 - /* The partial symbol table associated with this compilation unit,
2347 - or NULL for partial units (which do not have an associated
2349 - struct partial_symtab *psymtab;
2350 + /* The corresponding objfile. */
2351 + struct objfile *objfile;
2353 + /* When using partial symbol tables, the 'psymtab' field is active.
2354 + Otherwise the 'quick' field is active. */
2357 + /* The partial symbol table associated with this compilation unit,
2358 + or NULL for partial units (which do not have an associated
2360 + struct partial_symtab *psymtab;
2362 + /* Data needed by the "quick" functions. */
2363 + struct dwarf2_per_cu_quick_data *quick;
2367 /* Entry in the signatured_types hash table. */
2368 @@ -1083,6 +1158,9 @@ static int attr_form_is_section_offset (struct attribute *);
2370 static int attr_form_is_constant (struct attribute *);
2372 +static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton
2373 + (struct attribute *attr, struct dwarf2_cu *cu);
2375 static void dwarf2_symbol_mark_computed (struct attribute *attr,
2377 struct dwarf2_cu *cu);
2378 @@ -1113,6 +1191,9 @@ static void age_cached_comp_units (void);
2380 static void free_one_cached_comp_unit (void *);
2382 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
2383 + struct dwarf2_cu *cu);
2385 static struct type *set_die_type (struct die_info *, struct type *,
2386 struct dwarf2_cu *);
2388 @@ -1132,6 +1213,56 @@ static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
2390 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
2392 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
2393 + (struct attribute *attr, struct dwarf2_cu *cu);
2395 +static void dwarf2_release_queue (void *dummy);
2397 +static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
2398 + struct objfile *objfile);
2400 +static void process_queue (struct objfile *objfile);
2402 +static void find_file_and_directory (struct die_info *die,
2403 + struct dwarf2_cu *cu,
2404 + char **name, char **comp_dir);
2406 +static char *file_full_name (int file, struct line_header *lh,
2407 + const char *comp_dir);
2409 +static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
2410 + gdb_byte *info_ptr,
2412 + unsigned int buffer_size,
2415 +static void init_cu_die_reader (struct die_reader_specs *reader,
2416 + struct dwarf2_cu *cu);
2418 +#if WORDS_BIGENDIAN
2420 +/* Convert VALUE between big- and little-endian. */
2422 +byte_swap (offset_type value)
2424 + offset_type result;
2426 + result = (value & 0xff) << 24;
2427 + result |= (value & 0xff00) << 8;
2428 + result |= (value & 0xff0000) >> 8;
2429 + result |= (value & 0xff000000) >> 24;
2433 +#define MAYBE_SWAP(V) byte_swap (V)
2436 +#define MAYBE_SWAP(V) (V)
2437 +#endif /* WORDS_BIGENDIAN */
2439 +/* The suffix for an index file. */
2440 +#define INDEX_SUFFIX ".gdb-index"
2442 /* Try to locate the sections we need for DWARF 2 debugging
2443 information and return true if we have enough to do something. */
2445 @@ -1230,6 +1361,11 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
2446 dwarf2_per_objfile->types.asection = sectp;
2447 dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
2449 + else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
2451 + dwarf2_per_objfile->gdb_index.asection = sectp;
2452 + dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
2455 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
2456 && bfd_section_vma (abfd, sectp) == 0)
2457 @@ -1353,87 +1489,940 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
2459 pagesize = getpagesize ();
2461 - /* Only try to mmap sections which are large enough: we don't want to
2462 - waste space due to fragmentation. Also, only try mmap for sections
2463 - without relocations. */
2464 + /* Only try to mmap sections which are large enough: we don't want to
2465 + waste space due to fragmentation. Also, only try mmap for sections
2466 + without relocations. */
2468 + if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
2470 + off_t pg_offset = sectp->filepos & ~(pagesize - 1);
2471 + size_t map_length = info->size + sectp->filepos - pg_offset;
2472 + caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
2473 + MAP_PRIVATE, pg_offset);
2475 + if (retbuf != MAP_FAILED)
2477 + info->was_mmapped = 1;
2478 + info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
2479 +#if HAVE_POSIX_MADVISE
2480 + posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
2487 + /* If we get here, we are a normal, not-compressed section. */
2488 + info->buffer = buf
2489 + = obstack_alloc (&objfile->objfile_obstack, info->size);
2491 + /* When debugging .o files, we may need to apply relocations; see
2492 + http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2493 + We never compress sections in .o files, so we only need to
2494 + try this when the section is not compressed. */
2495 + retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
2496 + if (retbuf != NULL)
2498 + info->buffer = retbuf;
2502 + if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
2503 + || bfd_bread (buf, info->size, abfd) != info->size)
2504 + error (_("Dwarf Error: Can't read DWARF data from '%s'"),
2505 + bfd_get_filename (abfd));
2508 +/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2512 +dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
2513 + asection **sectp, gdb_byte **bufp,
2514 + bfd_size_type *sizep)
2516 + struct dwarf2_per_objfile *data
2517 + = objfile_data (objfile, dwarf2_objfile_data_key);
2518 + struct dwarf2_section_info *info;
2520 + /* We may see an objfile without any DWARF, in which case we just
2521 + return nothing. */
2529 + if (section_is_p (section_name, EH_FRAME_SECTION))
2530 + info = &data->eh_frame;
2531 + else if (section_is_p (section_name, FRAME_SECTION))
2532 + info = &data->frame;
2536 + if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
2537 + /* We haven't read this section in yet. Do it now. */
2538 + dwarf2_read_section (objfile, info);
2540 + *sectp = info->asection;
2541 + *bufp = info->buffer;
2542 + *sizep = info->size;
2547 +/* Read in the symbols for PER_CU. OBJFILE is the objfile from which
2550 +dw2_do_instantiate_symtab (struct objfile *objfile,
2551 + struct dwarf2_per_cu_data *per_cu)
2553 + struct cleanup *back_to;
2555 + back_to = make_cleanup (dwarf2_release_queue, NULL);
2557 + queue_comp_unit (per_cu, objfile);
2559 + if (per_cu->from_debug_types)
2560 + read_signatured_type_at_offset (objfile, per_cu->offset);
2562 + load_full_comp_unit (per_cu, objfile);
2564 + process_queue (objfile);
2566 + /* Age the cache, releasing compilation units that have not
2567 + been used recently. */
2568 + age_cached_comp_units ();
2570 + do_cleanups (back_to);
2573 +/* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2574 + the objfile from which this CU came. Returns the resulting symbol
2576 +static struct symtab *
2577 +dw2_instantiate_symtab (struct objfile *objfile,
2578 + struct dwarf2_per_cu_data *per_cu)
2580 + if (!per_cu->v.quick->symtab)
2582 + struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
2583 + increment_reading_symtab ();
2584 + dw2_do_instantiate_symtab (objfile, per_cu);
2585 + do_cleanups (back_to);
2587 + return per_cu->v.quick->symtab;
2590 +/* A helper function that knows how to read a 64-bit value in a way
2591 + that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2594 +extract_cu_value (const char *bytes, ULONGEST *result)
2596 + if (sizeof (ULONGEST) < 8)
2600 + /* Ignore the upper 4 bytes if they are all zero. */
2601 + for (i = 0; i < 4; ++i)
2602 + if (bytes[i + 4] != 0)
2605 + *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
2608 + *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
2612 +/* Read the CU list from the mapped index, and use it to create all
2613 + the CU objects for this objfile. Return 0 if something went wrong,
2614 + 1 if everything went ok. */
2616 +create_cus_from_index (struct objfile *objfile, struct mapped_index *index,
2617 + const gdb_byte *cu_list, offset_type cu_list_elements)
2620 + const char *entry;
2622 + dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
2623 + dwarf2_per_objfile->all_comp_units
2624 + = obstack_alloc (&objfile->objfile_obstack,
2625 + dwarf2_per_objfile->n_comp_units
2626 + * sizeof (struct dwarf2_per_cu_data *));
2628 + for (i = 0; i < cu_list_elements; i += 2)
2630 + struct dwarf2_per_cu_data *the_cu;
2631 + ULONGEST offset, length;
2633 + if (!extract_cu_value (cu_list, &offset)
2634 + || !extract_cu_value (cu_list + 8, &length))
2638 + the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2639 + struct dwarf2_per_cu_data);
2640 + the_cu->offset = offset;
2641 + the_cu->length = length;
2642 + the_cu->objfile = objfile;
2643 + the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2644 + struct dwarf2_per_cu_quick_data);
2645 + dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
2651 +/* Read the address map data from the mapped index, and use it to
2652 + populate the objfile's psymtabs_addrmap. */
2654 +create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2656 + const gdb_byte *iter, *end;
2657 + struct obstack temp_obstack;
2658 + struct addrmap *mutable_map;
2659 + struct cleanup *cleanup;
2660 + CORE_ADDR baseaddr;
2662 + obstack_init (&temp_obstack);
2663 + cleanup = make_cleanup_obstack_free (&temp_obstack);
2664 + mutable_map = addrmap_create_mutable (&temp_obstack);
2666 + iter = index->address_table;
2667 + end = iter + index->address_table_size;
2669 + baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2671 + while (iter < end)
2673 + ULONGEST hi, lo, cu_index;
2674 + lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2676 + hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2678 + cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2681 + addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2682 + dwarf2_per_objfile->all_comp_units[cu_index]);
2685 + objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2686 + &objfile->objfile_obstack);
2687 + do_cleanups (cleanup);
2690 +/* The hash function for strings in the mapped index. This is the
2691 + same as the hashtab.c hash function, but we keep a separate copy to
2692 + maintain control over the implementation. This is necessary
2693 + because the hash function is tied to the format of the mapped index
2696 +mapped_index_string_hash (const void *p)
2698 + const unsigned char *str = (const unsigned char *) p;
2702 + while ((c = *str++) != 0)
2703 + r = r * 67 + c - 113;
2708 +/* Find a slot in the mapped index INDEX for the object named NAME.
2709 + If NAME is found, set *VEC_OUT to point to the CU vector in the
2710 + constant pool and return 1. If NAME cannot be found, return 0. */
2712 +find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2713 + offset_type **vec_out)
2715 + offset_type hash = mapped_index_string_hash (name);
2716 + offset_type slot, step;
2718 + slot = hash & (index->index_table_slots - 1);
2719 + step = ((hash * 17) & (index->index_table_slots - 1)) | 1;
2723 + /* Convert a slot number to an offset into the table. */
2724 + offset_type i = 2 * slot;
2726 + if (index->index_table[i] == 0 && index->index_table[i + 1] == 0)
2729 + str = index->constant_pool + MAYBE_SWAP (index->index_table[i]);
2730 + if (!strcmp (name, str))
2732 + *vec_out = (offset_type *) (index->constant_pool
2733 + + MAYBE_SWAP (index->index_table[i + 1]));
2737 + slot = (slot + step) & (index->index_table_slots - 1);
2741 +/* Read the index file. If everything went ok, initialize the "quick"
2742 + elements of all the CUs and return 1. Otherwise, return 0. */
2744 +dwarf2_read_index (struct objfile *objfile)
2747 + struct mapped_index *map;
2748 + offset_type *metadata;
2749 + const gdb_byte *cu_list;
2750 + offset_type cu_list_elements;
2752 + if (dwarf2_per_objfile->gdb_index.asection == NULL
2753 + || dwarf2_per_objfile->gdb_index.size == 0)
2755 + dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2757 + addr = dwarf2_per_objfile->gdb_index.buffer;
2758 + /* Version check. */
2759 + if (MAYBE_SWAP (*(offset_type *) addr) != 1)
2762 + map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2763 + map->total_size = dwarf2_per_objfile->gdb_index.size;
2765 + metadata = (offset_type *) (addr + sizeof (offset_type));
2766 + cu_list = addr + MAYBE_SWAP (metadata[0]);
2767 + cu_list_elements = ((MAYBE_SWAP (metadata[1]) - MAYBE_SWAP (metadata[0]))
2769 + map->address_table = addr + MAYBE_SWAP (metadata[1]);
2770 + map->address_table_size = (MAYBE_SWAP (metadata[2])
2771 + - MAYBE_SWAP (metadata[1]));
2772 + map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[2]));
2773 + map->index_table_slots = ((MAYBE_SWAP (metadata[3])
2774 + - MAYBE_SWAP (metadata[2]))
2775 + / (2 * sizeof (offset_type)));
2776 + map->constant_pool = addr + MAYBE_SWAP (metadata[3]);
2778 + if (!create_cus_from_index (objfile, map, cu_list, cu_list_elements))
2781 + create_addrmap_from_index (objfile, map);
2783 + dwarf2_per_objfile->index_table = map;
2784 + dwarf2_per_objfile->using_index = 1;
2789 +/* A helper for the "quick" functions which sets the global
2790 + dwarf2_per_objfile according to OBJFILE. */
2792 +dw2_setup (struct objfile *objfile)
2794 + dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2795 + gdb_assert (dwarf2_per_objfile);
2798 +/* A helper for the "quick" functions which attempts to read the line
2799 + table for THIS_CU. */
2801 +dw2_require_line_header (struct objfile *objfile,
2802 + struct dwarf2_per_cu_data *this_cu)
2804 + bfd *abfd = objfile->obfd;
2805 + struct line_header *lh = NULL;
2806 + struct attribute *attr;
2807 + struct cleanup *cleanups;
2808 + struct die_info *comp_unit_die;
2809 + gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2810 + int has_children, i;
2811 + struct dwarf2_cu cu;
2812 + unsigned int bytes_read, buffer_size;
2813 + struct die_reader_specs reader_specs;
2814 + char *name, *comp_dir;
2816 + if (this_cu->v.quick->read_lines)
2818 + this_cu->v.quick->read_lines = 1;
2820 + memset (&cu, 0, sizeof (cu));
2821 + cu.objfile = objfile;
2822 + obstack_init (&cu.comp_unit_obstack);
2824 + cleanups = make_cleanup (free_stack_comp_unit, &cu);
2826 + dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2827 + buffer_size = dwarf2_per_objfile->info.size;
2828 + buffer = dwarf2_per_objfile->info.buffer;
2829 + info_ptr = buffer + this_cu->offset;
2830 + beg_of_comp_unit = info_ptr;
2832 + info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2833 + buffer, buffer_size,
2836 + /* Complete the cu_header. */
2837 + cu.header.offset = beg_of_comp_unit - buffer;
2838 + cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2840 + this_cu->cu = &cu;
2841 + cu.per_cu = this_cu;
2843 + dwarf2_read_abbrevs (abfd, &cu);
2844 + make_cleanup (dwarf2_free_abbrev_table, &cu);
2846 + if (this_cu->from_debug_types)
2847 + info_ptr += 8 /*signature*/ + cu.header.offset_size;
2848 + init_cu_die_reader (&reader_specs, &cu);
2849 + info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2852 + attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2855 + unsigned int line_offset = DW_UNSND (attr);
2856 + lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2860 + do_cleanups (cleanups);
2864 + find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2866 + this_cu->v.quick->lines = lh;
2868 + this_cu->v.quick->file_names
2869 + = obstack_alloc (&objfile->objfile_obstack,
2870 + lh->num_file_names * sizeof (char *));
2871 + for (i = 0; i < lh->num_file_names; ++i)
2872 + this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2874 + do_cleanups (cleanups);
2877 +/* A helper for the "quick" functions which computes and caches the
2878 + real path for a given file name from the line table.
2879 + dw2_require_line_header must have been called before this is
2881 +static const char *
2882 +dw2_require_full_path (struct objfile *objfile,
2883 + struct dwarf2_per_cu_data *cu,
2886 + if (!cu->v.quick->full_names)
2887 + cu->v.quick->full_names
2888 + = OBSTACK_CALLOC (&objfile->objfile_obstack,
2889 + cu->v.quick->lines->num_file_names,
2892 + if (!cu->v.quick->full_names[index])
2893 + cu->v.quick->full_names[index]
2894 + = gdb_realpath (cu->v.quick->file_names[index]);
2896 + return cu->v.quick->full_names[index];
2899 +static struct symtab *
2900 +dw2_find_last_source_symtab (struct objfile *objfile)
2903 + dw2_setup (objfile);
2904 + index = dwarf2_per_objfile->n_comp_units - 1;
2905 + return dw2_instantiate_symtab (objfile,
2906 + dwarf2_per_objfile->all_comp_units[index]);
2910 +dw2_forget_cached_source_info (struct objfile *objfile)
2914 + dw2_setup (objfile);
2915 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2917 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
2919 + if (cu->v.quick->full_names)
2923 + for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2924 + xfree ((void *) cu->v.quick->full_names[j]);
2930 +dw2_lookup_symtab (struct objfile *objfile, const char *name,
2931 + const char *full_path, const char *real_path,
2932 + struct symtab **result)
2935 + int check_basename = lbasename (name) == name;
2936 + struct dwarf2_per_cu_data *base_cu = NULL;
2938 + dw2_setup (objfile);
2939 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2942 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
2944 + if (cu->v.quick->symtab)
2947 + dw2_require_line_header (objfile, cu);
2948 + if (!cu->v.quick->lines)
2951 + for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
2953 + const char *this_name = cu->v.quick->file_names[j];
2955 + if (FILENAME_CMP (name, this_name) == 0)
2957 + *result = dw2_instantiate_symtab (objfile, cu);
2961 + if (check_basename && ! base_cu
2962 + && FILENAME_CMP (lbasename (this_name), name) == 0)
2965 + if (full_path != NULL)
2967 + const char *this_full_name = dw2_require_full_path (objfile,
2970 + if (this_full_name
2971 + && FILENAME_CMP (full_path, this_full_name) == 0)
2973 + *result = dw2_instantiate_symtab (objfile, cu);
2978 + if (real_path != NULL)
2980 + const char *this_full_name = dw2_require_full_path (objfile,
2983 + if (this_full_name != NULL)
2985 + char *rp = gdb_realpath (this_full_name);
2986 + if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
2989 + *result = dw2_instantiate_symtab (objfile, cu);
3000 + *result = dw2_instantiate_symtab (objfile, base_cu);
3007 +static struct symtab *
3008 +dw2_lookup_symbol (struct objfile *objfile, int block_index,
3009 + const char *name, domain_enum domain)
3011 + /* We do all the work in the pre_expand_symtabs_matching hook
3016 +/* A helper function that expands all symtabs that hold an object
3019 +dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
3021 + dw2_setup (objfile);
3023 + if (dwarf2_per_objfile->index_table)
3027 + if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3030 + offset_type i, len = MAYBE_SWAP (*vec);
3031 + for (i = 0; i < len; ++i)
3033 + offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
3034 + struct dwarf2_per_cu_data *cu;
3035 + cu = dwarf2_per_objfile->all_comp_units[cu_index];
3036 + dw2_instantiate_symtab (objfile, cu);
3043 +dw2_pre_expand_symtabs_matching (struct objfile *objfile,
3044 + int kind, const char *name,
3045 + domain_enum domain)
3047 + dw2_do_expand_symtabs_matching (objfile, name);
3051 +dw2_print_stats (struct objfile *objfile)
3055 + dw2_setup (objfile);
3057 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3059 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3061 + if (!cu->v.quick->symtab)
3064 + printf_filtered (_(" Number of unread CUs: %d\n"), count);
3068 +dw2_dump (struct objfile *objfile)
3070 + /* Nothing worth printing. */
3074 +dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
3075 + struct section_offsets *delta)
3077 + /* There's nothing to relocate here. */
3081 +dw2_expand_symtabs_for_function (struct objfile *objfile,
3082 + const char *func_name)
3084 + dw2_do_expand_symtabs_matching (objfile, func_name);
3088 +dw2_expand_all_symtabs (struct objfile *objfile)
3092 + dw2_setup (objfile);
3093 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3095 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3097 + dw2_instantiate_symtab (objfile, cu);
3102 +dw2_expand_symtabs_with_filename (struct objfile *objfile,
3103 + const char *filename)
3107 + dw2_setup (objfile);
3108 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3111 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3113 + if (cu->v.quick->symtab)
3116 + dw2_require_line_header (objfile, cu);
3117 + if (!cu->v.quick->lines)
3120 + for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
3122 + const char *this_name = cu->v.quick->file_names[j];
3123 + if (strcmp (this_name, filename) == 0)
3125 + dw2_instantiate_symtab (objfile, cu);
3132 +static const char *
3133 +dw2_find_symbol_file (struct objfile *objfile, const char *name)
3135 + struct dwarf2_per_cu_data *cu;
3138 + dw2_setup (objfile);
3140 + if (!dwarf2_per_objfile->index_table)
3143 + if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3147 + /* Note that this just looks at the very first one named NAME -- but
3148 + actually we are looking for a function. find_main_filename
3149 + should be rewritten so that it doesn't require a custom hook. It
3150 + could just use the ordinary symbol tables. */
3151 + /* vec[0] is the length, which must always be >0. */
3152 + cu = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[1])];
3154 + dw2_require_line_header (objfile, cu);
3155 + if (!cu->v.quick->lines)
3158 + return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1];
3162 +dw2_map_ada_symtabs (struct objfile *objfile,
3163 + int (*wild_match) (const char *, int, const char *),
3164 + int (*is_name_suffix) (const char *),
3165 + void (*callback) (struct objfile *,
3166 + struct symtab *, void *),
3167 + const char *name, int global,
3168 + domain_enum namespace, int wild,
3171 + /* For now, we don't support Ada, so this function can't be
3173 + internal_error (__FILE__, __LINE__,
3174 + _("map_ada_symtabs called via index method"));
3178 +dw2_expand_symtabs_matching (struct objfile *objfile,
3179 + int (*file_matcher) (const char *, void *),
3180 + int (*name_matcher) (const char *, void *),
3187 + dw2_setup (objfile);
3188 + if (!dwarf2_per_objfile->index_table)
3191 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3194 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3196 + cu->v.quick->mark = 0;
3197 + if (cu->v.quick->symtab)
3200 + dw2_require_line_header (objfile, cu);
3201 + if (!cu->v.quick->lines)
3204 + for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
3206 + if (file_matcher (cu->v.quick->file_names[j], data))
3208 + cu->v.quick->mark = 1;
3215 + iter < dwarf2_per_objfile->index_table->index_table_slots;
3218 + offset_type idx = 2 * iter;
3220 + offset_type *vec, vec_len, vec_idx;
3222 + if (dwarf2_per_objfile->index_table->index_table[idx] == 0
3223 + && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
3226 + name = (dwarf2_per_objfile->index_table->constant_pool
3227 + + dwarf2_per_objfile->index_table->index_table[idx]);
3229 + if (! (*name_matcher) (name, data))
3232 + /* The name was matched, now expand corresponding CUs that were
3234 + vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool
3235 + + dwarf2_per_objfile->index_table->index_table[idx + 1]);
3236 + vec_len = MAYBE_SWAP (vec[0]);
3237 + for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
3239 + struct dwarf2_per_cu_data *cu
3240 + = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[vec_idx + 1])];
3241 + if (cu->v.quick->mark)
3242 + dw2_instantiate_symtab (objfile, cu);
3247 +static struct symtab *
3248 +dw2_find_pc_sect_symtab (struct objfile *objfile,
3249 + struct minimal_symbol *msymbol,
3251 + struct obj_section *section,
3252 + int warn_if_readin)
3254 + struct dwarf2_per_cu_data *data;
3256 + dw2_setup (objfile);
3258 + if (!objfile->psymtabs_addrmap)
3261 + data = addrmap_find (objfile->psymtabs_addrmap, pc);
3265 + if (warn_if_readin && data->v.quick->symtab)
3266 + warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"),
3267 + paddress (get_objfile_arch (objfile), pc));
3269 + return dw2_instantiate_symtab (objfile, data);
3273 +dw2_map_symbol_names (struct objfile *objfile,
3274 + void (*fun) (const char *, void *),
3278 + dw2_setup (objfile);
3280 - if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
3281 + if (!dwarf2_per_objfile->index_table)
3285 + iter < dwarf2_per_objfile->index_table->index_table_slots;
3288 - off_t pg_offset = sectp->filepos & ~(pagesize - 1);
3289 - size_t map_length = info->size + sectp->filepos - pg_offset;
3290 - caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
3291 - MAP_PRIVATE, pg_offset);
3292 + offset_type idx = 2 * iter;
3294 + offset_type *vec, vec_len, vec_idx;
3296 - if (retbuf != MAP_FAILED)
3298 - info->was_mmapped = 1;
3299 - info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
3300 -#if HAVE_POSIX_MADVISE
3301 - posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
3305 + if (dwarf2_per_objfile->index_table->index_table[idx] == 0
3306 + && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
3309 + name = (dwarf2_per_objfile->index_table->constant_pool
3310 + + dwarf2_per_objfile->index_table->index_table[idx]);
3312 + (*fun) (name, data);
3317 - /* If we get here, we are a normal, not-compressed section. */
3318 - info->buffer = buf
3319 - = obstack_alloc (&objfile->objfile_obstack, info->size);
3321 +dw2_map_symbol_filenames (struct objfile *objfile,
3322 + void (*fun) (const char *, const char *, void *),
3327 - /* When debugging .o files, we may need to apply relocations; see
3328 - http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
3329 - We never compress sections in .o files, so we only need to
3330 - try this when the section is not compressed. */
3331 - retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
3332 - if (retbuf != NULL)
3333 + dw2_setup (objfile);
3334 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3336 - info->buffer = retbuf;
3339 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3341 + if (cu->v.quick->symtab)
3344 + dw2_require_line_header (objfile, cu);
3345 + if (!cu->v.quick->lines)
3348 + for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
3350 + const char *this_full_name = dw2_require_full_path (objfile, cu, j);
3351 + (*fun) (cu->v.quick->file_names[j], this_full_name, data);
3356 - if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
3357 - || bfd_bread (buf, info->size, abfd) != info->size)
3358 - error (_("Dwarf Error: Can't read DWARF data from '%s'"),
3359 - bfd_get_filename (abfd));
3361 +dw2_has_symbols (struct objfile *objfile)
3366 -/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
3368 +const struct quick_symbol_functions dwarf2_gdb_index_functions =
3371 + dw2_find_last_source_symtab,
3372 + dw2_forget_cached_source_info,
3373 + dw2_lookup_symtab,
3374 + dw2_lookup_symbol,
3375 + dw2_pre_expand_symtabs_matching,
3379 + dw2_expand_symtabs_for_function,
3380 + dw2_expand_all_symtabs,
3381 + dw2_expand_symtabs_with_filename,
3382 + dw2_find_symbol_file,
3383 + dw2_map_ada_symtabs,
3384 + dw2_expand_symtabs_matching,
3385 + dw2_find_pc_sect_symtab,
3386 + dw2_map_symbol_names,
3387 + dw2_map_symbol_filenames
3391 -dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
3392 - asection **sectp, gdb_byte **bufp,
3393 - bfd_size_type *sizep)
3395 - struct dwarf2_per_objfile *data
3396 - = objfile_data (objfile, dwarf2_objfile_data_key);
3397 - struct dwarf2_section_info *info;
3398 +/* Initialize for reading DWARF for this objfile. Return 0 if this
3399 + file will use psymtabs, or 1 if using the GNU index. */
3401 - /* We may see an objfile without any DWARF, in which case we just
3402 - return nothing. */
3405 +dwarf2_initialize_objfile (struct objfile *objfile)
3407 + /* If we're about to read full symbols, don't bother with the
3408 + indices. In this case we also don't care if some other debug
3409 + format is making psymtabs, because they are all about to be
3410 + expanded anyway. */
3411 + if ((objfile->flags & OBJF_READNOW))
3419 + dwarf2_per_objfile->using_index = 1;
3420 + create_all_comp_units (objfile);
3422 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3424 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
3426 + cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
3427 + struct dwarf2_per_cu_quick_data);
3430 + /* Return 1 so that gdb sees the "quick" functions. However,
3431 + these functions will be no-ops because we will have expanded
3435 - if (section_is_p (section_name, EH_FRAME_SECTION))
3436 - info = &data->eh_frame;
3437 - else if (section_is_p (section_name, FRAME_SECTION))
3438 - info = &data->frame;
3442 - if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
3443 - /* We haven't read this section in yet. Do it now. */
3444 - dwarf2_read_section (objfile, info);
3445 + if (dwarf2_read_index (objfile))
3448 - *sectp = info->asection;
3449 - *bufp = info->buffer;
3450 - *sizep = info->size;
3451 + dwarf2_build_psymtabs (objfile);
3457 /* Build a partial symbol table. */
3460 @@ -1699,6 +2688,7 @@ create_debug_types_hash_table (struct objfile *objfile)
3461 type_sig->signature = signature;
3462 type_sig->offset = offset;
3463 type_sig->type_offset = type_offset;
3464 + type_sig->per_cu.objfile = objfile;
3466 slot = htab_find_slot (types_htab, type_sig, INSERT);
3467 gdb_assert (slot != NULL);
3468 @@ -1897,7 +2887,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
3469 /* Store the function that reads in the rest of the symbol table */
3470 pst->read_symtab = dwarf2_psymtab_to_symtab;
3472 - this_cu->psymtab = pst;
3473 + this_cu->v.psymtab = pst;
3475 dwarf2_find_base_address (comp_unit_die, &cu);
3477 @@ -2182,6 +3172,7 @@ create_all_comp_units (struct objfile *objfile)
3478 memset (this_cu, 0, sizeof (*this_cu));
3479 this_cu->offset = offset;
3480 this_cu->length = length + initial_length_size;
3481 + this_cu->objfile = objfile;
3483 if (n_comp_units == n_allocated)
3485 @@ -2613,7 +3604,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
3486 addrmap_set_empty (objfile->psymtabs_addrmap,
3487 pdi->lowpc + baseaddr,
3488 pdi->highpc - 1 + baseaddr,
3489 - cu->per_cu->psymtab);
3490 + cu->per_cu->v.psymtab);
3492 if (!pdi->is_declaration)
3493 /* Ignore subprogram DIEs that do not have a name, they are
3494 @@ -2885,7 +3876,6 @@ locate_pdi_sibling (struct partial_die_info *orig_pdi,
3496 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
3498 - /* FIXME: This is barely more than a stub. */
3502 @@ -2958,7 +3948,9 @@ process_queue (struct objfile *objfile)
3503 may load a new CU, adding it to the end of the queue. */
3504 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
3506 - if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
3507 + if (dwarf2_per_objfile->using_index
3508 + ? !item->per_cu->v.quick->symtab
3509 + : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
3510 process_full_comp_unit (item->per_cu);
3512 item->per_cu->queued = 0;
3513 @@ -3035,22 +4027,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
3517 - back_to = make_cleanup (dwarf2_release_queue, NULL);
3519 - queue_comp_unit (per_cu, pst->objfile);
3521 - if (per_cu->from_debug_types)
3522 - read_signatured_type_at_offset (pst->objfile, per_cu->offset);
3524 - load_full_comp_unit (per_cu, pst->objfile);
3526 - process_queue (pst->objfile);
3528 - /* Age the cache, releasing compilation units that have not
3529 - been used recently. */
3530 - age_cached_comp_units ();
3532 - do_cleanups (back_to);
3533 + dw2_do_instantiate_symtab (pst->objfile, per_cu);
3536 /* Load the DIEs associated with PER_CU into memory. */
3537 @@ -3130,9 +4107,8 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
3539 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3541 - struct partial_symtab *pst = per_cu->psymtab;
3542 struct dwarf2_cu *cu = per_cu->cu;
3543 - struct objfile *objfile = pst->objfile;
3544 + struct objfile *objfile = per_cu->objfile;
3545 CORE_ADDR lowpc, highpc;
3546 struct symtab *symtab;
3547 struct cleanup *back_to;
3548 @@ -3165,8 +4141,15 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
3550 symtab->language = cu->language;
3552 - pst->symtab = symtab;
3555 + if (dwarf2_per_objfile->using_index)
3556 + per_cu->v.quick->symtab = symtab;
3559 + struct partial_symtab *pst = per_cu->v.psymtab;
3560 + pst->symtab = symtab;
3564 do_cleanups (back_to);
3566 @@ -3557,6 +4540,46 @@ free_cu_line_header (void *arg)
3570 +find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
3571 + char **name, char **comp_dir)
3573 + struct attribute *attr;
3578 + /* Find the filename. Do not use dwarf2_name here, since the filename
3579 + is not a source language identifier. */
3580 + attr = dwarf2_attr (die, DW_AT_name, cu);
3583 + *name = DW_STRING (attr);
3586 + attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3588 + *comp_dir = DW_STRING (attr);
3589 + else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
3591 + *comp_dir = ldirname (*name);
3592 + if (*comp_dir != NULL)
3593 + make_cleanup (xfree, *comp_dir);
3595 + if (*comp_dir != NULL)
3597 + /* Irix 6.2 native cc prepends <machine>.: to the compilation
3598 + directory, get rid of it. */
3599 + char *cp = strchr (*comp_dir, ':');
3601 + if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
3602 + *comp_dir = cp + 1;
3605 + if (*name == NULL)
3606 + *name = "<unknown>";
3610 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3612 struct objfile *objfile = cu->objfile;
3613 @@ -3582,35 +4605,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
3617 - /* Find the filename. Do not use dwarf2_name here, since the filename
3618 - is not a source language identifier. */
3619 - attr = dwarf2_attr (die, DW_AT_name, cu);
3622 - name = DW_STRING (attr);
3625 - attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
3627 - comp_dir = DW_STRING (attr);
3628 - else if (name != NULL && IS_ABSOLUTE_PATH (name))
3630 - comp_dir = ldirname (name);
3631 - if (comp_dir != NULL)
3632 - make_cleanup (xfree, comp_dir);
3634 - if (comp_dir != NULL)
3636 - /* Irix 6.2 native cc prepends <machine>.: to the compilation
3637 - directory, get rid of it. */
3638 - char *cp = strchr (comp_dir, ':');
3640 - if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
3641 - comp_dir = cp + 1;
3645 - name = "<unknown>";
3646 + find_file_and_directory (die, cu, &name, &comp_dir);
3648 attr = dwarf2_attr (die, DW_AT_language, cu);
3650 @@ -5529,6 +6524,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3651 new_symbol (die, this_type, cu);
3654 +/* Create a new array dimension referencing its target type TYPE.
3656 + Multidimensional arrays are internally represented as a stack of
3657 + singledimensional arrays being referenced by their TYPE_TARGET_TYPE. */
3659 +static struct type *
3660 +create_single_array_dimension (struct type *type, struct type *range_type,
3661 + struct die_info *die, struct dwarf2_cu *cu)
3663 + type = create_array_type (NULL, type, range_type);
3665 + /* These generic type attributes need to be fetched by
3666 + evaluate_subexp_standard <multi_f77_subscript>'s call of
3667 + value_subscripted_rvalue only for the innermost array type. */
3668 + fetch_die_type_attrs (die, type, cu);
3670 + /* These generic type attributes are checked for allocated/associated
3671 + validity while accessing FIELD_LOC_KIND_DWARF_BLOCK. */
3672 + fetch_die_type_attrs (die, range_type, cu);
3677 /* Extract all information from a DW_TAG_array_type DIE and put it in
3678 the DIE's type field. For now, this only handles one dimensional
3680 @@ -5542,7 +6560,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3681 struct type *element_type, *range_type, *index_type;
3682 struct type **range_types = NULL;
3683 struct attribute *attr;
3686 struct cleanup *back_to;
3689 @@ -5595,17 +6613,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3690 type = element_type;
3692 if (read_array_order (die, cu) == DW_ORD_col_major)
3697 - type = create_array_type (NULL, type, range_types[i++]);
3701 - while (ndim-- > 0)
3702 - type = create_array_type (NULL, type, range_types[ndim]);
3704 + for (i = 0; i < ndim; i++)
3705 + type = create_single_array_dimension (type, range_types[i], die, cu);
3706 + else /* (read_array_order (die, cu) == DW_ORD_row_major) */
3707 + for (i = ndim - 1; i >= 0; i--)
3708 + type = create_single_array_dimension (type, range_types[i], die, cu);
3710 /* Understand Dwarf2 support for vector types (like they occur on
3711 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3712 @@ -6059,29 +7071,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3713 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3714 struct type *type, *range_type, *index_type, *char_type;
3715 struct attribute *attr;
3716 - unsigned int length;
3719 + index_type = objfile_type (objfile)->builtin_int;
3720 + /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type. */
3721 + range_type = alloc_type (objfile);
3722 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
3723 + range_type = create_range_type (range_type, index_type, 0, -1);
3725 + /* C/C++ should probably have the low bound 0 but C/C++ does not use
3726 + DW_TAG_string_type. */
3727 + TYPE_LOW_BOUND (range_type) = 1;
3729 attr = dwarf2_attr (die, DW_AT_string_length, cu);
3732 - length = DW_UNSND (attr);
3733 + if (attr && attr_form_is_block (attr))
3735 + /* Security check for a size overflow. */
3736 + if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
3737 + TYPE_HIGH_BOUND (range_type) = 1;
3738 + /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
3739 + instruction as DW_AT_string_length specifies the length location, not
3743 + struct dwarf2_locexpr_baton *length_baton = NULL;
3744 + struct dwarf_block *blk = DW_BLOCK (attr);
3746 + /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
3747 + DW_OP_deref* in such case. */
3749 + if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
3750 + && blk->data[0] <= DW_OP_reg31)
3751 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
3752 + else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
3754 + ULONGEST ulongest;
3755 + const gdb_byte *end;
3757 + end = read_uleb128 (&blk->data[1], &blk->data[blk->size],
3759 + if (end == &blk->data[blk->size])
3760 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
3763 + if (length_baton == NULL)
3765 + struct attribute *size_attr;
3768 + length_baton = obstack_alloc (&cu->comp_unit_obstack,
3769 + sizeof (*length_baton));
3770 + length_baton->per_cu = cu->per_cu;
3771 + length_baton->size = DW_BLOCK (attr)->size + 2;
3772 + data = obstack_alloc (&cu->comp_unit_obstack,
3773 + length_baton->size);
3774 + length_baton->data = data;
3775 + memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
3777 + /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
3778 + specifies the size of an integer to fetch. */
3779 + size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3782 + data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
3783 + data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr);
3784 + if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr))
3785 + complaint (&symfile_complaints,
3786 + _("DW_AT_string_length's DW_AT_byte_size "
3787 + "integer exceeds the byte size storage"));
3791 + data[DW_BLOCK (attr)->size] = DW_OP_deref;
3792 + data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
3796 + TYPE_RANGE_DATA (range_type)->high.kind
3797 + = RANGE_BOUND_KIND_DWARF_BLOCK;
3798 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton;
3799 + TYPE_DYNAMIC (range_type) = 1;
3804 - /* check for the DW_AT_byte_size attribute */
3805 + if (attr && attr_form_is_constant (attr))
3807 + /* We currently do not support a constant address where the location
3808 + should be read from - attr_form_is_block is expected instead. See
3809 + DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
3814 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3817 - length = DW_UNSND (attr);
3819 + if (attr && attr_form_is_block (attr))
3821 + TYPE_RANGE_DATA (range_type)->high.kind
3822 + = RANGE_BOUND_KIND_DWARF_BLOCK;
3823 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
3824 + dwarf2_attr_to_locexpr_baton (attr, cu);
3825 + TYPE_DYNAMIC (range_type) = 1;
3827 + else if (attr && attr_form_is_constant (attr))
3828 + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
3833 + TYPE_HIGH_BOUND (range_type) = 1;
3836 - index_type = objfile_type (objfile)->builtin_int;
3837 - range_type = create_range_type (NULL, index_type, 1, length);
3838 char_type = language_string_char_type (cu->language_defn, gdbarch);
3839 type = create_string_type (NULL, char_type, range_type);
3841 @@ -6324,60 +7421,136 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
3842 struct type *base_type;
3843 struct type *range_type;
3844 struct attribute *attr;
3846 - LONGEST high = -1;
3849 LONGEST negative_mask;
3851 base_type = die_type (die, cu);
3852 + /* Preserve BASE_TYPE's original type, just set its LENGTH. */
3853 + check_typedef (base_type);
3855 /* The die_type call above may have already set the type for this DIE. */
3856 range_type = get_die_type (die, cu);
3860 - if (cu->language == language_fortran)
3862 - /* FORTRAN implies a lower bound of 1, if not given. */
3865 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
3866 + range_type = create_range_type (NULL, base_type, 0, -1);
3869 + (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
3871 + /* Exclude language_ada from any TYPE_DYNAMIC constructs below. GDB Ada
3872 + supports implements the dynamic bounds in a non-DWARF way and the
3873 + existing DWARF dynamic bounds are invalid, leading to memory access
3876 - /* FIXME: For variable sized arrays either of these could be
3877 - a variable rather than a constant value. We'll allow it,
3878 - but we don't know how to handle it. */
3879 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
3881 - low = dwarf2_get_attr_constant_value (attr, 0);
3882 + if (attr && attr_form_is_block (attr) && cu->language != language_ada)
3884 + TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
3885 + TYPE_RANGE_DATA (range_type)->low.u.dwarf_block =
3886 + dwarf2_attr_to_locexpr_baton (attr, cu);
3887 + TYPE_DYNAMIC (range_type) = 1;
3888 + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */
3891 + else if (attr && is_ref_attr (attr) && cu->language != language_ada)
3893 + struct die_info *target_die;
3894 + struct dwarf2_cu *target_cu = cu;
3895 + struct attribute *target_loc_attr;
3897 + target_die = follow_die_ref_or_sig (die, attr, &target_cu);
3898 + gdb_assert (target_cu->objfile == cu->objfile);
3899 + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
3901 + TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
3902 + TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist
3903 + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
3904 + TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type
3905 + = die_type (target_die, target_cu);
3906 + TYPE_DYNAMIC (range_type) = 1;
3907 + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */
3912 + if (attr && attr_form_is_constant (attr))
3913 + low = dwarf2_get_attr_constant_value (attr, 0);
3916 + if (cu->language == language_fortran)
3918 + /* FORTRAN implies a lower bound of 1, if not given. */
3923 + /* According to DWARF we should assume the value 0 only for
3924 + LANGUAGE_C and LANGUAGE_CPLUS. */
3928 + if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
3929 + low |= negative_mask;
3930 + TYPE_LOW_BOUND (range_type) = low;
3932 + TYPE_UNSIGNED (range_type) = 1;
3935 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
3937 + if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
3938 + && !is_ref_attr (attr)))
3940 - if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
3942 - /* GCC encodes arrays with unspecified or dynamic length
3943 - with a DW_FORM_block1 attribute or a reference attribute.
3944 - FIXME: GDB does not yet know how to handle dynamic
3945 - arrays properly, treat them as arrays with unspecified
3948 - FIXME: jimb/2003-09-22: GDB does not really know
3949 - how to handle arrays of unspecified length
3950 - either; we just represent them as zero-length
3951 - arrays. Choose an appropriate upper bound given
3952 - the lower bound we've computed above. */
3956 - high = dwarf2_get_attr_constant_value (attr, 1);
3957 + attr = dwarf2_attr (die, DW_AT_count, cu);
3958 + /* It does not hurt but it is needlessly ineffective in check_typedef. */
3959 + if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
3961 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
3962 + TYPE_DYNAMIC (range_type) = 1;
3964 + /* Pass it now as the regular DW_AT_upper_bound. */
3967 + if (attr && attr_form_is_block (attr) && cu->language != language_ada)
3969 + TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
3970 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
3971 + dwarf2_attr_to_locexpr_baton (attr, cu);
3972 + TYPE_DYNAMIC (range_type) = 1;
3974 + else if (attr && is_ref_attr (attr) && cu->language != language_ada)
3976 + struct die_info *target_die;
3977 + struct dwarf2_cu *target_cu = cu;
3978 + struct attribute *target_loc_attr;
3980 + target_die = follow_die_ref_or_sig (die, attr, &target_cu);
3981 + gdb_assert (target_cu->objfile == cu->objfile);
3982 + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
3984 + TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
3985 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist
3986 + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
3987 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type
3988 + = die_type (target_die, target_cu);
3989 + TYPE_DYNAMIC (range_type) = 1;
3993 - attr = dwarf2_attr (die, DW_AT_count, cu);
3997 + if (attr && attr_form_is_constant (attr))
3998 + high = dwarf2_get_attr_constant_value (attr, 0);
4001 - int count = dwarf2_get_attr_constant_value (attr, 1);
4002 - high = low + count - 1;
4003 + TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
4006 + if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
4007 + high |= negative_mask;
4008 + TYPE_HIGH_BOUND (range_type) = high;
4011 /* Dwarf-2 specifications explicitly allows to create subrange types
4012 @@ -6419,20 +7592,41 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4017 - (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
4018 - if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
4019 - low |= negative_mask;
4020 - if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
4021 - high |= negative_mask;
4022 + /* DW_AT_bit_stride is currently unsupported as we count in bytes. */
4023 + attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
4024 + if (attr && attr_form_is_block (attr) && cu->language != language_ada)
4026 + TYPE_RANGE_DATA (range_type)->byte_stride.kind
4027 + = RANGE_BOUND_KIND_DWARF_BLOCK;
4028 + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block =
4029 + dwarf2_attr_to_locexpr_baton (attr, cu);
4030 + TYPE_DYNAMIC (range_type) = 1;
4032 + else if (attr && is_ref_attr (attr) && cu->language != language_ada)
4034 + struct die_info *target_die;
4035 + struct dwarf2_cu *target_cu = cu;
4036 + struct attribute *target_loc_attr;
4038 - range_type = create_range_type (NULL, base_type, low, high);
4039 + target_die = follow_die_ref_or_sig (die, attr, &target_cu);
4040 + gdb_assert (target_cu->objfile == cu->objfile);
4041 + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
4043 - /* Mark arrays with dynamic length at least as an array of unspecified
4044 - length. GDB could check the boundary but before it gets implemented at
4045 - least allow accessing the array elements. */
4046 - if (attr && attr->form == DW_FORM_block1)
4047 - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
4048 + TYPE_RANGE_DATA (range_type)->byte_stride.kind
4049 + = RANGE_BOUND_KIND_DWARF_LOCLIST;
4050 + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist
4051 + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
4052 + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type
4053 + = die_type (target_die, target_cu);
4054 + TYPE_DYNAMIC (range_type) = 1;
4056 + else if (attr && attr_form_is_constant (attr))
4058 + TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
4059 + if (TYPE_BYTE_STRIDE (range_type) == 0)
4060 + complaint (&symfile_complaints,
4061 + _("Found DW_AT_byte_stride with unsupported value 0"));
4064 name = dwarf2_name (die, cu);
4066 @@ -8712,10 +9906,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
4067 (i.e. when the value of a register or memory location is
4068 referenced, or a thread-local block, etc.). Then again, it might
4069 not be worthwhile. I'm assuming that it isn't unless performance
4070 - or memory numbers show me otherwise. */
4071 + or memory numbers show me otherwise.
4073 + SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed. */
4075 - dwarf2_symbol_mark_computed (attr, sym, cu);
4076 SYMBOL_CLASS (sym) = LOC_COMPUTED;
4077 + dwarf2_symbol_mark_computed (attr, sym, cu);
4080 /* Given a pointer to a DWARF information entry, figure out if we need
4081 @@ -8746,6 +9942,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
4082 sizeof (struct symbol));
4083 OBJSTAT (objfile, n_syms++);
4084 memset (sym, 0, sizeof (struct symbol));
4085 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
4086 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
4088 /* Cache this symbol's name and the name's demangled form (if any). */
4089 SYMBOL_LANGUAGE (sym) = cu->language;
4090 @@ -9375,6 +10573,9 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
4095 + finalize_type (this_type);
4100 @@ -11979,67 +13180,102 @@ attr_form_is_constant (struct attribute *attr)
4105 -dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
4106 - struct dwarf2_cu *cu)
4107 +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton. ATTR must be a DW_BLOCK
4108 + attribute type. */
4110 +static struct dwarf2_locexpr_baton *
4111 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
4113 - if (attr_form_is_section_offset (attr)
4114 - /* ".debug_loc" may not exist at all, or the offset may be outside
4115 - the section. If so, fall through to the complaint in the
4117 - && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
4119 - struct dwarf2_loclist_baton *baton;
4120 + struct dwarf2_locexpr_baton *baton;
4122 - baton = obstack_alloc (&cu->objfile->objfile_obstack,
4123 - sizeof (struct dwarf2_loclist_baton));
4124 - baton->per_cu = cu->per_cu;
4125 - gdb_assert (baton->per_cu);
4126 + gdb_assert (attr_form_is_block (attr));
4128 - dwarf2_read_section (dwarf2_per_objfile->objfile,
4129 - &dwarf2_per_objfile->loc);
4130 + baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton));
4131 + baton->per_cu = cu->per_cu;
4132 + gdb_assert (baton->per_cu);
4134 - /* We don't know how long the location list is, but make sure we
4135 - don't run off the edge of the section. */
4136 - baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
4137 - baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
4138 - baton->base_address = cu->base_address;
4139 - if (cu->base_known == 0)
4140 - complaint (&symfile_complaints,
4141 - _("Location list used without specifying the CU base address."));
4142 + /* Note that we're just copying the block's data pointer
4143 + here, not the actual data. We're still pointing into the
4144 + info_buffer for SYM's objfile; right now we never release
4145 + that buffer, but when we do clean up properly this may
4146 + need to change. */
4147 + baton->size = DW_BLOCK (attr)->size;
4148 + baton->data = DW_BLOCK (attr)->data;
4149 + gdb_assert (baton->size == 0 || baton->data != NULL);
4154 +static struct dwarf2_loclist_baton *
4155 +dwarf2_attr_to_loclist_baton (struct attribute *attr, struct dwarf2_cu *cu)
4157 + struct dwarf2_loclist_baton *baton;
4159 + /* DW_AT_location of the referenced DIE may be missing if the referenced
4160 + variable has been optimized out. */
4164 + dwarf2_read_section (dwarf2_per_objfile->objfile,
4165 + &dwarf2_per_objfile->loc);
4167 + if (!(attr_form_is_section_offset (attr)
4168 + /* ".debug_loc" may not exist at all, or the offset may be outside
4169 + the section. If so, fall through to the complaint in the
4171 + && DW_UNSND (attr) < dwarf2_per_objfile->loc.size))
4174 + baton = obstack_alloc (&cu->objfile->objfile_obstack,
4175 + sizeof (struct dwarf2_loclist_baton));
4176 + baton->per_cu = cu->per_cu;
4177 + gdb_assert (baton->per_cu);
4179 + /* We don't know how long the location list is, but make sure we
4180 + don't run off the edge of the section. */
4181 + baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
4182 + baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
4183 + baton->base_address = cu->base_address;
4184 + if (cu->base_known == 0)
4185 + complaint (&symfile_complaints,
4186 + _("Location list used without specifying the CU base address."));
4191 +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content. */
4194 +dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
4195 + struct dwarf2_cu *cu)
4197 + struct dwarf2_loclist_baton *loclist_baton;
4199 + loclist_baton = dwarf2_attr_to_loclist_baton (attr, cu);
4200 + if (loclist_baton)
4202 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
4203 - SYMBOL_LOCATION_BATON (sym) = baton;
4204 + SYMBOL_LOCATION_BATON (sym) = loclist_baton;
4206 + else if (attr_form_is_block (attr))
4208 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
4209 + SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
4213 - struct dwarf2_locexpr_baton *baton;
4214 + dwarf2_invalid_attrib_class_complaint ("location description",
4215 + SYMBOL_NATURAL_NAME (sym));
4217 - baton = obstack_alloc (&cu->objfile->objfile_obstack,
4218 - sizeof (struct dwarf2_locexpr_baton));
4219 - baton->per_cu = cu->per_cu;
4220 - gdb_assert (baton->per_cu);
4221 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
4223 - if (attr_form_is_block (attr))
4225 - /* Note that we're just copying the block's data pointer
4226 - here, not the actual data. We're still pointing into the
4227 - info_buffer for SYM's objfile; right now we never release
4228 - that buffer, but when we do clean up properly this may
4229 - need to change. */
4230 - baton->size = DW_BLOCK (attr)->size;
4231 - baton->data = DW_BLOCK (attr)->data;
4235 - dwarf2_invalid_attrib_class_complaint ("location description",
4236 - SYMBOL_NATURAL_NAME (sym));
4238 - baton->data = NULL;
4240 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
4241 + SYMBOL_LOCATION_BATON (sym) = NULL;
4243 - SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
4244 - SYMBOL_LOCATION_BATON (sym) = baton;
4245 + /* For functions a missing DW_AT_frame_base does not optimize out the
4246 + whole function definition, only its frame base resolving. */
4247 + if (attr->name == DW_AT_location)
4248 + SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
4252 @@ -12050,7 +13286,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
4254 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
4256 - struct objfile *objfile = per_cu->psymtab->objfile;
4257 + struct objfile *objfile = per_cu->objfile;
4259 /* Return the master objfile, so that we can report and look up the
4260 correct file containing this variable. */
4261 @@ -12070,7 +13306,7 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
4264 /* If the CU is not currently read in, we re-read its header. */
4265 - struct objfile *objfile = per_cu->psymtab->objfile;
4266 + struct objfile *objfile = per_cu->objfile;
4267 struct dwarf2_per_objfile *per_objfile
4268 = objfile_data (objfile, dwarf2_objfile_data_key);
4269 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
4270 @@ -12092,7 +13328,7 @@ dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
4273 /* If the CU is not currently read in, we re-read its header. */
4274 - struct objfile *objfile = per_cu->psymtab->objfile;
4275 + struct objfile *objfile = per_cu->objfile;
4276 struct dwarf2_per_objfile *per_objfile
4277 = objfile_data (objfile, dwarf2_objfile_data_key);
4278 gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
4279 @@ -12112,7 +13348,7 @@ dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
4281 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
4283 - struct objfile *objfile = per_cu->psymtab->objfile;
4284 + struct objfile *objfile = per_cu->objfile;
4286 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4288 @@ -12334,6 +13570,30 @@ dwarf2_free_objfile (struct objfile *objfile)
4289 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
4290 free_cached_comp_units (NULL);
4292 + if (dwarf2_per_objfile->using_index)
4296 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
4299 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
4301 + if (!cu->v.quick->lines)
4304 + for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
4306 + if (cu->v.quick->file_names)
4307 + xfree ((void *) cu->v.quick->file_names[j]);
4308 + if (cu->v.quick->full_names)
4309 + xfree ((void *) cu->v.quick->full_names[j]);
4312 + free_line_header (cu->v.quick->lines);
4316 /* Everything else should be on the objfile obstack. */
4319 @@ -12368,6 +13628,31 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
4320 return ofs_lhs->offset == ofs_rhs->offset;
4323 +/* Fill in generic attributes applicable for type DIEs. */
4326 +fetch_die_type_attrs (struct die_info *die, struct type *type,
4327 + struct dwarf2_cu *cu)
4329 + struct attribute *attr;
4331 + attr = dwarf2_attr (die, DW_AT_data_location, cu);
4332 + if (attr_form_is_block (attr))
4333 + TYPE_DATA_LOCATION_DWARF_BLOCK (type) = dwarf2_attr_to_locexpr_baton (attr,
4335 + gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
4337 + attr = dwarf2_attr (die, DW_AT_allocated, cu);
4338 + if (attr_form_is_block (attr))
4339 + TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
4340 + gdb_assert (!TYPE_NOT_ALLOCATED (type));
4342 + attr = dwarf2_attr (die, DW_AT_associated, cu);
4343 + if (attr_form_is_block (attr))
4344 + TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
4345 + gdb_assert (!TYPE_NOT_ASSOCIATED (type));
4348 /* Set the type associated with DIE to TYPE. Save it in CU's hash
4349 table if necessary. For convenience, return TYPE.
4351 @@ -12391,6 +13676,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
4353 struct dwarf2_offset_and_type **slot, ofs;
4355 + fetch_die_type_attrs (die, type, cu);
4357 /* For Ada types, make sure that the gnat-specific data is always
4358 initialized (if not already set). There are a few types where
4359 we should not be doing so, because the type-specific area is
4360 @@ -12591,8 +13878,567 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
4361 munmap_section_buffer (&data->types);
4362 munmap_section_buffer (&data->frame);
4363 munmap_section_buffer (&data->eh_frame);
4364 + munmap_section_buffer (&data->gdb_index);
4369 +/* The contents of the hash table we create when building the string
4371 +struct strtab_entry
4373 + offset_type offset;
4377 +/* Hash function for a strtab_entry. */
4379 +hash_strtab_entry (const void *e)
4381 + const struct strtab_entry *entry = e;
4382 + return mapped_index_string_hash (entry->str);
4385 +/* Equality function for a strtab_entry. */
4387 +eq_strtab_entry (const void *a, const void *b)
4389 + const struct strtab_entry *ea = a;
4390 + const struct strtab_entry *eb = b;
4391 + return !strcmp (ea->str, eb->str);
4394 +/* Create a strtab_entry hash table. */
4396 +create_strtab (void)
4398 + return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
4399 + xfree, xcalloc, xfree);
4402 +/* Add a string to the constant pool. Return the string's offset in
4405 +add_string (htab_t table, struct obstack *cpool, const char *str)
4408 + struct strtab_entry entry;
4409 + struct strtab_entry *result;
4412 + slot = htab_find_slot (table, &entry, INSERT);
4417 + result = XNEW (struct strtab_entry);
4418 + result->offset = obstack_object_size (cpool);
4419 + result->str = str;
4420 + obstack_grow_str0 (cpool, str);
4423 + return result->offset;
4426 +/* An entry in the symbol table. */
4427 +struct symtab_index_entry
4429 + /* The name of the symbol. */
4431 + /* The offset of the name in the constant pool. */
4432 + offset_type index_offset;
4433 + /* A sorted vector of the indices of all the CUs that hold an object
4435 + VEC (offset_type) *cu_indices;
4438 +/* The symbol table. This is a power-of-2-sized hash table. */
4439 +struct mapped_symtab
4441 + offset_type n_elements;
4443 + struct symtab_index_entry **data;
4446 +/* Hash function for a symtab_index_entry. */
4448 +hash_symtab_entry (const void *e)
4450 + const struct symtab_index_entry *entry = e;
4451 + return iterative_hash (VEC_address (offset_type, entry->cu_indices),
4452 + sizeof (offset_type) * VEC_length (offset_type,
4453 + entry->cu_indices),
4457 +/* Equality function for a symtab_index_entry. */
4459 +eq_symtab_entry (const void *a, const void *b)
4461 + const struct symtab_index_entry *ea = a;
4462 + const struct symtab_index_entry *eb = b;
4463 + int len = VEC_length (offset_type, ea->cu_indices);
4464 + if (len != VEC_length (offset_type, eb->cu_indices))
4466 + return !memcmp (VEC_address (offset_type, ea->cu_indices),
4467 + VEC_address (offset_type, eb->cu_indices),
4468 + sizeof (offset_type) * len);
4471 +/* Destroy a symtab_index_entry. */
4473 +delete_symtab_entry (void *p)
4475 + struct symtab_index_entry *entry = p;
4476 + VEC_free (offset_type, entry->cu_indices);
4480 +/* Create a hash table holding symtab_index_entry objects. */
4482 +create_index_table (void)
4484 + return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
4485 + delete_symtab_entry, xcalloc, xfree);
4488 +/* Create a new mapped symtab object. */
4489 +static struct mapped_symtab *
4490 +create_mapped_symtab (void)
4492 + struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
4493 + symtab->n_elements = 0;
4494 + symtab->size = 1024;
4495 + symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
4499 +/* Destroy a mapped_symtab. */
4501 +cleanup_mapped_symtab (void *p)
4503 + struct mapped_symtab *symtab = p;
4504 + /* The contents of the array are freed when the other hash table is
4506 + xfree (symtab->data);
4510 +/* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
4512 +static struct symtab_index_entry **
4513 +find_slot (struct mapped_symtab *symtab, const char *name)
4515 + offset_type index, step, hash = mapped_index_string_hash (name);
4517 + index = hash & (symtab->size - 1);
4518 + step = ((hash * 17) & (symtab->size - 1)) | 1;
4522 + if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
4523 + return &symtab->data[index];
4524 + index = (index + step) & (symtab->size - 1);
4528 +/* Expand SYMTAB's hash table. */
4530 +hash_expand (struct mapped_symtab *symtab)
4532 + offset_type old_size = symtab->size;
4534 + struct symtab_index_entry **old_entries = symtab->data;
4536 + symtab->size *= 2;
4537 + symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
4539 + for (i = 0; i < old_size; ++i)
4541 + if (old_entries[i])
4543 + struct symtab_index_entry **slot = find_slot (symtab,
4544 + old_entries[i]->name);
4545 + *slot = old_entries[i];
4549 + xfree (old_entries);
4552 +/* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
4553 + is the index of the CU in which the symbol appears. */
4555 +add_index_entry (struct mapped_symtab *symtab, const char *name,
4556 + offset_type cu_index)
4558 + struct symtab_index_entry **slot;
4560 + ++symtab->n_elements;
4561 + if (4 * symtab->n_elements / 3 >= symtab->size)
4562 + hash_expand (symtab);
4564 + slot = find_slot (symtab, name);
4567 + *slot = XNEW (struct symtab_index_entry);
4568 + (*slot)->name = name;
4569 + (*slot)->cu_indices = NULL;
4571 + /* Don't push an index twice. Due to how we add entries we only
4572 + have to check the last one. */
4573 + if (VEC_empty (offset_type, (*slot)->cu_indices)
4574 + || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
4575 + VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
4578 +/* Add a vector of indices to the constant pool. */
4580 +add_indices_to_cpool (htab_t index_table, struct obstack *cpool,
4581 + struct symtab_index_entry *entry)
4585 + slot = htab_find_slot (index_table, entry, INSERT);
4588 + offset_type len = VEC_length (offset_type, entry->cu_indices);
4589 + offset_type val = MAYBE_SWAP (len);
4594 + entry->index_offset = obstack_object_size (cpool);
4596 + obstack_grow (cpool, &val, sizeof (val));
4598 + VEC_iterate (offset_type, entry->cu_indices, i, iter);
4601 + val = MAYBE_SWAP (iter);
4602 + obstack_grow (cpool, &val, sizeof (val));
4607 + struct symtab_index_entry *old_entry = *slot;
4608 + entry->index_offset = old_entry->index_offset;
4609 + entry = old_entry;
4611 + return entry->index_offset;
4614 +/* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
4615 + constant pool entries going into the obstack CPOOL. */
4617 +write_hash_table (struct mapped_symtab *symtab,
4618 + struct obstack *output, struct obstack *cpool)
4621 + htab_t index_table;
4624 + index_table = create_index_table ();
4625 + str_table = create_strtab ();
4626 + /* We add all the index vectors to the constant pool first, to
4627 + ensure alignment is ok. */
4628 + for (i = 0; i < symtab->size; ++i)
4630 + if (symtab->data[i])
4631 + add_indices_to_cpool (index_table, cpool, symtab->data[i]);
4634 + /* Now write out the hash table. */
4635 + for (i = 0; i < symtab->size; ++i)
4637 + offset_type str_off, vec_off;
4639 + if (symtab->data[i])
4641 + str_off = add_string (str_table, cpool, symtab->data[i]->name);
4642 + vec_off = symtab->data[i]->index_offset;
4646 + /* While 0 is a valid constant pool index, it is not valid
4647 + to have 0 for both offsets. */
4652 + str_off = MAYBE_SWAP (str_off);
4653 + vec_off = MAYBE_SWAP (vec_off);
4655 + obstack_grow (output, &str_off, sizeof (str_off));
4656 + obstack_grow (output, &vec_off, sizeof (vec_off));
4659 + htab_delete (str_table);
4660 + htab_delete (index_table);
4663 +/* Write an address entry to ADDR_OBSTACK. The addresses are taken
4664 + from PST; CU_INDEX is the index of the CU in the vector of all
4667 +add_address_entry (struct objfile *objfile,
4668 + struct obstack *addr_obstack, struct partial_symtab *pst,
4669 + unsigned int cu_index)
4671 + offset_type offset;
4673 + CORE_ADDR baseaddr;
4675 + baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4677 + store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr);
4678 + obstack_grow (addr_obstack, addr, 8);
4679 + store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr);
4680 + obstack_grow (addr_obstack, addr, 8);
4681 + offset = MAYBE_SWAP (cu_index);
4682 + obstack_grow (addr_obstack, &offset, sizeof (offset_type));
4685 +/* Add a list of partial symbols to SYMTAB. */
4687 +write_psymbols (struct mapped_symtab *symtab,
4688 + struct partial_symbol **psymp,
4690 + offset_type cu_index)
4692 + for (; count-- > 0; ++psymp)
4694 + if (SYMBOL_LANGUAGE (*psymp) == language_ada)
4695 + error (_("Ada is not currently supported by the index"));
4696 + add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
4700 +/* Write the contents of an ("unfinished") obstack to FILE. Throw an
4701 + exception if there is an error. */
4703 +write_obstack (FILE *file, struct obstack *obstack)
4705 + if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
4707 + != obstack_object_size (obstack))
4708 + error (_("couldn't data write to file"));
4711 +/* Unlink a file if the argument is not NULL. */
4713 +unlink_if_set (void *p)
4715 + char **filename = p;
4717 + unlink (*filename);
4720 +/* Create an index file for OBJFILE in the directory DIR. */
4722 +write_psymtabs_to_index (struct objfile *objfile, const char *dir)
4724 + struct cleanup *cleanup;
4725 + char *filename, *cleanup_filename;
4726 + struct obstack contents, addr_obstack, constant_pool, symtab_obstack, cu_list;
4729 + struct mapped_symtab *symtab;
4730 + offset_type val, size_of_contents, total_len;
4734 + if (!objfile->psymtabs)
4736 + if (dwarf2_per_objfile->using_index)
4737 + error (_("Cannot use an index to create the index"));
4739 + if (stat (objfile->name, &st) < 0)
4740 + perror_with_name (_("Could not stat"));
4742 + filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
4743 + INDEX_SUFFIX, (char *) NULL);
4744 + cleanup = make_cleanup (xfree, filename);
4746 + out_file = fopen (filename, "wb");
4748 + error (_("Can't open `%s' for writing"), filename);
4750 + cleanup_filename = filename;
4751 + make_cleanup (unlink_if_set, &cleanup_filename);
4753 + symtab = create_mapped_symtab ();
4754 + make_cleanup (cleanup_mapped_symtab, symtab);
4756 + obstack_init (&addr_obstack);
4757 + make_cleanup_obstack_free (&addr_obstack);
4759 + obstack_init (&cu_list);
4760 + make_cleanup_obstack_free (&cu_list);
4762 + for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
4764 + struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
4765 + struct partial_symtab *psymtab = cu->v.psymtab;
4768 + write_psymbols (symtab,
4769 + objfile->global_psymbols.list + psymtab->globals_offset,
4770 + psymtab->n_global_syms, i);
4771 + write_psymbols (symtab,
4772 + objfile->static_psymbols.list + psymtab->statics_offset,
4773 + psymtab->n_static_syms, i);
4775 + add_address_entry (objfile, &addr_obstack, psymtab, i);
4777 + store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset);
4778 + obstack_grow (&cu_list, val, 8);
4779 + store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length);
4780 + obstack_grow (&cu_list, val, 8);
4783 + obstack_init (&constant_pool);
4784 + make_cleanup_obstack_free (&constant_pool);
4785 + obstack_init (&symtab_obstack);
4786 + make_cleanup_obstack_free (&symtab_obstack);
4787 + write_hash_table (symtab, &symtab_obstack, &constant_pool);
4789 + obstack_init (&contents);
4790 + make_cleanup_obstack_free (&contents);
4791 + size_of_contents = 5 * sizeof (offset_type);
4792 + total_len = size_of_contents;
4794 + /* The version number. */
4795 + val = MAYBE_SWAP (1);
4796 + obstack_grow (&contents, &val, sizeof (val));
4798 + /* The offset of the CU list from the start of the file. */
4799 + val = MAYBE_SWAP (total_len);
4800 + obstack_grow (&contents, &val, sizeof (val));
4801 + total_len += obstack_object_size (&cu_list);
4803 + /* The offset of the address table from the start of the file. */
4804 + val = MAYBE_SWAP (total_len);
4805 + obstack_grow (&contents, &val, sizeof (val));
4806 + total_len += obstack_object_size (&addr_obstack);
4808 + /* The offset of the symbol table from the start of the file. */
4809 + val = MAYBE_SWAP (total_len);
4810 + obstack_grow (&contents, &val, sizeof (val));
4811 + total_len += obstack_object_size (&symtab_obstack);
4813 + /* The offset of the constant pool from the start of the file. */
4814 + val = MAYBE_SWAP (total_len);
4815 + obstack_grow (&contents, &val, sizeof (val));
4816 + total_len += obstack_object_size (&constant_pool);
4818 + gdb_assert (obstack_object_size (&contents) == size_of_contents);
4820 + write_obstack (out_file, &contents);
4821 + write_obstack (out_file, &cu_list);
4822 + write_obstack (out_file, &addr_obstack);
4823 + write_obstack (out_file, &symtab_obstack);
4824 + write_obstack (out_file, &constant_pool);
4826 + fclose (out_file);
4828 + /* We want to keep the file, so we set cleanup_filename to NULL
4829 + here. See unlink_if_set. */
4830 + cleanup_filename = NULL;
4832 + do_cleanups (cleanup);
4835 +/* The mapped index file format is designed to be directly mmap()able
4836 + on any architecture. In most cases, a datum is represented using a
4837 + little-endian 32-bit integer value, called an offset_type. Big
4838 + endian machines must byte-swap the values before using them.
4839 + Exceptions to this rule are noted. The data is laid out such that
4840 + alignment is always respected.
4842 + A mapped index consists of several sections.
4844 + 1. The file header. This is a sequence of values, of offset_type
4845 + unless otherwise noted:
4846 + [0] The version number. Currently 1.
4847 + [1] The offset, from the start of the file, of the CU list.
4848 + [2] The offset, from the start of the file, of the address section.
4849 + [3] The offset, from the start of the file, of the symbol table.
4850 + [4] The offset, from the start of the file, of the constant pool.
4852 + 2. The CU list. This is a sequence of pairs of 64-bit
4853 + little-endian values. The first element in each pair is the offset
4854 + of a CU in the .debug_info section. The second element in each
4855 + pair is the length of that CU. References to a CU elsewhere in the
4856 + map are done using a CU index, which is just the 0-based index into
4859 + 3. The address section. The address section consists of a sequence
4860 + of address entries. Each address entry has three elements.
4861 + [0] The low address. This is a 64-bit little-endian value.
4862 + [1] The high address. This is a 64-bit little-endian value.
4863 + [2] The CU index. This is an offset_type value.
4865 + 4. The symbol table. This is a hash table. The size of the hash
4866 + table is always a power of 2. The initial hash and the step are
4867 + currently defined by the `find_slot' function.
4869 + Each slot in the hash table consists of a pair of offset_type
4870 + values. The first value is the offset of the symbol's name in the
4871 + constant pool. The second value is the offset of the CU vector in
4872 + the constant pool.
4874 + If both values are 0, then this slot in the hash table is empty.
4875 + This is ok because while 0 is a valid constant pool index, it
4876 + cannot be a valid index for both a string and a CU vector.
4878 + A string in the constant pool is stored as a \0-terminated string,
4881 + A CU vector in the constant pool is a sequence of offset_type
4882 + values. The first value is the number of CU indices in the vector.
4883 + Each subsequent value is the index of a CU in the CU list. This
4884 + element in the hash table is used to indicate which CUs define the
4887 + 5. The constant pool. This is simply a bunch of bytes. It is
4888 + organized so that alignment is correct: CU vectors are stored
4889 + first, followed by strings. */
4891 +save_gdb_index_command (char *arg, int from_tty)
4893 + struct objfile *objfile;
4895 + if (!arg || !*arg)
4896 + error (_("usage: save gdb-index DIRECTORY"));
4898 + ALL_OBJFILES (objfile)
4902 + /* If the objfile does not correspond to an actual file, skip it. */
4903 + if (stat (objfile->name, &st) < 0)
4906 + dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
4907 + if (dwarf2_per_objfile)
4909 + volatile struct gdb_exception except;
4911 + TRY_CATCH (except, RETURN_MASK_ERROR)
4913 + write_psymtabs_to_index (objfile, arg);
4915 + if (except.reason < 0)
4916 + exception_fprintf (gdb_stderr, except,
4917 + _("Error while writing index for `%s': "),
4925 int dwarf2_always_disassemble;
4928 @@ -12609,6 +14455,8 @@ void _initialize_dwarf2_read (void);
4930 _initialize_dwarf2_read (void)
4932 + struct cmd_list_element *c;
4934 dwarf2_objfile_data_key
4935 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
4937 @@ -12656,4 +14504,9 @@ The value is the maximum depth to print."),
4940 &setdebuglist, &showdebuglist);
4942 + c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
4943 + _("Save a .gdb-index file"),
4945 + set_cmd_completer (c, filename_completer);
4947 diff --git a/gdb/elfread.c b/gdb/elfread.c
4948 index 8c00938..a250c58 100644
4952 #include "complaints.h"
4953 #include "demangle.h"
4954 #include "psympriv.h"
4955 +#include "gdbtypes.h"
4957 extern void _initialize_elfread (void);
4959 +/* Forward declaration. */
4960 +static struct sym_fns elf_sym_fns_gdb_index;
4962 /* The struct elfinfo is available only during ELF symbol table and
4963 psymtab reading. It is destroyed at the completion of psymtab-reading.
4964 It's local to elf_symfile_read. */
4965 @@ -180,7 +184,8 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
4967 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4969 - if (ms_type == mst_text || ms_type == mst_file_text)
4970 + if (ms_type == mst_text || ms_type == mst_file_text
4971 + || ms_type == mst_text_gnu_ifunc)
4972 address = gdbarch_smash_text_address (gdbarch, address);
4974 return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
4975 @@ -388,7 +393,10 @@ elf_symtab_read (struct objfile *objfile, int type,
4977 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
4979 - ms_type = mst_text;
4980 + if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
4981 + ms_type = mst_text_gnu_ifunc;
4983 + ms_type = mst_text;
4985 else if ((sym->name[0] == '.' && sym->name[1] == 'L')
4986 || ((sym->flags & BSF_LOCAL)
4987 @@ -569,6 +577,250 @@ elf_symtab_read (struct objfile *objfile, int type,
4991 +/* FIXME: Delay it through elf_sym_fns. */
4994 +elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
4996 + bfd *obfd = objfile->obfd;
4997 + const struct elf_backend_data *bed = get_elf_backend_data (obfd);
4998 + asection *plt, *relplt, *got_plt;
5001 + bfd_size_type reloc_count, reloc;
5002 + char *string_buffer = NULL;
5003 + size_t string_buffer_size = 0;
5004 + struct cleanup *back_to;
5005 + struct gdbarch *gdbarch = objfile->gdbarch;
5006 + struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
5007 + size_t ptr_size = TYPE_LENGTH (ptr_type);
5009 + if (objfile->separate_debug_objfile_backlink)
5012 + plt = bfd_get_section_by_name (obfd, ".plt");
5015 + plt_elf_idx = elf_section_data (plt)->this_idx;
5017 + got_plt = bfd_get_section_by_name (obfd, ".got.plt");
5018 + if (got_plt == NULL)
5021 + /* This search algorithm is from _bfd_elf_canonicalize_dynamic_reloc. */
5022 + for (relplt = obfd->sections; relplt != NULL; relplt = relplt->next)
5023 + if (elf_section_data (relplt)->this_hdr.sh_info == plt_elf_idx
5024 + && (elf_section_data (relplt)->this_hdr.sh_type == SHT_REL
5025 + || elf_section_data (relplt)->this_hdr.sh_type == SHT_RELA))
5027 + if (relplt == NULL)
5030 + if (! bed->s->slurp_reloc_table (obfd, relplt, dyn_symbol_table, TRUE))
5033 + back_to = make_cleanup (free_current_contents, &string_buffer);
5035 + reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
5036 + for (reloc = 0; reloc < reloc_count; reloc++)
5038 + const char *name, *name_got_plt;
5039 + struct minimal_symbol *msym;
5040 + CORE_ADDR address;
5041 + const char *suffix = "@got.plt";
5042 + size_t suffix_len = strlen (suffix);
5045 + name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
5046 + name_len = strlen (name);
5047 + address = relplt->relocation[reloc].address;
5049 + /* Does the pointer reside in the .got.plt section? */
5050 + if (!(bfd_get_section_vma (obfd, got_plt) <= address
5051 + && address < bfd_get_section_vma (obfd, got_plt)
5052 + + bfd_get_section_size (got_plt)))
5055 + /* We cannot check if NAME is a reference to mst_text_gnu_ifunc as in
5056 + OBJFILE the symbol is undefined and the objfile having NAME defined
5057 + may not yet have been loaded. */
5059 + if (string_buffer_size < name_len + suffix_len)
5061 + string_buffer_size = 2 * (name_len + suffix_len);
5062 + string_buffer = xrealloc (string_buffer, string_buffer_size);
5064 + memcpy (string_buffer, name, name_len);
5065 + memcpy (&string_buffer[name_len], suffix, suffix_len);
5067 + msym = record_minimal_symbol (string_buffer, name_len + suffix_len, 1,
5068 + address, mst_slot_got_plt, got_plt,
5071 + MSYMBOL_SIZE (msym) = ptr_size;
5074 + do_cleanups (back_to);
5077 +/* Function does not check for possibly created duplicities in the cache.
5078 + Check it by resolve_gnu_ifunc_by_cache first. */
5080 +static struct minimal_symbol *
5081 +gnu_ifunc_record_cache_unchecked (const char *function_name,
5082 + CORE_ADDR function_address)
5084 + struct minimal_symbol *msym, *msym_new;
5086 + struct objfile *objfile;
5087 + char *function_name_gnu_ifunc_tgt;
5089 + msym = lookup_minimal_symbol_by_pc (function_address);
5092 + if (SYMBOL_VALUE_ADDRESS (msym) != function_address)
5094 + /* minimal symbols have always SYMBOL_OBJ_SECTION non-NULL. */
5095 + sect = SYMBOL_OBJ_SECTION (msym)->the_bfd_section;
5096 + objfile = SYMBOL_OBJ_SECTION (msym)->objfile;
5098 + /* If .plt jumps back to .plt the symbol is still deferred for later
5099 + resolution and it has no use for GDB. Besides ".text" this symbol can
5100 + reside also in ".opd" for ppc64 function descriptor. */
5101 + if (strcmp (bfd_get_section_name (objfile->obfd, sect), ".plt") == 0)
5104 + function_name_gnu_ifunc_tgt = alloca (strlen (function_name)
5105 + + strlen ("@gnu-ifunc-tgt") + 1);
5106 + sprintf (function_name_gnu_ifunc_tgt, "%s@gnu-ifunc-tgt", function_name);
5108 + /* Create new alias "@gnu-ifunc-tgt" for MSYM. */
5109 + msym_new = record_minimal_symbol (function_name_gnu_ifunc_tgt,
5110 + strlen (function_name_gnu_ifunc_tgt), 1,
5111 + SYMBOL_VALUE_ADDRESS (msym),
5112 + MSYMBOL_TYPE (msym), sect, objfile);
5113 + /* Should not happen. */
5114 + if (msym_new == NULL)
5117 + /* objfile->msymbols array is already allocated on obstack and it cannot be
5118 + easily extended. Therefore <tab>-completion on symbol names will never
5119 + show the @gnu-ifunc-tgt symbol. Link it at least to the hash table so
5120 + that resolve_gnu_ifunc_by_cache can find it. */
5121 + add_minsym_to_hash_table (msym_new, objfile->msymbol_hash);
5123 + MSYMBOL_SIZE (msym_new) = MSYMBOL_SIZE (msym);
5127 +/* Check first the cache if it - unlikely - has not been populated since
5128 + bp_gnu_ifunc_resolver has been created. gnu_ifunc_record_cache_unchecked
5129 + could create a duplicate symbol otherwise. */
5132 +gnu_ifunc_record_cache (struct gdbarch *gdbarch, const char *function_name,
5133 + CORE_ADDR function_address)
5135 + struct minimal_symbol *msym;
5137 + msym = resolve_gnu_ifunc_by_cache (function_name);
5139 + gnu_ifunc_record_cache_unchecked (function_name, function_address);
5140 + else if (SYMBOL_VALUE_ADDRESS (msym) != function_address)
5142 + /* This case indicates buggy inferior program. GDB would need to update
5143 + its MSYM cache symbol for function_address. Anyway FUNCTION_NAME is
5144 + never normally found in the case as in such case no
5145 + bp_gnu_ifunc_resolver would be created in the first place. */
5147 + warning (_("gnu-indirect-function \"%s\" has changed its resolved "
5148 + "function_address from %s to %s; GDB is using the former one"),
5149 + function_name, paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)),
5150 + paddress (gdbarch, function_address));
5154 +static struct minimal_symbol *
5155 +resolve_gnu_ifunc_by_got (const char *function_name)
5157 + char *function_name_got_plt;
5158 + struct objfile *objfile;
5160 + function_name_got_plt = alloca (strlen (function_name) + strlen ("@got.plt")
5162 + sprintf (function_name_got_plt, "%s@got.plt", function_name);
5164 + ALL_PSPACE_OBJFILES (current_program_space, objfile)
5166 + bfd *obfd = objfile->obfd;
5167 + struct gdbarch *gdbarch = objfile->gdbarch;
5168 + struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
5169 + size_t ptr_size = TYPE_LENGTH (ptr_type);
5170 + CORE_ADDR pointer_address, function_address;
5172 + gdb_byte *buf = alloca (ptr_size);
5173 + struct minimal_symbol *msym;
5175 + msym = lookup_minimal_symbol (function_name_got_plt, NULL, objfile);
5178 + if (MSYMBOL_TYPE (msym) != mst_slot_got_plt)
5180 + pointer_address = SYMBOL_VALUE_ADDRESS (msym);
5182 + plt = bfd_get_section_by_name (obfd, ".plt");
5186 + if (MSYMBOL_SIZE (msym) != ptr_size)
5188 + if (target_read_memory (pointer_address, buf, ptr_size) != 0)
5190 + function_address = extract_typed_address (buf, ptr_type);
5192 + msym = gnu_ifunc_record_cache_unchecked (function_name, function_address);
5201 +struct minimal_symbol *
5202 +resolve_gnu_ifunc_by_cache (const char *function_name)
5204 + char *function_name_gnu_ifunc_tgt;
5206 + function_name_gnu_ifunc_tgt = alloca (strlen (function_name)
5207 + + strlen ("@gnu-ifunc-tgt") + 1);
5208 + sprintf (function_name_gnu_ifunc_tgt, "%s@gnu-ifunc-tgt", function_name);
5210 + return lookup_minimal_symbol (function_name_gnu_ifunc_tgt, NULL, NULL);
5214 +resolve_gnu_ifunc (const char *function_name, CORE_ADDR *function_addressp)
5216 + struct minimal_symbol *msym;
5218 + msym = resolve_gnu_ifunc_by_cache (function_name);
5221 + *function_addressp = SYMBOL_VALUE_ADDRESS (msym);
5225 + msym = resolve_gnu_ifunc_by_got (function_name);
5228 + *function_addressp = SYMBOL_VALUE_ADDRESS (msym);
5238 @@ -797,6 +1049,8 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
5239 bfd_errmsg (bfd_get_error ()));
5241 elf_symtab_read (objfile, ST_DYNAMIC, dynsymcount, dyn_symbol_table, 0);
5243 + elf_rel_plt_read (objfile, dyn_symbol_table);
5246 /* Add synthetic symbols - for instance, names for any PLT entries. */
5247 @@ -869,11 +1123,9 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
5249 bfd_section_size (abfd, str_sect));
5251 - if (dwarf2_has_info (objfile))
5253 - /* DWARF 2 sections */
5254 - dwarf2_build_psymtabs (objfile);
5257 + if (dwarf2_has_info (objfile) && dwarf2_initialize_objfile (objfile))
5258 + objfile->sf = &elf_sym_fns_gdb_index;
5260 /* If the file has its own symbol tables it has no separate debug info.
5261 `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
5262 @@ -1049,6 +1301,24 @@ static struct sym_fns elf_sym_fns =
5263 NULL /* next: pointer to next struct sym_fns */
5266 +/* The same as elf_sym_fns, but not registered and uses the
5267 + DWARF-specific GNU index rather than psymtab. */
5268 +static struct sym_fns elf_sym_fns_gdb_index =
5270 + bfd_target_elf_flavour,
5271 + elf_new_init, /* sym_new_init: init anything gbl to entire symab */
5272 + elf_symfile_init, /* sym_init: read initial info, setup for sym_red() */
5273 + elf_symfile_read, /* sym_read: read a symbol file into symtab */
5274 + elf_symfile_finish, /* sym_finish: finished with file, cleanup */
5275 + default_symfile_offsets, /* sym_offsets: Translate ext. to int. relocatin */
5276 + elf_symfile_segments, /* sym_segments: Get segment information from
5278 + NULL, /* sym_read_linetable */
5279 + default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
5280 + &dwarf2_gdb_index_functions,
5281 + NULL /* next: pointer to next struct sym_fns */
5285 _initialize_elfread (void)
5287 diff --git a/gdb/eval.c b/gdb/eval.c
5288 index ff17c34..7b9e871 100644
5292 #include "objfiles.h"
5293 #include "python/python.h"
5294 #include "wrapper.h"
5295 +#include "dwarf2loc.h"
5297 #include "gdb_assert.h"
5299 @@ -788,6 +789,7 @@ evaluate_subexp_standard (struct type *expect_type,
5301 struct symbol *function = NULL;
5302 char *function_name = NULL;
5303 + struct cleanup *old_chain;
5306 op = exp->elts[pc].opcode;
5307 @@ -1772,6 +1774,8 @@ evaluate_subexp_standard (struct type *expect_type,
5308 return value_zero (builtin_type (exp->gdbarch)->builtin_int,
5311 + else if (TYPE_GNU_IFUNC (ftype))
5312 + return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
5313 else if (TYPE_TARGET_TYPE (ftype))
5314 return allocate_value (TYPE_TARGET_TYPE (ftype));
5316 @@ -1798,6 +1802,8 @@ evaluate_subexp_standard (struct type *expect_type,
5318 /* First determine the type code we are dealing with. */
5319 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
5320 + old_chain = make_cleanup (null_cleanup, 0);
5321 + object_address_set (value_raw_address (arg1));
5322 type = check_typedef (value_type (arg1));
5323 code = TYPE_CODE (type);
5325 @@ -1818,6 +1824,7 @@ evaluate_subexp_standard (struct type *expect_type,
5326 code = TYPE_CODE (type);
5329 + do_cleanups (old_chain);
5333 @@ -2254,13 +2261,19 @@ evaluate_subexp_standard (struct type *expect_type,
5335 int subscript_array[MAX_FORTRAN_DIMS];
5336 int array_size_array[MAX_FORTRAN_DIMS];
5337 + int byte_stride_array[MAX_FORTRAN_DIMS];
5338 int ndimensions = 1, i;
5339 struct type *tmp_type;
5340 int offset_item; /* The array offset where the item lives */
5341 + CORE_ADDR offset_byte; /* byte_stride based offset */
5342 + unsigned element_size;
5344 if (nargs > MAX_FORTRAN_DIMS)
5345 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
5347 + old_chain = make_cleanup (null_cleanup, 0);
5348 + object_address_set (value_raw_address (arg1));
5350 tmp_type = check_typedef (value_type (arg1));
5351 ndimensions = calc_f77_array_dims (type);
5353 @@ -2290,6 +2303,9 @@ evaluate_subexp_standard (struct type *expect_type,
5354 upper = f77_get_upperbound (tmp_type);
5355 lower = f77_get_lowerbound (tmp_type);
5357 + byte_stride_array[nargs - i - 1] =
5358 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
5360 array_size_array[nargs - i - 1] = upper - lower + 1;
5362 /* Zero-normalize subscripts so that offsetting will work. */
5363 @@ -2308,13 +2324,25 @@ evaluate_subexp_standard (struct type *expect_type,
5364 tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
5367 + /* Kept for the f77_get_upperbound / f77_get_lowerbound calls above. */
5368 + do_cleanups (old_chain);
5370 /* Now let us calculate the offset for this item */
5372 - offset_item = subscript_array[ndimensions - 1];
5376 + for (i = ndimensions - 1; i >= 0; --i)
5378 + offset_item *= array_size_array[i];
5379 + if (byte_stride_array[i] == 0)
5380 + offset_item += subscript_array[i];
5382 + offset_byte += subscript_array[i] * byte_stride_array[i];
5385 - for (i = ndimensions - 1; i > 0; --i)
5387 - array_size_array[i - 1] * offset_item + subscript_array[i - 1];
5388 + element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tmp_type));
5389 + offset_byte += offset_item * element_size;
5391 /* Let us now play a dirty trick: we will take arg1
5392 which is a value node pointing to the topmost level
5393 @@ -2324,7 +2352,7 @@ evaluate_subexp_standard (struct type *expect_type,
5394 returns the correct type value */
5396 deprecated_set_value_type (arg1, tmp_type);
5397 - return value_subscripted_rvalue (arg1, offset_item, 0);
5398 + return value_subscripted_rvalue (arg1, offset_byte);
5401 case BINOP_LOGICAL_AND:
5402 @@ -2558,14 +2586,22 @@ evaluate_subexp_standard (struct type *expect_type,
5403 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
5404 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
5405 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
5406 + old_chain = make_cleanup (null_cleanup, 0);
5407 + object_address_set (value_raw_address (arg1));
5408 type = check_typedef (value_type (arg1));
5409 if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
5410 || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
5411 error (_("Attempt to dereference pointer to member without an object"));
5412 if (noside == EVAL_SKIP)
5415 + do_cleanups (old_chain);
5418 if (unop_user_defined_p (op, arg1))
5419 - return value_x_unop (arg1, op, noside);
5421 + do_cleanups (old_chain);
5422 + return value_x_unop (arg1, op, noside);
5424 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
5426 type = check_typedef (value_type (arg1));
5427 @@ -2574,12 +2610,18 @@ evaluate_subexp_standard (struct type *expect_type,
5428 /* In C you can dereference an array to get the 1st elt. */
5429 || TYPE_CODE (type) == TYPE_CODE_ARRAY
5431 - return value_zero (TYPE_TARGET_TYPE (type),
5434 + do_cleanups (old_chain);
5435 + return value_zero (TYPE_TARGET_TYPE (type),
5438 else if (TYPE_CODE (type) == TYPE_CODE_INT)
5439 - /* GDB allows dereferencing an int. */
5440 - return value_zero (builtin_type (exp->gdbarch)->builtin_int,
5443 + do_cleanups (old_chain);
5444 + /* GDB allows dereferencing an int. */
5445 + return value_zero (builtin_type (exp->gdbarch)->builtin_int,
5449 error (_("Attempt to take contents of a non-pointer value."));
5451 @@ -2589,9 +2631,14 @@ evaluate_subexp_standard (struct type *expect_type,
5452 do. "long long" variables are rare enough that
5453 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
5454 if (TYPE_CODE (type) == TYPE_CODE_INT)
5455 - return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
5456 - (CORE_ADDR) value_as_address (arg1));
5457 - return value_ind (arg1);
5459 + do_cleanups (old_chain);
5460 + return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
5461 + (CORE_ADDR) value_as_address (arg1));
5463 + arg1 = value_ind (arg1);
5464 + do_cleanups (old_chain);
5468 /* C++: check for and handle pointer to members. */
5469 @@ -2933,7 +2980,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
5473 - struct value *val;
5474 + struct value *val = NULL;
5478 @@ -2944,12 +2991,17 @@ evaluate_subexp_with_coercion (struct expression *exp,
5481 var = exp->elts[pc + 2].symbol;
5482 + /* address_of_variable will call object_address_set for check_typedef.
5483 + Call it only if required as it can error-out on VAR in register. */
5484 + if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
5485 + val = address_of_variable (var, exp->elts[pc + 1].block);
5486 type = check_typedef (SYMBOL_TYPE (var));
5487 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
5488 && CAST_IS_CONVERSION (exp->language_defn))
5491 - val = address_of_variable (var, exp->elts[pc + 1].block);
5493 + val = address_of_variable (var, exp->elts[pc + 1].block);
5494 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
5497 @@ -3001,9 +3053,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
5501 - type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
5503 - value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
5504 + /* We do not need to call read_var_value but the object evaluation may
5505 + need to have executed object_address_set which needs valid
5506 + SYMBOL_VALUE_ADDRESS of the symbol. Still VALUE returned by
5507 + read_var_value we left as lazy. */
5508 + type = value_type (read_var_value (exp->elts[pc + 2].symbol,
5509 + deprecated_safe_get_selected_frame ()));
5510 + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
5513 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
5514 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
5515 index f5bb82d..29cf5ba 100644
5518 @@ -28,6 +28,10 @@ extern void f_error (char *); /* Defined in f-exp.y */
5519 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
5522 +extern const char *f_object_address_data_valid_print_to_stream
5523 + (struct type *type, struct ui_file *stream);
5524 +extern void f_object_address_data_valid_or_error (struct type *type);
5526 extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
5527 struct ui_file *, int,
5528 const struct value *,
5529 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
5530 index d35a255..dec81d5 100644
5531 --- a/gdb/f-typeprint.c
5532 +++ b/gdb/f-typeprint.c
5534 #include "gdbcore.h"
5538 +#include "dwarf2loc.h"
5539 #include "gdb_string.h"
5542 @@ -49,6 +49,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
5543 void f_type_print_base (struct type *, struct ui_file *, int, int);
5547 +f_object_address_data_valid_print_to_stream (struct type *type,
5548 + struct ui_file *stream)
5552 + msg = object_address_data_not_valid (type);
5555 + /* Assuming the content printed to STREAM should not be localized. */
5556 + fprintf_filtered (stream, "<%s>", msg);
5563 +f_object_address_data_valid_or_error (struct type *type)
5567 + msg = object_address_data_not_valid (type);
5570 + error (_("Cannot access it because the %s."), _(msg));
5574 /* LEVEL is the depth to indent lines by. */
5577 @@ -58,6 +86,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
5578 enum type_code code;
5581 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
5584 f_type_print_base (type, stream, show, level);
5585 code = TYPE_CODE (type);
5586 if ((varstring != NULL && *varstring != '\0')
5587 @@ -165,6 +196,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
5591 + if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
5592 + CHECK_TYPEDEF (type);
5594 switch (TYPE_CODE (type))
5596 case TYPE_CODE_ARRAY:
5597 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
5598 index 85f698d..2f72b97 100644
5599 --- a/gdb/f-valprint.c
5600 +++ b/gdb/f-valprint.c
5601 @@ -54,15 +54,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
5602 /* The following macro gives us the size of the nth dimension, Where
5605 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
5606 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
5608 -/* The following gives us the offset for row n where n is 1-based. */
5609 +/* The following gives us the element size for row n where n is 1-based. */
5611 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
5612 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
5615 f77_get_lowerbound (struct type *type)
5617 + f_object_address_data_valid_or_error (type);
5619 if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
5620 error (_("Lower bound may not be '*' in F77"));
5622 @@ -72,14 +74,17 @@ f77_get_lowerbound (struct type *type)
5624 f77_get_upperbound (struct type *type)
5626 + f_object_address_data_valid_or_error (type);
5628 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
5630 - /* We have an assumed size array on our hands. Assume that
5631 - upper_bound == lower_bound so that we show at least 1 element.
5632 - If the user wants to see more elements, let him manually ask for 'em
5633 - and we'll subscript the array and show him. */
5634 + /* We have an assumed size array on our hands. As type_length_get
5635 + already assumes a length zero of arrays with underfined bounds VALADDR
5636 + passed to the Fortran functions does not contained the real inferior
5637 + memory content. User should request printing of specific array
5638 + elements instead. */
5640 - return f77_get_lowerbound (type);
5641 + return f77_get_lowerbound (type) - 1;
5644 return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
5645 @@ -134,24 +139,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
5646 upper = f77_get_upperbound (tmp_type);
5647 lower = f77_get_lowerbound (tmp_type);
5649 - F77_DIM_SIZE (ndimen) = upper - lower + 1;
5650 + F77_DIM_COUNT (ndimen) = upper - lower + 1;
5652 + F77_DIM_BYTE_STRIDE (ndimen) =
5653 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
5655 tmp_type = TYPE_TARGET_TYPE (tmp_type);
5659 - /* Now we multiply eltlen by all the offsets, so that later we
5660 + /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
5661 can print out array elements correctly. Up till now we
5662 - know an offset to apply to get the item but we also
5663 + know an eltlen to apply to get the item but we also
5664 have to know how much to add to get to the next item */
5667 eltlen = TYPE_LENGTH (tmp_type);
5668 - F77_DIM_OFFSET (ndimen) = eltlen;
5669 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
5670 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
5671 while (--ndimen > 0)
5673 - eltlen *= F77_DIM_SIZE (ndimen + 1);
5674 - F77_DIM_OFFSET (ndimen) = eltlen;
5675 + eltlen *= F77_DIM_COUNT (ndimen + 1);
5676 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
5677 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
5681 @@ -172,34 +182,34 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
5683 if (nss != ndimensions)
5685 - for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
5686 + for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
5688 fprintf_filtered (stream, "( ");
5689 f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
5690 - valaddr + i * F77_DIM_OFFSET (nss),
5691 - address + i * F77_DIM_OFFSET (nss),
5692 + valaddr + i * F77_DIM_BYTE_STRIDE (nss),
5693 + address + i * F77_DIM_BYTE_STRIDE (nss),
5694 stream, recurse, val, options, elts);
5695 fprintf_filtered (stream, ") ");
5697 - if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
5698 + if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
5699 fprintf_filtered (stream, "...");
5703 - for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
5704 + for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
5707 val_print (TYPE_TARGET_TYPE (type),
5708 - valaddr + i * F77_DIM_OFFSET (ndimensions),
5709 + valaddr + i * F77_DIM_BYTE_STRIDE (ndimensions),
5711 - address + i * F77_DIM_OFFSET (ndimensions),
5712 + address + i * F77_DIM_BYTE_STRIDE (ndimensions),
5713 stream, recurse, val, options, current_language);
5715 - if (i != (F77_DIM_SIZE (nss) - 1))
5716 + if (i != (F77_DIM_COUNT (nss) - 1))
5717 fprintf_filtered (stream, ", ");
5719 if ((*elts == options->print_max - 1)
5720 - && (i != (F77_DIM_SIZE (nss) - 1)))
5721 + && (i != (F77_DIM_COUNT (nss) - 1)))
5722 fprintf_filtered (stream, "...");
5725 @@ -256,6 +266,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
5729 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
5732 CHECK_TYPEDEF (type);
5733 switch (TYPE_CODE (type))
5735 diff --git a/gdb/findcmd.c b/gdb/findcmd.c
5736 index ac63a9e..e9ba45c 100644
5739 @@ -45,6 +45,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
5743 +/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
5744 + will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
5745 + place as *PATTERN_BUF, indicating that the buffer is initially empty. */
5748 +allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
5749 + ULONGEST *pattern_buf_size)
5751 +#define INITIAL_PATTERN_BUF_SIZE 100
5752 + *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
5753 + *pattern_buf = xmalloc (*pattern_buf_size);
5754 + *pattern_buf_end = *pattern_buf;
5757 +/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
5758 + VAL_BYTES more bytes or a 64-bit value, whichever is larger.
5759 + *PATTERN_BUF_END is updated as necessary. */
5762 +increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
5763 + ULONGEST *pattern_buf_size, int val_bytes)
5765 + /* Keep it simple and assume size == 'g' when watching for when we
5766 + need to grow the pattern buf. */
5767 + if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
5768 + > *pattern_buf_size)
5770 + size_t current_offset = *pattern_buf_end - *pattern_buf;
5772 + *pattern_buf_size *= 2;
5773 + *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
5774 + *pattern_buf_end = *pattern_buf + current_offset;
5778 /* Subroutine of find_command to simplify it.
5779 Parse the arguments of the "find" command. */
5781 @@ -61,8 +96,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
5783 /* Current size of search pattern buffer.
5784 We realloc space as needed. */
5785 -#define INITIAL_PATTERN_BUF_SIZE 100
5786 - ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
5787 + ULONGEST pattern_buf_size;
5788 /* Pointer to one past the last in-use part of pattern_buf. */
5789 char *pattern_buf_end;
5790 ULONGEST pattern_len;
5791 @@ -75,8 +109,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
5793 error (_("Missing search parameters."));
5795 - pattern_buf = xmalloc (pattern_buf_size);
5796 - pattern_buf_end = pattern_buf;
5797 + allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
5798 old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
5800 /* Get search granularity and/or max count if specified.
5801 @@ -175,17 +208,9 @@ parse_find_args (char *args, ULONGEST *max_countp,
5802 v = parse_to_comma_and_eval (&s);
5803 val_bytes = TYPE_LENGTH (value_type (v));
5805 - /* Keep it simple and assume size == 'g' when watching for when we
5806 - need to grow the pattern buf. */
5807 - if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
5808 - > pattern_buf_size)
5810 - size_t current_offset = pattern_buf_end - pattern_buf;
5811 + increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
5812 + &pattern_buf_size, val_bytes);
5814 - pattern_buf_size *= 2;
5815 - pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
5816 - pattern_buf_end = pattern_buf + current_offset;
5821 @@ -240,6 +265,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
5822 discard_cleanups (old_cleanups);
5825 +/* Drives target_search_memory to sweep through the specified search space,
5826 + possibly in several iterations (with one call to this function for each
5827 + iteration). *START_ADDR is the address where the search starts, and is
5828 + updated to the next starting address to continue the search.
5829 + *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
5830 + updated for the next iteration. PATTERN_BUF holds the pattern to be searched
5831 + for, PATTERN_LEN is the size of the pattern in bytes. If a match is found,
5832 + it's address is put in *FOUND_ADDR.
5834 + Returns 1 if found, 0 if not found, and -1 if there was an error requiring
5835 + halting of the search (e.g. memory read error). */
5838 +search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
5839 + const char *pattern_buf, ULONGEST pattern_len,
5840 + CORE_ADDR *found_addr)
5842 + /* Offset from start of this iteration to the next iteration. */
5843 + ULONGEST next_iter_incr;
5846 + found = target_search_memory (*start_addr, *search_space_len,
5847 + pattern_buf, pattern_len, found_addr);
5851 + /* Begin next iteration at one byte past this match. */
5852 + next_iter_incr = (*found_addr - *start_addr) + 1;
5854 + /* For robustness, we don't let search_space_len go -ve here. */
5855 + if (*search_space_len >= next_iter_incr)
5856 + *search_space_len -= next_iter_incr;
5858 + *search_space_len = 0;
5859 + *start_addr += next_iter_incr;
5865 find_command (char *args, int from_tty)
5867 @@ -270,12 +334,11 @@ find_command (char *args, int from_tty)
5868 while (search_space_len >= pattern_len
5869 && found_count < max_count)
5871 - /* Offset from start of this iteration to the next iteration. */
5872 - ULONGEST next_iter_incr;
5873 CORE_ADDR found_addr;
5874 - int found = target_search_memory (start_addr, search_space_len,
5875 - pattern_buf, pattern_len, &found_addr);
5878 + found = search_memory (&start_addr, &search_space_len, pattern_buf,
5879 + pattern_len, &found_addr);
5883 @@ -283,16 +346,6 @@ find_command (char *args, int from_tty)
5884 printf_filtered ("\n");
5886 last_found_addr = found_addr;
5888 - /* Begin next iteration at one byte past this match. */
5889 - next_iter_incr = (found_addr - start_addr) + 1;
5891 - /* For robustness, we don't let search_space_len go -ve here. */
5892 - if (search_space_len >= next_iter_incr)
5893 - search_space_len -= next_iter_incr;
5895 - search_space_len = 0;
5896 - start_addr += next_iter_incr;
5899 /* Record and print the results. */
5900 diff --git a/gdb/findvar.c b/gdb/findvar.c
5901 index e0ca12c..de6311a 100644
5905 #include "user-regs.h"
5907 #include "objfiles.h"
5908 +#include "dwarf2loc.h"
5910 /* Basic byte-swapping routines. All 'extract' functions return a
5911 host-format integer from a target-format integer at ADDR which is
5912 @@ -401,27 +402,16 @@ symbol_read_needs_frame (struct symbol *sym)
5913 /* Given a struct symbol for a variable,
5914 and a stack frame id, read the value of the variable
5915 and return a (pointer to a) struct value containing the value.
5916 - If the variable cannot be found, return a zero pointer. */
5917 + If the variable cannot be found, return a zero pointer.
5918 + We have to first find the address of the variable before allocating struct
5919 + value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
5920 + used by its type. */
5923 read_var_value (struct symbol *var, struct frame_info *frame)
5926 struct type *type = SYMBOL_TYPE (var);
5930 - if (SYMBOL_CLASS (var) == LOC_COMPUTED
5931 - || SYMBOL_CLASS (var) == LOC_REGISTER)
5932 - /* These cases do not use V. */
5936 - v = allocate_value (type);
5937 - VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */
5940 - len = TYPE_LENGTH (type);
5942 if (symbol_read_needs_frame (var))
5944 @@ -429,33 +419,43 @@ read_var_value (struct symbol *var, struct frame_info *frame)
5945 switch (SYMBOL_CLASS (var))
5948 - /* Put the constant back in target format. */
5949 - store_signed_integer (value_contents_raw (v), len,
5950 - gdbarch_byte_order (get_type_arch (type)),
5951 - (LONGEST) SYMBOL_VALUE (var));
5952 - VALUE_LVAL (v) = not_lval;
5955 + /* Put the constant back in target format. */
5956 + struct value *v = allocate_value (type);
5957 + VALUE_LVAL (v) = not_lval;
5958 + store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
5959 + gdbarch_byte_order (get_type_arch (type)),
5960 + (LONGEST) SYMBOL_VALUE (var));
5965 - /* Put the constant back in target format. */
5966 - if (overlay_debugging)
5969 - = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
5970 - SYMBOL_OBJ_SECTION (var));
5972 + /* Put the constant back in target format. */
5973 + struct value *v = allocate_value (type);
5974 + VALUE_LVAL (v) = not_lval;
5975 + if (overlay_debugging)
5978 + = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
5979 + SYMBOL_OBJ_SECTION (var));
5981 - store_typed_address (value_contents_raw (v), type, addr);
5984 - store_typed_address (value_contents_raw (v), type,
5985 - SYMBOL_VALUE_ADDRESS (var));
5986 - VALUE_LVAL (v) = not_lval;
5988 + store_typed_address (value_contents_raw (v), type, addr);
5991 + store_typed_address (value_contents_raw (v), type,
5992 + SYMBOL_VALUE_ADDRESS (var));
5996 case LOC_CONST_BYTES:
5997 - memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
5998 - VALUE_LVAL (v) = not_lval;
6001 + struct value *v = allocate_value (type);
6002 + VALUE_LVAL (v) = not_lval;
6003 + memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
6004 + TYPE_LENGTH (type));
6009 if (overlay_debugging)
6010 @@ -496,12 +496,23 @@ read_var_value (struct symbol *var, struct frame_info *frame)
6014 - if (overlay_debugging)
6015 - set_value_address (v, symbol_overlayed_address
6016 - (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)));
6018 - set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
6024 + if (overlay_debugging)
6025 + addr = symbol_overlayed_address
6026 + (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
6028 + addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
6029 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
6030 + DW_OP_push_object_address. */
6031 + object_address_set (addr);
6032 + v = allocate_value (type);
6033 + VALUE_LVAL (v) = lval_memory;
6034 + set_value_address (v, addr);
6039 case LOC_REGPARM_ADDR:
6040 @@ -520,7 +531,6 @@ read_var_value (struct symbol *var, struct frame_info *frame)
6041 error (_("Value of register variable not available."));
6043 addr = value_as_address (regval);
6044 - VALUE_LVAL (v) = lval_memory;
6048 @@ -563,18 +573,33 @@ read_var_value (struct symbol *var, struct frame_info *frame)
6051 case LOC_OPTIMIZED_OUT:
6052 - VALUE_LVAL (v) = not_lval;
6053 - set_value_optimized_out (v, 1);
6056 + struct value *v = allocate_value (type);
6058 + VALUE_LVAL (v) = not_lval;
6059 + set_value_optimized_out (v, 1);
6064 error (_("Cannot look up value of a botched symbol."));
6068 - set_value_address (v, addr);
6069 - set_value_lazy (v, 1);
6074 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
6075 + DW_OP_PUSH_OBJECT_ADDRESS. */
6076 + object_address_set (addr);
6077 + v = allocate_value (type);
6078 + VALUE_LVAL (v) = lval_memory;
6079 + set_value_address (v, addr);
6081 + set_value_lazy (v, 1);
6087 /* Install default attributes for register values. */
6088 @@ -611,10 +636,11 @@ struct value *
6089 value_from_register (struct type *type, int regnum, struct frame_info *frame)
6091 struct gdbarch *gdbarch = get_frame_arch (frame);
6092 - struct type *type1 = check_typedef (type);
6095 - if (gdbarch_convert_register_p (gdbarch, regnum, type1))
6096 + type = check_typedef (type);
6098 + if (gdbarch_convert_register_p (gdbarch, regnum, type))
6100 /* The ISA/ABI need to something weird when obtaining the
6101 specified value from this register. It might need to
6102 @@ -628,7 +654,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
6103 VALUE_FRAME_ID (v) = get_frame_id (frame);
6104 VALUE_REGNUM (v) = regnum;
6105 gdbarch_register_to_value (gdbarch,
6106 - frame, regnum, type1, value_contents_raw (v));
6107 + frame, regnum, type, value_contents_raw (v));
6111 diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
6112 index 78151dd..da11686 100644
6115 @@ -124,6 +124,10 @@ extern struct cmd_list_element *setchecklist;
6117 extern struct cmd_list_element *showchecklist;
6119 +/* Chain containing all defined "save" subcommands. */
6121 +extern struct cmd_list_element *save_cmdlist;
6123 extern void execute_command (char *, int);
6124 extern char *execute_command_to_string (char *p, int from_tty);
6126 diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
6127 index ffb7f53..a2e7e94 100644
6128 --- a/gdb/gdbinit.in
6129 +++ b/gdb/gdbinit.in
6131 echo Setting up the environment for debugging gdb.\n
6133 +# Set up the Python library and "require" command.
6135 +from os.path import abspath
6136 +gdb.datadir = abspath ('@srcdir@/python/lib')
6137 +gdb.pythonlibdir = gdb.datadir
6138 +gdb.__path__ = [gdb.datadir + '/gdb']
6139 +sys.path.insert(0, gdb.datadir)
6141 +source @srcdir@/python/lib/gdb/__init__.py
6146 diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
6147 index cd24eaf..9638368 100644
6148 --- a/gdb/gdbthread.h
6149 +++ b/gdb/gdbthread.h
6150 @@ -66,6 +66,9 @@ struct thread_info
6151 /* Step-resume or longjmp-resume breakpoint. */
6152 struct breakpoint *step_resume_breakpoint;
6154 + /* Exception-resume breakpoint. */
6155 + struct breakpoint *exception_resume_breakpoint;
6157 /* Range to single step within.
6159 If this is nonzero, respond to a single-step signal by continuing
6160 @@ -185,6 +188,10 @@ struct thread_info
6161 /* True if this thread has been explicitly requested to stop. */
6164 + /* The initiating frame of a nexting operation, used for deciding
6165 + which exceptions to intercept. */
6166 + struct frame_id initiating_frame;
6168 /* Private data used by the target vector implementation. */
6169 struct private_thread_info *private;
6171 @@ -221,6 +228,9 @@ extern void delete_thread_silent (ptid_t);
6172 /* Delete a step_resume_breakpoint from the thread database. */
6173 extern void delete_step_resume_breakpoint (struct thread_info *);
6175 +/* Delete an exception_resume_breakpoint from the thread database. */
6176 +extern void delete_exception_resume_breakpoint (struct thread_info *);
6178 /* Translate the integer thread id (GDB's homegrown id, not the system's)
6179 into a "pid" (which may be overloaded with extra thread information). */
6180 extern ptid_t thread_id_to_pid (int);
6181 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
6182 index 443f6f7..d852a14 100644
6183 --- a/gdb/gdbtypes.c
6184 +++ b/gdb/gdbtypes.c
6187 #include "gdb_assert.h"
6188 #include "hashtab.h"
6189 +#include "observer.h"
6190 +#include "dwarf2expr.h"
6191 +#include "dwarf2loc.h"
6194 /* Floatformat pairs. */
6195 @@ -123,6 +126,11 @@ static void print_arg_types (struct field *, int, int);
6196 static void dump_fn_fieldlists (struct type *, int);
6197 static void print_cplus_stuff (struct type *, int);
6199 +/* The hash table holding all discardable `struct type *' references. */
6200 +static htab_t type_discardable_table;
6202 +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE. */
6203 +static int type_discardable_age_current;
6205 /* Allocate a new OBJFILE-associated type structure and fill it
6206 with some defaults. Space for the type structure is allocated
6207 @@ -153,6 +161,39 @@ alloc_type (struct objfile *objfile)
6211 +/* Declare TYPE as discardable on next garbage collection by free_all_types.
6212 + You must call type_mark_used during each free_all_types to protect TYPE from
6213 + being deallocated. */
6216 +set_type_as_discardable (struct type *type)
6220 + gdb_assert (!TYPE_DISCARDABLE (type));
6222 + TYPE_DISCARDABLE (type) = 1;
6223 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
6225 + slot = htab_find_slot (type_discardable_table, type, INSERT);
6226 + gdb_assert (!*slot);
6230 +/* Allocate a new type like alloc_type but preserve for it the discardability
6231 + state of PARENT_TYPE. */
6233 +static struct type *
6234 +alloc_type_as_parent (struct type *parent_type)
6236 + struct type *new_type = alloc_type_copy (parent_type);
6238 + if (TYPE_DISCARDABLE (parent_type))
6239 + set_type_as_discardable (new_type);
6244 /* Allocate a new GDBARCH-associated type structure and fill it
6245 with some defaults. Space for the type structure is allocated
6247 @@ -278,7 +319,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
6249 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
6251 - ntype = alloc_type_copy (type);
6252 + ntype = alloc_type_as_parent (type);
6256 @@ -355,7 +396,7 @@ make_reference_type (struct type *type, struct type **typeptr)
6258 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
6260 - ntype = alloc_type_copy (type);
6261 + ntype = alloc_type_as_parent (type);
6265 @@ -726,6 +767,7 @@ create_range_type (struct type *result_type, struct type *index_type,
6266 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
6267 TYPE_LOW_BOUND (result_type) = low_bound;
6268 TYPE_HIGH_BOUND (result_type) = high_bound;
6269 + TYPE_BYTE_STRIDE (result_type) = 0;
6272 TYPE_UNSIGNED (result_type) = 1;
6273 @@ -825,26 +867,45 @@ create_array_type (struct type *result_type,
6275 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
6276 TYPE_TARGET_TYPE (result_type) = element_type;
6277 - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
6278 - low_bound = high_bound = 0;
6279 - CHECK_TYPEDEF (element_type);
6280 - /* Be careful when setting the array length. Ada arrays can be
6281 - empty arrays with the high_bound being smaller than the low_bound.
6282 - In such cases, the array length should be zero. */
6283 - if (high_bound < low_bound)
6284 - TYPE_LENGTH (result_type) = 0;
6286 - TYPE_LENGTH (result_type) =
6287 - TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
6288 TYPE_NFIELDS (result_type) = 1;
6289 TYPE_FIELDS (result_type) =
6290 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
6291 TYPE_INDEX_TYPE (result_type) = range_type;
6292 TYPE_VPTR_FIELDNO (result_type) = -1;
6294 - /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
6295 + /* DWARF blocks may depend on runtime information like
6296 + DW_OP_PUSH_OBJECT_ADDRESS not being available during the
6297 + CREATE_ARRAY_TYPE time. */
6298 + if (TYPE_RANGE_DATA (range_type)->low.kind != RANGE_BOUND_KIND_CONSTANT
6299 + || TYPE_RANGE_DATA (range_type)->high.kind != RANGE_BOUND_KIND_CONSTANT
6300 + || TYPE_LOW_BOUND_UNDEFINED (range_type)
6301 + || TYPE_HIGH_BOUND_UNDEFINED (range_type)
6302 + || get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
6308 + /* Be careful when setting the array length. Ada arrays can be
6309 + empty arrays with the high_bound being smaller than the low_bound.
6310 + In such cases, the array length should be zero. TYPE_TARGET_STUB needs to
6311 + be checked as it may have dependencies on DWARF blocks depending on
6312 + runtime information not available during the CREATE_ARRAY_TYPE time. */
6313 + if (high_bound < low_bound || TYPE_TARGET_STUB (element_type))
6314 + TYPE_LENGTH (result_type) = 0;
6317 + CHECK_TYPEDEF (element_type);
6318 + TYPE_LENGTH (result_type) =
6319 + TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
6322 if (TYPE_LENGTH (result_type) == 0)
6323 - TYPE_TARGET_STUB (result_type) = 1;
6325 + /* The real size will be computed for specific instances by
6327 + TYPE_TARGET_STUB (result_type) = 1;
6332 @@ -1353,6 +1414,105 @@ stub_noname_complaint (void)
6333 complaint (&symfile_complaints, _("stub type has NULL name"));
6336 +/* Calculate the memory length of array TYPE.
6338 + TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
6339 + a performance hint. Feel free to pass NULL. Set FULL_SPAN to return the
6340 + size incl. the possible padding of the last element - it may differ from the
6341 + cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
6342 + TYPE_BYTE_STRIDE values. */
6345 +type_length_get (struct type *type, struct type *target_type, int full_span)
6347 + struct type *range_type;
6348 + LONGEST byte_stride = 0; /* `= 0' for a false GCC warning. */
6349 + LONGEST count, element_size, retval;
6351 + if (TYPE_CODE (type) != TYPE_CODE_ARRAY
6352 + && TYPE_CODE (type) != TYPE_CODE_STRING)
6353 + return TYPE_LENGTH (type);
6355 + /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
6356 + Fortran arrays. The allocated data will never be used so they can be
6358 + if (object_address_data_not_valid (type))
6361 + range_type = TYPE_INDEX_TYPE (type);
6362 + if (TYPE_LOW_BOUND_UNDEFINED (range_type)
6363 + || TYPE_HIGH_BOUND_UNDEFINED (range_type))
6365 + count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
6366 + /* It may happen for wrong DWARF annotations returning garbage data. */
6368 + warning (_("Range for type %s has invalid bounds %s..%s"),
6369 + TYPE_NAME (type), plongest (TYPE_LOW_BOUND (range_type)),
6370 + plongest (TYPE_HIGH_BOUND (range_type)));
6371 + /* The code below does not handle count == 0 right. */
6374 + if (full_span || count > 1)
6376 + /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
6377 + force FULL_SPAN to 1. */
6378 + byte_stride = TYPE_BYTE_STRIDE (range_type);
6379 + if (byte_stride == 0)
6381 + if (target_type == NULL)
6382 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
6383 + byte_stride = type_length_get (target_type, NULL, 1);
6387 + /* For now, we conservatively take the array length to be 0 if its length
6388 + exceeds UINT_MAX. The code below assumes that for x < 0,
6389 + (ULONGEST) x == -x + ULONGEST_MAX + 1, which is technically not guaranteed
6390 + by C, but is usually true (because it would be true if x were unsigned
6391 + with its high-order bit on). It uses the fact that high_bound-low_bound is
6392 + always representable in ULONGEST and that if high_bound-low_bound+1
6393 + overflows, it overflows to 0. We must change these tests if we decide to
6394 + increase the representation of TYPE_LENGTH from unsigned int to ULONGEST.
6399 + retval = count * byte_stride;
6400 + if (count == 0 || retval / count != byte_stride || retval > UINT_MAX)
6404 + if (target_type == NULL)
6405 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
6406 + element_size = type_length_get (target_type, NULL, 1);
6407 + retval = (count - 1) * byte_stride + element_size;
6408 + if (retval < element_size
6409 + || (byte_stride != 0
6410 + && (retval - element_size) / byte_stride != count - 1)
6411 + || retval > UINT_MAX)
6416 +/* Prepare TYPE after being read in by the backend. Currently this function
6417 + only propagates the TYPE_DYNAMIC flag. */
6420 +finalize_type (struct type *type)
6424 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
6425 + if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
6428 + /* FIXME: cplus_stuff is ignored here. */
6429 + if (i < TYPE_NFIELDS (type)
6430 + || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
6431 + || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
6432 + TYPE_DYNAMIC (type) = 1;
6435 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
6437 If this is a stubbed struct (i.e. declared as struct foo *), see if
6438 @@ -1486,52 +1646,36 @@ check_typedef (struct type *type)
6442 - if (TYPE_TARGET_STUB (type))
6443 + /* copy_type_recursive automatically makes the resulting type containing only
6444 + constant values expected by the callers of this function. */
6445 + if (TYPE_DYNAMIC (type))
6447 + htab_t copied_types;
6448 + struct type *type_old = type;
6450 + copied_types = create_copied_types_hash (NULL);
6451 + type = copy_type_recursive (type, copied_types);
6452 + htab_delete (copied_types);
6454 + gdb_assert (TYPE_DYNAMIC (type) == 0);
6457 + if (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type))
6459 - struct type *range_type;
6460 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
6462 + if (TYPE_DYNAMIC (type))
6463 + TYPE_TARGET_TYPE (type) = target_type;
6464 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
6468 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
6469 - && TYPE_NFIELDS (type) == 1
6470 - && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
6471 - == TYPE_CODE_RANGE))
6472 + || TYPE_CODE (type) == TYPE_CODE_STRING)
6474 /* Now recompute the length of the array type, based on its
6475 - number of elements and the target type's length.
6476 - Watch out for Ada null Ada arrays where the high bound
6477 - is smaller than the low bound. */
6478 - const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
6479 - const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
6482 - if (high_bound < low_bound)
6486 - /* For now, we conservatively take the array length to be 0
6487 - if its length exceeds UINT_MAX. The code below assumes
6488 - that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
6489 - which is technically not guaranteed by C, but is usually true
6490 - (because it would be true if x were unsigned with its
6491 - high-order bit on). It uses the fact that
6492 - high_bound-low_bound is always representable in
6493 - ULONGEST and that if high_bound-low_bound+1 overflows,
6494 - it overflows to 0. We must change these tests if we
6495 - decide to increase the representation of TYPE_LENGTH
6496 - from unsigned int to ULONGEST. */
6497 - ULONGEST ulow = low_bound, uhigh = high_bound;
6498 - ULONGEST tlen = TYPE_LENGTH (target_type);
6500 - len = tlen * (uhigh - ulow + 1);
6501 - if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
6502 - || len > UINT_MAX)
6505 - TYPE_LENGTH (type) = len;
6506 + number of elements and the target type's length. */
6507 + TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
6508 TYPE_TARGET_STUB (type) = 0;
6510 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
6511 @@ -1539,9 +1683,12 @@ check_typedef (struct type *type)
6512 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
6513 TYPE_TARGET_STUB (type) = 0;
6515 + TYPE_DYNAMIC (type) = 0;
6518 /* Cache TYPE_LENGTH for future use. */
6519 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
6524 @@ -1811,6 +1958,8 @@ init_type (enum type_code code, int length, int flags,
6525 TYPE_NOTTEXT (type) = 1;
6526 if (flags & TYPE_FLAG_FIXED_INSTANCE)
6527 TYPE_FIXED_INSTANCE (type) = 1;
6528 + if (flags & TYPE_FLAG_GNU_IFUNC)
6529 + TYPE_GNU_IFUNC (type) = 1;
6532 TYPE_NAME (type) = obsavestring (name, strlen (name),
6533 @@ -3006,33 +3155,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
6536 /* Allocate the hash table used by copy_type_recursive to walk
6537 - types without duplicates. We use OBJFILE's obstack, because
6538 - OBJFILE is about to be deleted. */
6539 + types without duplicates. */
6542 create_copied_types_hash (struct objfile *objfile)
6544 - return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
6545 - NULL, &objfile->objfile_obstack,
6546 - hashtab_obstack_allocate,
6547 - dummy_obstack_deallocate);
6548 + if (objfile == NULL)
6550 + /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
6551 + OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN. Table
6552 + element entries get allocated by xmalloc - so use xfree. */
6553 + return htab_create (1, type_pair_hash, type_pair_eq, xfree);
6557 + /* Use OBJFILE's obstack, because OBJFILE is about to be deleted. Table
6558 + element entries get allocated by xmalloc - so use xfree. */
6559 + return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
6560 + xfree, &objfile->objfile_obstack,
6561 + hashtab_obstack_allocate,
6562 + dummy_obstack_deallocate);
6566 -/* Recursively copy (deep copy) TYPE, if it is associated with
6567 - OBJFILE. Return a new type allocated using malloc, a saved type if
6568 - we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
6569 - not associated with OBJFILE. */
6570 +/* A helper for copy_type_recursive. This does all the work. OBJFILE is used
6571 + only for an assertion checking. */
6574 -copy_type_recursive (struct objfile *objfile,
6575 - struct type *type,
6576 - htab_t copied_types)
6577 +static struct type *
6578 +copy_type_recursive_1 (struct objfile *objfile,
6579 + struct type *type,
6580 + htab_t copied_types)
6582 struct type_pair *stored, pair;
6584 struct type *new_type;
6586 - if (! TYPE_OBJFILE_OWNED (type))
6587 + if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
6590 /* This type shouldn't be pointing to any types in other objfiles;
6591 @@ -3047,8 +3205,10 @@ copy_type_recursive (struct objfile *objfile,
6592 new_type = alloc_type_arch (get_type_arch (type));
6594 /* We must add the new type to the hash table immediately, in case
6595 - we encounter this type again during a recursive call below. */
6596 - stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
6597 + we encounter this type again during a recursive call below. Memory could
6598 + be allocated from OBJFILE in the case we will be removing OBJFILE, this
6599 + optimization is missed and xfree is called for it from COPIED_TYPES. */
6600 + stored = xmalloc (sizeof (*stored));
6602 stored->new = new_type;
6604 @@ -3059,6 +3219,19 @@ copy_type_recursive (struct objfile *objfile,
6605 TYPE_OBJFILE_OWNED (new_type) = 0;
6606 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
6608 + /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
6609 + need to initialize it again. And even if TYPE was already discardable
6610 + NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE. */
6611 + TYPE_DISCARDABLE (new_type) = 0;
6612 + set_type_as_discardable (new_type);
6614 + /* Pre-clear the fields processed by delete_main_type. If DWARF block
6615 + evaluations below call error we would leave an unfreeable TYPE. */
6616 + TYPE_TARGET_TYPE (new_type) = NULL;
6617 + TYPE_VPTR_BASETYPE (new_type) = NULL;
6618 + TYPE_NFIELDS (new_type) = 0;
6619 + TYPE_FIELDS (new_type) = NULL;
6621 if (TYPE_NAME (type))
6622 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
6623 if (TYPE_TAG_NAME (type))
6624 @@ -3067,12 +3240,48 @@ copy_type_recursive (struct objfile *objfile,
6625 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
6626 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
6628 + if (TYPE_ALLOCATED (new_type))
6630 + gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
6632 + if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
6633 + TYPE_NOT_ALLOCATED (new_type) = 1;
6634 + TYPE_ALLOCATED (new_type) = NULL;
6637 + if (TYPE_ASSOCIATED (new_type))
6639 + gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
6641 + if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
6642 + TYPE_NOT_ASSOCIATED (new_type) = 1;
6643 + TYPE_ASSOCIATED (new_type) = NULL;
6646 + if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
6647 + && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
6649 + if (TYPE_NOT_ALLOCATED (new_type)
6650 + || TYPE_NOT_ASSOCIATED (new_type))
6651 + TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
6654 + TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
6655 + TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
6656 + (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
6660 /* Copy the fields. */
6661 if (TYPE_NFIELDS (type))
6665 + /* TYPE_CODE_RANGE uses TYPE_RANGE_DATA of the union with TYPE_FIELDS. */
6666 + gdb_assert (TYPE_CODE (type) != TYPE_CODE_RANGE);
6668 nfields = TYPE_NFIELDS (type);
6669 + TYPE_NFIELDS (new_type) = nfields;
6670 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
6671 for (i = 0; i < nfields; i++)
6673 @@ -3081,8 +3290,8 @@ copy_type_recursive (struct objfile *objfile,
6674 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
6675 if (TYPE_FIELD_TYPE (type, i))
6676 TYPE_FIELD_TYPE (new_type, i)
6677 - = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
6679 + = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
6681 if (TYPE_FIELD_NAME (type, i))
6682 TYPE_FIELD_NAME (new_type, i) =
6683 xstrdup (TYPE_FIELD_NAME (type, i));
6684 @@ -3109,24 +3318,166 @@ copy_type_recursive (struct objfile *objfile,
6688 + /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
6689 + possibly converted. */
6690 + TYPE_DYNAMIC (new_type) = 0;
6692 /* For range types, copy the bounds information. */
6693 - if (TYPE_CODE (type) == TYPE_CODE_RANGE)
6694 + if (TYPE_CODE (new_type) == TYPE_CODE_RANGE)
6696 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
6697 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
6699 + switch (TYPE_RANGE_DATA (new_type)->low.kind)
6701 + case RANGE_BOUND_KIND_CONSTANT:
6703 + case RANGE_BOUND_KIND_DWARF_BLOCK:
6704 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6705 + it is expected to be made constant by CHECK_TYPEDEF.
6706 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6708 + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6709 + || ! has_stack_frames ())
6711 + /* We should set 1 for Fortran but how to find the language? */
6712 + TYPE_LOW_BOUND (new_type) = 0;
6713 + TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
6716 + TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval
6717 + (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block);
6718 + TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
6720 + case RANGE_BOUND_KIND_DWARF_LOCLIST:
6724 + /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6725 + it is expected to be made constant by CHECK_TYPEDEF.
6726 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6728 + if (! TYPE_NOT_ALLOCATED (new_type)
6729 + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
6730 + && dwarf_loclist_baton_eval
6731 + (TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.loclist,
6732 + TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.type, &addr))
6733 + TYPE_LOW_BOUND (new_type) = addr;
6736 + /* We should set 1 for Fortran but how to find the language? */
6737 + TYPE_LOW_BOUND (new_type) = 0;
6738 + TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
6740 + TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
6745 + switch (TYPE_RANGE_DATA (new_type)->high.kind)
6747 + case RANGE_BOUND_KIND_CONSTANT:
6749 + case RANGE_BOUND_KIND_DWARF_BLOCK:
6750 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6751 + it is expected to be made constant by CHECK_TYPEDEF.
6752 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6754 + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6755 + || ! has_stack_frames ())
6757 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
6758 + TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
6761 + TYPE_HIGH_BOUND (new_type) = dwarf_locexpr_baton_eval
6762 + (TYPE_RANGE_DATA (new_type)->high.u.dwarf_block);
6763 + TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
6765 + case RANGE_BOUND_KIND_DWARF_LOCLIST:
6769 + /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6770 + it is expected to be made constant by CHECK_TYPEDEF.
6771 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6773 + if (! TYPE_NOT_ALLOCATED (new_type)
6774 + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
6775 + && dwarf_loclist_baton_eval
6776 + (TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.loclist,
6777 + TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.type,
6779 + TYPE_HIGH_BOUND (new_type) = addr;
6782 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
6783 + TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
6785 + TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
6790 + switch (TYPE_RANGE_DATA (new_type)->byte_stride.kind)
6792 + case RANGE_BOUND_KIND_CONSTANT:
6794 + case RANGE_BOUND_KIND_DWARF_BLOCK:
6795 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6796 + it is expected to be made constant by CHECK_TYPEDEF.
6797 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6799 + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6800 + || ! has_stack_frames ())
6801 + TYPE_BYTE_STRIDE (new_type) = 0;
6803 + TYPE_BYTE_STRIDE (new_type) = dwarf_locexpr_baton_eval
6804 + (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_block);
6805 + TYPE_RANGE_DATA (new_type)->byte_stride.kind
6806 + = RANGE_BOUND_KIND_CONSTANT;
6808 + case RANGE_BOUND_KIND_DWARF_LOCLIST:
6810 + CORE_ADDR addr = 0;
6812 + /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6813 + it is expected to be made constant by CHECK_TYPEDEF.
6814 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6816 + if (! TYPE_NOT_ALLOCATED (new_type)
6817 + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ())
6818 + dwarf_loclist_baton_eval
6819 + (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.loclist,
6820 + TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.type,
6822 + TYPE_BYTE_STRIDE (new_type) = addr;
6823 + TYPE_RANGE_DATA (new_type)->byte_stride.kind
6824 + = RANGE_BOUND_KIND_CONSTANT;
6829 + /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound. */
6830 + if (TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type))
6832 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type)
6833 + + TYPE_HIGH_BOUND (new_type) - 1;
6834 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
6838 /* Copy pointers to other types. */
6839 if (TYPE_TARGET_TYPE (type))
6840 TYPE_TARGET_TYPE (new_type) =
6841 - copy_type_recursive (objfile,
6842 - TYPE_TARGET_TYPE (type),
6844 + copy_type_recursive_1 (objfile,
6845 + TYPE_TARGET_TYPE (type),
6847 if (TYPE_VPTR_BASETYPE (type))
6848 TYPE_VPTR_BASETYPE (new_type) =
6849 - copy_type_recursive (objfile,
6850 - TYPE_VPTR_BASETYPE (type),
6852 + copy_type_recursive_1 (objfile,
6853 + TYPE_VPTR_BASETYPE (type),
6855 /* Maybe copy the type_specific bits.
6857 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
6858 @@ -3143,6 +3494,17 @@ copy_type_recursive (struct objfile *objfile,
6862 +/* Recursively copy (deep copy) TYPE. Return a new type allocated using
6863 + malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
6864 + or TYPE if it is not associated with OBJFILE. */
6867 +copy_type_recursive (struct type *type,
6868 + htab_t copied_types)
6870 + return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
6873 /* Make a copy of the given TYPE, except that the pointer & reference
6874 types are not preserved.
6876 @@ -3165,6 +3527,199 @@ copy_type (const struct type *type)
6880 +/* Callback type for main_type_crawl. */
6881 +typedef int (*main_type_crawl_iter) (struct type *type, void *data);
6883 +/* Iterate all main_type structures reachable through any `struct type *' from
6884 + TYPE. ITER will be called only for one type of each main_type, use
6885 + TYPE_CHAIN traversal to find all the type instances. ITER is being called
6886 + for each main_type found. ITER returns non-zero if main_type_crawl should
6887 + depth-first enter the specific type. ITER must provide some detection for
6888 + reentering the same main_type as this function would otherwise endlessly
6892 +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
6894 + struct type *type_iter;
6900 + gdb_assert (TYPE_OBJFILE (type) == NULL);
6902 + /* `struct cplus_struct_type' handling is unsupported by this function. */
6903 + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
6904 + && TYPE_CODE (type) != TYPE_CODE_UNION)
6905 + || !HAVE_CPLUS_STRUCT (type));
6907 + if (!(*iter) (type, data))
6910 + /* Iterate all the type instances of this main_type. */
6914 + gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
6916 + main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
6917 + main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
6919 + type_iter = TYPE_CHAIN (type_iter);
6921 + while (type_iter != type);
6923 + for (i = 0; i < TYPE_NFIELDS (type); i++)
6924 + main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
6926 + main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
6927 + main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
6930 +/* A helper for delete_type which deletes a main_type and the things to which
6931 + it refers. TYPE is a type whose main_type we wish to destroy. */
6934 +delete_main_type (struct type *type)
6938 + gdb_assert (TYPE_DISCARDABLE (type));
6939 + gdb_assert (TYPE_OBJFILE (type) == NULL);
6941 + xfree (TYPE_NAME (type));
6942 + xfree (TYPE_TAG_NAME (type));
6944 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
6946 + xfree (TYPE_FIELD_NAME (type, i));
6948 + if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
6949 + xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
6951 + xfree (TYPE_FIELDS (type));
6953 + gdb_assert (!HAVE_CPLUS_STRUCT (type));
6955 + xfree (TYPE_MAIN_TYPE (type));
6958 +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
6959 + main_type. TYPE must be a reclaimable type - neither permanent nor objfile
6963 +delete_type_chain (struct type *type)
6965 + struct type *type_iter, *type_iter_to_free;
6967 + gdb_assert (TYPE_DISCARDABLE (type));
6968 + gdb_assert (TYPE_OBJFILE (type) == NULL);
6970 + delete_main_type (type);
6975 + type_iter_to_free = type_iter;
6976 + type_iter = TYPE_CHAIN (type_iter);
6977 + xfree (type_iter_to_free);
6979 + while (type_iter != type);
6982 +/* Hash function for type_discardable_table. */
6985 +type_discardable_hash (const void *p)
6987 + const struct type *type = p;
6989 + return htab_hash_pointer (TYPE_MAIN_TYPE (type));
6992 +/* Equality function for type_discardable_table. */
6995 +type_discardable_equal (const void *a, const void *b)
6997 + const struct type *left = a;
6998 + const struct type *right = b;
7000 + return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
7003 +/* A helper for type_mark_used. */
7006 +type_mark_used_crawl (struct type *type, void *unused)
7008 + if (!TYPE_DISCARDABLE (type))
7011 + if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
7014 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
7016 + /* Continue the traversal. */
7020 +/* Mark TYPE and its connected types as used in this free_all_types pass. */
7023 +type_mark_used (struct type *type)
7028 + if (!TYPE_DISCARDABLE (type))
7031 + main_type_crawl (type, type_mark_used_crawl, NULL);
7034 +/* A traverse callback for type_discardable_table which removes any
7035 + type_discardable whose reference count is now zero (unused link). */
7038 +type_discardable_remove (void **slot, void *unused)
7040 + struct type *type = *slot;
7042 + gdb_assert (TYPE_DISCARDABLE (type));
7044 + if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
7046 + delete_type_chain (type);
7048 + htab_clear_slot (type_discardable_table, slot);
7054 +/* Free all the reclaimable types that have been allocated and that have
7055 + currently zero reference counter.
7057 + This function is called after each command, successful or not. Use this
7058 + cleanup only in the GDB idle state as GDB only marks those types used by
7059 + globally tracked objects (with no autovariable references tracking). */
7062 +free_all_types (void)
7064 + /* Mark a new pass. As GDB checks all the entries were visited after each
7065 + pass there cannot be any stale entries already containing the changed
7067 + type_discardable_age_current ^= 1;
7069 + observer_notify_mark_used ();
7071 + htab_traverse (type_discardable_table, type_discardable_remove, NULL);
7074 /* Helper functions to initialize architecture-specific types. */
7076 @@ -3511,6 +4066,8 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
7077 = lookup_pointer_type (builtin_type->builtin_void);
7078 builtin_type->builtin_func_ptr
7079 = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
7080 + builtin_type->builtin_func_func
7081 + = lookup_function_type (builtin_type->builtin_func_ptr);
7083 /* This type represents a GDB internal function. */
7084 builtin_type->internal_fn
7085 @@ -3624,6 +4181,18 @@ objfile_type (struct objfile *objfile)
7086 "<text variable, no debug info>", objfile);
7087 TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
7088 = objfile_type->builtin_int;
7089 + objfile_type->nodebug_text_gnu_ifunc_symbol
7090 + = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
7091 + "<text gnu-indirect-function variable, no debug info>",
7093 + TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
7094 + = objfile_type->nodebug_text_symbol;
7095 + objfile_type->nodebug_got_plt_symbol
7096 + = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
7097 + "<text from jump slot in .got.plt, no debug info>",
7099 + TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
7100 + = objfile_type->nodebug_text_symbol;
7101 objfile_type->nodebug_data_symbol
7102 = init_type (TYPE_CODE_INT,
7103 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
7104 @@ -3678,6 +4247,11 @@ void
7105 _initialize_gdbtypes (void)
7107 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
7109 + type_discardable_table = htab_create_alloc (20, type_discardable_hash,
7110 + type_discardable_equal, NULL,
7113 objfile_type_data = register_objfile_data ();
7115 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
7116 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
7117 index 085270e..cb2b88e 100644
7118 --- a/gdb/gdbtypes.h
7119 +++ b/gdb/gdbtypes.h
7120 @@ -171,6 +171,7 @@ enum type_flag_value
7121 TYPE_FLAG_FIXED_INSTANCE = (1 << 15),
7122 TYPE_FLAG_STUB_SUPPORTED = (1 << 16),
7123 TYPE_FLAG_NOTTEXT = (1 << 17),
7124 + TYPE_FLAG_GNU_IFUNC = (1 << 18),
7126 /* Used for error-checking. */
7127 TYPE_FLAG_MIN = TYPE_FLAG_UNSIGNED
7128 @@ -214,6 +215,11 @@ enum type_instance_flag_value
7130 #define TYPE_TARGET_STUB(t) (TYPE_MAIN_TYPE (t)->flag_target_stub)
7132 +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
7135 +#define TYPE_DYNAMIC(t) (TYPE_MAIN_TYPE (t)->flag_dynamic)
7137 /* Static type. If this is set, the corresponding type had
7138 * a static modifier.
7139 * Note: This may be unnecessary, since static data members
7140 @@ -271,6 +277,12 @@ enum type_instance_flag_value
7142 #define TYPE_NOTTEXT(t) (TYPE_MAIN_TYPE (t)->flag_nottext)
7144 +/* Used only for TYPE_CODE_FUNC where it specifies the real function
7145 + address is returned by this function call. TYPE_TARGET_TYPE determines the
7146 + final returned function type to be presented to user. */
7148 +#define TYPE_GNU_IFUNC(t) (TYPE_MAIN_TYPE (t)->flag_gnu_ifunc)
7150 /* Type owner. If TYPE_OBJFILE_OWNED is true, the type is owned by
7151 the objfile retrieved as TYPE_OBJFILE. Otherweise, the type is
7152 owned by an architecture; TYPE_OBJFILE is NULL in this case. */
7153 @@ -285,6 +297,48 @@ enum type_instance_flag_value
7155 #define TYPE_DECLARED_CLASS(t) (TYPE_MAIN_TYPE (t)->flag_declared_class)
7157 +/* Define this type as being reclaimable during free_all_types. Type is
7158 + required to be have TYPE_OBJFILE set to NULL. Setting this flag requires
7159 + initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable. */
7161 +#define TYPE_DISCARDABLE(t) (TYPE_MAIN_TYPE (t)->flag_discardable)
7163 +/* Marker this type has been visited by the type_mark_used by this
7164 + mark-and-sweep types garbage collecting pass. Current pass is represented
7165 + by TYPE_DISCARDABLE_AGE_CURRENT. */
7167 +#define TYPE_DISCARDABLE_AGE(t) (TYPE_MAIN_TYPE (t)->flag_discardable_age)
7169 +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)? */
7171 +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
7172 + (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
7174 +/* Not allocated. TYPE_ALLOCATED(t) must be NULL in such case. If this flag
7175 + is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated. If this
7176 + flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
7177 + determines the actual allocation state. */
7179 +#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
7181 +/* Not associated. TYPE_ASSOCIATED(t) must be NULL in such case. If this flag
7182 + is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated. If
7183 + this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
7184 + determines the actual association state. */
7186 +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
7188 +/* Address of the actual data as for DW_AT_data_location. Its dwarf block must
7189 + not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
7190 + false. If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
7191 + is the actual data address value. If unset and
7192 + TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
7193 + value_raw_address. If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
7194 + then its DWARF block determines the actual data address. */
7196 +#define TYPE_DATA_LOCATION_IS_ADDR(t) \
7197 + (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
7199 /* Constant type. If this is set, the corresponding type has a
7202 @@ -389,11 +443,19 @@ struct main_type
7203 unsigned int flag_vector : 1;
7204 unsigned int flag_stub_supported : 1;
7205 unsigned int flag_nottext : 1;
7206 + unsigned int flag_gnu_ifunc : 1;
7207 unsigned int flag_fixed_instance : 1;
7208 unsigned int flag_objfile_owned : 1;
7209 /* True if this type was declared with "class" rather than
7211 unsigned int flag_declared_class : 1;
7212 + unsigned int flag_discardable : 1;
7213 + unsigned int flag_discardable_age : 1;
7214 + unsigned int flag_dynamic : 1;
7215 + unsigned int flag_range_high_bound_is_count : 1;
7216 + unsigned int flag_not_allocated : 1;
7217 + unsigned int flag_not_associated : 1;
7218 + unsigned int flag_data_location_is_addr : 1;
7220 /* A discriminant telling us which field of the type_specific union
7221 is being used for this type, if any. */
7222 @@ -467,6 +529,20 @@ struct main_type
7224 struct type *target_type;
7226 + /* For DW_AT_data_location. */
7229 + struct dwarf2_locexpr_baton *dwarf_block;
7234 + /* For DW_AT_allocated. */
7235 + struct dwarf2_locexpr_baton *allocated;
7237 + /* For DW_AT_associated. */
7238 + struct dwarf2_locexpr_baton *associated;
7240 /* For structure and union types, a description of each field.
7241 For set and pascal array types, there is one "field",
7242 whose type is the domain type of the set or array.
7243 @@ -540,13 +616,34 @@ struct main_type
7252 + struct dwarf2_locexpr_baton *dwarf_block;
7255 + struct dwarf2_loclist_baton *loclist;
7256 + struct type *type;
7261 + enum range_bound_kind
7263 + RANGE_BOUND_KIND_CONSTANT,
7264 + RANGE_BOUND_KIND_DWARF_BLOCK,
7265 + RANGE_BOUND_KIND_DWARF_LOCLIST
7269 /* Low bound of range. */
7274 /* High bound of range. */
7278 + /* Byte stride of range. */
7281 /* Flags indicating whether the values of low and high are
7282 valid. When true, the respective range value is
7283 @@ -889,9 +986,9 @@ extern void allocate_gnat_aux_type (struct type *);
7284 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
7285 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
7286 #define TYPE_CHAIN(thistype) (thistype)->chain
7287 -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
7288 - But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
7289 - so you only have to call check_typedef once. Since allocate_value
7290 +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
7291 + check_typedef. But check_typedef does set the TYPE_LENGTH of the TYPEDEF
7292 + type, so you only have to call check_typedef once. Since allocate_value
7293 calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
7294 #define TYPE_LENGTH(thistype) (thistype)->length
7295 /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
7296 @@ -899,11 +996,16 @@ extern void allocate_gnat_aux_type (struct type *);
7297 #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
7298 #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
7299 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
7300 +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
7301 +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
7302 +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
7303 +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
7305 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
7306 #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
7307 -#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
7308 -#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
7309 +#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low.u.constant
7310 +#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high.u.constant
7311 +#define TYPE_BYTE_STRIDE(range_type) TYPE_RANGE_DATA(range_type)->byte_stride.u.constant
7312 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
7313 TYPE_RANGE_DATA(range_type)->low_undefined
7314 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
7315 @@ -920,7 +1022,14 @@ extern void allocate_gnat_aux_type (struct type *);
7316 (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
7318 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
7319 - (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
7320 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
7322 +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
7323 + element size if no specific stride value is known. */
7324 +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype) \
7325 + (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \
7326 + ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype)) \
7327 + : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
7331 @@ -1141,6 +1250,10 @@ struct builtin_type
7332 (*) () can server as a generic function pointer. */
7333 struct type *builtin_func_ptr;
7335 + /* `function returning pointer to function (returning void)' type.
7336 + The final void return type is not significant for it. */
7337 + struct type *builtin_func_func;
7340 /* Special-purpose types. */
7342 @@ -1181,6 +1294,8 @@ struct objfile_type
7344 /* Types used for symbols with no debug information. */
7345 struct type *nodebug_text_symbol;
7346 + struct type *nodebug_text_gnu_ifunc_symbol;
7347 + struct type *nodebug_got_plt_symbol;
7348 struct type *nodebug_data_symbol;
7349 struct type *nodebug_unknown_symbol;
7350 struct type *nodebug_tls_symbol;
7351 @@ -1328,6 +1443,18 @@ extern struct type *create_array_type (struct type *, struct type *,
7353 extern struct type *lookup_array_range_type (struct type *, int, int);
7355 +extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
7358 +extern int type_range_high_bound_internal (struct type *range_type);
7360 +extern int type_range_count_bound_internal (struct type *range_type);
7362 +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
7363 + struct type *element_type);
7365 +extern void finalize_type (struct type *type);
7367 extern struct type *create_string_type (struct type *, struct type *,
7369 extern struct type *lookup_string_range_type (struct type *, int, int);
7370 @@ -1370,6 +1497,8 @@ extern int is_public_ancestor (struct type *, struct type *);
7372 extern int is_unique_ancestor (struct type *, struct value *);
7374 +extern void type_mark_used (struct type *type);
7376 /* Overload resolution */
7378 #define LENGTH_MATCH(bv) ((bv)->rank[0])
7379 @@ -1432,10 +1561,11 @@ extern void maintenance_print_type (char *, int);
7381 extern htab_t create_copied_types_hash (struct objfile *objfile);
7383 -extern struct type *copy_type_recursive (struct objfile *objfile,
7384 - struct type *type,
7385 +extern struct type *copy_type_recursive (struct type *type,
7386 htab_t copied_types);
7388 extern struct type *copy_type (const struct type *type);
7390 +extern void free_all_types (void);
7392 #endif /* GDBTYPES_H */
7393 diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
7394 index 4fce1ac..144a899 100644
7395 --- a/gdb/i386-linux-nat.c
7396 +++ b/gdb/i386-linux-nat.c
7397 @@ -747,6 +747,21 @@ i386_linux_dr_unset_status (unsigned long mask)
7401 +/* See i386_dr_low_type.detach. Do not use wrappers i386_linux_dr_set_control
7402 + or i386_linux_dr_reset_addr as they would modify the register cache
7403 + (i386_linux_dr). */
7406 +i386_linux_dr_detach (void)
7410 + i386_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
7411 + i386_linux_dr_unset_status (~0UL);
7412 + for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
7413 + i386_linux_dr_set (inferior_ptid, regnum, 0);
7417 i386_linux_new_thread (ptid_t ptid)
7419 @@ -976,6 +991,7 @@ _initialize_i386_linux_nat (void)
7420 i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
7421 i386_dr_low.get_status = i386_linux_dr_get_status;
7422 i386_dr_low.unset_status = i386_linux_dr_unset_status;
7423 + i386_dr_low.detach = i386_linux_dr_detach;
7424 i386_set_debug_register_length (4);
7426 /* Override the default ptrace resume method. */
7427 diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c
7428 index eaa3644..0921c7e 100644
7429 --- a/gdb/i386-nat.c
7430 +++ b/gdb/i386-nat.c
7431 @@ -533,6 +533,17 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type,
7435 +/* See target_detach_watchpoints. */
7438 +i386_detach_watchpoints (void)
7440 + if (i386_dr_low.detach)
7441 + i386_dr_low.detach ();
7446 /* Return non-zero if we can watch a memory region that starts at
7447 address ADDR and whose length is LEN bytes. */
7449 @@ -685,6 +696,7 @@ i386_use_watchpoints (struct target_ops *t)
7450 t->to_stopped_data_address = i386_stopped_data_address;
7451 t->to_insert_watchpoint = i386_insert_watchpoint;
7452 t->to_remove_watchpoint = i386_remove_watchpoint;
7453 + t->to_detach_watchpoints = i386_detach_watchpoints;
7454 t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
7455 t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
7457 diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h
7458 index 7317e7d..ea914a5 100644
7459 --- a/gdb/i386-nat.h
7460 +++ b/gdb/i386-nat.h
7461 @@ -62,6 +62,10 @@ extern void i386_use_watchpoints (struct target_ops *);
7462 unset_status -- unset the specified bits of the debug
7463 status (DR6) register for all LWPs
7465 + detach -- clear all debug registers of only the
7466 + INFERIOR_PTID task without affecting any
7469 Additionally, the native file should set the debug_register_length
7470 field to 4 or 8 depending on the number of bytes used for
7472 @@ -73,6 +77,7 @@ struct i386_dr_low_type
7473 void (*reset_addr) (int);
7474 unsigned long (*get_status) (void);
7475 void (*unset_status) (unsigned long);
7476 + void (*detach) (void);
7477 int debug_register_length;
7480 diff --git a/gdb/infcall.c b/gdb/infcall.c
7481 index 0c9a3af..957ec1d 100644
7484 @@ -225,6 +225,56 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
7485 return value_cast (type, arg);
7488 +/* Call gnu-ifunc (STT_GNU_IFUNC - a function returning addresss of a real
7489 + function to call). PC is the gnu-ifunc function entry. Function returns
7490 + function entry of the gnu-ifunc-resolved function to call. If RETVAL_TYPEP
7491 + is not NULL fill in *RETVAL_TYPEP with return type of the gnu-ifunc-resolved
7492 + function to call. Keep *RETVAL_TYPEP intact if the return type could not be
7496 +gnu_ifunc_resolve (struct gdbarch *gdbarch, CORE_ADDR pc)
7499 + CORE_ADDR start_at_pc, address;
7500 + struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
7501 + struct value *function, *address_val;
7503 + if (find_pc_partial_function (pc, &name_at_pc, &start_at_pc, NULL)
7504 + && start_at_pc == pc)
7506 + if (resolve_gnu_ifunc (name_at_pc, &address))
7510 + name_at_pc = NULL;
7512 + function = allocate_value (func_func_type);
7513 + set_value_address (function, pc);
7515 + /* gnu-ifuncs have no arguments. FUNCTION is the function entry address
7516 + while ADDRESS is a possible function descriptor.. */
7517 + address_val = call_function_by_hand (function, 0, NULL);
7518 + address = value_as_address (address_val);
7521 + gnu_ifunc_record_cache (gdbarch, name_at_pc, address);
7523 + return gdbarch_convert_from_func_ptr_addr (gdbarch, address, ¤t_target);
7526 +static struct type *
7527 +find_function_return_type (CORE_ADDR pc)
7529 + struct symbol *sym = find_pc_function (pc);
7531 + if (sym != NULL && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) == pc
7532 + && SYMBOL_TYPE (sym) != NULL)
7533 + return TYPE_TARGET_TYPE (SYMBOL_TYPE (sym));
7538 /* Determine a function's address and its return type from its value.
7539 Calls error() if the function is not valid for calling. */
7541 @@ -233,7 +283,6 @@ find_function_addr (struct value *function, struct type **retval_type)
7543 struct type *ftype = check_typedef (value_type (function));
7544 struct gdbarch *gdbarch = get_type_arch (ftype);
7545 - enum type_code code = TYPE_CODE (ftype);
7546 struct type *value_type = NULL;
7549 @@ -241,24 +290,34 @@ find_function_addr (struct value *function, struct type **retval_type)
7552 /* Determine address to call. */
7553 - if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
7555 - funaddr = value_address (function);
7556 - value_type = TYPE_TARGET_TYPE (ftype);
7558 - else if (code == TYPE_CODE_PTR)
7559 + if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
7560 + || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
7561 + funaddr = value_address (function);
7562 + else if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
7564 funaddr = value_as_address (function);
7565 ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
7566 if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
7567 || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
7568 + funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
7571 + if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
7572 + || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
7574 + value_type = TYPE_TARGET_TYPE (ftype);
7576 + if (TYPE_GNU_IFUNC (ftype))
7578 - funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
7580 - value_type = TYPE_TARGET_TYPE (ftype);
7581 + funaddr = gnu_ifunc_resolve (gdbarch, funaddr);
7583 + /* Skip querying the function symbol if no RETVAL_TYPE has been
7586 + value_type = find_function_return_type (funaddr);
7589 - else if (code == TYPE_CODE_INT)
7590 + else if (TYPE_CODE (ftype) == TYPE_CODE_INT)
7592 /* Handle the case of functions lacking debugging info.
7593 Their values are characters since their addresses are char */
7594 diff --git a/gdb/infcmd.c b/gdb/infcmd.c
7595 index c4cdb06..d213f6a 100644
7598 @@ -822,7 +822,7 @@ nexti_command (char *count_string, int from_tty)
7599 step_1 (1, 1, count_string);
7604 delete_longjmp_breakpoint_cleanup (void *arg)
7606 int thread = * (int *) arg;
7607 @@ -862,10 +862,13 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
7609 if (!single_inst || skip_subroutines) /* leave si command alone */
7611 + struct thread_info *tp = inferior_thread ();
7613 if (in_thread_list (inferior_ptid))
7614 thread = pid_to_thread_id (inferior_ptid);
7616 set_longjmp_breakpoint (thread);
7617 + tp->initiating_frame = get_frame_id (get_current_frame ());
7619 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
7621 @@ -1219,6 +1222,15 @@ signal_command (char *signum_exp, int from_tty)
7622 proceed ((CORE_ADDR) -1, oursig, 0);
7625 +/* A continuation callback for until_next_command. */
7628 +until_next_continuation (void *arg)
7630 + struct thread_info *tp = arg;
7631 + delete_longjmp_breakpoint (tp->num);
7634 /* Proceed until we reach a different source line with pc greater than
7635 our current one or exit the function. We skip calls in both cases.
7637 @@ -1235,6 +1247,8 @@ until_next_command (int from_tty)
7638 struct symbol *func;
7639 struct symtab_and_line sal;
7640 struct thread_info *tp = inferior_thread ();
7641 + int thread = tp->num;
7642 + struct cleanup *old_chain;
7644 clear_proceed_status ();
7646 @@ -1270,7 +1284,19 @@ until_next_command (int from_tty)
7648 tp->step_multi = 0; /* Only one call to proceed */
7650 + set_longjmp_breakpoint (thread);
7651 + tp->initiating_frame = get_frame_id (frame);
7652 + old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
7654 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
7656 + if (target_can_async_p () && is_running (inferior_ptid))
7658 + discard_cleanups (old_chain);
7659 + add_continuation (tp, until_next_continuation, tp, NULL);
7662 + do_cleanups (old_chain);
7666 @@ -1463,6 +1489,7 @@ finish_command_continuation (void *arg)
7667 if (bs != NULL && tp->proceed_to_finish)
7668 observer_notify_normal_stop (bs, 1 /* print frame */);
7669 delete_breakpoint (a->breakpoint);
7670 + delete_longjmp_breakpoint (inferior_thread ()->num);
7674 @@ -1546,6 +1573,7 @@ finish_forward (struct symbol *function, struct frame_info *frame)
7675 struct breakpoint *breakpoint;
7676 struct cleanup *old_chain;
7677 struct finish_command_continuation_args *cargs;
7678 + int thread = tp->num;
7680 sal = find_pc_line (get_frame_pc (frame), 0);
7681 sal.pc = get_frame_pc (frame);
7682 @@ -1556,6 +1584,10 @@ finish_forward (struct symbol *function, struct frame_info *frame)
7684 old_chain = make_cleanup_delete_breakpoint (breakpoint);
7686 + set_longjmp_breakpoint (thread);
7687 + tp->initiating_frame = get_frame_id (frame);
7688 + make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
7690 tp->proceed_to_finish = 1; /* We want stop_registers, please... */
7691 cargs = xmalloc (sizeof (*cargs));
7693 diff --git a/gdb/inferior.h b/gdb/inferior.h
7694 index 5abec68..e309277 100644
7695 --- a/gdb/inferior.h
7696 +++ b/gdb/inferior.h
7697 @@ -291,6 +291,8 @@ extern void interrupt_target_command (char *args, int from_tty);
7699 extern void interrupt_target_1 (int all_threads);
7701 +extern void delete_longjmp_breakpoint_cleanup (void *arg);
7703 extern void detach_command (char *, int);
7705 extern void notice_new_inferior (ptid_t, int, int);
7706 diff --git a/gdb/infrun.c b/gdb/infrun.c
7707 index 54b1d9f..58d045a 100644
7711 #include "language.h"
7714 +#include "dictionary.h"
7716 #include "gdb_assert.h"
7717 #include "mi/mi-common.h"
7718 #include "event-top.h"
7719 @@ -367,6 +369,7 @@ follow_fork (void)
7720 parent thread structure's run control related fields, not just these.
7721 Initialized to avoid "may be used uninitialized" warnings from gcc. */
7722 struct breakpoint *step_resume_breakpoint = NULL;
7723 + struct breakpoint *exception_resume_breakpoint = NULL;
7724 CORE_ADDR step_range_start = 0;
7725 CORE_ADDR step_range_end = 0;
7726 struct frame_id step_frame_id = { 0 };
7727 @@ -419,6 +422,8 @@ follow_fork (void)
7728 step_range_start = tp->step_range_start;
7729 step_range_end = tp->step_range_end;
7730 step_frame_id = tp->step_frame_id;
7731 + exception_resume_breakpoint
7732 + = clone_momentary_breakpoint (tp->exception_resume_breakpoint);
7734 /* For now, delete the parent's sr breakpoint, otherwise,
7735 parent/child sr breakpoints are considered duplicates,
7736 @@ -429,6 +434,7 @@ follow_fork (void)
7737 tp->step_range_start = 0;
7738 tp->step_range_end = 0;
7739 tp->step_frame_id = null_frame_id;
7740 + delete_exception_resume_breakpoint (tp);
7743 parent = inferior_ptid;
7744 @@ -470,6 +476,8 @@ follow_fork (void)
7745 tp->step_range_start = step_range_start;
7746 tp->step_range_end = step_range_end;
7747 tp->step_frame_id = step_frame_id;
7748 + tp->exception_resume_breakpoint
7749 + = exception_resume_breakpoint;
7753 @@ -523,6 +531,9 @@ follow_inferior_reset_breakpoints (void)
7754 if (tp->step_resume_breakpoint)
7755 breakpoint_re_set_thread (tp->step_resume_breakpoint);
7757 + if (tp->exception_resume_breakpoint)
7758 + breakpoint_re_set_thread (tp->exception_resume_breakpoint);
7760 /* Reinsert all breakpoints in the child. The user may have set
7761 breakpoints after catching the fork, in which case those
7762 were never set in the child, but only in the parent. This makes
7763 @@ -760,6 +771,7 @@ follow_exec (ptid_t pid, char *execd_pathname)
7764 /* If there was one, it's gone now. We cannot truly step-to-next
7765 statement through an exec(). */
7766 th->step_resume_breakpoint = NULL;
7767 + th->exception_resume_breakpoint = NULL;
7768 th->step_range_start = 0;
7769 th->step_range_end = 0;
7771 @@ -2190,6 +2202,8 @@ static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
7772 struct symtab_and_line sr_sal,
7773 struct frame_id sr_id);
7774 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
7775 +static void check_exception_resume (struct execution_control_state *,
7776 + struct frame_info *, struct symbol *);
7778 static void stop_stepping (struct execution_control_state *ecs);
7779 static void prepare_to_wait (struct execution_control_state *ecs);
7780 @@ -2313,6 +2327,7 @@ delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
7783 delete_step_resume_breakpoint (info);
7784 + delete_exception_resume_breakpoint (info);
7788 @@ -2337,6 +2352,7 @@ delete_step_thread_step_resume_breakpoint (void)
7789 struct thread_info *tp = inferior_thread ();
7791 delete_step_resume_breakpoint (tp);
7792 + delete_exception_resume_breakpoint (tp);
7795 /* In all-stop mode, delete all step-resume and longjmp-resume
7796 @@ -3241,6 +3257,10 @@ handle_inferior_event (struct execution_control_state *ecs)
7798 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
7800 + /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
7801 + confuse bpstat_stop_status and bpstat_explains_signal. */
7802 + watchpoints_triggered (&ecs->ws);
7804 ecs->event_thread->stop_bpstat
7805 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
7806 stop_pc, ecs->ptid);
7807 @@ -3328,6 +3348,10 @@ handle_inferior_event (struct execution_control_state *ecs)
7809 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
7811 + /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
7812 + confuse bpstat_stop_status and bpstat_explains_signal. */
7813 + watchpoints_triggered (&ecs->ws);
7815 /* Do whatever is necessary to the parent branch of the vfork. */
7816 handle_vfork_child_exec_or_exit (1);
7818 @@ -4076,23 +4100,33 @@ process_event_stop_test:
7820 ecs->event_thread->stepping_over_breakpoint = 1;
7822 - if (!gdbarch_get_longjmp_target_p (gdbarch)
7823 - || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
7824 + if (what.is_longjmp)
7827 - fprintf_unfiltered (gdb_stdlog, "\
7828 + if (!gdbarch_get_longjmp_target_p (gdbarch)
7829 + || !gdbarch_get_longjmp_target (gdbarch,
7830 + frame, &jmp_buf_pc))
7833 + fprintf_unfiltered (gdb_stdlog, "\
7834 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
7842 - /* We're going to replace the current step-resume breakpoint
7843 - with a longjmp-resume breakpoint. */
7844 - delete_step_resume_breakpoint (ecs->event_thread);
7845 + /* We're going to replace the current step-resume breakpoint
7846 + with a longjmp-resume breakpoint. */
7847 + delete_step_resume_breakpoint (ecs->event_thread);
7849 - /* Insert a breakpoint at resume address. */
7850 - insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
7851 + /* Insert a breakpoint at resume address. */
7852 + insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
7856 + struct symbol *func = get_frame_function (frame);
7859 + check_exception_resume (ecs, frame, func);
7864 @@ -4101,8 +4135,52 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
7865 fprintf_unfiltered (gdb_stdlog,
7866 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
7868 - gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
7869 - delete_step_resume_breakpoint (ecs->event_thread);
7870 + if (what.is_longjmp)
7872 + gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
7873 + delete_step_resume_breakpoint (ecs->event_thread);
7877 + /* There are several cases to consider.
7879 + 1. The initiating frame no longer exists. In this case
7880 + we must stop, because the exception has gone too far.
7882 + 2. The initiating frame exists, and is the same as the
7883 + current frame. We stop, because the exception has been
7886 + 3. The initiating frame exists and is different from
7887 + the current frame. This means the exception has been
7888 + caught beneath the initiating frame, so keep going. */
7889 + struct frame_info *init_frame
7890 + = frame_find_by_id (ecs->event_thread->initiating_frame);
7892 + gdb_assert (ecs->event_thread->exception_resume_breakpoint != NULL);
7893 + delete_exception_resume_breakpoint (ecs->event_thread);
7897 + struct frame_id current_id
7898 + = get_frame_id (get_current_frame ());
7899 + if (frame_id_eq (current_id,
7900 + ecs->event_thread->initiating_frame))
7902 + /* Case 2. Fall through. */
7912 + /* For Cases 1 and 2, remove the step-resume breakpoint,
7914 + delete_step_resume_breakpoint (ecs->event_thread);
7917 ecs->event_thread->stop_step = 1;
7918 print_stop_reason (END_STEPPING_RANGE, 0);
7919 @@ -5070,6 +5148,97 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
7920 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
7923 +/* Insert an exception resume breakpoint. TP is the thread throwing
7924 + the exception. The block B is the block of the unwinder debug hook
7925 + function. FRAME is the frame corresponding to the call to this
7926 + function. SYM is the symbol of the function argument holding the
7927 + target PC of the exception. */
7930 +insert_exception_resume_breakpoint (struct thread_info *tp,
7932 + struct frame_info *frame,
7933 + struct symbol *sym)
7935 + struct gdb_exception e;
7937 + /* We want to ignore errors here. */
7938 + TRY_CATCH (e, RETURN_MASK_ALL)
7940 + struct symbol *vsym;
7941 + struct value *value;
7942 + CORE_ADDR handler;
7943 + struct breakpoint *bp;
7945 + vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
7946 + value = read_var_value (vsym, frame);
7947 + /* If the value was optimized out, revert to the old behavior. */
7948 + if (! value_optimized_out (value))
7950 + handler = value_as_address (value);
7953 + fprintf_unfiltered (gdb_stdlog,
7954 + "infrun: exception resume at %lx\n",
7955 + (unsigned long) handler);
7957 + bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
7958 + handler, bp_exception_resume);
7959 + bp->thread = tp->num;
7960 + inferior_thread ()->exception_resume_breakpoint = bp;
7965 +/* This is called when an exception has been intercepted. Check to
7966 + see whether the exception's destination is of interest, and if so,
7967 + set an exception resume breakpoint there. */
7970 +check_exception_resume (struct execution_control_state *ecs,
7971 + struct frame_info *frame, struct symbol *func)
7973 + struct gdb_exception e;
7975 + TRY_CATCH (e, RETURN_MASK_ALL)
7978 + struct dict_iterator iter;
7979 + struct symbol *sym;
7982 + /* The exception breakpoint is a thread-specific breakpoint on
7983 + the unwinder's debug hook, declared as:
7985 + void _Unwind_DebugHook (void *cfa, void *handler);
7987 + The CFA argument indicates the frame to which control is
7988 + about to be transferred. HANDLER is the destination PC.
7990 + We ignore the CFA and set a temporary breakpoint at HANDLER.
7991 + This is not extremely efficient but it avoids issues in gdb
7992 + with computing the DWARF CFA, and it also works even in weird
7993 + cases such as throwing an exception from inside a signal
7996 + b = SYMBOL_BLOCK_VALUE (func);
7997 + ALL_BLOCK_SYMBOLS (b, iter, sym)
7999 + if (!SYMBOL_IS_ARGUMENT (sym))
8006 + insert_exception_resume_breakpoint (ecs->event_thread,
8015 stop_stepping (struct execution_control_state *ecs)
8017 diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
8018 index 93adfcd..34412a6 100644
8019 --- a/gdb/linux-nat.c
8020 +++ b/gdb/linux-nat.c
8021 @@ -2587,6 +2587,39 @@ linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
8022 return lp->stopped_data_address_p;
8025 +/* In `set follow-fork-mode child' with multithreaded parent we need to detach
8026 + watchpoints from all the LWPs. In such case INFERIOR_PTID will be the
8027 + non-threaded new child while LWP_LIST will still contain all the threads of
8028 + the parent being detached. */
8031 +linux_nat_detach_watchpoints (void)
8033 + struct lwp_info *lp;
8034 + int found = 0, retval = 0;
8035 + ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
8036 + struct cleanup *old_chain = save_inferior_ptid ();
8038 + for (lp = lwp_list; lp; lp = lp->next)
8039 + if (ptid_match (lp->ptid, filter))
8041 + inferior_ptid = lp->ptid;
8042 + retval |= linux_ops->to_detach_watchpoints ();
8046 + do_cleanups (old_chain);
8050 + gdb_assert (!is_lwp (inferior_ptid));
8052 + retval |= linux_ops->to_detach_watchpoints ();
8058 /* Wait until LP is stopped. */
8061 @@ -5606,6 +5639,8 @@ linux_nat_add_target (struct target_ops *t)
8062 t->to_thread_address_space = linux_nat_thread_address_space;
8063 t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint;
8064 t->to_stopped_data_address = linux_nat_stopped_data_address;
8065 + if (linux_ops->to_detach_watchpoints)
8066 + t->to_detach_watchpoints = linux_nat_detach_watchpoints;
8068 t->to_can_async_p = linux_nat_can_async_p;
8069 t->to_is_async_p = linux_nat_is_async_p;
8070 diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
8071 index 07fd67c..2524250 100644
8072 --- a/gdb/linux-tdep.c
8073 +++ b/gdb/linux-tdep.c
8077 #include "elf/common.h"
8079 +#include "infcall.h"
8081 /* This function is suitable for architectures that don't
8082 extend/override the standard siginfo structure. */
8083 diff --git a/gdb/main.c b/gdb/main.c
8084 index bfd1213..72faabd 100644
8089 #include "interps.h"
8091 +#include "python/python.h"
8093 #include "cli/cli-cmds.h"
8094 #include "python/python.h"
8095 @@ -259,6 +260,8 @@ captured_main (void *data)
8097 char *ttyarg = NULL;
8099 + int python_script = 0;
8101 /* These are static so that we can take their address in an initializer. */
8102 static int print_help;
8103 static int print_version;
8104 @@ -443,10 +446,14 @@ captured_main (void *data)
8105 {"args", no_argument, &set_args, 1},
8106 {"l", required_argument, 0, 'l'},
8107 {"return-child-result", no_argument, &return_child_result, 1},
8109 + {"python", no_argument, 0, 'P'},
8110 + {"P", no_argument, 0, 'P'},
8112 {0, no_argument, 0, 0}
8116 + while (!python_script)
8120 @@ -464,6 +471,9 @@ captured_main (void *data)
8122 /* Long option that just sets a flag. */
8125 + python_script = 1;
8130 @@ -650,7 +660,31 @@ extern int gdbtk_test (char *);
8132 /* Now that gdb_init has created the initial inferior, we're in position
8133 to set args for that inferior. */
8135 + if (python_script)
8137 + /* The first argument is a python script to evaluate, and
8138 + subsequent arguments are passed to the script for
8139 + processing there. */
8140 + if (optind >= argc)
8142 + fprintf_unfiltered (gdb_stderr,
8143 + _("%s: Python script file name required\n"),
8148 + /* FIXME: should handle inferior I/O intelligently here.
8149 + E.g., should be possible to run gdb in pipeline and have
8150 + Python (and gdb) output go to stderr or file; and if a
8151 + prompt is needed, open the tty. */
8153 + /* FIXME: should read .gdbinit if, and only if, a prompt is
8154 + requested by the script. Though... maybe this is not
8156 + /* FIXME: likewise, reading in history. */
8157 + inhibit_gdbinit = 1;
8159 + else if (set_args)
8161 /* The remaining options are the command-line options for the
8162 inferior. The first one is the sym/exec file, and the rest
8163 @@ -890,7 +924,8 @@ Can't attach to process and specify a core file at the same time."));
8166 /* Read in the old history after all the command files have been read. */
8168 + if (!python_script)
8173 @@ -901,13 +936,25 @@ Can't attach to process and specify a core file at the same time."));
8174 /* Show time and/or space usage. */
8175 do_cleanups (pre_stat_chain);
8177 - /* NOTE: cagney/1999-11-07: There is probably no reason for not
8178 - moving this loop and the code found in captured_command_loop()
8179 - into the command_loop() proper. The main thing holding back that
8180 - change - SET_TOP_LEVEL() - has been eliminated. */
8183 + if (python_script)
8185 - catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
8186 + extern int pagination_enabled;
8187 + pagination_enabled = 0;
8188 + run_python_script (argc - optind, &argv[optind]);
8194 + /* NOTE: cagney/1999-11-07: There is probably no reason for not
8195 + moving this loop and the code found in captured_command_loop()
8196 + into the command_loop() proper. The main thing holding back that
8197 + change - SET_TOP_LEVEL() - has been eliminated. */
8200 + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
8203 /* No exit -- exit is through quit_command. */
8205 @@ -939,7 +986,12 @@ print_gdb_help (struct ui_file *stream)
8206 fputs_unfiltered (_("\
8207 This is the GNU debugger. Usage:\n\n\
8208 gdb [options] [executable-file [core-file or process-id]]\n\
8209 - gdb [options] --args executable-file [inferior-arguments ...]\n\n\
8210 + gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
8212 + fputs_unfiltered (_("\
8213 + gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
8215 + fputs_unfiltered (_("\n\
8218 fputs_unfiltered (_("\
8219 @@ -977,7 +1029,13 @@ Options:\n\n\
8220 --nw Do not use a window interface.\n\
8221 --nx Do not read "), stream);
8222 fputs_unfiltered (gdbinit, stream);
8223 - fputs_unfiltered (_(" file.\n\
8224 + fputs_unfiltered (_(" file.\n"), stream);
8226 + fputs_unfiltered (_("\
8227 + --python, -P Following argument is Python script file; remaining\n\
8228 + arguments are passed to script.\n"), stream);
8230 + fputs_unfiltered (_("\
8231 --quiet Do not print version number on startup.\n\
8232 --readnow Fully read symbol files on first access.\n\
8234 diff --git a/gdb/maint.c b/gdb/maint.c
8235 index 28fd610..4e21476 100644
8238 @@ -909,4 +909,12 @@ When enabled GDB is profiled."),
8239 show_maintenance_profile_p,
8240 &maintenance_set_cmdlist,
8241 &maintenance_show_cmdlist);
8242 + add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
8243 + &gdb_datadir, _("Set GDB's datadir path."),
8244 + _("Show GDB's datadir path."),
8246 +When set, GDB uses the specified path to search for data files."),
8248 + &maintenance_set_cmdlist,
8249 + &maintenance_show_cmdlist);
8251 diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
8252 index 310ade9..d8710a1 100644
8253 --- a/gdb/mi/mi-cmd-var.c
8254 +++ b/gdb/mi/mi-cmd-var.c
8255 @@ -702,7 +702,6 @@ mi_cmd_var_update (char *command, char **argv, int argc)
8259 - /* Get varobj handle, if a valid var obj name was specified */
8260 struct varobj *var = varobj_get_handle (name);
8262 varobj_update_one (var, print_values, 1 /* explicit */);
8263 diff --git a/gdb/minsyms.c b/gdb/minsyms.c
8264 index cb4545c..92d4027 100644
8267 @@ -337,8 +337,9 @@ lookup_minimal_symbol_text (const char *name, struct objfile *objf)
8268 msymbol = msymbol->hash_next)
8270 if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 &&
8271 - (MSYMBOL_TYPE (msymbol) == mst_text ||
8272 - MSYMBOL_TYPE (msymbol) == mst_file_text))
8273 + (MSYMBOL_TYPE (msymbol) == mst_text
8274 + || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
8275 + || MSYMBOL_TYPE (msymbol) == mst_file_text))
8277 switch (MSYMBOL_TYPE (msymbol))
8279 @@ -700,6 +701,16 @@ lookup_minimal_symbol_by_pc (CORE_ADDR pc)
8280 return lookup_minimal_symbol_by_pc_section (pc, NULL);
8283 +/* Return non-zero iff PC is in function implementing gnu-ifunc selection. */
8286 +in_gnu_ifunc_stub (CORE_ADDR pc)
8288 + struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
8290 + return msymbol && MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
8293 /* Find the minimal symbol named NAME, and return both the minsym
8294 struct and its objfile. This only checks the linkage name. Sets
8295 *OBJFILE_P and returns the minimal symbol, if it is found. If it
8296 @@ -769,6 +780,7 @@ prim_record_minimal_symbol (const char *name, CORE_ADDR address,
8300 + case mst_text_gnu_ifunc:
8302 case mst_solib_trampoline:
8303 section = SECT_OFF_TEXT (objfile);
8304 @@ -1235,7 +1247,8 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
8306 ALL_MSYMBOLS (objfile, msymbol)
8308 - if (MSYMBOL_TYPE (msymbol) == mst_text
8309 + if ((MSYMBOL_TYPE (msymbol) == mst_text
8310 + || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc)
8311 && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
8312 SYMBOL_LINKAGE_NAME (tsymbol)) == 0)
8313 return SYMBOL_VALUE_ADDRESS (msymbol);
8314 diff --git a/gdb/p-lang.c b/gdb/p-lang.c
8315 index 08738ac..64d2e9f 100644
8318 @@ -222,7 +222,11 @@ pascal_printstr (struct ui_file *stream, struct type *type,
8319 unsigned int things_printed = 0;
8322 - int width = TYPE_LENGTH (type);
8325 + /* Preserve TYPE's original type, just set its LENGTH. */
8326 + check_typedef (type);
8327 + width = TYPE_LENGTH (type);
8329 /* If the string was not truncated due to `set print elements', and
8330 the last byte of it is a null, we don't print that, in traditional C
8331 diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
8332 index 4d39bed..d0ddebc 100644
8333 --- a/gdb/p-valprint.c
8334 +++ b/gdb/p-valprint.c
8338 #include "cp-support.h"
8339 +#include "dwarf2loc.h"
8343 @@ -68,8 +69,27 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8344 struct type *char_type;
8347 + struct cleanup *back_to;
8348 + struct type *saved_type = type;
8349 + CORE_ADDR saved_address = address;
8351 + back_to = make_cleanup (null_cleanup, 0);
8352 + type = object_address_get_data (type, &address);
8355 + fputs_filtered (object_address_data_not_valid (saved_type), stream);
8356 + gdb_flush (stream);
8357 + do_cleanups (back_to);
8360 + if (address != saved_address)
8362 + size_t length = TYPE_LENGTH (type);
8364 - CHECK_TYPEDEF (type);
8365 + valaddr = xmalloc (length);
8366 + make_cleanup (xfree, (gdb_byte *) valaddr);
8367 + read_memory (address, (gdb_byte *) valaddr, length);
8369 switch (TYPE_CODE (type))
8371 case TYPE_CODE_ARRAY:
8372 @@ -125,8 +145,9 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8376 - val_print_array_elements (type, valaddr + embedded_offset, address, stream,
8377 - recurse, original_value, options, i);
8378 + val_print_array_elements (saved_type, valaddr + embedded_offset,
8379 + saved_address, stream, recurse,
8380 + original_value, options, i);
8381 fprintf_filtered (stream, "}");
8384 @@ -164,6 +185,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8385 /* Try to print what function it points to. */
8386 print_address_demangle (gdbarch, addr, stream, demangle);
8387 /* Return value is irrelevant except for string pointers. */
8388 + do_cleanups (back_to);
8392 @@ -252,6 +274,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8393 /* Return number of characters printed, including the terminating
8394 '\0' if we reached the end. val_print_string takes care including
8395 the terminating '\0' if necessary. */
8396 + do_cleanups (back_to);
8400 @@ -554,6 +577,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
8401 error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type));
8404 + do_cleanups (back_to);
8408 diff --git a/gdb/parse.c b/gdb/parse.c
8409 index c885c6a..cbf9c65 100644
8412 @@ -487,9 +487,21 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
8413 pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, ¤t_target);
8416 + struct minimal_symbol *ifunc_msym = lookup_minimal_symbol_by_pc (pc);
8418 /* In this case, assume we have a code symbol instead of
8422 + if (ifunc_msym != NULL && MSYMBOL_TYPE (ifunc_msym) == mst_text_gnu_ifunc
8423 + && SYMBOL_VALUE_ADDRESS (ifunc_msym) == pc)
8425 + /* A function descriptor has been resolved but PC is still in the
8426 + gnu-ifunc resolver body (such as because inferior does not run to
8427 + be able to call it). */
8428 + type = mst_text_gnu_ifunc;
8435 @@ -521,6 +533,11 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
8436 write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
8439 + case mst_text_gnu_ifunc:
8440 + write_exp_elt_type (objfile_type (objfile)
8441 + ->nodebug_text_gnu_ifunc_symbol);
8447 @@ -528,6 +545,10 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
8448 write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
8451 + case mst_slot_got_plt:
8452 + write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol);
8456 write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
8458 @@ -1412,6 +1433,7 @@ parser_fprintf (FILE *x, const char *y, ...)
8461 operator_check_standard (struct expression *exp, int pos,
8462 + int (*type_func) (struct type *type, void *data),
8463 int (*objfile_func) (struct objfile *objfile,
8466 @@ -1453,7 +1475,7 @@ operator_check_standard (struct expression *exp, int pos,
8467 struct type *type = elts[pos + 2 + arg].type;
8468 struct objfile *objfile = TYPE_OBJFILE (type);
8470 - if (objfile && (*objfile_func) (objfile, data))
8471 + if (objfile && objfile_func && (*objfile_func) (objfile, data))
8475 @@ -1471,7 +1493,8 @@ operator_check_standard (struct expression *exp, int pos,
8477 /* Check objfile where the variable itself is placed.
8478 SYMBOL_OBJ_SECTION (symbol) may be NULL. */
8479 - if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
8481 + && (*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
8484 /* Check objfile where is placed the code touching the variable. */
8485 @@ -1484,24 +1507,27 @@ operator_check_standard (struct expression *exp, int pos,
8487 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
8489 - if (type && TYPE_OBJFILE (type)
8490 + if (type && type_func && (*type_func) (type, data))
8492 + if (type && TYPE_OBJFILE (type) && objfile_func
8493 && (*objfile_func) (TYPE_OBJFILE (type), data))
8495 - if (objfile && (*objfile_func) (objfile, data))
8496 + if (objfile && objfile_func && (*objfile_func) (objfile, data))
8502 -/* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP.
8503 - The functions are never called with NULL OBJFILE. Functions get passed an
8504 - arbitrary caller supplied DATA pointer. If any of the functions returns
8505 - non-zero value then (any other) non-zero value is immediately returned to
8506 - the caller. Otherwise zero is returned after iterating through whole EXP.
8508 +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
8509 + referenced by EXP. The functions are never called with NULL TYPE or NULL
8510 + OBJFILE. Functions get passed an arbitrary caller supplied DATA pointer.
8511 + If any of the functions returns non-zero value then (any other) non-zero
8512 + value is immediately returned to the caller. Otherwise zero is returned
8513 + after iterating through whole EXP. */
8516 exp_iterate (struct expression *exp,
8517 + int (*type_func) (struct type *type, void *data),
8518 int (*objfile_func) (struct objfile *objfile, void *data),
8521 @@ -1516,7 +1542,9 @@ exp_iterate (struct expression *exp,
8523 pos = endpos - oplen;
8524 if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
8525 - objfile_func, data))
8532 @@ -1547,7 +1575,26 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
8534 gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
8536 - return exp_iterate (exp, exp_uses_objfile_iter, objfile);
8537 + return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
8540 +/* Helper for exp_types_mark_used. */
8543 +exp_types_mark_used_iter (struct type *type, void *unused)
8545 + type_mark_used (type);
8547 + /* Continue the traversal. */
8551 +/* Call type_mark_used for any type contained in EXP. */
8554 +exp_types_mark_used (struct expression *exp)
8556 + exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
8560 diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
8561 index bb79ae1..fbbd600 100644
8562 --- a/gdb/parser-defs.h
8563 +++ b/gdb/parser-defs.h
8564 @@ -194,6 +194,8 @@ extern void operator_length_standard (const struct expression *, int, int *,
8567 extern int operator_check_standard (struct expression *exp, int pos,
8568 + int (*type_func) (struct type *type,
8571 (struct objfile *objfile, void *data),
8573 @@ -285,6 +287,7 @@ struct exp_descriptor
8574 value should be immediately returned to the caller. Otherwise zero
8575 should be returned. */
8576 int (*operator_check) (struct expression *exp, int pos,
8577 + int (*type_func) (struct type *type, void *data),
8578 int (*objfile_func) (struct objfile *objfile,
8581 @@ -323,4 +326,8 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
8583 extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
8585 +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
8587 +extern void exp_types_mark_used (struct expression *exp);
8589 #endif /* PARSER_DEFS_H */
8590 diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
8591 index 18ddee7..652b02a 100644
8592 --- a/gdb/ppc-linux-nat.c
8593 +++ b/gdb/ppc-linux-nat.c
8594 @@ -2010,6 +2010,24 @@ ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
8598 +/* See target_detach_watchpoints. Do not use wrapper
8599 + ppc_linux_remove_watchpoint as it would modify the register cache
8600 + (saved_dabr_value). */
8603 +ppc_linux_detach_watchpoints (void)
8607 + tid = TIDGET (inferior_ptid);
8609 + tid = PIDGET (inferior_ptid);
8611 + if (ptrace (PTRACE_SET_DEBUGREG, tid, NULL, NULL) < 0)
8617 ppc_linux_new_thread (ptid_t ptid)
8619 @@ -2349,6 +2367,7 @@ _initialize_ppc_linux_nat (void)
8620 t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
8621 t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
8622 t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
8623 + t->to_detach_watchpoints = ppc_linux_detach_watchpoints;
8624 t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
8625 t->to_stopped_data_address = ppc_linux_stopped_data_address;
8626 t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
8627 diff --git a/gdb/printcmd.c b/gdb/printcmd.c
8628 index 5ffa099..58d9c79 100644
8629 --- a/gdb/printcmd.c
8630 +++ b/gdb/printcmd.c
8631 @@ -971,6 +971,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
8633 val = access_value_history (0);
8635 + /* Do not try to OBJECT_ADDRESS_SET here anything. We are interested in the
8636 + source variable base addresses as found by READ_VAR_VALUE. The value here
8637 + can be already a calculated expression address inappropriate for
8638 + DW_OP_push_object_address. */
8640 if (voidprint || (val && value_type (val) &&
8641 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
8643 @@ -1471,6 +1476,22 @@ x_command (char *exp, int from_tty)
8644 set_internalvar (lookup_internalvar ("__"), last_examine_value);
8648 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
8651 +print_types_mark_used (void)
8653 + struct display *d;
8655 + if (last_examine_value)
8656 + type_mark_used (value_type (last_examine_value));
8658 + for (d = display_chain; d; d = d->next)
8660 + exp_types_mark_used (d->exp);
8665 /* Add an expression to the auto-display chain.
8666 @@ -2869,4 +2890,6 @@ Show printing of source filename and line number with <symbol>."), NULL,
8667 add_com ("eval", no_class, eval_command, _("\
8668 Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
8669 a command line, and call it."));
8671 + observer_attach_mark_used (print_types_mark_used);
8673 diff --git a/gdb/psymtab.c b/gdb/psymtab.c
8674 index 97a4eec..fce19c9 100644
8677 @@ -421,6 +421,14 @@ lookup_symbol_aux_psymtabs (struct objfile *objfile,
8682 +pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
8683 + int kind, const char *name,
8684 + domain_enum domain)
8689 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
8690 Check the global symbols if GLOBAL, the static symbols if not. */
8692 @@ -941,7 +949,7 @@ psymtab_to_fullname (struct partial_symtab *ps)
8697 +static const char *
8698 find_symbol_file_from_partial (struct objfile *objfile, const char *name)
8700 struct partial_symtab *pst;
8701 @@ -1199,6 +1207,7 @@ const struct quick_symbol_functions psym_functions =
8702 forget_cached_source_info_partial,
8703 lookup_symtab_via_partial_symtab,
8704 lookup_symbol_aux_psymtabs,
8705 + pre_expand_symtabs_matching_psymtabs,
8706 print_psymtab_stats_for_objfile,
8707 dump_psymtabs_for_objfile,
8709 diff --git a/gdb/psymtab.h b/gdb/psymtab.h
8710 index 9b8c8df..de8b67e 100644
8714 /* Public partial symbol table definitions.
8716 - Copyright (C) 2009 Free Software Foundation, Inc.
8717 + Copyright (C) 2009, 2010 Free Software Foundation, Inc.
8719 This file is part of GDB.
8721 @@ -28,4 +28,6 @@ void map_partial_symbol_filenames (void (*) (const char *, const char *,
8723 extern const struct quick_symbol_functions psym_functions;
8725 +extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
8727 #endif /* PSYMTAB_H */
8728 diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
8729 new file mode 100644
8730 index 0000000..5654546
8732 +++ b/gdb/python/lib/gdb/FrameIterator.py
8734 +# Iterator over frames.
8736 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
8738 +# This program is free software; you can redistribute it and/or modify
8739 +# it under the terms of the GNU General Public License as published by
8740 +# the Free Software Foundation; either version 3 of the License, or
8741 +# (at your option) any later version.
8743 +# This program is distributed in the hope that it will be useful,
8744 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8745 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8746 +# GNU General Public License for more details.
8748 +# You should have received a copy of the GNU General Public License
8749 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8751 +class FrameIterator:
8752 + """An iterator that iterates over frames."""
8754 + def __init__ (self, frame):
8755 + "Initialize a FrameIterator. FRAME is the starting frame."
8756 + self.frame = frame
8758 + def __iter__ (self):
8762 + result = self.frame
8763 + if result is None:
8764 + raise StopIteration
8765 + self.frame = result.older ()
8767 diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
8768 new file mode 100644
8769 index 0000000..b790a54
8771 +++ b/gdb/python/lib/gdb/FrameWrapper.py
8773 +# Wrapper API for frames.
8775 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
8777 +# This program is free software; you can redistribute it and/or modify
8778 +# it under the terms of the GNU General Public License as published by
8779 +# the Free Software Foundation; either version 3 of the License, or
8780 +# (at your option) any later version.
8782 +# This program is distributed in the hope that it will be useful,
8783 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8784 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8785 +# GNU General Public License for more details.
8787 +# You should have received a copy of the GNU General Public License
8788 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8792 +# FIXME: arguably all this should be on Frame somehow.
8793 +class FrameWrapper:
8794 + def __init__ (self, frame):
8795 + self.frame = frame;
8797 + def write_symbol (self, stream, sym, block):
8798 + if len (sym.linkage_name):
8799 + nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
8800 + if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
8803 + stream.write (sym.print_name + "=")
8805 + val = self.read_var (sym)
8808 + # FIXME: would be nice to have a more precise exception here.
8809 + except RuntimeError, text:
8812 + stream.write ("???")
8814 + stream.write (str (val))
8816 + def print_frame_locals (self, stream, func):
8821 + block = func.value
8824 + if sym.is_argument:
8827 + self.write_symbol (stream, sym, block)
8828 + stream.write ('\n')
8830 + def print_frame_args (self, stream, func):
8835 + block = func.value
8838 + if not sym.is_argument:
8842 + stream.write (", ")
8844 + self.write_symbol (stream, sym, block)
8847 + # FIXME: this should probably just be a method on gdb.Frame.
8848 + # But then we need stream wrappers.
8849 + def describe (self, stream, full):
8850 + if self.type () == gdb.DUMMY_FRAME:
8851 + stream.write (" <function called from gdb>\n")
8852 + elif self.type () == gdb.SIGTRAMP_FRAME:
8853 + stream.write (" <signal handler called>\n")
8855 + sal = self.find_sal ()
8857 + name = self.name ()
8860 + if pc != sal.pc or not sal.symtab:
8861 + stream.write (" 0x%08x in" % pc)
8862 + stream.write (" " + name + " (")
8864 + func = self.function ()
8865 + self.print_frame_args (stream, func)
8867 + stream.write (")")
8869 + if sal.symtab and sal.symtab.filename:
8870 + stream.write (" at " + sal.symtab.filename)
8871 + stream.write (":" + str (sal.line))
8873 + if not self.name () or (not sal.symtab or not sal.symtab.filename):
8874 + lib = gdb.solib_address (pc)
8876 + stream.write (" from " + lib)
8878 + stream.write ("\n")
8881 + self.print_frame_locals (stream, func)
8883 + def __getattr__ (self, name):
8884 + return getattr (self.frame, name)
8885 diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
8886 new file mode 100644
8887 index 0000000..b375c68
8889 +++ b/gdb/python/lib/gdb/__init__.py
8893 +# Copyright (C) 2008 Free Software Foundation, Inc.
8895 +# This program is free software; you can redistribute it and/or modify
8896 +# it under the terms of the GNU General Public License as published by
8897 +# the Free Software Foundation; either version 3 of the License, or
8898 +# (at your option) any later version.
8900 +# This program is distributed in the hope that it will be useful,
8901 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8902 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8903 +# GNU General Public License for more details.
8905 +# You should have received a copy of the GNU General Public License
8906 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8908 +# Load the require command by default.
8909 +import gdb.command.require
8910 diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
8911 new file mode 100644
8912 index 0000000..2baab5f
8914 +++ b/gdb/python/lib/gdb/backtrace.py
8916 +# Filtering backtrace.
8918 +# Copyright (C) 2008 Free Software Foundation, Inc.
8920 +# This program is free software; you can redistribute it and/or modify
8921 +# it under the terms of the GNU General Public License as published by
8922 +# the Free Software Foundation; either version 3 of the License, or
8923 +# (at your option) any later version.
8925 +# This program is distributed in the hope that it will be useful,
8926 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8927 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8928 +# GNU General Public License for more details.
8930 +# You should have received a copy of the GNU General Public License
8931 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8936 +# Our only exports.
8937 +__all__ = ['push_frame_filter', 'create_frame_filter']
8939 +frame_filter = None
8941 +def push_frame_filter (constructor):
8942 + """Register a new backtrace filter class with the 'backtrace' command.
8943 +The filter will be passed an iterator as an argument. The iterator
8944 +will return gdb.Frame-like objects. The filter should in turn act as
8945 +an iterator returning such objects."""
8946 + global frame_filter
8947 + if frame_filter == None:
8948 + frame_filter = constructor
8950 + frame_filter = lambda iterator: constructor (frame_filter (iterator))
8952 +def create_frame_filter (iter):
8953 + global frame_filter
8954 + if frame_filter is None:
8956 + return frame_filter (iter)
8958 diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
8959 new file mode 100644
8960 index 0000000..8b13789
8962 +++ b/gdb/python/lib/gdb/command/__init__.py
8965 diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
8966 new file mode 100644
8967 index 0000000..96b6618
8969 +++ b/gdb/python/lib/gdb/command/alias.py
8973 +# Copyright (C) 2008 Free Software Foundation, Inc.
8975 +# This program is free software; you can redistribute it and/or modify
8976 +# it under the terms of the GNU General Public License as published by
8977 +# the Free Software Foundation; either version 3 of the License, or
8978 +# (at your option) any later version.
8980 +# This program is distributed in the hope that it will be useful,
8981 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8982 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8983 +# GNU General Public License for more details.
8985 +# You should have received a copy of the GNU General Public License
8986 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8990 +class AliasImplementation (gdb.Command):
8991 + def __init__ (self, name, real, doc):
8992 + # Have to set __doc__ before the super init call.
8993 + # It would be nice if gdb's help looked up __doc__ dynamically.
8994 + self.__doc__ = doc
8995 + # Note: no good way to complete :(
8996 + super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE)
8999 + def invoke(self, arg, from_tty):
9000 + gdb.execute (self.real + ' ' + arg, from_tty)
9002 +class AliasCommand (gdb.Command):
9003 + """Alias one command to another.
9004 +In the simplest form, the first word is the name of the alias, and
9005 +the remaining words are the the expansion.
9006 +An '=' by itself can be used to define a multi-word alias; words
9007 +before the '=' are the name of the new command."""
9009 + def __init__ (self):
9010 + # Completion is not quite right here.
9011 + super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE,
9012 + gdb.COMPLETE_COMMAND)
9014 + def invoke (self, arg, from_tty):
9015 + self.dont_repeat ()
9016 + # Without some form of quoting we can't alias a multi-word
9017 + # command to another command.
9018 + args = arg.split()
9020 + start = args.index ('=')
9022 + except ValueError:
9025 + target = " ".join(args[end:])
9026 + AliasImplementation (" ".join (args[0:start]), target,
9027 + "This command is an alias for '%s'." % target)
9030 diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
9031 new file mode 100644
9032 index 0000000..ec9a527
9034 +++ b/gdb/python/lib/gdb/command/backtrace.py
9036 +# New backtrace command.
9038 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9040 +# This program is free software; you can redistribute it and/or modify
9041 +# it under the terms of the GNU General Public License as published by
9042 +# the Free Software Foundation; either version 3 of the License, or
9043 +# (at your option) any later version.
9045 +# This program is distributed in the hope that it will be useful,
9046 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9047 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9048 +# GNU General Public License for more details.
9050 +# You should have received a copy of the GNU General Public License
9051 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9054 +import gdb.backtrace
9056 +from gdb.FrameIterator import FrameIterator
9057 +from gdb.FrameWrapper import FrameWrapper
9060 +class ReverseBacktraceParameter (gdb.Parameter):
9061 + """The new-backtrace command can show backtraces in 'reverse' order.
9062 +This means that the innermost frame will be printed last.
9063 +Note that reverse backtraces are more expensive to compute."""
9065 + set_doc = "Enable or disable reverse backtraces."
9066 + show_doc = "Show whether backtraces will be printed in reverse order."
9068 + def __init__(self):
9069 + gdb.Parameter.__init__ (self, "reverse-backtrace",
9070 + gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
9071 + # Default to compatibility with gdb.
9072 + self.value = False
9074 +class FilteringBacktrace (gdb.Command):
9075 + """Print backtrace of all stack frames, or innermost COUNT frames.
9076 +With a negative argument, print outermost -COUNT frames.
9077 +Use of the 'full' qualifier also prints the values of the local variables.
9078 +Use of the 'raw' qualifier avoids any filtering by loadable modules.
9081 + def __init__ (self):
9082 + # FIXME: this is not working quite well enough to replace
9083 + # "backtrace" yet.
9084 + gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
9085 + self.reverse = ReverseBacktraceParameter()
9087 + def reverse_iter (self, iter):
9090 + result.append (item)
9094 + def final_n (self, iter, x):
9097 + result.append (item)
9100 + def invoke (self, arg, from_tty):
9106 + for word in arg.split (" "):
9109 + elif word == 'raw':
9111 + elif word == 'full':
9114 + count = int (word)
9116 + # FIXME: provide option to start at selected frame
9117 + # However, should still number as if starting from newest
9118 + newest_frame = gdb.selected_thread ().newest_frame ()
9119 + iter = itertools.imap (FrameWrapper,
9120 + FrameIterator (newest_frame))
9122 + iter = gdb.backtrace.create_frame_filter (iter)
9124 + # Now wrap in an iterator that numbers the frames.
9125 + iter = itertools.izip (itertools.count (0), iter)
9127 + # Reverse if the user wanted that.
9128 + if self.reverse.value:
9129 + iter = self.reverse_iter (iter)
9131 + # Extract sub-range user wants.
9133 + iter = self.final_n (iter, count)
9135 + iter = itertools.islice (iter, 0, count)
9138 + sys.stdout.write ("#%-2d" % pair[0])
9139 + pair[1].describe (sys.stdout, full)
9141 +FilteringBacktrace()
9142 diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
9143 new file mode 100644
9144 index 0000000..6fa48ff
9146 +++ b/gdb/python/lib/gdb/command/ignore_errors.py
9148 +# Ignore errors in user commands.
9150 +# Copyright (C) 2008 Free Software Foundation, Inc.
9152 +# This program is free software; you can redistribute it and/or modify
9153 +# it under the terms of the GNU General Public License as published by
9154 +# the Free Software Foundation; either version 3 of the License, or
9155 +# (at your option) any later version.
9157 +# This program is distributed in the hope that it will be useful,
9158 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9159 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9160 +# GNU General Public License for more details.
9162 +# You should have received a copy of the GNU General Public License
9163 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9167 +class IgnoreErrorsCommand (gdb.Command):
9168 + """Execute a single command, ignoring all errors.
9169 +Only one-line commands are supported.
9170 +This is primarily useful in scripts."""
9172 + def __init__ (self):
9173 + super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
9174 + gdb.COMMAND_OBSCURE,
9176 + gdb.COMPLETE_COMMAND)
9178 + def invoke (self, arg, from_tty):
9180 + gdb.execute (arg, from_tty)
9184 +IgnoreErrorsCommand ()
9185 diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
9186 new file mode 100644
9187 index 0000000..21a0bf0
9189 +++ b/gdb/python/lib/gdb/command/pahole.py
9191 +# pahole command for gdb
9193 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9195 +# This program is free software; you can redistribute it and/or modify
9196 +# it under the terms of the GNU General Public License as published by
9197 +# the Free Software Foundation; either version 3 of the License, or
9198 +# (at your option) any later version.
9200 +# This program is distributed in the hope that it will be useful,
9201 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9202 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9203 +# GNU General Public License for more details.
9205 +# You should have received a copy of the GNU General Public License
9206 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9210 +class Pahole (gdb.Command):
9211 + """Show the holes in a structure.
9212 +This command takes a single argument, a type name.
9213 +It prints the type and displays comments showing where holes are."""
9215 + def __init__ (self):
9216 + super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
9217 + gdb.COMPLETE_SYMBOL)
9219 + def pahole (self, type, level, name):
9225 + print '%sstruct %s {' % (' ' * (2 * level), tag)
9227 + for field in type.fields ():
9228 + # Skip static fields.
9229 + if not hasattr (field, ('bitpos')):
9232 + ftype = field.type.strip_typedefs()
9234 + if bitpos != field.bitpos:
9235 + hole = field.bitpos - bitpos
9236 + print ' /* XXX %d bit hole, try to pack */' % hole
9237 + bitpos = field.bitpos
9238 + if field.bitsize > 0:
9239 + fieldsize = field.bitsize
9241 + # TARGET_CHAR_BIT here...
9242 + fieldsize = 8 * ftype.sizeof
9245 + print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
9246 + bitpos = bitpos + fieldsize
9248 + if ftype.code == gdb.TYPE_CODE_STRUCT:
9249 + self.pahole (ftype, level + 1, field.name)
9251 + print ' ' * (2 + 2 * level),
9252 + print '%s %s' % (str (ftype), field.name)
9254 + print ' ' * (14 + 2 * level),
9255 + print '} %s' % name
9257 + def invoke (self, arg, from_tty):
9258 + type = gdb.lookup_type (arg)
9259 + type = type.strip_typedefs ()
9260 + if type.code != gdb.TYPE_CODE_STRUCT:
9261 + raise TypeError, '%s is not a struct type' % arg
9263 + self.pahole (type, 0, '')
9266 diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
9267 new file mode 100644
9268 index 0000000..1fbc1e8
9270 +++ b/gdb/python/lib/gdb/command/require.py
9272 +# Demand-loading commands.
9274 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9276 +# This program is free software; you can redistribute it and/or modify
9277 +# it under the terms of the GNU General Public License as published by
9278 +# the Free Software Foundation; either version 3 of the License, or
9279 +# (at your option) any later version.
9281 +# This program is distributed in the hope that it will be useful,
9282 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9283 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9284 +# GNU General Public License for more details.
9286 +# You should have received a copy of the GNU General Public License
9287 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9292 +class RequireCommand (gdb.Command):
9293 + """Prefix command for requiring features."""
9295 + def __init__ (self):
9296 + super (RequireCommand, self).__init__ ("require",
9297 + gdb.COMMAND_SUPPORT,
9298 + gdb.COMPLETE_NONE,
9301 +class RequireSubcommand (gdb.Command):
9302 + """Demand-load a command by name."""
9304 + def __init__ (self, name):
9305 + self.__doc__ = "Demand-load a %s by name." % name
9306 + super (RequireSubcommand, self).__init__ ("require %s" % name,
9307 + gdb.COMMAND_SUPPORT)
9310 + def invoke (self, arg, from_tty):
9311 + for cmd in arg.split():
9312 + exec ('import gdb.' + self.name + '.' + cmd, globals ())
9314 + def complete (self, text, word):
9315 + dir = gdb.pythondir + '/gdb/' + self.name
9317 + for file in os.listdir(dir):
9318 + if not file.startswith (word) or not file.endswith ('.py'):
9320 + feature = file[0:-3]
9321 + if feature == 'require' or feature == '__init__':
9323 + result.append (feature)
9327 +RequireSubcommand("command")
9328 +RequireSubcommand("function")
9329 diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
9330 new file mode 100644
9331 index 0000000..6143187
9333 +++ b/gdb/python/lib/gdb/command/save_breakpoints.py
9335 +# Save breakpoints.
9337 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9339 +# This program is free software; you can redistribute it and/or modify
9340 +# it under the terms of the GNU General Public License as published by
9341 +# the Free Software Foundation; either version 3 of the License, or
9342 +# (at your option) any later version.
9344 +# This program is distributed in the hope that it will be useful,
9345 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9346 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9347 +# GNU General Public License for more details.
9349 +# You should have received a copy of the GNU General Public License
9350 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9352 +from __future__ import with_statement
9355 +class SavePrefixCommand (gdb.Command):
9356 + "Prefix command for saving things."
9358 + def __init__ (self):
9359 + super (SavePrefixCommand, self).__init__ ("save",
9360 + gdb.COMMAND_SUPPORT,
9361 + gdb.COMPLETE_NONE, True)
9363 +class SaveBreakpointsCommand (gdb.Command):
9364 + """Save the current breakpoints to a file.
9365 +This command takes a single argument, a file name.
9366 +The breakpoints can be restored using the 'source' command."""
9368 + def __init__ (self):
9369 + super (SaveBreakpointsCommand, self).__init__ ("save breakpoints",
9370 + gdb.COMMAND_SUPPORT,
9371 + gdb.COMPLETE_FILENAME)
9373 + def invoke (self, arg, from_tty):
9374 + self.dont_repeat ()
9375 + bps = gdb.breakpoints ()
9377 + raise RuntimeError, 'No breakpoints to save'
9378 + with open (arg.strip (), 'w') as f:
9380 + print >> f, "break", bp.location,
9381 + if bp.thread is not None:
9382 + print >> f, " thread", bp.thread,
9383 + if bp.condition is not None:
9384 + print >> f, " if", bp.condition,
9386 + if not bp.enabled:
9387 + print >> f, "disable $bpnum"
9388 + # Note: we don't save the ignore count; there doesn't
9389 + # seem to be much point.
9390 + commands = bp.commands
9391 + if commands is not None:
9392 + print >> f, "commands"
9393 + # Note that COMMANDS has a trailing newline.
9394 + print >> f, commands,
9398 +SavePrefixCommand ()
9399 +SaveBreakpointsCommand ()
9400 diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
9401 new file mode 100644
9402 index 0000000..faf54ed
9404 +++ b/gdb/python/lib/gdb/command/upto.py
9408 +# Copyright (C) 2009 Free Software Foundation, Inc.
9410 +# This program is free software; you can redistribute it and/or modify
9411 +# it under the terms of the GNU General Public License as published by
9412 +# the Free Software Foundation; either version 3 of the License, or
9413 +# (at your option) any later version.
9415 +# This program is distributed in the hope that it will be useful,
9416 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9417 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9418 +# GNU General Public License for more details.
9420 +# You should have received a copy of the GNU General Public License
9421 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9425 +from gdb.FrameIterator import FrameIterator
9426 +from gdb.FrameWrapper import FrameWrapper
9428 +class UptoPrefix (gdb.Command):
9429 + def __init__ (self):
9430 + super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
9433 +class UptoImplementation (gdb.Command):
9434 + def __init__ (self, subcommand):
9435 + super (UptoImplementation, self).__init__ ("upto " + subcommand,
9436 + gdb.COMMAND_STACK)
9438 + def search (self):
9439 + saved = gdb.selected_frame ()
9440 + iter = FrameIterator (saved)
9443 + for frame in iter:
9446 + if self.filter (frame):
9447 + wrapper = FrameWrapper (frame)
9448 + wrapper.describe (sys.stdout, False)
9455 + raise RuntimeError, 'Could not find a matching frame'
9457 + def invoke (self, arg, from_tty):
9458 + self.rx = re.compile (arg)
9461 +class UptoSymbolCommand (UptoImplementation):
9462 + """Select and print some calling stack frame, based on symbol.
9463 +The argument is a regular expression. This command moves up the
9464 +stack, stopping at the first frame whose symbol matches the regular
9467 + def __init__ (self):
9468 + super (UptoSymbolCommand, self).__init__ ("symbol")
9470 + def filter (self, frame):
9471 + name = frame.name ()
9472 + if name is not None:
9473 + if self.rx.search (name) is not None:
9477 +class UptoSourceCommand (UptoImplementation):
9478 + """Select and print some calling stack frame, based on source file.
9479 +The argument is a regular expression. This command moves up the
9480 +stack, stopping at the first frame whose source file name matches the
9481 +regular expression."""
9483 + def __init__ (self):
9484 + super (UptoSourceCommand, self).__init__ ("source")
9486 + def filter (self, frame):
9487 + name = frame.find_sal ().symtab.filename
9488 + if name is not None:
9489 + if self.rx.search (name) is not None:
9493 +class UptoObjectCommand (UptoImplementation):
9494 + """Select and print some calling stack frame, based on object file.
9495 +The argument is a regular expression. This command moves up the
9496 +stack, stopping at the first frame whose object file name matches the
9497 +regular expression."""
9499 + def __init__ (self):
9500 + super (UptoObjectCommand, self).__init__ ("object")
9502 + def filter (self, frame):
9503 + name = frame.find_sal ().symtab.objfile.filename
9504 + if name is not None:
9505 + if self.rx.search (name) is not None:
9509 +class UptoWhereCommand (UptoImplementation):
9510 + """Select and print some calling stack frame, based on expression.
9511 +The argument is an expression. This command moves up the stack,
9512 +parsing and evaluating the expression in each frame. This stops when
9513 +the expression evaluates to a non-zero (true) value."""
9515 + def __init__ (self):
9516 + super (UptoWhereCommand, self).__init__ ("where")
9518 + def filter (self, frame):
9520 + if gdb.parse_and_eval (self.expression):
9526 + def invoke (self, arg, from_tty):
9527 + self.expression = arg
9531 +UptoSymbolCommand ()
9532 +UptoSourceCommand ()
9533 +UptoObjectCommand ()
9534 +UptoWhereCommand ()
9535 diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
9536 new file mode 100644
9537 index 0000000..8b13789
9539 +++ b/gdb/python/lib/gdb/function/__init__.py
9542 diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
9543 new file mode 100644
9544 index 0000000..2b9c5c7
9546 +++ b/gdb/python/lib/gdb/function/caller_is.py
9548 +# Caller-is functions.
9550 +# Copyright (C) 2008 Free Software Foundation, Inc.
9552 +# This program is free software; you can redistribute it and/or modify
9553 +# it under the terms of the GNU General Public License as published by
9554 +# the Free Software Foundation; either version 3 of the License, or
9555 +# (at your option) any later version.
9557 +# This program is distributed in the hope that it will be useful,
9558 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9559 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9560 +# GNU General Public License for more details.
9562 +# You should have received a copy of the GNU General Public License
9563 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9568 +class CallerIs (gdb.Function):
9569 + """Return True if the calling function's name is equal to a string.
9570 +This function takes one or two arguments.
9571 +The first argument is the name of a function; if the calling function's
9572 +name is equal to this argument, this function returns True.
9573 +The optional second argument tells this function how many stack frames
9574 +to traverse to find the calling function. The default is 1."""
9576 + def __init__ (self):
9577 + super (CallerIs, self).__init__ ("caller_is")
9579 + def invoke (self, name, nframes = 1):
9580 + frame = gdb.selected_frame ()
9581 + while nframes > 0:
9582 + frame = frame.older ()
9583 + nframes = nframes - 1
9584 + return frame.name () == name.string ()
9586 +class CallerMatches (gdb.Function):
9587 + """Return True if the calling function's name matches a string.
9588 +This function takes one or two arguments.
9589 +The first argument is a regular expression; if the calling function's
9590 +name is matched by this argument, this function returns True.
9591 +The optional second argument tells this function how many stack frames
9592 +to traverse to find the calling function. The default is 1."""
9594 + def __init__ (self):
9595 + super (CallerMatches, self).__init__ ("caller_matches")
9597 + def invoke (self, name, nframes = 1):
9598 + frame = gdb.selected_frame ()
9599 + while nframes > 0:
9600 + frame = frame.older ()
9601 + nframes = nframes - 1
9602 + return re.match (name.string (), frame.name ()) is not None
9606 diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
9607 new file mode 100644
9608 index 0000000..debb3bb
9610 +++ b/gdb/python/lib/gdb/function/in_scope.py
9612 +# In-scope function.
9614 +# Copyright (C) 2008 Free Software Foundation, Inc.
9616 +# This program is free software; you can redistribute it and/or modify
9617 +# it under the terms of the GNU General Public License as published by
9618 +# the Free Software Foundation; either version 3 of the License, or
9619 +# (at your option) any later version.
9621 +# This program is distributed in the hope that it will be useful,
9622 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
9623 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9624 +# GNU General Public License for more details.
9626 +# You should have received a copy of the GNU General Public License
9627 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
9631 +class InScope (gdb.Function):
9632 + """Return True if all the given variables or macros are in scope.
9633 +Takes one argument for each variable name to be checked."""
9635 + def __init__ (self):
9636 + super (InScope, self).__init__ ("in_scope")
9638 + def invoke (self, *vars):
9639 + if len (vars) == 0:
9640 + raise TypeError, "in_scope takes at least one argument"
9642 + # gdb.Value isn't hashable so it can't be put in a map.
9643 + # Convert to string first.
9644 + wanted = set (map (lambda x: x.string (), vars))
9646 + block = gdb.selected_frame ().block ()
9649 + if (sym.is_argument or sym.is_constant
9650 + or sym.is_function or sym.is_variable):
9651 + if sym.name in wanted:
9652 + found.add (sym.name)
9654 + block = block.superblock
9656 + return wanted == found
9659 diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
9660 index 2cff4ba..9255336 100644
9661 --- a/gdb/python/py-cmd.c
9662 +++ b/gdb/python/py-cmd.c
9663 @@ -49,8 +49,7 @@ static struct cmdpy_completer completers[] =
9665 #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
9667 -/* A gdb command. For the time being only ordinary commands (not
9668 - set/show commands) are allowed. */
9669 +/* A gdb command. */
9673 diff --git a/gdb/python/py-hooks.c b/gdb/python/py-hooks.c
9674 new file mode 100644
9675 index 0000000..a3140bc
9677 +++ b/gdb/python/py-hooks.c
9679 +/* Notifications from gdb to Python
9681 + Copyright (C) 2008 Free Software Foundation, Inc.
9683 + This file is part of GDB.
9685 + This program is free software; you can redistribute it and/or modify
9686 + it under the terms of the GNU General Public License as published by
9687 + the Free Software Foundation; either version 3 of the License, or
9688 + (at your option) any later version.
9690 + This program is distributed in the hope that it will be useful,
9691 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9692 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9693 + GNU General Public License for more details.
9695 + You should have received a copy of the GNU General Public License
9696 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
9699 +#include "cli/cli-decode.h"
9700 +#include "charset.h"
9701 +#include "python.h"
9702 +#include "python-internal.h"
9703 +#include "observer.h"
9706 +gdbpy_get_hook_function (const char *name)
9711 + if (! PyObject_HasAttrString (gdb_module, "hooks"))
9713 + hooks = PyObject_GetAttrString (gdb_module, "hooks");
9716 + /* The cast is because the Python function doesn't declare const argument.
9717 + This is a problem in Python version 2.4, but not in 2.5. */
9718 + if (! PyObject_HasAttrString (hooks, (char *) name))
9720 + Py_DECREF (hooks);
9723 + /* The cast is because the Python function doesn't declare const argument.
9724 + This is a problem in Python version 2.4, but not in 2.5. */
9725 + result = PyObject_GetAttrString (hooks, (char *) name);
9726 + Py_DECREF (hooks);
9729 diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
9730 new file mode 100644
9731 index 0000000..7bc294c
9733 +++ b/gdb/python/py-membuf.c
9735 +/* Python interface to the inferior memory.
9737 + Copyright (C) 2008, 2009 Free Software Foundation, Inc.
9739 + This file is part of GDB.
9741 + This program is free software; you can redistribute it and/or modify
9742 + it under the terms of the GNU General Public License as published by
9743 + the Free Software Foundation; either version 3 of the License, or
9744 + (at your option) any later version.
9746 + This program is distributed in the hope that it will be useful,
9747 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9748 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9749 + GNU General Public License for more details.
9751 + You should have received a copy of the GNU General Public License
9752 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
9755 +#include "exceptions.h"
9756 +#include "gdbcore.h"
9757 +#include "python-internal.h"
9763 + /* These are kept just for mbpy_str. */
9768 +static PyTypeObject membuf_object_type;
9770 +/* Implementation of gdb.read_memory (address, length).
9771 + Returns a Python buffer object with LENGTH bytes of the inferior's memory
9772 + at ADDRESS. Both arguments are integers. */
9775 +gdbpy_read_memory (PyObject *self, PyObject *args)
9778 + CORE_ADDR addr, length;
9779 + void *buffer = NULL;
9780 + membuf_object *membuf_obj;
9781 + PyObject *addr_obj, *length_obj;
9782 + struct cleanup *cleanups = NULL;
9783 + volatile struct gdb_exception except;
9785 + if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
9788 + TRY_CATCH (except, RETURN_MASK_ALL)
9790 + if (!get_addr_from_python (addr_obj, &addr)
9791 + || !get_addr_from_python (length_obj, &length))
9797 + buffer = xmalloc (length);
9798 + cleanups = make_cleanup (xfree, buffer);
9800 + read_memory (addr, buffer, length);
9802 + GDB_PY_HANDLE_EXCEPTION (except);
9807 + discard_cleanups (cleanups);
9809 + membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
9810 + if (membuf_obj == NULL)
9813 + PyErr_SetString (PyExc_MemoryError,
9814 + "Could not allocate memory buffer object.");
9818 + membuf_obj->buffer = buffer;
9819 + membuf_obj->addr = addr;
9820 + membuf_obj->length = length;
9822 + return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
9823 + Py_END_OF_BUFFER);
9826 +/* Implementation of gdb.write_memory (address, buffer [, length]).
9827 + Writes the contents of BUFFER (a Python object supporting the read buffer
9828 + protocol) at ADDRESS in the inferior's memory. Write LENGTH bytes from
9829 + BUFFER, or its entire contents if the argument is not provided. The
9830 + function returns nothing. */
9833 +gdbpy_write_memory (PyObject *self, PyObject *args)
9835 + int buf_len, error = 0;
9836 + const char *buffer;
9837 + CORE_ADDR addr, length;
9838 + PyObject *addr_obj, *length_obj = NULL;
9839 + volatile struct gdb_exception except;
9841 + if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
9845 + TRY_CATCH (except, RETURN_MASK_ALL)
9847 + if (!get_addr_from_python (addr_obj, &addr))
9855 + else if (!get_addr_from_python (length_obj, &length))
9861 + write_memory (addr, buffer, length);
9863 + GDB_PY_HANDLE_EXCEPTION (except);
9871 +/* Destructor of Membuf objects. */
9874 +mbpy_dealloc (PyObject *self)
9876 + xfree (((membuf_object *) self)->buffer);
9877 + self->ob_type->tp_free (self);
9880 +/* Return a description of the Membuf object. */
9883 +mbpy_str (PyObject *self)
9885 + membuf_object *membuf_obj = (membuf_object *) self;
9887 + return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
9888 + paddress (membuf_obj->addr),
9889 + pulongest (membuf_obj->length));
9893 +get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
9895 + membuf_object *membuf_obj = (membuf_object *) self;
9899 + PyErr_SetString (PyExc_SystemError,
9900 + "The memory buffer supports only one segment.");
9904 + *ptrptr = membuf_obj->buffer;
9906 + return membuf_obj->length;
9910 +get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
9912 + return get_read_buffer (self, segment, ptrptr);
9916 +get_seg_count (PyObject *self, Py_ssize_t *lenp)
9919 + *lenp = ((membuf_object *) self)->length;
9925 +get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
9930 + ret = get_read_buffer (self, segment, &ptr);
9931 + *ptrptr = (char *) ptr;
9936 +/* Python doesn't provide a decent way to get compatibility here. */
9937 +#if HAVE_LIBPYTHON2_4
9938 +#define CHARBUFFERPROC_NAME getcharbufferproc
9940 +#define CHARBUFFERPROC_NAME charbufferproc
9943 +static PyBufferProcs buffer_procs = {
9947 + /* The cast here works around a difference between Python 2.4 and
9949 + (CHARBUFFERPROC_NAME) get_char_buffer
9952 +static PyTypeObject membuf_object_type = {
9953 + PyObject_HEAD_INIT (NULL)
9955 + "gdb.Membuf", /*tp_name*/
9956 + sizeof (membuf_object), /*tp_basicsize*/
9957 + 0, /*tp_itemsize*/
9958 + mbpy_dealloc, /*tp_dealloc*/
9964 + 0, /*tp_as_number*/
9965 + 0, /*tp_as_sequence*/
9966 + 0, /*tp_as_mapping*/
9969 + mbpy_str, /*tp_str*/
9970 + 0, /*tp_getattro*/
9971 + 0, /*tp_setattro*/
9972 + &buffer_procs, /*tp_as_buffer*/
9973 + Py_TPFLAGS_DEFAULT, /*tp_flags*/
9974 + "GDB memory buffer object", /*tp_doc*/
9975 + 0, /* tp_traverse */
9977 + 0, /* tp_richcompare */
9978 + 0, /* tp_weaklistoffset */
9980 + 0, /* tp_iternext */
9981 + 0, /* tp_methods */
9982 + 0, /* tp_members */
9983 + 0, /* tp_getset */
9986 + 0, /* tp_descr_get */
9987 + 0, /* tp_descr_set */
9988 + 0, /* tp_dictoffset */
9991 + PyType_GenericNew /* tp_new */
9995 +gdbpy_initialize_membuf (void)
9997 + if (PyType_Ready (&membuf_object_type) < 0)
10000 + Py_INCREF (&membuf_object_type);
10001 + PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
10003 diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
10004 index 434c8a5..b22c557 100644
10005 --- a/gdb/python/py-prettyprint.c
10006 +++ b/gdb/python/py-prettyprint.c
10007 @@ -204,10 +204,10 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
10008 && result != Py_None)
10010 *out_value = convert_value_from_python (result);
10011 - if (PyErr_Occurred ())
10012 - *out_value = NULL;
10013 - Py_DECREF (result);
10015 + if (PyErr_Occurred ())
10016 + *out_value = NULL;
10017 + Py_DECREF (result);
10022 @@ -700,14 +700,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
10025 PyObject *pretty_printer = NULL;
10026 - volatile struct gdb_exception except;
10028 - TRY_CATCH (except, RETURN_MASK_ALL)
10030 - value = value_copy (value);
10032 - GDB_PY_HANDLE_EXCEPTION (except);
10034 val_obj = value_to_value_object (value);
10037 diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
10038 index b901255..4ff18e5 100644
10039 --- a/gdb/python/py-type.c
10040 +++ b/gdb/python/py-type.c
10042 #include "demangle.h"
10043 #include "objfiles.h"
10044 #include "language.h"
10045 +#include "observer.h"
10046 +#include "gdb_assert.h"
10048 typedef struct pyty_type_object
10050 @@ -35,11 +37,17 @@ typedef struct pyty_type_object
10052 /* If a Type object is associated with an objfile, it is kept on a
10053 doubly-linked list, rooted in the objfile. This lets us copy the
10054 - underlying struct type when the objfile is deleted. */
10055 + underlying struct type when the objfile is deleted.
10057 + With NULL objfile Type still can be doubly-linked in the list
10058 + PYTY_OBJECTS_DISCARDABLE. */
10059 struct pyty_type_object *prev;
10060 struct pyty_type_object *next;
10063 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types. */
10064 +static type_object *pyty_objects_discardable;
10066 static PyTypeObject type_object_type;
10068 /* A Field object. */
10069 @@ -618,8 +626,59 @@ typy_str (PyObject *self)
10073 +/* Key associated with each objfile pointing to the first element of
10074 + a doubly-linked list of Types associated with this objfile. */
10075 static const struct objfile_data *typy_objfile_data_key;
10077 +/* Link TYPE_OBJ to its appropriate list. Either to its objfile associated one
10078 + or at least to the global list for TYPE_DISCARDABLE Types. Permanent types
10079 + do not get linked anywhere. */
10081 +typy_link (type_object *type_obj)
10083 + type_obj->prev = NULL;
10085 + if (type_obj->type && TYPE_OBJFILE (type_obj->type))
10087 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
10089 + type_obj->next = objfile_data (objfile, typy_objfile_data_key);
10090 + if (type_obj->next)
10091 + type_obj->next->prev = type_obj;
10092 + set_objfile_data (objfile, typy_objfile_data_key, type_obj);
10094 + else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
10096 + type_obj->next = pyty_objects_discardable;
10097 + if (type_obj->next)
10098 + type_obj->next->prev = type_obj;
10099 + pyty_objects_discardable = type_obj;
10102 + type_obj->next = NULL;
10105 +/* Unlink TYPE_OBJ from its current list. Permanent types are not linked
10106 + anywhere and this function has no effect on them. */
10108 +typy_unlink (type_object *type_obj)
10110 + if (type_obj->prev)
10111 + type_obj->prev->next = type_obj->next;
10112 + else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
10114 + /* Must reset head of list. */
10115 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
10117 + set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
10119 + else if (pyty_objects_discardable == type_obj)
10120 + pyty_objects_discardable = type_obj->next;
10122 + if (type_obj->next)
10123 + type_obj->next->prev = type_obj->prev;
10127 save_objfile_types (struct objfile *objfile, void *datum)
10129 @@ -637,12 +696,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
10131 type_object *next = obj->next;
10133 - htab_empty (copied_types);
10134 + gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
10135 + typy_unlink (obj);
10137 - obj->type = copy_type_recursive (objfile, obj->type, copied_types);
10138 + obj->type = copy_type_recursive (obj->type, copied_types);
10140 - obj->next = NULL;
10141 - obj->prev = NULL;
10142 + gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
10147 @@ -653,42 +713,25 @@ save_objfile_types (struct objfile *objfile, void *datum)
10151 -set_type (type_object *obj, struct type *type)
10152 +typy_dealloc (PyObject *obj)
10154 - obj->type = type;
10155 - obj->prev = NULL;
10156 - if (type && TYPE_OBJFILE (type))
10158 - struct objfile *objfile = TYPE_OBJFILE (type);
10159 + type_object *type_obj = (type_object *) obj;
10161 - obj->next = objfile_data (objfile, typy_objfile_data_key);
10163 - obj->next->prev = obj;
10164 - set_objfile_data (objfile, typy_objfile_data_key, obj);
10167 - obj->next = NULL;
10168 + typy_unlink (type_obj);
10170 + type_obj->ob_type->tp_free (obj);
10173 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
10175 -typy_dealloc (PyObject *obj)
10176 +typy_types_mark_used (void)
10178 - type_object *type = (type_object *) obj;
10181 - type->prev->next = type->next;
10182 - else if (type->type && TYPE_OBJFILE (type->type))
10184 - /* Must reset head of list. */
10185 - struct objfile *objfile = TYPE_OBJFILE (type->type);
10188 - set_objfile_data (objfile, typy_objfile_data_key, type->next);
10191 - type->next->prev = type->prev;
10192 + type_object *type_obj;
10194 - type->ob_type->tp_free (type);
10195 + for (type_obj = pyty_objects_discardable;
10196 + type_obj != NULL;
10197 + type_obj = type_obj->next)
10198 + type_mark_used (type_obj->type);
10201 /* Create a new Type referring to TYPE. */
10202 @@ -699,7 +742,10 @@ type_to_type_object (struct type *type)
10204 type_obj = PyObject_New (type_object, &type_object_type);
10206 - set_type (type_obj, type);
10208 + type_obj->type = type;
10209 + typy_link (type_obj);
10212 return (PyObject *) type_obj;
10214 @@ -773,6 +819,8 @@ gdbpy_initialize_types (void)
10216 Py_INCREF (&field_object_type);
10217 PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
10219 + observer_attach_mark_used (typy_types_mark_used);
10223 diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
10224 index 2024021..e8be12d 100644
10225 --- a/gdb/python/py-value.c
10226 +++ b/gdb/python/py-value.c
10228 #include "language.h"
10230 #include "valprint.h"
10231 +#include "observer.h"
10235 @@ -1067,6 +1068,17 @@ gdbpy_is_value_object (PyObject *obj)
10236 return PyObject_TypeCheck (obj, &value_object_type);
10239 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
10242 +python_types_mark_used (void)
10244 + value_object *iter;
10246 + for (iter = values_in_python; iter; iter = iter->next)
10247 + type_mark_used (value_type (iter->value));
10251 gdbpy_initialize_values (void)
10253 @@ -1077,6 +1089,8 @@ gdbpy_initialize_values (void)
10254 PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
10256 values_in_python = NULL;
10258 + observer_attach_mark_used (python_types_mark_used);
10262 diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
10263 index 2b8d301..0af99c8 100644
10264 --- a/gdb/python/python-internal.h
10265 +++ b/gdb/python/python-internal.h
10266 @@ -82,10 +82,11 @@ struct language_defn;
10267 struct program_space;
10269 extern PyObject *gdb_module;
10270 -extern PyTypeObject value_object_type;
10271 extern PyTypeObject block_object_type;
10272 +extern PyTypeObject value_object_type;
10273 extern PyTypeObject symbol_object_type;
10275 +/* Used in python-inferior.c. */
10279 @@ -126,6 +127,10 @@ PyObject *block_to_block_object (struct block *block, struct objfile *objfile);
10280 PyObject *value_to_value_object (struct value *v);
10281 PyObject *type_to_type_object (struct type *);
10282 PyObject *frame_info_to_frame_object (struct frame_info *frame);
10283 +PyObject *frame_info_to_frame_object (struct frame_info *frame);
10284 +thread_object *create_thread_object (struct thread_info *tp);
10285 +thread_object *find_thread_object (ptid_t ptid);
10286 +PyObject *find_inferior_object (int pid);
10288 PyObject *pspace_to_pspace_object (struct program_space *);
10289 PyObject *pspy_get_printers (PyObject *, void *);
10290 @@ -145,8 +150,11 @@ struct type *type_object_to_type (PyObject *obj);
10291 struct symtab *symtab_object_to_symtab (PyObject *obj);
10292 struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
10294 +PyObject *gdbpy_get_hook_function (const char *);
10295 void gdbpy_initialize_auto_load (void);
10297 void gdbpy_initialize_values (void);
10298 +void gdbpy_initialize_breakpoints (void);
10299 void gdbpy_initialize_frames (void);
10300 void gdbpy_initialize_symtabs (void);
10301 void gdbpy_initialize_commands (void);
10302 @@ -154,6 +162,7 @@ void gdbpy_initialize_symbols (void);
10303 void gdbpy_initialize_symtabs (void);
10304 void gdbpy_initialize_blocks (void);
10305 void gdbpy_initialize_types (void);
10306 +void gdbpy_initialize_blocks (void);
10307 void gdbpy_initialize_functions (void);
10308 void gdbpy_initialize_pspace (void);
10309 void gdbpy_initialize_objfile (void);
10310 @@ -171,6 +180,12 @@ struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
10311 extern struct gdbarch *python_gdbarch;
10312 extern const struct language_defn *python_language;
10314 +char *gdbpy_parse_command_name (char *text,
10315 + struct cmd_list_element ***base_list,
10316 + struct cmd_list_element **start_list);
10318 +PyObject *gdbpy_parameter_value (enum var_types, void *);
10320 /* Use this after a TRY_EXCEPT to throw the appropriate Python
10322 #define GDB_PY_HANDLE_EXCEPTION(Exception) \
10323 @@ -221,13 +236,14 @@ int gdbpy_is_value_object (PyObject *obj);
10324 PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
10325 struct value **replacement);
10326 PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
10327 +PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
10328 char *gdbpy_get_display_hint (PyObject *printer);
10329 PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
10331 -extern PyObject *gdbpy_doc_cst;
10332 extern PyObject *gdbpy_children_cst;
10333 extern PyObject *gdbpy_to_string_cst;
10334 extern PyObject *gdbpy_display_hint_cst;
10335 +extern PyObject *gdbpy_doc_cst;
10336 extern PyObject *gdbpy_enabled_cst;
10338 extern PyObject *gdbpy_gdberror_exc;
10339 diff --git a/gdb/python/python.c b/gdb/python/python.c
10340 index 7346fba..34708c4 100644
10341 --- a/gdb/python/python.c
10342 +++ b/gdb/python/python.c
10345 #include "language.h"
10346 #include "exceptions.h"
10347 +#include "event-loop.h"
10351 @@ -42,10 +43,17 @@ static int gdbpy_should_print_stack = 1;
10352 #include "cli/cli-decode.h"
10353 #include "charset.h"
10355 +#include "solib.h"
10356 #include "python-internal.h"
10357 +#include "linespec.h"
10358 +#include "symtab.h"
10359 +#include "source.h"
10360 #include "version.h"
10361 +#include "inferior.h"
10362 +#include "gdbthread.h"
10363 #include "target.h"
10364 #include "gdbthread.h"
10365 +#include "event-top.h"
10367 static PyMethodDef GdbMethods[];
10369 @@ -374,6 +382,105 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
10373 +/* Implementation of gdb.solib_address (Long) -> String.
10374 + Returns the name of the shared library holding a given address, or None. */
10377 +gdbpy_solib_address (PyObject *self, PyObject *args)
10379 + unsigned long long pc;
10381 + PyObject *str_obj;
10383 + if (!PyArg_ParseTuple (args, "K", &pc))
10386 + soname = solib_name_from_address (current_program_space, pc);
10388 + str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
10391 + str_obj = Py_None;
10392 + Py_INCREF (Py_None);
10398 +/* A Python function which is a wrapper for decode_line_1. */
10401 +gdbpy_decode_line (PyObject *self, PyObject *args)
10403 + struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc. */
10404 + struct symtab_and_line sal;
10405 + char *arg = NULL;
10406 + int free_sals = 0, i;
10407 + PyObject *result = NULL;
10408 + volatile struct gdb_exception except;
10410 + if (! PyArg_ParseTuple (args, "|s", &arg))
10413 + TRY_CATCH (except, RETURN_MASK_ALL)
10419 + arg = strdup (arg);
10422 + sals = decode_line_1 (©, 0, 0, 0, 0, 0);
10427 + set_default_source_symtab_and_line ();
10428 + sal = get_current_source_symtab_and_line ();
10429 + sals.sals = &sal;
10436 + if (except.reason < 0)
10439 + xfree (sals.sals);
10440 + /* We know this will always throw. */
10441 + GDB_PY_HANDLE_EXCEPTION (except);
10446 + result = PyTuple_New (sals.nelts);
10447 + for (i = 0; i < sals.nelts; ++i)
10452 + obj = symtab_and_line_to_sal_object (sals.sals[i]);
10455 + Py_DECREF (result);
10460 + PyTuple_SetItem (result, i, obj);
10465 + xfree (sals.sals);
10472 /* Parse a string and evaluate it as an expression. */
10474 gdbpy_parse_and_eval (PyObject *self, PyObject *args)
10475 @@ -414,6 +521,114 @@ source_python_script (FILE *stream, const char *file)
10479 +/* Posting and handling events. */
10481 +/* A single event. */
10482 +struct gdbpy_event
10484 + /* The Python event. This is just a callable object. */
10486 + /* The next event. */
10487 + struct gdbpy_event *next;
10490 +/* All pending events. */
10491 +static struct gdbpy_event *gdbpy_event_list;
10492 +/* The final link of the event list. */
10493 +static struct gdbpy_event **gdbpy_event_list_end;
10495 +/* We use a file handler, and not an async handler, so that we can
10496 + wake up the main thread even when it is blocked in poll(). */
10497 +static int gdbpy_event_fds[2];
10499 +/* The file handler callback. This reads from the internal pipe, and
10500 + then processes the Python event queue. This will always be run in
10501 + the main gdb thread. */
10503 +gdbpy_run_events (int err, gdb_client_data ignore)
10505 + struct cleanup *cleanup;
10506 + char buffer[100];
10509 + cleanup = ensure_python_env (get_current_arch (), current_language);
10511 + /* Just read whatever is available on the fd. It is relatively
10512 + harmless if there are any bytes left over. */
10513 + r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
10515 + while (gdbpy_event_list)
10517 + /* Dispatching the event might push a new element onto the event
10518 + loop, so we update here "atomically enough". */
10519 + struct gdbpy_event *item = gdbpy_event_list;
10520 + gdbpy_event_list = gdbpy_event_list->next;
10521 + if (gdbpy_event_list == NULL)
10522 + gdbpy_event_list_end = &gdbpy_event_list;
10524 + /* Ignore errors. */
10525 + PyObject_CallObject (item->event, NULL);
10527 + Py_DECREF (item->event);
10531 + do_cleanups (cleanup);
10534 +/* Submit an event to the gdb thread. */
10536 +gdbpy_post_event (PyObject *self, PyObject *args)
10538 + struct gdbpy_event *event;
10542 + if (!PyArg_ParseTuple (args, "O", &func))
10545 + if (!PyCallable_Check (func))
10547 + PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
10551 + Py_INCREF (func);
10553 + /* From here until the end of the function, we have the GIL, so we
10554 + can operate on our global data structures without worrying. */
10555 + wakeup = gdbpy_event_list == NULL;
10557 + event = XNEW (struct gdbpy_event);
10558 + event->event = func;
10559 + event->next = NULL;
10560 + *gdbpy_event_list_end = event;
10561 + gdbpy_event_list_end = &event->next;
10563 + /* Wake up gdb when needed. */
10566 + char c = 'q'; /* Anything. */
10567 + if (write (gdbpy_event_fds[1], &c, 1) != 1)
10568 + return PyErr_SetFromErrno (PyExc_IOError);
10574 +/* Initialize the Python event handler. */
10576 +gdbpy_initialize_events (void)
10578 + if (!pipe (gdbpy_event_fds))
10580 + gdbpy_event_list_end = &gdbpy_event_list;
10581 + add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
10589 /* A python function to write a single string using gdb's filtered
10590 @@ -459,6 +674,53 @@ gdbpy_print_stack (void)
10592 /* Return the current Progspace.
10593 There always is one. */
10594 +/* True if 'gdb -P' was used, false otherwise. */
10595 +static int running_python_script;
10597 +/* True if we are currently in a call to 'gdb.cli', false otherwise. */
10598 +static int in_cli;
10600 +/* Enter the command loop. */
10603 +gdbpy_cli (PyObject *unused1, PyObject *unused2)
10605 + if (! running_python_script || in_cli)
10606 + return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
10609 + cli_command_loop ();
10615 +/* Set up the Python argument vector and evaluate a script. This is
10616 + used to implement 'gdb -P'. */
10619 +run_python_script (int argc, char **argv)
10623 + /* We never free this, since we plan to exit at the end. */
10624 + ensure_python_env (get_current_arch (), current_language);
10626 + running_python_script = 1;
10627 + PySys_SetArgv (argc - 1, argv + 1);
10628 + input = fopen (argv[0], "r");
10631 + fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
10634 + PyRun_SimpleFile (input, argv[0]);
10643 gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
10644 @@ -720,6 +982,7 @@ Enables or disables printing of Python stack traces."),
10645 gdbpy_initialize_lazy_string ();
10646 gdbpy_initialize_thread ();
10647 gdbpy_initialize_inferior ();
10648 + gdbpy_initialize_events ();
10650 PyRun_SimpleString ("import gdb");
10651 PyRun_SimpleString ("gdb.pretty_printers = []");
10652 @@ -787,6 +1050,8 @@ static PyMethodDef GdbMethods[] =
10653 "Get a value from history" },
10654 { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
10655 "Execute a gdb command" },
10656 + { "cli", gdbpy_cli, METH_NOARGS,
10657 + "Enter the gdb CLI" },
10658 { "parameter", gdbpy_parameter, METH_VARARGS,
10659 "Return a gdb parameter's value" },
10661 @@ -825,11 +1090,21 @@ a boolean indicating if name is a field of the current implied argument\n\
10662 `this' (when the current language is object-oriented)." },
10663 { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
10664 "Return the block containing the given pc value, or None." },
10665 + { "solib_address", gdbpy_solib_address, METH_VARARGS,
10666 + "solib_address (Long) -> String.\n\
10667 +Return the name of the shared library holding a given address, or None." },
10668 + { "decode_line", gdbpy_decode_line, METH_VARARGS,
10669 + "Decode a string argument the way that 'break' or 'edit' does.\n\
10670 +Return a tuple holding the file name (or None) and line number (or None).\n\
10671 +Note: may later change to return an object." },
10672 { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
10673 "parse_and_eval (String) -> Value.\n\
10674 Parse String as an expression, evaluate it, and return the result as a Value."
10677 + { "post_event", gdbpy_post_event, METH_VARARGS,
10678 + "Post an event into gdb's event loop." },
10680 { "target_charset", gdbpy_target_charset, METH_NOARGS,
10681 "target_charset () -> string.\n\
10682 Return the name of the current target charset." },
10683 diff --git a/gdb/python/python.h b/gdb/python/python.h
10684 index affd4a4..5407878 100644
10685 --- a/gdb/python/python.h
10686 +++ b/gdb/python/python.h
10687 @@ -28,6 +28,8 @@ void eval_python_from_control_command (struct command_line *);
10689 void source_python_script (FILE *stream, const char *file);
10691 +void run_python_script (int argc, char **argv);
10693 int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
10694 int embedded_offset, CORE_ADDR address,
10695 struct ui_file *stream, int recurse,
10696 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
10697 index 1f135d4..489838d 100644
10698 --- a/gdb/solib-svr4.c
10699 +++ b/gdb/solib-svr4.c
10700 @@ -1278,7 +1278,8 @@ svr4_in_dynsym_resolve_code (CORE_ADDR pc)
10701 && pc < info->interp_text_sect_high)
10702 || (pc >= info->interp_plt_sect_low
10703 && pc < info->interp_plt_sect_high)
10704 - || in_plt_section (pc, NULL));
10705 + || in_plt_section (pc, NULL)
10706 + || in_gnu_ifunc_stub (pc));
10709 /* Given an executable's ABFD and target, compute the entry-point
10710 diff --git a/gdb/symfile.c b/gdb/symfile.c
10711 index 42f7ae3..371db0d 100644
10712 --- a/gdb/symfile.c
10713 +++ b/gdb/symfile.c
10714 @@ -1059,6 +1059,9 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
10715 const char *name = bfd_get_filename (abfd);
10716 const int from_tty = add_flags & SYMFILE_VERBOSE;
10718 + if (readnow_symbol_files)
10719 + flags |= OBJF_READNOW;
10721 my_cleanups = make_cleanup_bfd_close (abfd);
10723 /* Give user a chance to burp if we'd be
10724 @@ -1095,7 +1098,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
10725 the gdb startup command line or on a per symbol file basis. Expand
10726 all partial symbol tables for this objfile if so. */
10728 - if ((flags & OBJF_READNOW) || readnow_symbol_files)
10729 + if ((flags & OBJF_READNOW))
10731 if (from_tty || info_verbose)
10733 @@ -1533,7 +1536,7 @@ symbol_file_command (char *args, int from_tty)
10735 set_initial_language (void)
10738 + const char *filename;
10739 enum language lang = language_unknown;
10741 filename = find_main_filename ();
10742 @@ -2660,7 +2663,7 @@ init_filename_language_table (void)
10746 -deduce_language_from_filename (char *filename)
10747 +deduce_language_from_filename (const char *filename)
10751 diff --git a/gdb/symfile.h b/gdb/symfile.h
10752 index d53c465..5815354 100644
10753 --- a/gdb/symfile.h
10754 +++ b/gdb/symfile.h
10755 @@ -171,6 +171,15 @@ struct quick_symbol_functions
10756 int kind, const char *name,
10757 domain_enum domain);
10759 + /* This is called to expand symbol tables before looking up a
10760 + symbol. A backend can choose to implement this and then have its
10761 + `lookup_symbol' hook always return NULL, or the reverse. (It
10762 + doesn't make sense to implement both.) The arguments are as for
10763 + `lookup_symbol'. */
10764 + void (*pre_expand_symtabs_matching) (struct objfile *objfile,
10765 + int kind, const char *name,
10766 + domain_enum domain);
10768 /* Print statistics about any indices loaded for OBJFILE. The
10769 statistics should be printed to gdb_stdout. This is used for
10770 "maint print statistics". */
10771 @@ -201,7 +210,7 @@ struct quick_symbol_functions
10773 /* Return the file name of the file holding the symbol in OBJFILE
10774 named NAME. If no such symbol exists in OBJFILE, return NULL. */
10775 - char *(*find_symbol_file) (struct objfile *objfile, const char *name);
10776 + const char *(*find_symbol_file) (struct objfile *objfile, const char *name);
10778 /* This method is specific to Ada. It walks the partial symbol
10779 tables of OBJFILE looking for a name match. WILD_MATCH and
10780 @@ -566,6 +575,7 @@ extern struct cleanup *increment_reading_symtab (void);
10782 extern int dwarf2_has_info (struct objfile *);
10784 +extern int dwarf2_initialize_objfile (struct objfile *);
10785 extern void dwarf2_build_psymtabs (struct objfile *);
10786 extern void dwarf2_build_frame_info (struct objfile *);
10788 diff --git a/gdb/symmisc.c b/gdb/symmisc.c
10789 index 62e6b97..00dc613 100644
10790 --- a/gdb/symmisc.c
10791 +++ b/gdb/symmisc.c
10792 @@ -262,6 +262,9 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
10796 + case mst_text_gnu_ifunc:
10799 case mst_solib_trampoline:
10802 diff --git a/gdb/symtab.c b/gdb/symtab.c
10803 index 2c4c9e4..28f0450 100644
10806 @@ -1295,16 +1295,25 @@ lookup_symbol_aux_symtabs (int block_index, const char *name,
10807 const struct block *block;
10810 - ALL_PRIMARY_SYMTABS (objfile, s)
10811 + ALL_OBJFILES (objfile)
10813 - bv = BLOCKVECTOR (s);
10814 - block = BLOCKVECTOR_BLOCK (bv, block_index);
10815 - sym = lookup_block_symbol (block, name, domain);
10818 - block_found = block;
10819 - return fixup_symbol_section (sym, objfile);
10822 + objfile->sf->qf->pre_expand_symtabs_matching (objfile,
10826 + ALL_OBJFILE_SYMTABS (objfile, s)
10829 + bv = BLOCKVECTOR (s);
10830 + block = BLOCKVECTOR_BLOCK (bv, block_index);
10831 + sym = lookup_block_symbol (block, name, domain);
10834 + block_found = block;
10835 + return fixup_symbol_section (sym, objfile);
10841 @@ -1547,15 +1556,24 @@ basic_lookup_transparent_type (const char *name)
10842 of the desired name as a global, then do psymtab-to-symtab
10843 conversion on the fly and return the found symbol. */
10845 - ALL_PRIMARY_SYMTABS (objfile, s)
10846 + ALL_OBJFILES (objfile)
10848 - bv = BLOCKVECTOR (s);
10849 - block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
10850 - sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
10851 - if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
10853 - return SYMBOL_TYPE (sym);
10856 + objfile->sf->qf->pre_expand_symtabs_matching (objfile,
10858 + name, STRUCT_DOMAIN);
10860 + ALL_OBJFILE_SYMTABS (objfile, s)
10863 + bv = BLOCKVECTOR (s);
10864 + block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
10865 + sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
10866 + if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
10868 + return SYMBOL_TYPE (sym);
10873 ALL_OBJFILES (objfile)
10874 @@ -1599,14 +1617,16 @@ basic_lookup_transparent_type (const char *name)
10875 /* FIXME: What about languages without main() or specially linked
10876 executables that have no main() ? */
10880 find_main_filename (void)
10882 struct objfile *objfile;
10883 - char *result, *name = main_name ();
10884 + char *name = main_name ();
10886 ALL_OBJFILES (objfile)
10888 + const char *result;
10892 result = objfile->sf->qf->find_symbol_file (objfile, name);
10893 @@ -2914,7 +2934,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
10894 static enum minimal_symbol_type types3[]
10895 = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
10896 static enum minimal_symbol_type types4[]
10897 - = {mst_file_bss, mst_text, mst_abs, mst_unknown};
10898 + = {mst_file_bss, mst_text_gnu_ifunc, mst_abs, mst_unknown};
10899 enum minimal_symbol_type ourtype;
10900 enum minimal_symbol_type ourtype2;
10901 enum minimal_symbol_type ourtype3;
10902 diff --git a/gdb/symtab.h b/gdb/symtab.h
10903 index bedc10a..dc284e4 100644
10906 @@ -277,6 +277,9 @@ enum minimal_symbol_type
10908 mst_unknown = 0, /* Unknown type, the default */
10909 mst_text, /* Generally executable instructions */
10910 + mst_text_gnu_ifunc, /* Executable code returning address
10911 + of executable code */
10912 + mst_slot_got_plt,
10913 mst_data, /* Generally initialized data */
10914 mst_bss, /* Generally uninitialized data */
10915 mst_abs, /* Generally absolute (nonrelocatable) */
10916 @@ -917,11 +920,25 @@ extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
10918 /* lookup function from address, return name, start addr and end addr */
10920 -extern int find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *,
10922 +extern enum find_pc_partial_function_type
10924 + FIND_PC_PARTIAL_FUNCTION_NOT_FOUND = 0,
10925 + FIND_PC_PARTIAL_FUNCTION_NORMAL,
10926 + FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
10927 + } find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *, CORE_ADDR *);
10929 extern void clear_pc_function_cache (void);
10931 +extern int resolve_gnu_ifunc (const char *function_name,
10932 + CORE_ADDR *function_addressp);
10934 +extern struct minimal_symbol *resolve_gnu_ifunc_by_cache
10935 + (const char *function_name);
10937 +extern void gnu_ifunc_record_cache (struct gdbarch *gdbarch,
10938 + const char *function_name,
10939 + CORE_ADDR function_address);
10941 /* lookup partial symbol table by address and section */
10943 extern struct symtab *find_pc_sect_symtab_via_partial (CORE_ADDR,
10944 @@ -996,6 +1013,8 @@ extern struct minimal_symbol *lookup_minimal_symbol_by_pc_name
10946 extern struct minimal_symbol *lookup_minimal_symbol_by_pc (CORE_ADDR);
10948 +extern int in_gnu_ifunc_stub (CORE_ADDR pc);
10950 extern struct minimal_symbol *
10951 lookup_minimal_symbol_and_objfile (const char *,
10952 struct objfile **);
10953 @@ -1137,7 +1156,7 @@ extern char **make_source_files_completion_list (char *, char *);
10955 int matching_obj_sections (struct obj_section *, struct obj_section *);
10957 -extern char *find_main_filename (void);
10958 +extern const char *find_main_filename (void);
10960 extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
10962 @@ -1150,7 +1169,7 @@ extern void skip_prologue_sal (struct symtab_and_line *);
10964 extern void clear_symtab_users (void);
10966 -extern enum language deduce_language_from_filename (char *);
10967 +extern enum language deduce_language_from_filename (const char *);
10971 diff --git a/gdb/target.c b/gdb/target.c
10972 index 4cabcbd..34b3b60 100644
10975 @@ -123,6 +123,8 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int,
10976 static int debug_to_remove_watchpoint (CORE_ADDR, int, int,
10977 struct expression *);
10979 +static int debug_to_detach_watchpoints (void);
10981 static int debug_to_stopped_by_watchpoint (void);
10983 static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
10984 @@ -606,6 +608,7 @@ update_current_target (void)
10985 INHERIT (to_remove_hw_breakpoint, t);
10986 INHERIT (to_insert_watchpoint, t);
10987 INHERIT (to_remove_watchpoint, t);
10988 + INHERIT (to_detach_watchpoints, t);
10989 INHERIT (to_stopped_data_address, t);
10990 INHERIT (to_have_steppable_watchpoint, t);
10991 INHERIT (to_have_continuable_watchpoint, t);
10992 @@ -739,6 +742,9 @@ update_current_target (void)
10993 de_fault (to_remove_watchpoint,
10994 (int (*) (CORE_ADDR, int, int, struct expression *))
10996 + de_fault (to_detach_watchpoints,
10999 de_fault (to_stopped_by_watchpoint,
11002 @@ -3440,6 +3446,19 @@ debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type,
11007 +debug_to_detach_watchpoints (void)
11011 + retval = debug_target.to_detach_watchpoints ();
11013 + fprintf_unfiltered (gdb_stdlog,
11014 + "target_detach_watchpoints () = %ld\n",
11015 + (unsigned long) retval);
11020 debug_to_terminal_init (void)
11022 @@ -3687,6 +3706,7 @@ setup_target_debug (void)
11023 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
11024 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
11025 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
11026 + current_target.to_detach_watchpoints = debug_to_detach_watchpoints;
11027 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
11028 current_target.to_stopped_data_address = debug_to_stopped_data_address;
11029 current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
11030 diff --git a/gdb/target.h b/gdb/target.h
11031 index 3c8c017..608a742 100644
11034 @@ -433,6 +433,7 @@ struct target_ops
11035 provided with the corresponding target_* macros. */
11036 int (*to_remove_watchpoint) (CORE_ADDR, int, int, struct expression *);
11037 int (*to_insert_watchpoint) (CORE_ADDR, int, int, struct expression *);
11038 + int (*to_detach_watchpoints) (void);
11040 int (*to_stopped_by_watchpoint) (void);
11041 int to_have_steppable_watchpoint;
11042 @@ -1316,6 +1317,15 @@ extern char *normal_pid_to_str (ptid_t ptid);
11043 #define target_remove_watchpoint(addr, len, type, cond) \
11044 (*current_target.to_remove_watchpoint) (addr, len, type, cond)
11046 +/* Clear all debug registers without affecting any register caches. Function
11047 + acts on INFERIOR_PTID which should be the forked-off process, either the
11048 + non-threaded child one or the threaded parent one, depending on `set
11049 + follow-fork-mode'. Both watchpoints and hardware breakpoints get removed.
11050 + Return 0 on success, -1 on failure. */
11052 +#define target_detach_watchpoints() \
11053 + (*current_target.to_detach_watchpoints) ()
11055 #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
11056 (*current_target.to_insert_hw_breakpoint) (gdbarch, bp_tgt)
11058 @@ -1369,6 +1379,18 @@ extern int target_search_memory (CORE_ADDR start_addr,
11059 ULONGEST pattern_len,
11060 CORE_ADDR *found_addrp);
11062 +/* Utility functions which can be used by search_memory implementations. */
11064 +void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
11065 + ULONGEST *pattern_buf_size);
11067 +void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
11068 + ULONGEST *pattern_buf_size, int val_bytes);
11070 +int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
11071 + const char *pattern_buf, ULONGEST pattern_len,
11072 + CORE_ADDR *found_addr);
11074 /* Tracepoint-related operations. */
11076 #define target_trace_init() \
11077 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
11078 new file mode 100644
11079 index 0000000..83faaf6
11081 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
11083 + .file "x86_64-vla-pointer.c"
11084 + .section .debug_abbrev,"",@progbits
11086 + .section .debug_info,"",@progbits
11088 + .section .debug_line,"",@progbits
11093 + .type foo, @function
11096 + .file 1 "x86_64-vla-pointer.c"
11104 + movl %edi, -36(%rbp)
11107 + movq %rax, -48(%rbp)
11109 + movl -36(%rbp), %edx
11112 + movq %rax, -24(%rbp)
11120 + movq %rsp, -56(%rbp)
11121 + movq -56(%rbp), %rax
11125 + movq %rax, -56(%rbp)
11126 + movq -56(%rbp), %rax
11127 + movq %rax, -16(%rbp)
11129 + movl $0, -4(%rbp)
11133 + movl -4(%rbp), %esi
11134 + movl -4(%rbp), %eax
11136 + movq -16(%rbp), %rdx
11138 + movb %cl, (%rdx,%rax)
11140 + addl $1, -4(%rbp)
11142 + movl -4(%rbp), %eax
11143 + cmpl -36(%rbp), %eax
11146 + .globl break_here
11148 + movq -16(%rbp), %rax
11150 + movq -48(%rbp), %rsp
11156 + .section .debug_frame,"",@progbits
11158 + .long .LECIE0-.LSCIE0
11174 + .long .LEFDE0-.LASFDE0
11178 + .quad .LFE2-.LFB2
11180 + .long .LCFI0-.LFB2
11186 + .long .LCFI1-.LCFI0
11191 + .section .eh_frame,"a",@progbits
11193 + .long .LECIE1-.LSCIE1
11211 + .long .LEFDE1-.LASFDE1
11213 + .long .LASFDE1-.Lframe1
11215 + .long .LFE2-.LFB2
11218 + .long .LCFI0-.LFB2
11224 + .long .LCFI1-.LCFI0
11231 + .section .debug_loc,"",@progbits
11234 + .quad .LFB2-.Ltext0
11235 + .quad .LCFI0-.Ltext0
11239 + .quad .LCFI0-.Ltext0
11240 + .quad .LCFI1-.Ltext0
11244 + .quad .LCFI1-.Ltext0
11245 + .quad .LFE2-.Ltext0
11251 + .section .debug_info
11253 + .long .Ldebug_end - .Ldebug_start
11256 + .long .Ldebug_abbrev0
11265 + .long .Ldebug_line0
11275 + .long .Ltype_int - .Ldebug_relative
11280 + .long .Ltype_int - .Ldebug_relative
11286 + .byte 0x8 /* DW_AT_byte_size */
11287 + .long .Ltag_array_type - .debug_info /* DW_AT_type */
11288 + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */
11293 + .long .Ltag_pointer - .debug_info
11295 + /* Debugging only: Skip the typedef indirection. */
11296 + .long .Ltag_array_type - .debug_info
11298 + /* DW_AT_location: DW_FORM_block1: start */
11303 + .byte 0x6 /* DW_OP_deref */
11305 + .byte 0x96 /* DW_OP_nop */
11307 + /* DW_AT_location: DW_FORM_block1: end */
11312 + .long .Ltype_int - .Ldebug_relative
11323 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
11324 + .long .Ltype_char - .Ldebug_relative
11325 + .long .Ltype_ulong - .Ldebug_relative /* DW_AT_sibling: DW_FORM_ref4 */
11326 +1: /* DW_AT_data_location: DW_FORM_block1: start */
11327 + .byte 2f - 3f /* length */
11329 + .byte 0x97 /* DW_OP_push_object_address */
11331 + .byte 0x6 /* DW_OP_deref */
11333 + .byte 0x96 /* DW_OP_nop */
11335 +2: /* DW_AT_data_location: DW_FORM_block1: end */
11337 + .long .Ltype_char - .Ldebug_relative /* DW_AT_type: DW_FORM_ref4 */
11354 + .section .debug_abbrev
11412 + .uleb128 0x4 /* .Ltag_pointer abbrev */
11413 + .uleb128 0x0f /* DW_TAG_pointer_type */
11462 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
11465 + .uleb128 0x49 /* DW_AT_type */
11466 + .uleb128 0x13 /* DW_FORM_ref4 */
11467 + .uleb128 0x1 /* DW_AT_sibling */
11468 + .uleb128 0x13 /* DW_FORM_ref4 */
11469 + .uleb128 0x50 /* DW_AT_data_location */
11470 + .uleb128 0xa /* DW_FORM_block1 */
11476 + .uleb128 0x49 /* DW_AT_type */
11477 + .uleb128 0x13 /* DW_FORM_ref4 */
11503 + .section .debug_pubnames,"",@progbits
11506 + .long .Ldebug_info0
11511 + .section .debug_aranges,"",@progbits
11514 + .long .Ldebug_info0
11520 + .quad .Letext0-.Ltext0
11523 + .section .debug_str,"MS",@progbits,1
11529 + .string "x86_64-vla-pointer.c"
11531 + .string "array_t"
11535 + .string "gdb.arch"
11537 + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
11538 + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
11539 + .section .note.GNU-stack,"",@progbits
11540 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
11541 new file mode 100644
11542 index 0000000..fe2c8f7
11544 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
11546 +/* This testcase is part of GDB, the GNU debugger.
11548 + Copyright 2009 Free Software Foundation, Inc.
11550 + This program is free software; you can redistribute it and/or modify
11551 + it under the terms of the GNU General Public License as published by
11552 + the Free Software Foundation; either version 3 of the License, or
11553 + (at your option) any later version.
11555 + This program is distributed in the hope that it will be useful,
11556 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11557 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11558 + GNU General Public License for more details.
11560 + You should have received a copy of the GNU General Public License
11561 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11568 + typedef char array_t[size];
11572 + for (i = 0; i < size; i++)
11575 + array[0] = 0; /* break-here */
11589 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
11590 new file mode 100644
11591 index 0000000..d243cf1
11593 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
11595 +# Copyright 2009 Free Software Foundation, Inc.
11597 +# This program is free software; you can redistribute it and/or modify
11598 +# it under the terms of the GNU General Public License as published by
11599 +# the Free Software Foundation; either version 3 of the License, or
11600 +# (at your option) any later version.
11602 +# This program is distributed in the hope that it will be useful,
11603 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11604 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11605 +# GNU General Public License for more details.
11607 +# You should have received a copy of the GNU General Public License
11608 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11610 +if ![istarget "x86_64-*-*"] then {
11611 + verbose "Skipping over gdb.arch/x86_64-vla-pointer.exp test made only for x86_64."
11615 +set testfile x86_64-vla-pointer
11616 +set srcasmfile ${testfile}-foo.S
11617 +set srcfile ${testfile}.c
11618 +set binfile ${objdir}/${subdir}/${testfile}
11619 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
11620 +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
11621 + untested "Couldn't compile test program"
11624 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
11625 + untested "Couldn't compile test program"
11631 +gdb_reinitialize_dir $srcdir/$subdir
11632 +gdb_load ${binfile}
11634 +if ![runto_main] {
11635 + untested x86_64-vla-pointer
11639 +gdb_breakpoint "break_here"
11641 +gdb_continue_to_breakpoint "break_here"
11643 +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array"
11644 +gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array"
11646 +gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array"
11647 +gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array"
11649 +gdb_test "p (*array)\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
11650 +gdb_test "p (*array)\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
11651 +gdb_test "p (*array)\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
11652 +gdb_test "p (*array)\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
11654 +gdb_continue_to_breakpoint "break_here"
11656 +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array"
11657 +gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array"
11659 +gdb_test "whatis *array" "type = char \\\[78\\\]" "second: whatis *array"
11660 +gdb_test "ptype *array" "type = char \\\[78\\\]" "second: ptype *array"
11661 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
11662 new file mode 100644
11663 index 0000000..66f7a39
11665 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
11667 + .file "x86_64-vla-typedef.c"
11668 + .section .debug_abbrev,"",@progbits
11670 + .section .debug_info,"",@progbits
11672 + .section .debug_line,"",@progbits
11677 + .type foo, @function
11680 + .file 1 "x86_64-vla-typedef.c"
11688 + movl %edi, -36(%rbp)
11691 + movq %rax, -48(%rbp)
11693 + movl -36(%rbp), %edx
11696 + movq %rax, -24(%rbp)
11704 + movq %rsp, -56(%rbp)
11705 + movq -56(%rbp), %rax
11709 + movq %rax, -56(%rbp)
11710 + movq -56(%rbp), %rax
11711 + movq %rax, -16(%rbp)
11713 + movl $0, -4(%rbp)
11717 + movl -4(%rbp), %esi
11718 + movl -4(%rbp), %eax
11720 + movq -16(%rbp), %rdx
11722 + movb %cl, (%rdx,%rax)
11724 + addl $1, -4(%rbp)
11726 + movl -4(%rbp), %eax
11727 + cmpl -36(%rbp), %eax
11730 + .globl break_here
11732 + movq -16(%rbp), %rax
11734 + movq -48(%rbp), %rsp
11740 + .section .debug_frame,"",@progbits
11742 + .long .LECIE0-.LSCIE0
11758 + .long .LEFDE0-.LASFDE0
11762 + .quad .LFE2-.LFB2
11764 + .long .LCFI0-.LFB2
11770 + .long .LCFI1-.LCFI0
11775 + .section .eh_frame,"a",@progbits
11777 + .long .LECIE1-.LSCIE1
11795 + .long .LEFDE1-.LASFDE1
11797 + .long .LASFDE1-.Lframe1
11799 + .long .LFE2-.LFB2
11802 + .long .LCFI0-.LFB2
11808 + .long .LCFI1-.LCFI0
11815 + .section .debug_loc,"",@progbits
11818 + .quad .LFB2-.Ltext0
11819 + .quad .LCFI0-.Ltext0
11823 + .quad .LCFI0-.Ltext0
11824 + .quad .LCFI1-.Ltext0
11828 + .quad .LCFI1-.Ltext0
11829 + .quad .LFE2-.Ltext0
11835 + .section .debug_info
11836 + .long .Ldebug_end - .Ldebug_start
11839 + .long .Ldebug_abbrev0
11848 + .long .Ldebug_line0
11872 + .long .Ltag_array_type - .debug_info
11873 + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */
11878 + .long .Ltag_typedef - .debug_info
11880 + /* Debugging only: Skip the typedef indirection. */
11881 + .long .Ltag_array_type - .debug_info
11883 + /* DW_AT_location: DW_FORM_block1: start */
11888 + .byte 0x6 /* DW_OP_deref */
11890 + .byte 0x96 /* DW_OP_nop */
11892 + /* DW_AT_location: DW_FORM_block1: end */
11907 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
11908 + .long 0xa0 + (2f - 1f) /* DW_AT_type: DW_FORM_ref4 */
11909 + .long 0x9d + (2f - 1f) /* DW_AT_sibling: DW_FORM_ref4 */
11910 +1: /* DW_AT_data_location: DW_FORM_block1: start */
11911 + .byte 2f - 3f /* length */
11913 + .byte 0x97 /* DW_OP_push_object_address */
11914 + .byte 0x6 /* DW_OP_deref */
11915 +2: /* DW_AT_data_location: DW_FORM_block1: end */
11917 + .long 0x9d + (2b - 1b) /* DW_AT_type: DW_FORM_ref4 */
11932 + .section .debug_abbrev
12044 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
12047 + .uleb128 0x49 /* DW_AT_type */
12048 + .uleb128 0x13 /* DW_FORM_ref4 */
12049 + .uleb128 0x1 /* DW_AT_sibling */
12050 + .uleb128 0x13 /* DW_FORM_ref4 */
12051 + .uleb128 0x50 /* DW_AT_data_location */
12052 + .uleb128 0xa /* DW_FORM_block1 */
12058 + .uleb128 0x49 /* DW_AT_type */
12059 + .uleb128 0x13 /* DW_FORM_ref4 */
12085 + .section .debug_pubnames,"",@progbits
12088 + .long .Ldebug_info0
12093 + .section .debug_aranges,"",@progbits
12096 + .long .Ldebug_info0
12102 + .quad .Letext0-.Ltext0
12105 + .section .debug_str,"MS",@progbits,1
12111 + .string "x86_64-vla-typedef.c"
12113 + .string "array_t"
12117 + .string "gdb.arch"
12119 + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
12120 + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
12121 + .section .note.GNU-stack,"",@progbits
12122 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
12123 new file mode 100644
12124 index 0000000..b809c4e
12126 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
12128 +/* This testcase is part of GDB, the GNU debugger.
12130 + Copyright 2008 Free Software Foundation, Inc.
12132 + This program is free software; you can redistribute it and/or modify
12133 + it under the terms of the GNU General Public License as published by
12134 + the Free Software Foundation; either version 3 of the License, or
12135 + (at your option) any later version.
12137 + This program is distributed in the hope that it will be useful,
12138 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12139 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12140 + GNU General Public License for more details.
12142 + You should have received a copy of the GNU General Public License
12143 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12150 + typedef char array_t[size];
12154 + for (i = 0; i < size; i++)
12157 + array[0] = 0; /* break-here */
12171 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
12172 new file mode 100644
12173 index 0000000..b05411e
12175 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
12177 +# Copyright 2009 Free Software Foundation, Inc.
12179 +# This program is free software; you can redistribute it and/or modify
12180 +# it under the terms of the GNU General Public License as published by
12181 +# the Free Software Foundation; either version 3 of the License, or
12182 +# (at your option) any later version.
12184 +# This program is distributed in the hope that it will be useful,
12185 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12186 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12187 +# GNU General Public License for more details.
12189 +# You should have received a copy of the GNU General Public License
12190 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12192 +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
12194 +if ![istarget "x86_64-*-*"] then {
12195 + verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
12199 +set testfile x86_64-vla-typedef
12200 +set srcasmfile ${testfile}-foo.S
12201 +set srcfile ${testfile}.c
12202 +set binfile ${objdir}/${subdir}/${testfile}
12203 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
12204 +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
12205 + untested "Couldn't compile test program"
12208 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
12209 + untested "Couldn't compile test program"
12215 +gdb_reinitialize_dir $srcdir/$subdir
12216 +gdb_load ${binfile}
12218 +if ![runto_main] {
12219 + untested x86_64-vla-typedef
12223 +gdb_breakpoint "break_here"
12225 +gdb_continue_to_breakpoint "break_here"
12227 +gdb_test "whatis array" "type = array_t" "first: whatis array"
12229 +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
12231 +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
12232 +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
12233 +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
12234 +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
12236 +gdb_continue_to_breakpoint "break_here"
12238 +gdb_test "whatis array" "type = array_t" "second: whatis array"
12240 +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
12241 diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
12242 index ecc3289..f79ad40 100644
12243 --- a/gdb/testsuite/gdb.base/arrayidx.c
12244 +++ b/gdb/testsuite/gdb.base/arrayidx.c
12247 int array[] = {1, 2, 3, 4};
12259 diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
12260 index 3a33618..f2e11dd 100644
12261 --- a/gdb/testsuite/gdb.base/arrayidx.exp
12262 +++ b/gdb/testsuite/gdb.base/arrayidx.exp
12263 @@ -57,4 +57,12 @@ gdb_test "print array" \
12264 "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
12265 "Print array with array-indexes on"
12268 +set test "p unbound.a == &unbound.a\[0\]"
12269 +gdb_test_multiple $test $test {
12270 + -re " = 1\r\n$gdb_prompt $" {
12273 + -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
12274 + unsupported "$test (no GCC)"
12277 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc-lib.c b/gdb/testsuite/gdb.base/gnu-ifunc-lib.c
12278 new file mode 100644
12279 index 0000000..680530a
12281 +++ b/gdb/testsuite/gdb.base/gnu-ifunc-lib.c
12283 +/* This testcase is part of GDB, the GNU debugger.
12285 + Copyright 2009, 2010 Free Software Foundation, Inc.
12287 + This program is free software; you can redistribute it and/or modify
12288 + it under the terms of the GNU General Public License as published by
12289 + the Free Software Foundation; either version 3 of the License, or
12290 + (at your option) any later version.
12292 + This program is distributed in the hope that it will be useful,
12293 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12294 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12295 + GNU General Public License for more details.
12297 + You should have received a copy of the GNU General Public License
12298 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12300 +extern volatile int gnu_ifunc_initialized;
12301 +extern int init_stub (int arg);
12302 +extern int final (int arg);
12304 +typedef int (*final_t) (int arg);
12306 +asm (".type gnu_ifunc, @gnu_indirect_function");
12311 + if (! gnu_ifunc_initialized)
12312 + return init_stub;
12316 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.c b/gdb/testsuite/gdb.base/gnu-ifunc.c
12317 new file mode 100644
12318 index 0000000..106271f
12320 +++ b/gdb/testsuite/gdb.base/gnu-ifunc.c
12322 +/* This testcase is part of GDB, the GNU debugger.
12324 + Copyright 2009, 2010 Free Software Foundation, Inc.
12326 + This program is free software; you can redistribute it and/or modify
12327 + it under the terms of the GNU General Public License as published by
12328 + the Free Software Foundation; either version 3 of the License, or
12329 + (at your option) any later version.
12331 + This program is distributed in the hope that it will be useful,
12332 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12333 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12334 + GNU General Public License for more details.
12336 + You should have received a copy of the GNU General Public License
12337 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12339 +#include <assert.h>
12342 +init_stub (int arg)
12353 +/* Make differentiation of how the gnu_ifunc call resolves before and after
12354 + calling gnu_ifunc_pre. This ensures the resolved function address is not
12355 + being cached anywhere for the debugging purposes. */
12357 +volatile int gnu_ifunc_initialized;
12360 +gnu_ifunc_pre (void)
12362 + assert (!gnu_ifunc_initialized);
12364 + gnu_ifunc_initialized = 1;
12367 +extern int gnu_ifunc (int arg);
12374 + gnu_ifunc_pre ();
12376 + i = gnu_ifunc (1); /* break-at-call */
12379 + gnu_ifunc (2); /* break-at-nextcall */
12381 + return 0; /* break-at-exit */
12383 diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp
12384 new file mode 100644
12385 index 0000000..8ecf558
12387 +++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp
12389 +# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
12391 +# This program is free software; you can redistribute it and/or modify
12392 +# it under the terms of the GNU General Public License as published by
12393 +# the Free Software Foundation; either version 3 of the License, or
12394 +# (at your option) any later version.
12396 +# This program is distributed in the hope that it will be useful,
12397 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12398 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12399 +# GNU General Public License for more details.
12401 +# You should have received a copy of the GNU General Public License
12402 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12404 +if {[skip_shlib_tests]} {
12408 +set testfile "gnu-ifunc"
12409 +set srcfile ${testfile}.c
12410 +set binfile ${objdir}/${subdir}/${testfile}
12412 +set libfile "${testfile}-lib"
12413 +set libsrc ${libfile}.c
12414 +set lib_so ${objdir}/${subdir}/${libfile}.so
12416 +# We need DWARF for the "final" function as we "step" into the function and GDB
12417 +# would step-over the "final" function if there would be no line number debug
12418 +# information (DWARF) available.
12420 +# We must not have DWARF for the "gnu_ifunc" function as DWARF has no way to
12421 +# express the gnu-ifunc type and it would be considered as a regular function
12422 +# due to DWARF by GDB. In ELF gnu-ifunc is expressed by the STT_GNU_IFUNC type.
12424 +# Both functions need to be in the same shared library file but
12425 +# gdb_compile_shlib has no way to specify source-specific compilation options.
12427 +# Therefore $libfile contains only the gnu-ifunc function with no DWARF
12428 +# referencing all the other parts from the main executable with DWARF.
12431 +set exec_opts [list debug shlib=$lib_so]
12433 +if [get_compiler_info ${binfile}] {
12437 +if { [gdb_compile_shlib ${srcdir}/${subdir}/$libsrc $lib_so $lib_opts] != ""
12438 + || [gdb_compile ${srcdir}/${subdir}/$srcfile $binfile executable $exec_opts] != ""} {
12439 + untested "Could not compile either $libsrc or $srcfile."
12443 +# Start with a fresh gdb.
12445 +clean_restart $testfile
12446 +gdb_load_shlibs ${lib_so}
12448 +if ![runto_main] then {
12449 + fail "Can't run to main"
12453 +# The "if" condition is artifical to test regression of a former patch.
12454 +gdb_breakpoint "[gdb_get_line_number "break-at-nextcall"] if i && gnu_ifunc (i) != 42"
12456 +gdb_breakpoint [gdb_get_line_number "break-at-call"]
12457 +gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*"
12459 +# Test GDB will automatically indirect the call.
12461 +gdb_test "p gnu_ifunc (3)" " = 4"
12463 +# Test GDB will skip the gnu_ifunc resolver on first call.
12465 +gdb_test "step" "\r\nfinal .*"
12467 +# Test GDB will not break before the final chosen implementation.
12469 +# Also test a former patch regression:
12471 +# Error in testing breakpoint condition:
12472 +# Attempt to take address of value not located in memory.
12474 +# Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33
12476 +gdb_test "continue" "Continuing.\r\n\r\nBreakpoint .* (at|in) .*break-at-nextcall.*" \
12477 + "continue to break-at-nextcall"
12479 +gdb_breakpoint "gnu_ifunc"
12481 +gdb_continue_to_breakpoint "nextcall gnu_ifunc"
12483 +gdb_test "frame" "#0 +(0x\[0-9a-f\]+ in +)?final \\(.*" "nextcall gnu_ifunc skipped"
12486 +# Check any commands not doing an inferior call still compute with address of
12487 +# the gnu-ifunc resolver.
12489 +gdb_test "p gnu_ifunc" " = {<text gnu-indirect-function variable, no debug info>} 0x\[0-9a-f\]+ <gnu_ifunc>" "p gnu_ifunc executing"
12490 +gdb_test "info sym gnu_ifunc" "gnu_ifunc in section .*" "info sym gnu_ifunc executing"
12492 +set test "info addr gnu_ifunc"
12493 +gdb_test_multiple $test $test {
12494 + -re "Symbol \"gnu_ifunc\" is at (0x\[0-9a-f\]+) in .*$gdb_prompt $" {
12498 +gdb_test "info sym $expect_out(1,string)" "gnu_ifunc in section .*" "info sym <gnu_ifunc-address>"
12499 diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.c b/gdb/testsuite/gdb.base/internal-var-field-address.c
12500 new file mode 100644
12501 index 0000000..eeb7b85
12503 +++ b/gdb/testsuite/gdb.base/internal-var-field-address.c
12505 +/* This testcase is part of GDB, the GNU debugger.
12507 + Copyright 2009 Free Software Foundation, Inc.
12509 + This program is free software; you can redistribute it and/or modify
12510 + it under the terms of the GNU General Public License as published by
12511 + the Free Software Foundation; either version 3 of the License, or
12512 + (at your option) any later version.
12514 + This program is distributed in the hope that it will be useful,
12515 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12516 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12517 + GNU General Public License for more details.
12519 + You should have received a copy of the GNU General Public License
12520 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12524 +} staticstruct = { 1 };
12525 diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.exp b/gdb/testsuite/gdb.base/internal-var-field-address.exp
12526 new file mode 100644
12527 index 0000000..6d82e73
12529 +++ b/gdb/testsuite/gdb.base/internal-var-field-address.exp
12531 +# Copyright 2009 Free Software Foundation, Inc.
12533 +# This program is free software; you can redistribute it and/or modify
12534 +# it under the terms of the GNU General Public License as published by
12535 +# the Free Software Foundation; either version 3 of the License, or
12536 +# (at your option) any later version.
12538 +# This program is distributed in the hope that it will be useful,
12539 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12540 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12541 +# GNU General Public License for more details.
12543 +# You should have received a copy of the GNU General Public License
12544 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12546 +set test internal-var-field-address
12547 +set binfile ${test}.x
12548 +if { [gdb_compile "${srcdir}/${subdir}/${test}.c" "${objdir}/${subdir}/${binfile}" object {debug}] != "" } {
12549 + untested "Couldn't compile test program"
12553 +clean_restart $binfile
12555 +gdb_test {set $varstruct = staticstruct}
12556 +gdb_test {p $varstruct.field} " = 1"
12557 diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
12558 new file mode 100644
12559 index 0000000..c5d5ee0
12561 +++ b/gdb/testsuite/gdb.base/vla-overflow.c
12563 +/* This testcase is part of GDB, the GNU debugger.
12565 + Copyright 2008 Free Software Foundation, Inc.
12567 + This program is free software; you can redistribute it and/or modify
12568 + it under the terms of the GNU General Public License as published by
12569 + the Free Software Foundation; either version 3 of the License, or
12570 + (at your option) any later version.
12572 + This program is distributed in the hope that it will be useful,
12573 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12574 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12575 + GNU General Public License for more details.
12577 + You should have received a copy of the GNU General Public License
12578 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12580 +#include <stdlib.h>
12583 +main (int argc, char **argv)
12587 + array[0] = array[0];
12593 diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
12594 new file mode 100644
12595 index 0000000..24a608f
12597 +++ b/gdb/testsuite/gdb.base/vla-overflow.exp
12599 +# Copyright 2008 Free Software Foundation, Inc.
12601 +# This program is free software; you can redistribute it and/or modify
12602 +# it under the terms of the GNU General Public License as published by
12603 +# the Free Software Foundation; either version 3 of the License, or
12604 +# (at your option) any later version.
12606 +# This program is distributed in the hope that it will be useful,
12607 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12608 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12609 +# GNU General Public License for more details.
12611 +# You should have received a copy of the GNU General Public License
12612 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12614 +# We could crash in:
12615 +# #0 block_linkage_function (bl=0x0) at ../../gdb/block.c:69
12616 +# #1 in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
12617 +# 97 framefunc = block_linkage_function (get_frame_block (frame, NULL));
12618 +# #2 in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
12619 +# #3 in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
12620 +# #4 dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
12621 +# #5 in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
12622 +# #6 in create_array_type (...) at ../../gdb/gdbtypes.c:840
12624 +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
12626 +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
12628 +set testfile vla-overflow
12629 +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
12630 +set srcfile ${testfile}.c
12631 +set binfile ${objdir}/${subdir}/${testfile}
12632 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
12633 + untested "Couldn't compile test program"
12637 +set f [open "|getconf PAGESIZE" "r"]
12643 +gdb_reinitialize_dir $srcdir/$subdir
12644 +gdb_load ${binfile}
12646 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
12648 +if { [runto_main] < 0 } {
12649 + untested vla-overflow
12653 +# Get the GDB memory size when we stay at main.
12655 +proc memory_v_pages_get {} {
12656 + global pid_of_gdb pagesize
12657 + set fd [open "/proc/$pid_of_gdb/statm"]
12660 + # number of pages of virtual memory
12661 + scan $line "%d" drs
12665 +set pages_found [memory_v_pages_get]
12667 +# s390x with glibc-debuginfo.s390x installed used approx. 16MB.
12669 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
12670 +set kb_found [expr $pages_found * $pagesize / 1024]
12671 +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
12672 +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
12674 +# Create the ulimit wrapper.
12675 +set f [open $shfile "w"]
12676 +puts $f "#! /bin/sh"
12677 +puts $f "ulimit -v $kb_permit"
12678 +puts $f "exec $GDB \"\$@\""
12680 +remote_exec host "chmod +x $shfile"
12688 +gdb_reinitialize_dir $srcdir/$subdir
12689 +gdb_load ${binfile}
12691 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
12693 +# Check the size again after the second run.
12694 +# We must not stop in main as it would cache `array' and never crash later.
12698 +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
12700 +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
12702 +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
12704 +# `abort' can get expressed as `*__GI_abort'.
12705 +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
12707 +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
12708 diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
12709 new file mode 100644
12710 index 0000000..e1f3ed1
12712 +++ b/gdb/testsuite/gdb.base/vla.c
12714 +/* This testcase is part of GDB, the GNU debugger.
12716 + Copyright 2008 Free Software Foundation, Inc.
12718 + This program is free software; you can redistribute it and/or modify
12719 + it under the terms of the GNU General Public License as published by
12720 + the Free Software Foundation; either version 3 of the License, or
12721 + (at your option) any later version.
12723 + This program is distributed in the hope that it will be useful,
12724 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12725 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12726 + GNU General Public License for more details.
12728 + You should have received a copy of the GNU General Public License
12729 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12731 +#include <string.h>
12739 +bar (char *a, char *b, char *c, int size)
12741 + memset (a, '1', size);
12742 + memset (b, '2', size);
12743 + memset (c, '3', 48);
12749 + char temp1[size];
12752 + temp1[size - 1] = '\0';
12754 + char temp2[size];
12756 + bar (temp1, temp2, temp3, size);
12758 + marker (); /* break-here */
12769 diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
12770 new file mode 100644
12771 index 0000000..5da7378
12773 +++ b/gdb/testsuite/gdb.base/vla.exp
12775 +# Copyright 2008 Free Software Foundation, Inc.
12777 +# This program is free software; you can redistribute it and/or modify
12778 +# it under the terms of the GNU General Public License as published by
12779 +# the Free Software Foundation; either version 3 of the License, or
12780 +# (at your option) any later version.
12782 +# This program is distributed in the hope that it will be useful,
12783 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12784 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12785 +# GNU General Public License for more details.
12787 +# You should have received a copy of the GNU General Public License
12788 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12791 +set srcfile ${testfile}.c
12792 +set binfile ${objdir}/${subdir}/${testfile}
12793 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
12794 + untested "Couldn't compile test program"
12800 +gdb_reinitialize_dir $srcdir/$subdir
12801 +gdb_load ${binfile}
12803 +if ![runto_main] {
12808 +gdb_breakpoint [gdb_get_line_number "break-here"]
12810 +gdb_continue_to_breakpoint "break-here"
12812 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
12813 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
12814 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
12816 +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
12817 +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
12818 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
12820 +gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
12821 +gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
12822 +gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
12824 +gdb_continue_to_breakpoint "break-here"
12826 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
12827 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
12828 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
12830 +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
12831 +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
12832 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
12834 +gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
12835 +gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
12836 +gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
12837 diff --git a/gdb/testsuite/gdb.cp/gdb9593.cc b/gdb/testsuite/gdb.cp/gdb9593.cc
12838 new file mode 100644
12839 index 0000000..783c962
12841 +++ b/gdb/testsuite/gdb.cp/gdb9593.cc
12843 +/* This testcase is part of GDB, the GNU debugger.
12845 + Copyright 2008, 2009 Free Software Foundation, Inc.
12847 + This program is free software; you can redistribute it and/or modify
12848 + it under the terms of the GNU General Public License as published by
12849 + the Free Software Foundation; either version 3 of the License, or
12850 + (at your option) any later version.
12852 + This program is distributed in the hope that it will be useful,
12853 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12854 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12855 + GNU General Public License for more details.
12857 + You should have received a copy of the GNU General Public License
12858 + along with this program. If not, see <http://www.gnu.org/licenses/>.
12860 +#include <iostream>
12862 +using namespace std;
12864 +class NextOverThrowDerivates
12870 + // Single throw an exception in this function.
12876 + // Throw an exception in another function.
12882 + // Throw an exception in another function, but handle it
12884 + void function3 ()
12893 + cout << "Caught and handled function1 exception" << endl;
12912 + // We use this to test that a "finish" here does not end up in
12913 + // this frame, but in the one above.
12921 + function1 (); // marker for until
12927 + function1 (); // until here
12931 +NextOverThrowDerivates next_cases;
12938 + next_cases.function1 ();
12947 + next_cases.function2 ();
12956 + // This is duplicated so we can next over one but step into
12958 + next_cases.function2 ();
12965 + next_cases.function3 ();
12969 + next_cases.rethrow ();
12978 + // Another duplicate so we can test "finish".
12979 + next_cases.function2 ();
12986 + // Another test for "finish".
12989 + next_cases.finish ();
12995 + // Test of "until".
12998 + next_cases.finish ();
13004 + // Test of "until" with an argument.
13007 + next_cases.until ();
13013 + // Test of "advance".
13016 + next_cases.until ();
13023 diff --git a/gdb/testsuite/gdb.cp/gdb9593.exp b/gdb/testsuite/gdb.cp/gdb9593.exp
13024 new file mode 100644
13025 index 0000000..3dad7ca
13027 +++ b/gdb/testsuite/gdb.cp/gdb9593.exp
13029 +# Copyright 2008, 2009 Free Software Foundation, Inc.
13031 +# This program is free software; you can redistribute it and/or modify
13032 +# it under the terms of the GNU General Public License as published by
13033 +# the Free Software Foundation; either version 3 of the License, or
13034 +# (at your option) any later version.
13036 +# This program is distributed in the hope that it will be useful,
13037 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13038 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13039 +# GNU General Public License for more details.
13041 +# You should have received a copy of the GNU General Public License
13042 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13045 +if $tracelevel then {
13046 + strace $tracelevel
13049 +if { [skip_cplus_tests] } { continue }
13051 +set testfile "gdb9593"
13052 +set srcfile ${testfile}.cc
13053 +set binfile $objdir/$subdir/$testfile
13055 +# Create and source the file that provides information about the compiler
13056 +# used to compile the test case.
13057 +if [get_compiler_info ${binfile} "c++"] {
13058 + untested gdb9593.exp
13062 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
13063 + untested gdb9593.exp
13067 +# Some targets can't do function calls, so don't even bother with this
13069 +if [target_info exists gdb,cannot_call_functions] {
13070 + setup_xfail "*-*-*" 9593
13071 + fail "This target can not call functions"
13077 +gdb_reinitialize_dir $srcdir/$subdir
13078 +gdb_load ${binfile}
13080 +if ![runto_main] then {
13081 + perror "couldn't run to main"
13085 +# See whether we have the needed unwinder hooks.
13087 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
13088 + -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
13089 + pass "check for unwinder hook"
13091 + -re "No symbol .* in current context.\r\n$gdb_prompt $" {
13092 + # Pass the test so we don't get bogus fails in the results.
13093 + pass "check for unwinder hook"
13098 + untested gdb9593.exp
13102 +# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
13105 + ".*catch (...).*" \
13106 + "next over a throw 1"
13109 + ".*next_cases.function2.*" \
13110 + "next past catch 1"
13113 + ".*catch (...).*" \
13114 + "next over a throw 2"
13117 + ".*next_cases.function2.*" \
13118 + "next past catch 2"
13121 + ".*function1().*" \
13122 + "step into function2 1"
13125 + ".*catch (...).*" \
13126 + "next over a throw 3"
13129 + ".*next_cases.function3.*" \
13130 + "next past catch 3"
13133 + ".*next_cases.rethrow.*" \
13134 + "next over a throw 4"
13137 + ".*catch (...).*" \
13138 + "next over a rethrow"
13141 + ".*next_cases.function2.*" \
13142 + "next after a rethrow"
13145 + ".*function1().*" \
13146 + "step into function2 2"
13148 +gdb_test "finish" \
13149 + ".*catch (...).*" \
13153 + ".*next_cases.finish ().*" \
13154 + "next past catch 4"
13157 + ".*function1 ().*" \
13158 + "step into finish method"
13160 +gdb_test "finish" \
13161 + ".*catch (...).*" \
13165 + ".*next_cases.finish ().*" \
13166 + "next past catch 5"
13169 + ".*function1 ().*" \
13170 + "step into finish, for until"
13172 +gdb_test "until" \
13173 + ".*function1 ().*" \
13174 + "until with no argument 1"
13176 +set line [gdb_get_line_number "marker for until" $testfile.cc]
13178 +gdb_test "until $line" \
13179 + ".*function1 ().*" \
13180 + "next past catch 6"
13182 +gdb_test "until" \
13183 + ".*catch (...).*" \
13184 + "until with no argument 2"
13186 +set line [gdb_get_line_number "until here" $testfile.cc]
13189 + ".*next_cases.until ().*" \
13190 + "next past catch 6"
13193 + ".*function1 ().*" \
13194 + "step into until"
13196 +gdb_test "until $line" \
13197 + ".*catch (...).*" \
13198 + "until-over-throw"
13201 + ".*next_cases.until ().*" \
13202 + "next past catch 7"
13205 + ".*function1 ().*" \
13206 + "step into until, for advance"
13208 +gdb_test "advance $line" \
13209 + ".*catch (...).*" \
13210 + "advance-over-throw"
13211 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
13212 new file mode 100644
13213 index 0000000..7fb00ea
13215 +++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
13217 +/* This testcase is part of GDB, the GNU debugger.
13219 + Copyright 2010 Free Software Foundation, Inc.
13221 + This program is free software; you can redistribute it and/or modify
13222 + it under the terms of the GNU General Public License as published by
13223 + the Free Software Foundation; either version 3 of the License, or
13224 + (at your option) any later version.
13226 + This program is distributed in the hope that it will be useful,
13227 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13228 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13229 + GNU General Public License for more details.
13231 + You should have received a copy of the GNU General Public License
13232 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13234 +/* Debug information */
13236 +/* We will `break *main' at the very first instruction. */
13237 +#define main_length 1
13241 + /* See DW_OP_lit3 + 1 (0-based). */
13242 + .string "seennotseen"
13244 + .section .debug_info
13246 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
13248 + .2byte 2 /* DWARF version number */
13249 + .4byte .Ldebug_abbrev0 /* Offset Into Abbrev. Section */
13250 + .byte 4 /* Pointer Size (in bytes) */
13253 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
13254 + .4byte .Lproducer /* DW_AT_producer */
13255 + /* Use C++ to exploit a bug in parsing DW_AT_name "". */
13256 + .byte 4 /* DW_AT_language (C++) - */
13257 + .4byte main /* DW_AT_low_pc */
13258 + .byte main_length /* DW_AT_high_pc */
13261 + .uleb128 2 /* Abbrev: DW_TAG_array_type */
13262 + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
13264 + .uleb128 3 /* Abbrev: DW_TAG_subrange_type */
13265 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
13266 + .byte 0 /* DW_AT_lower_bound */
13267 + .4byte .Llen_var-.Lcu1_begin /* DW_AT_upper_bound */
13268 + .byte 0 /* End of children of die */
13270 + /* DW_AT_upper_bound is referencing an optimized-out variable. */
13272 + .uleb128 2 /* Abbrev: DW_TAG_array_type */
13273 + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
13275 + .uleb128 3 /* Abbrev: DW_TAG_subrange_type */
13276 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
13277 + .byte 0 /* DW_AT_lower_bound */
13278 + .4byte .Llenb_var-.Lcu1_begin /* DW_AT_upper_bound */
13279 + .byte 0 /* End of children of die */
13282 + .uleb128 4 /* Abbrev: DW_TAG_base_type */
13283 + .4byte .Luint_str /* DW_AT_name */
13284 + .byte 4 /* DW_AT_byte_size */
13285 + .byte 7 /* DW_AT_encoding */
13288 + .uleb128 4 /* Abbrev: DW_TAG_base_type */
13289 + .4byte .Lchar_str /* DW_AT_name */
13290 + .byte 1 /* DW_AT_byte_size */
13291 + .byte 6 /* DW_AT_encoding */
13294 + .uleb128 5 /* Abbrev: DW_TAG_variable artificial */
13295 + .byte 1 /* DW_AT_artificial */
13296 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
13297 + .4byte .Llen_loclist-.Lloclist /* DW_AT_location */
13299 + /* optimized-out variable for b_string. */
13301 + .uleb128 7 /* Abbrev: DW_TAG_variable artificial no DW_AT_location */
13302 + .byte 1 /* DW_AT_artificial */
13303 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
13305 + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */
13306 + .string "a_string" /* DW_AT_name */
13307 + .4byte .Larray_type-.Lcu1_begin /* DW_AT_type */
13308 + .byte 2f - 1f /* DW_AT_location */
13309 +1: .byte 3 /* DW_OP_addr */
13310 + .4byte vardata /* <addr> */
13313 + /* DW_AT_upper_bound is referencing an optimized-out variable. */
13314 + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */
13315 + .string "b_string" /* DW_AT_name */
13316 + .4byte .Larrayb_type-.Lcu1_begin /* DW_AT_type */
13317 + .byte 2f - 1f /* DW_AT_location */
13318 +1: .byte 3 /* DW_OP_addr */
13319 + .4byte vardata /* <addr> */
13322 + .byte 0 /* End of children of CU */
13325 + .section .debug_loc
13328 + .4byte 0 # Location list begin address
13329 + .4byte main_length # Location list end address
13330 + .value 2f-1f # Location expression size
13331 +1: .byte 0x33 # DW_OP_lit3
13332 + .byte 0x9f # DW_OP_stack_value
13334 + .quad 0x0 # Location list terminator begin (*.LLST2)
13335 + .quad 0x0 # Location list terminator end (*.LLST2)
13337 + .section .debug_abbrev
13339 + .uleb128 1 /* Abbrev code */
13340 + .uleb128 0x11 /* DW_TAG_compile_unit */
13341 + .byte 0x1 /* has_children */
13342 + .uleb128 0x25 /* DW_AT_producer */
13343 + .uleb128 0xe /* DW_FORM_strp */
13344 + .uleb128 0x13 /* DW_AT_language */
13345 + .uleb128 0xb /* DW_FORM_data1 */
13346 + .uleb128 0x11 /* DW_AT_low_pc */
13347 + .uleb128 0x1 /* DW_FORM_addr */
13348 + .uleb128 0x12 /* DW_AT_high_pc */
13349 + .uleb128 0xb /* DW_FORM_data1 */
13350 + .byte 0x0 /* Terminator */
13351 + .byte 0x0 /* Terminator */
13353 + .uleb128 2 /* Abbrev code */
13354 + .uleb128 0x1 /* TAG: DW_TAG_array_type */
13355 + .byte 0x1 /* DW_children_yes */
13356 + .uleb128 0x49 /* DW_AT_type */
13357 + .uleb128 0x13 /* DW_FORM_ref4 */
13358 + .byte 0x0 /* Terminator */
13359 + .byte 0x0 /* Terminator */
13361 + .uleb128 3 /* Abbrev code */
13362 + .uleb128 0x21 /* DW_TAG_subrange_type */
13363 + .byte 0x0 /* no children */
13364 + .uleb128 0x49 /* DW_AT_type */
13365 + .uleb128 0x13 /* DW_FORM_ref4 */
13366 + .uleb128 0x22 /* DW_AT_lower_bound */
13367 + .uleb128 0xb /* DW_FORM_data1 */
13368 + .uleb128 0x2f /* DW_AT_upper_bound */
13369 + .uleb128 0x13 /* DW_FORM_ref4 */
13370 + .byte 0x0 /* Terminator */
13371 + .byte 0x0 /* Terminator */
13373 + .uleb128 4 /* Abbrev code */
13374 + .uleb128 0x24 /* DW_TAG_base_type */
13375 + .byte 0x0 /* no_children */
13376 + .uleb128 0x3 /* DW_AT_name */
13377 + .uleb128 0xe /* DW_FORM_strp */
13378 + .uleb128 0xb /* DW_AT_byte_size */
13379 + .uleb128 0xb /* DW_FORM_data1 */
13380 + .uleb128 0x3e /* DW_AT_encoding */
13381 + .uleb128 0xb /* DW_FORM_data1 */
13382 + .byte 0x0 /* Terminator */
13383 + .byte 0x0 /* Terminator */
13385 + .uleb128 5 /* Abbrev code */
13386 + .uleb128 0x34 /* DW_TAG_variable */
13387 + .byte 0x0 /* no_children */
13388 + .uleb128 0x34 /* DW_AT_artificial */
13389 + .uleb128 0x0c /* DW_FORM_flag */
13390 + .uleb128 0x49 /* DW_AT_type */
13391 + .uleb128 0x13 /* DW_FORM_ref4 */
13392 + .uleb128 0x02 /* DW_AT_location */
13393 + .uleb128 0x06 /* DW_FORM_data4 */
13394 + .byte 0x0 /* Terminator */
13395 + .byte 0x0 /* Terminator */
13397 + .uleb128 6 /* Abbrev code */
13398 + .uleb128 0x34 /* DW_TAG_variable */
13399 + .byte 0x0 /* no_children */
13400 + .uleb128 0x3 /* DW_AT_name */
13401 + .uleb128 0x8 /* DW_FORM_string */
13402 + .uleb128 0x49 /* DW_AT_type */
13403 + .uleb128 0x13 /* DW_FORM_ref4 */
13404 + .uleb128 0x2 /* DW_AT_location */
13405 + .uleb128 0xa /* DW_FORM_block1 */
13406 + .byte 0x0 /* Terminator */
13407 + .byte 0x0 /* Terminator */
13409 + .uleb128 7 /* Abbrev code */
13410 + .uleb128 0x34 /* DW_TAG_variable */
13411 + .byte 0x0 /* no_children */
13412 + .uleb128 0x34 /* DW_AT_artificial */
13413 + .uleb128 0x0c /* DW_FORM_flag */
13414 + .uleb128 0x49 /* DW_AT_type */
13415 + .uleb128 0x13 /* DW_FORM_ref4 */
13416 + .byte 0x0 /* Terminator */
13417 + .byte 0x0 /* Terminator */
13419 + .byte 0x0 /* Terminator */
13421 +/* String table */
13422 + .section .debug_str
13424 + .string "GNU C 3.3.3"
13428 + .string "unsigned int"
13429 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
13430 new file mode 100644
13431 index 0000000..5dbed3f
13433 +++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
13435 +# Copyright 2010 Free Software Foundation, Inc.
13437 +# This program is free software; you can redistribute it and/or modify
13438 +# it under the terms of the GNU General Public License as published by
13439 +# the Free Software Foundation; either version 3 of the License, or
13440 +# (at your option) any later version.
13442 +# This program is distributed in the hope that it will be useful,
13443 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13444 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13445 +# GNU General Public License for more details.
13447 +# You should have received a copy of the GNU General Public License
13448 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13450 +# Test printing variable with dynamic bounds which reference a different
13451 +# (artificial in the GCC case) variable containing loclist as its location.
13452 +# This testcase uses value (not address) of the referenced variable:
13453 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
13455 +# This test can only be run on targets which support DWARF-2 and use gas.
13456 +# For now pick a sampling of likely targets.
13457 +if {![istarget *-*-linux*]
13458 + && ![istarget *-*-gnu*]
13459 + && ![istarget *-*-elf*]
13460 + && ![istarget *-*-openbsd*]
13461 + && ![istarget arm-*-eabi*]
13462 + && ![istarget powerpc-*-eabi*]} {
13466 +set testfile dw2-bound-loclist
13467 +if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
13471 +# Verify it behaves at least as an unbound array without inferior.
13473 +gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"}
13474 +gdb_test "ptype a_string" {type = char \[\]}
13476 +# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
13477 +if ![runto "*main"] {
13481 +gdb_test "p a_string" { = "seen"}
13482 +gdb_test "ptype a_string" {type = char \[4\]}
13484 +gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"}
13485 +gdb_test "ptype b_string" {type = char \[\]}
13486 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
13487 new file mode 100644
13488 index 0000000..1f02d90
13490 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
13492 +/* This testcase is part of GDB, the GNU debugger.
13494 + Copyright 2004 Free Software Foundation, Inc.
13496 + This program is free software; you can redistribute it and/or modify
13497 + it under the terms of the GNU General Public License as published by
13498 + the Free Software Foundation; either version 2 of the License, or
13499 + (at your option) any later version.
13501 + This program is distributed in the hope that it will be useful,
13502 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13503 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13504 + GNU General Public License for more details.
13506 + You should have received a copy of the GNU General Public License
13507 + along with this program; if not, write to the Free Software
13508 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
13512 +/* The function `func1' traced into must have debug info on offset > 0;
13513 + (DW_UNSND (attr)). This is the reason of `func0' existence. */
13516 +func0(int a, int b)
13520 +/* `func1' being traced into must have some arguments to dump. */
13523 +func1(int a, int b)
13534 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
13535 new file mode 100644
13536 index 0000000..1c6e84a
13538 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
13540 +# Copyright 2006 Free Software Foundation, Inc.
13542 +# This program is free software; you can redistribute it and/or modify
13543 +# it under the terms of the GNU General Public License as published by
13544 +# the Free Software Foundation; either version 2 of the License, or
13545 +# (at your option) any later version.
13547 +# This program is distributed in the hope that it will be useful,
13548 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13549 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13550 +# GNU General Public License for more details.
13552 +# You should have received a copy of the GNU General Public License
13553 +# along with this program; if not, write to the Free Software
13554 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13556 +# Minimal DWARF-2 unit test
13558 +# This test can only be run on targets which support DWARF-2.
13559 +# For now pick a sampling of likely targets.
13560 +if {![istarget *-*-linux*]
13561 + && ![istarget *-*-gnu*]
13562 + && ![istarget *-*-elf*]
13563 + && ![istarget *-*-openbsd*]
13564 + && ![istarget arm-*-eabi*]
13565 + && ![istarget powerpc-*-eabi*]} {
13569 +set testfile "dw2-stripped"
13570 +set srcfile ${testfile}.c
13571 +set binfile ${objdir}/${subdir}/${testfile}.x
13573 +remote_exec build "rm -f ${binfile}"
13575 +# get the value of gcc_compiled
13576 +if [get_compiler_info ${binfile}] {
13580 +# This test can only be run on gcc as we use additional_flags=FIXME
13581 +if {$gcc_compiled == 0} {
13585 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
13589 +remote_exec build "objcopy -R .debug_loc ${binfile}"
13590 +set strip_output [remote_exec build "objdump -h ${binfile}"]
13592 +set test "stripping test file preservation"
13593 +if [ regexp ".debug_info " $strip_output] {
13594 + pass "$test (.debug_info preserved)"
13596 + fail "$test (.debug_info got also stripped)"
13599 +set test "stripping test file functionality"
13600 +if [ regexp ".debug_loc " $strip_output] {
13601 + fail "$test (.debug_loc still present)"
13603 + pass "$test (.debug_loc stripped)"
13608 +gdb_reinitialize_dir $srcdir/$subdir
13609 +gdb_load ${binfile}
13611 +# For C programs, "start" should stop in main().
13613 +gdb_test "start" \
13614 + ".*main \\(\\) at .*" \
13617 + "func.* \\(.*\\) at .*" \
13619 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
13620 new file mode 100644
13621 index 0000000..5fcdd84
13623 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
13625 +/* This testcase is part of GDB, the GNU debugger.
13627 + Copyright 2009 Free Software Foundation, Inc.
13629 + This program is free software; you can redistribute it and/or modify
13630 + it under the terms of the GNU General Public License as published by
13631 + the Free Software Foundation; either version 3 of the License, or
13632 + (at your option) any later version.
13634 + This program is distributed in the hope that it will be useful,
13635 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13636 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13637 + GNU General Public License for more details.
13639 + You should have received a copy of the GNU General Public License
13640 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13642 +/* Debug information */
13644 + .section .debug_info
13647 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
13649 + .2byte 2 /* DWARF Version */
13650 + .4byte .Labbrev1_begin /* Offset into abbrev section */
13651 + .byte 4 /* Pointer size */
13654 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
13655 + .ascii "dw2-struct-member-data-location.c\0" /* DW_AT_name */
13656 + .ascii "GNU C 4.3.2\0" /* DW_AT_producer */
13657 + .byte 1 /* DW_AT_language (C) */
13660 + .uleb128 2 /* Abbrev: DW_TAG_structure_type */
13661 + .ascii "some_struct\0" /* DW_AT_name */
13663 + .uleb128 3 /* Abbrev: DW_TAG_member */
13664 + .ascii "field\0" /* DW_AT_name */
13665 + .byte 0 /* DW_AT_data_member_location */
13667 + .byte 0 /* End of children of some_struct */
13669 + .byte 0 /* End of children of CU */
13673 +/* Abbrev table */
13674 + .section .debug_abbrev
13676 + .uleb128 1 /* Abbrev code */
13677 + .uleb128 0x11 /* DW_TAG_compile_unit */
13678 + .byte 1 /* has_children */
13679 + .uleb128 0x3 /* DW_AT_name */
13680 + .uleb128 0x8 /* DW_FORM_string */
13681 + .uleb128 0x25 /* DW_AT_producer */
13682 + .uleb128 0x8 /* DW_FORM_string */
13683 + .uleb128 0x13 /* DW_AT_language */
13684 + .uleb128 0xb /* DW_FORM_data1 */
13685 + .byte 0x0 /* Terminator */
13686 + .byte 0x0 /* Terminator */
13688 + .uleb128 2 /* Abbrev code */
13689 + .uleb128 0x13 /* DW_TAG_structure_type */
13690 + .byte 1 /* has_children */
13691 + .uleb128 0x3 /* DW_AT_name */
13692 + .uleb128 0x8 /* DW_FORM_string */
13693 + .byte 0x0 /* Terminator */
13694 + .byte 0x0 /* Terminator */
13696 + .uleb128 3 /* Abbrev code */
13697 + .uleb128 0x0d /* DW_TAG_member */
13698 + .byte 0 /* has_children */
13699 + .uleb128 0x3 /* DW_AT_name */
13700 + .uleb128 0x8 /* DW_FORM_string */
13701 + .uleb128 0x38 /* DW_AT_data_member_location */
13702 + .uleb128 0x0b /* DW_FORM_data1 */
13703 + .byte 0x0 /* Terminator */
13704 + .byte 0x0 /* Terminator */
13706 + .byte 0x0 /* Terminator */
13707 + .byte 0x0 /* Terminator */
13708 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
13709 new file mode 100644
13710 index 0000000..c41151c
13712 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
13714 +# Copyright 2009 Free Software Foundation, Inc.
13716 +# This program is free software; you can redistribute it and/or modify
13717 +# it under the terms of the GNU General Public License as published by
13718 +# the Free Software Foundation; either version 3 of the License, or
13719 +# (at your option) any later version.
13721 +# This program is distributed in the hope that it will be useful,
13722 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13723 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13724 +# GNU General Public License for more details.
13726 +# You should have received a copy of the GNU General Public License
13727 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13729 +# This test can only be run on targets which support DWARF-2 and use gas.
13730 +# For now pick a sampling of likely targets.
13731 +if {![istarget *-*-linux*]
13732 + && ![istarget *-*-gnu*]
13733 + && ![istarget *-*-elf*]
13734 + && ![istarget *-*-openbsd*]
13735 + && ![istarget arm-*-eabi*]
13736 + && ![istarget powerpc-*-eabi*]} {
13740 +set testfile "dw2-struct-member-data-location"
13741 +set srcfile ${testfile}.S
13742 +set binfile ${testfile}.x
13744 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
13748 +clean_restart $binfile
13750 +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
13751 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
13752 new file mode 100644
13753 index 0000000..cd3486b
13755 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
13757 +# Copyright 2009 Free Software Foundation, Inc.
13759 +# This program is free software; you can redistribute it and/or modify
13760 +# it under the terms of the GNU General Public License as published by
13761 +# the Free Software Foundation; either version 2 of the License, or
13762 +# (at your option) any later version.
13764 +# This program is distributed in the hope that it will be useful,
13765 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13766 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13767 +# GNU General Public License for more details.
13769 +# You should have received a copy of the GNU General Public License
13770 +# along with this program; if not, write to the Free Software
13771 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13773 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
13775 +# This file is part of the gdb testsuite. Array element stride must not be
13776 +# specified in the number of elements but in a number of bytes instead.
13777 +# Original problem:
13778 +# (gdb) p c40pt(1)
13779 +# $1 = '0-hello', ' ' <repeats 33 times>
13780 +# (gdb) p c40pt(2)
13781 +# warning: Fortran array stride not divisible by the element size
13783 +set testfile dwarf-stride
13784 +set srcfile ${testfile}.f90
13786 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } {
13790 +if ![runto MAIN__] then {
13791 + perror "couldn't run to breakpoint MAIN__"
13795 +gdb_breakpoint [gdb_get_line_number "break-here"]
13796 +gdb_continue_to_breakpoint "break-here" ".*break-here.*"
13797 +gdb_test "p c40pt(1)" " = '0-hello.*"
13798 +gdb_test "p c40pt(2)" " = '1-hello.*"
13799 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
13800 new file mode 100644
13801 index 0000000..e492b3a
13803 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
13805 +! Copyright 2009 Free Software Foundation, Inc.
13807 +! This program is free software; you can redistribute it and/or modify
13808 +! it under the terms of the GNU General Public License as published by
13809 +! the Free Software Foundation; either version 2 of the License, or
13810 +! (at your option) any later version.
13812 +! This program is distributed in the hope that it will be useful,
13813 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
13814 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13815 +! GNU General Public License for more details.
13817 +! You should have received a copy of the GNU General Public License
13818 +! along with this program; if not, write to the Free Software
13819 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13821 +! File written by Alan Matsuoka.
13825 + type small_stride
13826 + character*40 long_string
13827 + integer small_pad
13828 + end type small_stride
13830 + type(small_stride), dimension (20), target :: unpleasant
13831 + character*40, pointer, dimension(:):: c40pt
13836 + unpleasant(i+1)%small_pad = i+1
13837 + unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
13840 + c40pt => unpleasant%long_string
13842 + print *, c40pt ! break-here
13845 diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
13846 new file mode 100644
13847 index 0000000..0ccebe0
13849 +++ b/gdb/testsuite/gdb.fortran/dynamic.exp
13851 +# Copyright 2007 Free Software Foundation, Inc.
13853 +# This program is free software; you can redistribute it and/or modify
13854 +# it under the terms of the GNU General Public License as published by
13855 +# the Free Software Foundation; either version 2 of the License, or
13856 +# (at your option) any later version.
13858 +# This program is distributed in the hope that it will be useful,
13859 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13860 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13861 +# GNU General Public License for more details.
13863 +# You should have received a copy of the GNU General Public License
13864 +# along with this program; if not, write to the Free Software
13865 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13867 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
13869 +# This file is part of the gdb testsuite. It contains tests for dynamically
13870 +# allocated Fortran arrays.
13871 +# It depends on the GCC dynamic Fortran arrays DWARF support:
13872 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
13874 +set testfile "dynamic"
13875 +set srcfile ${testfile}.f90
13876 +set binfile ${objdir}/${subdir}/${testfile}
13878 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
13879 + untested "Couldn't compile ${srcfile}"
13885 +gdb_reinitialize_dir $srcdir/$subdir
13886 +gdb_load ${binfile}
13888 +if ![runto MAIN__] then {
13889 + perror "couldn't run to breakpoint MAIN__"
13893 +gdb_breakpoint [gdb_get_line_number "varx-init"]
13894 +gdb_continue_to_breakpoint "varx-init"
13895 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
13896 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
13897 +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"
13898 +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"
13899 +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"
13901 +gdb_breakpoint [gdb_get_line_number "varx-allocated"]
13902 +gdb_continue_to_breakpoint "varx-allocated"
13903 +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
13904 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
13905 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
13906 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
13908 +gdb_breakpoint [gdb_get_line_number "varx-filled"]
13909 +gdb_continue_to_breakpoint "varx-filled"
13910 +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
13911 +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
13912 +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
13913 +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
13914 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
13915 +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"
13916 +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"
13918 +gdb_breakpoint [gdb_get_line_number "varv-associated"]
13919 +gdb_continue_to_breakpoint "varv-associated"
13920 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
13921 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
13922 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
13923 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
13924 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
13925 +# Intel Fortran Compiler 10.1.008 uses the pointer type.
13926 +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
13928 +gdb_breakpoint [gdb_get_line_number "varv-filled"]
13929 +gdb_continue_to_breakpoint "varv-filled"
13930 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
13931 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
13933 +gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
13934 +gdb_continue_to_breakpoint "varv-deassociated"
13935 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
13936 +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"
13937 +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"
13938 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
13939 +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
13940 +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
13942 +gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
13943 +gdb_continue_to_breakpoint "varx-deallocated"
13944 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
13945 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
13946 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
13947 +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"
13948 +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"
13950 +gdb_breakpoint [gdb_get_line_number "vary-passed"]
13951 +gdb_continue_to_breakpoint "vary-passed"
13952 +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
13953 +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
13955 +gdb_breakpoint [gdb_get_line_number "vary-filled"]
13956 +gdb_continue_to_breakpoint "vary-filled"
13957 +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
13958 +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
13959 +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
13960 +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
13961 +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
13962 +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
13964 +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
13965 +gdb_continue_to_breakpoint "varw-almostfilled"
13966 +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
13967 +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
13968 +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
13969 +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
13970 +# "up" works with GCC but other Fortran compilers may copy the values into the
13971 +# outer function only on the exit of the inner function.
13972 +# We need both variants as depending on the arch we optionally may still be
13973 +# executing the caller line or not after `finish'.
13974 +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
13975 +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
13976 +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
13977 +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
13978 +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
13980 +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
13981 +gdb_continue_to_breakpoint "varz-almostfilled"
13982 +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
13983 +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
13984 +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
13985 +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
13986 +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
13987 +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
13988 +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
13989 +gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
13990 +# maps to foo::vary(1,1)
13991 +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
13992 +# maps to foo::vary(2,2)
13993 +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
13994 +# maps to foo::vary(1,3)
13995 +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
13996 diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
13997 new file mode 100644
13998 index 0000000..0f43564
14000 +++ b/gdb/testsuite/gdb.fortran/dynamic.f90
14002 +! Copyright 2007 Free Software Foundation, Inc.
14004 +! This program is free software; you can redistribute it and/or modify
14005 +! it under the terms of the GNU General Public License as published by
14006 +! the Free Software Foundation; either version 2 of the License, or
14007 +! (at your option) any later version.
14009 +! This program is distributed in the hope that it will be useful,
14010 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
14011 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14012 +! GNU General Public License for more details.
14014 +! You should have received a copy of the GNU General Public License
14015 +! along with this program; if not, write to the Free Software
14016 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14018 +! Ihis file is the Fortran source file for dynamic.exp.
14019 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
14020 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
14023 + real, target, allocatable :: varx (:, :, :)
14024 + real, pointer :: varv (:, :, :)
14025 + real, target :: varu (1, 2, 3)
14027 + allocate (varx (1:6, 5:15, 17:28)) ! varx-init
14028 + l = allocated (varx)
14029 + varx(:, :, :) = 6 ! varx-allocated
14030 + varx(1, 5, 17) = 7
14031 + varx(2, 6, 18) = 8
14032 + varx(6, 15, 28) = 9
14033 + varv => varx ! varx-filled
14034 + l = associated (varv)
14035 + varv(3, 7, 19) = 10 ! varv-associated
14036 + varv => null () ! varv-filled
14037 + l = associated (varv)
14038 + deallocate (varx) ! varv-deassociated
14039 + l = allocated (varx)
14040 + varu(:, :, :) = 10 ! varx-deallocated
14041 + allocate (varv (1:6, 5:15, 17:28))
14042 + l = associated (varv)
14043 + varv(:, :, :) = 6
14044 + varv(1, 5, 17) = 7
14045 + varv(2, 6, 18) = 8
14046 + varv(6, 15, 28) = 9
14047 + deallocate (varv)
14048 + l = associated (varv)
14050 + varv(1, 1, 1) = 6
14051 + varv(1, 2, 3) = 7
14052 + l = associated (varv)
14053 +end subroutine baz
14054 +subroutine foo (vary, varw)
14055 + real :: vary (:, :)
14056 + real :: varw (:, :, :)
14057 + vary(:, :) = 4 ! vary-passed
14061 + varw(:, :, :) = 5 ! vary-filled
14062 + varw(1, 1, 1) = 6
14063 + varw(2, 2, 2) = 7 ! varw-almostfilled
14064 +end subroutine foo
14065 +subroutine bar (varz, vart)
14067 + real :: vart (2:11, 7:*)
14069 + varz(2) = 5 ! varz-almostfilled
14070 + vart(2,7) = vart(2,7)
14071 +end subroutine bar
14074 + subroutine foo (vary, varw)
14075 + real :: vary (:, :)
14076 + real :: varw (:, :, :)
14080 + subroutine bar (varz, vart)
14082 + real :: vart (2:11, 7:*)
14085 + real :: x (10, 10), y (5), z(8, 8, 8)
14090 + call foo (x, z(2:6, 4:7, 6:8))
14092 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
14093 + if (x (1, 3) .ne. 10) call abort
14094 + if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
14095 + if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
14096 + call foo (transpose (x), z)
14097 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
14098 + if (x (3, 1) .ne. 10) call abort
14100 diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
14101 new file mode 100644
14102 index 0000000..b1120c3
14104 +++ b/gdb/testsuite/gdb.fortran/string.exp
14106 +# Copyright 2008 Free Software Foundation, Inc.
14108 +# This program is free software; you can redistribute it and/or modify
14109 +# it under the terms of the GNU General Public License as published by
14110 +# the Free Software Foundation; either version 2 of the License, or
14111 +# (at your option) any later version.
14113 +# This program is distributed in the hope that it will be useful,
14114 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14115 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14116 +# GNU General Public License for more details.
14118 +# You should have received a copy of the GNU General Public License
14119 +# along with this program; if not, write to the Free Software
14120 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14122 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
14124 +# This file is part of the gdb testsuite. It contains tests for Fortran
14125 +# strings with dynamic length.
14127 +set testfile "string"
14128 +set srcfile ${testfile}.f90
14129 +set binfile ${objdir}/${subdir}/${testfile}
14131 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
14132 + untested "Couldn't compile ${srcfile}"
14138 +gdb_reinitialize_dir $srcdir/$subdir
14139 +gdb_load ${binfile}
14141 +if ![runto MAIN__] then {
14142 + perror "couldn't run to breakpoint MAIN__"
14146 +gdb_breakpoint [gdb_get_line_number "var-init"]
14147 +gdb_continue_to_breakpoint "var-init"
14148 +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
14149 +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
14150 +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
14151 +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
14152 +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
14153 +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
14154 +gdb_test "p c" "\\$\[0-9\]* = 'c'"
14155 +gdb_test "p d" "\\$\[0-9\]* = 'd '"
14156 +gdb_test "p e" "\\$\[0-9\]* = 'g '"
14157 +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 '\\) \\)"
14158 +gdb_test "p *e" "Attempt to take contents of a non-pointer value."
14159 +gdb_test "p *f" "Attempt to take contents of a non-pointer value."
14161 +gdb_breakpoint [gdb_get_line_number "var-finish"]
14162 +gdb_continue_to_breakpoint "var-finish"
14163 +gdb_test "p e" "\\$\[0-9\]* = 'e '" "p e re-set"
14164 +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"
14165 diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
14166 new file mode 100644
14167 index 0000000..226dc5d
14169 +++ b/gdb/testsuite/gdb.fortran/string.f90
14171 +! Copyright 2008 Free Software Foundation, Inc.
14173 +! This program is free software; you can redistribute it and/or modify
14174 +! it under the terms of the GNU General Public License as published by
14175 +! the Free Software Foundation; either version 2 of the License, or
14176 +! (at your option) any later version.
14178 +! This program is distributed in the hope that it will be useful,
14179 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
14180 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14181 +! GNU General Public License for more details.
14183 +! You should have received a copy of the GNU General Public License
14184 +! along with this program; if not, write to the Free Software
14185 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14187 +! Ihis file is the Fortran source file for dynamic.exp.
14188 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
14189 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
14191 +subroutine foo (e, f)
14192 + character (len=1) :: c
14193 + character (len=8) :: d
14194 + character (len=*) :: e
14195 + character (len=*) :: f (1:7, 8:10)
14198 + e = 'e' ! var-init
14201 + c = 'c' ! var-finish
14202 +end subroutine foo
14203 + character (len=4) :: g, h (1:7, 8:10)
14208 diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
14209 index fc8bccc..e053813 100644
14210 --- a/gdb/testsuite/gdb.gdb/selftest.exp
14211 +++ b/gdb/testsuite/gdb.gdb/selftest.exp
14212 @@ -92,6 +92,10 @@ proc do_steps_and_nexts {} {
14213 set description "step over ttyarg initialization"
14216 + -re ".*python_script = 0.*$gdb_prompt $" {
14217 + set description "step over python_script initialization"
14218 + set command "step"
14220 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
14221 set description "next over make_command_stats_cleanup and everything it calls"
14223 diff --git a/gdb/testsuite/gdb.java/jnpe.exp b/gdb/testsuite/gdb.java/jnpe.exp
14224 new file mode 100644
14225 index 0000000..55aa80d
14227 +++ b/gdb/testsuite/gdb.java/jnpe.exp
14229 +# Copyright 2009 Free Software Foundation, Inc.
14231 +# This program is free software; you can redistribute it and/or modify
14232 +# it under the terms of the GNU General Public License as published by
14233 +# the Free Software Foundation; either version 3 of the License, or
14234 +# (at your option) any later version.
14236 +# This program is distributed in the hope that it will be useful,
14237 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14238 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14239 +# GNU General Public License for more details.
14241 +# You should have received a copy of the GNU General Public License
14242 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
14244 +if $tracelevel then {
14245 + strace $tracelevel
14248 +load_lib "java.exp"
14250 +set testfile "jnpe"
14251 +set srcfile ${testfile}.java
14252 +set binfile ${objdir}/${subdir}/${testfile}
14253 +if { [compile_java_from_source ${srcdir}/$subdir/${srcfile} ${binfile} "-g"] != "" } {
14254 + untested "Couldn't compile ${srcdir}/$subdir/${srcfile}"
14258 +# Start with a fresh gdb.
14262 +gdb_reinitialize_dir $srcdir/$subdir
14263 +gdb_load ${binfile}
14265 +set line [gdb_get_line_number "break here" $testfile.java]
14266 +gdb_test "break $testfile.java:$line" ""
14269 + "// break here.*" \
14270 + "run java next-over-throw"
14272 +# See whether we have the needed unwinder hooks.
14274 +gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook in java" {
14275 + -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
14276 + pass "check for unwinder hook in java"
14278 + -re "No symbol .* in current context.?\r\n$gdb_prompt $" {
14279 + # Pass the test so we don't get bogus fails in the results.
14280 + setup_xfail *-*-*
14281 + fail "check for unwinder hook in java"
14286 + untested jnpe.exp
14290 +gdb_test "handle SIGSEGV nostop noprint" \
14291 + "SIGSEGV.*fault" \
14292 + "disable SIGSEGV for next-over-NPE"
14294 +# The line where we stop differ according to gcj; check just we did not already
14295 +# execute the catch point.
14301 +gdb_breakpoint [gdb_get_line_number "catch point"]
14302 +gdb_continue_to_breakpoint "catch point" ".*// catch point.*"
14303 diff --git a/gdb/testsuite/gdb.java/jnpe.java b/gdb/testsuite/gdb.java/jnpe.java
14304 new file mode 100644
14305 index 0000000..3524830
14307 +++ b/gdb/testsuite/gdb.java/jnpe.java
14309 +// Test next-over-NPE.
14310 +/* This testcase is part of GDB, the GNU debugger.
14312 + Copyright 2009 Free Software Foundation, Inc.
14314 + This program is free software; you can redistribute it and/or modify
14315 + it under the terms of the GNU General Public License as published by
14316 + the Free Software Foundation; either version 3 of the License, or
14317 + (at your option) any later version.
14319 + This program is distributed in the hope that it will be useful,
14320 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14321 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14322 + GNU General Public License for more details.
14324 + You should have received a copy of the GNU General Public License
14325 + along with this program. If not, see <http://www.gnu.org/licenses/>.
14330 + public static String npe ()
14332 + return ((Object) null).toString();
14335 + public static void main (String[] args)
14339 + System.out.println (npe ()); // break here
14341 + catch (NullPointerException n)
14343 + System.out.println ("success"); // catch point
14347 diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
14348 new file mode 100644
14349 index 0000000..729f457
14351 +++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
14353 +/* This file is part of GDB, the GNU debugger.
14355 + Copyright 2009 Free Software Foundation, Inc.
14357 + This program is free software; you can redistribute it and/or modify
14358 + it under the terms of the GNU General Public License as published by
14359 + the Free Software Foundation; either version 3 of the License, or
14360 + (at your option) any later version.
14362 + This program is distributed in the hope that it will be useful,
14363 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14364 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14365 + GNU General Public License for more details.
14367 + You should have received a copy of the GNU General Public License
14368 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
14375 diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
14376 new file mode 100644
14377 index 0000000..3090e7e
14379 +++ b/gdb/testsuite/gdb.opt/array-from-register.c
14381 +/* This file is part of GDB, the GNU debugger.
14383 + Copyright 2009 Free Software Foundation, Inc.
14385 + This program is free software; you can redistribute it and/or modify
14386 + it under the terms of the GNU General Public License as published by
14387 + the Free Software Foundation; either version 3 of the License, or
14388 + (at your option) any later version.
14390 + This program is distributed in the hope that it will be useful,
14391 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14392 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14393 + GNU General Public License for more details.
14395 + You should have received a copy of the GNU General Public License
14396 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
14398 +extern int func (int *arr);
14403 + int arr[] = { 42 };
14409 diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
14410 new file mode 100644
14411 index 0000000..f2de718
14413 +++ b/gdb/testsuite/gdb.opt/array-from-register.exp
14415 +# Copyright 2009 Free Software Foundation, Inc.
14417 +# This program is free software; you can redistribute it and/or modify
14418 +# it under the terms of the GNU General Public License as published by
14419 +# the Free Software Foundation; either version 2 of the License, or
14420 +# (at your option) any later version.
14422 +# This program is distributed in the hope that it will be useful,
14423 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14424 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14425 +# GNU General Public License for more details.
14427 +# You should have received a copy of the GNU General Public License
14428 +# along with this program; if not, write to the Free Software
14429 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14431 +# This file is part of the gdb testsuite.
14433 +if { [prepare_for_testing array-from-register.exp "array-from-register" \
14434 + {array-from-register.c array-from-register-func.c} \
14435 + {debug optimize=-O2}] } {
14439 +if ![runto func] then {
14443 +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
14445 +# Seen regression:
14446 +# Address requested for identifier "arr" which is in register $rdi
14447 +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
14448 diff --git a/gdb/testsuite/gdb.opt/fortran-string.exp b/gdb/testsuite/gdb.opt/fortran-string.exp
14449 new file mode 100644
14450 index 0000000..f997eec
14452 +++ b/gdb/testsuite/gdb.opt/fortran-string.exp
14454 +# Copyright 2009 Free Software Foundation, Inc.
14456 +# This program is free software; you can redistribute it and/or modify
14457 +# it under the terms of the GNU General Public License as published by
14458 +# the Free Software Foundation; either version 2 of the License, or
14459 +# (at your option) any later version.
14461 +# This program is distributed in the hope that it will be useful,
14462 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14463 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14464 +# GNU General Public License for more details.
14466 +# You should have received a copy of the GNU General Public License
14467 +# along with this program; if not, write to the Free Software
14468 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14470 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
14472 +# Test GDB can cope with Fortran strings having their length present in a CPU
14473 +# register. With -O0 the string length is passed on the stack. To make this
14474 +# test meaningful the follow assertion should pass. It is not being checked
14475 +# here as the "_s" symbol is compiler dependent:
14476 +# (gdb) info address _s
14477 +# Symbol "_s" is a variable in register XX.
14479 +set test fortran-string
14480 +set srcfile ${test}.f90
14481 +if { [prepare_for_testing ${test}.exp ${test} ${srcfile} {debug f77 additional_flags=-O2}] } {
14485 +if ![runto MAIN__] then {
14486 + perror "couldn't run to breakpoint MAIN__"
14490 +gdb_breakpoint [gdb_get_line_number "s = s"]
14491 +gdb_continue_to_breakpoint "s = s"
14492 +gdb_test "frame" ".*s='foo'.*"
14493 +gdb_test "ptype s" "type = character\\*3"
14494 +gdb_test "p s" "\\$\[0-9\]* = 'foo'"
14495 diff --git a/gdb/testsuite/gdb.opt/fortran-string.f90 b/gdb/testsuite/gdb.opt/fortran-string.f90
14496 new file mode 100644
14497 index 0000000..e48d520
14499 +++ b/gdb/testsuite/gdb.opt/fortran-string.f90
14501 +! Copyright 2009 Free Software Foundation, Inc.
14503 +! This program is free software; you can redistribute it and/or modify
14504 +! it under the terms of the GNU General Public License as published by
14505 +! the Free Software Foundation; either version 2 of the License, or
14506 +! (at your option) any later version.
14508 +! This program is distributed in the hope that it will be useful,
14509 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
14510 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14511 +! GNU General Public License for more details.
14513 +! You should have received a copy of the GNU General Public License
14514 +! along with this program; if not, write to the Free Software
14515 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14517 +! Ihis file is the Fortran source file for dynamic.exp.
14518 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
14519 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
14529 diff --git a/gdb/testsuite/gdb.pascal/arrays.exp b/gdb/testsuite/gdb.pascal/arrays.exp
14530 new file mode 100644
14531 index 0000000..ccc6e1e
14533 +++ b/gdb/testsuite/gdb.pascal/arrays.exp
14535 +# Copyright 2008, 2009 Free Software Foundation, Inc.
14537 +# This program is free software; you can redistribute it and/or modify
14538 +# it under the terms of the GNU General Public License as published by
14539 +# the Free Software Foundation; either version 3 of the License, or
14540 +# (at your option) any later version.
14542 +# This program is distributed in the hope that it will be useful,
14543 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14544 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14545 +# GNU General Public License for more details.
14547 +# You should have received a copy of the GNU General Public License
14548 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
14550 +if $tracelevel then {
14551 + strace $tracelevel
14554 +load_lib "pascal.exp"
14556 +set testfile "arrays"
14557 +set srcfile ${testfile}.pas
14558 +set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
14560 +# These tests only work with fpc, using the -gw3 compile-option
14562 +if { $pascal_compiler_is_fpc != 1 } {
14566 +# Detect if the fpc version is below 2.3.0
14567 +set fpc_generates_dwarf_for_dynamic_arrays 1
14568 +if { ($fpcversion_major < 2) || ( ($fpcversion_major == 2) && ($fpcversion_minor < 3))} {
14569 + set fpc_generates_dwarf_for_dynamic_arrays 0
14573 +if {[gdb_compile_pascal "-gw3 ${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
14579 +gdb_reinitialize_dir $srcdir/$subdir
14580 +gdb_load ${binfile}
14581 +set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
14582 +set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
14585 +if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
14586 + pass "setting breakpoint 1"
14588 +if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
14589 + pass "setting breakpoint 2"
14592 +# Verify that "start" lands inside the right procedure.
14593 +if { [gdb_start_cmd] < 0 } {
14598 +gdb_test "" ".* at .*${srcfile}.*" "start"
14600 +gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
14602 +gdb_test "print StatArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer type"
14603 +gdb_test "print StatArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer"
14605 +gdb_test "cont" "Breakpoint .*:${bp_location2}.*" "Going to second breakpoint"
14607 +gdb_test "print StatArrChar" ".* = 'abcdefghijkl'" "Print static array of char"
14608 +gdb_test "print Stat2dArrInt" ".* = \\{\\{0, 1, 2, 3, 4\\}, \\{1, 2, 3, 4, 5\\}, \\{2, 3, 4, 5, 6\\}, \\{3, 4, 5, 6, 7\\}, \\{4, 5, 6, 7, 8\\}, \\{5, 6, 7, 8, 9\\}, \\{6, 7, 8, 9, 10\\}, \\{7, 8, 9, 10, 11\\}, \\{8, 9, 10, 11, 12\\}, \\{9, 10, 11, 12, 13\\}, \\{10, 11, 12, 13, 14\\}, \\{11, 12, 13, 14, 15\\}\\}" "Print static 2-dimensional array of integer"
14610 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14611 + setup_xfail "*-*-*"
14613 +gdb_test "print DynArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer type"
14614 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14615 + setup_xfail "*-*-*"
14617 +gdb_test "print DynArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer"
14619 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14620 + setup_xfail "*-*-*"
14622 +gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char"
14624 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14625 + setup_xfail "*-*-*"
14627 +gdb_test "print DynArrStr" ".* = \\{'dstr0', 'dstr1', 'dstr2', 'dstr3', 'dstr4', 'dstr5', 'dstr6', 'dstr7', 'dstr8', 'dstr9', 'dstr10', 'dstr11', 'dstr12'\\}" "Print dynamic array of string"
14629 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14630 + setup_xfail "*-*-*"
14632 +gdb_test "print StatArrStr" ".* = \\{'str0', 'str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9', 'str10', 'str11', 'str12'\\}" "Print static array of string"
14634 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
14635 + setup_xfail "*-*-*"
14637 +gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char"
14639 diff --git a/gdb/testsuite/gdb.pascal/arrays.pas b/gdb/testsuite/gdb.pascal/arrays.pas
14640 new file mode 100644
14641 index 0000000..295602d
14643 +++ b/gdb/testsuite/gdb.pascal/arrays.pas
14646 + Copyright 2008, 2009 Free Software Foundation, Inc.
14648 + This program is free software; you can redistribute it and/or modify
14649 + it under the terms of the GNU General Public License as published by
14650 + the Free Software Foundation; either version 3 of the License, or
14651 + (at your option) any later version.
14653 + This program is distributed in the hope that it will be useful,
14654 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14655 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14656 + GNU General Public License for more details.
14658 + You should have received a copy of the GNU General Public License
14659 + along with this program. If not, see <http://www.gnu.org/licenses/>.
14664 +{$mode objfpc}{$h+}
14668 +type TStatArrInt= array[0..11] of integer;
14669 + TDynArrInt= array of integer;
14670 + TStatArrStr= array[0..12] of string;
14671 + TDynArrStr= array of string;
14672 + TDynArrChar = array of char;
14673 + TStatArrChar = array [0..11] of char;
14675 + TStat2dArrInt = array[0..11,0..4] of integer;
14677 +var StatArrInt: TStatArrInt;
14678 + StatArrInt_: Array[0..11] of integer;
14679 + DynArrInt: TDynArrInt;
14680 + DynArrInt_: Array of integer;
14681 + StatArrStr: TStatArrStr;
14682 + DynArrStr: TDynArrStr;
14683 + StatArrChar: TStatArrChar;
14684 + DynArrChar: TDynArrChar;
14686 + Stat2dArrInt: TStat2dArrInt;
14693 + for i := 0 to 11 do
14695 + StatArrInt[i]:= i+50;
14696 + StatArrInt_[i]:= i+50;
14697 + StatArrChar[i]:= chr(ord('a')+i);
14698 + for j := 0 to 4 do
14699 + Stat2dArrInt[i,j]:=i+j;
14701 + writeln(StatArrInt_[0]);
14702 + writeln(StatArrInt[0]); { set breakpoint 1 here }
14703 + writeln(StatArrChar[0]);
14704 + writeln(Stat2dArrInt[0,0]);
14706 + setlength(DynArrInt,13);
14707 + setlength(DynArrInt_,13);
14708 + setlength(DynArrStr,13);
14709 + setlength(DynArrChar,13);
14710 + for i := 0 to 12 do
14712 + DynArrInt[i]:= i+50;
14713 + DynArrInt_[i]:= i+50;
14714 + DynArrChar[i]:= chr(ord('a')+i);
14715 + StatArrStr[i]:='str'+inttostr(i);
14716 + DynArrStr[i]:='dstr'+inttostr(i);
14718 + writeln(DynArrInt_[1]);
14719 + writeln(DynArrInt[1]);
14720 + writeln(DynArrStr[1]);
14721 + writeln(StatArrStr[1]);
14722 + writeln(DynArrChar[1]);
14724 + s := 'test'#0'string';
14725 + writeln(s); { set breakpoint 2 here }
14727 diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
14728 index 0f250d2..84e5038 100644
14729 --- a/gdb/testsuite/gdb.python/py-cmd.exp
14730 +++ b/gdb/testsuite/gdb.python/py-cmd.exp
14731 @@ -20,24 +20,6 @@ if $tracelevel then {
14735 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
14736 -# Run a test named NAME, consisting of multiple lines of input.
14737 -# After each input line INPUT, search for result line RESULT.
14738 -# Succeed if all results are seen; fail otherwise.
14739 -proc gdb_py_test_multiple {name args} {
14740 - global gdb_prompt
14741 - foreach {input result} $args {
14742 - if {[gdb_test_multiple $input "$name - $input" {
14743 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
14744 - pass "$name - $input"
14753 # Start with a fresh gdb.
14756 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
14757 index e1212d3..77f44f5 100644
14758 --- a/gdb/testsuite/gdb.python/py-frame.exp
14759 +++ b/gdb/testsuite/gdb.python/py-frame.exp
14760 @@ -89,8 +89,6 @@ gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
14762 gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
14763 gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
14764 -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
14765 -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
14766 gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
14767 gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
14768 gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
14769 @@ -105,3 +103,5 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
14770 gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
14772 gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
14774 +gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
14775 diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
14776 index 38c5693..e7f0037 100644
14777 --- a/gdb/testsuite/gdb.python/py-function.exp
14778 +++ b/gdb/testsuite/gdb.python/py-function.exp
14779 @@ -20,24 +20,6 @@ if $tracelevel then {
14783 -# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
14784 -# Run a test named NAME, consisting of multiple lines of input.
14785 -# After each input line INPUT, search for result line RESULT.
14786 -# Succeed if all results are seen; fail otherwise.
14787 -proc gdb_py_test_multiple {name args} {
14788 - global gdb_prompt
14789 - foreach {input result} $args {
14790 - if {[gdb_test_multiple $input "$name - $input" {
14791 - -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
14792 - pass "$name - $input"
14801 # Start with a fresh gdb.
14804 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
14805 index 3b2aadd..03bbf3e 100644
14806 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp
14807 +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
14808 @@ -102,6 +102,8 @@ proc run_lang_tests {lang} {
14809 gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
14810 gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
14812 + gdb_test "print nullstr" "RuntimeError: Error reading string from inferior.*"
14814 gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
14815 gdb_test "continue" "Program exited normally\."
14817 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
14818 index a24bc11..e3043bc 100644
14819 --- a/gdb/testsuite/gdb.python/py-value.exp
14820 +++ b/gdb/testsuite/gdb.python/py-value.exp
14821 @@ -313,6 +313,15 @@ proc test_value_after_death {} {
14822 "print value's type"
14825 +# Regression test for a cast failure. The bug was that if we cast a
14826 +# value to its own type, gdb could crash. This happened because we
14827 +# could end up double-freeing a struct value.
14828 +proc test_cast_regression {} {
14829 + gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
14830 + gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
14831 + gdb_test "python print v" "5" "print value for cast test"
14834 # Regression test for invalid subscript operations. The bug was that
14835 # the type of the value was not being checked before allowing a
14836 # subscript operation to proceed.
14837 @@ -437,6 +446,7 @@ if ![runto_main] then {
14838 test_value_in_inferior
14840 test_value_after_death
14841 +test_cast_regression
14843 # The following test recompiles the binary to test either C or C++
14845 diff --git a/gdb/testsuite/gdb.python/rh634108-solib_address.exp b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
14846 new file mode 100644
14847 index 0000000..70319ff
14849 +++ b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
14851 +# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
14853 +# This program is free software; you can redistribute it and/or modify
14854 +# it under the terms of the GNU General Public License as published by
14855 +# the Free Software Foundation; either version 3 of the License, or
14856 +# (at your option) any later version.
14858 +# This program is distributed in the hope that it will be useful,
14859 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
14860 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14861 +# GNU General Public License for more details.
14863 +# You should have received a copy of the GNU General Public License
14864 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
14866 +# https://bugzilla.redhat.com/show_bug.cgi?id=634108
14871 +# Skip all tests if Python scripting is not enabled.
14872 +if { [skip_python_tests] } { continue }
14874 +gdb_test "python print gdb.solib_address(-1)" "None" "gdb.solib_address exists"
14875 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
14876 new file mode 100644
14877 index 0000000..4dc308b
14879 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
14881 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
14883 + Copyright 2008, 2009 Free Software Foundation, Inc.
14885 + This file is part of GDB.
14887 + This program is free software; you can redistribute it and/or modify
14888 + it under the terms of the GNU General Public License as published by
14889 + the Free Software Foundation; either version 2 of the License, or
14890 + (at your option) any later version.
14892 + This program is distributed in the hope that it will be useful,
14893 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14894 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14895 + GNU General Public License for more details.
14897 + You should have received a copy of the GNU General Public License
14898 + along with this program; if not, write to the Free Software
14899 + Foundation, Inc., 59 Temple Place - Suite 330,
14900 + Boston, MA 02111-1307, USA. */
14902 +#include <string.h>
14903 +#include <errno.h>
14908 + int i = usleep (1000000 / 100);
14909 + assert (i == 0 || errno == EINTR);
14912 +#if defined FOLLOW_PARENT
14917 + pid_t child, pid_got;
14918 + int exit_code = 42 + nr;
14927 + printf ("child%d: %d\n", nr, (int) getpid ());
14928 + /* Delay to get both the "child%d" and "parent%d" message printed without
14929 + a race breaking expect by its endless wait on `$gdb_prompt$':
14930 + Breakpoint 3, breakpoint () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
14932 + (gdb) parent2: 14223 */
14936 + /* We must not get caught here (against a forgotten breakpoint). */
14940 + _exit (exit_code);
14942 + printf ("parent%d: %d\n", nr, (int) child);
14943 + /* Delay to get both the "child%d" and "parent%d" message printed, see
14948 + pid_got = wait (&status);
14949 + assert (pid_got == child);
14950 + assert (WIFEXITED (status));
14951 + assert (WEXITSTATUS (status) == exit_code);
14953 + /* We must get caught here (against a false watchpoint removal). */
14958 +#elif defined FOLLOW_CHILD
14960 +static volatile int usr1_got;
14963 +handler_usr1 (int signo)
14973 + struct sigaction act, oldact;
14975 + void *thread_result;
14978 + memset (&act, 0, sizeof act);
14979 + act.sa_flags = SA_RESTART;
14980 + act.sa_handler = handler_usr1;
14981 + sigemptyset (&act.sa_mask);
14982 + i = sigaction (SIGUSR1, &act, &oldact);
14991 + printf ("parent%d: %d\n", nr, (int) child);
14993 + /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB
14994 + tracing the child fork with no longer valid thread/lwp entries of the
15000 + /* We must not get caught here (against a forgotten breakpoint). */
15006 + /* And neither got caught our thread. */
15009 + i = pthread_join (thread, &thread_result);
15011 + assert (thread_result == (void *) 99UL);
15014 + /* Be sure our child knows we did not get caught above. */
15016 + i = kill (child, SIGUSR1);
15019 + /* Sleep for a while to check GDB's `info threads' no longer tracks us in
15020 + the child fork. */
15027 + printf ("child%d: %d\n", nr, (int) getpid ());
15029 + /* Let the parent signal us about its success. Be careful of races. */
15031 + for (loop = 0; loop < 1000; loop++)
15033 + /* Parent either died (and USR1_GOT is zero) or it succeeded. */
15034 + if (kill (getppid (), 0) != 0)
15036 + /* Parent succeeded? */
15042 + assert (usr1_got);
15044 + /* We must get caught here (against a false watchpoint removal). */
15049 + i = sigaction (SIGUSR1, &oldact, NULL);
15054 +# error "!FOLLOW_PARENT && !FOLLOW_CHILD"
15056 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
15057 new file mode 100644
15058 index 0000000..edacfc0
15060 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
15062 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
15064 + Copyright 2008, 2009 Free Software Foundation, Inc.
15066 + This file is part of GDB.
15068 + This program is free software; you can redistribute it and/or modify
15069 + it under the terms of the GNU General Public License as published by
15070 + the Free Software Foundation; either version 2 of the License, or
15071 + (at your option) any later version.
15073 + This program is distributed in the hope that it will be useful,
15074 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15075 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15076 + GNU General Public License for more details.
15078 + You should have received a copy of the GNU General Public License
15079 + along with this program; if not, write to the Free Software
15080 + Foundation, Inc., 59 Temple Place - Suite 330,
15081 + Boston, MA 02111-1307, USA. */
15083 +#include <assert.h>
15084 +#include <unistd.h>
15085 +#include <sys/wait.h>
15086 +#include <stdio.h>
15087 +#include <stdlib.h>
15088 +#include <pthread.h>
15090 +#include <asm/unistd.h>
15091 +#include <unistd.h>
15092 +#define gettid() syscall (__NR_gettid)
15094 +/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
15095 + variable. Hit-comments need to be duplicite there to catch both at-stops
15096 + and behind-stops, depending on the target. */
15098 +static volatile int var;
15110 +/* Include here the functions:
15111 + static void forkoff (int nr);
15112 + static void delay (void); */
15114 +static pthread_t thread;
15115 +static volatile int step;
15118 +#include "watchpoint-fork-forkoff.c"
15126 + while (step != 1)
15129 + var++; /* validity-thread-B */
15130 + dummy (); /* validity-thread-B */
15132 + while (step != 3)
15143 + var++; /* after-fork1-B */
15144 + dummy (); /* after-fork1-B */
15146 + while (step != 5)
15154 + var++; /* after-fork2-B */
15155 + dummy (); /* after-fork2-B */
15156 + return (void *) 5UL;
15159 + /* We must not get caught here (against a forgotten breakpoint). */
15162 + return (void *) 99UL;
15169 + void *thread_result;
15171 + setbuf (stdout, NULL);
15172 + printf ("main: %d\n", (int) gettid ());
15174 + /* General watchpoints validity. */
15175 + var++; /* validity-first */
15176 + dummy (); /* validity-first */
15178 + i = pthread_create (&thread, NULL, start, NULL);
15181 + var++; /* validity-thread-A */
15182 + dummy (); /* validity-thread-A */
15184 + while (step != 2)
15187 + /* Hardware watchpoints got disarmed here. */
15190 + var++; /* after-fork1-A */
15191 + dummy (); /* after-fork1-A */
15193 +#ifdef FOLLOW_CHILD
15194 + /* Spawn new thread as it was deleted in the child of FORK. */
15195 + i = pthread_create (&thread, NULL, start, NULL);
15198 + while (step != 4)
15201 + /* A sanity check for double hardware watchpoints removal. */
15204 + var++; /* after-fork2-A */
15205 + dummy (); /* after-fork2-A */
15207 +#ifdef FOLLOW_CHILD
15208 + /* Spawn new thread as it was deleted in the child of FORK. */
15209 + i = pthread_create (&thread, NULL, start, NULL);
15213 + i = pthread_join (thread, &thread_result);
15215 + assert (thread_result == (void *) 5UL);
15219 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.c b/gdb/testsuite/gdb.threads/watchpoint-fork.c
15220 new file mode 100644
15221 index 0000000..5f62e7f
15223 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.c
15225 +/* Test case for forgotten hw-watchpoints after fork()-off of a process.
15227 + Copyright 2008, 2009 Free Software Foundation, Inc.
15229 + This file is part of GDB.
15231 + This program is free software; you can redistribute it and/or modify
15232 + it under the terms of the GNU General Public License as published by
15233 + the Free Software Foundation; either version 2 of the License, or
15234 + (at your option) any later version.
15236 + This program is distributed in the hope that it will be useful,
15237 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15238 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15239 + GNU General Public License for more details.
15241 + You should have received a copy of the GNU General Public License
15242 + along with this program; if not, write to the Free Software
15243 + Foundation, Inc., 59 Temple Place - Suite 330,
15244 + Boston, MA 02111-1307, USA. */
15246 +#include <assert.h>
15247 +#include <unistd.h>
15248 +#include <sys/wait.h>
15249 +#include <stdio.h>
15250 +#include <stdlib.h>
15252 +static volatile int var;
15259 +/* Include here the function:
15260 + static void forkoff (int nr); */
15262 +#include "watchpoint-fork-forkoff.c"
15267 + setbuf (stdout, NULL);
15268 + printf ("main: %d\n", (int) getpid ());
15270 + /* General watchpoints validity. */
15272 + /* Hardware watchpoints got disarmed here. */
15274 + /* This watchpoint got lost before. */
15276 + /* A sanity check for double hardware watchpoints removal. */
15282 diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
15283 new file mode 100644
15284 index 0000000..1dc93ab
15286 +++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
15288 +# Copyright 2008, 2009 Free Software Foundation, Inc.
15290 +# This program is free software; you can redistribute it and/or modify
15291 +# it under the terms of the GNU General Public License as published by
15292 +# the Free Software Foundation; either version 3 of the License, or
15293 +# (at your option) any later version.
15295 +# This program is distributed in the hope that it will be useful,
15296 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
15297 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15298 +# GNU General Public License for more details.
15300 +# You should have received a copy of the GNU General Public License
15301 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
15303 +# Test case for forgotten hw-watchpoints after fork()-off of a process.
15305 +proc test {type symbol} {
15306 + global objdir subdir srcdir
15308 + set test watchpoint-fork
15311 + set prefix_test $pf_prefix
15312 + lappend pf_prefix "$type:"
15313 + set prefix_mt $pf_prefix
15317 + set pf_prefix $prefix_mt
15318 + lappend pf_prefix "singlethreaded:"
15320 + set executable ${test}-${type}
15321 + if { [gdb_compile ${srcdir}/${subdir}/${test}.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
15322 + untested ${test}.exp
15325 + clean_restart $executable
15327 + gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on."
15328 + gdb_test "set follow-fork-mode $type"
15329 + gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"."
15330 + # Testcase uses it for the `follow-fork-mode child' type.
15331 + gdb_test "handle SIGUSR1 nostop noprint pass"
15333 + if { ![runto_main] } then {
15334 + gdb_suppress_tests
15338 + # Install the watchpoint only after getting into MAIN - workaround some PPC
15340 + gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
15342 + # It is never hit but it should not be left over in the fork()ed-off child.
15343 + gdb_breakpoint "breakpoint"
15345 + gdb_test "continue" \
15346 + "atchpoint 2: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
15347 + gdb_test "continue" \
15348 + "reakpoint 3, breakpoint.*" "breakpoint after the first fork"
15349 + gdb_test "continue" \
15350 + "atchpoint 2: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
15351 + gdb_test "continue" \
15352 + "reakpoint 3, breakpoint.*" "breakpoint after the second fork"
15353 + gdb_test "continue" \
15354 + "atchpoint 2: var.*Old value = 2.*New value = 3.*return *0;" "watchpoint after the second fork"
15355 + gdb_test "continue" "Continuing..*Program exited normally." "finish"
15360 + set pf_prefix $prefix_mt
15361 + lappend pf_prefix "multithreaded:"
15363 + set executable ${test}-mt-${type}
15364 + if { [gdb_compile_pthreads ${srcdir}/${subdir}/${test}-mt.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
15365 + untested ${test}.exp
15368 + clean_restart $executable
15370 + gdb_test "set follow-fork-mode $type"
15371 + # Testcase uses it for the `follow-fork-mode child' type.
15372 + gdb_test "handle SIGUSR1 nostop noprint pass"
15374 + if { ![runto_main] } then {
15375 + gdb_suppress_tests
15379 + # Install the watchpoint only after getting into MAIN - workaround some PPC
15381 + gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
15383 + # It is never hit but it should not be left over in the fork()ed-off child.
15384 + gdb_breakpoint "breakpoint"
15386 + gdb_test "continue" \
15387 + "atchpoint 2: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
15388 + gdb_test "continue" \
15389 + "atchpoint 2: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
15390 + gdb_test "continue" \
15391 + "atchpoint 2: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
15392 + gdb_test "continue" \
15393 + "reakpoint 3, breakpoint.*" "breakpoint (A) after the first fork"
15394 + gdb_test "continue" \
15395 + "atchpoint 2: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
15396 + gdb_test "continue" \
15397 + "atchpoint 2: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
15398 + gdb_test "continue" \
15399 + "reakpoint 3, breakpoint.*" "breakpoint (A) after the second fork"
15400 + gdb_test "continue" \
15401 + "atchpoint 2: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
15402 + gdb_test "continue" \
15403 + "atchpoint 2: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
15404 + gdb_test "continue" "Continuing..*Program exited normally." "finish"
15409 + set pf_prefix $prefix_test
15412 +test parent FOLLOW_PARENT
15414 +# Only GNU/Linux is known to support `set follow-fork-mode child'.
15415 +if {[istarget "*-*-linux*"]} {
15416 + test child FOLLOW_CHILD
15418 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
15419 index 20e2fb7..b27d25c 100644
15420 --- a/gdb/testsuite/lib/gdb.exp
15421 +++ b/gdb/testsuite/lib/gdb.exp
15422 @@ -27,6 +27,7 @@ if {$tool == ""} {
15425 load_lib libgloss.exp
15426 +load_lib python-support.exp
15430 diff --git a/gdb/testsuite/lib/pascal.exp b/gdb/testsuite/lib/pascal.exp
15431 index 9691bc1..13ea8b5 100644
15432 --- a/gdb/testsuite/lib/pascal.exp
15433 +++ b/gdb/testsuite/lib/pascal.exp
15434 @@ -37,6 +37,9 @@ proc pascal_init {} {
15435 global pascal_compiler_is_fpc
15436 global gpc_compiler
15437 global fpc_compiler
15438 + global fpcversion_major
15439 + global fpcversion_minor
15440 + global fpcversion_release
15443 if { $pascal_init_done == 1 } {
15444 @@ -64,6 +67,20 @@ proc pascal_init {} {
15445 set pascal_compiler_is_fpc 1
15446 verbose -log "Free Pascal compiler found"
15449 + # Detect the fpc-version
15450 + if { $pascal_compiler_is_fpc == 1 } {
15451 + set fpcversion_major 1
15452 + set fpcversion_minor 0
15453 + set fpcversion_release 0
15454 + set fpcversion [ remote_exec host $fpc_compiler "-iV" ]
15455 + if [regexp {.*([0-9]+)\.([0-9]+)\.([0-9]+).?} $fpcversion] {
15456 + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\1} fpcversion_major
15457 + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\2} fpcversion_minor
15458 + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\3} fpcversion_release
15460 + verbose -log "Freepascal version: $fpcversion_major.$fpcversion_minor.$fpcversion_release"
15463 set pascal_init_done 1
15465 diff --git a/gdb/testsuite/lib/python-support.exp b/gdb/testsuite/lib/python-support.exp
15466 new file mode 100644
15467 index 0000000..b8e9836
15469 +++ b/gdb/testsuite/lib/python-support.exp
15471 +global python_supported_saved
15473 +# Return 1 if Python scripting is supported in GDB, 0 if not.
15474 +proc python_supported { } {
15475 + global gdb_prompt
15476 + global python_supported_saved
15478 + if [info exists python_supported_saved] {
15479 + verbose "python_supported: returning saved $python_supported_saved" 2
15480 + return $python_supported_saved
15483 + gdb_test_multiple "python print 'hello, world!'" "verify python support" {
15484 + -re "not supported.*$gdb_prompt $" {
15485 + return [set python_supported_saved 0]
15487 + -re "$gdb_prompt $" {
15488 + return [set python_supported_saved 1]
15492 + return [set python_supported_saved 0]
15495 +# Run a command in GDB, and report a failure if a Python exception is thrown.
15496 +# If report_pass is true, report a pass if no exception is thrown.
15497 +proc gdb_py_test_silent_cmd {cmd name report_pass} {
15498 + global gdb_prompt
15500 + gdb_test_multiple $cmd $name {
15501 + -re "Traceback.*$gdb_prompt $" { fail $name }
15502 + -re "$gdb_prompt $" { if $report_pass { pass $name } }
15506 +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
15507 +# Run a test named NAME, consisting of multiple lines of input.
15508 +# After each input line INPUT, search for result line RESULT.
15509 +# Succeed if all results are seen; fail otherwise.
15510 +proc gdb_py_test_multiple {name args} {
15511 + global gdb_prompt
15513 + foreach {input result} $args {
15514 + if {[gdb_test_multiple $input "$name - $input" {
15515 + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
15516 + pass "$name - $input"
15524 diff --git a/gdb/thread.c b/gdb/thread.c
15525 index 0b291ba..ae3e4ff 100644
15528 @@ -90,6 +90,16 @@ delete_step_resume_breakpoint (struct thread_info *tp)
15533 +delete_exception_resume_breakpoint (struct thread_info *tp)
15535 + if (tp && tp->exception_resume_breakpoint)
15537 + delete_breakpoint (tp->exception_resume_breakpoint);
15538 + tp->exception_resume_breakpoint = NULL;
15543 clear_thread_inferior_resources (struct thread_info *tp)
15545 @@ -103,6 +113,12 @@ clear_thread_inferior_resources (struct thread_info *tp)
15546 tp->step_resume_breakpoint = NULL;
15549 + if (tp->exception_resume_breakpoint)
15551 + tp->exception_resume_breakpoint->disposition = disp_del_at_next_stop;
15552 + tp->exception_resume_breakpoint = NULL;
15555 bpstat_clear (&tp->stop_bpstat);
15557 discard_all_intermediate_continuations_thread (tp);
15558 diff --git a/gdb/top.c b/gdb/top.c
15559 index b29e68d..8edac70 100644
15562 @@ -337,6 +337,7 @@ void
15563 prepare_execute_command (void)
15565 free_all_values ();
15566 + free_all_types ();
15568 /* With multiple threads running while the one we're examining is stopped,
15569 the dcache can get stale without us being able to detect it.
15570 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
15571 index ce9f551..5f9d739 100644
15572 --- a/gdb/typeprint.c
15573 +++ b/gdb/typeprint.c
15575 #include "gdb_string.h"
15576 #include "exceptions.h"
15577 #include "valprint.h"
15578 +#include "dwarf2loc.h"
15581 extern void _initialize_typeprint (void);
15582 @@ -77,6 +78,9 @@ void
15583 type_print (struct type *type, char *varstring, struct ui_file *stream,
15587 + type = check_typedef (type);
15589 LA_PRINT_TYPE (type, varstring, stream, show, 0);
15592 @@ -115,7 +119,8 @@ whatis_exp (char *exp, int show)
15594 struct expression *expr;
15596 - struct cleanup *old_chain = NULL;
15597 + /* Required at least for the object_address_set call. */
15598 + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
15599 struct type *real_type = NULL;
15602 @@ -126,12 +131,13 @@ whatis_exp (char *exp, int show)
15605 expr = parse_expression (exp);
15606 - old_chain = make_cleanup (free_current_contents, &expr);
15607 + make_cleanup (free_current_contents, &expr);
15608 val = evaluate_type (expr);
15611 val = access_value_history (0);
15613 + object_address_set (value_raw_address (val));
15614 type = value_type (val);
15616 get_user_print_options (&opts);
15617 @@ -168,8 +174,7 @@ whatis_exp (char *exp, int show)
15618 type_print (type, "", gdb_stdout, show);
15619 printf_filtered ("\n");
15622 - do_cleanups (old_chain);
15623 + do_cleanups (old_chain);
15627 diff --git a/gdb/valarith.c b/gdb/valarith.c
15628 index 0c40905..a781636 100644
15629 --- a/gdb/valarith.c
15630 +++ b/gdb/valarith.c
15631 @@ -161,12 +161,26 @@ value_subscript (struct value *array, LONGEST index)
15633 get_discrete_bounds (range_type, &lowerbound, &upperbound);
15634 if (VALUE_LVAL (array) != lval_memory)
15635 - return value_subscripted_rvalue (array, index, lowerbound);
15637 + if (index >= lowerbound && index <= upperbound)
15639 + CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
15640 + CORE_ADDR offset = (index - lowerbound) * element_size;
15642 + return value_subscripted_rvalue (array, offset);
15644 + error (_("array or string index out of range"));
15649 if (index >= lowerbound && index <= upperbound)
15650 - return value_subscripted_rvalue (array, index, lowerbound);
15652 + CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
15653 + CORE_ADDR offset = (index - lowerbound) * element_size;
15655 + return value_subscripted_rvalue (array, offset);
15657 /* Emit warning unless we have an array of unknown size.
15658 An array of unknown size has lowerbound 0 and upperbound -1. */
15659 if (upperbound > -1)
15660 @@ -185,34 +199,37 @@ value_subscript (struct value *array, LONGEST index)
15661 error (_("not an array or string"));
15664 -/* Return the value of EXPR[IDX], expr an aggregate rvalue
15665 - (eg, a vector register). This routine used to promote floats
15666 - to doubles, but no longer does. */
15667 +/* Return the value of *((void *) ARRAY + ELEMENT), ARRAY an aggregate rvalue
15668 + (eg, a vector register). This routine used to promote floats to doubles,
15669 + but no longer does. OFFSET is zero-based with 0 for the lowermost existing
15670 + element, it must be expressed in bytes (therefore multiplied by
15671 + check_typedef (TYPE_TARGET_TYPE (array_type)). */
15674 -value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
15675 +value_subscripted_rvalue (struct value *array, CORE_ADDR offset)
15677 struct type *array_type = check_typedef (value_type (array));
15678 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
15679 - unsigned int elt_size = TYPE_LENGTH (elt_type);
15680 - unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
15683 - if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
15684 - && elt_offs >= TYPE_LENGTH (array_type)))
15685 - error (_("no such vector element"));
15686 + /* Do not check TYPE_LENGTH (array_type) as we may have been given the
15687 + innermost dimension of a multi-dimensional Fortran array where its length
15688 + is shorter than the possibly accessed element offset. */
15690 v = allocate_value (elt_type);
15691 if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
15692 set_value_lazy (v, 1);
15694 - memcpy (value_contents_writeable (v),
15695 - value_contents (array) + elt_offs, elt_size);
15697 + unsigned int elt_size = TYPE_LENGTH (elt_type);
15698 + memcpy (value_contents_writeable (v),
15699 + value_contents (array) + offset, elt_size);
15702 set_value_component_location (v, array);
15703 VALUE_REGNUM (v) = VALUE_REGNUM (array);
15704 VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
15705 - set_value_offset (v, value_offset (array) + elt_offs);
15706 + set_value_offset (v, value_offset (array) + offset);
15710 @@ -292,6 +309,10 @@ int
15711 binop_user_defined_p (enum exp_opcode op,
15712 struct value *arg1, struct value *arg2)
15714 + /* FIXME: We should support user defined ops for dynamic types. */
15715 + if (TYPE_DYNAMIC (value_type (arg1)) || TYPE_DYNAMIC (value_type (arg2)))
15718 return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
15721 diff --git a/gdb/valops.c b/gdb/valops.c
15722 index 7fbad10..8e32405 100644
15726 #include "cp-support.h"
15728 #include "user-regs.h"
15729 +#include "dwarf2loc.h"
15732 #include "gdb_string.h"
15733 @@ -858,6 +859,65 @@ value_one (struct type *type, enum lval_type lv)
15737 +/* object_address_set must be already called before this function. */
15740 +object_address_data_not_valid (struct type *type)
15742 + /* Attributes are present only at the target type of a typedef. Make the
15743 + call conditional as it would otherwise loop through type_length_get. */
15744 + if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
15745 + CHECK_TYPEDEF (type);
15747 + /* DW_AT_associated has a preference over DW_AT_allocated. */
15748 + if (TYPE_NOT_ASSOCIATED (type)
15749 + || (TYPE_ASSOCIATED (type) != NULL
15750 + && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
15751 + return N_("object is not associated");
15753 + if (TYPE_NOT_ALLOCATED (type)
15754 + || (TYPE_ALLOCATED (type) != NULL
15755 + && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
15756 + return N_("object is not allocated");
15761 +/* Return non-NULL check_typedef result on TYPE if the variable is valid. If
15762 + it is valid the function may store the data address (DW_AT_DATA_LOCATION) of
15763 + TYPE at *ADDRESS_RETURN. You must set *ADDRESS_RETURN from
15764 + value_raw_address (VAL) before calling this function. If no
15765 + DW_AT_DATA_LOCATION is present for TYPE the address at *ADDRESS_RETURN is
15766 + left unchanged. ADDRESS_RETURN must not be NULL, use
15767 + object_address_data_not_valid () for just the data validity check. */
15770 +object_address_get_data (struct type *type, CORE_ADDR *address_return)
15772 + gdb_assert (address_return != NULL);
15774 + object_address_set (*address_return);
15776 + /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
15777 + at the target type of a typedef. */
15778 + CHECK_TYPEDEF (type);
15780 + if (object_address_data_not_valid (type) != NULL)
15782 + /* Do not try to evaluate DW_AT_data_location as it may even crash
15783 + (it would just return the value zero in the gfortran case). */
15787 + if (TYPE_DATA_LOCATION_IS_ADDR (type))
15788 + *address_return = TYPE_DATA_LOCATION_ADDR (type);
15789 + else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
15791 + = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
15796 /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */
15798 static struct value *
15799 @@ -956,15 +1016,21 @@ value_fetch_lazy (struct value *val)
15801 else if (VALUE_LVAL (val) == lval_memory)
15803 - CORE_ADDR addr = value_address (val);
15804 - int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
15805 + CORE_ADDR addr = value_raw_address (val);
15808 + if (object_address_get_data (value_type (val), &addr))
15810 - if (value_stack (val))
15811 - read_stack (addr, value_contents_all_raw (val), length);
15813 - read_memory (addr, value_contents_all_raw (val), length);
15814 + struct type *type = value_enclosing_type (val);
15815 + int length = TYPE_LENGTH (check_typedef (type));
15819 + addr += value_offset (val);
15820 + if (value_stack (val))
15821 + read_stack (addr, value_contents_all_raw (val), length);
15823 + read_memory (addr, value_contents_all_raw (val), length);
15827 else if (VALUE_LVAL (val) == lval_register)
15828 @@ -1374,7 +1440,18 @@ address_of_variable (struct symbol *var, struct block *b)
15829 if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
15830 || TYPE_CODE (type) == TYPE_CODE_FUNC)
15832 - CORE_ADDR addr = value_address (val);
15835 + if (VALUE_LVAL (val) == lval_memory)
15837 + addr = value_raw_address (val);
15838 + if (!object_address_get_data (type, &addr))
15839 + error (_("Can't take address of memory lvalue \"%s\"."),
15840 + SYMBOL_PRINT_NAME (var));
15841 + set_value_address (val, addr);
15844 + addr = value_address (val);
15846 return value_from_pointer (lookup_pointer_type (type), addr);
15848 @@ -1481,6 +1558,7 @@ struct value *
15849 value_coerce_array (struct value *arg1)
15851 struct type *type = check_typedef (value_type (arg1));
15852 + CORE_ADDR address;
15854 /* If the user tries to do something requiring a pointer with an
15855 array that has not yet been pushed to the target, then this would
15856 @@ -1490,8 +1568,12 @@ value_coerce_array (struct value *arg1)
15857 if (VALUE_LVAL (arg1) != lval_memory)
15858 error (_("Attempt to take address of value not located in memory."));
15860 + address = value_raw_address (arg1);
15861 + if (!object_address_get_data (type, &address))
15862 + error (_("Attempt to take address of non-valid value."));
15864 return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
15865 - value_address (arg1));
15866 + address + value_offset (arg1));
15869 /* Given a value which is a function, return a value which is a pointer
15870 diff --git a/gdb/valprint.c b/gdb/valprint.c
15871 index ad6268e..fb0ef7a 100644
15872 --- a/gdb/valprint.c
15873 +++ b/gdb/valprint.c
15876 #include "python/python.h"
15877 #include "ada-lang.h"
15878 +#include "dwarf2loc.h"
15882 @@ -237,7 +238,6 @@ scalar_type_p (struct type *type)
15883 case TYPE_CODE_STRUCT:
15884 case TYPE_CODE_UNION:
15885 case TYPE_CODE_SET:
15886 - case TYPE_CODE_STRING:
15887 case TYPE_CODE_BITSTRING:
15890 @@ -1142,6 +1142,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15892 unsigned int things_printed = 0;
15894 + struct type *saved_type = type;
15895 struct type *elttype, *index_type;
15897 /* Position of the array element we are examining to see
15898 @@ -1150,9 +1151,33 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15899 /* Number of repetitions we have detected so far. */
15901 LONGEST low_bound_index = 0;
15902 + struct cleanup *back_to;
15903 + CORE_ADDR saved_address = address;
15905 + back_to = make_cleanup (null_cleanup, 0);
15906 + type = object_address_get_data (type, &address);
15909 + fputs_filtered (object_address_data_not_valid (type), stream);
15910 + do_cleanups (back_to);
15913 + if (address != saved_address)
15915 + size_t length = TYPE_LENGTH (type);
15917 - elttype = TYPE_TARGET_TYPE (type);
15918 - eltlen = TYPE_LENGTH (check_typedef (elttype));
15919 + valaddr = xmalloc (length);
15920 + make_cleanup (xfree, (gdb_byte *) valaddr);
15921 + read_memory (address, (gdb_byte *) valaddr, length);
15924 + /* Skip typedefs but do not resolve TYPE_DYNAMIC. */
15925 + elttype = saved_type;
15926 + while (TYPE_CODE (elttype) == TYPE_CODE_TYPEDEF)
15927 + elttype = TYPE_TARGET_TYPE (elttype);
15928 + elttype = TYPE_TARGET_TYPE (elttype);
15930 + eltlen = TYPE_ARRAY_BYTE_STRIDE_VALUE (type);
15931 index_type = TYPE_INDEX_TYPE (type);
15933 /* Compute the number of elements in the array. On most arrays,
15934 @@ -1160,9 +1185,6 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15935 is simply the size of the array divided by the size of the elements.
15936 But for arrays of elements whose size is zero, we need to look at
15939 - len = TYPE_LENGTH (type) / eltlen;
15944 @@ -1236,6 +1258,8 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
15946 fprintf_filtered (stream, "...");
15949 + do_cleanups (back_to);
15952 /* Read LEN bytes of target memory at address MEMADDR, placing the
15953 diff --git a/gdb/value.c b/gdb/value.c
15954 index d552402..b10269c 100644
15958 #include "objfiles.h"
15959 #include "valprint.h"
15960 #include "cli/cli-decode.h"
15961 +#include "observer.h"
15963 #include "python/python.h"
15965 @@ -828,12 +829,15 @@ void
15966 set_value_component_location (struct value *component,
15967 const struct value *whole)
15971 if (whole->lval == lval_internalvar)
15972 VALUE_LVAL (component) = lval_internalvar_component;
15974 VALUE_LVAL (component) = whole->lval;
15976 component->location = whole->location;
15978 if (whole->lval == lval_computed)
15980 struct lval_funcs *funcs = whole->location.computed.funcs;
15981 @@ -841,6 +845,12 @@ set_value_component_location (struct value *component,
15982 if (funcs->copy_closure)
15983 component->location.computed.closure = funcs->copy_closure (whole);
15986 + addr = value_raw_address (component);
15987 + object_address_get_data (value_type (whole), &addr);
15988 + if (component->lval != lval_internalvar
15989 + && component->lval != lval_internalvar_component)
15990 + set_value_address (component, addr);
15994 @@ -973,6 +983,29 @@ show_values (char *num_exp, int from_tty)
15999 +/* Sanity check for memory leaks and proper types reference counting. */
16002 +value_history_cleanup (void *unused)
16004 + while (value_history_chain)
16006 + struct value_history_chunk *chunk = value_history_chain;
16009 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
16010 + value_free (chunk->values[i]);
16012 + value_history_chain = chunk->next;
16015 + value_history_count = 0;
16017 + /* Free the unreferenced types above. */
16018 + free_all_values ();
16019 + free_all_types ();
16022 /* Internal variables. These are variables within the debugger
16023 that hold values assigned by debugger commands.
16024 @@ -1451,6 +1484,40 @@ call_internal_function (struct gdbarch *gdbarch,
16025 return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
16028 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
16031 +value_types_mark_used (void)
16033 + struct internalvar *var;
16034 + struct value_history_chunk *chunk;
16036 + for (var = internalvars; var != NULL; var = var->next)
16037 + switch (var->kind)
16039 + case INTERNALVAR_VALUE:
16040 + type_mark_used (value_type (var->u.value));
16043 + case INTERNALVAR_INTEGER:
16044 + type_mark_used (var->u.integer.type);
16047 + case INTERNALVAR_POINTER:
16048 + type_mark_used (var->u.pointer.type);
16052 + for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
16056 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
16057 + if (chunk->values[i])
16058 + type_mark_used (value_type (chunk->values[i]));
16062 /* The 'function' command. This does nothing -- it is just a
16063 placeholder to let "help function NAME" work. This is also used as
16064 the implementation of the sub-command that is created when
16065 @@ -1498,11 +1565,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
16066 htab_t copied_types)
16068 if (TYPE_OBJFILE (value->type) == objfile)
16069 - value->type = copy_type_recursive (objfile, value->type, copied_types);
16070 + value->type = copy_type_recursive (value->type, copied_types);
16072 if (TYPE_OBJFILE (value->enclosing_type) == objfile)
16073 - value->enclosing_type = copy_type_recursive (objfile,
16074 - value->enclosing_type,
16075 + value->enclosing_type = copy_type_recursive (value->enclosing_type,
16079 @@ -1517,13 +1583,13 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
16080 case INTERNALVAR_INTEGER:
16081 if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
16082 var->u.integer.type
16083 - = copy_type_recursive (objfile, var->u.integer.type, copied_types);
16084 + = copy_type_recursive (var->u.integer.type, copied_types);
16087 case INTERNALVAR_POINTER:
16088 if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
16089 var->u.pointer.type
16090 - = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
16091 + = copy_type_recursive (var->u.pointer.type, copied_types);
16094 case INTERNALVAR_VALUE:
16095 @@ -2387,7 +2453,24 @@ value_from_decfloat (struct type *type, const gdb_byte *dec)
16097 coerce_ref (struct value *arg)
16099 - struct type *value_type_arg_tmp = check_typedef (value_type (arg));
16100 + struct type *value_type_arg_tmp;
16102 + if (TYPE_DYNAMIC (value_type (arg)))
16104 + struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
16105 + CORE_ADDR address;
16107 + value_type_arg_tmp = value_type (arg);
16108 + address = value_raw_address (arg);
16109 + value_type_arg_tmp = object_address_get_data (value_type_arg_tmp,
16111 + if (! value_type_arg_tmp)
16112 + error (_("Attempt to coerce non-valid value."));
16113 + arg = value_at_lazy (value_type_arg_tmp, address);
16114 + do_cleanups (cleanups);
16117 + value_type_arg_tmp = check_typedef (value_type (arg));
16119 if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
16120 arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
16121 @@ -2485,4 +2568,8 @@ VARIABLE is already initialized."));
16122 add_prefix_cmd ("function", no_class, function_command, _("\
16123 Placeholder command for showing help on convenience functions."),
16124 &functionlist, "function ", 0, &cmdlist);
16126 + make_final_cleanup (value_history_cleanup, NULL);
16128 + observer_attach_mark_used (value_types_mark_used);
16130 diff --git a/gdb/value.h b/gdb/value.h
16131 index 12cbc0a..a508bf6 100644
16134 @@ -372,6 +372,10 @@ extern struct value *value_from_double (struct type *type, DOUBLEST num);
16135 extern struct value *value_from_decfloat (struct type *type,
16136 const gdb_byte *decbytes);
16138 +extern const char *object_address_data_not_valid (struct type *type);
16139 +extern struct type *object_address_get_data (struct type *type,
16140 + CORE_ADDR *address_return);
16142 extern struct value *value_at (struct type *type, CORE_ADDR addr);
16143 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
16145 @@ -729,7 +733,7 @@ extern struct value *value_allocate_space_in_inferior (int);
16146 extern struct value *value_of_local (const char *name, int complain);
16148 extern struct value *value_subscripted_rvalue (struct value *array,
16149 - LONGEST index, int lowerbound);
16150 + CORE_ADDR offset);
16152 /* User function handler. */
16154 diff --git a/gdb/varobj.c b/gdb/varobj.c
16155 index b9b8e91..a81d25c 100644
16159 #include "gdbcmd.h"
16161 #include "valprint.h"
16162 +#include "objfiles.h"
16163 +#include "parser-defs.h"
16165 #include "gdb_assert.h"
16166 #include "gdb_string.h"