1 http://sourceware.org/gdb/wiki/ProjectArcher
2 http://sourceware.org/gdb/wiki/ArcherBranchManagement
5 commit 897686c0aedb7a6da59b823f22b1d24ec5a1d2ba
7 branch `archer' - the merge of branches:
8 archer-jankratochvil-vla
10 archer-tromey-dwz-multifile-rebase (but from post-7.5 FSF GDB commits)
13 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
14 index a41cff9..d7786a6 100644
17 @@ -704,7 +704,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
18 exceptions.c expprint.c \
19 f-exp.y f-lang.c f-typeprint.c f-valprint.c filesystem.c \
20 findcmd.c findvar.c frame.c frame-base.c frame-unwind.c \
21 - gdbarch.c arch-utils.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \
22 + gdbarch.c arch-utils.c gdb_bfd.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \
23 go-exp.y go-lang.c go-typeprint.c go-valprint.c \
26 @@ -829,7 +829,7 @@ gnulib/import/extra/snippet/warn-on-use.h \
27 gnulib/import/stddef.in.h gnulib/import/inttypes.in.h inline-frame.h skip.h \
28 common/common-utils.h common/xml-utils.h common/buffer.h common/ptid.h \
30 -common/linux-osdata.h gdb-dlfcn.h auto-load.h probe.h stap-probe.h
31 +common/linux-osdata.h gdb-dlfcn.h auto-load.h probe.h stap-probe.h gdb_bfd.h
33 # Header files that already have srcdir in them, or which are in objdir.
35 @@ -879,7 +879,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
36 macrotab.o macrocmd.o macroexp.o macroscope.o \
38 event-loop.o event-top.o inf-loop.o completer.o \
39 - gdbarch.o arch-utils.o gdbtypes.o osabi.o copying.o \
40 + gdbarch.o arch-utils.o gdbtypes.o gdb_bfd.o osabi.o copying.o \
41 memattr.o mem-break.o target.o parse.o language.o buildsym.o \
44 @@ -1307,6 +1307,12 @@ stamp-h: $(srcdir)/config.in config.status
46 $(SHELL) config.status
48 +.gdbinit: $(srcdir)/gdbinit.in config.status
49 + CONFIG_FILES=".gdbinit:gdbinit.in" \
52 + $(SHELL) config.status
54 config.status: $(srcdir)/configure configure.tgt configure.host
55 $(SHELL) config.status --recheck
57 diff --git a/gdb/NEWS b/gdb/NEWS
58 index b281824..4da886c 100644
62 What has changed in GDB?
63 (Organized release by release)
65 +*** Changes since GDB 7.5
67 +* New commands (for set/show, see "New options" below)
70 + List the BFDs known to GDB.
72 *** Changes in GDB 7.5
74 * GDB now supports x32 ABI. Visit <http://sites.google.com/site/x32abi/>
75 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
76 index aa090af..e672731 100644
79 @@ -12037,6 +12037,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
82 ada_operator_check (struct expression *exp, int pos,
83 + int (*type_func) (struct type *type, void *data),
84 int (*objfile_func) (struct objfile *objfile, void *data),
87 @@ -12051,12 +12052,15 @@ ada_operator_check (struct expression *exp, int pos,
91 - return operator_check_standard (exp, pos, objfile_func, data);
92 + return operator_check_standard (exp, pos, type_func, objfile_func,
96 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
98 - if (type && TYPE_OBJFILE (type)
99 + if (type && type_func && (*type_func) (type, data))
101 + if (type && TYPE_OBJFILE (type) && objfile_func
102 && (*objfile_func) (TYPE_OBJFILE (type), data))
105 diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
106 index 6728800..455d3e6 100644
107 --- a/gdb/bfd-target.c
108 +++ b/gdb/bfd-target.c
111 #include "bfd-target.h"
113 +#include "gdb_bfd.h"
115 /* The object that is stored in the target_ops->to_data field has this
117 @@ -70,7 +71,7 @@ target_bfd_xclose (struct target_ops *t, int quitting)
119 struct target_bfd_data *data = t->to_data;
121 - bfd_close (data->bfd);
122 + gdb_bfd_unref (data->bfd);
123 xfree (data->table.sections);
126 @@ -84,6 +85,7 @@ target_bfd_reopen (struct bfd *abfd)
128 data = XZALLOC (struct target_bfd_data);
130 + gdb_bfd_ref (abfd);
131 build_section_table (abfd, &data->table.sections, &data->table.sections_end);
133 t = XZALLOC (struct target_ops);
134 diff --git a/gdb/bfd-target.h b/gdb/bfd-target.h
135 index 71001c5..7f4e628 100644
136 --- a/gdb/bfd-target.h
137 +++ b/gdb/bfd-target.h
142 -/* Given an existing BFD, re-open it as a "struct target_ops". On
143 - close, it will also close the corresponding BFD (which is like
144 - freopen and fdopen). */
145 +/* Given an existing BFD, re-open it as a "struct target_ops". This
146 + acquires a new reference to the BFD. This reference will be
147 + released when the target is closed. */
148 struct target_ops *target_bfd_reopen (struct bfd *bfd);
151 diff --git a/gdb/block.c b/gdb/block.c
152 index a0f82ec..097dbf6 100644
155 @@ -692,3 +692,21 @@ block_iter_match_next (const char *name,
157 return block_iter_match_step (iterator, name, compare, 0);
160 +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
161 + whatever reason. */
164 +block_objfile (const struct block *block)
166 + struct symbol *func;
171 + func = block_linkage_function (block);
175 + return SYMBOL_SYMTAB (func)->objfile;
177 diff --git a/gdb/block.h b/gdb/block.h
178 index 99c4788..6ceb704 100644
181 @@ -279,4 +279,6 @@ extern struct symbol *block_iter_match_next (const char *name,
183 (sym) = block_iterator_next (&(iter)))
185 +extern struct objfile *block_objfile (const struct block *block);
188 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
189 index 78fffd3..224ba49 100644
190 --- a/gdb/breakpoint.c
191 +++ b/gdb/breakpoint.c
192 @@ -15519,6 +15519,24 @@ all_tracepoints (void)
197 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
200 +breakpoint_types_mark_used (void)
202 + struct breakpoint *b;
204 + ALL_BREAKPOINTS (b)
207 + exp_types_mark_used (b->exp);
209 + type_mark_used (value_type (b->val));
215 /* This help string is used for the break, hbreak, tbreak and thbreak
216 commands. It is defined as a macro to prevent duplication.
217 @@ -16484,4 +16502,7 @@ agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
218 automatic_hardware_breakpoints = 1;
220 observer_attach_about_to_proceed (breakpoint_about_to_proceed);
222 + observer_attach_mark_used (breakpoint_types_mark_used);
225 diff --git a/gdb/buildsym.c b/gdb/buildsym.c
226 index d547012..e4882fb 100644
229 @@ -966,11 +966,14 @@ reset_symtab_globals (void)
232 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
236 + If REQUIRED is non-zero, then a symtab is created even if it does
237 + not contain any symbols. */
240 end_symtab_get_static_block (CORE_ADDR end_addr, struct objfile *objfile,
242 + int expandable, int required)
244 /* Finish the lexical context of the last function in the file; pop
245 the context stack. */
246 @@ -1038,7 +1041,8 @@ end_symtab_get_static_block (CORE_ADDR end_addr, struct objfile *objfile,
247 cleanup_undefined_stabs_types (objfile);
248 finish_global_stabs (objfile);
250 - if (pending_blocks == NULL
252 + && pending_blocks == NULL
253 && file_symbols == NULL
254 && global_symbols == NULL
255 && have_line_numbers == 0
256 @@ -1296,7 +1300,7 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
258 struct block *static_block;
260 - static_block = end_symtab_get_static_block (end_addr, objfile, 0);
261 + static_block = end_symtab_get_static_block (end_addr, objfile, 0, 0);
262 return end_symtab_from_static_block (static_block, objfile, section, 0);
265 @@ -1308,7 +1312,7 @@ end_expandable_symtab (CORE_ADDR end_addr, struct objfile *objfile,
267 struct block *static_block;
269 - static_block = end_symtab_get_static_block (end_addr, objfile, 1);
270 + static_block = end_symtab_get_static_block (end_addr, objfile, 1, 0);
271 return end_symtab_from_static_block (static_block, objfile, section, 1);
274 diff --git a/gdb/buildsym.h b/gdb/buildsym.h
275 index 162ee8c..33b34c8 100644
278 @@ -260,7 +260,8 @@ extern char *pop_subfile (void);
280 extern struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
281 struct objfile *objfile,
286 extern struct symtab *end_symtab_from_static_block (struct block *static_block,
287 struct objfile *objfile,
288 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
289 index a5892b5..2944c2d 100644
290 --- a/gdb/c-typeprint.c
291 +++ b/gdb/c-typeprint.c
292 @@ -624,9 +624,14 @@ c_type_print_varspec_suffix (struct type *type,
293 fprintf_filtered (stream, ")");
295 fprintf_filtered (stream, "[");
296 - if (get_array_bounds (type, &low_bound, &high_bound))
297 - fprintf_filtered (stream, "%d",
298 - (int) (high_bound - low_bound + 1));
299 + if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind
300 + != RANGE_BOUND_KIND_CONSTANT)
302 + /* No _() - printed sources should not be locale dependent. */
303 + fprintf_filtered (stream, "variable");
305 + else if (get_array_bounds (type, &low_bound, &high_bound))
306 + fprintf_filtered (stream, "%d", (int) (high_bound - low_bound + 1));
307 fprintf_filtered (stream, "]");
309 c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
310 diff --git a/gdb/cc-with-dwz.sh b/gdb/cc-with-dwz.sh
311 deleted file mode 100755
312 index f66deb1..0000000
313 --- a/gdb/cc-with-dwz.sh
317 -# Wrapper around gcc to run 'dwz' when running the testsuite.
319 -# Copyright (C) 2010-2012 Free Software Foundation, Inc.
320 -# This program is free software; you can redistribute it and/or modify
321 -# it under the terms of the GNU General Public License as published by
322 -# the Free Software Foundation; either version 3 of the License, or
323 -# (at your option) any later version.
325 -# This program is distributed in the hope that it will be useful,
326 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
327 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
328 -# GNU General Public License for more details.
330 -# You should have received a copy of the GNU General Public License
331 -# along with this program. If not, see <http://www.gnu.org/licenses/>.
333 -# This program requires dwz in addition to gcc.
337 -# bash$ cd $objdir/gdb/testsuite
339 -# CC_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh gcc" \
340 -# CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh g++"
343 -myname=cc-with-dwz.sh
348 -next_is_output_file=no
353 - if [ "$next_is_output_file" = "yes" ]
356 - next_is_output_file=no
360 - # Poor man's gcc argument parser.
361 - # We don't need to handle all arguments, we just need to know if we're
362 - # doing a link and what the output file is.
363 - # It's not perfect, but it seems to work well enough for the task at hand.
365 - "-c") have_link=no ;;
366 - "-E") have_link=no ;;
367 - "-S") have_link=no ;;
368 - "-o") next_is_output_file=yes ;;
372 -if [ "$next_is_output_file" = "yes" ]
374 - echo "$myname: Unable to find output file" >&2
378 -if [ "$have_link" = "no" ]
386 -[ $rc != 0 ] && exit $rc
387 -if [ ! -f "$output_file" ]
389 - echo "$myname: Internal error: $output_file missing." >&2
393 -$DWZ "$output_file" > /dev/null 2>&1
396 diff --git a/gdb/cc-with-index.sh b/gdb/cc-with-index.sh
397 deleted file mode 100644
398 index 644ba34..0000000
399 --- a/gdb/cc-with-index.sh
403 -# Wrapper around gcc to add the .gdb_index section when running the testsuite.
405 -# Copyright (C) 2010-2012 Free Software Foundation, Inc.
406 -# This program is free software; you can redistribute it and/or modify
407 -# it under the terms of the GNU General Public License as published by
408 -# the Free Software Foundation; either version 3 of the License, or
409 -# (at your option) any later version.
411 -# This program is distributed in the hope that it will be useful,
412 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
413 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
414 -# GNU General Public License for more details.
416 -# You should have received a copy of the GNU General Public License
417 -# along with this program. If not, see <http://www.gnu.org/licenses/>.
419 -# This program requires gdb and objcopy in addition to gcc.
420 -# The default values are gdb from the build tree and objcopy from $PATH.
421 -# They may be overridden by setting environment variables GDB and OBJCOPY
423 -# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
427 -# bash$ cd $objdir/gdb/testsuite
429 -# CC_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh gcc" \
430 -# CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh g++"
432 -# For documentation on index files: info -f gdb.info -n "Index Files"
434 -myname=cc-with-index.sh
444 - elif [ -f ../../gdb ]
448 - echo "$myname: unable to find usable gdb" >&2
453 -OBJCOPY=${OBJCOPY:-objcopy}
456 -next_is_output_file=no
461 - if [ "$next_is_output_file" = "yes" ]
464 - next_is_output_file=no
468 - # Poor man's gcc argument parser.
469 - # We don't need to handle all arguments, we just need to know if we're
470 - # doing a link and what the output file is.
471 - # It's not perfect, but it seems to work well enough for the task at hand.
473 - "-c") have_link=no ;;
474 - "-E") have_link=no ;;
475 - "-S") have_link=no ;;
476 - "-o") next_is_output_file=yes ;;
480 -if [ "$next_is_output_file" = "yes" ]
482 - echo "$myname: Unable to find output file" >&2
486 -if [ "$have_link" = "no" ]
492 -index_file="${output_file}.gdb-index"
493 -if [ -f "$index_file" ]
495 - echo "$myname: Index file $index_file exists, won't clobber." >&2
499 -output_dir="${output_file%/*}"
500 -[ "$output_dir" = "$output_file" ] && output_dir="."
504 -[ $rc != 0 ] && exit $rc
505 -if [ ! -f "$output_file" ]
507 - echo "$myname: Internal error: $output_file missing." >&2
511 -$GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
513 -[ $rc != 0 ] && exit $rc
515 -# GDB might not always create an index. Cope.
516 -if [ -f "$index_file" ]
518 - $OBJCOPY --add-section .gdb_index="$index_file" \
519 - --set-section-flags .gdb_index=readonly \
520 - "$output_file" "$output_file"
528 diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
529 index 4a8b5d1..7341f00 100644
530 --- a/gdb/cli/cli-dump.c
531 +++ b/gdb/cli/cli-dump.c
533 #include "readline/readline.h"
535 #include "cli/cli-utils.h"
536 +#include "gdb_bfd.h"
538 #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
540 @@ -111,12 +112,12 @@ bfd_openr_with_cleanup (const char *filename, const char *target)
544 - ibfd = bfd_openr (filename, target);
545 + ibfd = gdb_bfd_openr (filename, target);
547 error (_("Failed to open %s: %s."), filename,
548 bfd_errmsg (bfd_get_error ()));
550 - make_cleanup_bfd_close (ibfd);
551 + make_cleanup_bfd_unref (ibfd);
552 if (!bfd_check_format (ibfd, bfd_object))
553 error (_("'%s' is not a recognized file format."), filename);
555 @@ -131,11 +132,11 @@ bfd_openw_with_cleanup (const char *filename, const char *target,
557 if (*mode == 'w') /* Write: create new file */
559 - obfd = bfd_openw (filename, target);
560 + obfd = gdb_bfd_openw (filename, target);
562 error (_("Failed to open %s: %s."), filename,
563 bfd_errmsg (bfd_get_error ()));
564 - make_cleanup_bfd_close (obfd);
565 + make_cleanup_bfd_unref (obfd);
566 if (!bfd_set_format (obfd, bfd_object))
567 error (_("bfd_openw_with_cleanup: %s."), bfd_errmsg (bfd_get_error ()));
569 diff --git a/gdb/coffread.c b/gdb/coffread.c
570 index b0a8b82..0c7e6d9 100644
573 @@ -653,13 +653,14 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
576 debugfile = find_separate_debug_file_by_debuglink (objfile);
577 + make_cleanup (xfree, debugfile);
581 bfd *abfd = symfile_bfd_open (debugfile);
583 + make_cleanup_bfd_unref (abfd);
584 symbol_file_add_separate (abfd, symfile_flags, objfile);
589 diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
591 index 0000000..7d7932c
593 +++ b/gdb/contrib/cc-with-tweaks.sh
596 +# Wrapper around gcc to tweak the output in various ways when running
599 +# Copyright (C) 2010-2012 Free Software Foundation, Inc.
600 +# This program is free software; you can redistribute it and/or modify
601 +# it under the terms of the GNU General Public License as published by
602 +# the Free Software Foundation; either version 3 of the License, or
603 +# (at your option) any later version.
605 +# This program is distributed in the hope that it will be useful,
606 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
607 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
608 +# GNU General Public License for more details.
610 +# You should have received a copy of the GNU General Public License
611 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
613 +# This program requires gdb and objcopy in addition to gcc.
614 +# The default values are gdb from the build tree and objcopy from $PATH.
615 +# They may be overridden by setting environment variables GDB and OBJCOPY
617 +# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
621 +# bash$ cd $objdir/gdb/testsuite
623 +# CC_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
624 +# CXX_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
626 +# For documentation on index files: info -f gdb.info -n "Index Files"
627 +# For information about 'dwz', see the announcement:
628 +# http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
629 +# (More documentation is to come.)
631 +# ARGS determine what is done. They can be:
632 +# -z compress using dwz
633 +# -m compress using dwz -m
635 +# If nothing is given, no changes are made
637 +myname=cc-with-tweaks.sh
647 + elif [ -f ../../gdb ]
651 + echo "$myname: unable to find usable gdb" >&2
656 +OBJCOPY=${OBJCOPY:-objcopy}
661 +next_is_output_file=no
668 +while [ $# -gt 0 ]; do
670 + -z) want_dwz=true ;;
671 + -i) want_index=true ;;
672 + -m) want_multi=true ;;
680 + if [ "$next_is_output_file" = "yes" ]
683 + next_is_output_file=no
687 + # Poor man's gcc argument parser.
688 + # We don't need to handle all arguments, we just need to know if we're
689 + # doing a link and what the output file is.
690 + # It's not perfect, but it seems to work well enough for the task at hand.
692 + "-c") have_link=no ;;
693 + "-E") have_link=no ;;
694 + "-S") have_link=no ;;
695 + "-o") next_is_output_file=yes ;;
699 +if [ "$next_is_output_file" = "yes" ]
701 + echo "$myname: Unable to find output file" >&2
705 +if [ "$have_link" = "no" ]
711 +index_file="${output_file}.gdb-index"
712 +if [ "$want_index" = true ] && [ -f "$index_file" ]
714 + echo "$myname: Index file $index_file exists, won't clobber." >&2
718 +output_dir="${output_file%/*}"
719 +[ "$output_dir" = "$output_file" ] && output_dir="."
723 +[ $rc != 0 ] && exit $rc
724 +if [ ! -f "$output_file" ]
726 + echo "$myname: Internal error: $output_file missing." >&2
730 +if [ "$want_index" = true ]; then
731 + $GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
733 + [ $rc != 0 ] && exit $rc
735 + # GDB might not always create an index. Cope.
736 + if [ -f "$index_file" ]
738 + $OBJCOPY --add-section .gdb_index="$index_file" \
739 + --set-section-flags .gdb_index=readonly \
740 + "$output_file" "$output_file"
745 + [ $rc != 0 ] && exit $rc
748 +if [ "$want_dwz" = true ]; then
749 + $DWZ "$output_file" > /dev/null 2>&1
750 +elif [ "$want_multi" = true ]; then
751 + cp $output_file ${output_file}.alt
752 + $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
757 diff --git a/gdb/corelow.c b/gdb/corelow.c
758 index dd62560..340b149 100644
762 #include "filenames.h"
763 #include "progspace.h"
764 #include "objfiles.h"
765 +#include "gdb_bfd.h"
768 #define O_LARGEFILE 0
769 @@ -215,9 +216,7 @@ core_close (int quitting)
773 - name = bfd_get_filename (core_bfd);
774 - gdb_bfd_close_or_warn (core_bfd);
776 + gdb_bfd_unref (core_bfd);
780 @@ -319,9 +318,9 @@ core_open (char *filename, int from_tty)
781 if (scratch_chan < 0)
782 perror_with_name (filename);
784 - temp_bfd = bfd_fopen (filename, gnutarget,
785 - write_files ? FOPEN_RUB : FOPEN_RB,
787 + temp_bfd = gdb_bfd_fopen (filename, gnutarget,
788 + write_files ? FOPEN_RUB : FOPEN_RB,
790 if (temp_bfd == NULL)
791 perror_with_name (filename);
793 @@ -332,7 +331,7 @@ core_open (char *filename, int from_tty)
794 /* FIXME: should be checking for errors from bfd_close (for one
795 thing, on error it does not free all the storage associated
797 - make_cleanup_bfd_close (temp_bfd);
798 + make_cleanup_bfd_unref (temp_bfd);
799 error (_("\"%s\" is not a core dump: %s"),
800 filename, bfd_errmsg (bfd_get_error ()));
802 @@ -340,7 +339,7 @@ core_open (char *filename, int from_tty)
803 /* Looks semi-reasonable. Toss the old core file and work on the
806 - discard_cleanups (old_chain); /* Don't free filename any more */
807 + do_cleanups (old_chain);
808 unpush_target (&core_ops);
810 old_chain = make_cleanup (core_close_cleanup, 0 /*ignore*/);
811 diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
812 index 87c6dd4..1c26652 100644
813 --- a/gdb/data-directory/Makefile.in
814 +++ b/gdb/data-directory/Makefile.in
815 @@ -52,14 +52,25 @@ SYSCALLS_FILES = \
817 PYTHON_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(PYTHON_DIR)
819 + gdb/FrameIterator.py \
820 + gdb/FrameWrapper.py \
826 gdb/command/__init__.py \
827 + gdb/command/backtrace.py \
828 + gdb/command/ignore_errors.py \
829 + gdb/command/pahole.py \
830 gdb/command/pretty_printers.py \
831 gdb/command/prompt.py \
832 - gdb/command/explore.py
833 + gdb/command/explore.py \
834 + gdb/command/require.py \
835 + gdb/command/upto.py \
836 + gdb/function/__init__.py \
837 + gdb/function/caller_is.py \
838 + gdb/function/in_scope.py \
845 diff --git a/gdb/defs.h b/gdb/defs.h
846 index 1c6fa79..ec08348 100644
849 @@ -315,7 +315,7 @@ extern struct cleanup *make_cleanup_close (int fd);
851 extern struct cleanup *make_cleanup_fclose (FILE *file);
853 -extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
854 +extern struct cleanup *make_cleanup_bfd_unref (bfd *abfd);
857 extern struct cleanup *make_cleanup_obstack_free (struct obstack *obstack);
858 @@ -353,6 +353,8 @@ extern struct cleanup *make_cleanup_restore_page_info (void);
859 extern struct cleanup *
860 set_batch_flag_and_make_cleanup_restore_page_info (void);
862 +extern struct cleanup *make_cleanup_restore_selected_frame (void);
864 extern char *gdb_realpath (const char *);
865 extern char *xfullpath (const char *);
867 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
868 index 68ea817..5945bac 100644
869 --- a/gdb/doc/gdb.texinfo
870 +++ b/gdb/doc/gdb.texinfo
871 @@ -1200,6 +1200,16 @@ for remote debugging.
872 Run using @var{device} for your program's standard input and output.
873 @c FIXME: kingdon thinks there is more to -tty. Investigate.
878 +@cindex @code{--python}
879 +Change interpretation of command line so that the argument immediately
880 +following this switch is taken to be the name of a Python script file.
881 +This option stops option processing; subsequent options are passed to
882 +Python as @code{sys.argv}. This option is only available if Python
883 +scripting support was enabled when @value{GDBN} was configured.
885 @c resolve the situation of these eventually
888 @@ -22563,8 +22573,6 @@ containing @code{end}. For example:
891 (@value{GDBP}) python
893 -End with a line saying just "end".
897 @@ -22578,6 +22586,14 @@ controlled using @code{set python print-stack}: if @code{full}, then
898 full Python stack printing is enabled; if @code{none}, then Python stack
899 and message printing is disabled; if @code{message}, the default, only
900 the message component of the error is printed.
902 +@kindex maint set python auto-load
903 +@item maint set python auto-load
904 +By default, @value{GDBN} will attempt to automatically load Python
905 +code when an object file is opened. This can be controlled using
906 +@code{maint set python auto-load}: if @code{on}, the default, then
907 +Python auto-loading is enabled; if @code{off}, then Python
908 +auto-loading is disabled.
911 It is also possible to execute a Python script from the @value{GDBN}
912 @@ -22599,6 +22615,14 @@ and thus is always available.
914 @cindex programming in python
916 +You can get quick online help for @value{GDBN}'s Python API by issuing
917 +the command @w{@kbd{python help (gdb)}}.
919 +Functions and methods which have two or more optional arguments allow
920 +them to be specified using keyword syntax. This allows passing some
921 +optional arguments while skipping others. Example:
922 +@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
924 @cindex python stdout
925 @cindex python pagination
926 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
927 @@ -34536,6 +34560,11 @@ Shared library events.
931 +@kindex maint info bfds
932 +@item maint info bfds
933 +This prints information about each @code{bfd} object that is known to
934 +@value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
936 @kindex set displaced-stepping
937 @kindex show displaced-stepping
938 @cindex displaced stepping support
939 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
940 index 5e00f1f..c5c432b 100644
941 --- a/gdb/doc/gdbint.texinfo
942 +++ b/gdb/doc/gdbint.texinfo
943 @@ -2102,6 +2102,18 @@ time, and so we attempt to handle symbols incrementally. For instance,
944 we create @dfn{partial symbol tables} consisting of only selected
945 symbols, and only expand them to full symbol tables when necessary.
949 +* Partial Symbol Tables::
951 +* Object File Formats::
952 +* Debugging File Formats::
953 +* Adding a New Symbol Reader to GDB::
954 +* Memory Management for Symbol Files::
955 +* Memory Management for Types::
958 +@node Symbol Reading
959 @section Symbol Reading
961 @cindex symbol reading
962 @@ -2194,6 +2206,7 @@ symtab. Upon return, @code{pst->readin} should have been set to 1, and
963 zero if there were no symbols in that part of the symbol file.
966 +@node Partial Symbol Tables
967 @section Partial Symbol Tables
969 @value{GDBN} has three types of symbol tables:
970 @@ -2295,6 +2308,7 @@ and partial symbol tables behind a set of function pointers known as
971 the @dfn{quick symbol functions}. These are documented in
977 @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
978 @@ -2317,6 +2331,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
979 other members of the type struct, such as whether the type is signed
980 or unsigned, and how many bits it uses.
982 +@anchor{Builtin Types}
983 @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
985 These are instances of type structs that roughly correspond to
986 @@ -2331,6 +2346,7 @@ only one instance exists, while @file{c-lang.c} builds as many
987 @code{TYPE_CODE_INT} types as needed, with each one associated with
988 some particular objfile.
990 +@node Object File Formats
991 @section Object File Formats
992 @cindex object file formats
994 @@ -2416,6 +2432,7 @@ SOM, which is a cross-language ABI).
996 The SOM reader is in @file{somread.c}.
998 +@node Debugging File Formats
999 @section Debugging File Formats
1001 This section describes characteristics of debugging information that
1002 @@ -2487,6 +2504,7 @@ DWARF 3 is an improved version of DWARF 2.
1003 @cindex SOM debugging info
1004 Like COFF, the SOM definition includes debugging information.
1006 +@node Adding a New Symbol Reader to GDB
1007 @section Adding a New Symbol Reader to @value{GDBN}
1009 @cindex adding debugging info reader
1010 @@ -2509,6 +2527,7 @@ will only ever be implemented by one object file format may be called
1011 directly. This interface should be described in a file
1012 @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
1014 +@node Memory Management for Symbol Files
1015 @section Memory Management for Symbol Files
1017 Most memory associated with a loaded symbol file is stored on
1018 @@ -2520,10 +2539,45 @@ released when the objfile is unloaded or reloaded. Therefore one
1019 objfile must not reference symbol or type data from another objfile;
1020 they could be unloaded at different times.
1022 -User convenience variables, et cetera, have associated types. Normally
1023 -these types live in the associated objfile. However, when the objfile
1024 -is unloaded, those types are deep copied to global memory, so that
1025 -the values of the user variables and history items are not lost.
1026 +@node Memory Management for Types
1027 +@section Memory Management for Types
1028 +@cindex memory management for types
1030 +@findex TYPE_OBJFILE
1031 +@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
1032 +Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
1033 +obstack) and in such case the type remains valid till the objfile is unloaded
1034 +or reloaded. For such types with an associated objfile no reference counting
1037 +User convenience variables, et cetera, have associated types. Normally these
1038 +types live in the associated objfile. However, when the objfile is unloaded,
1039 +those types are deep copied to global memory, so that the values of the user
1040 +variables and history items are not lost. During the copy they will get their
1041 +@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
1044 +Types with null @code{TYPE_OBJFILE} can be either permanent types
1045 +(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
1046 +first idle @value{GDBN} moment if the last object referencing them is removed.
1047 +Permanent types are allocated by the function @code{alloc_type} (and its
1048 +derivations like @code{init_type}) specifying objfile as @code{NULL}. The
1049 +reclaimable types are created the same way but moreover they need to have
1050 +@code{type_init_group} called to start their tracking as being possibly
1053 +@findex free_all_types
1054 +When @value{GDBN} gets idle it always calls the @code{free_all_types} function
1055 +which deallocates any unused types. All types currently not owned by an
1056 +objfile must be marked as used on each @code{free_all_types} call as they would
1057 +get deallocated as unused otherwise.
1059 +@code{free_all_types} automatically checks for any cross-type references such
1060 +as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
1061 +prevents early deallocation for any such existing references. Reclaimable
1062 +types may reference any other reclaimable types or even permanent types. But
1063 +permanent types must not reference reclaimable types (nor an objfile associated
1067 @node Language Support
1068 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
1069 index 6827ed8..c63b901 100644
1070 --- a/gdb/doc/observer.texi
1071 +++ b/gdb/doc/observer.texi
1072 @@ -230,6 +230,11 @@ the current top-level prompt.
1073 Variable gdb_datadir has been set. The value may not necessarily change.
1076 +@c @deftypefun void mark_used (void)
1077 +@c Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
1078 +@c collector pass. Currently only @code{type_mark_used} marker is supported.
1081 @deftypefun void test_notification (int @var{somearg})
1082 This observer is used for internal testing. Do not use.
1083 See testsuite/gdb.gdb/observer.exp.
1084 diff --git a/gdb/dsrec.c b/gdb/dsrec.c
1085 index d2c99b2..f39d0ed 100644
1090 #include "gdb_assert.h"
1091 #include "gdb_string.h"
1092 +#include "gdb_bfd.h"
1094 extern void report_transfer_performance (unsigned long, time_t, time_t);
1096 @@ -56,19 +57,22 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
1098 time_t start_time, end_time;
1099 unsigned long data_count = 0;
1100 + struct cleanup *cleanup;
1102 srec = (char *) alloca (maxrecsize + 1);
1104 - abfd = bfd_openr (file, 0);
1105 + abfd = gdb_bfd_openr (file, 0);
1108 printf_filtered (_("Unable to open file %s\n"), file);
1112 + cleanup = make_cleanup_bfd_unref (abfd);
1113 if (bfd_check_format (abfd, bfd_object) == 0)
1115 printf_filtered (_("File is not an object file\n"));
1116 + do_cleanups (cleanup);
1120 @@ -170,6 +174,7 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
1121 serial_flush_input (desc);
1123 report_transfer_performance (data_count, start_time, end_time);
1124 + do_cleanups (cleanup);
1128 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
1129 index 214b371..d9b3751 100644
1130 --- a/gdb/dwarf2expr.c
1131 +++ b/gdb/dwarf2expr.c
1132 @@ -1480,6 +1480,14 @@ execute_stack_op (struct dwarf_expr_context *ctx,
1136 + case DW_OP_push_object_address:
1137 + if (ctx->funcs->get_object_address == NULL)
1138 + error (_("DWARF-2 expression error: DW_OP_push_object_address must "
1139 + "have a value to push."));
1140 + result = (ctx->funcs->get_object_address) (ctx->baton);
1141 + result_val = value_from_ulongest (address_type, result);
1145 error (_("Unhandled dwarf expression opcode 0x%x"), op);
1147 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
1148 index 19efbfd..0e0e498 100644
1149 --- a/gdb/dwarf2expr.h
1150 +++ b/gdb/dwarf2expr.h
1151 @@ -78,12 +78,8 @@ struct dwarf_expr_context_funcs
1152 This can throw an exception if the index is out of range. */
1153 CORE_ADDR (*get_addr_index) (void *baton, unsigned int index);
1156 - /* Not yet implemented. */
1158 /* Return the `object address' for DW_OP_push_object_address. */
1159 CORE_ADDR (*get_object_address) (void *baton);
1163 /* The location of a value. */
1164 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
1165 index 38e4814..46a033d 100644
1166 --- a/gdb/dwarf2loc.c
1167 +++ b/gdb/dwarf2loc.c
1168 @@ -293,6 +293,9 @@ struct dwarf_expr_baton
1170 struct frame_info *frame;
1171 struct dwarf2_per_cu_data *per_cu;
1172 + /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
1173 + DW_AT_data_location) for DW_OP_push_object_address. */
1174 + CORE_ADDR object_address;
1177 /* Helper functions for dwarf2_evaluate_loc_desc. */
1178 @@ -352,16 +355,14 @@ static void
1179 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
1180 const gdb_byte **start, size_t *length)
1182 - if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
1184 - else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
1185 + if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
1187 struct dwarf2_loclist_baton *symbaton;
1189 symbaton = SYMBOL_LOCATION_BATON (framefunc);
1190 *start = dwarf2_find_location_expression (symbaton, length, pc);
1193 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
1195 struct dwarf2_locexpr_baton *symbaton;
1197 @@ -374,10 +375,23 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
1201 + else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
1203 + struct dwarf2_locexpr_baton *symbaton;
1205 + symbaton = SYMBOL_LOCATION_BATON (framefunc);
1206 + gdb_assert (symbaton == NULL);
1210 + internal_error (__FILE__, __LINE__,
1211 + _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
1212 + SYMBOL_COMPUTED_OPS (framefunc),
1213 + SYMBOL_PRINT_NAME (framefunc));
1216 error (_("Could not find the frame base for \"%s\"."),
1217 - SYMBOL_NATURAL_NAME (framefunc));
1218 + SYMBOL_PRINT_NAME (framefunc));
1221 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
1222 @@ -445,6 +459,85 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset)
1223 ctx->funcs->get_frame_pc, ctx->baton);
1227 +dwarf_expr_object_address (void *baton)
1229 + struct dwarf_expr_baton *debaton = baton;
1231 + /* The message is suppressed in DWARF_BLOCK_EXEC. */
1232 + if (debaton->object_address == 0)
1233 + error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
1235 + return debaton->object_address;
1238 +/* Address of the variable we are currently referring to. It is set from
1239 + DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
1240 + DW_OP_push_object_address. */
1242 +static CORE_ADDR object_address;
1244 +/* Callers use object_address_set while their callers use the result set so we
1245 + cannot run the cleanup at the local block of our direct caller. Still we
1246 + should reset OBJECT_ADDRESS at least for the next GDB command. */
1249 +object_address_cleanup (void *prev_save_voidp)
1251 + CORE_ADDR *prev_save = prev_save_voidp;
1253 + object_address = *prev_save;
1254 + xfree (prev_save);
1257 +/* Set the base address - DW_AT_location - of a variable. It is being later
1258 + used to derive other object addresses by DW_OP_push_object_address.
1260 + It would be useful to sanity check ADDRESS - such as for some objects with
1261 + unset value_raw_address - but some valid addresses may be zero (such as first
1262 + objects in relocatable .o files). */
1265 +object_address_set (CORE_ADDR address)
1267 + CORE_ADDR *prev_save;
1269 + prev_save = xmalloc (sizeof *prev_save);
1270 + *prev_save = object_address;
1271 + make_cleanup (object_address_cleanup, prev_save);
1273 + object_address = address;
1276 +/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one
1277 + CORE_ADDR result stored to *ADDRP on the DWARF stack stack. If the result
1278 + could not be found return zero and keep *ADDRP unchanged. */
1281 +dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
1282 + struct type *type, CORE_ADDR *addrp)
1284 + struct frame_info *frame = get_selected_frame (NULL);
1285 + const gdb_byte *data;
1287 + struct value *val;
1292 + data = dwarf2_find_location_expression (dllbaton, &size,
1293 + get_frame_address_in_block (frame));
1297 + val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu);
1298 + if (value_optimized_out (val))
1301 + *addrp = value_as_address (val);
1305 /* Callback function for dwarf2_evaluate_loc_desc. */
1307 static struct type *
1308 @@ -1139,10 +1232,12 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
1310 saved_ctx.gdbarch = ctx->gdbarch;
1311 saved_ctx.addr_size = ctx->addr_size;
1312 + saved_ctx.ref_addr_size = ctx->ref_addr_size;
1313 saved_ctx.offset = ctx->offset;
1314 saved_ctx.baton = ctx->baton;
1315 ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (baton_local.per_cu));
1316 ctx->addr_size = dwarf2_per_cu_addr_size (baton_local.per_cu);
1317 + ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (baton_local.per_cu);
1318 ctx->offset = dwarf2_per_cu_text_offset (baton_local.per_cu);
1319 ctx->baton = &baton_local;
1321 @@ -1150,10 +1245,95 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
1323 ctx->gdbarch = saved_ctx.gdbarch;
1324 ctx->addr_size = saved_ctx.addr_size;
1325 + ctx->ref_addr_size = saved_ctx.ref_addr_size;
1326 ctx->offset = saved_ctx.offset;
1327 ctx->baton = saved_ctx.baton;
1330 +static CORE_ADDR dwarf_expr_get_addr_index (void *baton, unsigned int index);
1332 +/* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
1334 +static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
1336 + dwarf_expr_read_reg,
1337 + dwarf_expr_read_mem,
1338 + dwarf_expr_frame_base,
1339 + dwarf_expr_frame_cfa,
1340 + dwarf_expr_frame_pc,
1341 + dwarf_expr_tls_address,
1342 + dwarf_expr_dwarf_call,
1343 + dwarf_expr_get_base_type,
1344 + dwarf_expr_push_dwarf_reg_entry_value,
1345 + dwarf_expr_get_addr_index,
1346 + dwarf_expr_object_address
1349 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
1350 + by dwarf_expr_fetch (RETVAL, 0). FRAME parameter can be NULL to call
1351 + get_selected_frame to find it. Returned dwarf_expr_context freeing is
1352 + pushed on the cleanup chain. */
1355 +dwarf_expr_prep_ctx (struct dwarf_expr_context *ctx, struct frame_info *frame,
1356 + const gdb_byte *data, size_t size,
1357 + struct dwarf2_per_cu_data *per_cu)
1359 + struct dwarf_expr_baton baton;
1360 + struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1361 + volatile struct gdb_exception ex;
1363 + baton.frame = frame;
1364 + baton.per_cu = per_cu;
1365 + baton.object_address = object_address;
1367 + ctx->gdbarch = get_objfile_arch (objfile);
1368 + ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1369 + ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
1370 + ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1371 + ctx->baton = &baton;
1372 + ctx->funcs = &dwarf_expr_ctx_funcs;
1374 + dwarf_expr_eval (ctx, data, size);
1377 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
1378 + CORE_ADDR result on the DWARF stack stack. */
1381 +dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
1383 + struct dwarf_expr_context *ctx;
1385 + struct cleanup *back_to;
1387 + ctx = new_dwarf_expr_context ();
1388 + back_to = make_cleanup_free_dwarf_expr_context (ctx);
1390 + dwarf_expr_prep_ctx (ctx, get_selected_frame (NULL), dlbaton->data,
1391 + dlbaton->size, dlbaton->per_cu);
1393 + if (ctx->num_pieces > 0)
1394 + error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
1396 + retval = dwarf_expr_fetch_address (ctx, 0);
1398 + if (ctx->location == DWARF_VALUE_REGISTER)
1400 + /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
1402 + int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
1403 + struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
1404 + struct frame_info *frame = get_selected_frame (NULL);
1406 + retval = address_from_register (type, gdb_regnum, frame);
1409 + do_cleanups (back_to);
1414 /* Callback function for dwarf2_evaluate_loc_desc.
1415 Fetch the address indexed by DW_OP_GNU_addr_index. */
1417 @@ -2088,22 +2268,6 @@ invalid_synthetic_pointer (void)
1418 "referenced via synthetic pointer"));
1421 -/* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
1423 -static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
1425 - dwarf_expr_read_reg,
1426 - dwarf_expr_read_mem,
1427 - dwarf_expr_frame_base,
1428 - dwarf_expr_frame_cfa,
1429 - dwarf_expr_frame_pc,
1430 - dwarf_expr_tls_address,
1431 - dwarf_expr_dwarf_call,
1432 - dwarf_expr_get_base_type,
1433 - dwarf_expr_push_dwarf_reg_entry_value,
1434 - dwarf_expr_get_addr_index
1437 /* Evaluate a location description, starting at DATA and with length
1438 SIZE, to find the current location of variable of TYPE in the
1439 context of FRAME. BYTE_OFFSET is applied after the contents are
1440 @@ -2116,7 +2280,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
1441 LONGEST byte_offset)
1443 struct value *retval;
1444 - struct dwarf_expr_baton baton;
1445 struct dwarf_expr_context *ctx;
1446 struct cleanup *old_chain, *value_chain;
1447 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1448 @@ -2128,29 +2291,18 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
1450 return allocate_optimized_out_value (type);
1452 - baton.frame = frame;
1453 - baton.per_cu = per_cu;
1455 ctx = new_dwarf_expr_context ();
1456 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1457 value_chain = make_cleanup_value_free_to_mark (value_mark ());
1459 - ctx->gdbarch = get_objfile_arch (objfile);
1460 - ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1461 - ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
1462 - ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1463 - ctx->baton = &baton;
1464 - ctx->funcs = &dwarf_expr_ctx_funcs;
1466 TRY_CATCH (ex, RETURN_MASK_ERROR)
1468 - dwarf_expr_eval (ctx, data, size);
1469 + dwarf_expr_prep_ctx (ctx, frame, data, size, per_cu);
1473 if (ex.error == NOT_AVAILABLE_ERROR)
1475 - do_cleanups (old_chain);
1476 retval = allocate_value (type);
1477 mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type));
1479 @@ -2214,6 +2366,16 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
1480 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
1482 do_cleanups (value_chain);
1484 + /* Frame may be needed for check_typedef of TYPE_DYNAMIC. */
1485 + make_cleanup_restore_selected_frame ();
1486 + select_frame (frame);
1488 + /* object_address_set called here is required in ALLOCATE_VALUE's
1489 + CHECK_TYPEDEF for the object's possible
1490 + DW_OP_push_object_address. */
1491 + object_address_set (address);
1493 retval = allocate_value_lazy (type);
1494 VALUE_LVAL (retval) = lval_memory;
1495 if (in_stack_memory)
1496 @@ -4130,8 +4292,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
1500 -/* The set of location functions used with the DWARF-2 expression
1501 - evaluator and location lists. */
1502 +/* The set of location functions used with the DWARF-2 location lists. */
1503 const struct symbol_computed_ops dwarf2_loclist_funcs = {
1504 loclist_read_variable,
1505 loclist_read_variable_at_entry,
1506 @@ -4140,6 +4301,48 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = {
1507 loclist_tracepoint_var_ref
1510 +static struct value *
1511 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
1513 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
1515 + gdb_assert (dlbaton == NULL);
1516 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
1520 +missing_read_needs_frame (struct symbol *symbol)
1526 +missing_describe_location (struct symbol *symbol, CORE_ADDR addr,
1527 + struct ui_file *stream)
1529 + fprintf_filtered (stream, _("a variable we are unable to resolve"));
1533 +missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
1534 + struct agent_expr *ax, struct axs_value *value)
1536 + struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
1538 + gdb_assert (dlbaton == NULL);
1539 + error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
1542 +/* The set of location functions used with the DWARF-2 evaluator when we are
1543 + unable to resolve the symbols. */
1544 +const struct symbol_computed_ops dwarf2_missing_funcs = {
1545 + missing_read_variable,
1546 + missing_read_variable, /* read_variable_at_entry */
1547 + missing_read_needs_frame,
1548 + missing_describe_location,
1549 + missing_tracepoint_var_ref
1552 /* Provide a prototype to silence -Wmissing-prototypes. */
1553 extern initialize_file_ftype _initialize_dwarf2loc;
1555 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
1556 index e9d06a3..bfa6776 100644
1557 --- a/gdb/dwarf2loc.h
1558 +++ b/gdb/dwarf2loc.h
1559 @@ -127,6 +127,15 @@ struct dwarf2_loclist_baton
1561 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
1562 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
1563 +extern const struct symbol_computed_ops dwarf2_missing_funcs;
1565 +extern void object_address_set (CORE_ADDR address);
1567 +extern CORE_ADDR dwarf_locexpr_baton_eval
1568 + (struct dwarf2_locexpr_baton *dlbaton);
1570 +extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
1571 + struct type *type, CORE_ADDR *addrp);
1573 /* Compile a DWARF location expression to an agent expression.
1575 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
1576 index deee5a2..b2f052b 100644
1577 --- a/gdb/dwarf2read.c
1578 +++ b/gdb/dwarf2read.c
1580 #include "gdbcore.h" /* for gnutarget */
1581 #include "gdb/gdb-index.h"
1583 +#include "gdb_bfd.h"
1586 #include "gdb_string.h"
1587 #include "gdb_assert.h"
1588 #include <sys/types.h>
1593 -#include <sys/mman.h>
1595 -#define MAP_FAILED ((void *) -1)
1599 typedef struct symbol *symbolp;
1600 DEF_VEC_P (symbolp);
1601 @@ -95,8 +87,6 @@ static int check_physname = 0;
1602 /* When non-zero, do not reject deprecated .gdb_index sections. */
1603 static int use_deprecated_index_sections = 0;
1605 -static int pagesize;
1607 /* When set, the file that we're processing is known to have debugging
1608 info for C++ namespaces. GCC 3.3.x did not produce this information,
1609 but later versions do. */
1610 @@ -110,10 +100,6 @@ struct dwarf2_section_info
1614 - /* Not NULL if the section was actually mmapped. */
1616 - /* Page aligned size of mmapped area. */
1617 - bfd_size_type map_len;
1618 /* True if we have tried to read this section. */
1621 @@ -247,6 +233,10 @@ struct dwarf2_per_objfile
1622 This is NULL if the table hasn't been allocated yet. */
1625 + /* The shared '.dwz' file, if one exists. This is used when the
1626 + original data was compressed using 'dwz -m'. */
1627 + struct dwz_file *dwz_file;
1629 /* A flag indicating wether this objfile has a section loaded at a
1631 int has_section_at_zero;
1632 @@ -505,15 +495,13 @@ struct dwarf2_cu
1634 struct dwarf2_per_cu_data
1636 - /* The start offset and length of this compilation unit. 2**29-1
1637 - bytes should suffice to store the length of any compilation unit
1638 - - if it doesn't, GDB will fall over anyway.
1639 + /* The start offset and length of this compilation unit.
1640 NOTE: Unlike comp_unit_head.length, this length includes
1641 initial_length_size.
1642 If the DIE refers to a DWO file, this is always of the original die,
1643 not the DWO file. */
1645 - unsigned int length : 29;
1646 + unsigned int length;
1648 /* Flag indicating this compilation unit will be read in before
1649 any of the current compilation units are processed. */
1650 @@ -528,6 +516,9 @@ struct dwarf2_per_cu_data
1651 /* Non-zero if this CU is from .debug_types. */
1652 unsigned int is_debug_types : 1;
1654 + /* Non-zero if this CU is from the .dwz file. */
1655 + unsigned int is_dwz : 1;
1657 /* The section this CU/TU lives in.
1658 If the DIE refers to a DWO file, this is always the original die,
1659 not the DWO file. */
1660 @@ -715,6 +706,22 @@ struct dwo_file
1664 +/* This represents a '.dwz' file. */
1668 + /* A dwz file can only contain a few sections. */
1669 + struct dwarf2_section_info abbrev;
1670 + struct dwarf2_section_info info;
1671 + struct dwarf2_section_info str;
1672 + struct dwarf2_section_info line;
1673 + struct dwarf2_section_info macro;
1674 + struct dwarf2_section_info gdb_index;
1676 + /* The dwz's BFD. */
1680 /* Struct used to pass misc. parameters to read_die_and_children, et
1681 al. which are used for both .debug_info and .debug_types dies.
1682 All parameters here are unchanging for the life of the call. This
1683 @@ -828,6 +835,12 @@ struct partial_die_info
1684 /* Flag set if fixup_partial_die has been called on this die. */
1685 unsigned int fixup_called : 1;
1687 + /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1688 + unsigned int is_dwz : 1;
1690 + /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1691 + unsigned int spec_is_dwz : 1;
1693 /* The name of this DIE. Normally the value of DW_AT_name, but
1694 sometimes a default name for unnamed DIEs. */
1696 @@ -1213,7 +1226,7 @@ static gdb_byte *read_partial_die (const struct die_reader_specs *,
1700 -static struct partial_die_info *find_partial_die (sect_offset,
1701 +static struct partial_die_info *find_partial_die (sect_offset, int,
1702 struct dwarf2_cu *);
1704 static void fixup_partial_die (struct partial_die_info *,
1705 @@ -1258,6 +1271,8 @@ static char *read_indirect_string (bfd *, gdb_byte *,
1706 const struct comp_unit_head *,
1709 +static char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST);
1711 static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
1713 static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
1714 @@ -1509,6 +1524,9 @@ static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1715 struct dwarf2_loclist_baton *baton,
1716 struct attribute *attr);
1718 +static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton
1719 + (struct attribute *attr, struct dwarf2_cu *cu);
1721 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1723 struct dwarf2_cu *cu);
1724 @@ -1524,7 +1542,7 @@ static hashval_t partial_die_hash (const void *item);
1725 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1727 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1728 - (sect_offset offset, struct objfile *objfile);
1729 + (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile);
1731 static void init_one_comp_unit (struct dwarf2_cu *cu,
1732 struct dwarf2_per_cu_data *per_cu);
1733 @@ -1541,6 +1559,9 @@ static void age_cached_comp_units (void);
1735 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
1737 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
1738 + struct dwarf2_cu *cu);
1740 static struct type *set_die_type (struct die_info *, struct type *,
1741 struct dwarf2_cu *);
1743 @@ -1569,6 +1590,9 @@ static struct type *get_die_type_at_offset (sect_offset,
1745 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1747 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
1748 + (struct attribute *attr, struct dwarf2_cu *cu);
1750 static void dwarf2_release_queue (void *dummy);
1752 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1753 @@ -1587,6 +1611,12 @@ static void find_file_and_directory (struct die_info *die,
1754 static char *file_full_name (int file, struct line_header *lh,
1755 const char *comp_dir);
1757 +static gdb_byte *read_and_check_comp_unit_head
1758 + (struct comp_unit_head *header,
1759 + struct dwarf2_section_info *section,
1760 + struct dwarf2_section_info *abbrev_section, gdb_byte *info_ptr,
1761 + int is_debug_types_section);
1763 static void init_cutu_and_read_dies
1764 (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table,
1765 int use_existing_cu, int keep,
1766 @@ -1608,8 +1638,6 @@ static struct dwo_unit *lookup_dwo_type_unit
1768 static void free_dwo_file_cleanup (void *);
1770 -static void munmap_section_buffer (struct dwarf2_section_info *);
1772 static void process_cu_includes (void);
1775 @@ -1779,85 +1807,6 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1776 dwarf2_per_objfile->has_section_at_zero = 1;
1779 -/* Decompress a section that was compressed using zlib. Store the
1780 - decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1783 -zlib_decompress_section (struct objfile *objfile, asection *sectp,
1784 - gdb_byte **outbuf, bfd_size_type *outsize)
1786 - bfd *abfd = sectp->owner;
1787 -#ifndef HAVE_ZLIB_H
1788 - error (_("Support for zlib-compressed DWARF data (from '%s') "
1789 - "is disabled in this copy of GDB"),
1790 - bfd_get_filename (abfd));
1792 - bfd_size_type compressed_size = bfd_get_section_size (sectp);
1793 - gdb_byte *compressed_buffer = xmalloc (compressed_size);
1794 - struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1795 - bfd_size_type uncompressed_size;
1796 - gdb_byte *uncompressed_buffer;
1799 - int header_size = 12;
1801 - if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1802 - || bfd_bread (compressed_buffer,
1803 - compressed_size, abfd) != compressed_size)
1804 - error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1805 - bfd_get_filename (abfd));
1807 - /* Read the zlib header. In this case, it should be "ZLIB" followed
1808 - by the uncompressed section size, 8 bytes in big-endian order. */
1809 - if (compressed_size < header_size
1810 - || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1811 - error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1812 - bfd_get_filename (abfd));
1813 - uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1814 - uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1815 - uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1816 - uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1817 - uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1818 - uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1819 - uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1820 - uncompressed_size += compressed_buffer[11];
1822 - /* It is possible the section consists of several compressed
1823 - buffers concatenated together, so we uncompress in a loop. */
1824 - strm.zalloc = NULL;
1825 - strm.zfree = NULL;
1826 - strm.opaque = NULL;
1827 - strm.avail_in = compressed_size - header_size;
1828 - strm.next_in = (Bytef*) compressed_buffer + header_size;
1829 - strm.avail_out = uncompressed_size;
1830 - uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1831 - uncompressed_size);
1832 - rc = inflateInit (&strm);
1833 - while (strm.avail_in > 0)
1836 - error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1837 - bfd_get_filename (abfd), rc);
1838 - strm.next_out = ((Bytef*) uncompressed_buffer
1839 - + (uncompressed_size - strm.avail_out));
1840 - rc = inflate (&strm, Z_FINISH);
1841 - if (rc != Z_STREAM_END)
1842 - error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1843 - bfd_get_filename (abfd), rc);
1844 - rc = inflateReset (&strm);
1846 - rc = inflateEnd (&strm);
1848 - || strm.avail_out != 0)
1849 - error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1850 - bfd_get_filename (abfd), rc);
1852 - do_cleanups (cleanup);
1853 - *outbuf = uncompressed_buffer;
1854 - *outsize = uncompressed_size;
1858 /* A helper function that decides whether a section is empty,
1861 @@ -1884,56 +1833,27 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1864 info->buffer = NULL;
1865 - info->map_addr = NULL;
1868 if (dwarf2_section_empty_p (info))
1871 - /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1872 abfd = sectp->owner;
1874 - /* Check if the file has a 4-byte header indicating compression. */
1875 - if (info->size > sizeof (header)
1876 - && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1877 - && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1879 - /* Upon decompression, update the buffer and its size. */
1880 - if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1882 - zlib_decompress_section (objfile, sectp, &info->buffer,
1889 - if (pagesize == 0)
1890 - pagesize = getpagesize ();
1892 - /* Only try to mmap sections which are large enough: we don't want to
1893 - waste space due to fragmentation. Also, only try mmap for sections
1894 - without relocations. */
1896 - if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1897 + /* If the section has relocations, we must read it ourselves.
1898 + Otherwise we attach it to the BFD. */
1899 + if ((sectp->flags & SEC_RELOC) == 0)
1901 - info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1902 - MAP_PRIVATE, sectp->filepos,
1903 - &info->map_addr, &info->map_len);
1904 + const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size);
1906 - if ((caddr_t)info->buffer != MAP_FAILED)
1908 -#if HAVE_POSIX_MADVISE
1909 - posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1913 + /* We have to cast away const here for historical reasons.
1914 + Fixing dwarf2read to be const-correct would be quite nice. */
1915 + info->buffer = (gdb_byte *) bytes;
1920 - /* If we get here, we are a normal, not-compressed section. */
1921 - info->buffer = buf
1922 - = obstack_alloc (&objfile->objfile_obstack, info->size);
1923 + buf = obstack_alloc (&objfile->objfile_obstack, info->size);
1924 + info->buffer = buf;
1926 /* When debugging .o files, we may need to apply relocations; see
1927 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1928 @@ -2009,6 +1929,111 @@ dwarf2_get_section_info (struct objfile *objfile,
1929 *sizep = info->size;
1932 +/* A helper function to find the sections for a .dwz file. */
1935 +locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
1937 + struct dwz_file *dwz_file = arg;
1939 + /* Note that we only support the standard ELF names, because .dwz
1940 + is ELF-only (at the time of writing). */
1941 + if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
1943 + dwz_file->abbrev.asection = sectp;
1944 + dwz_file->abbrev.size = bfd_get_section_size (sectp);
1946 + else if (section_is_p (sectp->name, &dwarf2_elf_names.info))
1948 + dwz_file->info.asection = sectp;
1949 + dwz_file->info.size = bfd_get_section_size (sectp);
1951 + else if (section_is_p (sectp->name, &dwarf2_elf_names.str))
1953 + dwz_file->str.asection = sectp;
1954 + dwz_file->str.size = bfd_get_section_size (sectp);
1956 + else if (section_is_p (sectp->name, &dwarf2_elf_names.line))
1958 + dwz_file->line.asection = sectp;
1959 + dwz_file->line.size = bfd_get_section_size (sectp);
1961 + else if (section_is_p (sectp->name, &dwarf2_elf_names.macro))
1963 + dwz_file->macro.asection = sectp;
1964 + dwz_file->macro.size = bfd_get_section_size (sectp);
1966 + else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index))
1968 + dwz_file->gdb_index.asection = sectp;
1969 + dwz_file->gdb_index.size = bfd_get_section_size (sectp);
1973 +/* Open the separate '.dwz' debug file, if needed. Error if the file
1974 + cannot be found. */
1976 +static struct dwz_file *
1977 +dwarf2_get_dwz_file (void)
1979 + bfd *abfd, *dwz_bfd;
1980 + asection *section;
1982 + struct cleanup *cleanup;
1983 + const char *filename;
1984 + struct dwz_file *result;
1986 + if (dwarf2_per_objfile->dwz_file != NULL)
1987 + return dwarf2_per_objfile->dwz_file;
1989 + abfd = dwarf2_per_objfile->objfile->obfd;
1990 + section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink");
1991 + if (section == NULL)
1992 + error (_("could not find '.gnu_debugaltlink' section"));
1993 + if (!bfd_malloc_and_get_section (abfd, section, &data))
1994 + error (_("could not read '.gnu_debugaltlink' section: %s"),
1995 + bfd_errmsg (bfd_get_error ()));
1996 + cleanup = make_cleanup (xfree, data);
1999 + if (!IS_ABSOLUTE_PATH (filename))
2001 + char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name);
2004 + make_cleanup (xfree, abs);
2005 + abs = ldirname (abs);
2006 + make_cleanup (xfree, abs);
2008 + rel = concat (abs, SLASH_STRING, filename, (char *) NULL);
2009 + make_cleanup (xfree, rel);
2013 + /* The format is just a NUL-terminated file name, followed by the
2014 + build-id. For now, though, we ignore the build-id. */
2015 + dwz_bfd = gdb_bfd_open (filename, gnutarget, -1);
2016 + if (dwz_bfd == NULL)
2017 + error (_("could not read '%s': %s"), filename,
2018 + bfd_errmsg (bfd_get_error ()));
2020 + if (!bfd_check_format (dwz_bfd, bfd_object))
2022 + gdb_bfd_unref (dwz_bfd);
2023 + error (_("file '%s' was not usable: %s"), filename,
2024 + bfd_errmsg (bfd_get_error ()));
2027 + result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
2029 + result->dwz_bfd = dwz_bfd;
2031 + bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result);
2033 + do_cleanups (cleanup);
2038 /* DWARF quick_symbols_functions support. */
2040 @@ -2279,23 +2304,19 @@ extract_cu_value (const char *bytes, ULONGEST *result)
2044 -/* Read the CU list from the mapped index, and use it to create all
2045 - the CU objects for this objfile. Return 0 if something went wrong,
2046 - 1 if everything went ok. */
2047 +/* A helper for create_cus_from_index that handles a given list of
2051 -create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
2052 - offset_type cu_list_elements)
2053 +create_cus_from_index_list (struct objfile *objfile,
2054 + const gdb_byte *cu_list, offset_type n_elements,
2055 + struct dwarf2_section_info *section,
2061 - dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
2062 - dwarf2_per_objfile->all_comp_units
2063 - = obstack_alloc (&objfile->objfile_obstack,
2064 - dwarf2_per_objfile->n_comp_units
2065 - * sizeof (struct dwarf2_per_cu_data *));
2067 - for (i = 0; i < cu_list_elements; i += 2)
2068 + for (i = 0; i < n_elements; i += 2)
2070 struct dwarf2_per_cu_data *the_cu;
2071 ULONGEST offset, length;
2072 @@ -2310,15 +2331,45 @@ create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
2073 the_cu->offset.sect_off = offset;
2074 the_cu->length = length;
2075 the_cu->objfile = objfile;
2076 - the_cu->info_or_types_section = &dwarf2_per_objfile->info;
2077 + the_cu->info_or_types_section = section;
2078 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2079 struct dwarf2_per_cu_quick_data);
2080 - dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
2081 + the_cu->is_dwz = is_dwz;
2082 + dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu;
2088 +/* Read the CU list from the mapped index, and use it to create all
2089 + the CU objects for this objfile. Return 0 if something went wrong,
2090 + 1 if everything went ok. */
2093 +create_cus_from_index (struct objfile *objfile,
2094 + const gdb_byte *cu_list, offset_type cu_list_elements,
2095 + const gdb_byte *dwz_list, offset_type dwz_elements)
2097 + struct dwz_file *dwz;
2099 + dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2;
2100 + dwarf2_per_objfile->all_comp_units
2101 + = obstack_alloc (&objfile->objfile_obstack,
2102 + dwarf2_per_objfile->n_comp_units
2103 + * sizeof (struct dwarf2_per_cu_data *));
2105 + if (!create_cus_from_index_list (objfile, cu_list, cu_list_elements,
2106 + &dwarf2_per_objfile->info, 0, 0))
2109 + if (dwz_elements == 0)
2112 + dwz = dwarf2_get_dwz_file ();
2113 + return create_cus_from_index_list (objfile, dwz_list, dwz_elements,
2114 + &dwz->info, 1, cu_list_elements / 2);
2117 /* Create the signatured type hash table from the index. */
2120 @@ -2508,33 +2559,44 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2124 -/* Read the index file. If everything went ok, initialize the "quick"
2125 - elements of all the CUs and return 1. Otherwise, return 0. */
2126 +/* A helper function that reads the .gdb_index from SECTION and fills
2127 + in MAP. FILENAME is the name of the file containing the section;
2128 + it is used for error reporting. DEPRECATED_OK is nonzero if it is
2129 + ok to use deprecated sections.
2131 + CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2132 + out parameters that are filled in with information about the CU and
2133 + TU lists in the section.
2135 + Returns 1 if all went well, 0 otherwise. */
2138 -dwarf2_read_index (struct objfile *objfile)
2139 +read_index_from_section (struct objfile *objfile,
2140 + const char *filename,
2141 + int deprecated_ok,
2142 + struct dwarf2_section_info *section,
2143 + struct mapped_index *map,
2144 + const gdb_byte **cu_list,
2145 + offset_type *cu_list_elements,
2146 + const gdb_byte **types_list,
2147 + offset_type *types_list_elements)
2150 - struct mapped_index *map;
2151 + offset_type version;
2152 offset_type *metadata;
2153 - const gdb_byte *cu_list;
2154 - const gdb_byte *types_list = NULL;
2155 - offset_type version, cu_list_elements;
2156 - offset_type types_list_elements = 0;
2159 - if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2160 + if (dwarf2_section_empty_p (section))
2163 /* Older elfutils strip versions could keep the section in the main
2164 executable while splitting it for the separate debug info file. */
2165 - if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2166 - & SEC_HAS_CONTENTS) == 0)
2167 + if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0)
2170 - dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2171 + dwarf2_read_section (objfile, section);
2173 - addr = dwarf2_per_objfile->gdb_index.buffer;
2174 + addr = section->buffer;
2175 /* Version check. */
2176 version = MAYBE_SWAP (*(offset_type *) addr);
2177 /* Versions earlier than 3 emitted every copy of a psymbol. This
2178 @@ -2547,7 +2609,7 @@ dwarf2_read_index (struct objfile *objfile)
2179 if (!warning_printed)
2181 warning (_("Skipping obsolete .gdb_index section in %s."),
2184 warning_printed = 1;
2187 @@ -2560,7 +2622,7 @@ dwarf2_read_index (struct objfile *objfile)
2188 set breakpoints on inlined functions by name, so we ignore these
2189 indices unless the user has done
2190 "set use-deprecated-index-sections on". */
2191 - if (version < 6 && !use_deprecated_index_sections)
2192 + if (version < 6 && !deprecated_ok)
2194 static int warning_printed = 0;
2195 if (!warning_printed)
2196 @@ -2569,7 +2631,7 @@ dwarf2_read_index (struct objfile *objfile)
2197 Skipping deprecated .gdb_index section in %s.\n\
2198 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2199 to use the section anyway."),
2202 warning_printed = 1;
2205 @@ -2579,22 +2641,21 @@ to use the section anyway."),
2209 - map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2210 map->version = version;
2211 - map->total_size = dwarf2_per_objfile->gdb_index.size;
2212 + map->total_size = section->size;
2214 metadata = (offset_type *) (addr + sizeof (offset_type));
2217 - cu_list = addr + MAYBE_SWAP (metadata[i]);
2218 - cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2220 + *cu_list = addr + MAYBE_SWAP (metadata[i]);
2221 + *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2225 - types_list = addr + MAYBE_SWAP (metadata[i]);
2226 - types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2227 - - MAYBE_SWAP (metadata[i]))
2229 + *types_list = addr + MAYBE_SWAP (metadata[i]);
2230 + *types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2231 + - MAYBE_SWAP (metadata[i]))
2235 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2236 @@ -2610,11 +2671,55 @@ to use the section anyway."),
2238 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2244 +/* Read the index file. If everything went ok, initialize the "quick"
2245 + elements of all the CUs and return 1. Otherwise, return 0. */
2248 +dwarf2_read_index (struct objfile *objfile)
2250 + struct mapped_index local_map, *map;
2251 + const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
2252 + offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
2254 + if (!read_index_from_section (objfile, objfile->name,
2255 + use_deprecated_index_sections,
2256 + &dwarf2_per_objfile->gdb_index, &local_map,
2257 + &cu_list, &cu_list_elements,
2258 + &types_list, &types_list_elements))
2261 /* Don't use the index if it's empty. */
2262 - if (map->symbol_table_slots == 0)
2263 + if (local_map.symbol_table_slots == 0)
2266 - if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2267 + /* If there is a .dwz file, read it so we can get its CU list as
2269 + if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
2271 + struct dwz_file *dwz = dwarf2_get_dwz_file ();
2272 + struct mapped_index dwz_map;
2273 + const gdb_byte *dwz_types_ignore;
2274 + offset_type dwz_types_elements_ignore;
2276 + if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd),
2278 + &dwz->gdb_index, &dwz_map,
2279 + &dwz_list, &dwz_list_elements,
2280 + &dwz_types_ignore,
2281 + &dwz_types_elements_ignore))
2283 + warning (_("could not read '.gdb_index' section from %s; skipping"),
2284 + bfd_get_filename (dwz->dwz_bfd));
2289 + if (!create_cus_from_index (objfile, cu_list, cu_list_elements,
2290 + dwz_list, dwz_list_elements))
2293 if (types_list_elements)
2294 @@ -2635,7 +2740,10 @@ to use the section anyway."),
2298 - create_addrmap_from_index (objfile, map);
2299 + create_addrmap_from_index (objfile, &local_map);
2301 + map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index));
2304 dwarf2_per_objfile->index_table = map;
2305 dwarf2_per_objfile->using_index = 1;
2306 @@ -3686,6 +3794,22 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
2310 +/* Helper function that returns the proper abbrev section for
2313 +static struct dwarf2_section_info *
2314 +get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
2316 + struct dwarf2_section_info *abbrev;
2318 + if (this_cu->is_dwz)
2319 + abbrev = &dwarf2_get_dwz_file ()->abbrev;
2321 + abbrev = &dwarf2_per_objfile->abbrev;
2326 /* Subroutine of read_and_check_comp_unit_head and
2327 read_and_check_type_unit_head to simplify them.
2328 Perform various error checking on the header. */
2329 @@ -3704,8 +3828,7 @@ error_check_comp_unit_head (struct comp_unit_head *header,
2332 if (header->abbrev_offset.sect_off
2333 - >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2334 - &dwarf2_per_objfile->abbrev))
2335 + >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
2336 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2337 "(offset 0x%lx + 6) [in module %s]"),
2338 (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off,
2339 @@ -3942,6 +4065,7 @@ create_debug_types_hash_table (struct dwo_file *dwo_file,
2342 gdb_byte *info_ptr, *end_ptr;
2343 + struct dwarf2_section_info *abbrev_section;
2345 dwarf2_read_section (objfile, section);
2346 info_ptr = section->buffer;
2347 @@ -3953,6 +4077,11 @@ create_debug_types_hash_table (struct dwo_file *dwo_file,
2348 not present, in which case section->asection will be NULL. */
2349 abfd = section->asection->owner;
2352 + abbrev_section = &dwo_file->sections.abbrev;
2354 + abbrev_section = &dwarf2_per_objfile->abbrev;
2356 if (types_htab == NULL)
2359 @@ -4192,7 +4321,8 @@ init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
2360 dwarf2_read_section (objfile, section);
2362 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
2363 - abbrev_section = &dwarf2_per_objfile->abbrev;
2365 + abbrev_section = get_abbrev_section_for_cu (this_cu);
2367 if (use_existing_cu && this_cu->cu != NULL)
2369 @@ -4574,7 +4704,7 @@ init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu,
2372 init_cutu_and_read_dies_no_follow (this_cu,
2373 - &dwarf2_per_objfile->abbrev,
2374 + get_abbrev_section_for_cu (this_cu),
2376 die_reader_func, data);
2378 @@ -5202,6 +5332,9 @@ set_partial_user (struct objfile *objfile)
2379 struct partial_symtab *pst = per_cu->v.psymtab;
2385 for (j = 0; j < pst->number_of_dependencies; ++j)
2387 /* Set the 'user' field only if it is not already set. */
2388 @@ -5296,38 +5429,32 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
2389 load_partial_comp_unit_reader, NULL);
2392 -/* Create a list of all compilation units in OBJFILE.
2393 - This is only done for -readnow and building partial symtabs. */
2396 -create_all_comp_units (struct objfile *objfile)
2397 +read_comp_units_from_section (struct objfile *objfile,
2398 + struct dwarf2_section_info *section,
2399 + unsigned int is_dwz,
2401 + int *n_comp_units,
2402 + struct dwarf2_per_cu_data ***all_comp_units)
2406 - struct dwarf2_per_cu_data **all_comp_units;
2408 + bfd *abfd = section->asection->owner;
2410 - dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
2411 - info_ptr = dwarf2_per_objfile->info.buffer;
2412 + dwarf2_read_section (objfile, section);
2416 - all_comp_units = xmalloc (n_allocated
2417 - * sizeof (struct dwarf2_per_cu_data *));
2418 + info_ptr = section->buffer;
2420 - while (info_ptr < dwarf2_per_objfile->info.buffer
2421 - + dwarf2_per_objfile->info.size)
2422 + while (info_ptr < section->buffer + section->size)
2424 unsigned int length, initial_length_size;
2425 struct dwarf2_per_cu_data *this_cu;
2428 - offset.sect_off = info_ptr - dwarf2_per_objfile->info.buffer;
2429 + offset.sect_off = info_ptr - section->buffer;
2431 /* Read just enough information to find out where the next
2432 compilation unit is. */
2433 - length = read_initial_length (objfile->obfd, info_ptr,
2434 - &initial_length_size);
2435 + length = read_initial_length (abfd, info_ptr, &initial_length_size);
2437 /* Save the compilation unit for later lookup. */
2438 this_cu = obstack_alloc (&objfile->objfile_obstack,
2439 @@ -5335,20 +5462,50 @@ create_all_comp_units (struct objfile *objfile)
2440 memset (this_cu, 0, sizeof (*this_cu));
2441 this_cu->offset = offset;
2442 this_cu->length = length + initial_length_size;
2443 + this_cu->is_dwz = is_dwz;
2444 this_cu->objfile = objfile;
2445 - this_cu->info_or_types_section = &dwarf2_per_objfile->info;
2446 + this_cu->info_or_types_section = section;
2448 - if (n_comp_units == n_allocated)
2449 + if (*n_comp_units == *n_allocated)
2452 - all_comp_units = xrealloc (all_comp_units,
2454 - * sizeof (struct dwarf2_per_cu_data *));
2455 + *n_allocated *= 2;
2456 + *all_comp_units = xrealloc (*all_comp_units,
2458 + * sizeof (struct dwarf2_per_cu_data *));
2460 - all_comp_units[n_comp_units++] = this_cu;
2461 + (*all_comp_units)[*n_comp_units] = this_cu;
2464 info_ptr = info_ptr + this_cu->length;
2468 +/* Create a list of all compilation units in OBJFILE.
2469 + This is only done for -readnow and building partial symtabs. */
2472 +create_all_comp_units (struct objfile *objfile)
2476 + struct dwarf2_per_cu_data **all_comp_units;
2480 + all_comp_units = xmalloc (n_allocated
2481 + * sizeof (struct dwarf2_per_cu_data *));
2483 + read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0,
2484 + &n_allocated, &n_comp_units, &all_comp_units);
2486 + if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
2488 + struct dwz_file *dwz = dwarf2_get_dwz_file ();
2490 + read_comp_units_from_section (objfile, &dwz->info, 1,
2491 + &n_allocated, &n_comp_units,
2495 dwarf2_per_objfile->all_comp_units
2496 = obstack_alloc (&objfile->objfile_obstack,
2497 @@ -5441,6 +5598,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
2500 per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset,
2504 /* Go read the partial unit, if needed. */
2505 @@ -5498,7 +5656,8 @@ partial_die_parent_scope (struct partial_die_info *pdi,
2508 while (real_pdi->has_specification)
2509 - real_pdi = find_partial_die (real_pdi->spec_offset, cu);
2510 + real_pdi = find_partial_die (real_pdi->spec_offset,
2511 + real_pdi->spec_is_dwz, cu);
2513 parent = real_pdi->die_parent;
2515 @@ -5998,6 +6157,9 @@ skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
2517 info_ptr += cu->header.offset_size;
2519 + case DW_FORM_GNU_ref_alt:
2520 + info_ptr += cu->header.offset_size;
2523 info_ptr += cu->header.addr_size;
2525 @@ -6027,6 +6189,7 @@ skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
2527 case DW_FORM_sec_offset:
2529 + case DW_FORM_GNU_strp_alt:
2530 info_ptr += cu->header.offset_size;
2532 case DW_FORM_exprloc:
2533 @@ -6694,7 +6857,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
2534 it, by scanning the DIE's below the compilation unit. */
2535 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
2537 - static_block = end_symtab_get_static_block (highpc + baseaddr, objfile, 0);
2539 + = end_symtab_get_static_block (highpc + baseaddr, objfile, 0,
2540 + per_cu->s.imported_symtabs != NULL);
2542 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
2543 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
2544 @@ -6845,9 +7010,11 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
2545 struct dwarf2_per_cu_data *per_cu;
2546 struct symtab *imported_symtab;
2550 offset = dwarf2_get_ref_die_offset (attr);
2551 - per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
2552 + is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
2553 + per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile);
2555 /* Queue the unit, if needed. */
2556 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
2557 @@ -8116,24 +8283,21 @@ try_open_dwo_file (const char *file_name)
2561 - sym_bfd = bfd_fopen (absolute_name, gnutarget, FOPEN_RB, desc);
2562 + sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
2565 xfree (absolute_name);
2568 + xfree (absolute_name);
2569 bfd_set_cacheable (sym_bfd, 1);
2571 if (!bfd_check_format (sym_bfd, bfd_object))
2573 - bfd_close (sym_bfd); /* This also closes desc. */
2574 - xfree (absolute_name);
2575 + gdb_bfd_unref (sym_bfd); /* This also closes desc. */
2579 - /* bfd_usrdata exists for applications and libbfd must not touch it. */
2580 - gdb_assert (bfd_usrdata (sym_bfd) == NULL);
2585 @@ -8325,20 +8489,7 @@ free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
2586 struct dwarf2_section_info *section;
2588 gdb_assert (dwo_file->dwo_bfd != objfile->obfd);
2589 - bfd_close (dwo_file->dwo_bfd);
2591 - munmap_section_buffer (&dwo_file->sections.abbrev);
2592 - munmap_section_buffer (&dwo_file->sections.info);
2593 - munmap_section_buffer (&dwo_file->sections.line);
2594 - munmap_section_buffer (&dwo_file->sections.loc);
2595 - munmap_section_buffer (&dwo_file->sections.str);
2596 - munmap_section_buffer (&dwo_file->sections.str_offsets);
2599 - VEC_iterate (dwarf2_section_info_def, dwo_file->sections.types,
2602 - munmap_section_buffer (section);
2603 + gdb_bfd_unref (dwo_file->dwo_bfd);
2605 VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
2607 @@ -10721,6 +10872,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
2608 new_symbol (die, this_type, cu);
2611 +/* Create a new array dimension referencing its target type TYPE.
2613 + Multidimensional arrays are internally represented as a stack of
2614 + singledimensional arrays being referenced by their TYPE_TARGET_TYPE. */
2616 +static struct type *
2617 +create_single_array_dimension (struct type *type, struct type *range_type,
2618 + struct die_info *die, struct dwarf2_cu *cu)
2620 + type = create_array_type (NULL, type, range_type);
2622 + /* These generic type attributes need to be fetched by
2623 + evaluate_subexp_standard <multi_f77_subscript>'s call of
2624 + value_subscripted_rvalue only for the innermost array type. */
2625 + fetch_die_type_attrs (die, type, cu);
2627 + /* These generic type attributes are checked for allocated/associated
2628 + validity while accessing FIELD_LOC_KIND_DWARF_BLOCK. */
2629 + fetch_die_type_attrs (die, range_type, cu);
2634 /* Extract all information from a DW_TAG_array_type DIE and put it in
2635 the DIE's type field. For now, this only handles one dimensional
2637 @@ -10734,7 +10908,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
2638 struct type *element_type, *range_type, *index_type;
2639 struct type **range_types = NULL;
2640 struct attribute *attr;
2643 struct cleanup *back_to;
2646 @@ -10787,17 +10961,19 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
2647 type = element_type;
2649 if (read_array_order (die, cu) == DW_ORD_col_major)
2654 - type = create_array_type (NULL, type, range_types[i++]);
2658 - while (ndim-- > 0)
2659 - type = create_array_type (NULL, type, range_types[ndim]);
2661 + for (i = 0; i < ndim; i++)
2662 + type = create_single_array_dimension (type, range_types[i], die, cu);
2663 + else /* (read_array_order (die, cu) == DW_ORD_row_major) */
2664 + for (i = ndim - 1; i >= 0; i--)
2665 + type = create_single_array_dimension (type, range_types[i], die, cu);
2667 + /* Data locations should be set only for the outermost dimension as they
2668 + would be confusing for the dereferenced offset on the inner ones. */
2669 + attr = dwarf2_attr (die, DW_AT_data_location, cu);
2670 + if (attr_form_is_block (attr))
2671 + TYPE_DATA_LOCATION_DWARF_BLOCK (type)
2672 + = dwarf2_attr_to_locexpr_baton (attr, cu);
2673 + gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
2675 /* Understand Dwarf2 support for vector types (like they occur on
2676 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
2677 @@ -11281,29 +11457,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
2678 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2679 struct type *type, *range_type, *index_type, *char_type;
2680 struct attribute *attr;
2681 - unsigned int length;
2684 + index_type = objfile_type (objfile)->builtin_int;
2685 + /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type. */
2686 + range_type = alloc_type (objfile);
2687 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
2688 + range_type = create_range_type (range_type, index_type, 0, -1);
2690 + /* C/C++ should probably have the low bound 0 but C/C++ does not use
2691 + DW_TAG_string_type. */
2692 + TYPE_LOW_BOUND (range_type) = 1;
2694 attr = dwarf2_attr (die, DW_AT_string_length, cu);
2696 + if (attr && attr_form_is_block (attr))
2698 - length = DW_UNSND (attr);
2699 + /* Security check for a size overflow. */
2700 + if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
2701 + TYPE_HIGH_BOUND (range_type) = 1;
2702 + /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
2703 + instruction as DW_AT_string_length specifies the length location, not
2707 + struct dwarf2_locexpr_baton *length_baton = NULL;
2708 + struct dwarf_block *blk = DW_BLOCK (attr);
2710 + /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
2711 + DW_OP_deref* in such case. */
2713 + if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
2714 + && blk->data[0] <= DW_OP_reg31)
2715 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
2716 + else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
2718 + ULONGEST ulongest;
2719 + const gdb_byte *end;
2721 + end = safe_read_uleb128 (&blk->data[1], &blk->data[blk->size],
2723 + if (end == &blk->data[blk->size])
2724 + length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
2727 + if (length_baton == NULL)
2729 + struct attribute *size_attr;
2732 + length_baton = obstack_alloc (&cu->comp_unit_obstack,
2733 + sizeof (*length_baton));
2734 + length_baton->per_cu = cu->per_cu;
2735 + length_baton->size = DW_BLOCK (attr)->size + 2;
2736 + data = obstack_alloc (&cu->comp_unit_obstack,
2737 + length_baton->size);
2738 + length_baton->data = data;
2739 + memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
2741 + /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
2742 + specifies the size of an integer to fetch. */
2743 + size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2746 + data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
2747 + data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr);
2748 + if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr))
2749 + complaint (&symfile_complaints,
2750 + _("DW_AT_string_length's DW_AT_byte_size "
2751 + "integer exceeds the byte size storage"));
2755 + data[DW_BLOCK (attr)->size] = DW_OP_deref;
2756 + data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
2760 + TYPE_RANGE_DATA (range_type)->high.kind
2761 + = RANGE_BOUND_KIND_DWARF_BLOCK;
2762 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton;
2763 + TYPE_DYNAMIC (range_type) = 1;
2768 - /* Check for the DW_AT_byte_size attribute. */
2769 + if (attr && attr_form_is_constant (attr))
2771 + /* We currently do not support a constant address where the location
2772 + should be read from - attr_form_is_block is expected instead. See
2773 + DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
2778 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2781 - length = DW_UNSND (attr);
2783 + if (attr && attr_form_is_block (attr))
2785 + TYPE_RANGE_DATA (range_type)->high.kind
2786 + = RANGE_BOUND_KIND_DWARF_BLOCK;
2787 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
2788 + dwarf2_attr_to_locexpr_baton (attr, cu);
2789 + TYPE_DYNAMIC (range_type) = 1;
2791 + else if (attr && attr_form_is_constant (attr))
2792 + TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
2797 + TYPE_HIGH_BOUND (range_type) = 1;
2800 - index_type = objfile_type (objfile)->builtin_int;
2801 - range_type = create_range_type (NULL, index_type, 1, length);
2802 char_type = language_string_char_type (cu->language_defn, gdbarch);
2803 type = create_string_type (NULL, char_type, range_type);
2805 @@ -11607,7 +11868,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
2806 struct type *base_type;
2807 struct type *range_type;
2808 struct attribute *attr;
2809 - LONGEST low, high;
2811 int low_default_is_valid;
2813 LONGEST negative_mask;
2814 @@ -11663,42 +11924,6 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
2815 "- DIE at 0x%x [in module %s]"),
2816 die->offset.sect_off, cu->objfile->name);
2818 - attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
2821 - if (attr_form_is_block (attr) || is_ref_attr (attr))
2823 - /* GCC encodes arrays with unspecified or dynamic length
2824 - with a DW_FORM_block1 attribute or a reference attribute.
2825 - FIXME: GDB does not yet know how to handle dynamic
2826 - arrays properly, treat them as arrays with unspecified
2829 - FIXME: jimb/2003-09-22: GDB does not really know
2830 - how to handle arrays of unspecified length
2831 - either; we just represent them as zero-length
2832 - arrays. Choose an appropriate upper bound given
2833 - the lower bound we've computed above. */
2837 - high = dwarf2_get_attr_constant_value (attr, 1);
2841 - attr = dwarf2_attr (die, DW_AT_count, cu);
2844 - int count = dwarf2_get_attr_constant_value (attr, 1);
2845 - high = low + count - 1;
2849 - /* Unspecified array length. */
2854 /* Dwarf-2 specifications explicitly allows to create subrange types
2855 without specifying a base type.
2856 In that case, the base type must be set to the type of
2857 @@ -11737,24 +11962,163 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
2862 + /* LOW_BOUND and HIGH_BOUND are set for real below. */
2863 + range_type = create_range_type (NULL, base_type, 0, -1);
2864 + TYPE_UNSIGNED (range_type) = 0;
2867 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
2868 - if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
2869 - low |= negative_mask;
2870 - if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
2871 - high |= negative_mask;
2873 - range_type = create_range_type (NULL, base_type, low, high);
2874 + /* Exclude language_ada from any TYPE_DYNAMIC constructs below. GDB Ada
2875 + supports implements the dynamic bounds in a non-DWARF way and the
2876 + existing DWARF dynamic bounds are invalid, leading to memory access
2879 - /* Mark arrays with dynamic length at least as an array of unspecified
2880 - length. GDB could check the boundary but before it gets implemented at
2881 - least allow accessing the array elements. */
2882 - if (attr && attr_form_is_block (attr))
2883 - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
2884 + attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
2885 + if (attr && attr_form_is_block (attr) && cu->language != language_ada)
2887 + TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
2888 + TYPE_RANGE_DATA (range_type)->low.u.dwarf_block =
2889 + dwarf2_attr_to_locexpr_baton (attr, cu);
2890 + TYPE_DYNAMIC (range_type) = 1;
2891 + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */
2894 + else if (attr && is_ref_attr (attr) && cu->language != language_ada)
2896 + struct die_info *target_die;
2897 + struct dwarf2_cu *target_cu = cu;
2898 + struct attribute *target_loc_attr;
2900 - /* Ada expects an empty array on no boundary attributes. */
2901 - if (attr == NULL && cu->language != language_ada)
2902 - TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
2903 + target_die = follow_die_ref_or_sig (die, attr, &target_cu);
2904 + gdb_assert (target_cu->objfile == cu->objfile);
2905 + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
2907 + TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
2908 + TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist
2909 + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
2910 + TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type
2911 + = die_type (target_die, target_cu);
2912 + TYPE_DYNAMIC (range_type) = 1;
2913 + /* For setting a default if DW_AT_UPPER_BOUND would be missing. */
2918 + if (attr && attr_form_is_constant (attr))
2919 + low = dwarf2_get_attr_constant_value (attr, 0);
2922 + if (cu->language == language_fortran)
2924 + /* FORTRAN implies a lower bound of 1, if not given. */
2929 + /* According to DWARF we should assume the value 0 only for
2930 + LANGUAGE_C and LANGUAGE_CPLUS. */
2934 + if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
2935 + low |= negative_mask;
2936 + TYPE_LOW_BOUND (range_type) = low;
2938 + TYPE_UNSIGNED (range_type) = 1;
2941 + attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
2942 + if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
2943 + && !is_ref_attr (attr)))
2945 + attr = dwarf2_attr (die, DW_AT_count, cu);
2946 + /* It does not hurt but it is needlessly ineffective in check_typedef. */
2947 + if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
2949 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
2950 + TYPE_DYNAMIC (range_type) = 1;
2952 + /* Pass it now as the regular DW_AT_upper_bound. */
2955 + if (attr && attr_form_is_block (attr) && cu->language != language_ada)
2957 + TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
2958 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
2959 + dwarf2_attr_to_locexpr_baton (attr, cu);
2960 + TYPE_DYNAMIC (range_type) = 1;
2962 + else if (attr && is_ref_attr (attr) && cu->language != language_ada)
2964 + struct die_info *target_die;
2965 + struct dwarf2_cu *target_cu = cu;
2966 + struct attribute *target_loc_attr;
2968 + target_die = follow_die_ref_or_sig (die, attr, &target_cu);
2969 + gdb_assert (target_cu->objfile == cu->objfile);
2970 + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
2972 + TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
2973 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist
2974 + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
2975 + TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type
2976 + = die_type (target_die, target_cu);
2977 + TYPE_DYNAMIC (range_type) = 1;
2983 + if (attr && attr_form_is_constant (attr))
2984 + high = dwarf2_get_attr_constant_value (attr, 0);
2987 + /* Ada expects an empty array on no boundary attributes. */
2988 + if (cu->language != language_ada)
2989 + TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
2992 + if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
2993 + high |= negative_mask;
2994 + TYPE_HIGH_BOUND (range_type) = high;
2997 + /* DW_AT_bit_stride is currently unsupported as we count in bytes. */
2998 + attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
2999 + if (attr && attr_form_is_block (attr) && cu->language != language_ada)
3001 + TYPE_RANGE_DATA (range_type)->byte_stride.kind
3002 + = RANGE_BOUND_KIND_DWARF_BLOCK;
3003 + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block =
3004 + dwarf2_attr_to_locexpr_baton (attr, cu);
3005 + TYPE_DYNAMIC (range_type) = 1;
3007 + else if (attr && is_ref_attr (attr) && cu->language != language_ada)
3009 + struct die_info *target_die;
3010 + struct dwarf2_cu *target_cu = cu;
3011 + struct attribute *target_loc_attr;
3013 + target_die = follow_die_ref_or_sig (die, attr, &target_cu);
3014 + gdb_assert (target_cu->objfile == cu->objfile);
3015 + target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
3017 + TYPE_RANGE_DATA (range_type)->byte_stride.kind
3018 + = RANGE_BOUND_KIND_DWARF_LOCLIST;
3019 + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist
3020 + = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
3021 + TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type
3022 + = die_type (target_die, target_cu);
3023 + TYPE_DYNAMIC (range_type) = 1;
3025 + else if (attr && attr_form_is_constant (attr))
3027 + TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
3028 + if (TYPE_BYTE_STRIDE (range_type) == 0)
3029 + complaint (&symfile_complaints,
3030 + _("Found DW_AT_byte_stride with unsupported value 0"));
3033 name = dwarf2_name (die, cu);
3035 @@ -12544,6 +12908,8 @@ read_partial_die (const struct die_reader_specs *reader,
3036 case DW_AT_extension:
3037 part_die->has_specification = 1;
3038 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
3039 + part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
3040 + || cu->per_cu->is_dwz);
3043 /* Ignore absolute siblings, they might point outside of
3044 @@ -12590,7 +12956,11 @@ read_partial_die (const struct die_reader_specs *reader,
3047 if (part_die->tag == DW_TAG_imported_unit)
3048 - part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
3050 + part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
3051 + part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt
3052 + || cu->per_cu->is_dwz);
3057 @@ -12661,13 +13031,14 @@ find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu)
3058 DW_FORM_ref_sig8). */
3060 static struct partial_die_info *
3061 -find_partial_die (sect_offset offset, struct dwarf2_cu *cu)
3062 +find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu)
3064 struct objfile *objfile = cu->objfile;
3065 struct dwarf2_per_cu_data *per_cu = NULL;
3066 struct partial_die_info *pd = NULL;
3068 - if (offset_in_cu_p (&cu->header, offset))
3069 + if (offset_in_dwz == cu->per_cu->is_dwz
3070 + && offset_in_cu_p (&cu->header, offset))
3072 pd = find_partial_die_in_comp_unit (offset, cu);
3074 @@ -12686,7 +13057,8 @@ find_partial_die (sect_offset offset, struct dwarf2_cu *cu)
3075 (long) cu->header.offset.sect_off, (long) offset.sect_off,
3076 bfd_get_filename (objfile->obfd));
3078 - per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
3079 + per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
3082 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
3083 load_partial_comp_unit (per_cu);
3084 @@ -12744,7 +13116,8 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
3086 real_pdi = struct_pdi;
3087 while (real_pdi->has_specification)
3088 - real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3089 + real_pdi = find_partial_die (real_pdi->spec_offset,
3090 + real_pdi->spec_is_dwz, cu);
3092 if (real_pdi->die_parent != NULL)
3094 @@ -12792,7 +13165,8 @@ fixup_partial_die (struct partial_die_info *part_die,
3096 struct partial_die_info *spec_die;
3098 - spec_die = find_partial_die (part_die->spec_offset, cu);
3099 + spec_die = find_partial_die (part_die->spec_offset,
3100 + part_die->spec_is_dwz, cu);
3102 fixup_partial_die (spec_die, cu);
3104 @@ -12880,6 +13254,10 @@ read_attribute_value (const struct die_reader_specs *reader,
3105 &cu->header, &bytes_read);
3106 info_ptr += bytes_read;
3108 + case DW_FORM_GNU_ref_alt:
3109 + DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
3110 + info_ptr += bytes_read;
3113 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
3114 info_ptr += bytes_read;
3115 @@ -12922,10 +13300,25 @@ read_attribute_value (const struct die_reader_specs *reader,
3116 info_ptr += bytes_read;
3119 - DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
3121 - DW_STRING_IS_CANONICAL (attr) = 0;
3122 - info_ptr += bytes_read;
3123 + if (!cu->per_cu->is_dwz)
3125 + DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
3127 + DW_STRING_IS_CANONICAL (attr) = 0;
3128 + info_ptr += bytes_read;
3132 + case DW_FORM_GNU_strp_alt:
3134 + struct dwz_file *dwz = dwarf2_get_dwz_file ();
3135 + LONGEST str_offset = read_offset (abfd, info_ptr, cu_header,
3138 + DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset);
3139 + DW_STRING_IS_CANONICAL (attr) = 0;
3140 + info_ptr += bytes_read;
3143 case DW_FORM_exprloc:
3145 @@ -13037,6 +13430,10 @@ read_attribute_value (const struct die_reader_specs *reader,
3146 bfd_get_filename (abfd));
3150 + if (cu->per_cu->is_dwz && is_ref_attr (attr))
3151 + attr->form = DW_FORM_GNU_ref_alt;
3153 /* We have seen instances where the compiler tried to emit a byte
3154 size attribute of -1 which ended up being encoded as an unsigned
3155 0xffffffff. Although 0xffffffff is technically a valid size value,
3156 @@ -13333,6 +13730,30 @@ read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
3157 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
3160 +/* Read a string at offset STR_OFFSET in the .debug_str section from
3161 + the .dwz file DWZ. Throw an error if the offset is too large. If
3162 + the string consists of a single NUL byte, return NULL; otherwise
3163 + return a pointer to the string. */
3166 +read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset)
3168 + dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str);
3170 + if (dwz->str.buffer == NULL)
3171 + error (_("DW_FORM_GNU_strp_alt used without .debug_str "
3172 + "section [in module %s]"),
3173 + bfd_get_filename (dwz->dwz_bfd));
3174 + if (str_offset >= dwz->str.size)
3175 + error (_("DW_FORM_GNU_strp_alt pointing outside of "
3176 + ".debug_str section [in module %s]"),
3177 + bfd_get_filename (dwz->dwz_bfd));
3178 + gdb_assert (HOST_CHAR_BIT == 8);
3179 + if (dwz->str.buffer[str_offset] == '\0')
3181 + return (char *) (dwz->str.buffer + str_offset);
3185 read_indirect_string (bfd *abfd, gdb_byte *buf,
3186 const struct comp_unit_head *cu_header,
3187 @@ -13804,6 +14225,30 @@ add_file_name (struct line_header *lh,
3191 +/* A convenience function to find the proper .debug_line section for a
3194 +static struct dwarf2_section_info *
3195 +get_debug_line_section (struct dwarf2_cu *cu)
3197 + struct dwarf2_section_info *section;
3199 + /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3201 + if (cu->dwo_unit && cu->per_cu->is_debug_types)
3202 + section = &cu->dwo_unit->dwo_file->sections.line;
3203 + else if (cu->per_cu->is_dwz)
3205 + struct dwz_file *dwz = dwarf2_get_dwz_file ();
3207 + section = &dwz->line;
3210 + section = &dwarf2_per_objfile->line;
3215 /* Read the statement program header starting at OFFSET in
3216 .debug_line, or .debug_line.dwo. Return a pointer
3217 to a struct line_header, allocated using xmalloc.
3218 @@ -13824,13 +14269,7 @@ dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu)
3219 struct dwarf2_section_info *section;
3222 - /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3224 - if (cu->dwo_unit && cu->per_cu->is_debug_types)
3225 - section = &cu->dwo_unit->dwo_file->sections.line;
3227 - section = &dwarf2_per_objfile->line;
3229 + section = get_debug_line_section (cu);
3230 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
3231 if (section->buffer == NULL)
3233 @@ -14155,7 +14594,7 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
3234 GCd by the linker. Ignore it. PR gdb/12528 */
3237 - = line_ptr - dwarf2_per_objfile->line.buffer;
3238 + = line_ptr - get_debug_line_section (cu)->buffer;
3240 complaint (&symfile_complaints,
3241 _(".debug_line address at offset 0x%lx is 0 "
3242 @@ -14534,10 +14973,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
3243 (i.e. when the value of a register or memory location is
3244 referenced, or a thread-local block, etc.). Then again, it might
3245 not be worthwhile. I'm assuming that it isn't unless performance
3246 - or memory numbers show me otherwise. */
3247 + or memory numbers show me otherwise.
3249 + SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed. */
3251 - dwarf2_symbol_mark_computed (attr, sym, cu);
3252 SYMBOL_CLASS (sym) = LOC_COMPUTED;
3253 + dwarf2_symbol_mark_computed (attr, sym, cu);
3255 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
3256 cu->has_loclist = 1;
3257 @@ -14578,6 +15019,8 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
3259 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
3260 OBJSTAT (objfile, n_syms++);
3261 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
3262 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
3264 /* Cache this symbol's name and the name's demangled form (if any). */
3265 SYMBOL_SET_LANGUAGE (sym, cu->language);
3266 @@ -15001,6 +15444,7 @@ dwarf2_const_value_attr (struct attribute *attr, struct type *type,
3267 case DW_FORM_string:
3269 case DW_FORM_GNU_str_index:
3270 + case DW_FORM_GNU_strp_alt:
3271 /* DW_STRING is already allocated on the objfile obstack, point
3273 *bytes = (gdb_byte *) DW_STRING (attr);
3274 @@ -15187,7 +15631,15 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
3276 /* First see if we have it cached. */
3278 - if (is_ref_attr (attr))
3279 + if (attr->form == DW_FORM_GNU_ref_alt)
3281 + struct dwarf2_per_cu_data *per_cu;
3282 + sect_offset offset = dwarf2_get_ref_die_offset (attr);
3284 + per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile);
3285 + this_type = get_die_type_at_offset (offset, per_cu);
3287 + else if (is_ref_attr (attr))
3289 sect_offset offset = dwarf2_get_ref_die_offset (attr);
3291 @@ -15352,6 +15804,9 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
3296 + finalize_type (this_type);
3301 @@ -15960,6 +16415,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
3302 fprintf_unfiltered (f, "ref address: ");
3303 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
3305 + case DW_FORM_GNU_ref_alt:
3306 + fprintf_unfiltered (f, "alt ref address: ");
3307 + fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
3312 @@ -15991,6 +16450,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
3313 case DW_FORM_string:
3315 case DW_FORM_GNU_str_index:
3316 + case DW_FORM_GNU_strp_alt:
3317 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
3318 DW_STRING (&die->attrs[i])
3319 ? DW_STRING (&die->attrs[i]) : "",
3320 @@ -16094,6 +16554,7 @@ is_ref_attr (struct attribute *attr)
3323 case DW_FORM_ref_udata:
3324 + case DW_FORM_GNU_ref_alt:
3328 @@ -16171,7 +16632,8 @@ follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
3329 Returns NULL if OFFSET is invalid. */
3331 static struct die_info *
3332 -follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu)
3333 +follow_die_offset (sect_offset offset, int offset_in_dwz,
3334 + struct dwarf2_cu **ref_cu)
3336 struct die_info temp_die;
3337 struct dwarf2_cu *target_cu, *cu = *ref_cu;
3338 @@ -16188,11 +16650,13 @@ follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu)
3339 if (! offset_in_cu_p (&cu->header, offset))
3342 - else if (! offset_in_cu_p (&cu->header, offset))
3343 + else if (offset_in_dwz != cu->per_cu->is_dwz
3344 + || ! offset_in_cu_p (&cu->header, offset))
3346 struct dwarf2_per_cu_data *per_cu;
3348 - per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
3349 + per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
3352 /* If necessary, add it to the queue and load its DIEs. */
3353 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
3354 @@ -16224,7 +16688,10 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr,
3355 struct dwarf2_cu *cu = *ref_cu;
3356 struct die_info *die;
3358 - die = follow_die_offset (offset, ref_cu);
3359 + die = follow_die_offset (offset,
3360 + (attr->form == DW_FORM_GNU_ref_alt
3361 + || cu->per_cu->is_dwz),
3364 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
3365 "at 0x%x [in module %s]"),
3366 @@ -16255,7 +16722,7 @@ dwarf2_fetch_die_location_block (cu_offset offset_in_cu,
3370 - die = follow_die_offset (offset, &cu);
3371 + die = follow_die_offset (offset, per_cu->is_dwz, &cu);
3373 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
3374 offset.sect_off, per_cu->objfile->name);
3375 @@ -17049,6 +17516,7 @@ skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end,
3377 case DW_FORM_sec_offset:
3379 + case DW_FORM_GNU_strp_alt:
3380 bytes += offset_size;
3383 @@ -17204,7 +17672,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
3384 struct macro_source_file *current_file,
3385 struct line_header *lh, char *comp_dir,
3386 struct dwarf2_section_info *section,
3387 - int section_is_gnu,
3388 + int section_is_gnu, int section_is_dwz,
3389 unsigned int offset_size,
3390 struct objfile *objfile,
3391 htab_t include_hash)
3392 @@ -17255,6 +17723,8 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
3393 case DW_MACRO_GNU_undef:
3394 case DW_MACRO_GNU_define_indirect:
3395 case DW_MACRO_GNU_undef_indirect:
3396 + case DW_MACRO_GNU_define_indirect_alt:
3397 + case DW_MACRO_GNU_undef_indirect_alt:
3399 unsigned int bytes_read;
3401 @@ -17277,11 +17747,21 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
3402 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
3403 mac_ptr += offset_size;
3405 - body = read_indirect_string_at_offset (abfd, str_offset);
3406 + if (macinfo_type == DW_MACRO_GNU_define_indirect_alt
3407 + || macinfo_type == DW_MACRO_GNU_undef_indirect_alt
3408 + || section_is_dwz)
3410 + struct dwz_file *dwz = dwarf2_get_dwz_file ();
3412 + body = read_indirect_string_from_dwz (dwz, str_offset);
3415 + body = read_indirect_string_at_offset (abfd, str_offset);
3418 is_define = (macinfo_type == DW_MACRO_GNU_define
3419 - || macinfo_type == DW_MACRO_GNU_define_indirect);
3420 + || macinfo_type == DW_MACRO_GNU_define_indirect
3421 + || macinfo_type == DW_MACRO_GNU_define_indirect_alt);
3424 /* DWARF violation as no main source is present. */
3425 @@ -17305,7 +17785,8 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
3428 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
3429 - || macinfo_type == DW_MACRO_GNU_undef_indirect);
3430 + || macinfo_type == DW_MACRO_GNU_undef_indirect
3431 + || macinfo_type == DW_MACRO_GNU_undef_indirect_alt);
3432 macro_undef (current_file, line, body);
3435 @@ -17380,6 +17861,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
3438 case DW_MACRO_GNU_transparent_include:
3439 + case DW_MACRO_GNU_transparent_include_alt:
3443 @@ -17398,13 +17880,32 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
3447 + bfd *include_bfd = abfd;
3448 + struct dwarf2_section_info *include_section = section;
3449 + struct dwarf2_section_info alt_section;
3450 + gdb_byte *include_mac_end = mac_end;
3451 + int is_dwz = section_is_dwz;
3455 - dwarf_decode_macro_bytes (abfd,
3456 - section->buffer + offset,
3457 - mac_end, current_file,
3458 + if (macinfo_type == DW_MACRO_GNU_transparent_include_alt)
3460 + struct dwz_file *dwz = dwarf2_get_dwz_file ();
3462 + dwarf2_read_section (dwarf2_per_objfile->objfile,
3465 + include_bfd = dwz->macro.asection->owner;
3466 + include_section = &dwz->macro;
3467 + include_mac_end = dwz->macro.buffer + dwz->macro.size;
3471 + dwarf_decode_macro_bytes (include_bfd,
3472 + include_section->buffer + offset,
3473 + include_mac_end, current_file,
3475 - section, section_is_gnu,
3476 + section, section_is_gnu, is_dwz,
3477 offset_size, objfile, include_hash);
3479 htab_remove_elt (include_hash, mac_ptr);
3480 @@ -17571,6 +18072,8 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
3482 case DW_MACRO_GNU_define_indirect:
3483 case DW_MACRO_GNU_undef_indirect:
3484 + case DW_MACRO_GNU_define_indirect_alt:
3485 + case DW_MACRO_GNU_undef_indirect_alt:
3487 unsigned int bytes_read;
3489 @@ -17581,6 +18084,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
3492 case DW_MACRO_GNU_transparent_include:
3493 + case DW_MACRO_GNU_transparent_include_alt:
3494 /* Note that, according to the spec, a transparent include
3495 chain cannot call DW_MACRO_GNU_start_file. So, we can just
3496 skip this opcode. */
3497 @@ -17623,7 +18127,8 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
3498 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
3500 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
3501 - current_file, lh, comp_dir, section, section_is_gnu,
3502 + current_file, lh, comp_dir, section,
3503 + section_is_gnu, 0,
3504 offset_size, objfile, include_hash);
3505 do_cleanups (cleanup);
3507 @@ -17721,62 +18226,100 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
3508 baton->from_dwo = cu->dwo_unit != NULL;
3512 -dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
3513 - struct dwarf2_cu *cu)
3514 +/* Convert DW_BLOCK into struct dwarf2_locexpr_baton. ATTR must be a DW_BLOCK
3515 + attribute type. */
3517 +static struct dwarf2_locexpr_baton *
3518 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
3520 + struct objfile *objfile = dwarf2_per_objfile->objfile;
3521 + struct dwarf2_locexpr_baton *baton;
3523 + gdb_assert (attr_form_is_block (attr));
3525 + baton = obstack_alloc (&objfile->objfile_obstack, sizeof (*baton));
3526 + baton->per_cu = cu->per_cu;
3527 + gdb_assert (baton->per_cu);
3529 + /* Note that we're just copying the block's data pointer
3530 + here, not the actual data. We're still pointing into the
3531 + info_buffer for SYM's objfile; right now we never release
3532 + that buffer, but when we do clean up properly this may
3533 + need to change. */
3534 + baton->size = DW_BLOCK (attr)->size;
3535 + baton->data = DW_BLOCK (attr)->data;
3536 + gdb_assert (baton->size == 0 || baton->data != NULL);
3541 +static struct dwarf2_loclist_baton *
3542 +dwarf2_attr_to_loclist_baton (struct attribute *attr, struct dwarf2_cu *cu)
3544 struct objfile *objfile = dwarf2_per_objfile->objfile;
3545 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
3546 + struct dwarf2_loclist_baton *baton;
3548 + /* DW_AT_location of the referenced DIE may be missing if the referenced
3549 + variable has been optimized out. */
3553 + dwarf2_read_section (dwarf2_per_objfile->objfile, section);
3555 - if (attr_form_is_section_offset (attr)
3556 + if (!(attr_form_is_section_offset (attr)
3557 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
3558 the section. If so, fall through to the complaint in the
3560 - && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
3562 - struct dwarf2_loclist_baton *baton;
3563 + && DW_UNSND (attr) < dwarf2_section_size (objfile, section)))
3566 - baton = obstack_alloc (&objfile->objfile_obstack,
3567 - sizeof (struct dwarf2_loclist_baton));
3568 + baton = obstack_alloc (&objfile->objfile_obstack,
3569 + sizeof (struct dwarf2_loclist_baton));
3571 - fill_in_loclist_baton (cu, baton, attr);
3572 + fill_in_loclist_baton (cu, baton, attr);
3574 - if (cu->base_known == 0)
3575 - complaint (&symfile_complaints,
3576 - _("Location list used without "
3577 - "specifying the CU base address."));
3578 + if (cu->base_known == 0)
3579 + complaint (&symfile_complaints,
3580 + _("Location list used without "
3581 + "specifying the CU base address."));
3586 +/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content. */
3589 +dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
3590 + struct dwarf2_cu *cu)
3592 + struct dwarf2_loclist_baton *loclist_baton;
3594 + loclist_baton = dwarf2_attr_to_loclist_baton (attr, cu);
3595 + if (loclist_baton)
3597 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
3598 - SYMBOL_LOCATION_BATON (sym) = baton;
3599 + SYMBOL_LOCATION_BATON (sym) = loclist_baton;
3601 + else if (attr_form_is_block (attr))
3603 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
3604 + SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
3608 - struct dwarf2_locexpr_baton *baton;
3609 + dwarf2_invalid_attrib_class_complaint ("location description",
3610 + SYMBOL_NATURAL_NAME (sym));
3612 - baton = obstack_alloc (&objfile->objfile_obstack,
3613 - sizeof (struct dwarf2_locexpr_baton));
3614 - baton->per_cu = cu->per_cu;
3615 - gdb_assert (baton->per_cu);
3616 + /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
3618 - if (attr_form_is_block (attr))
3620 - /* Note that we're just copying the block's data pointer
3621 - here, not the actual data. We're still pointing into the
3622 - info_buffer for SYM's objfile; right now we never release
3623 - that buffer, but when we do clean up properly this may
3624 - need to change. */
3625 - baton->size = DW_BLOCK (attr)->size;
3626 - baton->data = DW_BLOCK (attr)->data;
3630 - dwarf2_invalid_attrib_class_complaint ("location description",
3631 - SYMBOL_NATURAL_NAME (sym));
3634 + SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
3635 + SYMBOL_LOCATION_BATON (sym) = NULL;
3637 - SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
3638 - SYMBOL_LOCATION_BATON (sym) = baton;
3639 + /* For functions a missing DW_AT_frame_base does not optimize out the
3640 + whole function definition, only its frame base resolving. */
3641 + if (attr->name == DW_AT_location)
3642 + SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
3646 @@ -17878,28 +18421,35 @@ dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
3648 static struct dwarf2_per_cu_data *
3649 dwarf2_find_containing_comp_unit (sect_offset offset,
3650 + unsigned int offset_in_dwz,
3651 struct objfile *objfile)
3653 struct dwarf2_per_cu_data *this_cu;
3655 + const sect_offset *cu_off;
3658 high = dwarf2_per_objfile->n_comp_units - 1;
3661 + struct dwarf2_per_cu_data *mid_cu;
3662 int mid = low + (high - low) / 2;
3664 - if (dwarf2_per_objfile->all_comp_units[mid]->offset.sect_off
3665 - >= offset.sect_off)
3666 + mid_cu = dwarf2_per_objfile->all_comp_units[mid];
3667 + cu_off = &mid_cu->offset;
3668 + if (mid_cu->is_dwz > offset_in_dwz
3669 + || (mid_cu->is_dwz == offset_in_dwz
3670 + && cu_off->sect_off >= offset.sect_off))
3675 gdb_assert (low == high);
3676 - if (dwarf2_per_objfile->all_comp_units[low]->offset.sect_off
3677 - > offset.sect_off)
3678 + this_cu = dwarf2_per_objfile->all_comp_units[low];
3679 + cu_off = &this_cu->offset;
3680 + if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off)
3683 + if (low == 0 || this_cu->is_dwz != offset_in_dwz)
3684 error (_("Dwarf Error: could not find partial DIE containing "
3685 "offset 0x%lx [in module %s]"),
3686 (long) offset.sect_off, bfd_get_filename (objfile->obfd));
3687 @@ -18140,6 +18690,25 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
3688 && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
3691 +/* Fill in generic attributes applicable for type DIEs. */
3694 +fetch_die_type_attrs (struct die_info *die, struct type *type,
3695 + struct dwarf2_cu *cu)
3697 + struct attribute *attr;
3699 + attr = dwarf2_attr (die, DW_AT_allocated, cu);
3700 + if (attr_form_is_block (attr))
3701 + TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
3702 + gdb_assert (!TYPE_NOT_ALLOCATED (type));
3704 + attr = dwarf2_attr (die, DW_AT_associated, cu);
3705 + if (attr_form_is_block (attr))
3706 + TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
3707 + gdb_assert (!TYPE_NOT_ASSOCIATED (type));
3710 /* Set the type associated with DIE to TYPE. Save it in CU's hash
3711 table if necessary. For convenience, return TYPE.
3713 @@ -18164,6 +18733,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
3714 struct dwarf2_per_cu_offset_and_type **slot, ofs;
3715 struct objfile *objfile = cu->objfile;
3717 + fetch_die_type_attrs (die, type, cu);
3719 /* For Ada types, make sure that the gnat-specific data is always
3720 initialized (if not already set). There are a few types where
3721 we should not be doing so, because the type-specific area is
3722 @@ -18341,53 +18912,13 @@ show_dwarf2_cmd (char *args, int from_tty)
3723 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
3726 -/* If section described by INFO was mmapped, munmap it now. */
3729 -munmap_section_buffer (struct dwarf2_section_info *info)
3731 - if (info->map_addr != NULL)
3736 - res = munmap (info->map_addr, info->map_len);
3737 - gdb_assert (res == 0);
3739 - /* Without HAVE_MMAP, we should never be here to begin with. */
3740 - gdb_assert_not_reached ("no mmap support");
3745 -/* munmap debug sections for OBJFILE, if necessary. */
3746 +/* Free data associated with OBJFILE, if necessary. */
3749 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
3751 struct dwarf2_per_objfile *data = d;
3753 - struct dwarf2_section_info *section;
3755 - /* This is sorted according to the order they're defined in to make it easier
3756 - to keep in sync. */
3757 - munmap_section_buffer (&data->info);
3758 - munmap_section_buffer (&data->abbrev);
3759 - munmap_section_buffer (&data->line);
3760 - munmap_section_buffer (&data->loc);
3761 - munmap_section_buffer (&data->macinfo);
3762 - munmap_section_buffer (&data->macro);
3763 - munmap_section_buffer (&data->str);
3764 - munmap_section_buffer (&data->ranges);
3765 - munmap_section_buffer (&data->addr);
3766 - munmap_section_buffer (&data->frame);
3767 - munmap_section_buffer (&data->eh_frame);
3768 - munmap_section_buffer (&data->gdb_index);
3771 - VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
3773 - munmap_section_buffer (section);
3775 for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix)
3776 VEC_free (dwarf2_per_cu_ptr,
3777 @@ -18397,6 +18928,9 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
3779 if (data->dwo_files)
3780 free_dwo_files (data->dwo_files, objfile);
3782 + if (data->dwz_file && data->dwz_file->dwz_bfd)
3783 + gdb_bfd_unref (data->dwz_file->dwz_bfd);
3787 diff --git a/gdb/elfread.c b/gdb/elfread.c
3788 index 1edfb27..0b54b8a 100644
3792 #include "gdbthread.h"
3793 #include "regcache.h"
3795 +#include "gdb_bfd.h"
3797 extern void _initialize_elfread (void);
3799 @@ -1108,7 +1109,7 @@ build_id_verify (const char *filename, struct build_id *check)
3802 /* We expect to be silent on the non-existing files. */
3803 - abfd = bfd_open_maybe_remote (filename);
3804 + abfd = gdb_bfd_open_maybe_remote (filename);
3808 @@ -1123,7 +1124,7 @@ build_id_verify (const char *filename, struct build_id *check)
3812 - gdb_bfd_close_or_warn (abfd);
3813 + gdb_bfd_unref (abfd);
3817 @@ -1444,10 +1445,12 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
3821 + struct cleanup *cleanup = make_cleanup (xfree, debugfile);
3822 bfd *abfd = symfile_bfd_open (debugfile);
3824 + make_cleanup_bfd_unref (abfd);
3825 symbol_file_add_separate (abfd, symfile_flags, objfile);
3826 - xfree (debugfile);
3827 + do_cleanups (cleanup);
3831 diff --git a/gdb/eval.c b/gdb/eval.c
3832 index 7d3a8b9..f69dff0 100644
3836 #include "gdb_obstack.h"
3837 #include "objfiles.h"
3838 #include "python/python.h"
3839 +#include "dwarf2loc.h"
3841 #include "gdb_assert.h"
3843 @@ -500,27 +501,217 @@ init_array_element (struct value *array, struct value *element,
3846 static struct value *
3847 -value_f90_subarray (struct value *array,
3848 - struct expression *exp, int *pos, enum noside noside)
3849 +value_f90_subarray (struct value *array, struct expression *exp, int *pos,
3850 + int nargs, enum noside noside)
3852 - int pc = (*pos) + 1;
3853 - LONGEST low_bound, high_bound;
3854 - struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
3855 - enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
3859 - if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
3860 - low_bound = TYPE_LOW_BOUND (range);
3861 + /* Type to use for the newly allocated value ARRAY. */
3862 + struct type *new_array_type;
3864 + /* Type being iterated for each dimension. */
3865 + struct type *type, *type_last_target;
3867 + /* Pointer in the last holder to the type of current dimension. */
3868 + struct type **typep = &new_array_type;
3870 + struct subscript_index
3872 + enum { SUBSCRIPT_RANGE, SUBSCRIPT_NUMBER } kind;
3875 + struct subscript_range
3877 + enum f90_range_type f90_range_type;
3878 + LONGEST low_bound, high_bound;
3885 + struct type **type_array;
3887 + struct cleanup *old_chain;
3888 + CORE_ADDR value_byte_address, value_byte_offset = 0;
3889 + htab_t copied_types;
3890 + struct value *saved_array;
3892 + old_chain = make_cleanup (null_cleanup, 0);
3893 + object_address_set (value_raw_address (array));
3895 + if (value_optimized_out (array)
3896 + || (VALUE_LVAL (array) != not_lval
3897 + && VALUE_LVAL (array) != lval_memory
3898 + && VALUE_LVAL (array) != lval_internalvar_component
3899 + && VALUE_LVAL (array) != lval_internalvar))
3900 + error (_("value being subranged must be in memory"));
3901 + type = check_typedef (value_type (array));
3902 + f_object_address_data_valid_or_error (type);
3904 + copied_types = create_copied_types_hash (NULL);
3905 + type = copy_type_recursive (type, copied_types);
3906 + htab_delete (copied_types);
3908 + if (nargs != calc_f77_array_dims (type))
3909 + error (_("Wrong number of subscripts"));
3911 + if (TYPE_DATA_LOCATION_IS_ADDR (type))
3913 + value_byte_address = (TYPE_DATA_LOCATION_ADDR (type)
3914 + + value_offset (array));
3915 + TYPE_DATA_LOCATION_IS_ADDR (type) = 0;
3916 + TYPE_DATA_LOCATION_DWARF_BLOCK (type) = NULL;
3919 - low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
3921 + gdb_assert (TYPE_DATA_LOCATION_DWARF_BLOCK (type) == NULL);
3922 + value_byte_address = value_address (array);
3925 + new_array_type = type;
3927 + subscript_array = alloca (sizeof (*subscript_array) * nargs);
3929 + gdb_assert (nargs > 0);
3931 + /* Now that we know we have a legal array subscript expression
3932 + let us actually find out where this element exists in the array. */
3934 + /* Take array indices left to right. */
3935 + for (i = 0; i < nargs; i++)
3937 + struct subscript_index *index = &subscript_array[i];
3939 + if (exp->elts[*pos].opcode == OP_F90_RANGE)
3941 + int pc = (*pos) + 1;
3942 + struct subscript_range *range;
3944 + index->kind = SUBSCRIPT_RANGE;
3945 + range = &index->range;
3948 + range->f90_range_type = longest_to_int (exp->elts[pc].longconst);
3950 + if (range->f90_range_type == HIGH_BOUND_DEFAULT
3951 + || range->f90_range_type == NONE_BOUND_DEFAULT)
3952 + range->low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp,
3955 + if (range->f90_range_type == LOW_BOUND_DEFAULT
3956 + || range->f90_range_type == NONE_BOUND_DEFAULT)
3957 + range->high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp,
3962 + struct value *val;
3964 + index->kind = SUBSCRIPT_NUMBER;
3966 - if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
3967 - high_bound = TYPE_HIGH_BOUND (range);
3968 + /* Evaluate each subscript; it must be a legal integer in F77. */
3969 + val = evaluate_subexp_with_coercion (exp, pos, noside);
3970 + index->number = value_as_long (val);
3974 + /* Internal type of array is arranged right to left. */
3975 + for (i = nargs - 1; i >= 0; i--)
3977 + struct subscript_index *index = &subscript_array[i];
3978 + struct type *range_type = TYPE_INDEX_TYPE (type);
3980 + switch (index->kind)
3982 + case SUBSCRIPT_RANGE:
3984 + struct subscript_range *range = &index->range;
3985 + CORE_ADDR byte_offset;
3987 + if (range->f90_range_type == LOW_BOUND_DEFAULT
3988 + || range->f90_range_type == BOTH_BOUND_DEFAULT)
3989 + range->low_bound = TYPE_LOW_BOUND (range_type);
3991 + if (range->f90_range_type == HIGH_BOUND_DEFAULT
3992 + || range->f90_range_type == BOTH_BOUND_DEFAULT)
3993 + range->high_bound = TYPE_HIGH_BOUND (range_type);
3995 + if (range->low_bound < TYPE_LOW_BOUND (range_type)
3996 + || (!TYPE_HIGH_BOUND_UNDEFINED (range_type)
3997 + && range->high_bound > TYPE_HIGH_BOUND (range_type)))
3998 + error (_("slice out of range"));
4000 + byte_offset = ((range->low_bound - TYPE_LOW_BOUND (range_type))
4001 + * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
4002 + TYPE_LOW_BOUND (range_type) = range->low_bound;
4003 + TYPE_HIGH_BOUND (range_type) = range->high_bound;
4004 + if (range->f90_range_type == LOW_BOUND_DEFAULT
4005 + || range->f90_range_type == NONE_BOUND_DEFAULT)
4006 + TYPE_HIGH_BOUND_UNDEFINED (range_type) = 0;
4008 + typep = &TYPE_TARGET_TYPE (type);
4009 + value_byte_offset += byte_offset;
4010 + type = TYPE_TARGET_TYPE (type);
4014 + case SUBSCRIPT_NUMBER:
4016 + CORE_ADDR byte_offset;
4018 + if (index->number < TYPE_LOW_BOUND (range_type)
4019 + || (!TYPE_HIGH_BOUND_UNDEFINED (range_type)
4020 + && index->number > TYPE_HIGH_BOUND (range_type)))
4021 + error (_("no such vector element"));
4023 + byte_offset = ((index->number - TYPE_LOW_BOUND (range_type))
4024 + * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
4026 + type = TYPE_TARGET_TYPE (type);
4028 + value_byte_offset += byte_offset;
4034 + type_last_target = type;
4035 + type_array = alloca (sizeof (*type_array) * nargs);
4037 + for (type = new_array_type; type != type_last_target;
4038 + type = TYPE_TARGET_TYPE (type))
4039 + type_array[i++] = type;
4042 + struct type *type = type_array[--i];
4044 + /* Force TYPE_LENGTH (type) recalculation. */
4045 + TYPE_TARGET_STUB (type) = 1;
4046 + check_typedef (type);
4049 + saved_array = array;
4050 + array = allocate_value_lazy (new_array_type);
4051 + VALUE_LVAL (array) = VALUE_LVAL (saved_array);
4052 + if (VALUE_LVAL (saved_array) == lval_internalvar_component)
4053 + VALUE_LVAL (array) = lval_internalvar;
4055 - high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
4056 + VALUE_LVAL (array) = VALUE_LVAL (saved_array);
4057 + VALUE_FRAME_ID (array) = VALUE_FRAME_ID (saved_array);
4058 + if (VALUE_LVAL (array) != lval_internalvar)
4059 + set_value_address (array, value_byte_address + value_byte_offset);
4061 + if (!value_lazy (saved_array))
4063 + allocate_value_contents (array);
4064 + set_value_lazy (array, 0);
4066 - return value_slice (array, low_bound, high_bound - low_bound + 1);
4067 + memcpy (value_contents_writeable (array),
4068 + value_contents (saved_array) + value_byte_offset,
4069 + TYPE_LENGTH (new_array_type));
4072 + do_cleanups (old_chain);
4077 @@ -818,6 +1009,7 @@ evaluate_subexp_standard (struct type *expect_type,
4079 struct symbol *function = NULL;
4080 char *function_name = NULL;
4081 + struct cleanup *old_chain;
4084 op = exp->elts[pc].opcode;
4085 @@ -1892,6 +2084,8 @@ evaluate_subexp_standard (struct type *expect_type,
4087 /* First determine the type code we are dealing with. */
4088 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
4089 + old_chain = make_cleanup (null_cleanup, 0);
4090 + object_address_set (value_raw_address (arg1));
4091 type = check_typedef (value_type (arg1));
4092 code = TYPE_CODE (type);
4094 @@ -1912,23 +2106,13 @@ evaluate_subexp_standard (struct type *expect_type,
4095 code = TYPE_CODE (type);
4098 + do_cleanups (old_chain);
4102 case TYPE_CODE_ARRAY:
4103 - if (exp->elts[*pos].opcode == OP_F90_RANGE)
4104 - return value_f90_subarray (arg1, exp, pos, noside);
4106 - goto multi_f77_subscript;
4108 case TYPE_CODE_STRING:
4109 - if (exp->elts[*pos].opcode == OP_F90_RANGE)
4110 - return value_f90_subarray (arg1, exp, pos, noside);
4113 - arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
4114 - return value_subscript (arg1, value_as_long (arg2));
4116 + return value_f90_subarray (arg1, exp, pos, nargs, noside);
4119 case TYPE_CODE_FUNC:
4120 @@ -2361,49 +2545,6 @@ evaluate_subexp_standard (struct type *expect_type,
4124 - multi_f77_subscript:
4126 - LONGEST subscript_array[MAX_FORTRAN_DIMS];
4127 - int ndimensions = 1, i;
4128 - struct value *array = arg1;
4130 - if (nargs > MAX_FORTRAN_DIMS)
4131 - error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
4133 - ndimensions = calc_f77_array_dims (type);
4135 - if (nargs != ndimensions)
4136 - error (_("Wrong number of subscripts"));
4138 - gdb_assert (nargs > 0);
4140 - /* Now that we know we have a legal array subscript expression
4141 - let us actually find out where this element exists in the array. */
4143 - /* Take array indices left to right. */
4144 - for (i = 0; i < nargs; i++)
4146 - /* Evaluate each subscript; it must be a legal integer in F77. */
4147 - arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
4149 - /* Fill in the subscript array. */
4151 - subscript_array[i] = value_as_long (arg2);
4154 - /* Internal type of array is arranged right to left. */
4155 - for (i = nargs; i > 0; i--)
4157 - struct type *array_type = check_typedef (value_type (array));
4158 - LONGEST index = subscript_array[i - 1];
4160 - lower = f77_get_lowerbound (array_type);
4161 - array = value_subscripted_rvalue (array, index, lower);
4167 case BINOP_LOGICAL_AND:
4168 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
4169 if (noside == EVAL_SKIP)
4170 @@ -2635,15 +2776,23 @@ evaluate_subexp_standard (struct type *expect_type,
4171 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
4172 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
4173 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
4174 + old_chain = make_cleanup (null_cleanup, 0);
4175 + object_address_set (value_raw_address (arg1));
4176 type = check_typedef (value_type (arg1));
4177 if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
4178 || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
4179 error (_("Attempt to dereference pointer "
4180 "to member without an object"));
4181 if (noside == EVAL_SKIP)
4184 + do_cleanups (old_chain);
4187 if (unop_user_defined_p (op, arg1))
4188 - return value_x_unop (arg1, op, noside);
4190 + do_cleanups (old_chain);
4191 + return value_x_unop (arg1, op, noside);
4193 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
4195 type = check_typedef (value_type (arg1));
4196 @@ -2652,12 +2801,18 @@ evaluate_subexp_standard (struct type *expect_type,
4197 /* In C you can dereference an array to get the 1st elt. */
4198 || TYPE_CODE (type) == TYPE_CODE_ARRAY
4200 - return value_zero (TYPE_TARGET_TYPE (type),
4203 + do_cleanups (old_chain);
4204 + return value_zero (TYPE_TARGET_TYPE (type),
4207 else if (TYPE_CODE (type) == TYPE_CODE_INT)
4208 - /* GDB allows dereferencing an int. */
4209 - return value_zero (builtin_type (exp->gdbarch)->builtin_int,
4212 + do_cleanups (old_chain);
4213 + /* GDB allows dereferencing an int. */
4214 + return value_zero (builtin_type (exp->gdbarch)->builtin_int,
4218 error (_("Attempt to take contents of a non-pointer value."));
4220 @@ -2667,9 +2822,14 @@ evaluate_subexp_standard (struct type *expect_type,
4221 do. "long long" variables are rare enough that
4222 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
4223 if (TYPE_CODE (type) == TYPE_CODE_INT)
4224 - return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
4225 - (CORE_ADDR) value_as_address (arg1));
4226 - return value_ind (arg1);
4228 + do_cleanups (old_chain);
4229 + return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
4230 + (CORE_ADDR) value_as_address (arg1));
4232 + arg1 = value_ind (arg1);
4233 + do_cleanups (old_chain);
4237 /* C++: check for and handle pointer to members. */
4238 @@ -3011,7 +3171,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
4242 - struct value *val;
4243 + struct value *val = NULL;
4247 @@ -3022,13 +3182,18 @@ evaluate_subexp_with_coercion (struct expression *exp,
4250 var = exp->elts[pc + 2].symbol;
4251 + /* address_of_variable will call object_address_set for check_typedef.
4252 + Call it only if required as it can error-out on VAR in register. */
4253 + if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
4254 + val = address_of_variable (var, exp->elts[pc + 1].block);
4255 type = check_typedef (SYMBOL_TYPE (var));
4256 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
4257 && !TYPE_VECTOR (type)
4258 && CAST_IS_CONVERSION (exp->language_defn))
4261 - val = address_of_variable (var, exp->elts[pc + 1].block);
4263 + val = address_of_variable (var, exp->elts[pc + 1].block);
4264 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
4267 @@ -3080,9 +3245,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
4271 - type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
4273 - value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
4274 + /* We do not need to call read_var_value but the object evaluation may
4275 + need to have executed object_address_set which needs valid
4276 + SYMBOL_VALUE_ADDRESS of the symbol. Still VALUE returned by
4277 + read_var_value we left as lazy. */
4278 + type = value_type (read_var_value (exp->elts[pc + 2].symbol,
4279 + deprecated_safe_get_selected_frame ()));
4280 + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
4283 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
4284 @@ -3113,18 +3282,25 @@ parse_and_eval_type (char *p, int length)
4286 calc_f77_array_dims (struct type *array_type)
4289 - struct type *tmp_type;
4290 + switch (TYPE_CODE (array_type))
4292 + case TYPE_CODE_STRING:
4295 - if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
4296 - error (_("Can't get dimensions for a non-array type"));
4297 + case TYPE_CODE_ARRAY:
4301 - tmp_type = array_type;
4302 + while ((array_type = TYPE_TARGET_TYPE (array_type)))
4304 + if (TYPE_CODE (array_type) == TYPE_CODE_ARRAY)
4310 - while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
4312 - if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
4315 + error (_("Can't get dimensions for a non-array/non-string type"));
4320 diff --git a/gdb/exec.c b/gdb/exec.c
4321 index 6ba1986..e076609 100644
4325 #include "arch-utils.h"
4326 #include "gdbthread.h"
4327 #include "progspace.h"
4328 +#include "gdb_bfd.h"
4331 #include "readline/readline.h"
4332 @@ -98,10 +99,8 @@ exec_close (void)
4335 bfd *abfd = exec_bfd;
4336 - char *name = bfd_get_filename (abfd);
4338 - gdb_bfd_close_or_warn (abfd);
4340 + gdb_bfd_unref (abfd);
4342 /* Removing target sections may close the exec_ops target.
4343 Clear exec_bfd before doing so to prevent recursion. */
4344 @@ -128,17 +127,13 @@ exec_close_1 (int quitting)
4348 - /* if there is an objfile associated with this bfd,
4349 - free_objfile() will do proper cleanup of objfile *and* bfd. */
4353 free_objfile (vp->objfile);
4354 need_symtab_cleanup = 1;
4356 - else if (vp->bfd != exec_bfd)
4357 - /* FIXME-leak: We should be freeing vp->name too, I think. */
4358 - gdb_bfd_close_or_warn (vp->bfd);
4360 + gdb_bfd_unref (vp->bfd);
4364 @@ -230,11 +225,14 @@ exec_file_attach (char *filename, int from_tty)
4369 + cleanups = make_cleanup (xfree, scratch_pathname);
4371 if (scratch_chan < 0)
4372 perror_with_name (filename);
4373 - exec_bfd = bfd_fopen (scratch_pathname, gnutarget,
4374 - write_files ? FOPEN_RUB : FOPEN_RB,
4376 + exec_bfd = gdb_bfd_fopen (scratch_pathname, gnutarget,
4377 + write_files ? FOPEN_RUB : FOPEN_RB,
4382 @@ -242,13 +240,6 @@ exec_file_attach (char *filename, int from_tty)
4383 scratch_pathname, bfd_errmsg (bfd_get_error ()));
4386 - /* At this point, scratch_pathname and exec_bfd->name both point to the
4387 - same malloc'd string. However exec_close() will attempt to free it
4388 - via the exec_bfd->name pointer, so we need to make another copy and
4389 - leave exec_bfd as the new owner of the original copy. */
4390 - scratch_pathname = xstrdup (scratch_pathname);
4391 - cleanups = make_cleanup (xfree, scratch_pathname);
4393 if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
4395 /* Make sure to close exec_bfd, or else "run" might try to use
4396 @@ -554,6 +545,7 @@ map_vmap (bfd *abfd, bfd *arch)
4397 memset ((char *) vp, '\0', sizeof (*vp));
4400 + gdb_bfd_ref (abfd);
4401 vp->name = bfd_get_filename (arch ? arch : abfd);
4402 vp->member = arch ? bfd_get_filename (abfd) : "";
4404 diff --git a/gdb/f-exp.y b/gdb/f-exp.y
4405 index 33c7418..4db1bfa 100644
4408 @@ -298,7 +298,9 @@ arglist : subrange
4409 { arglist_len = 1; }
4412 -arglist : arglist ',' exp %prec ABOVE_COMMA
4413 +arglist : arglist ',' exp %prec ABOVE_COMMA
4414 + { arglist_len++; }
4415 + | arglist ',' subrange %prec ABOVE_COMMA
4419 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
4420 index 4aae3c5..51a4e1e 100644
4423 @@ -28,6 +28,10 @@ extern void f_error (char *); /* Defined in f-exp.y */
4424 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
4427 +extern const char *f_object_address_data_valid_print_to_stream
4428 + (struct type *type, struct ui_file *stream);
4429 +extern void f_object_address_data_valid_or_error (struct type *type);
4431 extern void f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
4432 struct ui_file *, int,
4433 const struct value *,
4434 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
4435 index a95ef84..830917d 100644
4436 --- a/gdb/f-typeprint.c
4437 +++ b/gdb/f-typeprint.c
4439 #include "gdbcore.h"
4443 +#include "dwarf2loc.h"
4444 #include "gdb_string.h"
4447 @@ -48,6 +48,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
4448 void f_type_print_base (struct type *, struct ui_file *, int, int);
4452 +f_object_address_data_valid_print_to_stream (struct type *type,
4453 + struct ui_file *stream)
4457 + msg = object_address_data_not_valid (type);
4460 + /* Assuming the content printed to STREAM should not be localized. */
4461 + fprintf_filtered (stream, "<%s>", msg);
4468 +f_object_address_data_valid_or_error (struct type *type)
4472 + msg = object_address_data_not_valid (type);
4475 + error (_("Cannot access it because the %s."), _(msg));
4479 /* LEVEL is the depth to indent lines by. */
4482 @@ -57,6 +85,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
4483 enum type_code code;
4486 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
4489 f_type_print_base (type, stream, show, level);
4490 code = TYPE_CODE (type);
4491 if ((varstring != NULL && *varstring != '\0')
4492 @@ -164,6 +195,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
4496 + if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
4497 + CHECK_TYPEDEF (type);
4499 switch (TYPE_CODE (type))
4501 case TYPE_CODE_ARRAY:
4502 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
4503 index 4359f6f..8ff834b 100644
4504 --- a/gdb/f-valprint.c
4505 +++ b/gdb/f-valprint.c
4506 @@ -54,15 +54,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
4507 /* The following macro gives us the size of the nth dimension, Where
4510 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
4511 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
4513 -/* The following gives us the offset for row n where n is 1-based. */
4514 +/* The following gives us the element size for row n where n is 1-based. */
4516 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
4517 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
4520 f77_get_lowerbound (struct type *type)
4522 + f_object_address_data_valid_or_error (type);
4524 if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
4525 error (_("Lower bound may not be '*' in F77"));
4527 @@ -72,14 +74,17 @@ f77_get_lowerbound (struct type *type)
4529 f77_get_upperbound (struct type *type)
4531 + f_object_address_data_valid_or_error (type);
4533 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
4535 - /* We have an assumed size array on our hands. Assume that
4536 - upper_bound == lower_bound so that we show at least 1 element.
4537 - If the user wants to see more elements, let him manually ask for 'em
4538 - and we'll subscript the array and show him. */
4539 + /* We have an assumed size array on our hands. As type_length_get
4540 + already assumes a length zero of arrays with underfined bounds VALADDR
4541 + passed to the Fortran functions does not contained the real inferior
4542 + memory content. User should request printing of specific array
4543 + elements instead. */
4545 - return f77_get_lowerbound (type);
4546 + return f77_get_lowerbound (type) - 1;
4549 return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
4550 @@ -135,24 +140,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
4551 upper = f77_get_upperbound (tmp_type);
4552 lower = f77_get_lowerbound (tmp_type);
4554 - F77_DIM_SIZE (ndimen) = upper - lower + 1;
4555 + F77_DIM_COUNT (ndimen) = upper - lower + 1;
4557 + F77_DIM_BYTE_STRIDE (ndimen) =
4558 + TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
4560 tmp_type = TYPE_TARGET_TYPE (tmp_type);
4564 - /* Now we multiply eltlen by all the offsets, so that later we
4565 + /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
4566 can print out array elements correctly. Up till now we
4567 - know an offset to apply to get the item but we also
4568 + know an eltlen to apply to get the item but we also
4569 have to know how much to add to get to the next item. */
4572 eltlen = TYPE_LENGTH (tmp_type);
4573 - F77_DIM_OFFSET (ndimen) = eltlen;
4574 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
4575 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
4576 while (--ndimen > 0)
4578 - eltlen *= F77_DIM_SIZE (ndimen + 1);
4579 - F77_DIM_OFFSET (ndimen) = eltlen;
4580 + eltlen *= F77_DIM_COUNT (ndimen + 1);
4581 + if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
4582 + F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
4586 @@ -174,37 +184,35 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
4588 if (nss != ndimensions)
4591 - (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max);
4593 + for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
4595 fprintf_filtered (stream, "( ");
4596 f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
4598 - embedded_offset + i * F77_DIM_OFFSET (nss),
4599 + embedded_offset + i * F77_DIM_BYTE_STRIDE (nss),
4601 stream, recurse, val, options, elts);
4602 fprintf_filtered (stream, ") ");
4604 - if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
4605 + if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
4606 fprintf_filtered (stream, "...");
4610 - for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
4611 + for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
4614 val_print (TYPE_TARGET_TYPE (type),
4616 - embedded_offset + i * F77_DIM_OFFSET (ndimensions),
4617 + embedded_offset + i * F77_DIM_BYTE_STRIDE (ndimensions),
4618 address, stream, recurse,
4619 val, options, current_language);
4621 - if (i != (F77_DIM_SIZE (nss) - 1))
4622 + if (i != (F77_DIM_COUNT (nss) - 1))
4623 fprintf_filtered (stream, ", ");
4625 if ((*elts == options->print_max - 1)
4626 - && (i != (F77_DIM_SIZE (nss) - 1)))
4627 + && (i != (F77_DIM_COUNT (nss) - 1)))
4628 fprintf_filtered (stream, "...");
4631 @@ -270,6 +278,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
4635 + if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
4638 CHECK_TYPEDEF (type);
4639 switch (TYPE_CODE (type))
4641 diff --git a/gdb/findvar.c b/gdb/findvar.c
4642 index 66bcebe..e59e5f2 100644
4647 #include "objfiles.h"
4648 #include "language.h"
4649 +#include "dwarf2loc.h"
4651 /* Basic byte-swapping routines. All 'extract' functions return a
4652 host-format integer from a target-format integer at ADDR which is
4653 @@ -438,7 +439,10 @@ minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data)
4656 /* A default implementation for the "la_read_var_value" hook in
4657 - the language vector which should work in most situations. */
4658 + the language vector which should work in most situations.
4659 + We have to first find the address of the variable before allocating struct
4660 + value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
4661 + used by its type. */
4664 default_read_var_value (struct symbol *var, struct frame_info *frame)
4665 @@ -446,16 +450,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4667 struct type *type = SYMBOL_TYPE (var);
4671 - /* Call check_typedef on our type to make sure that, if TYPE is
4672 - a TYPE_CODE_TYPEDEF, its length is set to the length of the target type
4673 - instead of zero. However, we do not replace the typedef type by the
4674 - target type, because we want to keep the typedef in order to be able to
4675 - set the returned value type description correctly. */
4676 - check_typedef (type);
4678 - len = TYPE_LENGTH (type);
4680 if (symbol_read_needs_frame (var))
4682 @@ -465,7 +459,7 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4684 /* Put the constant back in target format. */
4685 v = allocate_value (type);
4686 - store_signed_integer (value_contents_raw (v), len,
4687 + store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
4688 gdbarch_byte_order (get_type_arch (type)),
4689 (LONGEST) SYMBOL_VALUE (var));
4690 VALUE_LVAL (v) = not_lval;
4691 @@ -490,12 +484,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4693 case LOC_CONST_BYTES:
4694 v = allocate_value (type);
4695 - memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
4696 + memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
4697 + TYPE_LENGTH (type));
4698 VALUE_LVAL (v) = not_lval;
4702 - v = allocate_value_lazy (type);
4703 if (overlay_debugging)
4704 addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
4705 SYMBOL_OBJ_SECTION (var));
4706 @@ -509,7 +503,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4707 error (_("Unknown argument list address for `%s'."),
4708 SYMBOL_PRINT_NAME (var));
4709 addr += SYMBOL_VALUE (var);
4710 - v = allocate_value_lazy (type);
4714 @@ -524,14 +517,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4715 argref += SYMBOL_VALUE (var);
4716 ref = value_at (lookup_pointer_type (type), argref);
4717 addr = value_as_address (ref);
4718 - v = allocate_value_lazy (type);
4723 addr = get_frame_locals_address (frame);
4724 addr += SYMBOL_VALUE (var);
4725 - v = allocate_value_lazy (type);
4729 @@ -540,7 +531,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4733 - v = allocate_value_lazy (type);
4734 if (overlay_debugging)
4735 addr = symbol_overlayed_address
4736 (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
4737 @@ -566,7 +556,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4738 SYMBOL_PRINT_NAME (var));
4740 addr = value_as_address (regval);
4741 - v = allocate_value_lazy (type);
4745 @@ -615,7 +604,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4747 && (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
4748 addr = target_translate_tls_address (obj_section->objfile, addr);
4749 - v = allocate_value_lazy (type);
4753 @@ -628,6 +616,10 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
4757 + /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
4758 + DW_OP_PUSH_OBJECT_ADDRESS. */
4759 + object_address_set (addr);
4760 + v = allocate_value_lazy (type);
4761 VALUE_LVAL (v) = lval_memory;
4762 set_value_address (v, addr);
4764 @@ -723,10 +715,11 @@ struct value *
4765 value_from_register (struct type *type, int regnum, struct frame_info *frame)
4767 struct gdbarch *gdbarch = get_frame_arch (frame);
4768 - struct type *type1 = check_typedef (type);
4771 - if (gdbarch_convert_register_p (gdbarch, regnum, type1))
4772 + type = check_typedef (type);
4774 + if (gdbarch_convert_register_p (gdbarch, regnum, type))
4776 int optim, unavail, ok;
4778 @@ -741,7 +734,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
4779 VALUE_LVAL (v) = lval_register;
4780 VALUE_FRAME_ID (v) = get_frame_id (frame);
4781 VALUE_REGNUM (v) = regnum;
4782 - ok = gdbarch_register_to_value (gdbarch, frame, regnum, type1,
4783 + ok = gdbarch_register_to_value (gdbarch, frame, regnum, type,
4784 value_contents_raw (v), &optim,
4787 diff --git a/gdb/gcore.c b/gdb/gcore.c
4788 index aedda41..a45e787 100644
4793 #include "regcache.h"
4795 +#include "gdb_bfd.h"
4797 /* The largest amount of memory to read from the target at once. We
4798 must throttle it to limit the amount of memory used by GDB during
4799 @@ -50,7 +51,7 @@ static int gcore_memory_sections (bfd *);
4801 create_gcore_bfd (char *filename)
4803 - bfd *obfd = bfd_openw (filename, default_gcore_target ());
4804 + bfd *obfd = gdb_bfd_openw (filename, default_gcore_target ());
4807 error (_("Failed to open '%s' for output."), filename);
4808 @@ -110,7 +111,7 @@ do_bfd_delete_cleanup (void *arg)
4810 const char *filename = obfd->filename;
4813 + gdb_bfd_unref (arg);
4817 @@ -154,7 +155,7 @@ gcore_command (char *args, int from_tty)
4818 fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename);
4820 discard_cleanups (old_chain);
4822 + gdb_bfd_unref (obfd);
4825 static unsigned long
4826 diff --git a/gdb/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
4827 index ffb7f53..a2e7e94 100644
4828 --- a/gdb/gdb-gdb.gdb.in
4829 +++ b/gdb/gdb-gdb.gdb.in
4831 echo Setting up the environment for debugging gdb.\n
4833 +# Set up the Python library and "require" command.
4835 +from os.path import abspath
4836 +gdb.datadir = abspath ('@srcdir@/python/lib')
4837 +gdb.pythonlibdir = gdb.datadir
4838 +gdb.__path__ = [gdb.datadir + '/gdb']
4839 +sys.path.insert(0, gdb.datadir)
4841 +source @srcdir@/python/lib/gdb/__init__.py
4846 diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
4847 new file mode 100644
4848 index 0000000..fac8776
4852 +/* Definitions for BFD wrappers used by GDB.
4854 + Copyright (C) 2011, 2012
4855 + Free Software Foundation, Inc.
4857 + This file is part of GDB.
4859 + This program is free software; you can redistribute it and/or modify
4860 + it under the terms of the GNU General Public License as published by
4861 + the Free Software Foundation; either version 3 of the License, or
4862 + (at your option) any later version.
4864 + This program is distributed in the hope that it will be useful,
4865 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4866 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4867 + GNU General Public License for more details.
4869 + You should have received a copy of the GNU General Public License
4870 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
4873 +#include "gdb_bfd.h"
4874 +#include "gdb_assert.h"
4875 +#include "gdb_string.h"
4876 +#include "ui-out.h"
4877 +#include "gdbcmd.h"
4878 +#include "hashtab.h"
4883 +#include <sys/mman.h>
4885 +#define MAP_FAILED ((void *) -1)
4889 +/* An object of this type is stored in the section's user data when
4890 + mapping a section. */
4892 +struct gdb_bfd_section_data
4894 + /* Size of the data. */
4895 + bfd_size_type size;
4896 + /* If the data was mmapped, this is the length of the map. */
4897 + bfd_size_type map_len;
4898 + /* The data. If NULL, the section data has not been read. */
4900 + /* If the data was mmapped, this is the map address. */
4904 +/* A hash table holding every BFD that gdb knows about. This is not
4905 + to be confused with 'gdb_bfd_cache', which is used for sharing
4906 + BFDs; in contrast, this hash is used just to implement
4907 + "maint info bfd". */
4909 +static htab_t all_bfds;
4911 +/* See gdb_bfd.h. */
4914 +gdb_bfd_stash_filename (struct bfd *abfd)
4916 + char *name = bfd_get_filename (abfd);
4919 + data = bfd_alloc (abfd, strlen (name) + 1);
4920 + strcpy (data, name);
4922 + /* Unwarranted chumminess with BFD. */
4923 + abfd->filename = data;
4926 +/* An object of this type is stored in each BFD's user data. */
4928 +struct gdb_bfd_data
4930 + /* The reference count. */
4933 + /* The mtime of the BFD at the point the cache entry was made. */
4937 +/* A hash table storing all the BFDs maintained in the cache. */
4939 +static htab_t gdb_bfd_cache;
4941 +/* The type of an object being looked up in gdb_bfd_cache. We use
4942 + htab's capability of storing one kind of object (BFD in this case)
4943 + and using a different sort of object for searching. */
4945 +struct gdb_bfd_cache_search
4947 + /* The filename. */
4948 + const char *filename;
4953 +/* A hash function for BFDs. */
4956 +hash_bfd (const void *b)
4958 + const bfd *abfd = b;
4960 + /* It is simplest to just hash the filename. */
4961 + return htab_hash_string (bfd_get_filename (abfd));
4964 +/* An equality function for BFDs. Note that this expects the caller
4965 + to search using struct gdb_bfd_cache_search only, not BFDs. */
4968 +eq_bfd (const void *a, const void *b)
4970 + const bfd *abfd = a;
4971 + const struct gdb_bfd_cache_search *s = b;
4972 + struct gdb_bfd_data *gdata = bfd_usrdata (abfd);
4974 + return (gdata->mtime == s->mtime
4975 + && strcmp (bfd_get_filename (abfd), s->filename) == 0);
4978 +/* See gdb_bfd.h. */
4981 +gdb_bfd_open (const char *name, const char *target, int fd)
4986 + struct gdb_bfd_cache_search search;
4989 + if (gdb_bfd_cache == NULL)
4990 + gdb_bfd_cache = htab_create_alloc (1, hash_bfd, eq_bfd, NULL,
4995 + fd = open (name, O_RDONLY | O_BINARY);
4998 + bfd_set_error (bfd_error_system_call);
5003 + search.filename = name;
5004 + if (fstat (fd, &st) < 0)
5006 + /* Weird situation here. */
5010 + search.mtime = st.st_mtime;
5012 + /* Note that this must compute the same result as hash_bfd. */
5013 + hash = htab_hash_string (name);
5014 + /* Note that we cannot use htab_find_slot_with_hash here, because
5015 + opening the BFD may fail; and this would violate hashtab
5017 + abfd = htab_find_with_hash (gdb_bfd_cache, &search, hash);
5021 + gdb_bfd_ref (abfd);
5025 + abfd = bfd_fopen (name, target, FOPEN_RB, fd);
5029 + slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
5030 + gdb_assert (!*slot);
5033 + gdb_bfd_stash_filename (abfd);
5034 + gdb_bfd_ref (abfd);
5038 +/* A helper function that releases any section data attached to the
5042 +free_one_bfd_section (bfd *abfd, asection *sectp, void *ignore)
5044 + struct gdb_bfd_section_data *sect = bfd_get_section_userdata (abfd, sectp);
5046 + if (sect != NULL && sect->data != NULL)
5049 + if (sect->map_addr != NULL)
5053 + res = munmap (sect->map_addr, sect->map_len);
5054 + gdb_assert (res == 0);
5058 + xfree (sect->data);
5062 +/* Close ABFD, and warn if that fails. */
5065 +gdb_bfd_close_or_warn (struct bfd *abfd)
5068 + char *name = bfd_get_filename (abfd);
5070 + bfd_map_over_sections (abfd, free_one_bfd_section, NULL);
5072 + ret = bfd_close (abfd);
5075 + warning (_("cannot close \"%s\": %s"),
5076 + name, bfd_errmsg (bfd_get_error ()));
5081 +/* See gdb_bfd.h. */
5084 +gdb_bfd_ref (struct bfd *abfd)
5086 + struct gdb_bfd_data *gdata;
5092 + gdata = bfd_usrdata (abfd);
5094 + if (gdata != NULL)
5100 + gdata = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
5102 + gdata->mtime = bfd_get_mtime (abfd);
5103 + bfd_usrdata (abfd) = gdata;
5105 + /* This is the first we've seen it, so add it to the hash table. */
5106 + slot = htab_find_slot (all_bfds, abfd, INSERT);
5107 + gdb_assert (slot && !*slot);
5111 +/* See gdb_bfd.h. */
5114 +gdb_bfd_unref (struct bfd *abfd)
5116 + struct gdb_bfd_data *gdata;
5117 + struct gdb_bfd_cache_search search;
5123 + gdata = bfd_usrdata (abfd);
5124 + gdb_assert (gdata->refc >= 1);
5127 + if (gdata->refc > 0)
5130 + search.filename = bfd_get_filename (abfd);
5132 + if (gdb_bfd_cache && search.filename)
5134 + hashval_t hash = htab_hash_string (search.filename);
5137 + search.mtime = gdata->mtime;
5138 + slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash,
5141 + if (slot && *slot)
5142 + htab_clear_slot (gdb_bfd_cache, slot);
5145 + bfd_usrdata (abfd) = NULL; /* Paranoia. */
5147 + htab_remove_elt (all_bfds, abfd);
5149 + gdb_bfd_close_or_warn (abfd);
5152 +/* A helper function that returns the section data descriptor
5153 + associated with SECTION. If no such descriptor exists, a new one
5154 + is allocated and cleared. */
5156 +static struct gdb_bfd_section_data *
5157 +get_section_descriptor (asection *section)
5159 + struct gdb_bfd_section_data *result;
5161 + result = bfd_get_section_userdata (section->owner, section);
5163 + if (result == NULL)
5165 + result = bfd_zalloc (section->owner, sizeof (*result));
5166 + bfd_set_section_userdata (section->owner, section, result);
5172 +/* Decompress a section that was compressed using zlib. Store the
5173 + decompressed buffer, and its size, in DESCRIPTOR. */
5176 +zlib_decompress_section (asection *sectp,
5177 + struct gdb_bfd_section_data *descriptor)
5179 + bfd *abfd = sectp->owner;
5180 +#ifndef HAVE_ZLIB_H
5181 + error (_("Support for zlib-compressed data (from '%s', section '%s') "
5182 + "is disabled in this copy of GDB"),
5183 + bfd_get_filename (abfd),
5184 + bfd_get_section_name (sectp));
5186 + bfd_size_type compressed_size = bfd_get_section_size (sectp);
5187 + gdb_byte *compressed_buffer = xmalloc (compressed_size);
5188 + struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
5189 + struct cleanup *inner_cleanup;
5190 + bfd_size_type uncompressed_size;
5191 + gdb_byte *uncompressed_buffer;
5194 + int header_size = 12;
5195 + struct dwarf2_per_bfd_section *section_data;
5197 + if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5198 + || bfd_bread (compressed_buffer,
5199 + compressed_size, abfd) != compressed_size)
5200 + error (_("can't read data from '%s', section '%s'"),
5201 + bfd_get_filename (abfd),
5202 + bfd_get_section_name (abfd, sectp));
5204 + /* Read the zlib header. In this case, it should be "ZLIB" followed
5205 + by the uncompressed section size, 8 bytes in big-endian order. */
5206 + if (compressed_size < header_size
5207 + || strncmp (compressed_buffer, "ZLIB", 4) != 0)
5208 + error (_("corrupt ZLIB header from '%s', section '%s'"),
5209 + bfd_get_filename (abfd),
5210 + bfd_get_section_name (abfd, sectp));
5211 + uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
5212 + uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
5213 + uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
5214 + uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
5215 + uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
5216 + uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
5217 + uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
5218 + uncompressed_size += compressed_buffer[11];
5220 + /* It is possible the section consists of several compressed
5221 + buffers concatenated together, so we uncompress in a loop. */
5222 + strm.zalloc = NULL;
5223 + strm.zfree = NULL;
5224 + strm.opaque = NULL;
5225 + strm.avail_in = compressed_size - header_size;
5226 + strm.next_in = (Bytef*) compressed_buffer + header_size;
5227 + strm.avail_out = uncompressed_size;
5228 + uncompressed_buffer = xmalloc (uncompressed_size);
5229 + inner_cleanup = make_cleanup (xfree, uncompressed_buffer);
5230 + rc = inflateInit (&strm);
5231 + while (strm.avail_in > 0)
5234 + error (_("setting up uncompression in '%s', section '%s': %d"),
5235 + bfd_get_filename (abfd),
5236 + bfd_get_section_name (abfd, sectp),
5238 + strm.next_out = ((Bytef*) uncompressed_buffer
5239 + + (uncompressed_size - strm.avail_out));
5240 + rc = inflate (&strm, Z_FINISH);
5241 + if (rc != Z_STREAM_END)
5242 + error (_("zlib error uncompressing from '%s', section '%s': %d"),
5243 + bfd_get_filename (abfd),
5244 + bfd_get_section_name (abfd, sectp),
5246 + rc = inflateReset (&strm);
5248 + rc = inflateEnd (&strm);
5250 + || strm.avail_out != 0)
5251 + error (_("concluding uncompression in '%s', section '%s': %d"),
5252 + bfd_get_filename (abfd),
5253 + bfd_get_section_name (abfd, sectp),
5256 + discard_cleanups (inner_cleanup);
5257 + do_cleanups (cleanup);
5259 + /* Attach the data to the BFD section. */
5260 + descriptor->data = uncompressed_buffer;
5261 + descriptor->size = uncompressed_size;
5265 +/* See gdb_bfd.h. */
5268 +gdb_bfd_map_section (asection *sectp, bfd_size_type *size)
5271 + gdb_byte *buf, *retbuf;
5272 + unsigned char header[4];
5273 + struct gdb_bfd_section_data *descriptor;
5275 + gdb_assert ((sectp->flags & SEC_RELOC) == 0);
5276 + gdb_assert (size != NULL);
5278 + abfd = sectp->owner;
5280 + descriptor = get_section_descriptor (sectp);
5282 + /* If the data was already read for this BFD, just reuse it. */
5283 + if (descriptor->data != NULL)
5286 + /* Check if the file has a 4-byte header indicating compression. */
5287 + if (bfd_get_section_size (sectp) > sizeof (header)
5288 + && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
5289 + && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
5291 + /* Upon decompression, update the buffer and its size. */
5292 + if (strncmp (header, "ZLIB", sizeof (header)) == 0)
5294 + zlib_decompress_section (sectp, descriptor);
5301 + /* The page size, used when mmapping. */
5302 + static int pagesize;
5304 + if (pagesize == 0)
5305 + pagesize = getpagesize ();
5307 + /* Only try to mmap sections which are large enough: we don't want
5308 + to waste space due to fragmentation. */
5310 + if (bfd_get_section_size (sectp) > 4 * pagesize)
5312 + descriptor->size = bfd_get_section_size (sectp);
5313 + descriptor->data = bfd_mmap (abfd, 0, descriptor->size, PROT_READ,
5314 + MAP_PRIVATE, sectp->filepos,
5315 + &descriptor->map_addr,
5316 + &descriptor->map_len);
5318 + if ((caddr_t)descriptor->data != MAP_FAILED)
5320 +#if HAVE_POSIX_MADVISE
5321 + posix_madvise (descriptor->map_addr, descriptor->map_len,
5322 + POSIX_MADV_WILLNEED);
5327 + /* On failure, clear out the section data and try again. */
5328 + memset (descriptor, 0, sizeof (*descriptor));
5331 +#endif /* HAVE_MMAP */
5333 + /* If we get here, we are a normal, not-compressed section. */
5335 + descriptor->size = bfd_get_section_size (sectp);
5336 + descriptor->data = xmalloc (descriptor->size);
5338 + if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
5339 + || bfd_bread (descriptor->data, bfd_get_section_size (sectp),
5340 + abfd) != bfd_get_section_size (sectp))
5342 + xfree (descriptor->data);
5343 + descriptor->data = NULL;
5344 + error (_("Can't read data for section '%s'"),
5345 + bfd_get_filename (abfd));
5349 + gdb_assert (descriptor->data != NULL);
5350 + *size = descriptor->size;
5351 + return descriptor->data;
5356 +/* See gdb_bfd.h. */
5359 +gdb_bfd_fopen (const char *filename, const char *target, const char *mode,
5362 + bfd *result = bfd_fopen (filename, target, mode, fd);
5366 + gdb_bfd_stash_filename (result);
5367 + gdb_bfd_ref (result);
5373 +/* See gdb_bfd.h. */
5376 +gdb_bfd_openr (const char *filename, const char *target)
5378 + bfd *result = bfd_openr (filename, target);
5382 + gdb_bfd_stash_filename (result);
5383 + gdb_bfd_ref (result);
5389 +/* See gdb_bfd.h. */
5392 +gdb_bfd_openw (const char *filename, const char *target)
5394 + bfd *result = bfd_openw (filename, target);
5398 + gdb_bfd_stash_filename (result);
5399 + gdb_bfd_ref (result);
5405 +/* See gdb_bfd.h. */
5408 +gdb_bfd_openr_iovec (const char *filename, const char *target,
5409 + void *(*open_func) (struct bfd *nbfd,
5410 + void *open_closure),
5411 + void *open_closure,
5412 + file_ptr (*pread_func) (struct bfd *nbfd,
5417 + int (*close_func) (struct bfd *nbfd,
5419 + int (*stat_func) (struct bfd *abfd,
5423 + bfd *result = bfd_openr_iovec (filename, target,
5424 + open_func, open_closure,
5425 + pread_func, close_func, stat_func);
5429 + gdb_bfd_ref (result);
5430 + gdb_bfd_stash_filename (result);
5436 +/* See gdb_bfd.h. */
5439 +gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous)
5441 + bfd *result = bfd_openr_next_archived_file (archive, previous);
5445 + gdb_bfd_ref (result);
5446 + /* No need to stash the filename here. */
5452 +/* See gdb_bfd.h. */
5455 +gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
5457 + bfd *result = bfd_fdopenr (filename, target, fd);
5461 + gdb_bfd_ref (result);
5462 + gdb_bfd_stash_filename (result);
5470 +/* A callback for htab_traverse that prints a single BFD. */
5473 +print_one_bfd (void **slot, void *data)
5475 + bfd *abfd = *slot;
5476 + struct gdb_bfd_data *gdata = bfd_usrdata (abfd);
5477 + struct ui_out *uiout = data;
5478 + struct cleanup *inner;
5480 + inner = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
5481 + ui_out_field_int (uiout, "refcount", gdata->refc);
5482 + ui_out_field_string (uiout, "addr", host_address_to_string (abfd));
5483 + ui_out_field_string (uiout, "filename", bfd_get_filename (abfd));
5484 + ui_out_text (uiout, "\n");
5485 + do_cleanups (inner);
5490 +/* Implement the 'maint info bfd' command. */
5493 +maintenance_info_bfds (char *arg, int from_tty)
5495 + struct cleanup *cleanup;
5496 + struct ui_out *uiout = current_uiout;
5498 + cleanup = make_cleanup_ui_out_table_begin_end (uiout, 3, -1, "bfds");
5499 + ui_out_table_header (uiout, 10, ui_left, "refcount", "Refcount");
5500 + ui_out_table_header (uiout, 18, ui_left, "addr", "Address");
5501 + ui_out_table_header (uiout, 40, ui_left, "filename", "Filename");
5503 + ui_out_table_body (uiout);
5504 + htab_traverse (all_bfds, print_one_bfd, uiout);
5506 + do_cleanups (cleanup);
5509 +/* -Wmissing-prototypes */
5510 +extern initialize_file_ftype _initialize_gdb_bfd;
5513 +_initialize_gdb_bfd (void)
5515 + all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
5516 + NULL, xcalloc, xfree);
5518 + add_cmd ("bfds", class_maintenance, maintenance_info_bfds, _("\
5519 +List the BFDs that are currently open."),
5520 + &maintenanceinfolist);
5522 diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
5523 new file mode 100644
5524 index 0000000..f131ba7
5528 +/* Definitions for BFD wrappers used by GDB.
5530 + Copyright (C) 2011, 2012
5531 + Free Software Foundation, Inc.
5533 + This file is part of GDB.
5535 + This program is free software; you can redistribute it and/or modify
5536 + it under the terms of the GNU General Public License as published by
5537 + the Free Software Foundation; either version 3 of the License, or
5538 + (at your option) any later version.
5540 + This program is distributed in the hope that it will be useful,
5541 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5542 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5543 + GNU General Public License for more details.
5545 + You should have received a copy of the GNU General Public License
5546 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
5551 +/* Make a copy ABFD's filename using bfd_alloc, and reassign it to the
5552 + BFD. This ensures that the BFD's filename has the same lifetime as
5553 + the BFD itself. */
5555 +void gdb_bfd_stash_filename (struct bfd *abfd);
5557 +/* Open a read-only (FOPEN_RB) BFD given arguments like bfd_fopen.
5558 + Returns NULL on error. On success, returns a new reference to the
5559 + BFD, which must be freed with gdb_bfd_unref. BFDs returned by this
5560 + call are shared among all callers opening the same file. If FD is
5561 + not -1, then after this call it is owned by BFD. */
5563 +struct bfd *gdb_bfd_open (const char *name, const char *target, int fd);
5565 +/* Increment the reference count of ABFD. It is fine for ABFD to be
5566 + NULL; in this case the function does nothing. */
5568 +void gdb_bfd_ref (struct bfd *abfd);
5570 +/* Decrement the reference count of ABFD. If this is the last
5571 + reference, ABFD will be freed. If ABFD is NULL, this function does
5574 +void gdb_bfd_unref (struct bfd *abfd);
5576 +/* Try to read or map the contents of the section SECT. If
5577 + successful, the section data is returned and *SIZE is set to the
5578 + size of the section data; this may not be the same as the size
5579 + according to bfd_get_section_size if the section was compressed.
5580 + The returned section data is associated with the BFD and will be
5581 + destroyed when the BFD is destroyed. There is no other way to free
5582 + it; for temporary uses of section data, see
5583 + bfd_malloc_and_get_section. SECT may not have relocations. This
5584 + function will throw on error. */
5586 +const gdb_byte *gdb_bfd_map_section (asection *section, bfd_size_type *size);
5590 +/* A wrapper for bfd_fopen that initializes the gdb-specific reference
5591 + count and calls gdb_bfd_stash_filename. */
5593 +bfd *gdb_bfd_fopen (const char *, const char *, const char *, int);
5595 +/* A wrapper for bfd_openr that initializes the gdb-specific reference
5596 + count and calls gdb_bfd_stash_filename. */
5598 +bfd *gdb_bfd_openr (const char *, const char *);
5600 +/* A wrapper for bfd_openw that initializes the gdb-specific reference
5601 + count and calls gdb_bfd_stash_filename. */
5603 +bfd *gdb_bfd_openw (const char *, const char *);
5605 +/* A wrapper for bfd_openr_iovec that initializes the gdb-specific
5606 + reference count and calls gdb_bfd_stash_filename. */
5608 +bfd *gdb_bfd_openr_iovec (const char *filename, const char *target,
5609 + void *(*open_func) (struct bfd *nbfd,
5610 + void *open_closure),
5611 + void *open_closure,
5612 + file_ptr (*pread_func) (struct bfd *nbfd,
5617 + int (*close_func) (struct bfd *nbfd,
5619 + int (*stat_func) (struct bfd *abfd,
5621 + struct stat *sb));
5623 +/* A wrapper for bfd_openr_next_archived_file that initializes the
5624 + gdb-specific reference count and calls gdb_bfd_stash_filename. */
5626 +bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous);
5628 +/* A wrapper for bfd_fdopenr that initializes the gdb-specific
5629 + reference count and calls gdb_bfd_stash_filename. */
5631 +bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
5633 +#endif /* GDB_BFD_H */
5634 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
5635 index 8142ab9..a2953cc 100644
5636 --- a/gdb/gdbtypes.c
5637 +++ b/gdb/gdbtypes.c
5639 #include "gdb_assert.h"
5640 #include "hashtab.h"
5641 #include "exceptions.h"
5642 +#include "observer.h"
5643 +#include "dwarf2expr.h"
5644 +#include "dwarf2loc.h"
5646 /* Initialize BADNESS constants. */
5648 @@ -141,7 +144,16 @@ static void print_bit_vector (B_TYPE *, int);
5649 static void print_arg_types (struct field *, int, int);
5650 static void dump_fn_fieldlists (struct type *, int);
5651 static void print_cplus_stuff (struct type *, int);
5652 +static LONGEST type_length_get (struct type *type, struct type *target_type,
5656 +/* The hash table holding all discardable `struct type *' references. */
5657 +static htab_t type_discardable_table;
5659 +/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE. */
5660 +static int type_discardable_age_current;
5663 /* Allocate a new OBJFILE-associated type structure and fill it
5664 with some defaults. Space for the type structure is allocated
5665 @@ -172,6 +184,43 @@ alloc_type (struct objfile *objfile)
5670 +/* Declare TYPE as discardable on next garbage collection by free_all_types.
5671 + You must call type_mark_used during each free_all_types to protect TYPE from
5672 + being deallocated. */
5675 +set_type_as_discardable (struct type *type)
5679 + gdb_assert (!TYPE_DISCARDABLE (type));
5681 + TYPE_DISCARDABLE (type) = 1;
5682 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
5684 + slot = htab_find_slot (type_discardable_table, type, INSERT);
5685 + gdb_assert (!*slot);
5690 +/* Allocate a new type like alloc_type but preserve for it the discardability
5691 + state of PARENT_TYPE. */
5693 +static struct type *
5694 +alloc_type_as_parent (struct type *parent_type)
5696 + struct type *new_type = alloc_type_copy (parent_type);
5699 + if (TYPE_DISCARDABLE (parent_type))
5700 + set_type_as_discardable (new_type);
5706 /* Allocate a new GDBARCH-associated type structure and fill it
5707 with some defaults. Space for the type structure is allocated
5709 @@ -297,7 +346,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
5711 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
5713 - ntype = alloc_type_copy (type);
5714 + ntype = alloc_type_as_parent (type);
5718 @@ -374,7 +423,7 @@ make_reference_type (struct type *type, struct type **typeptr)
5720 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
5722 - ntype = alloc_type_copy (type);
5723 + ntype = alloc_type_as_parent (type);
5727 @@ -784,6 +833,7 @@ create_range_type (struct type *result_type, struct type *index_type,
5728 TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
5729 TYPE_LOW_BOUND (result_type) = low_bound;
5730 TYPE_HIGH_BOUND (result_type) = high_bound;
5731 + TYPE_BYTE_STRIDE (result_type) = 0;
5734 TYPE_UNSIGNED (result_type) = 1;
5735 @@ -927,26 +977,31 @@ create_array_type (struct type *result_type,
5737 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
5738 TYPE_TARGET_TYPE (result_type) = element_type;
5739 - if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
5740 - low_bound = high_bound = 0;
5741 - CHECK_TYPEDEF (element_type);
5742 - /* Be careful when setting the array length. Ada arrays can be
5743 - empty arrays with the high_bound being smaller than the low_bound.
5744 - In such cases, the array length should be zero. */
5745 - if (high_bound < low_bound)
5746 - TYPE_LENGTH (result_type) = 0;
5748 - TYPE_LENGTH (result_type) =
5749 - TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
5750 TYPE_NFIELDS (result_type) = 1;
5751 TYPE_FIELDS (result_type) =
5752 (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
5753 TYPE_INDEX_TYPE (result_type) = range_type;
5754 TYPE_VPTR_FIELDNO (result_type) = -1;
5756 - /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */
5757 + /* DWARF blocks may depend on runtime information like
5758 + DW_OP_PUSH_OBJECT_ADDRESS not being available during the
5759 + CREATE_ARRAY_TYPE time. */
5760 + if (TYPE_RANGE_DATA (range_type)->low.kind != RANGE_BOUND_KIND_CONSTANT
5761 + || TYPE_RANGE_DATA (range_type)->high.kind != RANGE_BOUND_KIND_CONSTANT
5762 + || TYPE_DYNAMIC (element_type))
5763 + TYPE_LENGTH (result_type) = 0;
5766 + CHECK_TYPEDEF (element_type);
5767 + TYPE_LENGTH (result_type) = type_length_get (result_type, element_type,
5770 if (TYPE_LENGTH (result_type) == 0)
5771 - TYPE_TARGET_STUB (result_type) = 1;
5773 + /* The real size will be computed for specific instances by
5775 + TYPE_TARGET_STUB (result_type) = 1;
5780 @@ -1468,6 +1523,105 @@ stub_noname_complaint (void)
5781 complaint (&symfile_complaints, _("stub type has NULL name"));
5784 +/* Calculate the memory length of array TYPE.
5786 + TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
5787 + a performance hint. Feel free to pass NULL. Set FULL_SPAN to return the
5788 + size incl. the possible padding of the last element - it may differ from the
5789 + cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
5790 + TYPE_BYTE_STRIDE values. */
5793 +type_length_get (struct type *type, struct type *target_type, int full_span)
5795 + struct type *range_type;
5796 + LONGEST byte_stride = 0; /* `= 0' for a false GCC warning. */
5797 + LONGEST count, element_size, retval;
5799 + if (TYPE_CODE (type) != TYPE_CODE_ARRAY
5800 + && TYPE_CODE (type) != TYPE_CODE_STRING)
5801 + return TYPE_LENGTH (type);
5803 + /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
5804 + Fortran arrays. The allocated data will never be used so they can be
5806 + if (object_address_data_not_valid (type))
5809 + range_type = TYPE_INDEX_TYPE (type);
5810 + if (TYPE_LOW_BOUND_UNDEFINED (range_type)
5811 + || TYPE_HIGH_BOUND_UNDEFINED (range_type))
5813 + count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
5814 + /* It may happen for wrong DWARF annotations returning garbage data. */
5816 + warning (_("Range for type %s has invalid bounds %s..%s"),
5817 + TYPE_ERROR_NAME (type), plongest (TYPE_LOW_BOUND (range_type)),
5818 + plongest (TYPE_HIGH_BOUND (range_type)));
5819 + /* The code below does not handle count == 0 right. */
5822 + if (full_span || count > 1)
5824 + /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
5825 + force FULL_SPAN to 1. */
5826 + byte_stride = TYPE_BYTE_STRIDE (range_type);
5827 + if (byte_stride == 0)
5829 + if (target_type == NULL)
5830 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
5831 + byte_stride = type_length_get (target_type, NULL, 1);
5835 + /* For now, we conservatively take the array length to be 0 if its length
5836 + exceeds UINT_MAX. The code below assumes that for x < 0,
5837 + (ULONGEST) x == -x + ULONGEST_MAX + 1, which is technically not guaranteed
5838 + by C, but is usually true (because it would be true if x were unsigned
5839 + with its high-order bit on). It uses the fact that high_bound-low_bound is
5840 + always representable in ULONGEST and that if high_bound-low_bound+1
5841 + overflows, it overflows to 0. We must change these tests if we decide to
5842 + increase the representation of TYPE_LENGTH from unsigned int to ULONGEST.
5847 + retval = count * byte_stride;
5848 + if (count == 0 || retval / count != byte_stride || retval > UINT_MAX)
5852 + if (target_type == NULL)
5853 + target_type = check_typedef (TYPE_TARGET_TYPE (type));
5854 + element_size = type_length_get (target_type, NULL, 1);
5855 + retval = (count - 1) * byte_stride + element_size;
5856 + if (retval < element_size
5857 + || (byte_stride != 0
5858 + && (retval - element_size) / byte_stride != count - 1)
5859 + || retval > UINT_MAX)
5864 +/* Prepare TYPE after being read in by the backend. Currently this function
5865 + only propagates the TYPE_DYNAMIC flag. */
5868 +finalize_type (struct type *type)
5872 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
5873 + if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
5876 + /* FIXME: cplus_stuff is ignored here. */
5877 + if (i < TYPE_NFIELDS (type)
5878 + || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
5879 + || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
5880 + TYPE_DYNAMIC (type) = 1;
5883 /* Find the real type of TYPE. This function returns the real type,
5884 after removing all layers of typedefs, and completing opaque or stub
5885 types. Completion changes the TYPE argument, but stripping of
5886 @@ -1634,52 +1788,37 @@ check_typedef (struct type *type)
5890 - if (TYPE_TARGET_STUB (type))
5891 + /* copy_type_recursive automatically makes the resulting type containing only
5892 + constant values expected by the callers of this function. */
5893 + if (TYPE_DYNAMIC (type))
5895 + htab_t copied_types;
5897 + copied_types = create_copied_types_hash (NULL);
5898 + type = copy_type_recursive (type, copied_types);
5899 + htab_delete (copied_types);
5901 + gdb_assert (TYPE_DYNAMIC (type) == 0);
5902 + /* Force TYPE_LENGTH (type) recalculation. */
5903 + TYPE_DYNAMIC (type) = 1;
5906 + if (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type))
5908 - struct type *range_type;
5909 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
5911 + if (TYPE_DYNAMIC (type))
5912 + TYPE_TARGET_TYPE (type) = target_type;
5913 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
5915 /* Nothing we can do. */
5917 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
5918 - && TYPE_NFIELDS (type) == 1
5919 - && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
5920 - == TYPE_CODE_RANGE))
5921 + || TYPE_CODE (type) == TYPE_CODE_STRING)
5923 /* Now recompute the length of the array type, based on its
5924 - number of elements and the target type's length.
5925 - Watch out for Ada null Ada arrays where the high bound
5926 - is smaller than the low bound. */
5927 - const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
5928 - const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
5931 - if (high_bound < low_bound)
5935 - /* For now, we conservatively take the array length to be 0
5936 - if its length exceeds UINT_MAX. The code below assumes
5937 - that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
5938 - which is technically not guaranteed by C, but is usually true
5939 - (because it would be true if x were unsigned with its
5940 - high-order bit on). It uses the fact that
5941 - high_bound-low_bound is always representable in
5942 - ULONGEST and that if high_bound-low_bound+1 overflows,
5943 - it overflows to 0. We must change these tests if we
5944 - decide to increase the representation of TYPE_LENGTH
5945 - from unsigned int to ULONGEST. */
5946 - ULONGEST ulow = low_bound, uhigh = high_bound;
5947 - ULONGEST tlen = TYPE_LENGTH (target_type);
5949 - len = tlen * (uhigh - ulow + 1);
5950 - if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh
5951 - || len > UINT_MAX)
5954 - TYPE_LENGTH (type) = len;
5955 + number of elements and the target type's length. */
5956 + TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
5957 TYPE_TARGET_STUB (type) = 0;
5959 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
5960 @@ -1687,6 +1826,7 @@ check_typedef (struct type *type)
5961 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
5962 TYPE_TARGET_STUB (type) = 0;
5964 + TYPE_DYNAMIC (type) = 0;
5967 type = make_qualified_type (type, instance_flags, NULL);
5968 @@ -3345,33 +3485,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
5971 /* Allocate the hash table used by copy_type_recursive to walk
5972 - types without duplicates. We use OBJFILE's obstack, because
5973 - OBJFILE is about to be deleted. */
5974 + types without duplicates. */
5977 create_copied_types_hash (struct objfile *objfile)
5979 - return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
5980 - NULL, &objfile->objfile_obstack,
5981 - hashtab_obstack_allocate,
5982 - dummy_obstack_deallocate);
5983 + if (objfile == NULL)
5985 + /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
5986 + OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN. Table
5987 + element entries get allocated by xmalloc - so use xfree. */
5988 + return htab_create (1, type_pair_hash, type_pair_eq, xfree);
5992 + /* Use OBJFILE's obstack, because OBJFILE is about to be deleted. Table
5993 + element entries get allocated by xmalloc - so use xfree. */
5994 + return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
5995 + xfree, &objfile->objfile_obstack,
5996 + hashtab_obstack_allocate,
5997 + dummy_obstack_deallocate);
6001 -/* Recursively copy (deep copy) TYPE, if it is associated with
6002 - OBJFILE. Return a new type allocated using malloc, a saved type if
6003 - we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
6004 - not associated with OBJFILE. */
6005 +/* A helper for copy_type_recursive. This does all the work. OBJFILE is used
6006 + only for an assertion checking. */
6009 -copy_type_recursive (struct objfile *objfile,
6010 - struct type *type,
6011 - htab_t copied_types)
6012 +static struct type *
6013 +copy_type_recursive_1 (struct objfile *objfile,
6014 + struct type *type,
6015 + htab_t copied_types)
6017 struct type_pair *stored, pair;
6019 struct type *new_type;
6021 - if (! TYPE_OBJFILE_OWNED (type))
6022 + if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
6025 /* This type shouldn't be pointing to any types in other objfiles;
6026 @@ -3386,9 +3535,10 @@ copy_type_recursive (struct objfile *objfile,
6027 new_type = alloc_type_arch (get_type_arch (type));
6029 /* We must add the new type to the hash table immediately, in case
6030 - we encounter this type again during a recursive call below. */
6032 - = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
6033 + we encounter this type again during a recursive call below. Memory could
6034 + be allocated from OBJFILE in the case we will be removing OBJFILE, this
6035 + optimization is missed and xfree is called for it from COPIED_TYPES. */
6036 + stored = xmalloc (sizeof (*stored));
6038 stored->new = new_type;
6040 @@ -3399,6 +3549,21 @@ copy_type_recursive (struct objfile *objfile,
6041 TYPE_OBJFILE_OWNED (new_type) = 0;
6042 TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
6045 + /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
6046 + need to initialize it again. And even if TYPE was already discardable
6047 + NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE. */
6048 + TYPE_DISCARDABLE (new_type) = 0;
6049 + set_type_as_discardable (new_type);
6052 + /* Pre-clear the fields processed by delete_main_type. If DWARF block
6053 + evaluations below call error we would leave an unfreeable TYPE. */
6054 + TYPE_TARGET_TYPE (new_type) = NULL;
6055 + TYPE_VPTR_BASETYPE (new_type) = NULL;
6056 + TYPE_NFIELDS (new_type) = 0;
6057 + TYPE_FIELDS (new_type) = NULL;
6059 if (TYPE_NAME (type))
6060 TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
6061 if (TYPE_TAG_NAME (type))
6062 @@ -3407,12 +3572,48 @@ copy_type_recursive (struct objfile *objfile,
6063 TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
6064 TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
6066 + if (TYPE_ALLOCATED (new_type))
6068 + gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
6070 + if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
6071 + TYPE_NOT_ALLOCATED (new_type) = 1;
6072 + TYPE_ALLOCATED (new_type) = NULL;
6075 + if (TYPE_ASSOCIATED (new_type))
6077 + gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
6079 + if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
6080 + TYPE_NOT_ASSOCIATED (new_type) = 1;
6081 + TYPE_ASSOCIATED (new_type) = NULL;
6084 + if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
6085 + && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
6087 + if (TYPE_NOT_ALLOCATED (new_type)
6088 + || TYPE_NOT_ASSOCIATED (new_type))
6089 + TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
6092 + TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
6093 + TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
6094 + (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
6098 /* Copy the fields. */
6099 if (TYPE_NFIELDS (type))
6103 + /* TYPE_CODE_RANGE uses TYPE_RANGE_DATA of the union with TYPE_FIELDS. */
6104 + gdb_assert (TYPE_CODE (type) != TYPE_CODE_RANGE);
6106 nfields = TYPE_NFIELDS (type);
6107 + TYPE_NFIELDS (new_type) = nfields;
6108 TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
6109 for (i = 0; i < nfields; i++)
6111 @@ -3421,8 +3622,8 @@ copy_type_recursive (struct objfile *objfile,
6112 TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
6113 if (TYPE_FIELD_TYPE (type, i))
6114 TYPE_FIELD_TYPE (new_type, i)
6115 - = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
6117 + = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
6119 if (TYPE_FIELD_NAME (type, i))
6120 TYPE_FIELD_NAME (new_type, i) =
6121 xstrdup (TYPE_FIELD_NAME (type, i));
6122 @@ -3453,24 +3654,184 @@ copy_type_recursive (struct objfile *objfile,
6126 + /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
6127 + possibly converted. */
6128 + TYPE_DYNAMIC (new_type) = 0;
6130 /* For range types, copy the bounds information. */
6131 - if (TYPE_CODE (type) == TYPE_CODE_RANGE)
6132 + if (TYPE_CODE (new_type) == TYPE_CODE_RANGE)
6134 TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
6135 *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
6137 + switch (TYPE_RANGE_DATA (new_type)->low.kind)
6139 + case RANGE_BOUND_KIND_CONSTANT:
6141 + case RANGE_BOUND_KIND_DWARF_BLOCK:
6142 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6143 + it is expected to be made constant by CHECK_TYPEDEF.
6144 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6146 + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6147 + || ! has_stack_frames ())
6149 + /* We should set 1 for Fortran but how to find the language? */
6150 + TYPE_LOW_BOUND (new_type) = 0;
6151 + TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
6155 + TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval
6156 + (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block);
6157 + if (TYPE_LOW_BOUND (new_type) >= 0)
6158 + TYPE_UNSIGNED (new_type) = 1;
6160 + TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
6162 + case RANGE_BOUND_KIND_DWARF_LOCLIST:
6166 + /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6167 + it is expected to be made constant by CHECK_TYPEDEF.
6168 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6170 + if (! TYPE_NOT_ALLOCATED (new_type)
6171 + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
6172 + && dwarf_loclist_baton_eval
6173 + (TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.loclist,
6174 + TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.type, &addr))
6176 + TYPE_LOW_BOUND (new_type) = addr;
6177 + if (TYPE_LOW_BOUND (new_type) >= 0)
6178 + TYPE_UNSIGNED (new_type) = 1;
6182 + /* We should set 1 for Fortran but how to find the language? */
6183 + TYPE_LOW_BOUND (new_type) = 0;
6184 + TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
6186 + TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
6191 + switch (TYPE_RANGE_DATA (new_type)->high.kind)
6193 + case RANGE_BOUND_KIND_CONSTANT:
6195 + case RANGE_BOUND_KIND_DWARF_BLOCK:
6196 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6197 + it is expected to be made constant by CHECK_TYPEDEF.
6198 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6200 + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6201 + || ! has_stack_frames ())
6203 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
6204 + TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
6207 + TYPE_HIGH_BOUND (new_type) = dwarf_locexpr_baton_eval
6208 + (TYPE_RANGE_DATA (new_type)->high.u.dwarf_block);
6209 + TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
6211 + case RANGE_BOUND_KIND_DWARF_LOCLIST:
6215 + /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6216 + it is expected to be made constant by CHECK_TYPEDEF.
6217 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6219 + if (! TYPE_NOT_ALLOCATED (new_type)
6220 + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
6221 + && dwarf_loclist_baton_eval
6222 + (TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.loclist,
6223 + TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.type,
6225 + TYPE_HIGH_BOUND (new_type) = addr;
6228 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
6229 + TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
6231 + TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
6236 + switch (TYPE_RANGE_DATA (new_type)->byte_stride.kind)
6238 + case RANGE_BOUND_KIND_CONSTANT:
6240 + case RANGE_BOUND_KIND_DWARF_BLOCK:
6241 + /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
6242 + it is expected to be made constant by CHECK_TYPEDEF.
6243 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6245 + if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
6246 + || ! has_stack_frames ())
6247 + TYPE_BYTE_STRIDE (new_type) = 0;
6249 + TYPE_BYTE_STRIDE (new_type) = dwarf_locexpr_baton_eval
6250 + (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_block);
6251 + TYPE_RANGE_DATA (new_type)->byte_stride.kind
6252 + = RANGE_BOUND_KIND_CONSTANT;
6254 + case RANGE_BOUND_KIND_DWARF_LOCLIST:
6256 + CORE_ADDR addr = 0;
6258 + /* `struct dwarf2_loclist_baton' is too bound to its objfile so
6259 + it is expected to be made constant by CHECK_TYPEDEF.
6260 + TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
6262 + if (! TYPE_NOT_ALLOCATED (new_type)
6263 + && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ())
6264 + dwarf_loclist_baton_eval
6265 + (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.loclist,
6266 + TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.type,
6268 + TYPE_BYTE_STRIDE (new_type) = addr;
6269 + TYPE_RANGE_DATA (new_type)->byte_stride.kind
6270 + = RANGE_BOUND_KIND_CONSTANT;
6275 + /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound. */
6276 + if (TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type))
6278 + TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type)
6279 + + TYPE_HIGH_BOUND (new_type) - 1;
6280 + TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
6284 /* Copy pointers to other types. */
6285 if (TYPE_TARGET_TYPE (type))
6286 TYPE_TARGET_TYPE (new_type) =
6287 - copy_type_recursive (objfile,
6288 - TYPE_TARGET_TYPE (type),
6290 + copy_type_recursive_1 (objfile,
6291 + TYPE_TARGET_TYPE (type),
6293 if (TYPE_VPTR_BASETYPE (type))
6294 TYPE_VPTR_BASETYPE (new_type) =
6295 - copy_type_recursive (objfile,
6296 - TYPE_VPTR_BASETYPE (type),
6298 + copy_type_recursive_1 (objfile,
6299 + TYPE_VPTR_BASETYPE (type),
6302 + if (TYPE_CODE (new_type) == TYPE_CODE_ARRAY)
6304 + struct type *new_index_type = TYPE_INDEX_TYPE (new_type);
6306 + if (TYPE_BYTE_STRIDE (new_index_type) == 0)
6307 + TYPE_BYTE_STRIDE (new_index_type)
6308 + = TYPE_LENGTH (TYPE_TARGET_TYPE (new_type));
6311 /* Maybe copy the type_specific bits.
6313 NOTE drow/2005-12-09: We do not copy the C++-specific bits like
6314 @@ -3487,6 +3848,17 @@ copy_type_recursive (struct objfile *objfile,
6318 +/* Recursively copy (deep copy) TYPE. Return a new type allocated using
6319 + malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
6320 + or TYPE if it is not associated with OBJFILE. */
6323 +copy_type_recursive (struct type *type,
6324 + htab_t copied_types)
6326 + return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
6329 /* Make a copy of the given TYPE, except that the pointer & reference
6330 types are not preserved.
6332 @@ -3509,6 +3881,201 @@ copy_type (const struct type *type)
6337 +/* Callback type for main_type_crawl. */
6338 +typedef int (*main_type_crawl_iter) (struct type *type, void *data);
6340 +/* Iterate all main_type structures reachable through any `struct type *' from
6341 + TYPE. ITER will be called only for one type of each main_type, use
6342 + TYPE_CHAIN traversal to find all the type instances. ITER is being called
6343 + for each main_type found. ITER returns non-zero if main_type_crawl should
6344 + depth-first enter the specific type. ITER must provide some detection for
6345 + reentering the same main_type as this function would otherwise endlessly
6349 +main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
6351 + struct type *type_iter;
6357 + gdb_assert (TYPE_OBJFILE (type) == NULL);
6359 + /* `struct cplus_struct_type' handling is unsupported by this function. */
6360 + gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
6361 + && TYPE_CODE (type) != TYPE_CODE_UNION)
6362 + || !HAVE_CPLUS_STRUCT (type));
6364 + if (!(*iter) (type, data))
6367 + /* Iterate all the type instances of this main_type. */
6371 + gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
6373 + main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
6374 + main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
6376 + type_iter = TYPE_CHAIN (type_iter);
6378 + while (type_iter != type);
6380 + for (i = 0; i < TYPE_NFIELDS (type); i++)
6381 + main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
6383 + main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
6384 + main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
6387 +/* A helper for delete_type which deletes a main_type and the things to which
6388 + it refers. TYPE is a type whose main_type we wish to destroy. */
6391 +delete_main_type (struct type *type)
6395 + gdb_assert (TYPE_DISCARDABLE (type));
6396 + gdb_assert (TYPE_OBJFILE (type) == NULL);
6398 + xfree (TYPE_NAME (type));
6399 + xfree (TYPE_TAG_NAME (type));
6401 + for (i = 0; i < TYPE_NFIELDS (type); ++i)
6403 + xfree (TYPE_FIELD_NAME (type, i));
6405 + if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
6406 + xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
6408 + xfree (TYPE_FIELDS (type));
6410 + gdb_assert (!HAVE_CPLUS_STRUCT (type));
6412 + xfree (TYPE_MAIN_TYPE (type));
6415 +/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
6416 + main_type. TYPE must be a reclaimable type - neither permanent nor objfile
6420 +delete_type_chain (struct type *type)
6422 + struct type *type_iter, *type_iter_to_free;
6424 + gdb_assert (TYPE_DISCARDABLE (type));
6425 + gdb_assert (TYPE_OBJFILE (type) == NULL);
6427 + delete_main_type (type);
6432 + type_iter_to_free = type_iter;
6433 + type_iter = TYPE_CHAIN (type_iter);
6434 + xfree (type_iter_to_free);
6436 + while (type_iter != type);
6439 +/* Hash function for type_discardable_table. */
6442 +type_discardable_hash (const void *p)
6444 + const struct type *type = p;
6446 + return htab_hash_pointer (TYPE_MAIN_TYPE (type));
6449 +/* Equality function for type_discardable_table. */
6452 +type_discardable_equal (const void *a, const void *b)
6454 + const struct type *left = a;
6455 + const struct type *right = b;
6457 + return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
6460 +/* A helper for type_mark_used. */
6463 +type_mark_used_crawl (struct type *type, void *unused)
6465 + if (!TYPE_DISCARDABLE (type))
6468 + if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
6471 + TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
6473 + /* Continue the traversal. */
6477 +/* Mark TYPE and its connected types as used in this free_all_types pass. */
6480 +type_mark_used (struct type *type)
6485 + if (!TYPE_DISCARDABLE (type))
6488 + main_type_crawl (type, type_mark_used_crawl, NULL);
6491 +/* A traverse callback for type_discardable_table which removes any
6492 + type_discardable whose reference count is now zero (unused link). */
6495 +type_discardable_remove (void **slot, void *unused)
6497 + struct type *type = *slot;
6499 + gdb_assert (TYPE_DISCARDABLE (type));
6501 + if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
6503 + delete_type_chain (type);
6505 + htab_clear_slot (type_discardable_table, slot);
6511 +/* Free all the reclaimable types that have been allocated and that have
6512 + currently zero reference counter.
6514 + This function is called after each command, successful or not. Use this
6515 + cleanup only in the GDB idle state as GDB only marks those types used by
6516 + globally tracked objects (with no autovariable references tracking). */
6519 +free_all_types (void)
6521 + /* Mark a new pass. As GDB checks all the entries were visited after each
6522 + pass there cannot be any stale entries already containing the changed
6524 + type_discardable_age_current ^= 1;
6526 + observer_notify_mark_used ();
6528 + htab_traverse (type_discardable_table, type_discardable_remove, NULL);
6532 /* Helper functions to initialize architecture-specific types. */
6534 @@ -4042,6 +4609,13 @@ void
6535 _initialize_gdbtypes (void)
6537 gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
6540 + type_discardable_table = htab_create_alloc (20, type_discardable_hash,
6541 + type_discardable_equal, NULL,
6545 objfile_type_data = register_objfile_data ();
6547 add_setshow_zinteger_cmd ("overload", no_class, &overload_debug,
6548 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
6549 index 17bfbc5..72e9cc5 100644
6550 --- a/gdb/gdbtypes.h
6551 +++ b/gdb/gdbtypes.h
6552 @@ -228,6 +228,11 @@ enum type_instance_flag_value
6554 #define TYPE_TARGET_STUB(t) (TYPE_MAIN_TYPE (t)->flag_target_stub)
6556 +/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
6559 +#define TYPE_DYNAMIC(t) (TYPE_MAIN_TYPE (t)->flag_dynamic)
6561 /* Static type. If this is set, the corresponding type had
6563 Note: This may be unnecessary, since static data members
6564 @@ -311,6 +316,50 @@ enum type_instance_flag_value
6566 #define TYPE_FLAG_ENUM(t) (TYPE_MAIN_TYPE (t)->flag_flag_enum)
6569 +/* Define this type as being reclaimable during free_all_types. Type is
6570 + required to be have TYPE_OBJFILE set to NULL. Setting this flag requires
6571 + initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable. */
6573 +#define TYPE_DISCARDABLE(t) (TYPE_MAIN_TYPE (t)->flag_discardable)
6575 +/* Marker this type has been visited by the type_mark_used by this
6576 + mark-and-sweep types garbage collecting pass. Current pass is represented
6577 + by TYPE_DISCARDABLE_AGE_CURRENT. */
6579 +#define TYPE_DISCARDABLE_AGE(t) (TYPE_MAIN_TYPE (t)->flag_discardable_age)
6582 +/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)? */
6584 +#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
6585 + (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
6587 +/* Not allocated. TYPE_ALLOCATED(t) must be NULL in such case. If this flag
6588 + is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated. If this
6589 + flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
6590 + determines the actual allocation state. */
6592 +#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
6594 +/* Not associated. TYPE_ASSOCIATED(t) must be NULL in such case. If this flag
6595 + is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated. If
6596 + this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
6597 + determines the actual association state. */
6599 +#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
6601 +/* Address of the actual data as for DW_AT_data_location. Its dwarf block must
6602 + not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
6603 + false. If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
6604 + is the actual data address value. If unset and
6605 + TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
6606 + value_raw_address. If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
6607 + then its DWARF block determines the actual data address. */
6609 +#define TYPE_DATA_LOCATION_IS_ADDR(t) \
6610 + (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
6612 /* Constant type. If this is set, the corresponding type has a
6615 @@ -421,6 +470,15 @@ struct main_type
6616 /* True if this type was declared with "class" rather than
6618 unsigned int flag_declared_class : 1;
6620 + unsigned int flag_discardable : 1;
6621 + unsigned int flag_discardable_age : 1;
6623 + unsigned int flag_dynamic : 1;
6624 + unsigned int flag_range_high_bound_is_count : 1;
6625 + unsigned int flag_not_allocated : 1;
6626 + unsigned int flag_not_associated : 1;
6627 + unsigned int flag_data_location_is_addr : 1;
6629 /* True if this is an enum type with disjoint values. This affects
6630 how the enum is printed. */
6631 @@ -501,6 +559,20 @@ struct main_type
6633 struct type *target_type;
6635 + /* For DW_AT_data_location. */
6638 + struct dwarf2_locexpr_baton *dwarf_block;
6643 + /* For DW_AT_allocated. */
6644 + struct dwarf2_locexpr_baton *allocated;
6646 + /* For DW_AT_associated. */
6647 + struct dwarf2_locexpr_baton *associated;
6649 /* For structure and union types, a description of each field.
6650 For set and pascal array types, there is one "field",
6651 whose type is the domain type of the set or array.
6652 @@ -583,13 +655,34 @@ struct main_type
6661 + struct dwarf2_locexpr_baton *dwarf_block;
6664 + struct dwarf2_loclist_baton *loclist;
6665 + struct type *type;
6670 + enum range_bound_kind
6672 + RANGE_BOUND_KIND_CONSTANT,
6673 + RANGE_BOUND_KIND_DWARF_BLOCK,
6674 + RANGE_BOUND_KIND_DWARF_LOCLIST
6678 /* Low bound of range. */
6683 /* High bound of range. */
6687 + /* Byte stride of range. */
6690 /* Flags indicating whether the values of low and high are
6691 valid. When true, the respective range value is
6692 @@ -1054,9 +1147,9 @@ extern void allocate_gnat_aux_type (struct type *);
6693 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
6694 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
6695 #define TYPE_CHAIN(thistype) (thistype)->chain
6696 -/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
6697 - But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
6698 - so you only have to call check_typedef once. Since allocate_value
6699 +/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
6700 + check_typedef. But check_typedef does set the TYPE_LENGTH of the TYPEDEF
6701 + type, so you only have to call check_typedef once. Since allocate_value
6702 calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
6703 #define TYPE_LENGTH(thistype) (thistype)->length
6704 /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
6705 @@ -1064,11 +1157,16 @@ extern void allocate_gnat_aux_type (struct type *);
6706 #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
6707 #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
6708 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
6709 +#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
6710 +#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
6711 +#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
6712 +#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
6714 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
6715 #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
6716 -#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
6717 -#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
6718 +#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low.u.constant
6719 +#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high.u.constant
6720 +#define TYPE_BYTE_STRIDE(range_type) TYPE_RANGE_DATA(range_type)->byte_stride.u.constant
6721 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
6722 TYPE_RANGE_DATA(range_type)->low_undefined
6723 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
6724 @@ -1085,7 +1183,14 @@ extern void allocate_gnat_aux_type (struct type *);
6725 (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
6727 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
6728 - (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
6729 + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
6731 +/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
6732 + element size if no specific stride value is known. */
6733 +#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype) \
6734 + (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0 \
6735 + ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype)) \
6736 + : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
6740 @@ -1531,6 +1636,18 @@ extern struct type *create_array_type (struct type *, struct type *,
6742 extern struct type *lookup_array_range_type (struct type *, int, int);
6744 +extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
6747 +extern int type_range_high_bound_internal (struct type *range_type);
6749 +extern int type_range_count_bound_internal (struct type *range_type);
6751 +extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
6752 + struct type *element_type);
6754 +extern void finalize_type (struct type *type);
6756 extern struct type *create_string_type (struct type *, struct type *,
6758 extern struct type *lookup_string_range_type (struct type *, int, int);
6759 @@ -1576,6 +1693,10 @@ extern int is_public_ancestor (struct type *, struct type *);
6761 extern int is_unique_ancestor (struct type *, struct value *);
6764 +extern void type_mark_used (struct type *type);
6767 /* Overload resolution */
6769 #define LENGTH_MATCH(bv) ((bv)->rank[0])
6770 @@ -1651,10 +1772,13 @@ extern void maintenance_print_type (char *, int);
6772 extern htab_t create_copied_types_hash (struct objfile *objfile);
6774 -extern struct type *copy_type_recursive (struct objfile *objfile,
6775 - struct type *type,
6776 +extern struct type *copy_type_recursive (struct type *type,
6777 htab_t copied_types);
6779 extern struct type *copy_type (const struct type *type);
6782 +extern void free_all_types (void);
6785 #endif /* GDBTYPES_H */
6786 diff --git a/gdb/jit.c b/gdb/jit.c
6787 index 568d17b..cdd9f49 100644
6791 #include "gdb-dlfcn.h"
6792 #include "gdb_stat.h"
6793 #include "exceptions.h"
6794 +#include "gdb_bfd.h"
6796 static const char *jit_reader_dir = NULL;
6798 @@ -132,17 +133,16 @@ mem_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
6800 bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size, char *target)
6802 - const char *filename = xstrdup ("<in-memory>");
6803 struct target_buffer *buffer = xmalloc (sizeof (struct target_buffer));
6805 buffer->base = addr;
6806 buffer->size = size;
6807 - return bfd_openr_iovec (filename, target,
6808 - mem_bfd_iovec_open,
6810 - mem_bfd_iovec_pread,
6811 - mem_bfd_iovec_close,
6812 - mem_bfd_iovec_stat);
6813 + return gdb_bfd_openr_iovec ("<in-memory>", target,
6814 + mem_bfd_iovec_open,
6816 + mem_bfd_iovec_pread,
6817 + mem_bfd_iovec_close,
6818 + mem_bfd_iovec_stat);
6821 /* One reader that has been loaded successfully, and can potentially be used to
6822 @@ -868,7 +868,7 @@ jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
6824 printf_unfiltered (_("\
6825 JITed symbol file is not an object file, ignoring it.\n"));
6827 + gdb_bfd_unref (nbfd);
6831 @@ -896,7 +896,8 @@ JITed symbol file is not an object file, ignoring it.\n"));
6835 - /* This call takes ownership of NBFD. It does not take ownership of SAI. */
6836 + /* This call does not take ownership of SAI. */
6837 + make_cleanup_bfd_unref (nbfd);
6838 objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);
6840 do_cleanups (old_cleanups);
6841 diff --git a/gdb/m32r-rom.c b/gdb/m32r-rom.c
6842 index 76e4bf1..9a2f5aa 100644
6843 --- a/gdb/m32r-rom.c
6844 +++ b/gdb/m32r-rom.c
6846 #include "inferior.h"
6848 #include "regcache.h"
6849 +#include "gdb_bfd.h"
6852 * All this stuff just to get my host computer's IP address!
6853 @@ -124,13 +125,15 @@ m32r_load (char *filename, int from_tty)
6855 unsigned int data_count = 0;
6856 struct timeval start_time, end_time;
6857 + struct cleanup *cleanup;
6859 if (filename == NULL || filename[0] == 0)
6860 filename = get_exec_file (1);
6862 - abfd = bfd_openr (filename, 0);
6863 + abfd = gdb_bfd_openr (filename, 0);
6865 error (_("Unable to open file %s."), filename);
6866 + cleanup = make_cleanup_bfd_unref (abfd);
6867 if (bfd_check_format (abfd, bfd_object) == 0)
6868 error (_("File is not an object file."));
6869 gettimeofday (&start_time, NULL);
6870 @@ -188,6 +191,7 @@ m32r_load (char *filename, int from_tty)
6873 clear_symtab_users (0);
6874 + do_cleanups (cleanup);
6878 @@ -434,6 +438,7 @@ m32r_upload_command (char *args, int from_tty)
6880 struct hostent *hostent;
6881 struct in_addr inet_addr;
6882 + struct cleanup *cleanup;
6884 /* First check to see if there's an ethernet port! */
6885 monitor_printf ("ust\r");
6886 @@ -524,7 +529,8 @@ m32r_upload_command (char *args, int from_tty)
6887 printf_filtered (" -- Ethernet load complete.\n");
6889 gettimeofday (&end_time, NULL);
6890 - abfd = bfd_openr (args, 0);
6891 + abfd = gdb_bfd_openr (args, 0);
6892 + cleanup = make_cleanup_bfd_unref (abfd);
6894 { /* Download is done -- print section statistics. */
6895 if (bfd_check_format (abfd, bfd_object) == 0)
6896 @@ -565,6 +571,7 @@ m32r_upload_command (char *args, int from_tty)
6899 clear_symtab_users (0);
6900 + do_cleanups (cleanup);
6903 /* Provide a prototype to silence -Wmissing-prototypes. */
6904 diff --git a/gdb/machoread.c b/gdb/machoread.c
6905 index 22530ab..0d7578a 100644
6906 --- a/gdb/machoread.c
6907 +++ b/gdb/machoread.c
6908 @@ -454,6 +454,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
6910 struct bfd_hash_table table;
6912 + struct cleanup *cleanup;
6914 /* Per section flag to mark which section have been rebased. */
6915 unsigned char *sections_rebased;
6916 @@ -466,14 +467,14 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
6918 warning (_("`%s': can't read symbols: %s."), oso->name,
6919 bfd_errmsg (bfd_get_error ()));
6921 + gdb_bfd_unref (abfd);
6925 if (abfd->my_archive == NULL && oso->mtime != bfd_get_mtime (abfd))
6927 warning (_("`%s': file time stamp mismatch."), oso->name);
6929 + gdb_bfd_unref (abfd);
6933 @@ -482,7 +483,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
6936 warning (_("`%s': can't create hash table"), oso->name);
6938 + gdb_bfd_unref (abfd);
6942 @@ -629,18 +630,15 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
6944 bfd_hash_table_free (&table);
6946 - /* Make sure that the filename was malloc'ed. The current filename comes
6947 - either from an OSO symbol name or from an archive name. Memory for both
6948 - is not managed by gdb. */
6949 - abfd->filename = xstrdup (abfd->filename);
6951 /* We need to clear SYMFILE_MAINLINE to avoid interractive question
6952 from symfile.c:symbol_file_add_with_addrs_or_offsets. */
6953 + cleanup = make_cleanup_bfd_unref (abfd);
6954 symbol_file_add_from_bfd
6955 (abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
6956 main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
6957 | OBJF_READNOW | OBJF_USERLOADED),
6959 + do_cleanups (cleanup);
6962 /* Read symbols from the vector of oso files. */
6963 @@ -651,6 +649,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
6967 + struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
6971 @@ -677,6 +676,8 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
6972 memcpy (archive_name, oso->name, pfx_len);
6973 archive_name[pfx_len] = '\0';
6975 + make_cleanup (xfree, archive_name);
6977 /* Compute number of oso for this archive. */
6979 VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++)
6980 @@ -686,7 +687,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
6983 /* Open the archive and check the format. */
6984 - archive_bfd = bfd_openr (archive_name, gnutarget);
6985 + archive_bfd = gdb_bfd_openr (archive_name, gnutarget);
6986 if (archive_bfd == NULL)
6988 warning (_("Could not open OSO archive file \"%s\""),
6989 @@ -698,17 +699,18 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
6991 warning (_("OSO archive file \"%s\" not an archive."),
6993 - bfd_close (archive_bfd);
6994 + gdb_bfd_unref (archive_bfd);
6998 - member_bfd = bfd_openr_next_archived_file (archive_bfd, NULL);
7000 + member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd, NULL);
7002 if (member_bfd == NULL)
7004 warning (_("Could not read archive members out of "
7005 "OSO archive \"%s\""), archive_name);
7006 - bfd_close (archive_bfd);
7007 + gdb_bfd_unref (archive_bfd);
7011 @@ -738,12 +740,12 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
7015 - member_bfd = bfd_openr_next_archived_file
7016 - (archive_bfd, member_bfd);
7017 + member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd,
7020 /* Free previous member if not referenced by an oso. */
7023 + gdb_bfd_unref (prev);
7025 for (ix2 = ix; ix2 < last_ix; ix2++)
7027 @@ -759,7 +761,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
7031 - abfd = bfd_openr (oso->name, gnutarget);
7032 + abfd = gdb_bfd_openr (oso->name, gnutarget);
7034 warning (_("`%s': can't open to read symbols: %s."), oso->name,
7035 bfd_errmsg (bfd_get_error ()));
7036 @@ -771,6 +773,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
7039 VEC_free (oso_el, vec);
7040 + do_cleanups (cleanup);
7043 /* DSYM (debug symbols) files contain the debug info of an executable.
7044 @@ -808,20 +811,17 @@ macho_check_dsym (struct objfile *objfile)
7045 warning (_("can't find UUID in %s"), objfile->name);
7048 - dsym_filename = xstrdup (dsym_filename);
7049 - dsym_bfd = bfd_openr (dsym_filename, gnutarget);
7050 + dsym_bfd = gdb_bfd_openr (dsym_filename, gnutarget);
7051 if (dsym_bfd == NULL)
7053 warning (_("can't open dsym file %s"), dsym_filename);
7054 - xfree (dsym_filename);
7058 if (!bfd_check_format (dsym_bfd, bfd_object))
7060 - bfd_close (dsym_bfd);
7061 + gdb_bfd_unref (dsym_bfd);
7062 warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
7063 - xfree (dsym_filename);
7067 @@ -829,16 +829,14 @@ macho_check_dsym (struct objfile *objfile)
7068 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
7070 warning (_("can't find UUID in %s"), dsym_filename);
7071 - bfd_close (dsym_bfd);
7072 - xfree (dsym_filename);
7073 + gdb_bfd_unref (dsym_bfd);
7076 if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
7077 sizeof (main_uuid->command.uuid.uuid)))
7079 warning (_("dsym file UUID doesn't match the one in %s"), objfile->name);
7080 - bfd_close (dsym_bfd);
7081 - xfree (dsym_filename);
7082 + gdb_bfd_unref (dsym_bfd);
7086 @@ -902,6 +900,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
7089 struct bfd_section *asect, *dsect;
7090 + struct cleanup *cleanup;
7092 if (mach_o_debug_level > 0)
7093 printf_unfiltered (_("dsym file found\n"));
7094 @@ -922,7 +921,9 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
7097 /* Add the dsym file as a separate file. */
7098 + cleanup = make_cleanup_bfd_unref (dsym_bfd);
7099 symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
7100 + do_cleanups (cleanup);
7102 /* Don't try to read dwarf2 from main file or shared libraries. */
7104 diff --git a/gdb/main.c b/gdb/main.c
7105 index d075694..e4da3f1 100644
7110 #include "interps.h"
7112 +#include "python/python.h"
7114 #include "cli/cli-cmds.h"
7115 #include "python/python.h"
7116 @@ -283,6 +284,8 @@ captured_main (void *data)
7118 char *ttyarg = NULL;
7120 + int python_script = 0;
7122 /* These are static so that we can take their address in an
7124 static int print_help;
7125 @@ -471,10 +474,14 @@ captured_main (void *data)
7126 {"args", no_argument, &set_args, 1},
7127 {"l", required_argument, 0, 'l'},
7128 {"return-child-result", no_argument, &return_child_result, 1},
7130 + {"python", no_argument, 0, 'P'},
7131 + {"P", no_argument, 0, 'P'},
7133 {0, no_argument, 0, 0}
7137 + while (!python_script)
7141 @@ -492,6 +499,9 @@ captured_main (void *data)
7143 /* Long option that just sets a flag. */
7146 + python_script = 1;
7151 @@ -699,7 +709,31 @@ captured_main (void *data)
7153 /* Now that gdb_init has created the initial inferior, we're in
7154 position to set args for that inferior. */
7156 + if (python_script)
7158 + /* The first argument is a python script to evaluate, and
7159 + subsequent arguments are passed to the script for
7160 + processing there. */
7161 + if (optind >= argc)
7163 + fprintf_unfiltered (gdb_stderr,
7164 + _("%s: Python script file name required\n"),
7169 + /* FIXME: should handle inferior I/O intelligently here.
7170 + E.g., should be possible to run gdb in pipeline and have
7171 + Python (and gdb) output go to stderr or file; and if a
7172 + prompt is needed, open the tty. */
7174 + /* FIXME: should read .gdbinit if, and only if, a prompt is
7175 + requested by the script. Though... maybe this is not
7177 + /* FIXME: likewise, reading in history. */
7178 + inhibit_gdbinit = 1;
7180 + else if (set_args)
7182 /* The remaining options are the command-line options for the
7183 inferior. The first one is the sym/exec file, and the rest
7184 @@ -979,7 +1013,8 @@ captured_main (void *data)
7186 /* Read in the old history after all the command files have been
7189 + if (!python_script)
7194 @@ -990,13 +1025,25 @@ captured_main (void *data)
7195 /* Show time and/or space usage. */
7196 do_cleanups (pre_stat_chain);
7198 - /* NOTE: cagney/1999-11-07: There is probably no reason for not
7199 - moving this loop and the code found in captured_command_loop()
7200 - into the command_loop() proper. The main thing holding back that
7201 - change - SET_TOP_LEVEL() - has been eliminated. */
7204 + if (python_script)
7206 - catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
7207 + extern int pagination_enabled;
7208 + pagination_enabled = 0;
7209 + run_python_script (argc - optind, &argv[optind]);
7215 + /* NOTE: cagney/1999-11-07: There is probably no reason for not
7216 + moving this loop and the code found in captured_command_loop()
7217 + into the command_loop() proper. The main thing holding back that
7218 + change - SET_TOP_LEVEL() - has been eliminated. */
7221 + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
7224 /* No exit -- exit is through quit_command. */
7226 @@ -1028,7 +1075,12 @@ print_gdb_help (struct ui_file *stream)
7227 fputs_unfiltered (_("\
7228 This is the GNU debugger. Usage:\n\n\
7229 gdb [options] [executable-file [core-file or process-id]]\n\
7230 - gdb [options] --args executable-file [inferior-arguments ...]\n\n\
7231 + gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
7233 + fputs_unfiltered (_("\
7234 + gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
7236 + fputs_unfiltered (_("\n\
7239 fputs_unfiltered (_("\
7240 @@ -1068,7 +1120,13 @@ Options:\n\n\
7241 --nw Do not use a window interface.\n\
7242 --nx Do not read "), stream);
7243 fputs_unfiltered (gdbinit, stream);
7244 - fputs_unfiltered (_(" file.\n\
7245 + fputs_unfiltered (_(" file.\n"), stream);
7247 + fputs_unfiltered (_("\
7248 + --python, -P Following argument is Python script file; remaining\n\
7249 + arguments are passed to script.\n"), stream);
7251 + fputs_unfiltered (_("\
7252 --quiet Do not print version number on startup.\n\
7253 --readnow Fully read symbol files on first access.\n\
7255 diff --git a/gdb/objfiles.c b/gdb/objfiles.c
7256 index f5e5c75..411618f 100644
7257 --- a/gdb/objfiles.c
7258 +++ b/gdb/objfiles.c
7260 #include "complaints.h"
7261 #include "psymtab.h"
7263 +#include "gdb_bfd.h"
7265 /* Prototypes for local functions */
7267 @@ -195,7 +196,8 @@ allocate_objfile (bfd *abfd, int flags)
7268 that any data that is reference is saved in the per-objfile data
7271 - objfile->obfd = gdb_bfd_ref (abfd);
7272 + objfile->obfd = abfd;
7273 + gdb_bfd_ref (abfd);
7276 /* Look up the gdbarch associated with the BFD. */
7277 @@ -1456,75 +1458,6 @@ objfiles_changed (void)
7278 get_objfile_pspace_data (current_program_space)->objfiles_changed_p = 1;
7281 -/* Close ABFD, and warn if that fails. */
7284 -gdb_bfd_close_or_warn (struct bfd *abfd)
7287 - char *name = bfd_get_filename (abfd);
7289 - ret = bfd_close (abfd);
7292 - warning (_("cannot close \"%s\": %s"),
7293 - name, bfd_errmsg (bfd_get_error ()));
7298 -/* Add reference to ABFD. Returns ABFD. */
7300 -gdb_bfd_ref (struct bfd *abfd)
7307 - p_refcount = bfd_usrdata (abfd);
7309 - if (p_refcount != NULL)
7315 - p_refcount = xmalloc (sizeof (*p_refcount));
7317 - bfd_usrdata (abfd) = p_refcount;
7322 -/* Unreference and possibly close ABFD. */
7324 -gdb_bfd_unref (struct bfd *abfd)
7332 - p_refcount = bfd_usrdata (abfd);
7334 - /* Valid range for p_refcount: a pointer to int counter, which has a
7335 - value of 1 (single owner) or 2 (shared). */
7336 - gdb_assert (*p_refcount == 1 || *p_refcount == 2);
7339 - if (*p_refcount > 0)
7342 - xfree (p_refcount);
7343 - bfd_usrdata (abfd) = NULL; /* Paranoia. */
7345 - name = bfd_get_filename (abfd);
7346 - gdb_bfd_close_or_warn (abfd);
7350 /* The default implementation for the "iterate_over_objfiles_in_search_order"
7351 gdbarch method. It is equivalent to use the ALL_OBJFILES macro,
7352 searching the objfiles in the order they are stored internally,
7353 diff --git a/gdb/objfiles.h b/gdb/objfiles.h
7354 index 01c3aea..0df5798 100644
7355 --- a/gdb/objfiles.h
7356 +++ b/gdb/objfiles.h
7357 @@ -522,10 +522,6 @@ extern void set_objfile_data (struct objfile *objfile,
7358 extern void *objfile_data (struct objfile *objfile,
7359 const struct objfile_data *data);
7361 -extern struct bfd *gdb_bfd_ref (struct bfd *abfd);
7362 -extern void gdb_bfd_unref (struct bfd *abfd);
7363 -extern int gdb_bfd_close_or_warn (struct bfd *abfd);
7365 extern void default_iterate_over_objfiles_in_search_order
7366 (struct gdbarch *gdbarch,
7367 iterate_over_objfiles_in_search_order_cb_ftype *cb,
7368 diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
7369 index b8434ed..98a076d 100644
7370 --- a/gdb/p-valprint.c
7371 +++ b/gdb/p-valprint.c
7374 #include "cp-support.h"
7375 #include "exceptions.h"
7376 +#include "dwarf2loc.h"
7379 /* Decorations for Pascal. */
7380 @@ -74,8 +75,31 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
7381 struct type *char_type;
7384 + struct cleanup *back_to;
7385 + struct type *saved_type = type;
7386 + CORE_ADDR saved_address = address;
7388 + back_to = make_cleanup (null_cleanup, 0);
7389 + address += embedded_offset;
7390 + type = object_address_get_data (type, &address);
7393 + fputs_filtered (object_address_data_not_valid (saved_type), stream);
7394 + gdb_flush (stream);
7395 + do_cleanups (back_to);
7398 + if (address != saved_address + embedded_offset)
7400 + size_t length = TYPE_LENGTH (type);
7402 - CHECK_TYPEDEF (type);
7403 + valaddr = xmalloc (length);
7404 + make_cleanup (xfree, (gdb_byte *) valaddr);
7405 + read_memory (address, (gdb_byte *) valaddr, length);
7406 + embedded_offset = 0;
7409 + address -= embedded_offset;
7410 switch (TYPE_CODE (type))
7412 case TYPE_CODE_ARRAY:
7413 @@ -131,8 +155,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
7417 - val_print_array_elements (type, valaddr, embedded_offset,
7418 - address, stream, recurse,
7419 + val_print_array_elements (saved_type, valaddr, embedded_offset,
7420 + saved_address, stream, recurse,
7421 original_value, options, i);
7422 fprintf_filtered (stream, "}");
7424 @@ -170,6 +194,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
7426 /* Try to print what function it points to. */
7427 print_address_demangle (options, gdbarch, addr, stream, demangle);
7428 + do_cleanups (back_to);
7432 @@ -271,6 +296,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
7436 + do_cleanups (back_to);
7440 @@ -421,6 +447,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
7444 + do_cleanups (back_to);
7448 diff --git a/gdb/parse.c b/gdb/parse.c
7449 index 529c517..6326a01 100644
7452 @@ -1708,6 +1708,7 @@ parser_fprintf (FILE *x, const char *y, ...)
7455 operator_check_standard (struct expression *exp, int pos,
7456 + int (*type_func) (struct type *type, void *data),
7457 int (*objfile_func) (struct objfile *objfile,
7460 @@ -1749,7 +1750,7 @@ operator_check_standard (struct expression *exp, int pos,
7461 struct type *type = elts[pos + 2 + arg].type;
7462 struct objfile *objfile = TYPE_OBJFILE (type);
7464 - if (objfile && (*objfile_func) (objfile, data))
7465 + if (objfile && objfile_func && (*objfile_func) (objfile, data))
7469 @@ -1767,7 +1768,8 @@ operator_check_standard (struct expression *exp, int pos,
7471 /* Check objfile where the variable itself is placed.
7472 SYMBOL_OBJ_SECTION (symbol) may be NULL. */
7473 - if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
7475 + && (*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
7478 /* Check objfile where is placed the code touching the variable. */
7479 @@ -1780,24 +1782,27 @@ operator_check_standard (struct expression *exp, int pos,
7481 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
7483 - if (type && TYPE_OBJFILE (type)
7484 + if (type && type_func && (*type_func) (type, data))
7486 + if (type && TYPE_OBJFILE (type) && objfile_func
7487 && (*objfile_func) (TYPE_OBJFILE (type), data))
7489 - if (objfile && (*objfile_func) (objfile, data))
7490 + if (objfile && objfile_func && (*objfile_func) (objfile, data))
7496 -/* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP.
7497 - The functions are never called with NULL OBJFILE. Functions get passed an
7498 - arbitrary caller supplied DATA pointer. If any of the functions returns
7499 - non-zero value then (any other) non-zero value is immediately returned to
7500 - the caller. Otherwise zero is returned after iterating through whole EXP.
7502 +/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
7503 + referenced by EXP. The functions are never called with NULL TYPE or NULL
7504 + OBJFILE. Functions get passed an arbitrary caller supplied DATA pointer.
7505 + If any of the functions returns non-zero value then (any other) non-zero
7506 + value is immediately returned to the caller. Otherwise zero is returned
7507 + after iterating through whole EXP. */
7510 exp_iterate (struct expression *exp,
7511 + int (*type_func) (struct type *type, void *data),
7512 int (*objfile_func) (struct objfile *objfile, void *data),
7515 @@ -1812,7 +1817,9 @@ exp_iterate (struct expression *exp,
7517 pos = endpos - oplen;
7518 if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
7519 - objfile_func, data))
7526 @@ -1843,8 +1850,29 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
7528 gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
7530 - return exp_iterate (exp, exp_uses_objfile_iter, objfile);
7531 + return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
7534 +/* Helper for exp_types_mark_used. */
7538 +exp_types_mark_used_iter (struct type *type, void *unused)
7540 + type_mark_used (type);
7542 + /* Continue the traversal. */
7546 +/* Call type_mark_used for any type contained in EXP. */
7549 +exp_types_mark_used (struct expression *exp)
7551 + exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
7556 _initialize_parse (void)
7557 diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
7558 index 86f3bdf..f908a61 100644
7559 --- a/gdb/parser-defs.h
7560 +++ b/gdb/parser-defs.h
7561 @@ -245,6 +245,8 @@ extern void operator_length_standard (const struct expression *, int, int *,
7564 extern int operator_check_standard (struct expression *exp, int pos,
7565 + int (*type_func) (struct type *type,
7568 (struct objfile *objfile, void *data),
7570 @@ -331,6 +333,7 @@ struct exp_descriptor
7571 value should be immediately returned to the caller. Otherwise zero
7572 should be returned. */
7573 int (*operator_check) (struct expression *exp, int pos,
7574 + int (*type_func) (struct type *type, void *data),
7575 int (*objfile_func) (struct objfile *objfile,
7578 @@ -369,4 +372,10 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
7580 extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
7582 +extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
7585 +extern void exp_types_mark_used (struct expression *exp);
7588 #endif /* PARSER_DEFS_H */
7589 diff --git a/gdb/printcmd.c b/gdb/printcmd.c
7590 index d5b5b63..4bc2b5b 100644
7591 --- a/gdb/printcmd.c
7592 +++ b/gdb/printcmd.c
7594 #include "arch-utils.h"
7595 #include "cli/cli-utils.h"
7597 +#include "dwarf2loc.h"
7600 #include "tui/tui.h" /* For tui_active et al. */
7601 @@ -968,6 +969,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
7603 val = access_value_history (0);
7605 + /* Do not try to OBJECT_ADDRESS_SET here anything. We are interested in the
7606 + source variable base addresses as found by READ_VAR_VALUE. The value here
7607 + can be already a calculated expression address inappropriate for
7608 + DW_OP_push_object_address. */
7610 if (voidprint || (val && value_type (val) &&
7611 TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
7613 @@ -1056,6 +1062,9 @@ output_command (char *exp, int from_tty)
7615 val = evaluate_expression (expr);
7617 + if (VALUE_LVAL (val) == lval_memory)
7618 + object_address_set (value_raw_address (val));
7620 annotate_value_begin (value_type (val));
7622 get_formatted_print_options (&opts, format);
7623 @@ -1485,6 +1494,24 @@ x_command (char *exp, int from_tty)
7624 set_internalvar (lookup_internalvar ("__"), last_examine_value);
7629 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
7632 +print_types_mark_used (void)
7634 + struct display *d;
7636 + if (last_examine_value)
7637 + type_mark_used (value_type (last_examine_value));
7639 + for (d = display_chain; d; d = d->next)
7641 + exp_types_mark_used (d->exp);
7647 /* Add an expression to the auto-display chain.
7648 @@ -1982,6 +2009,10 @@ print_variable_and_value (const char *name, struct symbol *var,
7649 struct value_print_options opts;
7651 val = read_var_value (var, frame);
7653 + make_cleanup_restore_selected_frame ();
7654 + select_frame (frame);
7656 get_user_print_options (&opts);
7658 common_val_print (val, stream, indent, &opts, current_language);
7659 @@ -2626,4 +2657,8 @@ Show printing of source filename and line number with <symbol>."), NULL,
7660 add_com ("eval", no_class, eval_command, _("\
7661 Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
7662 a command line, and call it."));
7665 + observer_attach_mark_used (print_types_mark_used);
7668 diff --git a/gdb/procfs.c b/gdb/procfs.c
7669 index 774df2e..4409e5b 100644
7672 @@ -3486,7 +3486,7 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
7673 long storage_needed;
7676 - abfd = bfd_fdopenr ("unamed", 0, fd);
7677 + abfd = gdb_bfd_fdopenr ("unamed", 0, fd);
7680 warning (_("Failed to create a bfd: %s."), bfd_errmsg (bfd_get_error ()));
7681 @@ -3497,7 +3497,7 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
7683 /* Not the correct format, so we can not possibly find the dbx_link
7686 + gdb_bfd_unref (abfd);
7690 @@ -3511,14 +3511,14 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
7691 if (dbx_link_bpt == NULL)
7693 warning (_("Failed to insert dbx_link breakpoint."));
7695 + gdb_bfd_unref (abfd);
7699 + gdb_bfd_unref (abfd);
7704 + gdb_bfd_unref (abfd);
7708 diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
7709 new file mode 100644
7710 index 0000000..5654546
7712 +++ b/gdb/python/lib/gdb/FrameIterator.py
7714 +# Iterator over frames.
7716 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
7718 +# This program is free software; you can redistribute it and/or modify
7719 +# it under the terms of the GNU General Public License as published by
7720 +# the Free Software Foundation; either version 3 of the License, or
7721 +# (at your option) any later version.
7723 +# This program is distributed in the hope that it will be useful,
7724 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7725 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7726 +# GNU General Public License for more details.
7728 +# You should have received a copy of the GNU General Public License
7729 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
7731 +class FrameIterator:
7732 + """An iterator that iterates over frames."""
7734 + def __init__ (self, frame):
7735 + "Initialize a FrameIterator. FRAME is the starting frame."
7736 + self.frame = frame
7738 + def __iter__ (self):
7742 + result = self.frame
7743 + if result is None:
7744 + raise StopIteration
7745 + self.frame = result.older ()
7747 diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
7748 new file mode 100644
7749 index 0000000..b790a54
7751 +++ b/gdb/python/lib/gdb/FrameWrapper.py
7753 +# Wrapper API for frames.
7755 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
7757 +# This program is free software; you can redistribute it and/or modify
7758 +# it under the terms of the GNU General Public License as published by
7759 +# the Free Software Foundation; either version 3 of the License, or
7760 +# (at your option) any later version.
7762 +# This program is distributed in the hope that it will be useful,
7763 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7764 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7765 +# GNU General Public License for more details.
7767 +# You should have received a copy of the GNU General Public License
7768 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
7772 +# FIXME: arguably all this should be on Frame somehow.
7773 +class FrameWrapper:
7774 + def __init__ (self, frame):
7775 + self.frame = frame;
7777 + def write_symbol (self, stream, sym, block):
7778 + if len (sym.linkage_name):
7779 + nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
7780 + if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
7783 + stream.write (sym.print_name + "=")
7785 + val = self.read_var (sym)
7788 + # FIXME: would be nice to have a more precise exception here.
7789 + except RuntimeError, text:
7792 + stream.write ("???")
7794 + stream.write (str (val))
7796 + def print_frame_locals (self, stream, func):
7801 + block = func.value
7804 + if sym.is_argument:
7807 + self.write_symbol (stream, sym, block)
7808 + stream.write ('\n')
7810 + def print_frame_args (self, stream, func):
7815 + block = func.value
7818 + if not sym.is_argument:
7822 + stream.write (", ")
7824 + self.write_symbol (stream, sym, block)
7827 + # FIXME: this should probably just be a method on gdb.Frame.
7828 + # But then we need stream wrappers.
7829 + def describe (self, stream, full):
7830 + if self.type () == gdb.DUMMY_FRAME:
7831 + stream.write (" <function called from gdb>\n")
7832 + elif self.type () == gdb.SIGTRAMP_FRAME:
7833 + stream.write (" <signal handler called>\n")
7835 + sal = self.find_sal ()
7837 + name = self.name ()
7840 + if pc != sal.pc or not sal.symtab:
7841 + stream.write (" 0x%08x in" % pc)
7842 + stream.write (" " + name + " (")
7844 + func = self.function ()
7845 + self.print_frame_args (stream, func)
7847 + stream.write (")")
7849 + if sal.symtab and sal.symtab.filename:
7850 + stream.write (" at " + sal.symtab.filename)
7851 + stream.write (":" + str (sal.line))
7853 + if not self.name () or (not sal.symtab or not sal.symtab.filename):
7854 + lib = gdb.solib_address (pc)
7856 + stream.write (" from " + lib)
7858 + stream.write ("\n")
7861 + self.print_frame_locals (stream, func)
7863 + def __getattr__ (self, name):
7864 + return getattr (self.frame, name)
7865 diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
7866 new file mode 100644
7867 index 0000000..6bb4fb1
7869 +++ b/gdb/python/lib/gdb/backtrace.py
7871 +# Filtering backtrace.
7873 +# Copyright (C) 2008, 2011 Free Software Foundation, Inc.
7875 +# This program is free software; you can redistribute it and/or modify
7876 +# it under the terms of the GNU General Public License as published by
7877 +# the Free Software Foundation; either version 3 of the License, or
7878 +# (at your option) any later version.
7880 +# This program is distributed in the hope that it will be useful,
7881 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7882 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7883 +# GNU General Public License for more details.
7885 +# You should have received a copy of the GNU General Public License
7886 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
7891 +# Our only exports.
7892 +__all__ = ['push_frame_filter', 'create_frame_filter']
7894 +frame_filter = None
7896 +def push_frame_filter (constructor):
7897 + """Register a new backtrace filter class with the 'backtrace' command.
7898 +The filter will be passed an iterator as an argument. The iterator
7899 +will return gdb.Frame-like objects. The filter should in turn act as
7900 +an iterator returning such objects."""
7901 + global frame_filter
7902 + if frame_filter == None:
7903 + frame_filter = constructor
7905 + frame_filter = lambda iterator, filter = frame_filter: constructor (filter (iterator))
7907 +def create_frame_filter (iter):
7908 + global frame_filter
7909 + if frame_filter is None:
7911 + return frame_filter (iter)
7913 diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
7914 new file mode 100644
7915 index 0000000..eeea909
7917 +++ b/gdb/python/lib/gdb/command/backtrace.py
7919 +# New backtrace command.
7921 +# Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
7923 +# This program is free software; you can redistribute it and/or modify
7924 +# it under the terms of the GNU General Public License as published by
7925 +# the Free Software Foundation; either version 3 of the License, or
7926 +# (at your option) any later version.
7928 +# This program is distributed in the hope that it will be useful,
7929 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
7930 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7931 +# GNU General Public License for more details.
7933 +# You should have received a copy of the GNU General Public License
7934 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
7937 +import gdb.backtrace
7939 +from gdb.FrameIterator import FrameIterator
7940 +from gdb.FrameWrapper import FrameWrapper
7943 +class ReverseBacktraceParameter (gdb.Parameter):
7944 + """The new-backtrace command can show backtraces in 'reverse' order.
7945 +This means that the innermost frame will be printed last.
7946 +Note that reverse backtraces are more expensive to compute."""
7948 + set_doc = "Enable or disable reverse backtraces."
7949 + show_doc = "Show whether backtraces will be printed in reverse order."
7951 + def __init__(self):
7952 + gdb.Parameter.__init__ (self, "reverse-backtrace",
7953 + gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
7954 + # Default to compatibility with gdb.
7955 + self.value = False
7957 +class FilteringBacktrace (gdb.Command):
7958 + """Print backtrace of all stack frames, or innermost COUNT frames.
7959 +With a negative argument, print outermost -COUNT frames.
7960 +Use of the 'full' qualifier also prints the values of the local variables.
7961 +Use of the 'raw' qualifier avoids any filtering by loadable modules.
7964 + def __init__ (self):
7965 + # FIXME: this is not working quite well enough to replace
7966 + # "backtrace" yet.
7967 + gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
7968 + self.reverse = ReverseBacktraceParameter()
7970 + def reverse_iter (self, iter):
7973 + result.append (item)
7977 + def final_n (self, iter, x):
7980 + result.append (item)
7983 + def invoke (self, arg, from_tty):
7989 + for word in arg.split (" "):
7992 + elif word == 'raw':
7994 + elif word == 'full':
7997 + count = int (word)
7999 + # FIXME: provide option to start at selected frame
8000 + # However, should still number as if starting from newest
8001 + newest_frame = gdb.newest_frame()
8002 + iter = itertools.imap (FrameWrapper,
8003 + FrameIterator (newest_frame))
8005 + iter = gdb.backtrace.create_frame_filter (iter)
8007 + # Now wrap in an iterator that numbers the frames.
8008 + iter = itertools.izip (itertools.count (0), iter)
8010 + # Reverse if the user wanted that.
8011 + if self.reverse.value:
8012 + iter = self.reverse_iter (iter)
8014 + # Extract sub-range user wants.
8016 + iter = self.final_n (iter, count)
8018 + iter = itertools.islice (iter, 0, count)
8021 + sys.stdout.write ("#%-2d" % pair[0])
8022 + pair[1].describe (sys.stdout, full)
8024 +FilteringBacktrace()
8025 diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
8026 new file mode 100644
8027 index 0000000..6fa48ff
8029 +++ b/gdb/python/lib/gdb/command/ignore_errors.py
8031 +# Ignore errors in user commands.
8033 +# Copyright (C) 2008 Free Software Foundation, Inc.
8035 +# This program is free software; you can redistribute it and/or modify
8036 +# it under the terms of the GNU General Public License as published by
8037 +# the Free Software Foundation; either version 3 of the License, or
8038 +# (at your option) any later version.
8040 +# This program is distributed in the hope that it will be useful,
8041 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8042 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8043 +# GNU General Public License for more details.
8045 +# You should have received a copy of the GNU General Public License
8046 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8050 +class IgnoreErrorsCommand (gdb.Command):
8051 + """Execute a single command, ignoring all errors.
8052 +Only one-line commands are supported.
8053 +This is primarily useful in scripts."""
8055 + def __init__ (self):
8056 + super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
8057 + gdb.COMMAND_OBSCURE,
8059 + gdb.COMPLETE_COMMAND)
8061 + def invoke (self, arg, from_tty):
8063 + gdb.execute (arg, from_tty)
8067 +IgnoreErrorsCommand ()
8068 diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
8069 new file mode 100644
8070 index 0000000..21a0bf0
8072 +++ b/gdb/python/lib/gdb/command/pahole.py
8074 +# pahole command for gdb
8076 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
8078 +# This program is free software; you can redistribute it and/or modify
8079 +# it under the terms of the GNU General Public License as published by
8080 +# the Free Software Foundation; either version 3 of the License, or
8081 +# (at your option) any later version.
8083 +# This program is distributed in the hope that it will be useful,
8084 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8085 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8086 +# GNU General Public License for more details.
8088 +# You should have received a copy of the GNU General Public License
8089 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8093 +class Pahole (gdb.Command):
8094 + """Show the holes in a structure.
8095 +This command takes a single argument, a type name.
8096 +It prints the type and displays comments showing where holes are."""
8098 + def __init__ (self):
8099 + super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
8100 + gdb.COMPLETE_SYMBOL)
8102 + def pahole (self, type, level, name):
8108 + print '%sstruct %s {' % (' ' * (2 * level), tag)
8110 + for field in type.fields ():
8111 + # Skip static fields.
8112 + if not hasattr (field, ('bitpos')):
8115 + ftype = field.type.strip_typedefs()
8117 + if bitpos != field.bitpos:
8118 + hole = field.bitpos - bitpos
8119 + print ' /* XXX %d bit hole, try to pack */' % hole
8120 + bitpos = field.bitpos
8121 + if field.bitsize > 0:
8122 + fieldsize = field.bitsize
8124 + # TARGET_CHAR_BIT here...
8125 + fieldsize = 8 * ftype.sizeof
8128 + print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
8129 + bitpos = bitpos + fieldsize
8131 + if ftype.code == gdb.TYPE_CODE_STRUCT:
8132 + self.pahole (ftype, level + 1, field.name)
8134 + print ' ' * (2 + 2 * level),
8135 + print '%s %s' % (str (ftype), field.name)
8137 + print ' ' * (14 + 2 * level),
8138 + print '} %s' % name
8140 + def invoke (self, arg, from_tty):
8141 + type = gdb.lookup_type (arg)
8142 + type = type.strip_typedefs ()
8143 + if type.code != gdb.TYPE_CODE_STRUCT:
8144 + raise TypeError, '%s is not a struct type' % arg
8146 + self.pahole (type, 0, '')
8149 diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
8150 new file mode 100644
8151 index 0000000..1fbc1e8
8153 +++ b/gdb/python/lib/gdb/command/require.py
8155 +# Demand-loading commands.
8157 +# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
8159 +# This program is free software; you can redistribute it and/or modify
8160 +# it under the terms of the GNU General Public License as published by
8161 +# the Free Software Foundation; either version 3 of the License, or
8162 +# (at your option) any later version.
8164 +# This program is distributed in the hope that it will be useful,
8165 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8166 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8167 +# GNU General Public License for more details.
8169 +# You should have received a copy of the GNU General Public License
8170 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8175 +class RequireCommand (gdb.Command):
8176 + """Prefix command for requiring features."""
8178 + def __init__ (self):
8179 + super (RequireCommand, self).__init__ ("require",
8180 + gdb.COMMAND_SUPPORT,
8181 + gdb.COMPLETE_NONE,
8184 +class RequireSubcommand (gdb.Command):
8185 + """Demand-load a command by name."""
8187 + def __init__ (self, name):
8188 + self.__doc__ = "Demand-load a %s by name." % name
8189 + super (RequireSubcommand, self).__init__ ("require %s" % name,
8190 + gdb.COMMAND_SUPPORT)
8193 + def invoke (self, arg, from_tty):
8194 + for cmd in arg.split():
8195 + exec ('import gdb.' + self.name + '.' + cmd, globals ())
8197 + def complete (self, text, word):
8198 + dir = gdb.pythondir + '/gdb/' + self.name
8200 + for file in os.listdir(dir):
8201 + if not file.startswith (word) or not file.endswith ('.py'):
8203 + feature = file[0:-3]
8204 + if feature == 'require' or feature == '__init__':
8206 + result.append (feature)
8210 +RequireSubcommand("command")
8211 +RequireSubcommand("function")
8212 diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
8213 new file mode 100644
8214 index 0000000..faf54ed
8216 +++ b/gdb/python/lib/gdb/command/upto.py
8220 +# Copyright (C) 2009 Free Software Foundation, Inc.
8222 +# This program is free software; you can redistribute it and/or modify
8223 +# it under the terms of the GNU General Public License as published by
8224 +# the Free Software Foundation; either version 3 of the License, or
8225 +# (at your option) any later version.
8227 +# This program is distributed in the hope that it will be useful,
8228 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8229 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8230 +# GNU General Public License for more details.
8232 +# You should have received a copy of the GNU General Public License
8233 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8237 +from gdb.FrameIterator import FrameIterator
8238 +from gdb.FrameWrapper import FrameWrapper
8240 +class UptoPrefix (gdb.Command):
8241 + def __init__ (self):
8242 + super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
8245 +class UptoImplementation (gdb.Command):
8246 + def __init__ (self, subcommand):
8247 + super (UptoImplementation, self).__init__ ("upto " + subcommand,
8248 + gdb.COMMAND_STACK)
8250 + def search (self):
8251 + saved = gdb.selected_frame ()
8252 + iter = FrameIterator (saved)
8255 + for frame in iter:
8258 + if self.filter (frame):
8259 + wrapper = FrameWrapper (frame)
8260 + wrapper.describe (sys.stdout, False)
8267 + raise RuntimeError, 'Could not find a matching frame'
8269 + def invoke (self, arg, from_tty):
8270 + self.rx = re.compile (arg)
8273 +class UptoSymbolCommand (UptoImplementation):
8274 + """Select and print some calling stack frame, based on symbol.
8275 +The argument is a regular expression. This command moves up the
8276 +stack, stopping at the first frame whose symbol matches the regular
8279 + def __init__ (self):
8280 + super (UptoSymbolCommand, self).__init__ ("symbol")
8282 + def filter (self, frame):
8283 + name = frame.name ()
8284 + if name is not None:
8285 + if self.rx.search (name) is not None:
8289 +class UptoSourceCommand (UptoImplementation):
8290 + """Select and print some calling stack frame, based on source file.
8291 +The argument is a regular expression. This command moves up the
8292 +stack, stopping at the first frame whose source file name matches the
8293 +regular expression."""
8295 + def __init__ (self):
8296 + super (UptoSourceCommand, self).__init__ ("source")
8298 + def filter (self, frame):
8299 + name = frame.find_sal ().symtab.filename
8300 + if name is not None:
8301 + if self.rx.search (name) is not None:
8305 +class UptoObjectCommand (UptoImplementation):
8306 + """Select and print some calling stack frame, based on object file.
8307 +The argument is a regular expression. This command moves up the
8308 +stack, stopping at the first frame whose object file name matches the
8309 +regular expression."""
8311 + def __init__ (self):
8312 + super (UptoObjectCommand, self).__init__ ("object")
8314 + def filter (self, frame):
8315 + name = frame.find_sal ().symtab.objfile.filename
8316 + if name is not None:
8317 + if self.rx.search (name) is not None:
8321 +class UptoWhereCommand (UptoImplementation):
8322 + """Select and print some calling stack frame, based on expression.
8323 +The argument is an expression. This command moves up the stack,
8324 +parsing and evaluating the expression in each frame. This stops when
8325 +the expression evaluates to a non-zero (true) value."""
8327 + def __init__ (self):
8328 + super (UptoWhereCommand, self).__init__ ("where")
8330 + def filter (self, frame):
8332 + if gdb.parse_and_eval (self.expression):
8338 + def invoke (self, arg, from_tty):
8339 + self.expression = arg
8343 +UptoSymbolCommand ()
8344 +UptoSourceCommand ()
8345 +UptoObjectCommand ()
8346 +UptoWhereCommand ()
8347 diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
8348 new file mode 100644
8349 index 0000000..8b13789
8351 +++ b/gdb/python/lib/gdb/function/__init__.py
8354 diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
8355 new file mode 100644
8356 index 0000000..2b9c5c7
8358 +++ b/gdb/python/lib/gdb/function/caller_is.py
8360 +# Caller-is functions.
8362 +# Copyright (C) 2008 Free Software Foundation, Inc.
8364 +# This program is free software; you can redistribute it and/or modify
8365 +# it under the terms of the GNU General Public License as published by
8366 +# the Free Software Foundation; either version 3 of the License, or
8367 +# (at your option) any later version.
8369 +# This program is distributed in the hope that it will be useful,
8370 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8371 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8372 +# GNU General Public License for more details.
8374 +# You should have received a copy of the GNU General Public License
8375 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8380 +class CallerIs (gdb.Function):
8381 + """Return True if the calling function's name is equal to a string.
8382 +This function takes one or two arguments.
8383 +The first argument is the name of a function; if the calling function's
8384 +name is equal to this argument, this function returns True.
8385 +The optional second argument tells this function how many stack frames
8386 +to traverse to find the calling function. The default is 1."""
8388 + def __init__ (self):
8389 + super (CallerIs, self).__init__ ("caller_is")
8391 + def invoke (self, name, nframes = 1):
8392 + frame = gdb.selected_frame ()
8393 + while nframes > 0:
8394 + frame = frame.older ()
8395 + nframes = nframes - 1
8396 + return frame.name () == name.string ()
8398 +class CallerMatches (gdb.Function):
8399 + """Return True if the calling function's name matches a string.
8400 +This function takes one or two arguments.
8401 +The first argument is a regular expression; if the calling function's
8402 +name is matched by this argument, this function returns True.
8403 +The optional second argument tells this function how many stack frames
8404 +to traverse to find the calling function. The default is 1."""
8406 + def __init__ (self):
8407 + super (CallerMatches, self).__init__ ("caller_matches")
8409 + def invoke (self, name, nframes = 1):
8410 + frame = gdb.selected_frame ()
8411 + while nframes > 0:
8412 + frame = frame.older ()
8413 + nframes = nframes - 1
8414 + return re.match (name.string (), frame.name ()) is not None
8418 diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
8419 new file mode 100644
8420 index 0000000..debb3bb
8422 +++ b/gdb/python/lib/gdb/function/in_scope.py
8424 +# In-scope function.
8426 +# Copyright (C) 2008 Free Software Foundation, Inc.
8428 +# This program is free software; you can redistribute it and/or modify
8429 +# it under the terms of the GNU General Public License as published by
8430 +# the Free Software Foundation; either version 3 of the License, or
8431 +# (at your option) any later version.
8433 +# This program is distributed in the hope that it will be useful,
8434 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
8435 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8436 +# GNU General Public License for more details.
8438 +# You should have received a copy of the GNU General Public License
8439 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
8443 +class InScope (gdb.Function):
8444 + """Return True if all the given variables or macros are in scope.
8445 +Takes one argument for each variable name to be checked."""
8447 + def __init__ (self):
8448 + super (InScope, self).__init__ ("in_scope")
8450 + def invoke (self, *vars):
8451 + if len (vars) == 0:
8452 + raise TypeError, "in_scope takes at least one argument"
8454 + # gdb.Value isn't hashable so it can't be put in a map.
8455 + # Convert to string first.
8456 + wanted = set (map (lambda x: x.string (), vars))
8458 + block = gdb.selected_frame ().block ()
8461 + if (sym.is_argument or sym.is_constant
8462 + or sym.is_function or sym.is_variable):
8463 + if sym.name in wanted:
8464 + found.add (sym.name)
8466 + block = block.superblock
8468 + return wanted == found
8471 diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
8472 index 98030a6..9870eec 100644
8473 --- a/gdb/python/py-type.c
8474 +++ b/gdb/python/py-type.c
8478 #include "dwarf2loc.h"
8479 +#include "observer.h"
8480 +#include "gdb_assert.h"
8482 typedef struct pyty_type_object
8484 @@ -38,11 +40,19 @@ typedef struct pyty_type_object
8486 /* If a Type object is associated with an objfile, it is kept on a
8487 doubly-linked list, rooted in the objfile. This lets us copy the
8488 - underlying struct type when the objfile is deleted. */
8489 + underlying struct type when the objfile is deleted.
8491 + With NULL objfile Type still can be doubly-linked in the list
8492 + PYTY_OBJECTS_DISCARDABLE. */
8493 struct pyty_type_object *prev;
8494 struct pyty_type_object *next;
8498 +/* First element of a doubly-linked list of TYPE_DISCARDABLE Types. */
8499 +static type_object *pyty_objects_discardable;
8502 static PyTypeObject type_object_type;
8504 /* A Field object. */
8505 @@ -1166,8 +1176,63 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
8509 +/* Key associated with each objfile pointing to the first element of
8510 + a doubly-linked list of Types associated with this objfile. */
8511 static const struct objfile_data *typy_objfile_data_key;
8513 +/* Link TYPE_OBJ to its appropriate list. Either to its objfile associated one
8514 + or at least to the global list for TYPE_DISCARDABLE Types. Permanent types
8515 + do not get linked anywhere. */
8517 +typy_link (type_object *type_obj)
8519 + type_obj->prev = NULL;
8521 + if (type_obj->type && TYPE_OBJFILE (type_obj->type))
8523 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
8525 + type_obj->next = objfile_data (objfile, typy_objfile_data_key);
8526 + if (type_obj->next)
8527 + type_obj->next->prev = type_obj;
8528 + set_objfile_data (objfile, typy_objfile_data_key, type_obj);
8531 + else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
8533 + type_obj->next = pyty_objects_discardable;
8534 + if (type_obj->next)
8535 + type_obj->next->prev = type_obj;
8536 + pyty_objects_discardable = type_obj;
8540 + type_obj->next = NULL;
8543 +/* Unlink TYPE_OBJ from its current list. Permanent types are not linked
8544 + anywhere and this function has no effect on them. */
8546 +typy_unlink (type_object *type_obj)
8548 + if (type_obj->prev)
8549 + type_obj->prev->next = type_obj->next;
8550 + else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
8552 + /* Must reset head of list. */
8553 + struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
8555 + set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
8558 + else if (pyty_objects_discardable == type_obj)
8559 + pyty_objects_discardable = type_obj->next;
8562 + if (type_obj->next)
8563 + type_obj->next->prev = type_obj->prev;
8567 save_objfile_types (struct objfile *objfile, void *datum)
8569 @@ -1185,12 +1250,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
8571 type_object *next = obj->next;
8573 - htab_empty (copied_types);
8574 + gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
8575 + typy_unlink (obj);
8577 - obj->type = copy_type_recursive (objfile, obj->type, copied_types);
8578 + obj->type = copy_type_recursive (obj->type, copied_types);
8582 + gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
8587 @@ -1201,43 +1267,28 @@ save_objfile_types (struct objfile *objfile, void *datum)
8591 -set_type (type_object *obj, struct type *type)
8592 +typy_dealloc (PyObject *obj)
8596 - if (type && TYPE_OBJFILE (type))
8598 - struct objfile *objfile = TYPE_OBJFILE (type);
8599 + type_object *type_obj = (type_object *) obj;
8601 - obj->next = objfile_data (objfile, typy_objfile_data_key);
8603 - obj->next->prev = obj;
8604 - set_objfile_data (objfile, typy_objfile_data_key, obj);
8608 + typy_unlink (type_obj);
8610 + type_obj->ob_type->tp_free (obj);
8614 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
8616 -typy_dealloc (PyObject *obj)
8617 +typy_types_mark_used (void)
8619 - type_object *type = (type_object *) obj;
8622 - type->prev->next = type->next;
8623 - else if (type->type && TYPE_OBJFILE (type->type))
8625 - /* Must reset head of list. */
8626 - struct objfile *objfile = TYPE_OBJFILE (type->type);
8629 - set_objfile_data (objfile, typy_objfile_data_key, type->next);
8632 - type->next->prev = type->prev;
8633 + type_object *type_obj;
8635 - type->ob_type->tp_free (type);
8636 + for (type_obj = pyty_objects_discardable;
8638 + type_obj = type_obj->next)
8639 + type_mark_used (type_obj->type);
8643 /* Return number of fields ("length" of the field dictionary). */
8645 @@ -1457,7 +1508,10 @@ type_to_type_object (struct type *type)
8647 type_obj = PyObject_New (type_object, &type_object_type);
8649 - set_type (type_obj, type);
8651 + type_obj->type = type;
8652 + typy_link (type_obj);
8655 return (PyObject *) type_obj;
8657 @@ -1537,6 +1591,10 @@ gdbpy_initialize_types (void)
8659 Py_INCREF (&field_object_type);
8660 PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
8663 + observer_attach_mark_used (typy_types_mark_used);
8668 diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
8669 index 6f67bdb..5ddd6bc 100644
8670 --- a/gdb/python/py-value.c
8671 +++ b/gdb/python/py-value.c
8673 #include "expression.h"
8676 +#include "observer.h"
8680 @@ -1378,6 +1379,19 @@ gdbpy_is_value_object (PyObject *obj)
8681 return PyObject_TypeCheck (obj, &value_object_type);
8685 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
8688 +python_types_mark_used (void)
8690 + value_object *iter;
8692 + for (iter = values_in_python; iter; iter = iter->next)
8693 + type_mark_used (value_type (iter->value));
8698 gdbpy_initialize_values (void)
8700 @@ -1388,6 +1402,10 @@ gdbpy_initialize_values (void)
8701 PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
8703 values_in_python = NULL;
8706 + observer_attach_mark_used (python_types_mark_used);
8711 diff --git a/gdb/python/python.c b/gdb/python/python.c
8712 index c66efe4..0211fcb 100644
8713 --- a/gdb/python/python.c
8714 +++ b/gdb/python/python.c
8715 @@ -66,10 +66,13 @@ static const char *gdbpy_should_print_stack = python_excp_message;
8716 #include "linespec.h"
8718 #include "version.h"
8719 +#include "inferior.h"
8720 +#include "gdbthread.h"
8722 #include "gdbthread.h"
8723 #include "observer.h"
8724 #include "interps.h"
8725 +#include "event-top.h"
8727 static PyMethodDef GdbMethods[];
8729 @@ -979,6 +982,53 @@ gdbpy_print_stack (void)
8731 /* Return the current Progspace.
8732 There always is one. */
8733 +/* True if 'gdb -P' was used, false otherwise. */
8734 +static int running_python_script;
8736 +/* True if we are currently in a call to 'gdb.cli', false otherwise. */
8739 +/* Enter the command loop. */
8742 +gdbpy_cli (PyObject *unused1, PyObject *unused2)
8744 + if (! running_python_script || in_cli)
8745 + return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
8748 + cli_command_loop ();
8754 +/* Set up the Python argument vector and evaluate a script. This is
8755 + used to implement 'gdb -P'. */
8758 +run_python_script (int argc, char **argv)
8762 + /* We never free this, since we plan to exit at the end. */
8763 + ensure_python_env (get_current_arch (), current_language);
8765 + running_python_script = 1;
8766 + PySys_SetArgv (argc - 1, argv + 1);
8767 + input = fopen (argv[0], "r");
8770 + fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
8773 + PyRun_SimpleFile (input, argv[0]);
8782 gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
8783 @@ -1420,6 +1470,8 @@ static PyMethodDef GdbMethods[] =
8784 "Get a value from history" },
8785 { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
8786 "Execute a gdb command" },
8787 + { "cli", gdbpy_cli, METH_NOARGS,
8788 + "Enter the gdb CLI" },
8789 { "parameter", gdbpy_parameter, METH_VARARGS,
8790 "Return a gdb parameter's value" },
8792 diff --git a/gdb/python/python.h b/gdb/python/python.h
8793 index dd7066f..f0f6e90 100644
8794 --- a/gdb/python/python.h
8795 +++ b/gdb/python/python.h
8796 @@ -30,6 +30,8 @@ void eval_python_from_control_command (struct command_line *);
8798 void source_python_script (FILE *file, const char *filename);
8800 +void run_python_script (int argc, char **argv);
8802 int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
8803 int embedded_offset, CORE_ADDR address,
8804 struct ui_file *stream, int recurse,
8805 diff --git a/gdb/record.c b/gdb/record.c
8806 index bb0fe52..ec42aac 100644
8811 #include "event-loop.h"
8812 #include "inf-loop.h"
8813 +#include "gdb_bfd.h"
8817 @@ -2638,7 +2639,7 @@ record_save_cleanups (void *data)
8819 char *pathname = xstrdup (bfd_get_filename (obfd));
8822 + gdb_bfd_unref (obfd);
8826 @@ -2854,7 +2855,7 @@ cmd_record_save (char *args, int from_tty)
8829 do_cleanups (set_cleanups);
8831 + gdb_bfd_unref (obfd);
8832 discard_cleanups (old_cleanups);
8835 diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c
8836 index 47f4405..85268b6 100644
8837 --- a/gdb/remote-m32r-sdi.c
8838 +++ b/gdb/remote-m32r-sdi.c
8840 #include <sys/time.h>
8843 +#include "gdb_bfd.h"
8847 @@ -1257,13 +1258,13 @@ m32r_load (char *args, int from_tty)
8849 filename = get_exec_file (1);
8851 - pbfd = bfd_openr (filename, gnutarget);
8852 + pbfd = gdb_bfd_openr (filename, gnutarget);
8855 perror_with_name (filename);
8858 - old_chain = make_cleanup_bfd_close (pbfd);
8859 + old_chain = make_cleanup_bfd_unref (pbfd);
8861 if (!bfd_check_format (pbfd, bfd_object))
8862 error (_("\"%s\" is not an object file: %s"), filename,
8863 diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c
8864 index babbf19..db4381b 100644
8865 --- a/gdb/remote-mips.c
8866 +++ b/gdb/remote-mips.c
8869 #include "mips-tdep.h"
8870 #include "gdbthread.h"
8871 +#include "gdb_bfd.h"
8874 /* Breakpoint types. Values 0, 1, and 2 must agree with the watch
8875 @@ -2783,20 +2784,23 @@ mips_load_srec (char *args)
8877 unsigned int srec_frame = 200;
8879 + struct cleanup *cleanup;
8880 static int hashmark = 1;
8882 buffer = alloca (srec_frame * 2 + 256);
8884 - abfd = bfd_openr (args, 0);
8885 + abfd = gdb_bfd_openr (args, 0);
8888 printf_filtered ("Unable to open file %s\n", args);
8892 + cleanup = make_cleanup_bfd_unref (abfd);
8893 if (bfd_check_format (abfd, bfd_object) == 0)
8895 printf_filtered ("File is not an object file\n");
8896 + do_cleanups (cleanup);
8900 @@ -2850,6 +2854,7 @@ mips_load_srec (char *args)
8901 send_srec (srec, reclen, abfd->start_address);
8903 serial_flush_input (mips_desc);
8904 + do_cleanups (cleanup);
8908 @@ -3366,20 +3371,23 @@ pmon_load_fast (char *file)
8912 + struct cleanup *cleanup;
8914 buffer = (char *) xmalloc (MAXRECSIZE + 1);
8915 binbuf = (unsigned char *) xmalloc (BINCHUNK);
8917 - abfd = bfd_openr (file, 0);
8918 + abfd = gdb_bfd_openr (file, 0);
8921 printf_filtered ("Unable to open file %s\n", file);
8924 + cleanup = make_cleanup_bfd_unref (abfd);
8926 if (bfd_check_format (abfd, bfd_object) == 0)
8928 printf_filtered ("File is not an object file\n");
8929 + do_cleanups (cleanup);
8933 @@ -3503,6 +3511,7 @@ pmon_load_fast (char *file)
8934 pmon_end_download (final, bintotal);
8937 + do_cleanups (cleanup);
8941 diff --git a/gdb/remote.c b/gdb/remote.c
8942 index 1c9367d..f2b5e7b 100644
8946 #include "cli/cli-decode.h"
8947 #include "cli/cli-setshow.h"
8948 #include "target-descriptions.h"
8949 +#include "gdb_bfd.h"
8952 #include <sys/time.h>
8953 @@ -9823,11 +9824,13 @@ remote_filename_p (const char *filename)
8955 remote_bfd_open (const char *remote_file, const char *target)
8957 - return bfd_openr_iovec (remote_file, target,
8958 - remote_bfd_iovec_open, NULL,
8959 - remote_bfd_iovec_pread,
8960 - remote_bfd_iovec_close,
8961 - remote_bfd_iovec_stat);
8962 + bfd *abfd = gdb_bfd_openr_iovec (remote_file, target,
8963 + remote_bfd_iovec_open, NULL,
8964 + remote_bfd_iovec_pread,
8965 + remote_bfd_iovec_close,
8966 + remote_bfd_iovec_stat);
8972 diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
8973 index 0a2000a..9b8efd3 100644
8974 --- a/gdb/rs6000-nat.c
8975 +++ b/gdb/rs6000-nat.c
8976 @@ -730,7 +730,7 @@ static struct vmap *
8977 add_vmap (LdInfo *ldi)
8980 - char *mem, *objname, *filename;
8981 + char *mem, *filename;
8982 struct objfile *obj;
8985 @@ -743,19 +743,18 @@ add_vmap (LdInfo *ldi)
8986 filename = LDI_FILENAME (ldi, arch64);
8987 mem = filename + strlen (filename) + 1;
8988 mem = xstrdup (mem);
8989 - objname = xstrdup (filename);
8991 fd = LDI_FD (ldi, arch64);
8993 /* Note that this opens it once for every member; a possible
8994 enhancement would be to only open it once for every object. */
8995 - abfd = bfd_openr (objname, gnutarget);
8996 + abfd = gdb_bfd_openr (filename, gnutarget);
8998 - abfd = bfd_fdopenr (objname, gnutarget, fd);
8999 + abfd = gdb_bfd_fdopenr (filename, gnutarget, fd);
9002 warning (_("Could not open `%s' as an executable file: %s"),
9003 - objname, bfd_errmsg (bfd_get_error ()));
9004 + filename, bfd_errmsg (bfd_get_error ()));
9008 @@ -766,35 +765,44 @@ add_vmap (LdInfo *ldi)
9010 else if (bfd_check_format (abfd, bfd_archive))
9013 - /* FIXME??? am I tossing BFDs? bfd? */
9014 - while ((last = bfd_openr_next_archived_file (abfd, last)))
9015 - if (strcmp (mem, last->filename) == 0)
9017 + last = gdb_bfd_openr_next_archived_file (abfd, NULL);
9018 + while (last != NULL)
9022 + if (strcmp (mem, last->filename) == 0)
9025 + next = gdb_bfd_openr_next_archived_file (abfd, last);
9026 + gdb_bfd_unref (last);
9031 - warning (_("\"%s\": member \"%s\" missing."), objname, mem);
9033 + warning (_("\"%s\": member \"%s\" missing."), filename, mem);
9034 + gdb_bfd_unref (abfd);
9038 if (!bfd_check_format (last, bfd_object))
9040 warning (_("\"%s\": member \"%s\" not in executable format: %s."),
9041 - objname, mem, bfd_errmsg (bfd_get_error ()));
9044 + filename, mem, bfd_errmsg (bfd_get_error ()));
9045 + gdb_bfd_unref (last);
9046 + gdb_bfd_unref (abfd);
9050 vp = map_vmap (last, abfd);
9051 + /* map_vmap acquired a reference to LAST, so we can release
9053 + gdb_bfd_unref (last);
9057 warning (_("\"%s\": not in executable format: %s."),
9058 - objname, bfd_errmsg (bfd_get_error ()));
9060 + filename, bfd_errmsg (bfd_get_error ()));
9061 + gdb_bfd_unref (abfd);
9064 obj = allocate_objfile (vp->bfd, 0);
9065 @@ -803,6 +811,11 @@ add_vmap (LdInfo *ldi)
9066 /* Always add symbols for the main objfile. */
9067 if (vp == vmap || auto_solib_add)
9068 vmap_add_symbols (vp);
9070 + /* Anything needing a reference to ABFD has already acquired it, so
9071 + release our local reference. */
9072 + gdb_bfd_unref (abfd);
9077 diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
9078 index d52fb46..db8f187 100644
9079 --- a/gdb/solib-darwin.c
9080 +++ b/gdb/solib-darwin.c
9082 #include "inferior.h"
9083 #include "regcache.h"
9084 #include "gdbthread.h"
9085 +#include "gdb_bfd.h"
9087 #include "gdb_assert.h"
9089 @@ -356,6 +357,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
9090 gdb_byte *interp_name;
9091 CORE_ADDR load_addr = 0;
9092 bfd *dyld_bfd = NULL;
9093 + struct cleanup *cleanup;
9095 /* This method doesn't work with an attached process. */
9096 if (current_inferior ()->attach_flag)
9097 @@ -366,24 +368,31 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
9101 + cleanup = make_cleanup (null_cleanup, NULL);
9103 /* Create a bfd for the interpreter. */
9104 - dyld_bfd = bfd_openr (interp_name, gnutarget);
9105 + dyld_bfd = gdb_bfd_openr (interp_name, gnutarget);
9110 + make_cleanup_bfd_unref (dyld_bfd);
9111 sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object,
9112 gdbarch_bfd_arch_info (target_gdbarch));
9117 - bfd_close (dyld_bfd);
9120 + gdb_bfd_ref (sub);
9121 + make_cleanup_bfd_unref (sub);
9129 + do_cleanups (cleanup);
9133 /* We find the dynamic linker's base address by examining
9134 the current pc (which should point at the entry point for the
9135 @@ -395,7 +404,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
9136 info->all_image_addr =
9137 lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos");
9139 - bfd_close (dyld_bfd);
9140 + do_cleanups (cleanup);
9142 if (info->all_image_addr == 0)
9144 @@ -509,17 +518,10 @@ darwin_bfd_open (char *pathname)
9145 gdbarch_bfd_arch_info (target_gdbarch));
9149 - make_cleanup (xfree, found_pathname);
9150 + make_cleanup_bfd_unref (abfd);
9151 error (_("`%s': not a shared-library: %s"),
9152 - found_pathname, bfd_errmsg (bfd_get_error ()));
9153 + bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
9156 - /* Make sure that the filename is malloc'ed. The current filename
9157 - for fat-binaries BFDs is a name that was generated by BFD, usually
9158 - a static string containing the name of the architecture. */
9159 - res->filename = xstrdup (pathname);
9164 diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
9165 index 2500c1f..fcc01a8 100644
9166 --- a/gdb/solib-dsbt.c
9167 +++ b/gdb/solib-dsbt.c
9170 #include "elf-bfd.h"
9171 #include "exceptions.h"
9172 +#include "gdb_bfd.h"
9174 #define GOT_MODULE_OFFSET 4
9176 @@ -899,7 +900,7 @@ enable_break2 (void)
9178 warning (_("Could not find symbol _dl_debug_addr in dynamic linker"));
9179 enable_break_failure_warning ();
9180 - bfd_close (tmp_bfd);
9181 + gdb_bfd_unref (tmp_bfd);
9185 @@ -948,13 +949,13 @@ enable_break2 (void)
9186 "(at address %s) from dynamic linker"),
9187 hex_string_custom (addr + 8, 8));
9188 enable_break_failure_warning ();
9189 - bfd_close (tmp_bfd);
9190 + gdb_bfd_unref (tmp_bfd);
9193 addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
9195 /* We're done with the temporary bfd. */
9196 - bfd_close (tmp_bfd);
9197 + gdb_bfd_unref (tmp_bfd);
9199 /* We're also done with the loadmap. */
9201 diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
9202 index 2f2c8b0..0f59535 100644
9203 --- a/gdb/solib-frv.c
9204 +++ b/gdb/solib-frv.c
9207 #include "elf/frv.h"
9208 #include "exceptions.h"
9209 +#include "gdb_bfd.h"
9211 /* Flag which indicates whether internal debug messages should be printed. */
9212 static int solib_frv_debug;
9213 @@ -574,7 +575,7 @@ enable_break2 (void)
9215 warning (_("Unable to determine dynamic linker loadmap address."));
9216 enable_break_failure_warning ();
9217 - bfd_close (tmp_bfd);
9218 + gdb_bfd_unref (tmp_bfd);
9222 @@ -589,7 +590,7 @@ enable_break2 (void)
9223 warning (_("Unable to load dynamic linker loadmap at address %s."),
9224 hex_string_custom (interp_loadmap_addr, 8));
9225 enable_break_failure_warning ();
9226 - bfd_close (tmp_bfd);
9227 + gdb_bfd_unref (tmp_bfd);
9231 @@ -623,7 +624,7 @@ enable_break2 (void)
9232 warning (_("Could not find symbol _dl_debug_addr "
9233 "in dynamic linker"));
9234 enable_break_failure_warning ();
9235 - bfd_close (tmp_bfd);
9236 + gdb_bfd_unref (tmp_bfd);
9240 @@ -674,7 +675,7 @@ enable_break2 (void)
9241 "(at address %s) from dynamic linker"),
9242 hex_string_custom (addr + 8, 8));
9243 enable_break_failure_warning ();
9244 - bfd_close (tmp_bfd);
9245 + gdb_bfd_unref (tmp_bfd);
9248 addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
9249 @@ -686,13 +687,13 @@ enable_break2 (void)
9250 "(at address %s) from dynamic linker"),
9251 hex_string_custom (addr, 8));
9252 enable_break_failure_warning ();
9253 - bfd_close (tmp_bfd);
9254 + gdb_bfd_unref (tmp_bfd);
9257 addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
9259 /* We're done with the temporary bfd. */
9260 - bfd_close (tmp_bfd);
9261 + gdb_bfd_unref (tmp_bfd);
9263 /* We're also done with the loadmap. */
9265 diff --git a/gdb/solib-pa64.c b/gdb/solib-pa64.c
9266 index 2b8d061..00ed8a5 100644
9267 --- a/gdb/solib-pa64.c
9268 +++ b/gdb/solib-pa64.c
9269 @@ -362,7 +362,7 @@ manpage for methods to privately map shared library text."));
9270 to find any magic formula to find it for Solaris (appears to
9271 be trivial on GNU/Linux). Therefore, we have to try an alternate
9272 mechanism to find the dynamic linker's base address. */
9273 - tmp_bfd = bfd_openr (buf, gnutarget);
9274 + tmp_bfd = gdb_bfd_openr (buf, gnutarget);
9275 if (tmp_bfd == NULL)
9278 @@ -371,7 +371,7 @@ manpage for methods to privately map shared library text."));
9280 warning (_("Unable to grok dynamic linker %s as an object file"),
9282 - bfd_close (tmp_bfd);
9283 + gdb_bfd_unref (tmp_bfd);
9287 @@ -401,7 +401,7 @@ manpage for methods to privately map shared library text."));
9290 /* We're done with the temporary bfd. */
9291 - bfd_close (tmp_bfd);
9292 + gdb_bfd_unref (tmp_bfd);
9296 diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
9297 index b5454e7..f62d96c 100644
9298 --- a/gdb/solib-spu.c
9299 +++ b/gdb/solib-spu.c
9301 #include "breakpoint.h"
9302 #include "gdbthread.h"
9303 #include "exceptions.h"
9304 +#include "gdb_bfd.h"
9306 #include "spu-tdep.h"
9308 @@ -325,16 +326,16 @@ spu_bfd_fopen (char *name, CORE_ADDR addr)
9309 CORE_ADDR *open_closure = xmalloc (sizeof (CORE_ADDR));
9310 *open_closure = addr;
9312 - nbfd = bfd_openr_iovec (xstrdup (name), "elf32-spu",
9313 - spu_bfd_iovec_open, open_closure,
9314 - spu_bfd_iovec_pread, spu_bfd_iovec_close,
9315 - spu_bfd_iovec_stat);
9316 + nbfd = gdb_bfd_openr_iovec (name, "elf32-spu",
9317 + spu_bfd_iovec_open, open_closure,
9318 + spu_bfd_iovec_pread, spu_bfd_iovec_close,
9319 + spu_bfd_iovec_stat);
9323 if (!bfd_check_format (nbfd, bfd_object))
9326 + gdb_bfd_unref (nbfd);
9330 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
9331 index 307e483..76bd872 100644
9332 --- a/gdb/solib-svr4.c
9333 +++ b/gdb/solib-svr4.c
9337 #include "exceptions.h"
9338 +#include "gdb_bfd.h"
9340 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
9341 static int svr4_have_link_map_offsets (void);
9342 @@ -1558,9 +1559,11 @@ enable_break (struct svr4_info *info, int from_tty)
9343 goto bkpt_at_symbol;
9345 /* Now convert the TMP_BFD into a target. That way target, as
9346 - well as BFD operations can be used. Note that closing the
9347 - target will also close the underlying bfd. */
9348 + well as BFD operations can be used. */
9349 tmp_bfd_target = target_bfd_reopen (tmp_bfd);
9350 + /* target_bfd_reopen acquired its own reference, so we can
9351 + release ours now. */
9352 + gdb_bfd_unref (tmp_bfd);
9354 /* On a running target, we can get the dynamic linker's base
9355 address from the shared library table. */
9356 @@ -1670,8 +1673,9 @@ enable_break (struct svr4_info *info, int from_tty)
9360 - /* We're done with both the temporary bfd and target. Remember,
9361 - closing the target closes the underlying bfd. */
9362 + /* We're done with both the temporary bfd and target. Closing
9363 + the target closes the underlying bfd, because it holds the
9364 + only remaining reference. */
9365 target_close (tmp_bfd_target, 0);
9368 diff --git a/gdb/solib.c b/gdb/solib.c
9369 index 90439ba..73773f1 100644
9374 #include "interps.h"
9375 #include "filesystem.h"
9376 +#include "gdb_bfd.h"
9378 /* Architecture-specific operations. */
9380 @@ -360,9 +361,9 @@ solib_find (char *in_pathname, int *fd)
9381 it is used as file handle to open the file. Throws an error if the file
9382 could not be opened. Handles both local and remote file access.
9384 - PATHNAME must be malloc'ed by the caller. If successful, the new BFD's
9385 - name will point to it. If unsuccessful, PATHNAME will be freed and the
9386 - FD will be closed (unless FD was -1). */
9387 + PATHNAME must be malloc'ed by the caller. It will be freed by this
9388 + function. If unsuccessful, the FD will be closed (unless FD was
9392 solib_bfd_fopen (char *pathname, int fd)
9393 @@ -376,7 +377,7 @@ solib_bfd_fopen (char *pathname, int fd)
9397 - abfd = bfd_fopen (pathname, gnutarget, FOPEN_RB, fd);
9398 + abfd = gdb_bfd_fopen (pathname, gnutarget, FOPEN_RB, fd);
9401 bfd_set_cacheable (abfd, 1);
9402 @@ -389,6 +390,8 @@ solib_bfd_fopen (char *pathname, int fd)
9403 pathname, bfd_errmsg (bfd_get_error ()));
9411 @@ -420,17 +423,16 @@ solib_bfd_open (char *pathname)
9412 /* Check bfd format. */
9413 if (!bfd_check_format (abfd, bfd_object))
9416 - make_cleanup (xfree, found_pathname);
9417 + make_cleanup_bfd_unref (abfd);
9418 error (_("`%s': not in executable format: %s"),
9419 - found_pathname, bfd_errmsg (bfd_get_error ()));
9420 + bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
9423 /* Check bfd arch. */
9424 b = gdbarch_bfd_arch_info (target_gdbarch);
9425 if (!b->compatible (b, bfd_get_arch_info (abfd)))
9426 warning (_("`%s': Shared library architecture %s is not compatible "
9427 - "with target architecture %s."), found_pathname,
9428 + "with target architecture %s."), bfd_get_filename (abfd),
9429 bfd_get_arch_info (abfd)->printable_name, b->printable_name);
9432 @@ -466,7 +468,7 @@ solib_map_sections (struct so_list *so)
9435 /* Leave bfd open, core_xfer_memory and "info files" need it. */
9436 - so->abfd = gdb_bfd_ref (abfd);
9439 /* copy full path name into so_name, so that later symbol_file_add
9441 @@ -1233,7 +1235,7 @@ reload_shared_libraries_1 (int from_tty)
9443 found_pathname = xstrdup (bfd_get_filename (abfd));
9444 make_cleanup (xfree, found_pathname);
9445 - gdb_bfd_close_or_warn (abfd);
9446 + gdb_bfd_unref (abfd);
9449 /* If this shared library is no longer associated with its previous
9450 diff --git a/gdb/spu-linux-nat.c b/gdb/spu-linux-nat.c
9451 index 2dfec8c..999f1ab 100644
9452 --- a/gdb/spu-linux-nat.c
9453 +++ b/gdb/spu-linux-nat.c
9454 @@ -315,16 +315,16 @@ spu_bfd_open (ULONGEST addr)
9455 ULONGEST *open_closure = xmalloc (sizeof (ULONGEST));
9456 *open_closure = addr;
9458 - nbfd = bfd_openr_iovec (xstrdup ("<in-memory>"), "elf32-spu",
9459 - spu_bfd_iovec_open, open_closure,
9460 - spu_bfd_iovec_pread, spu_bfd_iovec_close,
9461 - spu_bfd_iovec_stat);
9462 + nbfd = gdb_bfd_openr_iovec ("<in-memory>", "elf32-spu",
9463 + spu_bfd_iovec_open, open_closure,
9464 + spu_bfd_iovec_pread, spu_bfd_iovec_close,
9465 + spu_bfd_iovec_stat);
9469 if (!bfd_check_format (nbfd, bfd_object))
9472 + gdb_bfd_unref (nbfd);
9476 @@ -374,8 +374,13 @@ spu_symbol_file_add_from_memory (int inferior_fd)
9477 /* Open BFD representing SPE executable and read its symbols. */
9478 nbfd = spu_bfd_open (addr);
9480 - symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
9483 + struct cleanup *cleanup = make_cleanup_bfd_unref (nbfd);
9485 + symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
9487 + do_cleanups (cleanup);
9492 diff --git a/gdb/stack.c b/gdb/stack.c
9493 index 35d379d..04aab5e 100644
9496 @@ -509,6 +509,10 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
9497 stb = mem_fileopen ();
9498 old_chain = make_cleanup_ui_file_delete (stb);
9500 + /* Frame may be needed for check_typedef of TYPE_DYNAMIC. */
9501 + make_cleanup_restore_selected_frame ();
9502 + select_frame (frame);
9506 struct block *b = SYMBOL_BLOCK_VALUE (func);
9507 diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
9508 index e80fd25..2e53be0 100644
9509 --- a/gdb/symfile-mem.c
9510 +++ b/gdb/symfile-mem.c
9512 #include "observer.h"
9514 #include "elf/common.h"
9515 +#include "gdb_bfd.h"
9517 /* Verify parameters of target_read_memory_bfd and target_read_memory are
9519 @@ -100,23 +101,24 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name,
9521 error (_("Failed to read a valid object file image from memory."));
9523 + gdb_bfd_ref (nbfd);
9525 - nbfd->filename = xstrdup ("shared object read from target memory");
9526 + nbfd->filename = "shared object read from target memory";
9528 - nbfd->filename = name;
9530 - if (!bfd_check_format (nbfd, bfd_object))
9532 - /* FIXME: should be checking for errors from bfd_close (for one thing,
9533 - on error it does not free all the storage associated with the
9536 - error (_("Got object file from memory but can't read symbols: %s."),
9537 - bfd_errmsg (bfd_get_error ()));
9538 + nbfd->filename = name;
9539 + gdb_bfd_stash_filename (nbfd);
9543 + cleanup = make_cleanup_bfd_unref (nbfd);
9545 + if (!bfd_check_format (nbfd, bfd_object))
9546 + error (_("Got object file from memory but can't read symbols: %s."),
9547 + bfd_errmsg (bfd_get_error ()));
9549 sai = alloc_section_addr_info (bfd_count_sections (nbfd));
9550 - cleanup = make_cleanup (xfree, sai);
9551 + make_cleanup (xfree, sai);
9553 for (sec = nbfd->sections; sec != NULL; sec = sec->next)
9554 if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
9555 diff --git a/gdb/symfile.c b/gdb/symfile.c
9556 index 01252e2..95ed480 100644
9563 +#include "gdb_bfd.h"
9565 #include <sys/types.h>
9567 @@ -1036,7 +1037,7 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
9570 ABFD is a BFD already open on the file, as from symfile_bfd_open.
9571 - This BFD will be closed on error, and is always consumed by this function.
9572 + A new reference is acquired by this function.
9574 ADD_FLAGS encodes verbosity, whether this is main symbol file or
9575 extra, such as dynamically loaded code, and what to do with breakpoins.
9576 @@ -1060,7 +1061,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
9577 int flags, struct objfile *parent)
9579 struct objfile *objfile;
9580 - struct cleanup *my_cleanups;
9581 const char *name = bfd_get_filename (abfd);
9582 const int from_tty = add_flags & SYMFILE_VERBOSE;
9583 const int mainline = add_flags & SYMFILE_MAINLINE;
9584 @@ -1074,8 +1074,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
9585 add_flags &= ~SYMFILE_NO_READ;
9588 - my_cleanups = make_cleanup_bfd_close (abfd);
9590 /* Give user a chance to burp if we'd be
9591 interactively wiping out any existing symbols. */
9593 @@ -1086,7 +1084,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
9594 error (_("Not confirmed."));
9596 objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0));
9597 - discard_cleanups (my_cleanups);
9600 add_separate_debug_objfile (objfile, parent);
9601 @@ -1207,8 +1204,13 @@ struct objfile *
9602 symbol_file_add (char *name, int add_flags, struct section_addr_info *addrs,
9605 - return symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs,
9607 + bfd *bfd = symfile_bfd_open (name);
9608 + struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
9609 + struct objfile *objf;
9611 + objf = symbol_file_add_from_bfd (bfd, add_flags, addrs, flags, NULL);
9612 + do_cleanups (cleanup);
9617 @@ -1350,7 +1352,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
9618 if (filename_cmp (name, parent_objfile->name) == 0)
9621 - abfd = bfd_open_maybe_remote (name);
9622 + abfd = gdb_bfd_open_maybe_remote (name);
9626 @@ -1372,7 +1374,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
9627 if (abfd_stat.st_dev == parent_stat.st_dev
9628 && abfd_stat.st_ino == parent_stat.st_ino)
9631 + gdb_bfd_unref (abfd);
9634 verified_as_different = 1;
9635 @@ -1382,7 +1384,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
9637 file_crc_p = get_file_crc (abfd, &file_crc);
9640 + gdb_bfd_unref (abfd);
9644 @@ -1690,15 +1692,20 @@ set_initial_language (void)
9647 /* If NAME is a remote name open the file using remote protocol, otherwise
9648 - open it normally. */
9649 + open it normally. Returns a new reference to the BFD. On error,
9650 + returns NULL with the BFD error set. */
9653 -bfd_open_maybe_remote (const char *name)
9654 +gdb_bfd_open_maybe_remote (const char *name)
9658 if (remote_filename_p (name))
9659 - return remote_bfd_open (name, gnutarget);
9660 + result = remote_bfd_open (name, gnutarget);
9662 - return bfd_openr (name, gnutarget);
9663 + result = gdb_bfd_openr (name, gnutarget);
9669 @@ -1716,19 +1723,14 @@ symfile_bfd_open (char *name)
9671 if (remote_filename_p (name))
9673 - name = xstrdup (name);
9674 sym_bfd = remote_bfd_open (name, gnutarget);
9677 - make_cleanup (xfree, name);
9678 - error (_("`%s': can't open to read symbols: %s."), name,
9679 - bfd_errmsg (bfd_get_error ()));
9681 + error (_("`%s': can't open to read symbols: %s."), name,
9682 + bfd_errmsg (bfd_get_error ()));
9684 if (!bfd_check_format (sym_bfd, bfd_object))
9686 - bfd_close (sym_bfd);
9687 - make_cleanup (xfree, name);
9688 + make_cleanup_bfd_unref (sym_bfd);
9689 error (_("`%s': can't read symbols: %s."), name,
9690 bfd_errmsg (bfd_get_error ()));
9692 @@ -1757,12 +1759,11 @@ symfile_bfd_open (char *name)
9693 perror_with_name (name);
9696 - /* Free 1st new malloc'd copy, but keep the 2nd malloc'd copy in
9697 - bfd. It'll be freed in free_objfile(). */
9699 name = absolute_name;
9700 + make_cleanup (xfree, name);
9702 - sym_bfd = bfd_fopen (name, gnutarget, FOPEN_RB, desc);
9703 + sym_bfd = gdb_bfd_fopen (name, gnutarget, FOPEN_RB, desc);
9706 make_cleanup (xfree, name);
9707 @@ -1773,18 +1774,11 @@ symfile_bfd_open (char *name)
9709 if (!bfd_check_format (sym_bfd, bfd_object))
9711 - /* FIXME: should be checking for errors from bfd_close (for one
9712 - thing, on error it does not free all the storage associated
9714 - bfd_close (sym_bfd); /* This also closes desc. */
9715 - make_cleanup (xfree, name);
9716 + make_cleanup_bfd_unref (sym_bfd);
9717 error (_("`%s': can't read symbols: %s."), name,
9718 bfd_errmsg (bfd_get_error ()));
9721 - /* bfd_usrdata exists for applications and libbfd must not touch it. */
9722 - gdb_assert (bfd_usrdata (sym_bfd) == NULL);
9727 @@ -2109,17 +2103,14 @@ generic_load (char *args, int from_tty)
9730 /* Open the file for loading. */
9731 - loadfile_bfd = bfd_openr (filename, gnutarget);
9732 + loadfile_bfd = gdb_bfd_openr (filename, gnutarget);
9733 if (loadfile_bfd == NULL)
9735 perror_with_name (filename);
9739 - /* FIXME: should be checking for errors from bfd_close (for one thing,
9740 - on error it does not free all the storage associated with the
9742 - make_cleanup_bfd_close (loadfile_bfd);
9743 + make_cleanup_bfd_unref (loadfile_bfd);
9745 if (!bfd_check_format (loadfile_bfd, bfd_object))
9747 @@ -2518,15 +2509,18 @@ reread_symbols (void)
9748 /* Clean up any state BFD has sitting around. We don't need
9749 to close the descriptor but BFD lacks a way of closing the
9750 BFD without closing the descriptor. */
9751 - obfd_filename = bfd_get_filename (objfile->obfd);
9752 - if (!bfd_close (objfile->obfd))
9753 - error (_("Can't close BFD for %s: %s"), objfile->name,
9754 - bfd_errmsg (bfd_get_error ()));
9755 - objfile->obfd = bfd_open_maybe_remote (obfd_filename);
9757 + struct bfd *obfd = objfile->obfd;
9759 + obfd_filename = bfd_get_filename (objfile->obfd);
9760 + /* Open the new BFD before freeing the old one, so that
9761 + the filename remains live. */
9762 + objfile->obfd = gdb_bfd_open_maybe_remote (obfd_filename);
9763 + gdb_bfd_unref (obfd);
9766 if (objfile->obfd == NULL)
9767 error (_("Can't open %s to read symbols."), objfile->name);
9769 - objfile->obfd = gdb_bfd_ref (objfile->obfd);
9770 /* bfd_openr sets cacheable to true, which is what we want. */
9771 if (!bfd_check_format (objfile->obfd, bfd_object))
9772 error (_("Can't read symbols from %s: %s."), objfile->name,
9773 diff --git a/gdb/symfile.h b/gdb/symfile.h
9774 index aca7359..184a83e 100644
9777 @@ -553,7 +553,7 @@ extern void find_lowest_section (bfd *, asection *, void *);
9779 extern bfd *symfile_bfd_open (char *);
9781 -extern bfd *bfd_open_maybe_remote (const char *);
9782 +extern bfd *gdb_bfd_open_maybe_remote (const char *);
9784 extern int get_section_index (struct objfile *, char *);
9786 diff --git a/gdb/testsuite/gdb.ada/packed_array.exp b/gdb/testsuite/gdb.ada/packed_array.exp
9787 index 678639c..47a2202 100644
9788 --- a/gdb/testsuite/gdb.ada/packed_array.exp
9789 +++ b/gdb/testsuite/gdb.ada/packed_array.exp
9790 @@ -60,5 +60,11 @@ gdb_test_multiple "$test" "$test" {
9791 # are. Observed with (FSF GNU Ada 4.5.3 20110124).
9794 + -re "= \\(\\)\[\r\n\]+$gdb_prompt $" {
9795 + # archer-jankratochvil-vla resolves it as a dynamic type resolved as an
9796 + # empty array [0..-1].
9797 + # DW_AT_upper_bound : (DW_OP_fbreg: -48; DW_OP_deref)
9802 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
9803 new file mode 100644
9804 index 0000000..83faaf6
9806 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
9808 + .file "x86_64-vla-pointer.c"
9809 + .section .debug_abbrev,"",@progbits
9811 + .section .debug_info,"",@progbits
9813 + .section .debug_line,"",@progbits
9818 + .type foo, @function
9821 + .file 1 "x86_64-vla-pointer.c"
9829 + movl %edi, -36(%rbp)
9832 + movq %rax, -48(%rbp)
9834 + movl -36(%rbp), %edx
9837 + movq %rax, -24(%rbp)
9845 + movq %rsp, -56(%rbp)
9846 + movq -56(%rbp), %rax
9850 + movq %rax, -56(%rbp)
9851 + movq -56(%rbp), %rax
9852 + movq %rax, -16(%rbp)
9858 + movl -4(%rbp), %esi
9859 + movl -4(%rbp), %eax
9861 + movq -16(%rbp), %rdx
9863 + movb %cl, (%rdx,%rax)
9867 + movl -4(%rbp), %eax
9868 + cmpl -36(%rbp), %eax
9873 + movq -16(%rbp), %rax
9875 + movq -48(%rbp), %rsp
9881 + .section .debug_frame,"",@progbits
9883 + .long .LECIE0-.LSCIE0
9899 + .long .LEFDE0-.LASFDE0
9905 + .long .LCFI0-.LFB2
9911 + .long .LCFI1-.LCFI0
9916 + .section .eh_frame,"a",@progbits
9918 + .long .LECIE1-.LSCIE1
9936 + .long .LEFDE1-.LASFDE1
9938 + .long .LASFDE1-.Lframe1
9943 + .long .LCFI0-.LFB2
9949 + .long .LCFI1-.LCFI0
9956 + .section .debug_loc,"",@progbits
9959 + .quad .LFB2-.Ltext0
9960 + .quad .LCFI0-.Ltext0
9964 + .quad .LCFI0-.Ltext0
9965 + .quad .LCFI1-.Ltext0
9969 + .quad .LCFI1-.Ltext0
9970 + .quad .LFE2-.Ltext0
9976 + .section .debug_info
9978 + .long .Ldebug_end - .Ldebug_start
9981 + .long .Ldebug_abbrev0
9990 + .long .Ldebug_line0
10000 + .long .Ltype_int - .Ldebug_relative
10005 + .long .Ltype_int - .Ldebug_relative
10011 + .byte 0x8 /* DW_AT_byte_size */
10012 + .long .Ltag_array_type - .debug_info /* DW_AT_type */
10013 + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */
10018 + .long .Ltag_pointer - .debug_info
10020 + /* Debugging only: Skip the typedef indirection. */
10021 + .long .Ltag_array_type - .debug_info
10023 + /* DW_AT_location: DW_FORM_block1: start */
10028 + .byte 0x6 /* DW_OP_deref */
10030 + .byte 0x96 /* DW_OP_nop */
10032 + /* DW_AT_location: DW_FORM_block1: end */
10037 + .long .Ltype_int - .Ldebug_relative
10048 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
10049 + .long .Ltype_char - .Ldebug_relative
10050 + .long .Ltype_ulong - .Ldebug_relative /* DW_AT_sibling: DW_FORM_ref4 */
10051 +1: /* DW_AT_data_location: DW_FORM_block1: start */
10052 + .byte 2f - 3f /* length */
10054 + .byte 0x97 /* DW_OP_push_object_address */
10056 + .byte 0x6 /* DW_OP_deref */
10058 + .byte 0x96 /* DW_OP_nop */
10060 +2: /* DW_AT_data_location: DW_FORM_block1: end */
10062 + .long .Ltype_char - .Ldebug_relative /* DW_AT_type: DW_FORM_ref4 */
10079 + .section .debug_abbrev
10137 + .uleb128 0x4 /* .Ltag_pointer abbrev */
10138 + .uleb128 0x0f /* DW_TAG_pointer_type */
10187 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
10190 + .uleb128 0x49 /* DW_AT_type */
10191 + .uleb128 0x13 /* DW_FORM_ref4 */
10192 + .uleb128 0x1 /* DW_AT_sibling */
10193 + .uleb128 0x13 /* DW_FORM_ref4 */
10194 + .uleb128 0x50 /* DW_AT_data_location */
10195 + .uleb128 0xa /* DW_FORM_block1 */
10201 + .uleb128 0x49 /* DW_AT_type */
10202 + .uleb128 0x13 /* DW_FORM_ref4 */
10228 + .section .debug_pubnames,"",@progbits
10231 + .long .Ldebug_info0
10236 + .section .debug_aranges,"",@progbits
10239 + .long .Ldebug_info0
10245 + .quad .Letext0-.Ltext0
10248 + .section .debug_str,"MS",@progbits,1
10254 + .string "x86_64-vla-pointer.c"
10256 + .string "array_t"
10260 + .string "gdb.arch"
10262 + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
10263 + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
10264 + .section .note.GNU-stack,"",@progbits
10265 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
10266 new file mode 100644
10267 index 0000000..fe2c8f7
10269 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
10271 +/* This testcase is part of GDB, the GNU debugger.
10273 + Copyright 2009 Free Software Foundation, Inc.
10275 + This program is free software; you can redistribute it and/or modify
10276 + it under the terms of the GNU General Public License as published by
10277 + the Free Software Foundation; either version 3 of the License, or
10278 + (at your option) any later version.
10280 + This program is distributed in the hope that it will be useful,
10281 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10282 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10283 + GNU General Public License for more details.
10285 + You should have received a copy of the GNU General Public License
10286 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
10293 + typedef char array_t[size];
10297 + for (i = 0; i < size; i++)
10300 + array[0] = 0; /* break-here */
10314 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
10315 new file mode 100644
10316 index 0000000..d243cf1
10318 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
10320 +# Copyright 2009 Free Software Foundation, Inc.
10322 +# This program is free software; you can redistribute it and/or modify
10323 +# it under the terms of the GNU General Public License as published by
10324 +# the Free Software Foundation; either version 3 of the License, or
10325 +# (at your option) any later version.
10327 +# This program is distributed in the hope that it will be useful,
10328 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
10329 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10330 +# GNU General Public License for more details.
10332 +# You should have received a copy of the GNU General Public License
10333 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
10335 +if ![istarget "x86_64-*-*"] then {
10336 + verbose "Skipping over gdb.arch/x86_64-vla-pointer.exp test made only for x86_64."
10340 +set testfile x86_64-vla-pointer
10341 +set srcasmfile ${testfile}-foo.S
10342 +set srcfile ${testfile}.c
10343 +set binfile ${objdir}/${subdir}/${testfile}
10344 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
10345 +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
10346 + untested "Couldn't compile test program"
10349 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
10350 + untested "Couldn't compile test program"
10356 +gdb_reinitialize_dir $srcdir/$subdir
10357 +gdb_load ${binfile}
10359 +if ![runto_main] {
10360 + untested x86_64-vla-pointer
10364 +gdb_breakpoint "break_here"
10366 +gdb_continue_to_breakpoint "break_here"
10368 +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array"
10369 +gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array"
10371 +gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array"
10372 +gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array"
10374 +gdb_test "p (*array)\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
10375 +gdb_test "p (*array)\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
10376 +gdb_test "p (*array)\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
10377 +gdb_test "p (*array)\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
10379 +gdb_continue_to_breakpoint "break_here"
10381 +gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array"
10382 +gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array"
10384 +gdb_test "whatis *array" "type = char \\\[78\\\]" "second: whatis *array"
10385 +gdb_test "ptype *array" "type = char \\\[78\\\]" "second: ptype *array"
10386 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
10387 new file mode 100644
10388 index 0000000..66f7a39
10390 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
10392 + .file "x86_64-vla-typedef.c"
10393 + .section .debug_abbrev,"",@progbits
10395 + .section .debug_info,"",@progbits
10397 + .section .debug_line,"",@progbits
10402 + .type foo, @function
10405 + .file 1 "x86_64-vla-typedef.c"
10413 + movl %edi, -36(%rbp)
10416 + movq %rax, -48(%rbp)
10418 + movl -36(%rbp), %edx
10421 + movq %rax, -24(%rbp)
10429 + movq %rsp, -56(%rbp)
10430 + movq -56(%rbp), %rax
10434 + movq %rax, -56(%rbp)
10435 + movq -56(%rbp), %rax
10436 + movq %rax, -16(%rbp)
10438 + movl $0, -4(%rbp)
10442 + movl -4(%rbp), %esi
10443 + movl -4(%rbp), %eax
10445 + movq -16(%rbp), %rdx
10447 + movb %cl, (%rdx,%rax)
10449 + addl $1, -4(%rbp)
10451 + movl -4(%rbp), %eax
10452 + cmpl -36(%rbp), %eax
10455 + .globl break_here
10457 + movq -16(%rbp), %rax
10459 + movq -48(%rbp), %rsp
10465 + .section .debug_frame,"",@progbits
10467 + .long .LECIE0-.LSCIE0
10483 + .long .LEFDE0-.LASFDE0
10487 + .quad .LFE2-.LFB2
10489 + .long .LCFI0-.LFB2
10495 + .long .LCFI1-.LCFI0
10500 + .section .eh_frame,"a",@progbits
10502 + .long .LECIE1-.LSCIE1
10520 + .long .LEFDE1-.LASFDE1
10522 + .long .LASFDE1-.Lframe1
10524 + .long .LFE2-.LFB2
10527 + .long .LCFI0-.LFB2
10533 + .long .LCFI1-.LCFI0
10540 + .section .debug_loc,"",@progbits
10543 + .quad .LFB2-.Ltext0
10544 + .quad .LCFI0-.Ltext0
10548 + .quad .LCFI0-.Ltext0
10549 + .quad .LCFI1-.Ltext0
10553 + .quad .LCFI1-.Ltext0
10554 + .quad .LFE2-.Ltext0
10560 + .section .debug_info
10561 + .long .Ldebug_end - .Ldebug_start
10564 + .long .Ldebug_abbrev0
10573 + .long .Ldebug_line0
10597 + .long .Ltag_array_type - .debug_info
10598 + .uleb128 0x5 /* Abbrev Number: 5 (DW_TAG_variable) */
10603 + .long .Ltag_typedef - .debug_info
10605 + /* Debugging only: Skip the typedef indirection. */
10606 + .long .Ltag_array_type - .debug_info
10608 + /* DW_AT_location: DW_FORM_block1: start */
10613 + .byte 0x6 /* DW_OP_deref */
10615 + .byte 0x96 /* DW_OP_nop */
10617 + /* DW_AT_location: DW_FORM_block1: end */
10632 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
10633 + .long 0xa0 + (2f - 1f) /* DW_AT_type: DW_FORM_ref4 */
10634 + .long 0x9d + (2f - 1f) /* DW_AT_sibling: DW_FORM_ref4 */
10635 +1: /* DW_AT_data_location: DW_FORM_block1: start */
10636 + .byte 2f - 3f /* length */
10638 + .byte 0x97 /* DW_OP_push_object_address */
10639 + .byte 0x6 /* DW_OP_deref */
10640 +2: /* DW_AT_data_location: DW_FORM_block1: end */
10642 + .long 0x9d + (2b - 1b) /* DW_AT_type: DW_FORM_ref4 */
10657 + .section .debug_abbrev
10769 + .uleb128 0x8 /* Abbrev Number: 8 (DW_TAG_array_type) */
10772 + .uleb128 0x49 /* DW_AT_type */
10773 + .uleb128 0x13 /* DW_FORM_ref4 */
10774 + .uleb128 0x1 /* DW_AT_sibling */
10775 + .uleb128 0x13 /* DW_FORM_ref4 */
10776 + .uleb128 0x50 /* DW_AT_data_location */
10777 + .uleb128 0xa /* DW_FORM_block1 */
10783 + .uleb128 0x49 /* DW_AT_type */
10784 + .uleb128 0x13 /* DW_FORM_ref4 */
10810 + .section .debug_pubnames,"",@progbits
10813 + .long .Ldebug_info0
10818 + .section .debug_aranges,"",@progbits
10821 + .long .Ldebug_info0
10827 + .quad .Letext0-.Ltext0
10830 + .section .debug_str,"MS",@progbits,1
10836 + .string "x86_64-vla-typedef.c"
10838 + .string "array_t"
10842 + .string "gdb.arch"
10844 + .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
10845 + .ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
10846 + .section .note.GNU-stack,"",@progbits
10847 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
10848 new file mode 100644
10849 index 0000000..b809c4e
10851 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
10853 +/* This testcase is part of GDB, the GNU debugger.
10855 + Copyright 2008 Free Software Foundation, Inc.
10857 + This program is free software; you can redistribute it and/or modify
10858 + it under the terms of the GNU General Public License as published by
10859 + the Free Software Foundation; either version 3 of the License, or
10860 + (at your option) any later version.
10862 + This program is distributed in the hope that it will be useful,
10863 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10864 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10865 + GNU General Public License for more details.
10867 + You should have received a copy of the GNU General Public License
10868 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
10875 + typedef char array_t[size];
10879 + for (i = 0; i < size; i++)
10882 + array[0] = 0; /* break-here */
10896 diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
10897 new file mode 100644
10898 index 0000000..b05411e
10900 +++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
10902 +# Copyright 2009 Free Software Foundation, Inc.
10904 +# This program is free software; you can redistribute it and/or modify
10905 +# it under the terms of the GNU General Public License as published by
10906 +# the Free Software Foundation; either version 3 of the License, or
10907 +# (at your option) any later version.
10909 +# This program is distributed in the hope that it will be useful,
10910 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
10911 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10912 +# GNU General Public License for more details.
10914 +# You should have received a copy of the GNU General Public License
10915 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
10917 +# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
10919 +if ![istarget "x86_64-*-*"] then {
10920 + verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
10924 +set testfile x86_64-vla-typedef
10925 +set srcasmfile ${testfile}-foo.S
10926 +set srcfile ${testfile}.c
10927 +set binfile ${objdir}/${subdir}/${testfile}
10928 +set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
10929 +if { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
10930 + untested "Couldn't compile test program"
10933 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
10934 + untested "Couldn't compile test program"
10940 +gdb_reinitialize_dir $srcdir/$subdir
10941 +gdb_load ${binfile}
10943 +if ![runto_main] {
10944 + untested x86_64-vla-typedef
10948 +gdb_breakpoint "break_here"
10950 +gdb_continue_to_breakpoint "break_here"
10952 +gdb_test "whatis array" "type = array_t" "first: whatis array"
10954 +gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
10956 +gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
10957 +gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
10958 +gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
10959 +gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
10961 +gdb_continue_to_breakpoint "break_here"
10963 +gdb_test "whatis array" "type = array_t" "second: whatis array"
10965 +gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
10966 diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
10967 index a99137e..c3dc2d9 100644
10968 --- a/gdb/testsuite/gdb.base/arrayidx.c
10969 +++ b/gdb/testsuite/gdb.base/arrayidx.c
10972 int array[] = {1, 2, 3, 4};
10984 diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
10985 index cba0024..0dc0e46 100644
10986 --- a/gdb/testsuite/gdb.base/arrayidx.exp
10987 +++ b/gdb/testsuite/gdb.base/arrayidx.exp
10988 @@ -53,4 +53,12 @@ gdb_test "print array" \
10989 "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
10990 "Print array with array-indexes on"
10993 +set test "p unbound.a == &unbound.a\[0\]"
10994 +gdb_test_multiple $test $test {
10995 + -re " = 1\r\n$gdb_prompt $" {
10998 + -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
10999 + unsupported "$test (no GCC)"
11002 diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.c b/gdb/testsuite/gdb.base/internal-var-field-address.c
11003 new file mode 100644
11004 index 0000000..eeb7b85
11006 +++ b/gdb/testsuite/gdb.base/internal-var-field-address.c
11008 +/* This testcase is part of GDB, the GNU debugger.
11010 + Copyright 2009 Free Software Foundation, Inc.
11012 + This program is free software; you can redistribute it and/or modify
11013 + it under the terms of the GNU General Public License as published by
11014 + the Free Software Foundation; either version 3 of the License, or
11015 + (at your option) any later version.
11017 + This program is distributed in the hope that it will be useful,
11018 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11019 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11020 + GNU General Public License for more details.
11022 + You should have received a copy of the GNU General Public License
11023 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11027 +} staticstruct = { 1 };
11028 diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.exp b/gdb/testsuite/gdb.base/internal-var-field-address.exp
11029 new file mode 100644
11030 index 0000000..6d82e73
11032 +++ b/gdb/testsuite/gdb.base/internal-var-field-address.exp
11034 +# Copyright 2009 Free Software Foundation, Inc.
11036 +# This program is free software; you can redistribute it and/or modify
11037 +# it under the terms of the GNU General Public License as published by
11038 +# the Free Software Foundation; either version 3 of the License, or
11039 +# (at your option) any later version.
11041 +# This program is distributed in the hope that it will be useful,
11042 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11043 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11044 +# GNU General Public License for more details.
11046 +# You should have received a copy of the GNU General Public License
11047 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11049 +set test internal-var-field-address
11050 +set binfile ${test}.x
11051 +if { [gdb_compile "${srcdir}/${subdir}/${test}.c" "${objdir}/${subdir}/${binfile}" object {debug}] != "" } {
11052 + untested "Couldn't compile test program"
11056 +clean_restart $binfile
11058 +gdb_test {set $varstruct = staticstruct}
11059 +gdb_test {p $varstruct.field} " = 1"
11060 diff --git a/gdb/testsuite/gdb.base/vla-frame.c b/gdb/testsuite/gdb.base/vla-frame.c
11061 new file mode 100644
11062 index 0000000..5750f68
11064 +++ b/gdb/testsuite/gdb.base/vla-frame.c
11066 +/* This testcase is part of GDB, the GNU debugger.
11068 + Copyright 2011 Free Software Foundation, Inc.
11070 + This program is free software; you can redistribute it and/or modify
11071 + it under the terms of the GNU General Public License as published by
11072 + the Free Software Foundation; either version 3 of the License, or
11073 + (at your option) any later version.
11075 + This program is distributed in the hope that it will be useful,
11076 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11077 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11078 + GNU General Public License for more details.
11080 + You should have received a copy of the GNU General Public License
11081 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11083 +#include <string.h>
11086 +main (int argc, char **argv)
11088 + char s[2 + argc];
11089 + void (*f) (char *) = 0;
11091 + memset (s, 0, sizeof (s));
11097 diff --git a/gdb/testsuite/gdb.base/vla-frame.exp b/gdb/testsuite/gdb.base/vla-frame.exp
11098 new file mode 100644
11099 index 0000000..47736c7
11101 +++ b/gdb/testsuite/gdb.base/vla-frame.exp
11103 +# Copyright 2011 Free Software Foundation, Inc.
11105 +# This program is free software; you can redistribute it and/or modify
11106 +# it under the terms of the GNU General Public License as published by
11107 +# the Free Software Foundation; either version 3 of the License, or
11108 +# (at your option) any later version.
11110 +# This program is distributed in the hope that it will be useful,
11111 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11112 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11113 +# GNU General Public License for more details.
11115 +# You should have received a copy of the GNU General Public License
11116 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11118 +set testfile vla-frame
11119 +set executable ${testfile}
11121 +if { [prepare_for_testing ${testfile}.exp ${executable}] } {
11125 +if ![runto_main] {
11129 +set test "continue"
11130 +gdb_test_multiple $test $test {
11131 + -re "Continuing\\.\r\n\r\nProgram received signal SIGSEGV, Segmentation fault\\.\r\n0x0+ in \\?\\? \\(\\)\r\n$gdb_prompt $" {
11134 + -re "\r\n$gdb_prompt $" {
11135 + untested ${testfile}.exp
11140 +gdb_test "bt full" "\r\n +s = \"X\\\\000\"\r\n.*"
11141 diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
11142 new file mode 100644
11143 index 0000000..c5d5ee0
11145 +++ b/gdb/testsuite/gdb.base/vla-overflow.c
11147 +/* This testcase is part of GDB, the GNU debugger.
11149 + Copyright 2008 Free Software Foundation, Inc.
11151 + This program is free software; you can redistribute it and/or modify
11152 + it under the terms of the GNU General Public License as published by
11153 + the Free Software Foundation; either version 3 of the License, or
11154 + (at your option) any later version.
11156 + This program is distributed in the hope that it will be useful,
11157 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11158 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11159 + GNU General Public License for more details.
11161 + You should have received a copy of the GNU General Public License
11162 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11164 +#include <stdlib.h>
11167 +main (int argc, char **argv)
11171 + array[0] = array[0];
11177 diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
11178 new file mode 100644
11179 index 0000000..24a608f
11181 +++ b/gdb/testsuite/gdb.base/vla-overflow.exp
11183 +# Copyright 2008 Free Software Foundation, Inc.
11185 +# This program is free software; you can redistribute it and/or modify
11186 +# it under the terms of the GNU General Public License as published by
11187 +# the Free Software Foundation; either version 3 of the License, or
11188 +# (at your option) any later version.
11190 +# This program is distributed in the hope that it will be useful,
11191 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11192 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11193 +# GNU General Public License for more details.
11195 +# You should have received a copy of the GNU General Public License
11196 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11198 +# We could crash in:
11199 +# #0 block_linkage_function (bl=0x0) at ../../gdb/block.c:69
11200 +# #1 in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
11201 +# 97 framefunc = block_linkage_function (get_frame_block (frame, NULL));
11202 +# #2 in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
11203 +# #3 in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
11204 +# #4 dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
11205 +# #5 in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
11206 +# #6 in create_array_type (...) at ../../gdb/gdbtypes.c:840
11208 +# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
11210 +# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
11212 +set testfile vla-overflow
11213 +set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
11214 +set srcfile ${testfile}.c
11215 +set binfile ${objdir}/${subdir}/${testfile}
11216 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
11217 + untested "Couldn't compile test program"
11221 +set f [open "|getconf PAGESIZE" "r"]
11227 +gdb_reinitialize_dir $srcdir/$subdir
11228 +gdb_load ${binfile}
11230 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
11232 +if { [runto_main] < 0 } {
11233 + untested vla-overflow
11237 +# Get the GDB memory size when we stay at main.
11239 +proc memory_v_pages_get {} {
11240 + global pid_of_gdb pagesize
11241 + set fd [open "/proc/$pid_of_gdb/statm"]
11244 + # number of pages of virtual memory
11245 + scan $line "%d" drs
11249 +set pages_found [memory_v_pages_get]
11251 +# s390x with glibc-debuginfo.s390x installed used approx. 16MB.
11253 +verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
11254 +set kb_found [expr $pages_found * $pagesize / 1024]
11255 +set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
11256 +verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
11258 +# Create the ulimit wrapper.
11259 +set f [open $shfile "w"]
11260 +puts $f "#! /bin/sh"
11261 +puts $f "ulimit -v $kb_permit"
11262 +puts $f "exec $GDB \"\$@\""
11264 +remote_exec host "chmod +x $shfile"
11272 +gdb_reinitialize_dir $srcdir/$subdir
11273 +gdb_load ${binfile}
11275 +set pid_of_gdb [exp_pid -i [board_info host fileid]]
11277 +# Check the size again after the second run.
11278 +# We must not stop in main as it would cache `array' and never crash later.
11282 +verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
11284 +gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
11286 +verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
11288 +# `abort' can get expressed as `*__GI_abort'.
11289 +gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
11291 +verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
11292 diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
11293 new file mode 100644
11294 index 0000000..e1f3ed1
11296 +++ b/gdb/testsuite/gdb.base/vla.c
11298 +/* This testcase is part of GDB, the GNU debugger.
11300 + Copyright 2008 Free Software Foundation, Inc.
11302 + This program is free software; you can redistribute it and/or modify
11303 + it under the terms of the GNU General Public License as published by
11304 + the Free Software Foundation; either version 3 of the License, or
11305 + (at your option) any later version.
11307 + This program is distributed in the hope that it will be useful,
11308 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11309 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11310 + GNU General Public License for more details.
11312 + You should have received a copy of the GNU General Public License
11313 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11315 +#include <string.h>
11323 +bar (char *a, char *b, char *c, int size)
11325 + memset (a, '1', size);
11326 + memset (b, '2', size);
11327 + memset (c, '3', 48);
11333 + char temp1[size];
11336 + temp1[size - 1] = '\0';
11338 + char temp2[size];
11340 + bar (temp1, temp2, temp3, size);
11342 + marker (); /* break-here */
11353 diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
11354 new file mode 100644
11355 index 0000000..5da7378
11357 +++ b/gdb/testsuite/gdb.base/vla.exp
11359 +# Copyright 2008 Free Software Foundation, Inc.
11361 +# This program is free software; you can redistribute it and/or modify
11362 +# it under the terms of the GNU General Public License as published by
11363 +# the Free Software Foundation; either version 3 of the License, or
11364 +# (at your option) any later version.
11366 +# This program is distributed in the hope that it will be useful,
11367 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11368 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11369 +# GNU General Public License for more details.
11371 +# You should have received a copy of the GNU General Public License
11372 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11375 +set srcfile ${testfile}.c
11376 +set binfile ${objdir}/${subdir}/${testfile}
11377 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
11378 + untested "Couldn't compile test program"
11384 +gdb_reinitialize_dir $srcdir/$subdir
11385 +gdb_load ${binfile}
11387 +if ![runto_main] {
11392 +gdb_breakpoint [gdb_get_line_number "break-here"]
11394 +gdb_continue_to_breakpoint "break-here"
11396 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
11397 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
11398 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
11400 +gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
11401 +gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
11402 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
11404 +gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
11405 +gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
11406 +gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
11408 +gdb_continue_to_breakpoint "break-here"
11410 +gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
11411 +gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
11412 +gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
11414 +gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
11415 +gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
11416 +gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
11418 +gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
11419 +gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
11420 +gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
11421 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
11422 new file mode 100644
11423 index 0000000..aac3baa
11425 +++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
11427 +/* This testcase is part of GDB, the GNU debugger.
11429 + Copyright 2010 Free Software Foundation, Inc.
11431 + This program is free software; you can redistribute it and/or modify
11432 + it under the terms of the GNU General Public License as published by
11433 + the Free Software Foundation; either version 3 of the License, or
11434 + (at your option) any later version.
11436 + This program is distributed in the hope that it will be useful,
11437 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11438 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11439 + GNU General Public License for more details.
11441 + You should have received a copy of the GNU General Public License
11442 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11444 +/* Debug information */
11446 +/* We will `break *main' at the very first instruction. */
11447 +#define main_length 1
11451 + /* See DW_OP_lit3 + 1 (0-based). */
11452 + .string "seennotseen"
11454 + .section .debug_info
11456 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
11458 + .2byte 2 /* DWARF version number */
11459 + .4byte .Ldebug_abbrev0 /* Offset Into Abbrev. Section */
11460 + .byte 4 /* Pointer Size (in bytes) */
11463 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
11464 + .4byte .Lproducer /* DW_AT_producer */
11465 + /* Use C++ to exploit a bug in parsing DW_AT_name "". */
11466 + .byte 4 /* DW_AT_language (C++) - */
11467 + .4byte main /* DW_AT_low_pc */
11468 + .byte main_length /* DW_AT_high_pc */
11471 + .uleb128 2 /* Abbrev: DW_TAG_array_type */
11472 + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
11474 + .uleb128 3 /* Abbrev: DW_TAG_subrange_type */
11475 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
11476 + .byte 0 /* DW_AT_lower_bound */
11477 + .4byte .Llen_var-.Lcu1_begin /* DW_AT_upper_bound */
11478 + .byte 0 /* End of children of die */
11480 + /* DW_AT_upper_bound is referencing an optimized-out variable. */
11482 + .uleb128 2 /* Abbrev: DW_TAG_array_type */
11483 + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
11485 + .uleb128 3 /* Abbrev: DW_TAG_subrange_type */
11486 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
11487 + .byte 0 /* DW_AT_lower_bound */
11488 + .4byte .Llenb_var-.Lcu1_begin /* DW_AT_upper_bound */
11489 + .byte 0 /* End of children of die */
11491 + /* DW_AT_upper_bound is referencing register. */
11493 + .uleb128 2 /* Abbrev: DW_TAG_array_type */
11494 + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
11496 + .uleb128 8 /* Abbrev: DW_TAG_subrange_type with block */
11497 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
11498 + .byte 0 /* DW_AT_lower_bound */
11499 + .byte 2f - 1f /* DW_AT_upper_bound */
11500 +1: .byte 0x50 /* DW_OP_reg0 */
11502 + .byte 0 /* End of children of die */
11505 + .uleb128 4 /* Abbrev: DW_TAG_base_type */
11506 + .4byte .Luint_str /* DW_AT_name */
11507 + .byte 4 /* DW_AT_byte_size */
11508 + .byte 7 /* DW_AT_encoding */
11511 + .uleb128 4 /* Abbrev: DW_TAG_base_type */
11512 + .4byte .Lchar_str /* DW_AT_name */
11513 + .byte 1 /* DW_AT_byte_size */
11514 + .byte 6 /* DW_AT_encoding */
11517 + .uleb128 5 /* Abbrev: DW_TAG_variable artificial */
11518 + .byte 1 /* DW_AT_artificial */
11519 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
11520 + .4byte .Llen_loclist-.Lloclist /* DW_AT_location */
11522 + /* optimized-out variable for b_string. */
11524 + .uleb128 7 /* Abbrev: DW_TAG_variable artificial no DW_AT_location */
11525 + .byte 1 /* DW_AT_artificial */
11526 + .4byte .Luint_type-.Lcu1_begin /* DW_AT_type */
11528 + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */
11529 + .string "a_string" /* DW_AT_name */
11530 + .4byte .Larray_type-.Lcu1_begin /* DW_AT_type */
11531 + .byte 2f - 1f /* DW_AT_location */
11532 +1: .byte 3 /* DW_OP_addr */
11533 + .4byte vardata /* <addr> */
11536 + /* DW_AT_upper_bound is referencing an optimized-out variable. */
11537 + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */
11538 + .string "b_string" /* DW_AT_name */
11539 + .4byte .Larrayb_type-.Lcu1_begin /* DW_AT_type */
11540 + .byte 2f - 1f /* DW_AT_location */
11541 +1: .byte 3 /* DW_OP_addr */
11542 + .4byte vardata /* <addr> */
11545 + /* DW_AT_upper_bound is referencing register. */
11546 + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */
11547 + .string "reg_string" /* DW_AT_name */
11548 + .4byte .Larrayreg_type-.Lcu1_begin /* DW_AT_type */
11549 + .byte 2f - 1f /* DW_AT_location */
11550 +1: .byte 3 /* DW_OP_addr */
11551 + .4byte vardata /* <addr> */
11554 + .byte 0 /* End of children of CU */
11557 + .section .debug_loc
11560 + .4byte 0 # Location list begin address
11561 + .4byte main_length # Location list end address
11562 + .value 2f-1f # Location expression size
11563 +1: .byte 0x33 # DW_OP_lit3
11564 + .byte 0x9f # DW_OP_stack_value
11566 + .quad 0x0 # Location list terminator begin (*.LLST2)
11567 + .quad 0x0 # Location list terminator end (*.LLST2)
11569 + .section .debug_abbrev
11571 + .uleb128 1 /* Abbrev code */
11572 + .uleb128 0x11 /* DW_TAG_compile_unit */
11573 + .byte 0x1 /* has_children */
11574 + .uleb128 0x25 /* DW_AT_producer */
11575 + .uleb128 0xe /* DW_FORM_strp */
11576 + .uleb128 0x13 /* DW_AT_language */
11577 + .uleb128 0xb /* DW_FORM_data1 */
11578 + .uleb128 0x11 /* DW_AT_low_pc */
11579 + .uleb128 0x1 /* DW_FORM_addr */
11580 + .uleb128 0x12 /* DW_AT_high_pc */
11581 + .uleb128 0xb /* DW_FORM_data1 */
11582 + .byte 0x0 /* Terminator */
11583 + .byte 0x0 /* Terminator */
11585 + .uleb128 2 /* Abbrev code */
11586 + .uleb128 0x1 /* TAG: DW_TAG_array_type */
11587 + .byte 0x1 /* DW_children_yes */
11588 + .uleb128 0x49 /* DW_AT_type */
11589 + .uleb128 0x13 /* DW_FORM_ref4 */
11590 + .byte 0x0 /* Terminator */
11591 + .byte 0x0 /* Terminator */
11593 + .uleb128 3 /* Abbrev code */
11594 + .uleb128 0x21 /* DW_TAG_subrange_type */
11595 + .byte 0x0 /* no children */
11596 + .uleb128 0x49 /* DW_AT_type */
11597 + .uleb128 0x13 /* DW_FORM_ref4 */
11598 + .uleb128 0x22 /* DW_AT_lower_bound */
11599 + .uleb128 0xb /* DW_FORM_data1 */
11600 + .uleb128 0x2f /* DW_AT_upper_bound */
11601 + .uleb128 0x13 /* DW_FORM_ref4 */
11602 + .byte 0x0 /* Terminator */
11603 + .byte 0x0 /* Terminator */
11605 + .uleb128 4 /* Abbrev code */
11606 + .uleb128 0x24 /* DW_TAG_base_type */
11607 + .byte 0x0 /* no_children */
11608 + .uleb128 0x3 /* DW_AT_name */
11609 + .uleb128 0xe /* DW_FORM_strp */
11610 + .uleb128 0xb /* DW_AT_byte_size */
11611 + .uleb128 0xb /* DW_FORM_data1 */
11612 + .uleb128 0x3e /* DW_AT_encoding */
11613 + .uleb128 0xb /* DW_FORM_data1 */
11614 + .byte 0x0 /* Terminator */
11615 + .byte 0x0 /* Terminator */
11617 + .uleb128 5 /* Abbrev code */
11618 + .uleb128 0x34 /* DW_TAG_variable */
11619 + .byte 0x0 /* no_children */
11620 + .uleb128 0x34 /* DW_AT_artificial */
11621 + .uleb128 0x0c /* DW_FORM_flag */
11622 + .uleb128 0x49 /* DW_AT_type */
11623 + .uleb128 0x13 /* DW_FORM_ref4 */
11624 + .uleb128 0x02 /* DW_AT_location */
11625 + .uleb128 0x06 /* DW_FORM_data4 */
11626 + .byte 0x0 /* Terminator */
11627 + .byte 0x0 /* Terminator */
11629 + .uleb128 6 /* Abbrev code */
11630 + .uleb128 0x34 /* DW_TAG_variable */
11631 + .byte 0x0 /* no_children */
11632 + .uleb128 0x3 /* DW_AT_name */
11633 + .uleb128 0x8 /* DW_FORM_string */
11634 + .uleb128 0x49 /* DW_AT_type */
11635 + .uleb128 0x13 /* DW_FORM_ref4 */
11636 + .uleb128 0x2 /* DW_AT_location */
11637 + .uleb128 0xa /* DW_FORM_block1 */
11638 + .byte 0x0 /* Terminator */
11639 + .byte 0x0 /* Terminator */
11641 + .uleb128 7 /* Abbrev code */
11642 + .uleb128 0x34 /* DW_TAG_variable */
11643 + .byte 0x0 /* no_children */
11644 + .uleb128 0x34 /* DW_AT_artificial */
11645 + .uleb128 0x0c /* DW_FORM_flag */
11646 + .uleb128 0x49 /* DW_AT_type */
11647 + .uleb128 0x13 /* DW_FORM_ref4 */
11648 + .byte 0x0 /* Terminator */
11649 + .byte 0x0 /* Terminator */
11651 + .uleb128 8 /* Abbrev code */
11652 + .uleb128 0x21 /* DW_TAG_subrange_type with block */
11653 + .byte 0x0 /* no children */
11654 + .uleb128 0x49 /* DW_AT_type */
11655 + .uleb128 0x13 /* DW_FORM_ref4 */
11656 + .uleb128 0x22 /* DW_AT_lower_bound */
11657 + .uleb128 0xb /* DW_FORM_data1 */
11658 + .uleb128 0x2f /* DW_AT_upper_bound */
11659 + .uleb128 0xa /* DW_FORM_block1 */
11660 + .byte 0x0 /* Terminator */
11661 + .byte 0x0 /* Terminator */
11663 + .byte 0x0 /* Terminator */
11665 +/* String table */
11666 + .section .debug_str
11668 + .string "GNU C 3.3.3"
11672 + .string "unsigned int"
11673 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
11674 new file mode 100644
11675 index 0000000..815ed93
11677 +++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
11679 +# Copyright 2010 Free Software Foundation, Inc.
11681 +# This program is free software; you can redistribute it and/or modify
11682 +# it under the terms of the GNU General Public License as published by
11683 +# the Free Software Foundation; either version 3 of the License, or
11684 +# (at your option) any later version.
11686 +# This program is distributed in the hope that it will be useful,
11687 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11688 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11689 +# GNU General Public License for more details.
11691 +# You should have received a copy of the GNU General Public License
11692 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11694 +# Test printing variable with dynamic bounds which reference a different
11695 +# (artificial in the GCC case) variable containing loclist as its location.
11696 +# This testcase uses value (not address) of the referenced variable:
11697 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
11699 +# This test can only be run on targets which support DWARF-2 and use gas.
11700 +# For now pick a sampling of likely targets.
11701 +if {![istarget *-*-linux*]
11702 + && ![istarget *-*-gnu*]
11703 + && ![istarget *-*-elf*]
11704 + && ![istarget *-*-openbsd*]
11705 + && ![istarget arm-*-eabi*]
11706 + && ![istarget powerpc-*-eabi*]} {
11710 +set testfile dw2-bound-loclist
11711 +if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
11715 +# Verify it behaves at least as an unbound array without inferior.
11717 +gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"}
11718 +gdb_test "ptype a_string" {type = char \[\]}
11720 +# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
11721 +if ![runto "*main"] {
11725 +gdb_test "p a_string" { = "seen"}
11726 +gdb_test "ptype a_string" {type = char \[4\]}
11728 +gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"}
11729 +gdb_test "ptype b_string" {type = char \[\]}
11731 +# The register contains unpredictable value - the array size.
11732 +gdb_test "ptype reg_string" {type = char \[-?[0-9]+\]}
11733 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
11734 new file mode 100644
11735 index 0000000..1f02d90
11737 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
11739 +/* This testcase is part of GDB, the GNU debugger.
11741 + Copyright 2004 Free Software Foundation, Inc.
11743 + This program is free software; you can redistribute it and/or modify
11744 + it under the terms of the GNU General Public License as published by
11745 + the Free Software Foundation; either version 2 of the License, or
11746 + (at your option) any later version.
11748 + This program is distributed in the hope that it will be useful,
11749 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11750 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11751 + GNU General Public License for more details.
11753 + You should have received a copy of the GNU General Public License
11754 + along with this program; if not, write to the Free Software
11755 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
11759 +/* The function `func1' traced into must have debug info on offset > 0;
11760 + (DW_UNSND (attr)). This is the reason of `func0' existence. */
11763 +func0(int a, int b)
11767 +/* `func1' being traced into must have some arguments to dump. */
11770 +func1(int a, int b)
11781 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
11782 new file mode 100644
11783 index 0000000..1c6e84a
11785 +++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
11787 +# Copyright 2006 Free Software Foundation, Inc.
11789 +# This program is free software; you can redistribute it and/or modify
11790 +# it under the terms of the GNU General Public License as published by
11791 +# the Free Software Foundation; either version 2 of the License, or
11792 +# (at your option) any later version.
11794 +# This program is distributed in the hope that it will be useful,
11795 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11796 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11797 +# GNU General Public License for more details.
11799 +# You should have received a copy of the GNU General Public License
11800 +# along with this program; if not, write to the Free Software
11801 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11803 +# Minimal DWARF-2 unit test
11805 +# This test can only be run on targets which support DWARF-2.
11806 +# For now pick a sampling of likely targets.
11807 +if {![istarget *-*-linux*]
11808 + && ![istarget *-*-gnu*]
11809 + && ![istarget *-*-elf*]
11810 + && ![istarget *-*-openbsd*]
11811 + && ![istarget arm-*-eabi*]
11812 + && ![istarget powerpc-*-eabi*]} {
11816 +set testfile "dw2-stripped"
11817 +set srcfile ${testfile}.c
11818 +set binfile ${objdir}/${subdir}/${testfile}.x
11820 +remote_exec build "rm -f ${binfile}"
11822 +# get the value of gcc_compiled
11823 +if [get_compiler_info ${binfile}] {
11827 +# This test can only be run on gcc as we use additional_flags=FIXME
11828 +if {$gcc_compiled == 0} {
11832 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
11836 +remote_exec build "objcopy -R .debug_loc ${binfile}"
11837 +set strip_output [remote_exec build "objdump -h ${binfile}"]
11839 +set test "stripping test file preservation"
11840 +if [ regexp ".debug_info " $strip_output] {
11841 + pass "$test (.debug_info preserved)"
11843 + fail "$test (.debug_info got also stripped)"
11846 +set test "stripping test file functionality"
11847 +if [ regexp ".debug_loc " $strip_output] {
11848 + fail "$test (.debug_loc still present)"
11850 + pass "$test (.debug_loc stripped)"
11855 +gdb_reinitialize_dir $srcdir/$subdir
11856 +gdb_load ${binfile}
11858 +# For C programs, "start" should stop in main().
11860 +gdb_test "start" \
11861 + ".*main \\(\\) at .*" \
11864 + "func.* \\(.*\\) at .*" \
11866 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
11867 new file mode 100644
11868 index 0000000..5fcdd84
11870 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
11872 +/* This testcase is part of GDB, the GNU debugger.
11874 + Copyright 2009 Free Software Foundation, Inc.
11876 + This program is free software; you can redistribute it and/or modify
11877 + it under the terms of the GNU General Public License as published by
11878 + the Free Software Foundation; either version 3 of the License, or
11879 + (at your option) any later version.
11881 + This program is distributed in the hope that it will be useful,
11882 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11883 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11884 + GNU General Public License for more details.
11886 + You should have received a copy of the GNU General Public License
11887 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
11889 +/* Debug information */
11891 + .section .debug_info
11894 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
11896 + .2byte 2 /* DWARF Version */
11897 + .4byte .Labbrev1_begin /* Offset into abbrev section */
11898 + .byte 4 /* Pointer size */
11901 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
11902 + .ascii "dw2-struct-member-data-location.c\0" /* DW_AT_name */
11903 + .ascii "GNU C 4.3.2\0" /* DW_AT_producer */
11904 + .byte 1 /* DW_AT_language (C) */
11907 + .uleb128 2 /* Abbrev: DW_TAG_structure_type */
11908 + .ascii "some_struct\0" /* DW_AT_name */
11910 + .uleb128 3 /* Abbrev: DW_TAG_member */
11911 + .ascii "field\0" /* DW_AT_name */
11912 + .byte 0 /* DW_AT_data_member_location */
11914 + .byte 0 /* End of children of some_struct */
11916 + .byte 0 /* End of children of CU */
11920 +/* Abbrev table */
11921 + .section .debug_abbrev
11923 + .uleb128 1 /* Abbrev code */
11924 + .uleb128 0x11 /* DW_TAG_compile_unit */
11925 + .byte 1 /* has_children */
11926 + .uleb128 0x3 /* DW_AT_name */
11927 + .uleb128 0x8 /* DW_FORM_string */
11928 + .uleb128 0x25 /* DW_AT_producer */
11929 + .uleb128 0x8 /* DW_FORM_string */
11930 + .uleb128 0x13 /* DW_AT_language */
11931 + .uleb128 0xb /* DW_FORM_data1 */
11932 + .byte 0x0 /* Terminator */
11933 + .byte 0x0 /* Terminator */
11935 + .uleb128 2 /* Abbrev code */
11936 + .uleb128 0x13 /* DW_TAG_structure_type */
11937 + .byte 1 /* has_children */
11938 + .uleb128 0x3 /* DW_AT_name */
11939 + .uleb128 0x8 /* DW_FORM_string */
11940 + .byte 0x0 /* Terminator */
11941 + .byte 0x0 /* Terminator */
11943 + .uleb128 3 /* Abbrev code */
11944 + .uleb128 0x0d /* DW_TAG_member */
11945 + .byte 0 /* has_children */
11946 + .uleb128 0x3 /* DW_AT_name */
11947 + .uleb128 0x8 /* DW_FORM_string */
11948 + .uleb128 0x38 /* DW_AT_data_member_location */
11949 + .uleb128 0x0b /* DW_FORM_data1 */
11950 + .byte 0x0 /* Terminator */
11951 + .byte 0x0 /* Terminator */
11953 + .byte 0x0 /* Terminator */
11954 + .byte 0x0 /* Terminator */
11955 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
11956 new file mode 100644
11957 index 0000000..c41151c
11959 +++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
11961 +# Copyright 2009 Free Software Foundation, Inc.
11963 +# This program is free software; you can redistribute it and/or modify
11964 +# it under the terms of the GNU General Public License as published by
11965 +# the Free Software Foundation; either version 3 of the License, or
11966 +# (at your option) any later version.
11968 +# This program is distributed in the hope that it will be useful,
11969 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
11970 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11971 +# GNU General Public License for more details.
11973 +# You should have received a copy of the GNU General Public License
11974 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
11976 +# This test can only be run on targets which support DWARF-2 and use gas.
11977 +# For now pick a sampling of likely targets.
11978 +if {![istarget *-*-linux*]
11979 + && ![istarget *-*-gnu*]
11980 + && ![istarget *-*-elf*]
11981 + && ![istarget *-*-openbsd*]
11982 + && ![istarget arm-*-eabi*]
11983 + && ![istarget powerpc-*-eabi*]} {
11987 +set testfile "dw2-struct-member-data-location"
11988 +set srcfile ${testfile}.S
11989 +set binfile ${testfile}.x
11991 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
11995 +clean_restart $binfile
11997 +gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
11998 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S
11999 new file mode 100644
12000 index 0000000..9dbbf3c
12002 +++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S
12004 +/* This testcase is part of GDB, the GNU debugger.
12006 + Copyright 2012 Free Software Foundation, Inc.
12008 + This program is free software; you can redistribute it and/or modify
12009 + it under the terms of the GNU General Public License as published by
12010 + the Free Software Foundation; either version 3 of the License, or
12011 + (at your option) any later version.
12013 + This program is distributed in the hope that it will be useful,
12014 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12015 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12016 + GNU General Public License for more details.
12018 + You should have received a copy of the GNU General Public License
12019 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12021 +/* Debug information */
12028 + .ascii "UNSEEN\0"
12030 + .section .debug_info
12032 + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
12034 + .2byte 2 /* DWARF version number */
12035 + .4byte .Ldebug_abbrev0 /* Offset Into Abbrev. Section */
12036 + .byte 4 /* Pointer Size (in bytes) */
12039 + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */
12040 + .ascii "GNU C 3.3.3\0" /* DW_AT_producer */
12041 + .byte 2 /* DW_AT_language (C) - */
12044 + .uleb128 2 /* Abbrev: DW_TAG_array_type */
12045 + .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
12047 + .uleb128 8 /* Abbrev: DW_TAG_subrange_type without DW_AT_type */
12048 + .byte 0 /* DW_AT_lower_bound */
12049 + .byte 128 /* DW_AT_upper_bound */
12051 + .byte 0 /* End of children of die */
12054 + .uleb128 4 /* Abbrev: DW_TAG_base_type */
12055 + .ascii "char\0" /* DW_AT_name */
12056 + .byte 1 /* DW_AT_byte_size */
12057 + .byte 6 /* DW_AT_encoding */
12059 + .uleb128 6 /* Abbrev: DW_TAG_variable DW_FORM_string */
12060 + .ascii "notype_string\0" /* DW_AT_name */
12061 + .4byte .Larray_type-.Lcu1_begin /* DW_AT_type */
12062 + .byte 2f - 1f /* DW_AT_location */
12063 +1: .byte 3 /* DW_OP_addr */
12064 + .4byte vardata /* <addr> */
12067 + .byte 0 /* End of children of CU */
12070 + .section .debug_abbrev
12072 + .uleb128 1 /* Abbrev code */
12073 + .uleb128 0x11 /* DW_TAG_compile_unit */
12074 + .byte 0x1 /* has_children */
12075 + .uleb128 0x25 /* DW_AT_producer */
12076 + .uleb128 0x8 /* DW_FORM_string */
12077 + .uleb128 0x13 /* DW_AT_language */
12078 + .uleb128 0xb /* DW_FORM_data1 */
12079 + .byte 0x0 /* Terminator */
12080 + .byte 0x0 /* Terminator */
12082 + .uleb128 2 /* Abbrev code */
12083 + .uleb128 0x1 /* TAG: DW_TAG_array_type */
12084 + .byte 0x1 /* DW_children_yes */
12085 + .uleb128 0x49 /* DW_AT_type */
12086 + .uleb128 0x13 /* DW_FORM_ref4 */
12087 + .byte 0x0 /* Terminator */
12088 + .byte 0x0 /* Terminator */
12090 + .uleb128 4 /* Abbrev code */
12091 + .uleb128 0x24 /* DW_TAG_base_type */
12092 + .byte 0x0 /* no_children */
12093 + .uleb128 0x3 /* DW_AT_name */
12094 + .uleb128 0x8 /* DW_FORM_string */
12095 + .uleb128 0xb /* DW_AT_byte_size */
12096 + .uleb128 0xb /* DW_FORM_data1 */
12097 + .uleb128 0x3e /* DW_AT_encoding */
12098 + .uleb128 0xb /* DW_FORM_data1 */
12099 + .byte 0x0 /* Terminator */
12100 + .byte 0x0 /* Terminator */
12102 + .uleb128 6 /* Abbrev code */
12103 + .uleb128 0x34 /* DW_TAG_variable */
12104 + .byte 0x0 /* no_children */
12105 + .uleb128 0x3 /* DW_AT_name */
12106 + .uleb128 0x8 /* DW_FORM_string */
12107 + .uleb128 0x49 /* DW_AT_type */
12108 + .uleb128 0x13 /* DW_FORM_ref4 */
12109 + .uleb128 0x2 /* DW_AT_location */
12110 + .uleb128 0xa /* DW_FORM_block1 */
12111 + .byte 0x0 /* Terminator */
12112 + .byte 0x0 /* Terminator */
12114 + .uleb128 8 /* Abbrev code */
12115 + .uleb128 0x21 /* DW_TAG_subrange_type without DW_AT_type */
12116 + .byte 0x0 /* no children */
12117 + .uleb128 0x22 /* DW_AT_lower_bound */
12118 + .uleb128 0xb /* DW_FORM_data1 */
12119 + .uleb128 0x2f /* DW_AT_upper_bound */
12120 + .uleb128 0xb /* DW_FORM_data1 */
12121 + .byte 0x0 /* Terminator */
12122 + .byte 0x0 /* Terminator */
12124 + .byte 0x0 /* Terminator */
12125 diff --git a/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp
12126 new file mode 100644
12127 index 0000000..a13e346
12129 +++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp
12131 +# Copyright 2012 Free Software Foundation, Inc.
12133 +# This program is free software; you can redistribute it and/or modify
12134 +# it under the terms of the GNU General Public License as published by
12135 +# the Free Software Foundation; either version 3 of the License, or
12136 +# (at your option) any later version.
12138 +# This program is distributed in the hope that it will be useful,
12139 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12140 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12141 +# GNU General Public License for more details.
12143 +# You should have received a copy of the GNU General Public License
12144 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12145 +load_lib dwarf.exp
12147 +# https://bugzilla.redhat.com/show_bug.cgi?id=806920
12148 +# read_subrange_type <TYPE_CODE (base_type) == TYPE_CODE_VOID> reinitialization
12149 +# of BASE_TYPE was done too late, it affects DW_TAG_subrange_type without
12150 +# specified DW_AT_type, present only in XLF produced code.
12152 +# This test can only be run on targets which support DWARF-2 and use gas.
12153 +if {![dwarf2_support]} {
12157 +set testfile dw2-subrange-no-type
12158 +set srcfile ${testfile}.S
12159 +set executable ${testfile}.x
12160 +set binfile ${objdir}/${subdir}/${executable}
12162 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != "" } {
12166 +clean_restart $executable
12168 +gdb_test "ptype notype_string" {type = char \[129\]}
12169 +gdb_test "p notype_string" " = 'x' <repeats 129 times>"
12170 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
12171 new file mode 100644
12172 index 0000000..d7b8bea
12174 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
12176 +# Copyright 2009 Free Software Foundation, Inc.
12178 +# This program is free software; you can redistribute it and/or modify
12179 +# it under the terms of the GNU General Public License as published by
12180 +# the Free Software Foundation; either version 2 of the License, or
12181 +# (at your option) any later version.
12183 +# This program is distributed in the hope that it will be useful,
12184 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12185 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12186 +# GNU General Public License for more details.
12188 +# You should have received a copy of the GNU General Public License
12189 +# along with this program; if not, write to the Free Software
12190 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12192 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
12194 +# This file is part of the gdb testsuite. Array element stride must not be
12195 +# specified in the number of elements but in a number of bytes instead.
12196 +# Original problem:
12197 +# (gdb) p c40pt(1)
12198 +# $1 = '0-hello', ' ' <repeats 33 times>
12199 +# (gdb) p c40pt(2)
12200 +# warning: Fortran array stride not divisible by the element size
12202 +set testfile dwarf-stride
12203 +set srcfile ${testfile}.f90
12205 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}] } {
12209 +if ![runto MAIN__] then {
12210 + perror "couldn't run to breakpoint MAIN__"
12214 +gdb_breakpoint [gdb_get_line_number "break-here"]
12215 +gdb_continue_to_breakpoint "break-here" ".*break-here.*"
12216 +gdb_test "p c40pt(1)" " = '0-hello.*"
12217 +gdb_test "p c40pt(2)" " = '1-hello.*"
12218 diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
12219 new file mode 100644
12220 index 0000000..e492b3a
12222 +++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
12224 +! Copyright 2009 Free Software Foundation, Inc.
12226 +! This program is free software; you can redistribute it and/or modify
12227 +! it under the terms of the GNU General Public License as published by
12228 +! the Free Software Foundation; either version 2 of the License, or
12229 +! (at your option) any later version.
12231 +! This program is distributed in the hope that it will be useful,
12232 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
12233 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12234 +! GNU General Public License for more details.
12236 +! You should have received a copy of the GNU General Public License
12237 +! along with this program; if not, write to the Free Software
12238 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12240 +! File written by Alan Matsuoka.
12244 + type small_stride
12245 + character*40 long_string
12246 + integer small_pad
12247 + end type small_stride
12249 + type(small_stride), dimension (20), target :: unpleasant
12250 + character*40, pointer, dimension(:):: c40pt
12255 + unpleasant(i+1)%small_pad = i+1
12256 + unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
12259 + c40pt => unpleasant%long_string
12261 + print *, c40pt ! break-here
12264 diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90 b/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
12265 new file mode 100644
12266 index 0000000..261ce17
12268 +++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
12270 +! Copyright 2010 Free Software Foundation, Inc.
12272 +! This program is free software; you can redistribute it and/or modify
12273 +! it under the terms of the GNU General Public License as published by
12274 +! the Free Software Foundation; either version 2 of the License, or
12275 +! (at your option) any later version.
12277 +! This program is distributed in the hope that it will be useful,
12278 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
12279 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12280 +! GNU General Public License for more details.
12282 +! You should have received a copy of the GNU General Public License
12283 +! along with this program; if not, write to the Free Software
12284 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12286 +! Ihis file is the Fortran source file for dynamic.exp.
12287 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
12288 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
12293 +end subroutine bar
12294 diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp b/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
12295 new file mode 100644
12296 index 0000000..fa41b80
12298 +++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
12300 +# Copyright 2010 Free Software Foundation, Inc.
12302 +# This program is free software; you can redistribute it and/or modify
12303 +# it under the terms of the GNU General Public License as published by
12304 +# the Free Software Foundation; either version 2 of the License, or
12305 +# (at your option) any later version.
12307 +# This program is distributed in the hope that it will be useful,
12308 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12309 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12310 +# GNU General Public License for more details.
12312 +# You should have received a copy of the GNU General Public License
12313 +# along with this program; if not, write to the Free Software
12314 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12316 +set testfile "dynamic-other-frame"
12317 +set srcfile1 ${testfile}.f90
12318 +set srcfile2 ${testfile}-stub.f90
12319 +set objfile2 ${objdir}/${subdir}/${testfile}-stub.o
12320 +set executable ${testfile}
12321 +set binfile ${objdir}/${subdir}/${executable}
12323 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${objfile2}" object {f90}] != ""
12324 + || [gdb_compile "${srcdir}/${subdir}/${srcfile1} ${objfile2}" "${binfile}" executable {debug f90}] != "" } {
12325 + untested "Couldn't compile ${srcfile1} or ${srcfile2}"
12329 +clean_restart ${executable}
12331 +if ![runto bar_] then {
12332 + perror "couldn't run to bar_"
12336 +gdb_test "bt" {foo \(string='hello'.*}
12337 diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90 b/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
12338 new file mode 100644
12339 index 0000000..2bc637d
12341 +++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
12343 +! Copyright 2010 Free Software Foundation, Inc.
12345 +! This program is free software; you can redistribute it and/or modify
12346 +! it under the terms of the GNU General Public License as published by
12347 +! the Free Software Foundation; either version 2 of the License, or
12348 +! (at your option) any later version.
12350 +! This program is distributed in the hope that it will be useful,
12351 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
12352 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12353 +! GNU General Public License for more details.
12355 +! You should have received a copy of the GNU General Public License
12356 +! along with this program; if not, write to the Free Software
12357 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12359 +! Ihis file is the Fortran source file for dynamic.exp.
12360 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
12361 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
12363 +subroutine foo (string)
12368 + character string*(*)
12369 + call bar ! stop-here
12370 +end subroutine foo
12373 + subroutine foo (string)
12374 + character string*(*)
12377 + call foo ('hello')
12379 diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
12380 new file mode 100644
12381 index 0000000..e79e94a
12383 +++ b/gdb/testsuite/gdb.fortran/dynamic.exp
12385 +# Copyright 2007 Free Software Foundation, Inc.
12387 +# This program is free software; you can redistribute it and/or modify
12388 +# it under the terms of the GNU General Public License as published by
12389 +# the Free Software Foundation; either version 2 of the License, or
12390 +# (at your option) any later version.
12392 +# This program is distributed in the hope that it will be useful,
12393 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12394 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12395 +# GNU General Public License for more details.
12397 +# You should have received a copy of the GNU General Public License
12398 +# along with this program; if not, write to the Free Software
12399 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12401 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
12403 +# This file is part of the gdb testsuite. It contains tests for dynamically
12404 +# allocated Fortran arrays.
12405 +# It depends on the GCC dynamic Fortran arrays DWARF support:
12406 +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
12408 +set testfile "dynamic"
12409 +set srcfile ${testfile}.f90
12410 +set binfile ${objdir}/${subdir}/${testfile}
12412 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f90 quiet}] != "" } {
12413 + untested "Couldn't compile ${srcfile}"
12419 +gdb_reinitialize_dir $srcdir/$subdir
12420 +gdb_load ${binfile}
12422 +if ![runto MAIN__] then {
12423 + perror "couldn't run to breakpoint MAIN__"
12427 +gdb_breakpoint [gdb_get_line_number "varx-init"]
12428 +gdb_continue_to_breakpoint "varx-init"
12429 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
12430 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
12431 +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"
12432 +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"
12433 +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"
12435 +gdb_breakpoint [gdb_get_line_number "varx-allocated"]
12436 +gdb_continue_to_breakpoint "varx-allocated"
12437 +# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
12438 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
12439 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
12440 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
12442 +gdb_breakpoint [gdb_get_line_number "varx-filled"]
12443 +gdb_continue_to_breakpoint "varx-filled"
12444 +gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
12445 +gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
12446 +gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
12447 +gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
12448 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
12449 +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"
12450 +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"
12452 +set test "output varx"
12453 +gdb_test_multiple $test $test {
12454 + -re "^output varx\r\n\[() ,6789.\]*$gdb_prompt $" {
12459 +gdb_breakpoint [gdb_get_line_number "varv-associated"]
12460 +gdb_continue_to_breakpoint "varv-associated"
12461 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
12462 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
12463 +# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
12464 +gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
12465 +gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
12466 +# Intel Fortran Compiler 10.1.008 uses the pointer type.
12467 +gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
12469 +gdb_breakpoint [gdb_get_line_number "varv-filled"]
12470 +gdb_continue_to_breakpoint "varv-filled"
12471 +gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
12472 +gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
12474 +gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
12475 +gdb_continue_to_breakpoint "varv-deassociated"
12476 +# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
12477 +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"
12478 +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"
12479 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
12480 +gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
12481 +gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
12483 +gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
12484 +gdb_continue_to_breakpoint "varx-deallocated"
12485 +gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
12486 +gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
12487 +gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
12488 +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"
12489 +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"
12491 +gdb_breakpoint [gdb_get_line_number "vary-passed"]
12492 +gdb_continue_to_breakpoint "vary-passed"
12493 +# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
12494 +gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
12496 +gdb_breakpoint [gdb_get_line_number "vary-filled"]
12497 +gdb_continue_to_breakpoint "vary-filled"
12498 +gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
12499 +gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
12500 +gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
12501 +gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
12502 +# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
12503 +gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
12505 +gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
12506 +gdb_continue_to_breakpoint "varw-almostfilled"
12507 +gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
12508 +gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
12509 +# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
12510 +gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
12511 +# "up" works with GCC but other Fortran compilers may copy the values into the
12512 +# outer function only on the exit of the inner function.
12513 +# We need both variants as depending on the arch we optionally may still be
12514 +# executing the caller line or not after `finish'.
12515 +gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
12516 +gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
12517 +gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
12518 +gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
12519 +gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
12521 +gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
12522 +gdb_continue_to_breakpoint "varz-almostfilled"
12523 +# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
12524 +gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
12525 +# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
12526 +# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
12527 +gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
12528 +gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
12529 +gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
12530 +gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
12531 +# maps to foo::vary(1,1)
12532 +gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
12533 +# maps to foo::vary(2,2)
12534 +gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
12535 +# maps to foo::vary(1,3)
12536 +gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
12537 diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
12538 new file mode 100644
12539 index 0000000..0f43564
12541 +++ b/gdb/testsuite/gdb.fortran/dynamic.f90
12543 +! Copyright 2007 Free Software Foundation, Inc.
12545 +! This program is free software; you can redistribute it and/or modify
12546 +! it under the terms of the GNU General Public License as published by
12547 +! the Free Software Foundation; either version 2 of the License, or
12548 +! (at your option) any later version.
12550 +! This program is distributed in the hope that it will be useful,
12551 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
12552 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12553 +! GNU General Public License for more details.
12555 +! You should have received a copy of the GNU General Public License
12556 +! along with this program; if not, write to the Free Software
12557 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12559 +! Ihis file is the Fortran source file for dynamic.exp.
12560 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
12561 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
12564 + real, target, allocatable :: varx (:, :, :)
12565 + real, pointer :: varv (:, :, :)
12566 + real, target :: varu (1, 2, 3)
12568 + allocate (varx (1:6, 5:15, 17:28)) ! varx-init
12569 + l = allocated (varx)
12570 + varx(:, :, :) = 6 ! varx-allocated
12571 + varx(1, 5, 17) = 7
12572 + varx(2, 6, 18) = 8
12573 + varx(6, 15, 28) = 9
12574 + varv => varx ! varx-filled
12575 + l = associated (varv)
12576 + varv(3, 7, 19) = 10 ! varv-associated
12577 + varv => null () ! varv-filled
12578 + l = associated (varv)
12579 + deallocate (varx) ! varv-deassociated
12580 + l = allocated (varx)
12581 + varu(:, :, :) = 10 ! varx-deallocated
12582 + allocate (varv (1:6, 5:15, 17:28))
12583 + l = associated (varv)
12584 + varv(:, :, :) = 6
12585 + varv(1, 5, 17) = 7
12586 + varv(2, 6, 18) = 8
12587 + varv(6, 15, 28) = 9
12588 + deallocate (varv)
12589 + l = associated (varv)
12591 + varv(1, 1, 1) = 6
12592 + varv(1, 2, 3) = 7
12593 + l = associated (varv)
12594 +end subroutine baz
12595 +subroutine foo (vary, varw)
12596 + real :: vary (:, :)
12597 + real :: varw (:, :, :)
12598 + vary(:, :) = 4 ! vary-passed
12602 + varw(:, :, :) = 5 ! vary-filled
12603 + varw(1, 1, 1) = 6
12604 + varw(2, 2, 2) = 7 ! varw-almostfilled
12605 +end subroutine foo
12606 +subroutine bar (varz, vart)
12608 + real :: vart (2:11, 7:*)
12610 + varz(2) = 5 ! varz-almostfilled
12611 + vart(2,7) = vart(2,7)
12612 +end subroutine bar
12615 + subroutine foo (vary, varw)
12616 + real :: vary (:, :)
12617 + real :: varw (:, :, :)
12621 + subroutine bar (varz, vart)
12623 + real :: vart (2:11, 7:*)
12626 + real :: x (10, 10), y (5), z(8, 8, 8)
12631 + call foo (x, z(2:6, 4:7, 6:8))
12633 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
12634 + if (x (1, 3) .ne. 10) call abort
12635 + if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
12636 + if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
12637 + call foo (transpose (x), z)
12638 + if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
12639 + if (x (3, 1) .ne. 10) call abort
12641 diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
12642 new file mode 100644
12643 index 0000000..39de2c4
12645 +++ b/gdb/testsuite/gdb.fortran/string.exp
12647 +# Copyright 2008 Free Software Foundation, Inc.
12649 +# This program is free software; you can redistribute it and/or modify
12650 +# it under the terms of the GNU General Public License as published by
12651 +# the Free Software Foundation; either version 2 of the License, or
12652 +# (at your option) any later version.
12654 +# This program is distributed in the hope that it will be useful,
12655 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12656 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12657 +# GNU General Public License for more details.
12659 +# You should have received a copy of the GNU General Public License
12660 +# along with this program; if not, write to the Free Software
12661 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12663 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
12665 +# This file is part of the gdb testsuite. It contains tests for Fortran
12666 +# strings with dynamic length.
12668 +set testfile "string"
12669 +set srcfile ${testfile}.f90
12670 +set binfile ${objdir}/${subdir}/${testfile}
12672 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f90 quiet}] != "" } {
12673 + untested "Couldn't compile ${srcfile}"
12679 +gdb_reinitialize_dir $srcdir/$subdir
12680 +gdb_load ${binfile}
12682 +if ![runto MAIN__] then {
12683 + perror "couldn't run to breakpoint MAIN__"
12687 +gdb_breakpoint [gdb_get_line_number "var-init"]
12688 +gdb_continue_to_breakpoint "var-init"
12689 +gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
12690 +gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
12691 +gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
12692 +gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
12693 +gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
12694 +gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
12695 +gdb_test "p c" "\\$\[0-9\]* = 'c'"
12696 +gdb_test "p d" "\\$\[0-9\]* = 'd '"
12697 +gdb_test "p e" "\\$\[0-9\]* = 'g '"
12698 +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 '\\) \\)"
12699 +gdb_test "p *e" "Attempt to take contents of a non-pointer value."
12700 +gdb_test "p *f" "Attempt to take contents of a non-pointer value."
12702 +gdb_breakpoint [gdb_get_line_number "var-finish"]
12703 +gdb_continue_to_breakpoint "var-finish"
12704 +gdb_test "p e" "\\$\[0-9\]* = 'e '" "p e re-set"
12705 +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"
12706 diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
12707 new file mode 100644
12708 index 0000000..226dc5d
12710 +++ b/gdb/testsuite/gdb.fortran/string.f90
12712 +! Copyright 2008 Free Software Foundation, Inc.
12714 +! This program is free software; you can redistribute it and/or modify
12715 +! it under the terms of the GNU General Public License as published by
12716 +! the Free Software Foundation; either version 2 of the License, or
12717 +! (at your option) any later version.
12719 +! This program is distributed in the hope that it will be useful,
12720 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
12721 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12722 +! GNU General Public License for more details.
12724 +! You should have received a copy of the GNU General Public License
12725 +! along with this program; if not, write to the Free Software
12726 +! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12728 +! Ihis file is the Fortran source file for dynamic.exp.
12729 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
12730 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
12732 +subroutine foo (e, f)
12733 + character (len=1) :: c
12734 + character (len=8) :: d
12735 + character (len=*) :: e
12736 + character (len=*) :: f (1:7, 8:10)
12739 + e = 'e' ! var-init
12742 + c = 'c' ! var-finish
12743 +end subroutine foo
12744 + character (len=4) :: g, h (1:7, 8:10)
12749 diff --git a/gdb/testsuite/gdb.fortran/subrange.exp b/gdb/testsuite/gdb.fortran/subrange.exp
12750 new file mode 100644
12751 index 0000000..c819e23
12753 +++ b/gdb/testsuite/gdb.fortran/subrange.exp
12755 +# Copyright 2011 Free Software Foundation, Inc.
12757 +# This program is free software; you can redistribute it and/or modify
12758 +# it under the terms of the GNU General Public License as published by
12759 +# the Free Software Foundation; either version 3 of the License, or
12760 +# (at your option) any later version.
12762 +# This program is distributed in the hope that it will be useful,
12763 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12764 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12765 +# GNU General Public License for more details.
12767 +# You should have received a copy of the GNU General Public License
12768 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12770 +if { [skip_fortran_tests] } { return -1 }
12772 +set testfile "subrange"
12773 +set srcfile ${testfile}.f90
12774 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}] } {
12778 +if ![runto MAIN__] {
12779 + perror "Couldn't run to MAIN__"
12783 +# Depending on the compiler version being used, the name of the 4-byte integer
12784 +# and real types can be printed differently. For instance, gfortran-4.1 uses
12785 +# "int4" whereas gfortran-4.3 uses "int(kind=4)".
12786 +set int4 "(int4|integer\\(kind=4\\))"
12788 +gdb_breakpoint [gdb_get_line_number "break-static"]
12789 +gdb_continue_to_breakpoint "break-static" ".*break-static.*"
12791 +foreach var {a alloc ptr} {
12793 + set old_prefix $pf_prefix
12794 + lappend pf_prefix "$var:"
12796 + gdb_test "p $var (2, 2:3)" { = \(22, 32\)}
12797 + gdb_test "p $var (2:3, 3)" { = \(32, 33\)}
12798 + gdb_test "p $var (1, 2:)" { = \(21, 31\)}
12799 + gdb_test "p $var (2, :2)" { = \(12, 22\)}
12800 + gdb_test "p $var (3, 2:2)" { = \(23\)}
12801 + gdb_test "ptype $var (3, 2:2)" " = $int4 \\(2:2\\)"
12802 + gdb_test "p $var (4, :)" { = \(14, 24, 34\)}
12803 + gdb_test "p $var (:, :)" { = \(\( *11, 12, 13, 14\) \( *21, 22, 23, 24\) \( *31, 32, 33, 34\) *\)}
12804 + gdb_test "ptype $var (:, :)" " = $int4 \\(4,3\\)"
12805 + gdb_test "p $var (:)" "Wrong number of subscripts"
12806 + gdb_test "p $var (:, :, :)" "Wrong number of subscripts"
12808 + set pf_prefix $old_prefix
12811 +gdb_test_no_output {set $a=a}
12812 +delete_breakpoints
12814 +gdb_test {p $a (3, 2:2)} { = \(23\)}
12815 diff --git a/gdb/testsuite/gdb.fortran/subrange.f90 b/gdb/testsuite/gdb.fortran/subrange.f90
12816 new file mode 100644
12817 index 0000000..4747ea9
12819 +++ b/gdb/testsuite/gdb.fortran/subrange.f90
12821 +! Copyright 2011 Free Software Foundation, Inc.
12823 +! This program is free software; you can redistribute it and/or modify
12824 +! it under the terms of the GNU General Public License as published by
12825 +! the Free Software Foundation; either version 3 of the License, or
12826 +! (at your option) any later version.
12828 +! This program is distributed in the hope that it will be useful,
12829 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
12830 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12831 +! GNU General Public License for more details.
12833 +! You should have received a copy of the GNU General Public License
12834 +! along with this program. If not, see <http://www.gnu.org/licenses/>.
12837 + integer, target :: a (4, 3)
12838 + integer, allocatable :: alloc (:, :)
12839 + integer, pointer :: ptr (:, :)
12842 + a (i, j) = j * 10 + i
12844 + allocate (alloc (4, 3))
12847 + write (*,*) a ! break-static
12849 diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
12850 index 7645caf..f4f9c1f 100644
12851 --- a/gdb/testsuite/gdb.gdb/selftest.exp
12852 +++ b/gdb/testsuite/gdb.gdb/selftest.exp
12853 @@ -92,6 +92,10 @@ proc do_steps_and_nexts {} {
12854 set description "step over cmdarg_vec initialization"
12857 + -re ".*python_script = 0.*$gdb_prompt $" {
12858 + set description "step over python_script initialization"
12859 + set command "step"
12861 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
12862 set description "next over make_command_stats_cleanup and everything it calls"
12864 diff --git a/gdb/testsuite/gdb.mi/mi2-var-stale-type.c b/gdb/testsuite/gdb.mi/mi2-var-stale-type.c
12865 new file mode 100644
12866 index 0000000..ebced3c
12868 +++ b/gdb/testsuite/gdb.mi/mi2-var-stale-type.c
12870 +/* Copyright 2011 Free Software Foundation, Inc.
12872 + This file is part of GDB.
12874 + This program is free software; you can redistribute it and/or modify
12875 + it under the terms of the GNU General Public License as published by
12876 + the Free Software Foundation; either version 3 of the License, or
12877 + (at your option) any later version.
12879 + This program is distributed in the hope that it will be useful,
12880 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12881 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12882 + GNU General Public License for more details.
12884 + You should have received a copy of the GNU General Public License
12885 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12888 +main (int argc, char **argv)
12892 + vla[0] = 0; /* break-here */
12896 diff --git a/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp b/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp
12897 new file mode 100644
12898 index 0000000..74a104e
12900 +++ b/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp
12902 +# Copyright 2011 Free Software Foundation, Inc.
12904 +# This program is free software; you can redistribute it and/or modify
12905 +# it under the terms of the GNU General Public License as published by
12906 +# the Free Software Foundation; either version 3 of the License, or
12907 +# (at your option) any later version.
12909 +# This program is distributed in the hope that it will be useful,
12910 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12911 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12912 +# GNU General Public License for more details.
12914 +# You should have received a copy of the GNU General Public License
12915 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
12917 +load_lib mi-support.exp
12918 +set MIFLAGS "-i=mi2"
12921 +if [mi_gdb_start] {
12925 +set testfile "mi2-var-stale-type"
12926 +set srcfile ${testfile}.c
12927 +set binfile ${objdir}/${subdir}/${testfile}
12928 +if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} {
12932 +mi_delete_breakpoints
12933 +mi_gdb_reinitialize_dir $srcdir/$subdir
12934 +mi_gdb_load ${binfile}
12936 +mi_gdb_test {-interpreter-exec console "maintenance set internal-error quit yes"} \
12938 + "maintenance set internal-error quit yes"
12940 +mi_gdb_test {-interpreter-exec console "maintenance set internal-error corefile yes"} \
12942 + "maintenance set internal-error corefile yes"
12944 +set line [gdb_get_line_number "break-here"]
12947 +mi_gdb_test "-break-insert -t $srcfile:$line" \
12948 + "\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"$func\(\\\(.*\\\)\)?\",file=\".*\",line=\"$line\",times=\"0\",original-location=\".*\"\}" \
12949 + "breakpoint at $func"
12951 +if { [mi_run_cmd] < 0 } {
12954 +mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "stop after initializing vla"
12956 +mi_create_varobj "vla" "vla" "create local variable vla"
12958 +mi_gdb_test "-var-update *" "\\^done,changelist=.*" "-var-update *"
12959 diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
12960 new file mode 100644
12961 index 0000000..729f457
12963 +++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
12965 +/* This file is part of GDB, the GNU debugger.
12967 + Copyright 2009 Free Software Foundation, Inc.
12969 + This program is free software; you can redistribute it and/or modify
12970 + it under the terms of the GNU General Public License as published by
12971 + the Free Software Foundation; either version 3 of the License, or
12972 + (at your option) any later version.
12974 + This program is distributed in the hope that it will be useful,
12975 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12976 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12977 + GNU General Public License for more details.
12979 + You should have received a copy of the GNU General Public License
12980 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
12987 diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
12988 new file mode 100644
12989 index 0000000..3090e7e
12991 +++ b/gdb/testsuite/gdb.opt/array-from-register.c
12993 +/* This file is part of GDB, the GNU debugger.
12995 + Copyright 2009 Free Software Foundation, Inc.
12997 + This program is free software; you can redistribute it and/or modify
12998 + it under the terms of the GNU General Public License as published by
12999 + the Free Software Foundation; either version 3 of the License, or
13000 + (at your option) any later version.
13002 + This program is distributed in the hope that it will be useful,
13003 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13004 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13005 + GNU General Public License for more details.
13007 + You should have received a copy of the GNU General Public License
13008 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
13010 +extern int func (int *arr);
13015 + int arr[] = { 42 };
13021 diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
13022 new file mode 100644
13023 index 0000000..f2de718
13025 +++ b/gdb/testsuite/gdb.opt/array-from-register.exp
13027 +# Copyright 2009 Free Software Foundation, Inc.
13029 +# This program is free software; you can redistribute it and/or modify
13030 +# it under the terms of the GNU General Public License as published by
13031 +# the Free Software Foundation; either version 2 of the License, or
13032 +# (at your option) any later version.
13034 +# This program is distributed in the hope that it will be useful,
13035 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13036 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13037 +# GNU General Public License for more details.
13039 +# You should have received a copy of the GNU General Public License
13040 +# along with this program; if not, write to the Free Software
13041 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13043 +# This file is part of the gdb testsuite.
13045 +if { [prepare_for_testing array-from-register.exp "array-from-register" \
13046 + {array-from-register.c array-from-register-func.c} \
13047 + {debug optimize=-O2}] } {
13051 +if ![runto func] then {
13055 +gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
13057 +# Seen regression:
13058 +# Address requested for identifier "arr" which is in register $rdi
13059 +gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
13060 diff --git a/gdb/testsuite/gdb.pascal/arrays.exp b/gdb/testsuite/gdb.pascal/arrays.exp
13061 new file mode 100644
13062 index 0000000..ccc6e1e
13064 +++ b/gdb/testsuite/gdb.pascal/arrays.exp
13066 +# Copyright 2008, 2009 Free Software Foundation, Inc.
13068 +# This program is free software; you can redistribute it and/or modify
13069 +# it under the terms of the GNU General Public License as published by
13070 +# the Free Software Foundation; either version 3 of the License, or
13071 +# (at your option) any later version.
13073 +# This program is distributed in the hope that it will be useful,
13074 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13075 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13076 +# GNU General Public License for more details.
13078 +# You should have received a copy of the GNU General Public License
13079 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
13081 +if $tracelevel then {
13082 + strace $tracelevel
13085 +load_lib "pascal.exp"
13087 +set testfile "arrays"
13088 +set srcfile ${testfile}.pas
13089 +set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
13091 +# These tests only work with fpc, using the -gw3 compile-option
13093 +if { $pascal_compiler_is_fpc != 1 } {
13097 +# Detect if the fpc version is below 2.3.0
13098 +set fpc_generates_dwarf_for_dynamic_arrays 1
13099 +if { ($fpcversion_major < 2) || ( ($fpcversion_major == 2) && ($fpcversion_minor < 3))} {
13100 + set fpc_generates_dwarf_for_dynamic_arrays 0
13104 +if {[gdb_compile_pascal "-gw3 ${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
13110 +gdb_reinitialize_dir $srcdir/$subdir
13111 +gdb_load ${binfile}
13112 +set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
13113 +set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
13116 +if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
13117 + pass "setting breakpoint 1"
13119 +if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
13120 + pass "setting breakpoint 2"
13123 +# Verify that "start" lands inside the right procedure.
13124 +if { [gdb_start_cmd] < 0 } {
13129 +gdb_test "" ".* at .*${srcfile}.*" "start"
13131 +gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
13133 +gdb_test "print StatArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer type"
13134 +gdb_test "print StatArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer"
13136 +gdb_test "cont" "Breakpoint .*:${bp_location2}.*" "Going to second breakpoint"
13138 +gdb_test "print StatArrChar" ".* = 'abcdefghijkl'" "Print static array of char"
13139 +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"
13141 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
13142 + setup_xfail "*-*-*"
13144 +gdb_test "print DynArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer type"
13145 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
13146 + setup_xfail "*-*-*"
13148 +gdb_test "print DynArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer"
13150 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
13151 + setup_xfail "*-*-*"
13153 +gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char"
13155 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
13156 + setup_xfail "*-*-*"
13158 +gdb_test "print DynArrStr" ".* = \\{'dstr0', 'dstr1', 'dstr2', 'dstr3', 'dstr4', 'dstr5', 'dstr6', 'dstr7', 'dstr8', 'dstr9', 'dstr10', 'dstr11', 'dstr12'\\}" "Print dynamic array of string"
13160 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
13161 + setup_xfail "*-*-*"
13163 +gdb_test "print StatArrStr" ".* = \\{'str0', 'str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9', 'str10', 'str11', 'str12'\\}" "Print static array of string"
13165 +if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
13166 + setup_xfail "*-*-*"
13168 +gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char"
13170 diff --git a/gdb/testsuite/gdb.pascal/arrays.pas b/gdb/testsuite/gdb.pascal/arrays.pas
13171 new file mode 100644
13172 index 0000000..295602d
13174 +++ b/gdb/testsuite/gdb.pascal/arrays.pas
13177 + Copyright 2008, 2009 Free Software Foundation, Inc.
13179 + This program is free software; you can redistribute it and/or modify
13180 + it under the terms of the GNU General Public License as published by
13181 + the Free Software Foundation; either version 3 of the License, or
13182 + (at your option) any later version.
13184 + This program is distributed in the hope that it will be useful,
13185 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13186 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13187 + GNU General Public License for more details.
13189 + You should have received a copy of the GNU General Public License
13190 + along with this program. If not, see <http://www.gnu.org/licenses/>.
13195 +{$mode objfpc}{$h+}
13199 +type TStatArrInt= array[0..11] of integer;
13200 + TDynArrInt= array of integer;
13201 + TStatArrStr= array[0..12] of string;
13202 + TDynArrStr= array of string;
13203 + TDynArrChar = array of char;
13204 + TStatArrChar = array [0..11] of char;
13206 + TStat2dArrInt = array[0..11,0..4] of integer;
13208 +var StatArrInt: TStatArrInt;
13209 + StatArrInt_: Array[0..11] of integer;
13210 + DynArrInt: TDynArrInt;
13211 + DynArrInt_: Array of integer;
13212 + StatArrStr: TStatArrStr;
13213 + DynArrStr: TDynArrStr;
13214 + StatArrChar: TStatArrChar;
13215 + DynArrChar: TDynArrChar;
13217 + Stat2dArrInt: TStat2dArrInt;
13224 + for i := 0 to 11 do
13226 + StatArrInt[i]:= i+50;
13227 + StatArrInt_[i]:= i+50;
13228 + StatArrChar[i]:= chr(ord('a')+i);
13229 + for j := 0 to 4 do
13230 + Stat2dArrInt[i,j]:=i+j;
13232 + writeln(StatArrInt_[0]);
13233 + writeln(StatArrInt[0]); { set breakpoint 1 here }
13234 + writeln(StatArrChar[0]);
13235 + writeln(Stat2dArrInt[0,0]);
13237 + setlength(DynArrInt,13);
13238 + setlength(DynArrInt_,13);
13239 + setlength(DynArrStr,13);
13240 + setlength(DynArrChar,13);
13241 + for i := 0 to 12 do
13243 + DynArrInt[i]:= i+50;
13244 + DynArrInt_[i]:= i+50;
13245 + DynArrChar[i]:= chr(ord('a')+i);
13246 + StatArrStr[i]:='str'+inttostr(i);
13247 + DynArrStr[i]:='dstr'+inttostr(i);
13249 + writeln(DynArrInt_[1]);
13250 + writeln(DynArrInt[1]);
13251 + writeln(DynArrStr[1]);
13252 + writeln(StatArrStr[1]);
13253 + writeln(DynArrChar[1]);
13255 + s := 'test'#0'string';
13256 + writeln(s); { set breakpoint 2 here }
13258 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
13259 index 993e774..52dbd17 100644
13260 --- a/gdb/testsuite/gdb.python/py-frame.exp
13261 +++ b/gdb/testsuite/gdb.python/py-frame.exp
13262 @@ -74,8 +74,6 @@ gdb_test "python print bframe == gdb.newest_frame()" True \
13264 gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
13265 gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
13266 -gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
13267 -gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
13268 gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
13269 gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
13270 gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
13271 @@ -90,3 +88,5 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
13272 gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
13274 gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
13276 +gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
13277 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
13278 index acfd89b..c77d9c2 100644
13279 --- a/gdb/testsuite/gdb.python/py-value.exp
13280 +++ b/gdb/testsuite/gdb.python/py-value.exp
13281 @@ -358,6 +358,15 @@ proc test_value_after_death {} {
13282 "print value's type"
13285 +# Regression test for a cast failure. The bug was that if we cast a
13286 +# value to its own type, gdb could crash. This happened because we
13287 +# could end up double-freeing a struct value.
13288 +proc test_cast_regression {} {
13289 + gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
13290 + gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
13291 + gdb_test "python print v" "5" "print value for cast test"
13294 # Regression test for invalid subscript operations. The bug was that
13295 # the type of the value was not being checked before allowing a
13296 # subscript operation to proceed.
13297 @@ -494,6 +503,7 @@ test_value_in_inferior
13298 test_inferior_function_call
13300 test_value_after_death
13301 +test_cast_regression
13303 # Test either C or C++ values.
13304 test_subscript_regression "${binfile}" "c"
13305 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
13306 index 4f2b7c9..0daef25 100644
13307 --- a/gdb/testsuite/lib/gdb.exp
13308 +++ b/gdb/testsuite/lib/gdb.exp
13309 @@ -142,6 +142,11 @@ proc gdb_unload {} {
13313 + -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $"\
13315 + verbose "\t\tUnloading symbols for program being debugged"
13318 -re "Discard symbol table from .*y or n.*$" {
13321 diff --git a/gdb/testsuite/lib/pascal.exp b/gdb/testsuite/lib/pascal.exp
13322 index dd18d37..f973485 100644
13323 --- a/gdb/testsuite/lib/pascal.exp
13324 +++ b/gdb/testsuite/lib/pascal.exp
13325 @@ -37,6 +37,9 @@ proc pascal_init {} {
13326 global pascal_compiler_is_fpc
13327 global gpc_compiler
13328 global fpc_compiler
13329 + global fpcversion_major
13330 + global fpcversion_minor
13331 + global fpcversion_release
13334 if { $pascal_init_done == 1 } {
13335 @@ -64,6 +67,20 @@ proc pascal_init {} {
13336 set pascal_compiler_is_fpc 1
13337 verbose -log "Free Pascal compiler found"
13340 + # Detect the fpc-version
13341 + if { $pascal_compiler_is_fpc == 1 } {
13342 + set fpcversion_major 1
13343 + set fpcversion_minor 0
13344 + set fpcversion_release 0
13345 + set fpcversion [ remote_exec host $fpc_compiler "-iV" ]
13346 + if [regexp {.*([0-9]+)\.([0-9]+)\.([0-9]+).?} $fpcversion] {
13347 + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\1} fpcversion_major
13348 + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\2} fpcversion_minor
13349 + regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\3} fpcversion_release
13351 + verbose -log "Freepascal version: $fpcversion_major.$fpcversion_minor.$fpcversion_release"
13354 set pascal_init_done 1
13356 diff --git a/gdb/top.c b/gdb/top.c
13357 index 061ad48..d615cfc 100644
13360 @@ -352,6 +352,9 @@ prepare_execute_command (void)
13362 mark = value_mark ();
13363 cleanup = make_cleanup_value_free_to_mark (mark);
13365 + free_all_types ();
13368 /* With multiple threads running while the one we're examining is
13369 stopped, the dcache can get stale without us being able to detect
13370 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
13371 index c25e705..498958a 100644
13372 --- a/gdb/typeprint.c
13373 +++ b/gdb/typeprint.c
13375 #include "gdb_string.h"
13376 #include "exceptions.h"
13377 #include "valprint.h"
13378 +#include "dwarf2loc.h"
13381 extern void _initialize_typeprint (void);
13382 @@ -76,6 +77,9 @@ void
13383 type_print (struct type *type, const char *varstring, struct ui_file *stream,
13386 + if (show >= 0 && current_language->la_language != language_ada)
13387 + type = check_typedef (type);
13389 LA_PRINT_TYPE (type, varstring, stream, show, 0);
13392 @@ -114,7 +118,8 @@ whatis_exp (char *exp, int show)
13394 struct expression *expr;
13396 - struct cleanup *old_chain = NULL;
13397 + /* Required at least for the object_address_set call. */
13398 + struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
13399 struct type *real_type = NULL;
13402 @@ -125,12 +130,13 @@ whatis_exp (char *exp, int show)
13405 expr = parse_expression (exp);
13406 - old_chain = make_cleanup (free_current_contents, &expr);
13407 + make_cleanup (free_current_contents, &expr);
13408 val = evaluate_type (expr);
13411 val = access_value_history (0);
13413 + object_address_set (value_raw_address (val));
13414 type = value_type (val);
13416 get_user_print_options (&opts);
13417 @@ -158,8 +164,7 @@ whatis_exp (char *exp, int show)
13418 type_print (type, "", gdb_stdout, show);
13419 printf_filtered ("\n");
13422 - do_cleanups (old_chain);
13423 + do_cleanups (old_chain);
13427 diff --git a/gdb/utils.c b/gdb/utils.c
13428 index 5566149..6e1aa34 100644
13432 #include "exceptions.h"
13433 #include "gdbthread.h"
13434 #include "fnmatch.h"
13435 +#include "gdb_bfd.h"
13436 #ifdef HAVE_SYS_RESOURCE_H
13437 #include <sys/resource.h>
13438 #endif /* HAVE_SYS_RESOURCE_H */
13439 @@ -198,11 +199,11 @@ make_cleanup_dyn_string_delete (dyn_string_t arg)
13441 do_bfd_close_cleanup (void *arg)
13444 + gdb_bfd_unref (arg);
13448 -make_cleanup_bfd_close (bfd *abfd)
13449 +make_cleanup_bfd_unref (bfd *abfd)
13451 return make_cleanup (do_bfd_close_cleanup, abfd);
13453 @@ -1738,6 +1739,36 @@ set_batch_flag_and_make_cleanup_restore_page_info (void)
13457 +/* Helper for make_cleanup_restore_page_info. */
13460 +do_restore_selected_frame_cleanup (void *arg)
13462 + struct frame_id *frame_idp = arg;
13464 + select_frame (frame_find_by_id (*frame_idp));
13466 + xfree (frame_idp);
13469 +/* Provide cleanup for restoring currently selected frame. Use frame_id for
13470 + the case the current frame becomes stale in the meantime. */
13473 +make_cleanup_restore_selected_frame (void)
13475 + struct frame_id *frame_idp;
13477 + /* get_selected_frame->get_current_frame would error otherwise. */
13478 + if (!has_stack_frames ())
13479 + return make_cleanup (null_cleanup, NULL);
13481 + frame_idp = xmalloc (sizeof (*frame_idp));
13482 + *frame_idp = get_frame_id (get_selected_frame (NULL));
13484 + return make_cleanup (do_restore_selected_frame_cleanup, frame_idp);
13487 /* Set the screen size based on LINES_PER_PAGE and CHARS_PER_LINE. */
13490 diff --git a/gdb/valarith.c b/gdb/valarith.c
13491 index 96d5411..37bd464 100644
13492 --- a/gdb/valarith.c
13493 +++ b/gdb/valarith.c
13494 @@ -197,7 +197,10 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
13495 struct type *array_type = check_typedef (value_type (array));
13496 struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
13497 unsigned int elt_size = TYPE_LENGTH (elt_type);
13498 - unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
13499 + unsigned int elt_stride
13500 + = (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type)) == 0
13501 + ? elt_size : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type)));
13502 + unsigned int elt_offs = elt_stride * longest_to_int (index - lowerbound);
13505 if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
13506 @@ -297,6 +300,10 @@ int
13507 binop_user_defined_p (enum exp_opcode op,
13508 struct value *arg1, struct value *arg2)
13510 + /* FIXME: We should support user defined ops for dynamic types. */
13511 + if (TYPE_DYNAMIC (value_type (arg1)) || TYPE_DYNAMIC (value_type (arg2)))
13514 return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
13517 diff --git a/gdb/valops.c b/gdb/valops.c
13518 index 97d889b..6ae77b8 100644
13522 #include "objfiles.h"
13523 #include "symtab.h"
13524 #include "exceptions.h"
13525 +#include "dwarf2loc.h"
13527 extern int overload_debug;
13528 /* Local functions. */
13529 @@ -919,6 +920,65 @@ value_one (struct type *type)
13533 +/* object_address_set must be already called before this function. */
13536 +object_address_data_not_valid (struct type *type)
13538 + /* Attributes are present only at the target type of a typedef. Make the
13539 + call conditional as it would otherwise loop through type_length_get. */
13540 + if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
13541 + CHECK_TYPEDEF (type);
13543 + /* DW_AT_associated has a preference over DW_AT_allocated. */
13544 + if (TYPE_NOT_ASSOCIATED (type)
13545 + || (TYPE_ASSOCIATED (type) != NULL
13546 + && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
13547 + return N_("object is not associated");
13549 + if (TYPE_NOT_ALLOCATED (type)
13550 + || (TYPE_ALLOCATED (type) != NULL
13551 + && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
13552 + return N_("object is not allocated");
13557 +/* Return non-NULL check_typedef result on TYPE if the variable is valid. If
13558 + it is valid the function may store the data address (DW_AT_DATA_LOCATION) of
13559 + TYPE at *ADDRESS_RETURN. You must set *ADDRESS_RETURN from
13560 + value_raw_address (VAL) before calling this function. If no
13561 + DW_AT_DATA_LOCATION is present for TYPE the address at *ADDRESS_RETURN is
13562 + left unchanged. ADDRESS_RETURN must not be NULL, use
13563 + object_address_data_not_valid () for just the data validity check. */
13566 +object_address_get_data (struct type *type, CORE_ADDR *address_return)
13568 + gdb_assert (address_return != NULL);
13570 + object_address_set (*address_return);
13572 + /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
13573 + at the target type of a typedef. */
13574 + CHECK_TYPEDEF (type);
13576 + if (object_address_data_not_valid (type) != NULL)
13578 + /* Do not try to evaluate DW_AT_data_location as it may even crash
13579 + (it would just return the value zero in the gfortran case). */
13583 + if (TYPE_DATA_LOCATION_IS_ADDR (type))
13584 + *address_return = TYPE_DATA_LOCATION_ADDR (type);
13585 + else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
13587 + = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
13592 /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */
13594 static struct value *
13595 @@ -981,7 +1041,8 @@ int
13596 value_fetch_lazy (struct value *val)
13598 gdb_assert (value_lazy (val));
13599 - allocate_value_contents (val);
13600 + if (VALUE_LVAL (val) != lval_memory)
13601 + allocate_value_contents (val);
13602 if (value_bitsize (val))
13604 /* To read a lazy bitfield, read the entire enclosing value. This
13605 @@ -1015,12 +1076,24 @@ value_fetch_lazy (struct value *val)
13607 else if (VALUE_LVAL (val) == lval_memory)
13609 - CORE_ADDR addr = value_address (val);
13610 - int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
13611 + CORE_ADDR addr = value_raw_address (val);
13614 - read_value_memory (val, 0, value_stack (val),
13615 - addr, value_contents_all_raw (val), length);
13616 + if (object_address_get_data (value_type (val), &addr))
13618 + struct type *type = value_enclosing_type (val);
13619 + int length = TYPE_LENGTH (check_typedef (type));
13623 + /* Delay it after object_address_get_data above. */
13624 + allocate_value_contents (val);
13625 + addr += value_offset (val);
13626 + read_value_memory (val, 0, value_stack (val),
13627 + addr, value_contents_all_raw (val), length);
13630 + /* Just to be sure it has been called. */
13631 + allocate_value_contents (val);
13633 else if (VALUE_LVAL (val) == lval_register)
13635 @@ -1530,7 +1603,18 @@ address_of_variable (struct symbol *var, struct block *b)
13636 if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
13637 || TYPE_CODE (type) == TYPE_CODE_FUNC)
13639 - CORE_ADDR addr = value_address (val);
13642 + if (VALUE_LVAL (val) == lval_memory)
13644 + addr = value_raw_address (val);
13645 + if (!object_address_get_data (type, &addr))
13646 + error (_("Can't take address of memory lvalue \"%s\"."),
13647 + SYMBOL_PRINT_NAME (var));
13648 + set_value_address (val, addr);
13651 + addr = value_address (val);
13653 return value_from_pointer (lookup_pointer_type (type), addr);
13655 @@ -1637,6 +1721,7 @@ struct value *
13656 value_coerce_array (struct value *arg1)
13658 struct type *type = check_typedef (value_type (arg1));
13659 + CORE_ADDR address;
13661 /* If the user tries to do something requiring a pointer with an
13662 array that has not yet been pushed to the target, then this would
13663 @@ -1646,8 +1731,12 @@ value_coerce_array (struct value *arg1)
13664 if (VALUE_LVAL (arg1) != lval_memory)
13665 error (_("Attempt to take address of value not located in memory."));
13667 + address = value_raw_address (arg1);
13668 + if (!object_address_get_data (type, &address))
13669 + error (_("Attempt to take address of non-valid value."));
13671 return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
13672 - value_address (arg1));
13673 + address + value_offset (arg1));
13676 /* Given a value which is a function, return a value which is a pointer
13677 @@ -3769,6 +3858,8 @@ value_slice (struct value *array, int lowbound, int length)
13678 TYPE_TARGET_TYPE (range_type),
13680 lowbound + length - 1);
13681 + TYPE_BYTE_STRIDE (slice_range_type) = TYPE_BYTE_STRIDE (range_type);
13683 if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING)
13686 diff --git a/gdb/valprint.c b/gdb/valprint.c
13687 index fc5942d..8333eb4 100644
13688 --- a/gdb/valprint.c
13689 +++ b/gdb/valprint.c
13691 #include "gdb_obstack.h"
13692 #include "charset.h"
13694 +#include "dwarf2loc.h"
13698 @@ -251,7 +252,6 @@ scalar_type_p (struct type *type)
13699 case TYPE_CODE_STRUCT:
13700 case TYPE_CODE_UNION:
13701 case TYPE_CODE_SET:
13702 - case TYPE_CODE_STRING:
13703 case TYPE_CODE_BITSTRING:
13706 @@ -1570,6 +1570,7 @@ val_print_array_elements (struct type *type,
13708 unsigned int things_printed = 0;
13710 + struct type *saved_type = type;
13711 struct type *elttype, *index_type;
13713 /* Position of the array element we are examining to see
13714 @@ -1578,9 +1579,33 @@ val_print_array_elements (struct type *type,
13715 /* Number of repetitions we have detected so far. */
13717 LONGEST low_bound, high_bound;
13718 + struct cleanup *back_to;
13719 + CORE_ADDR saved_address = address;
13721 + back_to = make_cleanup (null_cleanup, 0);
13722 + type = object_address_get_data (type, &address);
13725 + fputs_filtered (object_address_data_not_valid (type), stream);
13726 + do_cleanups (back_to);
13729 + if (address != saved_address)
13731 + size_t length = TYPE_LENGTH (type);
13733 - elttype = TYPE_TARGET_TYPE (type);
13734 - eltlen = TYPE_LENGTH (check_typedef (elttype));
13735 + valaddr = xmalloc (length);
13736 + make_cleanup (xfree, (gdb_byte *) valaddr);
13737 + read_memory (address, (gdb_byte *) valaddr, length);
13740 + /* Skip typedefs but do not resolve TYPE_DYNAMIC. */
13741 + elttype = saved_type;
13742 + while (TYPE_CODE (elttype) == TYPE_CODE_TYPEDEF)
13743 + elttype = TYPE_TARGET_TYPE (elttype);
13744 + elttype = TYPE_TARGET_TYPE (elttype);
13746 + eltlen = TYPE_ARRAY_BYTE_STRIDE_VALUE (type);
13747 index_type = TYPE_INDEX_TYPE (type);
13749 if (get_array_bounds (type, &low_bound, &high_bound))
13750 @@ -1667,6 +1692,8 @@ val_print_array_elements (struct type *type,
13752 fprintf_filtered (stream, "...");
13755 + do_cleanups (back_to);
13758 /* Read LEN bytes of target memory at address MEMADDR, placing the
13759 diff --git a/gdb/value.c b/gdb/value.c
13760 index a6bb718..7b08d1f 100644
13765 #include "tracepoint.h"
13766 #include "cp-abi.h"
13767 +#include "observer.h"
13769 /* Prototypes for exported functions. */
13771 @@ -1437,12 +1438,15 @@ void
13772 set_value_component_location (struct value *component,
13773 const struct value *whole)
13777 if (whole->lval == lval_internalvar)
13778 VALUE_LVAL (component) = lval_internalvar_component;
13780 VALUE_LVAL (component) = whole->lval;
13782 component->location = whole->location;
13784 if (whole->lval == lval_computed)
13786 const struct lval_funcs *funcs = whole->location.computed.funcs;
13787 @@ -1450,6 +1454,12 @@ set_value_component_location (struct value *component,
13788 if (funcs->copy_closure)
13789 component->location.computed.closure = funcs->copy_closure (whole);
13792 + addr = value_raw_address (component);
13793 + object_address_get_data (value_type (whole), &addr);
13794 + if (component->lval != lval_internalvar
13795 + && component->lval != lval_internalvar_component)
13796 + set_value_address (component, addr);
13800 @@ -1583,6 +1593,31 @@ show_values (char *num_exp, int from_tty)
13805 +/* Sanity check for memory leaks and proper types reference counting. */
13808 +value_history_cleanup (void *unused)
13810 + while (value_history_chain)
13812 + struct value_history_chunk *chunk = value_history_chain;
13815 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
13816 + value_free (chunk->values[i]);
13818 + value_history_chain = chunk->next;
13821 + value_history_count = 0;
13823 + /* Free the unreferenced types above. */
13824 + free_all_values ();
13826 + free_all_types ();
13830 /* Internal variables. These are variables within the debugger
13831 that hold values assigned by debugger commands.
13832 @@ -2118,6 +2153,38 @@ call_internal_function (struct gdbarch *gdbarch,
13833 return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
13837 +/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
13840 +value_types_mark_used (void)
13842 + struct internalvar *var;
13843 + struct value_history_chunk *chunk;
13845 + for (var = internalvars; var != NULL; var = var->next)
13846 + switch (var->kind)
13848 + case INTERNALVAR_VALUE:
13849 + type_mark_used (value_type (var->u.value));
13852 + case INTERNALVAR_INTEGER:
13853 + type_mark_used (var->u.integer.type);
13857 + for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
13861 + for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
13862 + if (chunk->values[i])
13863 + type_mark_used (value_type (chunk->values[i]));
13868 /* The 'function' command. This does nothing -- it is just a
13869 placeholder to let "help function NAME" work. This is also used as
13870 the implementation of the sub-command that is created when
13871 @@ -2165,11 +2232,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
13872 htab_t copied_types)
13874 if (TYPE_OBJFILE (value->type) == objfile)
13875 - value->type = copy_type_recursive (objfile, value->type, copied_types);
13876 + value->type = copy_type_recursive (value->type, copied_types);
13878 if (TYPE_OBJFILE (value->enclosing_type) == objfile)
13879 - value->enclosing_type = copy_type_recursive (objfile,
13880 - value->enclosing_type,
13881 + value->enclosing_type = copy_type_recursive (value->enclosing_type,
13885 @@ -2184,7 +2250,7 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
13886 case INTERNALVAR_INTEGER:
13887 if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
13888 var->u.integer.type
13889 - = copy_type_recursive (objfile, var->u.integer.type, copied_types);
13890 + = copy_type_recursive (var->u.integer.type, copied_types);
13893 case INTERNALVAR_VALUE:
13894 @@ -3276,10 +3342,27 @@ readjust_indirect_value_type (struct value *value, struct type *enc_type,
13896 coerce_ref (struct value *arg)
13898 - struct type *value_type_arg_tmp = check_typedef (value_type (arg));
13899 + struct type *value_type_arg_tmp;
13900 struct value *retval;
13901 struct type *enc_type;
13903 + if (TYPE_DYNAMIC (value_type (arg)))
13905 + struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
13906 + CORE_ADDR address;
13908 + value_type_arg_tmp = value_type (arg);
13909 + address = value_raw_address (arg);
13910 + value_type_arg_tmp = object_address_get_data (value_type_arg_tmp,
13912 + if (! value_type_arg_tmp)
13913 + error (_("Attempt to coerce non-valid value."));
13914 + arg = value_at_lazy (value_type_arg_tmp, address);
13915 + do_cleanups (cleanups);
13918 + value_type_arg_tmp = check_typedef (value_type (arg));
13920 retval = coerce_ref_if_computed (arg);
13923 @@ -3386,4 +3469,10 @@ VARIABLE is already initialized."));
13924 add_prefix_cmd ("function", no_class, function_command, _("\
13925 Placeholder command for showing help on convenience functions."),
13926 &functionlist, "function ", 0, &cmdlist);
13928 + make_final_cleanup (value_history_cleanup, NULL);
13931 + observer_attach_mark_used (value_types_mark_used);
13934 diff --git a/gdb/value.h b/gdb/value.h
13935 index d8b157f..f49e827 100644
13938 @@ -533,6 +533,10 @@ extern struct value *value_from_decfloat (struct type *type,
13939 const gdb_byte *decbytes);
13940 extern struct value *value_from_history_ref (char *, char **);
13942 +extern const char *object_address_data_not_valid (struct type *type);
13943 +extern struct type *object_address_get_data (struct type *type,
13944 + CORE_ADDR *address_return);
13946 extern struct value *value_at (struct type *type, CORE_ADDR addr);
13947 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
13949 diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
13950 index f16588a..afef615 100644
13951 --- a/gdb/windows-nat.c
13952 +++ b/gdb/windows-nat.c
13953 @@ -752,7 +752,7 @@ windows_make_so (const char *name, LPVOID load_addr)
13954 asection *text = NULL;
13955 CORE_ADDR text_vma;
13957 - abfd = bfd_openr (so->so_name, "pei-i386");
13958 + abfd = gdb_bfd_openr (so->so_name, "pei-i386");
13962 @@ -762,7 +762,7 @@ windows_make_so (const char *name, LPVOID load_addr)
13966 - bfd_close (abfd);
13967 + gdb_bfd_unref (abfd);
13971 @@ -773,7 +773,7 @@ windows_make_so (const char *name, LPVOID load_addr)
13972 load_addr + 0x1000);
13973 cygwin_load_end = cygwin_load_start + bfd_section_size (abfd, text);
13975 - bfd_close (abfd);
13976 + gdb_bfd_unref (abfd);