]> git.pld-linux.org Git - packages/gdb.git/blobdiff - gdb-archer.patch
- typo
[packages/gdb.git] / gdb-archer.patch
index 43fda9e151dc1aad4d95f1328f44b93855d725b3..80e3cf283bfeb63ec7444d6ddf79da36bba5273f 100644 (file)
@@ -2,62 +2,46 @@ http://sourceware.org/gdb/wiki/ProjectArcher
 http://sourceware.org/gdb/wiki/ArcherBranchManagement
 
 GIT snapshot:
-commit 74fff58d0076fe97c6c99d65fa58126315266646
+commit 897686c0aedb7a6da59b823f22b1d24ec5a1d2ba
 
 branch `archer' - the merge of branches:
 archer-jankratochvil-vla
-archer-jankratochvil-watchpoint3
-archer-jankratochvil-ifunc
-archer-pmuldoon-next-over-throw2
-archer-tromey-python (not a merge)
-archer-tromey-optional-psymtab (cherry-picked from post-7.2 master)
-#TODO:archer-tromey-threaded-dwarf
+archer-tromey-python
+archer-tromey-dwz-multifile-rebase (but from post-7.5 FSF GDB commits)
 
 
 diff --git a/gdb/Makefile.in b/gdb/Makefile.in
-index f07bc8b..3703dca 100644
+index a41cff9..d7786a6 100644
 --- a/gdb/Makefile.in
 +++ b/gdb/Makefile.in
-@@ -169,6 +169,12 @@ TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@
- TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
- # Did the user give us a --with-gdb-datadir option?
-+GDB_DATADIR_PATH = @GDB_DATADIR_PATH@
-+
-+# The argument to --with-pythondir.  If not given, this is
-+# GDB_DATADIR_PATH/python.
-+pythondir = @pythondir@
-+
- GDB_DATADIR = @GDB_DATADIR@
- # Helper code from gnulib.
-@@ -295,13 +301,13 @@ SUBDIR_PYTHON_SRCS = \
-       python/py-cmd.c \
-       python/py-frame.c \
-       python/py-function.c \
-+      python/py-hooks.c \
-       python/py-inferior.c \
-       python/py-infthread.c \
-       python/py-lazy-string.c \
-       python/py-objfile.c \
-       python/py-param.c \
-       python/py-prettyprint.c \
--      python/py-progspace.c \
-       python/py-symbol.c \
-       python/py-symtab.c \
-       python/py-type.c \
-@@ -780,8 +786,8 @@ config/rs6000/nm-rs6000.h top.h bsd-kvm.h gdb-stabs.h reggroups.h \
- annotate.h sim-regno.h dictionary.h dfp.h main.h frame-unwind.h       \
- remote-fileio.h i386-linux-tdep.h vax-tdep.h objc-lang.h \
- sentinel-frame.h bcache.h symfile.h windows-tdep.h linux-tdep.h \
--gdb_usleep.h jit.h xml-syscall.h ada-operator.inc microblaze-tdep.h \
--psymtab.h psympriv.h
-+gdb_usleep.h jit.h python/python.h python/python-internal.h \
-+xml-syscall.h ada-operator.inc microblaze-tdep.h
+@@ -704,7 +704,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
+       exceptions.c expprint.c \
+       f-exp.y f-lang.c f-typeprint.c f-valprint.c filesystem.c \
+       findcmd.c findvar.c frame.c frame-base.c frame-unwind.c \
+-      gdbarch.c arch-utils.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \
++      gdbarch.c arch-utils.c gdb_bfd.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \
+       go-exp.y go-lang.c go-typeprint.c go-valprint.c \
+       inf-loop.c \
+       infcall.c \
+@@ -829,7 +829,7 @@ gnulib/import/extra/snippet/warn-on-use.h \
+ gnulib/import/stddef.in.h gnulib/import/inttypes.in.h inline-frame.h skip.h \
+ common/common-utils.h common/xml-utils.h common/buffer.h common/ptid.h \
+ common/format.h \
+-common/linux-osdata.h gdb-dlfcn.h auto-load.h probe.h stap-probe.h
++common/linux-osdata.h gdb-dlfcn.h auto-load.h probe.h stap-probe.h gdb_bfd.h
  
  # Header files that already have srcdir in them, or which are in objdir.
  
-@@ -1301,6 +1307,12 @@ stamp-h: $(srcdir)/config.in config.status
+@@ -879,7 +879,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
+       macrotab.o macrocmd.o macroexp.o macroscope.o \
+       mi-common.o \
+       event-loop.o event-top.o inf-loop.o completer.o \
+-      gdbarch.o arch-utils.o gdbtypes.o osabi.o copying.o \
++      gdbarch.o arch-utils.o gdbtypes.o gdb_bfd.o osabi.o copying.o \
+       memattr.o mem-break.o target.o parse.o language.o buildsym.o \
+       findcmd.o \
+       std-regs.o \
+@@ -1307,6 +1307,12 @@ stamp-h: $(srcdir)/config.in config.status
          CONFIG_LINKS= \
          $(SHELL) config.status
  
@@ -70,59 +54,29 @@ index f07bc8b..3703dca 100644
  config.status: $(srcdir)/configure configure.tgt configure.host
        $(SHELL) config.status --recheck
  
-@@ -2024,6 +2036,10 @@ py-function.o: $(srcdir)/python/py-function.c
-       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-function.c
-       $(POSTCOMPILE)
-+py-hooks.o: $(srcdir)/python/py-hooks.c
-+      $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-hooks.c
-+      $(POSTCOMPILE)
-+
- py-inferior.o: $(srcdir)/python/py-inferior.c
-       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-inferior.c
-       $(POSTCOMPILE)
-@@ -2072,6 +2088,36 @@ py-value.o: $(srcdir)/python/py-value.c
-       $(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-value.c
-       $(POSTCOMPILE)
-+# All python library files, with the "python/lib" stripped off.
-+# Note that we should only install files in the "gdb" module.
-+PY_FILES = gdb/FrameIterator.py gdb/FrameWrapper.py gdb/command/alias.py \
-+    gdb/command/backtrace.py gdb/command/require.py \
-+    gdb/command/pahole.py gdb/command/upto.py gdb/command/__init__.py \
-+    gdb/command/ignore_errors.py gdb/command/save_breakpoints.py \
-+    gdb/function/caller_is.py gdb/function/in_scope.py \
-+    gdb/function/__init__.py gdb/backtrace.py gdb/__init__.py
-+
-+# Install the Python library.  Python library files go under
-+# $(pythondir).
-+install-python:
-+      files='$(PY_FILES)'; for file in $$files; do \
-+        dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
-+        $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(pythondir)/$$dir; \
-+        $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(pythondir)/$$file; \
-+      done
-+
-+# Other packages may have their files installed in $(pythondir).
-+uninstall-python:
-+      files='$(PY_FILES)'; for file in $$files; do \
-+        slashdir=`echo "/$$file" | sed 's,/[^/]*$$,,'`; \
-+        rm -f $(DESTDIR)$(pythondir)/$$file; \
-+        while test "x$$file" != "x$$slashdir"; do \
-+          rmdir 2>/dev/null "$(DESTDIR)$(pythondir)$$slashdir"; \
-+          file="$$slashdir"; \
-+          slashdir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
-+        done \
-+      done
-+
- #
- # Dependency tracking.  Most of this is conditional on GNU Make being
- # found by configure; if GNU Make is not found, we fall back to a
+diff --git a/gdb/NEWS b/gdb/NEWS
+index b281824..4da886c 100644
+--- a/gdb/NEWS
++++ b/gdb/NEWS
+@@ -1,6 +1,13 @@
+               What has changed in GDB?
+            (Organized release by release)
++*** Changes since GDB 7.5
++
++* New commands (for set/show, see "New options" below)
++
++maint info bfds
++  List the BFDs known to GDB.
++
+ *** Changes in GDB 7.5
+ * GDB now supports x32 ABI.  Visit <http://sites.google.com/site/x32abi/>
 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
-index 1d4c38b..cafb88e 100644
+index aa090af..e672731 100644
 --- a/gdb/ada-lang.c
 +++ b/gdb/ada-lang.c
-@@ -11114,6 +11114,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
+@@ -12037,6 +12037,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
  
  static int
  ada_operator_check (struct expression *exp, int pos,
@@ -130,7 +84,7 @@ index 1d4c38b..cafb88e 100644
                    int (*objfile_func) (struct objfile *objfile, void *data),
                    void *data)
  {
-@@ -11128,12 +11129,15 @@ ada_operator_check (struct expression *exp, int pos,
+@@ -12051,12 +12052,15 @@ ada_operator_check (struct expression *exp, int pos,
        break;
  
        default:
@@ -148,46 +102,59 @@ index 1d4c38b..cafb88e 100644
        && (*objfile_func) (TYPE_OBJFILE (type), data))
      return 1;
  
-diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
-index c0edc10..17d36b5 100644
---- a/gdb/amd64-linux-nat.c
-+++ b/gdb/amd64-linux-nat.c
-@@ -375,6 +375,20 @@ amd64_linux_dr_unset_status (unsigned long mask)
-     }
- }
-+/* See i386_dr_low_type.detach.  Do not use wrappers amd64_linux_dr_set_control
-+   or amd64_linux_dr_reset_addr as they would modify the register cache
-+   (amd64_linux_dr).  */
-+
-+static void
-+amd64_linux_dr_detach (void)
-+{
-+  int regnum;
-+
-+  amd64_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
-+  amd64_linux_dr_unset_status (~0UL);
-+  for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
-+    amd64_linux_dr_set (inferior_ptid, regnum, 0);
-+}
+diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c
+index 6728800..455d3e6 100644
+--- a/gdb/bfd-target.c
++++ b/gdb/bfd-target.c
+@@ -21,6 +21,7 @@
+ #include "target.h"
+ #include "bfd-target.h"
+ #include "exec.h"
++#include "gdb_bfd.h"
  
- static void
- amd64_linux_new_thread (ptid_t ptid)
-@@ -796,6 +810,7 @@ _initialize_amd64_linux_nat (void)
-   i386_dr_low.reset_addr = amd64_linux_dr_reset_addr;
-   i386_dr_low.get_status = amd64_linux_dr_get_status;
-   i386_dr_low.unset_status = amd64_linux_dr_unset_status;
-+  i386_dr_low.detach = amd64_linux_dr_detach;
-   i386_set_debug_register_length (8);
-   /* Override the GNU/Linux inferior startup hook.  */
+ /* The object that is stored in the target_ops->to_data field has this
+    type.  */
+@@ -70,7 +71,7 @@ target_bfd_xclose (struct target_ops *t, int quitting)
+ {
+   struct target_bfd_data *data = t->to_data;
+-  bfd_close (data->bfd);
++  gdb_bfd_unref (data->bfd);
+   xfree (data->table.sections);
+   xfree (data);
+   xfree (t);
+@@ -84,6 +85,7 @@ target_bfd_reopen (struct bfd *abfd)
+   data = XZALLOC (struct target_bfd_data);
+   data->bfd = abfd;
++  gdb_bfd_ref (abfd);
+   build_section_table (abfd, &data->table.sections, &data->table.sections_end);
+   t = XZALLOC (struct target_ops);
+diff --git a/gdb/bfd-target.h b/gdb/bfd-target.h
+index 71001c5..7f4e628 100644
+--- a/gdb/bfd-target.h
++++ b/gdb/bfd-target.h
+@@ -23,9 +23,9 @@
+ struct bfd;
+ struct target_ops;
+-/* Given an existing BFD, re-open it as a "struct target_ops".  On
+-   close, it will also close the corresponding BFD (which is like
+-   freopen and fdopen).  */
++/* Given an existing BFD, re-open it as a "struct target_ops".  This
++   acquires a new reference to the BFD.  This reference will be
++   released when the target is closed.  */
+ struct target_ops *target_bfd_reopen (struct bfd *bfd);
+ #endif
 diff --git a/gdb/block.c b/gdb/block.c
-index 48ac21b..ffcc97f 100644
+index a0f82ec..097dbf6 100644
 --- a/gdb/block.c
 +++ b/gdb/block.c
-@@ -321,3 +321,21 @@ allocate_block (struct obstack *obstack)
+@@ -692,3 +692,21 @@ block_iter_match_next (const char *name,
  
-   return bl;
+   return block_iter_match_step (iterator, name, compare, 0);
  }
 +
 +/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
@@ -208,1430 +175,746 @@ index 48ac21b..ffcc97f 100644
 +  return SYMBOL_SYMTAB (func)->objfile;
 +}
 diff --git a/gdb/block.h b/gdb/block.h
-index 7eedb6c..a517e80 100644
+index 99c4788..6ceb704 100644
 --- a/gdb/block.h
 +++ b/gdb/block.h
-@@ -166,4 +166,6 @@ extern const struct block *block_global_block (const struct block *block);
- extern struct block *allocate_block (struct obstack *obstack);
+@@ -279,4 +279,6 @@ extern struct symbol *block_iter_match_next (const char *name,
+        (sym);                                         \
+        (sym) = block_iterator_next (&(iter)))
  
 +extern struct objfile *block_objfile (const struct block *block);
 +
  #endif /* BLOCK_H */
-diff --git a/gdb/blockframe.c b/gdb/blockframe.c
-index 0348bf4..f01d0ee 100644
---- a/gdb/blockframe.c
-+++ b/gdb/blockframe.c
-@@ -38,6 +38,7 @@
- #include "block.h"
- #include "inline-frame.h"
- #include "psymtab.h"
-+#include "elf-bfd.h"
- /* Return the innermost lexical block in execution
-    in a specified stack frame.  The frame address is assumed valid.
-@@ -159,6 +160,7 @@ static CORE_ADDR cache_pc_function_low = 0;
- static CORE_ADDR cache_pc_function_high = 0;
- static char *cache_pc_function_name = 0;
- static struct obj_section *cache_pc_function_section = NULL;
-+static int cache_pc_function_is_gnu_ifunc = 0;
- /* Clear cache, e.g. when symbol table is discarded. */
-@@ -169,6 +171,7 @@ clear_pc_function_cache (void)
-   cache_pc_function_high = 0;
-   cache_pc_function_name = (char *) 0;
-   cache_pc_function_section = NULL;
-+  cache_pc_function_is_gnu_ifunc = 0;
+diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
+index 78fffd3..224ba49 100644
+--- a/gdb/breakpoint.c
++++ b/gdb/breakpoint.c
+@@ -15519,6 +15519,24 @@ all_tracepoints (void)
+   return tp_vec;
  }
  
- /* Finds the "function" (text symbol) that is smaller than PC but
-@@ -184,7 +187,7 @@ clear_pc_function_cache (void)
- /* Backward compatibility, no section argument.  */
++#if 0
++/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
++
++static void
++breakpoint_types_mark_used (void)
++{
++  struct breakpoint *b;
++
++  ALL_BREAKPOINTS (b)
++    {
++      if (b->exp)
++      exp_types_mark_used (b->exp);
++      if (b->val)
++      type_mark_used (value_type (b->val));
++    }
++}
++#endif
++
\f
+ /* This help string is used for the break, hbreak, tbreak and thbreak
+    commands.  It is defined as a macro to prevent duplication.
+@@ -16484,4 +16502,7 @@ agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
+   automatic_hardware_breakpoints = 1;
  
--int
-+enum find_pc_partial_function_type
- find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
-                         CORE_ADDR *endaddr)
+   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
++#if 0
++  observer_attach_mark_used (breakpoint_types_mark_used);
++#endif
+ }
+diff --git a/gdb/buildsym.c b/gdb/buildsym.c
+index d547012..e4882fb 100644
+--- a/gdb/buildsym.c
++++ b/gdb/buildsym.c
+@@ -966,11 +966,14 @@ reset_symtab_globals (void)
+    file's text.
+    If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
+-   expandable.  */
++   expandable.
++
++   If REQUIRED is non-zero, then a symtab is created even if it does
++   not contain any symbols.  */
+ struct block *
+ end_symtab_get_static_block (CORE_ADDR end_addr, struct objfile *objfile,
+-                           int expandable)
++                           int expandable, int required)
  {
-@@ -236,6 +239,7 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
-         cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
-         cache_pc_function_name = SYMBOL_LINKAGE_NAME (f);
-         cache_pc_function_section = section;
-+        cache_pc_function_is_gnu_ifunc = TYPE_GNU_IFUNC (SYMBOL_TYPE (f));
-         goto return_cached_value;
-       }
-     }
-@@ -258,12 +262,13 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
-       *address = 0;
-       if (endaddr != NULL)
-       *endaddr = 0;
--      return 0;
-+      return FIND_PC_PARTIAL_FUNCTION_NOT_FOUND;
-     }
+   /* Finish the lexical context of the last function in the file; pop
+      the context stack.  */
+@@ -1038,7 +1041,8 @@ end_symtab_get_static_block (CORE_ADDR end_addr, struct objfile *objfile,
+   cleanup_undefined_stabs_types (objfile);
+   finish_global_stabs (objfile);
+-  if (pending_blocks == NULL
++  if (!required
++      && pending_blocks == NULL
+       && file_symbols == NULL
+       && global_symbols == NULL
+       && have_line_numbers == 0
+@@ -1296,7 +1300,7 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
+ {
+   struct block *static_block;
  
-   cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
-   cache_pc_function_name = SYMBOL_LINKAGE_NAME (msymbol);
-   cache_pc_function_section = section;
-+  cache_pc_function_is_gnu_ifunc = MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
+-  static_block = end_symtab_get_static_block (end_addr, objfile, 0);
++  static_block = end_symtab_get_static_block (end_addr, objfile, 0, 0);
+   return end_symtab_from_static_block (static_block, objfile, section, 0);
+ }
  
-   /* If the minimal symbol has a size, use it for the cache.
-      Otherwise use the lesser of the next minimal symbol in the same
-@@ -323,7 +328,8 @@ find_pc_partial_function (CORE_ADDR pc, char **name, CORE_ADDR *address,
-       *endaddr = cache_pc_function_high;
-     }
+@@ -1308,7 +1312,7 @@ end_expandable_symtab (CORE_ADDR end_addr, struct objfile *objfile,
+ {
+   struct block *static_block;
  
--  return 1;
-+  return cache_pc_function_is_gnu_ifunc ? FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
-+                                      : FIND_PC_PARTIAL_FUNCTION_NORMAL;
+-  static_block = end_symtab_get_static_block (end_addr, objfile, 1);
++  static_block = end_symtab_get_static_block (end_addr, objfile, 1, 0);
+   return end_symtab_from_static_block (static_block, objfile, section, 1);
  }
  
- /* Return the innermost stack frame executing inside of BLOCK,
-diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
-index 6a6864c..5df336d 100644
---- a/gdb/breakpoint.c
-+++ b/gdb/breakpoint.c
-@@ -62,6 +62,7 @@
- #include "jit.h"
- #include "xml-syscall.h"
- #include "parser-defs.h"
-+#include "regcache.h"
+diff --git a/gdb/buildsym.h b/gdb/buildsym.h
+index 162ee8c..33b34c8 100644
+--- a/gdb/buildsym.h
++++ b/gdb/buildsym.h
+@@ -260,7 +260,8 @@ extern char *pop_subfile (void);
  
- /* readline include files */
- #include "readline/readline.h"
-@@ -92,6 +93,9 @@ static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
+ extern struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
+                                                 struct objfile *objfile,
+-                                                int expandable);
++                                                int expandable,
++                                                int required);
  
- static void ignore_command (char *, int);
+ extern struct symtab *end_symtab_from_static_block (struct block *static_block,
+                                                   struct objfile *objfile,
+diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
+index a5892b5..2944c2d 100644
+--- a/gdb/c-typeprint.c
++++ b/gdb/c-typeprint.c
+@@ -624,9 +624,14 @@ c_type_print_varspec_suffix (struct type *type,
+         fprintf_filtered (stream, ")");
+       fprintf_filtered (stream, "[");
+-      if (get_array_bounds (type, &low_bound, &high_bound))
+-        fprintf_filtered (stream, "%d", 
+-                          (int) (high_bound - low_bound + 1));
++      if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind
++          != RANGE_BOUND_KIND_CONSTANT)
++        {
++          /* No _() - printed sources should not be locale dependent.  */
++          fprintf_filtered (stream, "variable");
++        }
++      else if (get_array_bounds (type, &low_bound, &high_bound))
++        fprintf_filtered (stream, "%d", (int) (high_bound - low_bound + 1));
+       fprintf_filtered (stream, "]");
+       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
+diff --git a/gdb/cc-with-dwz.sh b/gdb/cc-with-dwz.sh
+deleted file mode 100755
+index f66deb1..0000000
+--- a/gdb/cc-with-dwz.sh
++++ /dev/null
+@@ -1,80 +0,0 @@
+-#! /bin/sh
+-# Wrapper around gcc to run 'dwz' when running the testsuite.
+-
+-# Copyright (C) 2010-2012 Free Software Foundation, Inc.
+-# This program is free software; you can redistribute it and/or modify
+-# it under the terms of the GNU General Public License as published by
+-# the Free Software Foundation; either version 3 of the License, or
+-# (at your option) any later version.
+-#
+-# This program is distributed in the hope that it will be useful,
+-# but WITHOUT ANY WARRANTY; without even the implied warranty of
+-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-# GNU General Public License for more details.
+-#
+-# You should have received a copy of the GNU General Public License
+-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-
+-# This program requires dwz in addition to gcc.
+-#
+-# Example usage:
+-#
+-# bash$ cd $objdir/gdb/testsuite
+-# bash$ runtest \
+-#   CC_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh gcc" \
+-#   CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-dwz.sh g++"
+-#
+-
+-myname=cc-with-dwz.sh
+-
+-DWZ=${DWZ:-dwz}
+-
+-have_link=unknown
+-next_is_output_file=no
+-output_file=a.out
+-
+-for arg in "$@"
+-do
+-    if [ "$next_is_output_file" = "yes" ]
+-    then
+-      output_file="$arg"
+-      next_is_output_file=no
+-      continue
+-    fi
+-
+-    # Poor man's gcc argument parser.
+-    # We don't need to handle all arguments, we just need to know if we're
+-    # doing a link and what the output file is.
+-    # It's not perfect, but it seems to work well enough for the task at hand.
+-    case "$arg" in
+-    "-c") have_link=no ;;
+-    "-E") have_link=no ;;
+-    "-S") have_link=no ;;
+-    "-o") next_is_output_file=yes ;;
+-    esac
+-done
+-
+-if [ "$next_is_output_file" = "yes" ]
+-then
+-    echo "$myname: Unable to find output file" >&2
+-    exit 1
+-fi
+-
+-if [ "$have_link" = "no" ]
+-then
+-    "$@"
+-    exit $?
+-fi
+-
+-"$@"
+-rc=$?
+-[ $rc != 0 ] && exit $rc
+-if [ ! -f "$output_file" ]
+-then
+-    echo "$myname: Internal error: $output_file missing." >&2
+-    exit 1
+-fi
+-
+-$DWZ "$output_file" > /dev/null 2>&1
+-
+-exit 0
+diff --git a/gdb/cc-with-index.sh b/gdb/cc-with-index.sh
+deleted file mode 100644
+index 644ba34..0000000
+--- a/gdb/cc-with-index.sh
++++ /dev/null
+@@ -1,126 +0,0 @@
+-#! /bin/sh
+-# Wrapper around gcc to add the .gdb_index section when running the testsuite.
+-
+-# Copyright (C) 2010-2012 Free Software Foundation, Inc.
+-# This program is free software; you can redistribute it and/or modify
+-# it under the terms of the GNU General Public License as published by
+-# the Free Software Foundation; either version 3 of the License, or
+-# (at your option) any later version.
+-#
+-# This program is distributed in the hope that it will be useful,
+-# but WITHOUT ANY WARRANTY; without even the implied warranty of
+-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-# GNU General Public License for more details.
+-#
+-# You should have received a copy of the GNU General Public License
+-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-
+-# This program requires gdb and objcopy in addition to gcc.
+-# The default values are gdb from the build tree and objcopy from $PATH.
+-# They may be overridden by setting environment variables GDB and OBJCOPY
+-# respectively.
+-# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
+-#
+-# Example usage:
+-#
+-# bash$ cd $objdir/gdb/testsuite
+-# bash$ runtest \
+-#   CC_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh gcc" \
+-#   CXX_FOR_TARGET="/bin/sh $srcdir/cc-with-index.sh g++"
+-#
+-# For documentation on index files: info -f gdb.info -n "Index Files"
+-
+-myname=cc-with-index.sh
+-
+-if [ -z "$GDB" ]
+-then
+-    if [ -f ./gdb ]
+-    then
+-      GDB="./gdb"
+-    elif [ -f ../gdb ]
+-    then
+-      GDB="../gdb"
+-    elif [ -f ../../gdb ]
+-    then
+-      GDB="../../gdb"
+-    else
+-      echo "$myname: unable to find usable gdb" >&2
+-      exit 1
+-    fi
+-fi
+-
+-OBJCOPY=${OBJCOPY:-objcopy}
+-
+-have_link=unknown
+-next_is_output_file=no
+-output_file=a.out
+-
+-for arg in "$@"
+-do
+-    if [ "$next_is_output_file" = "yes" ]
+-    then
+-      output_file="$arg"
+-      next_is_output_file=no
+-      continue
+-    fi
+-
+-    # Poor man's gcc argument parser.
+-    # We don't need to handle all arguments, we just need to know if we're
+-    # doing a link and what the output file is.
+-    # It's not perfect, but it seems to work well enough for the task at hand.
+-    case "$arg" in
+-    "-c") have_link=no ;;
+-    "-E") have_link=no ;;
+-    "-S") have_link=no ;;
+-    "-o") next_is_output_file=yes ;;
+-    esac
+-done
+-
+-if [ "$next_is_output_file" = "yes" ]
+-then
+-    echo "$myname: Unable to find output file" >&2
+-    exit 1
+-fi
+-
+-if [ "$have_link" = "no" ]
+-then
+-    "$@"
+-    exit $?
+-fi
+-
+-index_file="${output_file}.gdb-index"
+-if [ -f "$index_file" ]
+-then
+-    echo "$myname: Index file $index_file exists, won't clobber." >&2
+-    exit 1
+-fi
+-
+-output_dir="${output_file%/*}"
+-[ "$output_dir" = "$output_file" ] && output_dir="."
+-
+-"$@"
+-rc=$?
+-[ $rc != 0 ] && exit $rc
+-if [ ! -f "$output_file" ]
+-then
+-    echo "$myname: Internal error: $output_file missing." >&2
+-    exit 1
+-fi
+-
+-$GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
+-rc=$?
+-[ $rc != 0 ] && exit $rc
+-
+-# GDB might not always create an index.  Cope.
+-if [ -f "$index_file" ]
+-then
+-    $OBJCOPY --add-section .gdb_index="$index_file" \
+-      --set-section-flags .gdb_index=readonly \
+-      "$output_file" "$output_file"
+-    rc=$?
+-else
+-    rc=0
+-fi
+-
+-rm -f "$index_file"
+-exit $rc
+diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
+index 4a8b5d1..7341f00 100644
+--- a/gdb/cli/cli-dump.c
++++ b/gdb/cli/cli-dump.c
+@@ -32,6 +32,7 @@
+ #include "readline/readline.h"
+ #include "gdbcore.h"
+ #include "cli/cli-utils.h"
++#include "gdb_bfd.h"
  
-+static void update_breakpoint_locations (struct breakpoint *b,
-+                                       struct symtabs_and_lines sals);
-+
- static int breakpoint_re_set_one (void *);
+ #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
  
- static void clear_command (char *, int);
-@@ -106,6 +110,9 @@ static void break_command_1 (char *, int, int);
+@@ -111,12 +112,12 @@ bfd_openr_with_cleanup (const char *filename, const char *target)
+ {
+   bfd *ibfd;
  
- static void mention (struct breakpoint *);
+-  ibfd = bfd_openr (filename, target);
++  ibfd = gdb_bfd_openr (filename, target);
+   if (ibfd == NULL)
+     error (_("Failed to open %s: %s."), filename, 
+          bfd_errmsg (bfd_get_error ()));
  
-+static struct bp_location *add_location_to_breakpoint (struct breakpoint *b,
-+                                           const struct symtab_and_line *sal);
-+
- /* This function is used in gdbtk sources and thus can not be made static.  */
- struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch,
-                                             struct symtab_and_line,
-@@ -230,6 +237,10 @@ static void disable_trace_command (char *, int);
+-  make_cleanup_bfd_close (ibfd);
++  make_cleanup_bfd_unref (ibfd);
+   if (!bfd_check_format (ibfd, bfd_object))
+     error (_("'%s' is not a recognized file format."), filename);
  
- static void trace_pass_command (char *, int);
+@@ -131,11 +132,11 @@ bfd_openw_with_cleanup (const char *filename, const char *target,
  
-+static void gnu_ifunc_resolver_stop (struct breakpoint *b);
-+
-+static void gnu_ifunc_resolver_return_stop (struct breakpoint *b);
-+
- /* Assuming we're creating a static tracepoint, does S look like a
-    static tracepoint marker spec ("-m MARKER_ID")?  */
- #define is_marker_spec(s)                                             \
-@@ -430,7 +441,7 @@ static int tracepoint_count;
+   if (*mode == 'w')   /* Write: create new file */
+     {
+-      obfd = bfd_openw (filename, target);
++      obfd = gdb_bfd_openw (filename, target);
+       if (obfd == NULL)
+       error (_("Failed to open %s: %s."), filename, 
+              bfd_errmsg (bfd_get_error ()));
+-      make_cleanup_bfd_close (obfd);
++      make_cleanup_bfd_unref (obfd);
+       if (!bfd_set_format (obfd, bfd_object))
+       error (_("bfd_openw_with_cleanup: %s."), bfd_errmsg (bfd_get_error ()));
+     }
+diff --git a/gdb/coffread.c b/gdb/coffread.c
+index b0a8b82..0c7e6d9 100644
+--- a/gdb/coffread.c
++++ b/gdb/coffread.c
+@@ -653,13 +653,14 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
+       char *debugfile;
  
- static struct cmd_list_element *breakpoint_set_cmdlist;
- static struct cmd_list_element *breakpoint_show_cmdlist;
--static struct cmd_list_element *save_cmdlist;
-+struct cmd_list_element *save_cmdlist;
+       debugfile = find_separate_debug_file_by_debuglink (objfile);
++      make_cleanup (xfree, debugfile);
  
- /* Return whether a breakpoint is an active enabled breakpoint.  */
- static int
-@@ -1252,6 +1263,22 @@ watchpoint_in_thread_scope (struct breakpoint *b)
-             && !is_executing (inferior_ptid)));
- }
+       if (debugfile)
+       {
+         bfd *abfd = symfile_bfd_open (debugfile);
  
-+static void
-+watchpoint_del_at_next_stop (struct breakpoint *b)
-+{
-+  gdb_assert (is_watchpoint (b));
-+
-+  if (b->related_breakpoint != b)
-+    {
-+      gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope);
-+      gdb_assert (b->related_breakpoint->related_breakpoint == b);
-+      b->related_breakpoint->disposition = disp_del_at_next_stop;
-+      b->related_breakpoint->related_breakpoint = b->related_breakpoint;
-+      b->related_breakpoint = b;
-+    }
-+  b->disposition = disp_del_at_next_stop;
-+}
-+
- /* Assuming that B is a watchpoint:
-    - Reparse watchpoint expression, if REPARSE is non-zero
-    - Evaluate expression and store the result in B->val
-@@ -1307,6 +1334,8 @@ update_watchpoint (struct breakpoint *b, int reparse)
-   struct frame_id saved_frame_id;
-   int frame_saved;
-+  gdb_assert (is_watchpoint (b));
-+
-   /* If this is a local watchpoint, we only want to check if the
-      watchpoint frame is in scope if the current thread is the thread
-      that was used to create the watchpoint.  */
-@@ -1510,13 +1539,7 @@ update_watchpoint (struct breakpoint *b, int reparse)
- Watchpoint %d deleted because the program has left the block\n\
- in which its expression is valid.\n"),
-                      b->number);
--      if (b->related_breakpoint)
--      {
--        b->related_breakpoint->disposition = disp_del_at_next_stop;
--        b->related_breakpoint->related_breakpoint = NULL;
--        b->related_breakpoint= NULL;
--      }
--      b->disposition = disp_del_at_next_stop;
-+      watchpoint_del_at_next_stop (b);
++        make_cleanup_bfd_unref (abfd);
+         symbol_file_add_separate (abfd, symfile_flags, objfile);
+-        xfree (debugfile);
+       }
      }
  
-   /* Restore the selected frame.  */
-@@ -2201,6 +2224,33 @@ create_std_terminate_master_breakpoint (const char *func_name)
-   do_cleanups (old_chain);
- }
-+/* Install a master breakpoint on the unwinder's debug hook.  */
+diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
+new file mode 100755
+index 0000000..7d7932c
+--- /dev/null
++++ b/gdb/contrib/cc-with-tweaks.sh
+@@ -0,0 +1,162 @@
++#! /bin/sh
++# Wrapper around gcc to tweak the output in various ways when running
++# the testsuite.
 +
-+void
-+create_exception_master_breakpoint (void)
-+{
-+  struct objfile *objfile;
++# Copyright (C) 2010-2012 Free Software Foundation, Inc.
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+  ALL_OBJFILES (objfile)
-+    {
-+      struct minimal_symbol *debug_hook;
++# This program requires gdb and objcopy in addition to gcc.
++# The default values are gdb from the build tree and objcopy from $PATH.
++# They may be overridden by setting environment variables GDB and OBJCOPY
++# respectively.
++# We assume the current directory is either $obj/gdb or $obj/gdb/testsuite.
++#
++# Example usage:
++#
++# bash$ cd $objdir/gdb/testsuite
++# bash$ runtest \
++#   CC_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS gcc" \
++#   CXX_FOR_TARGET="/bin/sh $srcdir/gdb/contrib/cc-with-tweaks.sh ARGS g++"
++#
++# For documentation on index files: info -f gdb.info -n "Index Files"
++# For information about 'dwz', see the announcement:
++#     http://gcc.gnu.org/ml/gcc/2012-04/msg00686.html
++# (More documentation is to come.)
++
++# ARGS determine what is done.  They can be:
++# -z compress using dwz
++# -m compress using dwz -m
++# -i make an index
++# If nothing is given, no changes are made
++
++myname=cc-with-tweaks.sh
++
++if [ -z "$GDB" ]
++then
++    if [ -f ./gdb ]
++    then
++      GDB="./gdb"
++    elif [ -f ../gdb ]
++    then
++      GDB="../gdb"
++    elif [ -f ../../gdb ]
++    then
++      GDB="../../gdb"
++    else
++      echo "$myname: unable to find usable gdb" >&2
++      exit 1
++    fi
++fi
 +
-+      debug_hook = lookup_minimal_symbol_text ("_Unwind_DebugHook", objfile);
-+      if (debug_hook != NULL)
-+      {
-+        struct breakpoint *b;
++OBJCOPY=${OBJCOPY:-objcopy}
++
++DWZ=${DWZ:-dwz}
++
++have_link=unknown
++next_is_output_file=no
++output_file=a.out
++
++want_index=false
++want_dwz=false
++want_multi=false
++
++while [ $# -gt 0 ]; do
++    case "$1" in
++      -z) want_dwz=true ;;
++      -i) want_index=true ;;
++      -m) want_multi=true ;;
++      *) break ;;
++    esac
++    shift
++done
++
++for arg in "$@"
++do
++    if [ "$next_is_output_file" = "yes" ]
++    then
++      output_file="$arg"
++      next_is_output_file=no
++      continue
++    fi
++
++    # Poor man's gcc argument parser.
++    # We don't need to handle all arguments, we just need to know if we're
++    # doing a link and what the output file is.
++    # It's not perfect, but it seems to work well enough for the task at hand.
++    case "$arg" in
++    "-c") have_link=no ;;
++    "-E") have_link=no ;;
++    "-S") have_link=no ;;
++    "-o") next_is_output_file=yes ;;
++    esac
++done
++
++if [ "$next_is_output_file" = "yes" ]
++then
++    echo "$myname: Unable to find output file" >&2
++    exit 1
++fi
 +
-+        b = create_internal_breakpoint (get_objfile_arch (objfile),
-+                                        SYMBOL_VALUE_ADDRESS (debug_hook),
-+                                        bp_exception_master);
-+        b->addr_string = xstrdup ("_Unwind_DebugHook");
-+        b->enable_state = bp_disabled;
-+      }
-+    }
++if [ "$have_link" = "no" ]
++then
++    "$@"
++    exit $?
++fi
 +
-+  update_global_location_list (1);
-+}
++index_file="${output_file}.gdb-index"
++if [ "$want_index" = true ] && [ -f "$index_file" ]
++then
++    echo "$myname: Index file $index_file exists, won't clobber." >&2
++    exit 1
++fi
 +
- void
- update_breakpoints_after_exec (void)
- {
-@@ -2242,7 +2292,8 @@ update_breakpoints_after_exec (void)
-     /* Thread event breakpoints must be set anew after an exec(),
-        as must overlay event and longjmp master breakpoints.  */
-     if (b->type == bp_thread_event || b->type == bp_overlay_event
--      || b->type == bp_longjmp_master || b->type == bp_std_terminate_master)
-+      || b->type == bp_longjmp_master || b->type == bp_std_terminate_master
-+      || b->type == bp_exception_master)
-       {
-       delete_breakpoint (b);
-       continue;
-@@ -2257,7 +2308,8 @@ update_breakpoints_after_exec (void)
-     /* Longjmp and longjmp-resume breakpoints are also meaningless
-        after an exec.  */
--    if (b->type == bp_longjmp || b->type == bp_longjmp_resume)
-+    if (b->type == bp_longjmp || b->type == bp_longjmp_resume
-+      || b->type == bp_exception || b->type == bp_exception_resume)
-       {
-       delete_breakpoint (b);
-       continue;
-@@ -2319,6 +2371,7 @@ update_breakpoints_after_exec (void)
-   create_longjmp_master_breakpoint ("siglongjmp");
-   create_longjmp_master_breakpoint ("_siglongjmp");
-   create_std_terminate_master_breakpoint ("std::terminate()");
-+  create_exception_master_breakpoint ();
- }
- int
-@@ -2346,6 +2399,8 @@ detach_breakpoints (int pid)
-   /* Detach single-step breakpoints as well.  */
-   detach_single_step_breakpoints ();
-+  val |= target_detach_watchpoints ();
++output_dir="${output_file%/*}"
++[ "$output_dir" = "$output_file" ] && output_dir="."
 +
-   do_cleanups (old_chain);
-   return val;
- }
-@@ -2447,9 +2502,11 @@ remove_breakpoint_1 (struct bp_location *b, insertion_state_t is)
-       return val;
-       b->inserted = (is == mark_inserted);
-     }
--  else if (b->loc_type == bp_loc_hardware_watchpoint)
-+  /* bp_loc_hardware_watchpoint with mark_inserted is being handled by
-+     target_detach_watchpoints.  */
-+  else if (b->loc_type == bp_loc_hardware_watchpoint && is == mark_uninserted)
-     {
--      b->inserted = (is == mark_inserted);
-+      b->inserted = 0;
-       val = target_remove_watchpoint (b->address, b->length,
-                                     b->watchpoint_type, b->owner->cond_exp);
-@@ -3237,6 +3294,12 @@ print_it_typical (bpstat bs)
-       result = PRINT_NOTHING;
-       break;
-+    case bp_exception_master:
-+      /* These should never be enabled.  */
-+      printf_filtered (_("Exception Master Breakpoint: gdb should not stop!\n"));
-+      result = PRINT_NOTHING;
-+      break;
++"$@"
++rc=$?
++[ $rc != 0 ] && exit $rc
++if [ ! -f "$output_file" ]
++then
++    echo "$myname: Internal error: $output_file missing." >&2
++    exit 1
++fi
 +
-     case bp_watchpoint:
-     case bp_hardware_watchpoint:
-       annotate_watchpoint (b->number);
-@@ -3324,6 +3387,8 @@ print_it_typical (bpstat bs)
-     case bp_none:
-     case bp_longjmp:
-     case bp_longjmp_resume:
-+    case bp_exception:
-+    case bp_exception_resume:
-     case bp_step_resume:
-     case bp_watchpoint_scope:
-     case bp_call_dummy:
-@@ -3331,6 +3396,8 @@ print_it_typical (bpstat bs)
-     case bp_tracepoint:
-     case bp_fast_tracepoint:
-     case bp_jit_event:
-+    case bp_gnu_ifunc_resolver:
-+    case bp_gnu_ifunc_resolver_return:
-     default:
-       result = PRINT_UNKNOWN;
-       break;
-@@ -3549,6 +3616,8 @@ watchpoint_check (void *p)
-   gdb_assert (bs->breakpoint_at->owner != NULL);
-   b = bs->breakpoint_at->owner;
-+  gdb_assert (is_watchpoint (b));
++if [ "$want_index" = true ]; then
++    $GDB --batch-silent -nx -ex "set auto-load no" -ex "file $output_file" -ex "save gdb-index $output_dir"
++    rc=$?
++    [ $rc != 0 ] && exit $rc
++
++    # GDB might not always create an index.  Cope.
++    if [ -f "$index_file" ]
++    then
++      $OBJCOPY --add-section .gdb_index="$index_file" \
++          --set-section-flags .gdb_index=readonly \
++          "$output_file" "$output_file"
++      rc=$?
++    else
++      rc=0
++    fi
++    [ $rc != 0 ] && exit $rc
++fi
++
++if [ "$want_dwz" = true ]; then
++    $DWZ "$output_file" > /dev/null 2>&1
++elif [ "$want_multi" = true ]; then
++    cp $output_file ${output_file}.alt
++    $DWZ -m ${output_file}.dwz "$output_file" ${output_file}.alt > /dev/null 2>&1
++fi
 +
-   /* If this is a local watchpoint, we only want to check if the
-      watchpoint frame is in scope if the current thread is the thread
-      that was used to create the watchpoint.  */
-@@ -3655,13 +3724,7 @@ watchpoint_check (void *p)
-       ui_out_text (uiout, " deleted because the program has left the block in\n\
- which its expression is valid.\n");     
++rm -f "$index_file"
++exit $rc
+diff --git a/gdb/corelow.c b/gdb/corelow.c
+index dd62560..340b149 100644
+--- a/gdb/corelow.c
++++ b/gdb/corelow.c
+@@ -46,6 +46,7 @@
+ #include "filenames.h"
+ #include "progspace.h"
+ #include "objfiles.h"
++#include "gdb_bfd.h"
  
--      if (b->related_breakpoint)
--      {
--        b->related_breakpoint->disposition = disp_del_at_next_stop;
--        b->related_breakpoint->related_breakpoint = NULL;
--        b->related_breakpoint = NULL;
--      }
--      b->disposition = disp_del_at_next_stop;
-+      watchpoint_del_at_next_stop (b);
+ #ifndef O_LARGEFILE
+ #define O_LARGEFILE 0
+@@ -215,9 +216,7 @@ core_close (int quitting)
+         core_data = NULL;
+       }
  
-       return WP_DELETED;
+-      name = bfd_get_filename (core_bfd);
+-      gdb_bfd_close_or_warn (core_bfd);
+-      xfree (name);
++      gdb_bfd_unref (core_bfd);
+       core_bfd = NULL;
      }
-@@ -3730,8 +3793,12 @@ bpstat_check_location (const struct bp_location *bl,
- /* If BS refers to a watchpoint, determine if the watched values
-    has actually changed, and we should stop.  If not, set BS->stop
--   to 0.  */
--static void
-+   to 0.
-+   Return 0 for watchpoints which could not be the cause of this trap.
-+   In such case PRINT_IT will be print_it_noop and STOP will be 0.
-+   Otherwise return 1 but in such case it is not guaranteed whether this
-+   breakpoint did or did not trigger this trap.  */
-+static int
- bpstat_check_watchpoint (bpstat bs)
- {
-   const struct bp_location *bl;
-@@ -3865,9 +3932,7 @@ bpstat_check_watchpoint (bpstat bs)
-           case 0:
-             /* Error from catch_errors.  */
-             printf_filtered (_("Watchpoint %d deleted.\n"), b->number);
--            if (b->related_breakpoint)
--              b->related_breakpoint->disposition = disp_del_at_next_stop;
--            b->disposition = disp_del_at_next_stop;
-+            watchpoint_del_at_next_stop (b);
-             /* We've already printed what needs to be printed.  */
-             bs->print_it = print_it_done;
-             break;
-@@ -3881,8 +3946,10 @@ bpstat_check_watchpoint (bpstat bs)
-            anything for this watchpoint.  */
-         bs->print_it = print_it_noop;
-         bs->stop = 0;
-+        return 0;
-       }
+   core_vec = NULL;
+@@ -319,9 +318,9 @@ core_open (char *filename, int from_tty)
+   if (scratch_chan < 0)
+     perror_with_name (filename);
+-  temp_bfd = bfd_fopen (filename, gnutarget, 
+-                      write_files ? FOPEN_RUB : FOPEN_RB,
+-                      scratch_chan);
++  temp_bfd = gdb_bfd_fopen (filename, gnutarget, 
++                          write_files ? FOPEN_RUB : FOPEN_RB,
++                          scratch_chan);
+   if (temp_bfd == NULL)
+     perror_with_name (filename);
+@@ -332,7 +331,7 @@ core_open (char *filename, int from_tty)
+       /* FIXME: should be checking for errors from bfd_close (for one
+          thing, on error it does not free all the storage associated
+          with the bfd).  */
+-      make_cleanup_bfd_close (temp_bfd);
++      make_cleanup_bfd_unref (temp_bfd);
+       error (_("\"%s\" is not a core dump: %s"),
+            filename, bfd_errmsg (bfd_get_error ()));
      }
-+  return 1;
- }
+@@ -340,7 +339,7 @@ core_open (char *filename, int from_tty)
+   /* Looks semi-reasonable.  Toss the old core file and work on the
+      new.  */
  
+-  discard_cleanups (old_chain);       /* Don't free filename any more */
++  do_cleanups (old_chain);
+   unpush_target (&core_ops);
+   core_bfd = temp_bfd;
+   old_chain = make_cleanup (core_close_cleanup, 0 /*ignore*/);
+diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
+index 87c6dd4..1c26652 100644
+--- a/gdb/data-directory/Makefile.in
++++ b/gdb/data-directory/Makefile.in
+@@ -52,14 +52,25 @@ SYSCALLS_FILES = \
+ PYTHON_DIR = python
+ PYTHON_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(PYTHON_DIR)
+ PYTHON_FILES = \
++      gdb/FrameIterator.py \
++      gdb/FrameWrapper.py \
+       gdb/__init__.py \
+-      gdb/types.py \
+-      gdb/printing.py \
+-      gdb/prompt.py \
++      gdb/backtrace.py \
+       gdb/command/__init__.py \
++      gdb/command/backtrace.py \
++      gdb/command/ignore_errors.py \
++      gdb/command/pahole.py \
+       gdb/command/pretty_printers.py \
+       gdb/command/prompt.py \
+-      gdb/command/explore.py
++      gdb/command/explore.py \
++      gdb/command/require.py \
++      gdb/command/upto.py \
++      gdb/function/__init__.py \
++      gdb/function/caller_is.py \
++      gdb/function/in_scope.py \
++      gdb/printing.py \
++      gdb/prompt.py \
++      gdb/types.py
+ FLAGS_TO_PASS = \
+       "prefix=$(prefix)" \
+diff --git a/gdb/defs.h b/gdb/defs.h
+index 1c6fa79..ec08348 100644
+--- a/gdb/defs.h
++++ b/gdb/defs.h
+@@ -315,7 +315,7 @@ extern struct cleanup *make_cleanup_close (int fd);
+ extern struct cleanup *make_cleanup_fclose (FILE *file);
+-extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
++extern struct cleanup *make_cleanup_bfd_unref (bfd *abfd);
+ struct obstack;
+ extern struct cleanup *make_cleanup_obstack_free (struct obstack *obstack);
+@@ -353,6 +353,8 @@ extern struct cleanup *make_cleanup_restore_page_info (void);
+ extern struct cleanup *
+   set_batch_flag_and_make_cleanup_restore_page_info (void);
++extern struct cleanup *make_cleanup_restore_selected_frame (void);
++
+ extern char *gdb_realpath (const char *);
+ extern char *xfullpath (const char *);
  
-@@ -3914,7 +3981,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
-        watchpoint as triggered so that we will handle the
-        out-of-scope event.  We'll get to the watchpoint next
-        iteration.  */
--      if (b->type == bp_watchpoint_scope)
-+      if (b->type == bp_watchpoint_scope && b->related_breakpoint != b)
-       b->related_breakpoint->watchpoint_triggered = watch_triggered_yes;
-       if (is_watchpoint (b))
-@@ -4045,6 +4112,8 @@ bpstat_stop_status (struct address_space *aspace,
-       for (bl = b->loc; bl != NULL; bl = bl->next)
-       {
-+        bpstat bs_prev = bs;
-+
-         /* For hardware watchpoints, we look only at the first location.
-            The watchpoint_check function will work on the entire expression,
-            not the individual locations.  For read watchpoints, the
-@@ -4062,6 +4131,7 @@ bpstat_stop_status (struct address_space *aspace,
-         /* Come here if it's a watchpoint, or if the break address matches */
-         bs = bpstat_alloc (bl, bs);   /* Alloc a bpstat to explain stop */
-+        gdb_assert (bs_prev->next == bs);
-         /* Assume we stop.  Should we find watchpoint that is not actually
-            triggered, or if condition of breakpoint is false, we'll reset
-@@ -4069,13 +4139,23 @@ bpstat_stop_status (struct address_space *aspace,
-         bs->stop = 1;
-         bs->print = 1;
--        bpstat_check_watchpoint (bs);
--        if (!bs->stop)
--          continue;
-+        if (!bpstat_check_watchpoint (bs))
-+          {
-+            /* Ensure bpstat_explains_signal stays false if this BL could not be
-+               the cause of this trap.  */
-+
-+            gdb_assert (bs->print_it == print_it_noop);
-+            gdb_assert (!bs->stop);
-+            xfree (bs);
-+            bs = bs_prev;
-+            bs->next = NULL;
-+            continue;
-+          }
-         if (b->type == bp_thread_event || b->type == bp_overlay_event
-             || b->type == bp_longjmp_master
--            || b->type == bp_std_terminate_master)
-+            || b->type == bp_std_terminate_master
-+            || b->type == bp_exception_master)
-           /* We do not stop for these.  */
-           bs->stop = 0;
-         else
-@@ -4176,7 +4256,7 @@ handle_jit_event (void)
- /* Decide what infrun needs to do with this bpstat.  */
+diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
+index 68ea817..5945bac 100644
+--- a/gdb/doc/gdb.texinfo
++++ b/gdb/doc/gdb.texinfo
+@@ -1200,6 +1200,16 @@ for remote debugging.
+ Run using @var{device} for your program's standard input and output.
+ @c FIXME: kingdon thinks there is more to -tty.  Investigate.
  
- struct bpstat_what
--bpstat_what (bpstat bs)
-+bpstat_what (bpstat bs_head)
- {
-   struct bpstat_what retval;
-   /* We need to defer calling `solib_add', as adding new symbols
-@@ -4184,11 +4264,13 @@ bpstat_what (bpstat bs)
-      and hence may clear unprocessed entries in the BS chain.  */
-   int shlib_event = 0;
-   int jit_event = 0;
-+  bpstat bs;
-   retval.main_action = BPSTAT_WHAT_KEEP_CHECKING;
-   retval.call_dummy = STOP_NONE;
-+  retval.is_longjmp = 0;
--  for (; bs != NULL; bs = bs->next)
-+  for (bs = bs_head; bs != NULL; bs = bs->next)
-     {
-       /* Extract this BS's action.  After processing each BS, we check
-        if its action overrides all we've seem so far.  */
-@@ -4242,10 +4324,15 @@ bpstat_what (bpstat bs)
-           }
-         break;
-       case bp_longjmp:
-+      case bp_exception:
-         this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME;
-+        retval.is_longjmp = bs->breakpoint_at->owner->type == bp_longjmp;
-         break;
-       case bp_longjmp_resume:
-+      case bp_exception_resume:
-         this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME;
-+        retval.is_longjmp
-+          = bs->breakpoint_at->owner->type == bp_longjmp_resume;
-         break;
-       case bp_step_resume:
-         if (bs->stop)
-@@ -4261,6 +4348,7 @@ bpstat_what (bpstat bs)
-       case bp_overlay_event:
-       case bp_longjmp_master:
-       case bp_std_terminate_master:
-+      case bp_exception_master:
-         this_action = BPSTAT_WHAT_SINGLE;
-         break;
-       case bp_catchpoint:
-@@ -4313,6 +4401,20 @@ bpstat_what (bpstat bs)
-            out already.  */
-         internal_error (__FILE__, __LINE__,
-                         _("bpstat_what: tracepoint encountered"));
-+        break;
-+      case bp_gnu_ifunc_resolver:
-+        /* Skip the current breakpoint but otherwise nothing happens.  GDB is
-+           inserting new bp_gnu_ifunc_resolver_return at this point but
-+           bp_gnu_ifunc_resolver is being kept there as another
-+           bp_gnu_ifunc_resolver_return may be inserted in the meantime.  */
-+        this_action = BPSTAT_WHAT_SINGLE;
-+        break;
-+      case bp_gnu_ifunc_resolver_return:
-+        /* The whole bp_gnu_ifunc_resolver with its associated
-+           bp_gnu_ifunc_resolver_return related_breakpoint's has been
-+           resolved now, all these helper breakpoints are being removed and
-+           new final bp_breakpoint is being put at the target location.  */
-+        break;
-       default:
-         internal_error (__FILE__, __LINE__,
-                         _("bpstat_what: unhandled bptype %d"), (int) bptype);
-@@ -4350,6 +4452,23 @@ bpstat_what (bpstat bs)
-       handle_jit_event ();
-     }
++@item -P
++@cindex @code{-P}
++@itemx --python
++@cindex @code{--python}
++Change interpretation of command line so that the argument immediately
++following this switch is taken to be the name of a Python script file.
++This option stops option processing; subsequent options are passed to
++Python as @code{sys.argv}.  This option is only available if Python
++scripting support was enabled when @value{GDBN} was configured.
++
+ @c resolve the situation of these eventually
+ @item -tui
+ @cindex @code{--tui}
+@@ -22563,8 +22573,6 @@ containing @code{end}.  For example:
  
-+  for (bs = bs_head; bs != NULL; bs = bs->next)
-+    {
-+      if (bs->breakpoint_at == NULL)
-+      continue;
-+      if (bs->breakpoint_at->owner == NULL)
-+      continue;
-+      switch (bs->breakpoint_at->owner->type)
-+      {
-+      case bp_gnu_ifunc_resolver:
-+        gnu_ifunc_resolver_stop (bs->breakpoint_at->owner);
-+        break;
-+      case bp_gnu_ifunc_resolver_return:
-+        gnu_ifunc_resolver_return_stop (bs->breakpoint_at->owner);
-+        break;
-+      }
-+    }
+ @smallexample
+ (@value{GDBP}) python
+-Type python script
+-End with a line saying just "end".
+ >print 23
+ >end
+ 23
+@@ -22578,6 +22586,14 @@ controlled using @code{set python print-stack}: if @code{full}, then
+ full Python stack printing is enabled; if @code{none}, then Python stack
+ and message printing is disabled; if @code{message}, the default, only
+ the message component of the error is printed.
 +
-   return retval;
- }
++@kindex maint set python auto-load
++@item maint set python auto-load
++By default, @value{GDBN} will attempt to automatically load Python
++code when an object file is opened.  This can be controlled using
++@code{maint set python auto-load}: if @code{on}, the default, then
++Python auto-loading is enabled; if @code{off}, then Python
++auto-loading is disabled.
+ @end table
  
-@@ -4461,6 +4580,8 @@ print_one_breakpoint_location (struct breakpoint *b,
-     {bp_access_watchpoint, "acc watchpoint"},
-     {bp_longjmp, "longjmp"},
-     {bp_longjmp_resume, "longjmp resume"},
-+    {bp_exception, "exception"},
-+    {bp_exception_resume, "exception resume"},
-     {bp_step_resume, "step resume"},
-     {bp_watchpoint_scope, "watchpoint scope"},
-     {bp_call_dummy, "call dummy"},
-@@ -4470,11 +4591,14 @@ print_one_breakpoint_location (struct breakpoint *b,
-     {bp_overlay_event, "overlay events"},
-     {bp_longjmp_master, "longjmp master"},
-     {bp_std_terminate_master, "std::terminate master"},
-+    {bp_exception_master, "exception master"},
-     {bp_catchpoint, "catchpoint"},
-     {bp_tracepoint, "tracepoint"},
-     {bp_fast_tracepoint, "fast tracepoint"},
-     {bp_static_tracepoint, "static tracepoint"},
-     {bp_jit_event, "jit events"},
-+    {bp_gnu_ifunc_resolver, "gnu-ifunc resolver"},
-+    {bp_gnu_ifunc_resolver_return, "gnu-func resolver return"},
-   };
-   
-   static char bpenables[] = "nynny";
-@@ -4595,6 +4719,8 @@ print_one_breakpoint_location (struct breakpoint *b,
-       case bp_finish:
-       case bp_longjmp:
-       case bp_longjmp_resume:
-+      case bp_exception:
-+      case bp_exception_resume:
-       case bp_step_resume:
-       case bp_watchpoint_scope:
-       case bp_call_dummy:
-@@ -4604,10 +4730,13 @@ print_one_breakpoint_location (struct breakpoint *b,
-       case bp_overlay_event:
-       case bp_longjmp_master:
-       case bp_std_terminate_master:
-+      case bp_exception_master:
-       case bp_tracepoint:
-       case bp_fast_tracepoint:
-       case bp_static_tracepoint:
-       case bp_jit_event:
-+      case bp_gnu_ifunc_resolver:
-+      case bp_gnu_ifunc_resolver_return:
-       if (opts.addressprint)
-         {
-           annotate_field (4);
-@@ -4888,7 +5017,8 @@ user_settable_breakpoint (const struct breakpoint *b)
-         || b->type == bp_catchpoint
-         || b->type == bp_hardware_breakpoint
-         || is_tracepoint (b)
--        || is_watchpoint (b));
-+        || is_watchpoint (b)
-+        || b->type == bp_gnu_ifunc_resolver);
- }
-       
- /* Print information on user settable breakpoint (watchpoint, etc)
-@@ -5334,6 +5464,8 @@ allocate_bp_location (struct breakpoint *bpt)
-     case bp_finish:
-     case bp_longjmp:
-     case bp_longjmp_resume:
-+    case bp_exception:
-+    case bp_exception_resume:
-     case bp_step_resume:
-     case bp_watchpoint_scope:
-     case bp_call_dummy:
-@@ -5344,6 +5476,9 @@ allocate_bp_location (struct breakpoint *bpt)
-     case bp_jit_event:
-     case bp_longjmp_master:
-     case bp_std_terminate_master:
-+    case bp_gnu_ifunc_resolver:
-+    case bp_gnu_ifunc_resolver_return:
-+    case bp_exception_master:
-       loc->loc_type = bp_loc_software_breakpoint;
-       break;
-     case bp_hardware_breakpoint:
-@@ -5420,6 +5555,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
-   b->syscalls_to_be_caught = NULL;
-   b->ops = NULL;
-   b->condition_not_parsed = 0;
-+  b->related_breakpoint = b;
-   /* Add this breakpoint to the end of the chain
-      so that a list of breakpoints will come out in order
-@@ -5439,7 +5575,7 @@ set_raw_breakpoint_without_location (struct gdbarch *gdbarch,
- /* Initialize loc->function_name.  */
- static void
--set_breakpoint_location_function (struct bp_location *loc)
-+set_breakpoint_location_function (struct bp_location *loc, int explicit_loc)
- {
-   gdb_assert (loc->owner != NULL);
+ It is also possible to execute a Python script from the @value{GDBN}
+@@ -22599,6 +22615,14 @@ and thus is always available.
+ @cindex python api
+ @cindex programming in python
  
-@@ -5447,8 +5583,29 @@ set_breakpoint_location_function (struct bp_location *loc)
-       || loc->owner->type == bp_hardware_breakpoint
-       || is_tracepoint (loc->owner))
-     {
--      find_pc_partial_function (loc->address, &(loc->function_name), 
--                              NULL, NULL);
-+      if (find_pc_partial_function (loc->address, &(loc->function_name), NULL,
-+                                  NULL) == FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
-+        && !explicit_loc)
-+      {
-+        struct breakpoint *b = loc->owner;
-+
-+        gdb_assert (loc->pspace == current_program_space);
-+        if (resolve_gnu_ifunc (loc->function_name, &loc->requested_address))
-+          {
-+            /* Recalculate ADDRESS based on new REQUESTED_ADDRESS.  */
-+            loc->address = adjust_breakpoint_address (loc->gdbarch,
-+                                                      loc->requested_address,
-+                                                      b->type);
-+          }
-+        else if (b->type == bp_breakpoint && b->loc == loc
-+                 && loc->next == NULL && b->related_breakpoint == b)
-+          {
-+            /* Create only the whole new breakpoint of this type but do not
-+               mess more complicated breakpoints with multiple locations.  */
-+            b->type = bp_gnu_ifunc_resolver;
-+          }
-+      }
-+
-       if (loc->function_name)
-       loc->function_name = xstrdup (loc->function_name);
-     }
-@@ -5521,7 +5678,8 @@ set_raw_breakpoint (struct gdbarch *gdbarch,
-   b->loc->section = sal.section;
-   b->line_number = sal.line;
--  set_breakpoint_location_function (b->loc);
-+  set_breakpoint_location_function (b->loc,
-+                                  sal.explicit_pc || sal.explicit_line);
-   breakpoints_changed ();
-@@ -5548,8 +5706,7 @@ make_breakpoint_permanent (struct breakpoint *b)
- }
- /* Call this routine when stepping and nexting to enable a breakpoint
--   if we do a longjmp() in THREAD.  When we hit that breakpoint, call
--   set_longjmp_resume_breakpoint() to figure out where we are going. */
-+   if we do a longjmp() or 'throw' in THREAD.  */
- void
- set_longjmp_breakpoint (int thread)
-@@ -5562,11 +5719,12 @@ set_longjmp_breakpoint (int thread)
-      clones of those and enable them for the requested thread.  */
-   ALL_BREAKPOINTS_SAFE (b, temp)
-     if (b->pspace == current_program_space
--      && b->type == bp_longjmp_master)
-+      && (b->type == bp_longjmp_master
-+          || b->type == bp_exception_master))
-       {
-       struct breakpoint *clone = clone_momentary_breakpoint (b);
--      clone->type = bp_longjmp;
-+      clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception;
-       clone->thread = thread;
-       }
- }
-@@ -5578,7 +5736,7 @@ delete_longjmp_breakpoint (int thread)
-   struct breakpoint *b, *temp;
-   ALL_BREAKPOINTS_SAFE (b, temp)
--    if (b->type == bp_longjmp)
-+    if (b->type == bp_longjmp || b->type == bp_exception)
-       {
-       if (b->thread == thread)
-         delete_breakpoint (b);
-@@ -6595,7 +6753,7 @@ clone_momentary_breakpoint (struct breakpoint *orig)
-   copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type);
-   copy->loc = allocate_bp_location (copy);
--  set_breakpoint_location_function (copy->loc);
-+  set_breakpoint_location_function (copy->loc, 1);
-   copy->loc->gdbarch = orig->loc->gdbarch;
-   copy->loc->requested_address = orig->loc->requested_address;
-@@ -6694,6 +6852,7 @@ mention (struct breakpoint *b)
-       do_cleanups (ui_out_chain);
-       break;
-       case bp_breakpoint:
-+      case bp_gnu_ifunc_resolver:
-       if (ui_out_is_mi_like_p (uiout))
-         {
-           say_where = 0;
-@@ -6704,6 +6863,8 @@ mention (struct breakpoint *b)
-       else
-         printf_filtered (_("Breakpoint"));
-       printf_filtered (_(" %d"), b->number);
-+      if (b->type == bp_gnu_ifunc_resolver)
-+        printf_filtered (_(" at gnu-indirect-function resolver"));
-       say_where = 1;
-       break;
-       case bp_hardware_breakpoint:
-@@ -6750,6 +6911,8 @@ mention (struct breakpoint *b)
-       case bp_finish:
-       case bp_longjmp:
-       case bp_longjmp_resume:
-+      case bp_exception:
-+      case bp_exception_resume:
-       case bp_step_resume:
-       case bp_call_dummy:
-       case bp_std_terminate:
-@@ -6760,6 +6923,8 @@ mention (struct breakpoint *b)
-       case bp_jit_event:
-       case bp_longjmp_master:
-       case bp_std_terminate_master:
-+      case bp_gnu_ifunc_resolver_return:
-+      case bp_exception_master:
-       break;
-       }
-@@ -6820,7 +6985,8 @@ add_location_to_breakpoint (struct breakpoint *b,
-   gdb_assert (loc->pspace != NULL);
-   loc->section = sal->section;
--  set_breakpoint_location_function (loc);
-+  set_breakpoint_location_function (loc,
-+                                  sal->explicit_pc || sal->explicit_line);
-   return loc;
- }
\f
-@@ -8346,6 +8512,7 @@ struct until_break_command_continuation_args
- {
-   struct breakpoint *breakpoint;
-   struct breakpoint *breakpoint2;
-+  int thread_num;
- };
- /* This function is called by fetch_inferior_event via the
-@@ -8360,6 +8527,7 @@ until_break_command_continuation (void *arg)
-   delete_breakpoint (a->breakpoint);
-   if (a->breakpoint2)
-     delete_breakpoint (a->breakpoint2);
-+  delete_longjmp_breakpoint (a->thread_num);
- }
- void
-@@ -8371,6 +8539,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
-   struct breakpoint *breakpoint;
-   struct breakpoint *breakpoint2 = NULL;
-   struct cleanup *old_chain;
-+  int thread;
-+  struct thread_info *tp;
-   clear_proceed_status ();
-@@ -8409,6 +8579,9 @@ until_break_command (char *arg, int from_tty, int anywhere)
-   old_chain = make_cleanup_delete_breakpoint (breakpoint);
-+  tp = inferior_thread ();
-+  thread = tp->num;
-+
-   /* Keep within the current frame, or in frames called by the current
-      one.  */
-@@ -8421,6 +8594,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
-                                             frame_unwind_caller_id (frame),
-                                             bp_until);
-       make_cleanup_delete_breakpoint (breakpoint2);
-+
-+      set_longjmp_breakpoint (thread);
-+      tp->initiating_frame = frame_unwind_caller_id (frame);
-+      make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
-     }
-   proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
-@@ -8437,6 +8614,7 @@ until_break_command (char *arg, int from_tty, int anywhere)
-       args->breakpoint = breakpoint;
-       args->breakpoint2 = breakpoint2;
-+      args->thread_num = thread;
-       discard_cleanups (old_chain);
-       add_continuation (inferior_thread (),
-@@ -9564,12 +9742,22 @@ delete_breakpoint (struct breakpoint *bpt)
-   /* At least avoid this stale reference until the reference counting of
-      breakpoints gets resolved.  */
--  if (bpt->related_breakpoint != NULL)
-+  if (bpt->related_breakpoint != bpt)
-     {
--      gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt);
--      bpt->related_breakpoint->disposition = disp_del_at_next_stop;
--      bpt->related_breakpoint->related_breakpoint = NULL;
--      bpt->related_breakpoint = NULL;
-+      if (bpt->type == bp_watchpoint_scope)
-+      watchpoint_del_at_next_stop (bpt->related_breakpoint);
-+      else if (bpt->related_breakpoint->type == bp_watchpoint_scope)
-+      watchpoint_del_at_next_stop (bpt);
-+      else
-+      {
-+        struct breakpoint *related;
-+
-+        /* Unlink bpt from the bpt->related_breakpoint ring.  */
-+        for (related = bpt; related->related_breakpoint != bpt;
-+             related = related->related_breakpoint);
-+        related->related_breakpoint = bpt->related_breakpoint;
-+        bpt->related_breakpoint = bpt;
-+      }
-     }
-   observer_notify_breakpoint_deleted (bpt->number);
-@@ -9658,6 +9846,7 @@ delete_command (char *arg, int from_tty)
-           && b->type != bp_overlay_event
-           && b->type != bp_longjmp_master
-           && b->type != bp_std_terminate_master
-+          && b->type != bp_exception_master
-           && b->number >= 0)
-         {
-           breaks_to_delete = 1;
-@@ -9679,6 +9868,7 @@ delete_command (char *arg, int from_tty)
-               && b->type != bp_overlay_event
-               && b->type != bp_longjmp_master
-               && b->type != bp_std_terminate_master
-+              && b->type != bp_exception_master
-               && b->number >= 0)
-             delete_breakpoint (b);
-         }
-@@ -9887,6 +10077,9 @@ update_breakpoint_locations (struct breakpoint *b,
-     return;
-   b->loc = NULL;
-+  xfree (b->source_file);
-+  b->source_file = NULL;
-+  b->line_number = 0;
-   for (i = 0; i < sals.nelts; ++i)
-     {
-@@ -9913,11 +10106,7 @@ update_breakpoint_locations (struct breakpoint *b,
-           }
-       }
--      if (b->source_file != NULL)
--      xfree (b->source_file);
--      if (sals.sals[i].symtab == NULL)
--      b->source_file = NULL;
--      else
-+      if (sals.sals[i].symtab != NULL && b->source_file == NULL)
-       b->source_file = xstrdup (sals.sals[i].symtab->filename);
-       if (b->line_number == 0)
-@@ -9999,6 +10188,7 @@ breakpoint_re_set_one (void *bint)
-     case bp_tracepoint:
-     case bp_fast_tracepoint:
-     case bp_static_tracepoint:
-+    case bp_gnu_ifunc_resolver:
-       /* Do not attempt to re-set breakpoints disabled during startup.  */
-       if (b->enable_state == bp_startup_disabled)
-       return 0;
-@@ -10139,6 +10329,7 @@ breakpoint_re_set_one (void *bint)
-     case bp_overlay_event:
-     case bp_longjmp_master:
-     case bp_std_terminate_master:
-+    case bp_exception_master:
-       delete_breakpoint (b);
-       break;
-@@ -10162,7 +10353,10 @@ breakpoint_re_set_one (void *bint)
-     case bp_step_resume:
-     case bp_longjmp:
-     case bp_longjmp_resume:
-+    case bp_exception:
-+    case bp_exception_resume:
-     case bp_jit_event:
-+    case bp_gnu_ifunc_resolver_return:
-       break;
-     }
-@@ -10205,6 +10399,7 @@ breakpoint_re_set (void)
-   create_longjmp_master_breakpoint ("siglongjmp");
-   create_longjmp_master_breakpoint ("_siglongjmp");
-   create_std_terminate_master_breakpoint ("std::terminate()");
-+  create_exception_master_breakpoint ();
- }
\f
- /* Reset the thread number of this breakpoint:
-@@ -10334,11 +10529,20 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
-         ALL_BREAKPOINTS_SAFE (b, tmp)
-           if (b->number == num)
-             {
--              struct breakpoint *related_breakpoint = b->related_breakpoint;
-+              struct breakpoint *related_breakpoint;
-+
-               match = 1;
--              function (b, data);
--              if (related_breakpoint)
--                function (related_breakpoint, data);
-+              related_breakpoint = b;
-+              do
-+                {
-+                  struct breakpoint *next_related_b;
-+
-+                  /* FUNCTION can be also delete_breakpoint.  */
-+                  next_related_b = related_breakpoint->related_breakpoint;
-+                  function (related_breakpoint, data);
-+                  related_breakpoint = next_related_b;
-+                }
-+              while (related_breakpoint != b);
-               break;
-             }
-         if (match == 0)
-@@ -11428,6 +11632,22 @@ all_tracepoints ()
-   return tp_vec;
- }
-+/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
-+
-+static void
-+breakpoint_types_mark_used (void)
-+{
-+  struct breakpoint *b;
-+
-+  ALL_BREAKPOINTS (b)
-+    {
-+      if (b->exp)
-+      exp_types_mark_used (b->exp);
-+      if (b->val)
-+      type_mark_used (value_type (b->val));
-+    }
-+}
-+
\f
- /* This help string is used for the break, hbreak, tbreak and thbreak commands.
-    It is defined as a macro to prevent duplication.
-@@ -11497,6 +11717,107 @@ save_command (char *arg, int from_tty)
-   help_list (save_cmdlist, "save ", -1, gdb_stdout);
- }
-+static void
-+gnu_ifunc_resolver_stop (struct breakpoint *b)
-+{
-+  struct breakpoint *b_return;
-+  struct frame_info *prev_frame = get_prev_frame (get_current_frame ());
-+  struct frame_id prev_frame_id = get_stack_frame_id (prev_frame);
-+  CORE_ADDR prev_pc = get_frame_pc (prev_frame);
-+  int thread_id = pid_to_thread_id (inferior_ptid);
-+
-+  gdb_assert (b->type == bp_gnu_ifunc_resolver);
-+
-+  for (b_return = b->related_breakpoint; b_return != b;
-+       b_return = b_return->related_breakpoint)
-+    {
-+      gdb_assert (b_return->type == bp_gnu_ifunc_resolver_return);
-+      gdb_assert (b_return->loc != NULL && b_return->loc->next == NULL);
-+      gdb_assert (frame_id_p (b_return->frame_id));
-+
-+      if (b_return->thread == thread_id
-+        && b_return->loc->requested_address == prev_pc
-+        && frame_id_eq (b_return->frame_id, prev_frame_id))
-+      break;
-+    }
-+
-+  if (b_return == b)
-+    {
-+      struct symtab_and_line sal;
-+
-+      /* No need to call find_pc_line for symbols resolving as this is only
-+       a helper breakpointer never shown to the user.  */
-+
-+      init_sal (&sal);
-+      sal.pspace = current_inferior ()->pspace;
-+      sal.pc = prev_pc;
-+      sal.section = find_pc_overlay (sal.pc);
-+      sal.explicit_pc = 1;
-+      b_return = set_momentary_breakpoint (get_frame_arch (prev_frame), sal,
-+                                         prev_frame_id,
-+                                         bp_gnu_ifunc_resolver_return);
-+
-+      /* Add new b_return to the ring list b->related_breakpoint.  */
-+      gdb_assert (b_return->related_breakpoint == b_return);
-+      b_return->related_breakpoint = b->related_breakpoint;
-+      b->related_breakpoint = b_return;
-+    }
-+}
-+
-+static void
-+gnu_ifunc_resolver_return_stop (struct breakpoint *b)
-+{
-+  struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
-+  struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
-+  struct type *value_type = TYPE_TARGET_TYPE (func_func_type);
-+  struct regcache *regcache = get_thread_regcache (inferior_ptid);
-+  struct value *value;
-+  CORE_ADDR resolved_address, resolved_pc;
-+  struct symtab_and_line sal;
-+  struct symtabs_and_lines sals;
-+
-+  gdb_assert (b->type == bp_gnu_ifunc_resolver_return);
-+
-+  value = allocate_value (value_type);
-+  gdbarch_return_value (gdbarch, func_func_type, value_type, regcache,
-+                      value_contents_raw (value), NULL);
-+  resolved_address = value_as_address (value);
-+  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
-+                                                  resolved_address,
-+                                                  &current_target);
-+
-+  while (b->related_breakpoint != b)
-+    {
-+      struct breakpoint *b_next = b->related_breakpoint;
-+
-+      switch (b->type)
-+      {
-+      case bp_gnu_ifunc_resolver:
-+        break;
-+      case bp_gnu_ifunc_resolver_return:
-+        delete_breakpoint (b);
-+        break;
-+      default:
-+        internal_error (__FILE__, __LINE__,
-+                        _("handle_inferior_event: Invalid "
-+                          "gnu-indirect-function breakpoint type %d"),
-+                        (int) b->type);
-+      }
-+      b = b_next;
-+    }
-+  gdb_assert (b->type == bp_gnu_ifunc_resolver);
-+
-+  gdb_assert (current_program_space == b->pspace);
-+  gnu_ifunc_record_cache (gdbarch, b->addr_string, resolved_pc);
-+
-+  sal = find_pc_line (resolved_pc, 0);
-+  sals.nelts = 1;
-+  sals.sals = &sal;
-+
-+  b->type = bp_breakpoint;
-+  update_breakpoint_locations (b, sals);
-+}
-+
- void
- _initialize_breakpoint (void)
- {
-@@ -12022,4 +12343,5 @@ inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
-   automatic_hardware_breakpoints = 1;
-   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
-+  observer_attach_mark_used (breakpoint_types_mark_used);
- }
-diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
-index 6f5d050..d0c3cc1 100644
---- a/gdb/breakpoint.h
-+++ b/gdb/breakpoint.h
-@@ -56,6 +56,13 @@ enum bptype
-     bp_longjmp,                       /* secret breakpoint to find longjmp() */
-     bp_longjmp_resume,                /* secret breakpoint to escape longjmp() */
-+    /* An internal breakpoint that is installed on the unwinder's
-+       debug hook.  */
-+    bp_exception,
-+    /* An internal breakpoint that is set at the point where an
-+       exception will land.  */
-+    bp_exception_resume,
-+
-     /* Used by wait_for_inferior for stepping over subroutine calls, for
-        stepping over signal handlers, and for skipping prologues.  */
-     bp_step_resume,
-@@ -125,6 +132,9 @@ enum bptype
-     /* Master copies of std::terminate breakpoints.  */
-     bp_std_terminate_master,
-+    /* Like bp_longjmp_master, but for exceptions.  */
-+    bp_exception_master,
-+
-     bp_catchpoint,
-     bp_tracepoint,
-@@ -133,6 +143,9 @@ enum bptype
-     /* Event for JIT compiled code generation or deletion.  */
-     bp_jit_event,
-+
-+    bp_gnu_ifunc_resolver,
-+    bp_gnu_ifunc_resolver_return,
-   };
- /* States of enablement of breakpoint. */
-@@ -653,6 +666,10 @@ struct bpstat_what
-        continuing from a call dummy without popping the frame is not a
-        useful one).  */
-     enum stop_stack_kind call_dummy;
-+
-+    /* Used for BPSTAT_WHAT_SET_LONGJMP_RESUME.  True if we are
-+       handling a longjmp, false if we are handling an exception.  */
-+    int is_longjmp;
-   };
- /* The possible return values for print_bpstat, print_it_normal,
-diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
-index 926ae2f..a59b965 100644
---- a/gdb/c-typeprint.c
-+++ b/gdb/c-typeprint.c
-@@ -585,7 +585,13 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
-       fprintf_filtered (stream, ")");
-       fprintf_filtered (stream, "[");
--      if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-+      if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind
-+        != RANGE_BOUND_KIND_CONSTANT)
-+      {
-+        /* No _() - printed sources should not be locale dependent.  */
-+        fprintf_filtered (stream, "variable");
-+      }
-+      else if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-       && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
-       fprintf_filtered (stream, "%d",
-                         (TYPE_LENGTH (type)
-diff --git a/gdb/config.in b/gdb/config.in
-index 1fc457d..f4c846a 100644
---- a/gdb/config.in
-+++ b/gdb/config.in
-@@ -50,11 +50,10 @@
-    language is requested. */
- #undef ENABLE_NLS
--/* look for global separate data files in this path [DATADIR/gdb] */
-+/* Global directory for GDB data files. */
- #undef GDB_DATADIR
--/* Define if the gdb-datadir directory should be relocated when GDB is moved.
--   */
-+/* Define if GDB datadir should be relocated when GDB is moved. */
- #undef GDB_DATADIR_RELOCATABLE
- /* Define to be a string naming the default host character set. */
-@@ -769,6 +768,9 @@
-    'ptrdiff_t'. */
- #undef PTRDIFF_T_SUFFIX
-+/* Define to install path for Python sources */
-+#undef PYTHONDIR
-+
- /* Define if the python directory should be relocated when GDB is moved. */
- #undef PYTHON_PATH_RELOCATABLE
-diff --git a/gdb/configure b/gdb/configure
-index 041ffc1..8243abb 100755
---- a/gdb/configure
-+++ b/gdb/configure
-@@ -679,6 +679,8 @@ REPORT_BUGS_TO
- PKGVERSION
- TARGET_OBS
- subdirs
-+pythondir
-+GDB_DATADIR_PATH
- GDB_DATADIR
- DEBUGDIR
- am__fastdepCC_FALSE
-@@ -945,6 +947,7 @@ enable_dependency_tracking
- with_separate_debug_dir
- with_gdb_datadir
- with_relocated_sources
-+with_pythondir
- enable_targets
- enable_64_bit_bfd
- enable_gdbcli
-@@ -1646,6 +1649,10 @@ Optional Packages:
-                           [DATADIR/gdb]
-   --with-relocated-sources=PATH
-                           automatically relocate this path for source files
-+  --with-gdb-datadir      look for global separate data files in this path
-+                          [DATADIR/gdb]
-+  --with-pythondir        install Python data files in this path
-+                          [DATADIR/gdb/python]
-   --with-libunwind        use libunwind frame unwinding support
-   --with-curses           use the curses library instead of the termcap
-                           library
-@@ -7878,6 +7885,73 @@ _ACEOF
- fi
-+# GDB's datadir relocation
-+
-+gdbdatadir=${datadir}/gdb
-+
-+
-+# Check whether --with-gdb-datadir was given.
-+if test "${with_gdb_datadir+set}" = set; then :
-+  withval=$with_gdb_datadir; gdbdatadir="${withval}"
-+fi
-+
-+
-+
-+  test "x$prefix" = xNONE && prefix="$ac_default_prefix"
-+  test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-+  ac_define_dir=`eval echo $gdbdatadir`
-+  ac_define_dir=`eval echo $ac_define_dir`
-+
-+cat >>confdefs.h <<_ACEOF
-+#define GDB_DATADIR "$ac_define_dir"
-+_ACEOF
-+
-+
-+
-+if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
-+  if test "x$prefix" = xNONE; then
-+    test_prefix=/usr/local
-+  else
-+    test_prefix=$prefix
-+  fi
-+else
-+  test_prefix=$exec_prefix
-+fi
-+
-+case ${gdbdatadir} in
-+  "${test_prefix}"|"${test_prefix}/"*|\
-+  '${exec_prefix}'|'${exec_prefix}/'*)
-+
-+$as_echo "#define GDB_DATADIR_RELOCATABLE 1" >>confdefs.h
-+
-+  ;;
-+esac
-+GDB_DATADIR_PATH=${gdbdatadir}
-+
-+
-+
-+# Check whether --with-pythondir was given.
-+if test "${with_pythondir+set}" = set; then :
-+  withval=$with_pythondir; pythondir="${withval}"
-+else
-+  pythondir=no
-+fi
-+
-+
-+# If the user passed in a path, define it.  Otherwise, compute it at
-+# runtime based on the possibly-relocatable datadir.
-+if test "$pythondir" = "no"; then
-+  pythondir='$(GDB_DATADIR_PATH)/python'
-+else
-+
-+cat >>confdefs.h <<_ACEOF
-+#define PYTHONDIR "$pythondir"
-+_ACEOF
-+
-+fi
-+
-+
-+
- subdirs="$subdirs doc testsuite"
-@@ -10919,6 +10993,7 @@ $as_echo "#define HAVE_PYTHON 1" >>confdefs.h
-   CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
-   CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
-   CONFIG_INSTALL="$CONFIG_INSTALL install-python"
-+  CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
-   ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
-   # Flags needed to compile Python code (taken from python-config --cflags).
-diff --git a/gdb/configure.ac b/gdb/configure.ac
-index b69c3b6..4e89558 100644
---- a/gdb/configure.ac
-+++ b/gdb/configure.ac
-@@ -108,6 +108,51 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat
-               [Relocated directory for source files. ])
- ])
-+# GDB's datadir relocation
-+
-+gdbdatadir=${datadir}/gdb
-+
-+AC_ARG_WITH([gdb-datadir],
-+  [AS_HELP_STRING([--with-gdb-datadir],
-+                  [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
-+
-+AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
-+              [Global directory for GDB data files. ])
-+
-+if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
-+  if test "x$prefix" = xNONE; then
-+    test_prefix=/usr/local
-+  else
-+    test_prefix=$prefix
-+  fi
-+else
-+  test_prefix=$exec_prefix
-+fi
-+
-+case ${gdbdatadir} in
-+  "${test_prefix}"|"${test_prefix}/"*|\
-+  '${exec_prefix}'|'${exec_prefix}/'*)
-+    AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
-+  ;;
-+esac
-+GDB_DATADIR_PATH=${gdbdatadir}
-+AC_SUBST(GDB_DATADIR_PATH)
-+
-+AC_ARG_WITH([pythondir],
-+  [AS_HELP_STRING([--with-pythondir],
-+                  [install Python data files in this path [DATADIR/gdb/python]])], [pythondir="${withval}"], [pythondir=no])
-+
-+# If the user passed in a path, define it.  Otherwise, compute it at
-+# runtime based on the possibly-relocatable datadir.
-+if test "$pythondir" = "no"; then
-+  pythondir='$(GDB_DATADIR_PATH)/python'
-+else
-+  AC_DEFINE_UNQUOTED(PYTHONDIR, "$pythondir",
-+      [Define to install path for Python sources])
-+fi
-+AC_SUBST(pythondir)
-+
-+
- AC_CONFIG_SUBDIRS(doc testsuite)
- # Check whether to support alternative target configurations
-@@ -833,6 +878,7 @@ if test "${have_libpython}" != no; then
-   CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)"
-   CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)"
-   CONFIG_INSTALL="$CONFIG_INSTALL install-python"
-+  CONFIG_UNINSTALL="$CONFIG_UNINSTALL uninstall-python"
-   ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)"
-   # Flags needed to compile Python code (taken from python-config --cflags).
-diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
-index 65d4899..96767b0 100644
---- a/gdb/doc/gdb.texinfo
-+++ b/gdb/doc/gdb.texinfo
-@@ -1162,6 +1162,16 @@ for remote debugging.
- Run using @var{device} for your program's standard input and output.
- @c FIXME: kingdon thinks there is more to -tty.  Investigate.
-+@item -P
-+@cindex @code{-P}
-+@itemx --python
-+@cindex @code{--python}
-+Change interpretation of command line so that the argument immediately
-+following this switch is taken to be the name of a Python script file.
-+This option stops option processing; subsequent options are passed to
-+Python as @code{sys.argv}.  This option is only available if Python
-+scripting support was enabled when @value{GDBN} was configured.
-+
- @c resolve the situation of these eventually
- @item -tui
- @cindex @code{--tui}
-@@ -14308,6 +14318,7 @@ program.  To debug a core dump of a previous run, you must also tell
- @menu
- * Files::                       Commands to specify files
- * Separate Debug Files::        Debugging information in separate files
-+* Index Files::                 Index files speed up GDB
- * Symbol Errors::               Errors reading symbol files
- * Data Files::                  GDB data files
- @end menu
-@@ -15197,6 +15208,46 @@ gnu_debuglink_crc32 (unsigned long crc,
- This computation does not apply to the ``build ID'' method.
-+@node Index Files
-+@section Index Files Speed Up @value{GDBN}
-+@cindex index files
-+@cindex @samp{.gdb_index} section
-+
-+When @value{GDBN} finds a symbol file, it scans the symbols in the
-+file in order to construct an internal symbol table.  This lets most
-+@value{GDBN} operations work quickly---at the cost of a delay early
-+on.  For large programs, this delay can be quite lengthy, so
-+@value{GDBN} provides a way to build an index, which speeds up
-+startup.
-+
-+The index is stored as a section in the symbol file.  @value{GDBN} can
-+write the index to a file, then you can put it into the symbol file
-+using @command{objcopy}.
-+
-+To create an index file, use the @code{save gdb-index} command:
-+
-+@table @code
-+@item save gdb-index @var{directory}
-+@kindex save gdb-index
-+Create an index file for each symbol file currently known by
-+@value{GDBN}.  Each file is named after its corresponding symbol file,
-+with @samp{.gdb-index} appended, and is written into the given
-+@var{directory}.
-+@end table
-+
-+Once you have created an index file you can merge it into your symbol
-+file, here named @file{symfile}, using @command{objcopy}:
-+
-+@smallexample
-+$ objcopy --add-section .gdb_index=symfile.gdb-index \
-+    --set-section-flags .gdb_index=readonly symfile symfile
-+@end smallexample
-+
-+There are currently some limitation on indices.  They only work when
-+for DWARF debugging information, not stabs.  And, they do not
-+currently work for programs using Ada.
-+
-+
- @node Symbol Errors
- @section Errors Reading Symbol Files
-@@ -20349,8 +20400,6 @@ containing @code{end}.  For example:
- @smallexample
- (@value{GDBP}) python
--Type python script
--End with a line saying just "end".
- >print 23
- >end
- 23
-@@ -20363,6 +20412,14 @@ in a Python script.  This can be controlled using @code{maint set
- python print-stack}: if @code{on}, the default, then Python stack
- printing is enabled; if @code{off}, then Python stack printing is
- disabled.
-+
-+@kindex maint set python auto-load
-+@item maint set python auto-load
-+By default, @value{GDBN} will attempt to automatically load Python
-+code when an object file is opened.  This can be controlled using
-+@code{maint set python auto-load}: if @code{on}, the default, then
-+Python auto-loading is enabled; if @code{off}, then Python
-+auto-loading is disabled.
- @end table
- It is also possible to execute a Python script from the @value{GDBN}
-@@ -20384,6 +20441,14 @@ and thus is always available.
- @cindex python api
- @cindex programming in python
-+You can get quick online help for @value{GDBN}'s Python API by issuing
-+the command @w{@kbd{python help (gdb)}}.
++You can get quick online help for @value{GDBN}'s Python API by issuing
++the command @w{@kbd{python help (gdb)}}.
 +
 +Functions and methods which have two or more optional arguments allow
 +them to be specified using keyword syntax.  This allows passing some
@@ -1641,60 +924,20 @@ index 65d4899..96767b0 100644
  @cindex python stdout
  @cindex python pagination
  At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
-@@ -20395,7 +20460,7 @@ situation, a Python @code{KeyboardInterrupt} exception is thrown.
- @menu
- * Basic Python::                Basic Python Functions.
- * Exception Handling::
--* Values From Inferior::
-+* Values From Inferior::      Python representation of values.
- * Types In Python::             Python representation of types.
- * Pretty Printing API::         Pretty-printing values.
- * Selecting Pretty-Printers::   How GDB chooses a pretty-printer.
-@@ -20456,6 +20521,12 @@ Return a sequence holding all of @value{GDBN}'s breakpoints.
- @xref{Breakpoints In Python}, for more information.
- @end defun
-+@findex gdb.breakpoints
-+@defun breakpoints
-+Return a sequence holding all of @value{GDBN}'s breakpoints.
-+@xref{Breakpoints In Python}, for more information.
-+@end defun
-+
- @findex gdb.parameter
- @defun parameter parameter
- Return the value of a @value{GDBN} parameter.  @var{parameter} is a
-@@ -20472,6 +20543,7 @@ a Python value of the appropriate type, and returned.
- @defun history number
- Return a value from @value{GDBN}'s value history (@pxref{Value
- History}).  @var{number} indicates which history element to return.
-+
- If @var{number} is negative, then @value{GDBN} will take its absolute value
- and count backward from the last element (i.e., the most recent element) to
- find the value to return.  If @var{number} is zero, then @value{GDBN} will
-@@ -20496,6 +20568,21 @@ compute values, for example, it is the only way to get the value of a
- convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
- @end defun
-+@findex gdb.post_event
-+@defun post_event event
-+Put @var{event}, a callable object taking no arguments, into
-+@value{GDBN}'s internal event queue.  This callable will be invoked at
-+some later point, during @value{GDBN}'s event processing.  Events
-+posted using @code{post_event} will be run in the order in which they
-+were posted; however, there is no way to know when they will be
-+processed relative to other events inside @value{GDBN}.
-+
-+@value{GDBN} is not thread-safe.  If your Python program uses multiple
-+threads, you must be careful to only call @value{GDBN}-specific
-+functions in the main @value{GDBN} thread.  @code{post_event} ensures
-+this.
-+@end defun
-+
- @findex gdb.write
- @defun write string
- Print a string to @value{GDBN}'s paginated standard output stream.
+@@ -34536,6 +34560,11 @@ Shared library events.
+ @end table
++@kindex maint info bfds
++@item maint info bfds
++This prints information about each @code{bfd} object that is known to
++@value{GDBN}.  @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
++
+ @kindex set displaced-stepping
+ @kindex show displaced-stepping
+ @cindex displaced stepping support
 diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
-index 54187dd..320b501 100644
+index 5e00f1f..c5c432b 100644
 --- a/gdb/doc/gdbint.texinfo
 +++ b/gdb/doc/gdbint.texinfo
 @@ -2102,6 +2102,18 @@ time, and so we attempt to handle symbols incrementally.  For instance,
@@ -1823,78 +1066,106 @@ index 54187dd..320b501 100644
  
  @node Language Support
 diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
-index e19b8ed..343e160 100644
+index 6827ed8..c63b901 100644
 --- a/gdb/doc/observer.texi
 +++ b/gdb/doc/observer.texi
-@@ -223,6 +223,11 @@ Bytes from @var{data} to @var{data} + @var{len} have been written
to the current inferior at @var{addr}.
+@@ -230,6 +230,11 @@ the current top-level prompt.
Variable gdb_datadir has been set.  The value may not necessarily change.
  @end deftypefun
  
-+@deftypefun void mark_used (void)
-+Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
-+collector pass.  Currently only @code{type_mark_used} marker is supported.
-+@end deftypefun
++@c @deftypefun void mark_used (void)
++@c Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
++@c collector pass.  Currently only @code{type_mark_used} marker is supported.
++@c @end deftypefun
 +
  @deftypefun void test_notification (int @var{somearg})
  This observer is used for internal testing.  Do not use.  
  See testsuite/gdb.gdb/observer.exp.
+diff --git a/gdb/dsrec.c b/gdb/dsrec.c
+index d2c99b2..f39d0ed 100644
+--- a/gdb/dsrec.c
++++ b/gdb/dsrec.c
+@@ -23,6 +23,7 @@
+ #include <time.h>
+ #include "gdb_assert.h"
+ #include "gdb_string.h"
++#include "gdb_bfd.h"
+ extern void report_transfer_performance (unsigned long, time_t, time_t);
+@@ -56,19 +57,22 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
+   int reclen;
+   time_t start_time, end_time;
+   unsigned long data_count = 0;
++  struct cleanup *cleanup;
+   srec = (char *) alloca (maxrecsize + 1);
+-  abfd = bfd_openr (file, 0);
++  abfd = gdb_bfd_openr (file, 0);
+   if (!abfd)
+     {
+       printf_filtered (_("Unable to open file %s\n"), file);
+       return;
+     }
++  cleanup = make_cleanup_bfd_unref (abfd);
+   if (bfd_check_format (abfd, bfd_object) == 0)
+     {
+       printf_filtered (_("File is not an object file\n"));
++      do_cleanups (cleanup);
+       return;
+     }
+@@ -170,6 +174,7 @@ load_srec (struct serial *desc, const char *file, bfd_vma load_offset,
+   serial_flush_input (desc);
+   report_transfer_performance (data_count, start_time, end_time);
++  do_cleanups (cleanup);
+ }
+ /*
 diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
-index b9ae108..2555908 100644
+index 214b371..d9b3751 100644
 --- a/gdb/dwarf2expr.c
 +++ b/gdb/dwarf2expr.c
-@@ -875,6 +875,13 @@ execute_stack_op (struct dwarf_expr_context *ctx,
-         ctx->dwarf_call (ctx, result);
-         goto no_push;
+@@ -1480,6 +1480,14 @@ execute_stack_op (struct dwarf_expr_context *ctx,
+         }
+         break;
  
 +      case DW_OP_push_object_address:
-+        if (ctx->get_object_address == NULL)
++        if (ctx->funcs->get_object_address == NULL)
 +          error (_("DWARF-2 expression error: DW_OP_push_object_address must "
 +                 "have a value to push."));
-+        result = (ctx->get_object_address) (ctx->baton);
++        result = (ctx->funcs->get_object_address) (ctx->baton);
++        result_val = value_from_ulongest (address_type, result);
 +        break;
 +
        default:
          error (_("Unhandled dwarf expression opcode 0x%x"), op);
        }
 diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
-index 61b8f00..d94c03c 100644
+index 19efbfd..0e0e498 100644
 --- a/gdb/dwarf2expr.h
 +++ b/gdb/dwarf2expr.h
-@@ -108,9 +108,15 @@ struct dwarf_expr_context
- #if 0
-   /* Not yet implemented.  */
-+  /* Return the location expression for the dwarf expression
-+     subroutine in the die at OFFSET in the current compilation unit.
-+     The result must be live until the current expression evaluation
-+     is complete.  */
-+  unsigned char *(*get_subr) (void *baton, off_t offset, size_t *length);
-+#endif
-+
+@@ -78,12 +78,8 @@ struct dwarf_expr_context_funcs
+      This can throw an exception if the index is out of range.  */
+   CORE_ADDR (*get_addr_index) (void *baton, unsigned int index);
+-#if 0
+-  /* Not yet implemented.  */
+-
    /* Return the `object address' for DW_OP_push_object_address.  */
    CORE_ADDR (*get_object_address) (void *baton);
 -#endif
+ };
  
-   /* The current depth of dwarf expression recursion, via DW_OP_call*,
-      DW_OP_fbreg, DW_OP_push_object_address, etc., and the maximum
+ /* The location of a value.  */
 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
-index f59bc40..7ff0ef9 100644
+index 38e4814..46a033d 100644
 --- a/gdb/dwarf2loc.c
 +++ b/gdb/dwarf2loc.c
-@@ -48,6 +48,12 @@ static void
- dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
-                        const gdb_byte **start, size_t *length);
-+static struct value *dwarf2_evaluate_loc_desc (struct type *type,
-+                                             struct frame_info *frame,
-+                                             const gdb_byte *data,
-+                                             unsigned short size,
-+                                           struct dwarf2_per_cu_data *per_cu);
-+
- /* A helper function for dealing with location lists.  Given a
-    symbol baton (BATON) and a pc value (PC), find the appropriate
-    location expression, set *LOCEXPR_LENGTH, and return a pointer
-@@ -127,6 +133,9 @@ struct dwarf_expr_baton
+@@ -293,6 +293,9 @@ struct dwarf_expr_baton
  {
    struct frame_info *frame;
    struct dwarf2_per_cu_data *per_cu;
@@ -1904,26 +1175,28 @@ index f59bc40..7ff0ef9 100644
  };
  
  /* Helper functions for dwarf2_evaluate_loc_desc.  */
-@@ -195,23 +204,33 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
-       symbaton = SYMBOL_LOCATION_BATON (framefunc);
-       *start = find_location_expression (symbaton, length, pc);
+@@ -352,16 +355,14 @@ static void
+ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
+                        const gdb_byte **start, size_t *length)
+ {
+-  if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
+-    *length = 0;
+-  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
++  if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
+     {
+       struct dwarf2_loclist_baton *symbaton;
+       symbaton = SYMBOL_LOCATION_BATON (framefunc);
+       *start = dwarf2_find_location_expression (symbaton, length, pc);
      }
 -  else
 +  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
      {
        struct dwarf2_locexpr_baton *symbaton;
  
-       symbaton = SYMBOL_LOCATION_BATON (framefunc);
--      if (symbaton != NULL)
--      {
--        *length = symbaton->size;
--        *start = symbaton->data;
--      }
--      else
--      *start = NULL;
-+      gdb_assert (symbaton != NULL);
-+      *start = symbaton->data;
-+      *length = symbaton->size;
+@@ -374,10 +375,23 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
+       else
+       *length = 0;
      }
 +  else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
 +    {
@@ -1931,8 +1204,7 @@ index f59bc40..7ff0ef9 100644
 +
 +      symbaton = SYMBOL_LOCATION_BATON (framefunc);
 +      gdb_assert (symbaton == NULL);
-+      *start = NULL;
-+      *length = 0;    /* unused */
++      *length = 0;
 +    }
 +  else
 +    internal_error (__FILE__, __LINE__,
@@ -1940,15 +1212,15 @@ index f59bc40..7ff0ef9 100644
 +                  SYMBOL_COMPUTED_OPS (framefunc),
 +                  SYMBOL_PRINT_NAME (framefunc));
  
-   if (*start == NULL)
+   if (*length == 0)
      error (_("Could not find the frame base for \"%s\"."),
 -         SYMBOL_NATURAL_NAME (framefunc));
 +         SYMBOL_PRINT_NAME (framefunc));
  }
  
  /* Helper function for dwarf2_evaluate_loc_desc.  Computes the CFA for
-@@ -263,6 +282,158 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
-   return per_cu_dwarf_call (ctx, die_offset, debaton->per_cu);
+@@ -445,6 +459,85 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset)
+                    ctx->funcs->get_frame_pc, ctx->baton);
  }
  
 +static CORE_ADDR
@@ -2001,44 +1273,105 @@ index f59bc40..7ff0ef9 100644
 +  object_address = address;
 +}
 +
++/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one
++   CORE_ADDR result stored to *ADDRP on the DWARF stack stack.  If the result
++   could not be found return zero and keep *ADDRP unchanged.  */
++
++int
++dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
++                        struct type *type, CORE_ADDR *addrp)
++{
++  struct frame_info *frame = get_selected_frame (NULL);
++  const gdb_byte *data;
++  size_t size;
++  struct value *val;
++
++  if (!dllbaton)
++    return 0;
++
++  data = dwarf2_find_location_expression (dllbaton, &size,
++                                        get_frame_address_in_block (frame));
++  if (data == NULL)
++    return 0;
++
++  val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu);
++  if (value_optimized_out (val))
++    return 0;
++
++  *addrp = value_as_address (val);
++  return 1;
++}
++
+ /* Callback function for dwarf2_evaluate_loc_desc.  */
+ static struct type *
+@@ -1139,10 +1232,12 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
+   saved_ctx.gdbarch = ctx->gdbarch;
+   saved_ctx.addr_size = ctx->addr_size;
++  saved_ctx.ref_addr_size = ctx->ref_addr_size;
+   saved_ctx.offset = ctx->offset;
+   saved_ctx.baton = ctx->baton;
+   ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (baton_local.per_cu));
+   ctx->addr_size = dwarf2_per_cu_addr_size (baton_local.per_cu);
++  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (baton_local.per_cu);
+   ctx->offset = dwarf2_per_cu_text_offset (baton_local.per_cu);
+   ctx->baton = &baton_local;
+@@ -1150,10 +1245,95 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
+   ctx->gdbarch = saved_ctx.gdbarch;
+   ctx->addr_size = saved_ctx.addr_size;
++  ctx->ref_addr_size = saved_ctx.ref_addr_size;
+   ctx->offset = saved_ctx.offset;
+   ctx->baton = saved_ctx.baton;
+ }
++static CORE_ADDR dwarf_expr_get_addr_index (void *baton, unsigned int index);
++
++/* Virtual method table for dwarf2_evaluate_loc_desc_full below.  */
++
++static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
++{
++  dwarf_expr_read_reg,
++  dwarf_expr_read_mem,
++  dwarf_expr_frame_base,
++  dwarf_expr_frame_cfa,
++  dwarf_expr_frame_pc,
++  dwarf_expr_tls_address,
++  dwarf_expr_dwarf_call,
++  dwarf_expr_get_base_type,
++  dwarf_expr_push_dwarf_reg_entry_value,
++  dwarf_expr_get_addr_index,
++  dwarf_expr_object_address
++};
++
 +/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
 +   by dwarf_expr_fetch (RETVAL, 0).  FRAME parameter can be NULL to call
 +   get_selected_frame to find it.  Returned dwarf_expr_context freeing is
 +   pushed on the cleanup chain.  */
 +
-+static struct dwarf_expr_context *
-+dwarf_expr_prep_ctx (struct frame_info *frame, const gdb_byte *data,
-+                   size_t size, struct dwarf2_per_cu_data *per_cu)
++static void
++dwarf_expr_prep_ctx (struct dwarf_expr_context *ctx, struct frame_info *frame,
++                   const gdb_byte *data, size_t size,
++                   struct dwarf2_per_cu_data *per_cu)
 +{
-+  struct dwarf_expr_context *ctx;
 +  struct dwarf_expr_baton baton;
 +  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
++  volatile struct gdb_exception ex;
 +
 +  baton.frame = frame;
 +  baton.per_cu = per_cu;
 +  baton.object_address = object_address;
 +
-+  ctx = new_dwarf_expr_context ();
-+  make_cleanup_free_dwarf_expr_context (ctx);
-+
 +  ctx->gdbarch = get_objfile_arch (objfile);
 +  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
++  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
 +  ctx->offset = dwarf2_per_cu_text_offset (per_cu);
 +  ctx->baton = &baton;
-+  ctx->read_reg = dwarf_expr_read_reg;
-+  ctx->read_mem = dwarf_expr_read_mem;
-+  ctx->get_frame_base = dwarf_expr_frame_base;
-+  ctx->get_frame_cfa = dwarf_expr_frame_cfa;
-+  ctx->get_tls_address = dwarf_expr_tls_address;
-+  ctx->dwarf_call = dwarf_expr_dwarf_call;
-+  ctx->get_object_address = dwarf_expr_object_address;
++  ctx->funcs = &dwarf_expr_ctx_funcs;
 +
 +  dwarf_expr_eval (ctx, data, size);
-+
-+  /* It was used only during dwarf_expr_eval.  */
-+  ctx->baton = NULL;
-+
-+  return ctx;
 +}
 +
 +/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
@@ -2049,14 +1382,18 @@ index f59bc40..7ff0ef9 100644
 +{
 +  struct dwarf_expr_context *ctx;
 +  CORE_ADDR retval;
-+  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
++  struct cleanup *back_to;
++
++  ctx = new_dwarf_expr_context ();
++  back_to = make_cleanup_free_dwarf_expr_context (ctx);
++
++  dwarf_expr_prep_ctx (ctx, get_selected_frame (NULL), dlbaton->data,
++                     dlbaton->size, dlbaton->per_cu);
 +
-+  ctx = dwarf_expr_prep_ctx (get_selected_frame (NULL), dlbaton->data,
-+                           dlbaton->size, dlbaton->per_cu);
 +  if (ctx->num_pieces > 0)
 +    error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
 +
-+  retval = dwarf_expr_fetch (ctx, 0);
++  retval = dwarf_expr_fetch_address (ctx, 0);
 +
 +  if (ctx->location == DWARF_VALUE_REGISTER)
 +    {
@@ -2074,90 +1411,90 @@ index f59bc40..7ff0ef9 100644
 +  return retval;
 +}
 +
-+/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one
-+   CORE_ADDR result stored to *ADDRP on the DWARF stack stack.  If the result
-+   could not be found return zero and keep *ADDRP unchanged.  */
-+
-+int
-+dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
-+                        struct type *type, CORE_ADDR *addrp)
-+{
-+  struct frame_info *frame = get_selected_frame (NULL);
-+  const gdb_byte *data;
-+  size_t size;
-+  struct value *val;
-+
-+  if (!dllbaton)
-+    return 0;
-+
-+  data = find_location_expression (dllbaton, &size,
-+                                 get_frame_address_in_block (frame));
-+  if (data == NULL)
-+    return 0;
-+
-+  val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu);
-+  if (value_optimized_out (val))
-+    return 0;
-+
-+  *addrp = value_as_address (val);
-+  return 1;
-+}
-+
- struct piece_closure
- {
-   /* Reference count.  */
-@@ -887,10 +1058,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
-                         struct dwarf2_per_cu_data *per_cu)
+ /* Callback function for dwarf2_evaluate_loc_desc.
+    Fetch the address indexed by DW_OP_GNU_addr_index.  */
+@@ -2088,22 +2268,6 @@ invalid_synthetic_pointer (void)
+          "referenced via synthetic pointer"));
+ }
+-/* Virtual method table for dwarf2_evaluate_loc_desc_full below.  */
+-
+-static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
+-{
+-  dwarf_expr_read_reg,
+-  dwarf_expr_read_mem,
+-  dwarf_expr_frame_base,
+-  dwarf_expr_frame_cfa,
+-  dwarf_expr_frame_pc,
+-  dwarf_expr_tls_address,
+-  dwarf_expr_dwarf_call,
+-  dwarf_expr_get_base_type,
+-  dwarf_expr_push_dwarf_reg_entry_value,
+-  dwarf_expr_get_addr_index
+-};
+-
+ /* Evaluate a location description, starting at DATA and with length
+    SIZE, to find the current location of variable of TYPE in the
+    context of FRAME.  BYTE_OFFSET is applied after the contents are
+@@ -2116,7 +2280,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
+                              LONGEST byte_offset)
  {
    struct value *retval;
 -  struct dwarf_expr_baton baton;
    struct dwarf_expr_context *ctx;
--  struct cleanup *old_chain;
--  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
-+  struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
+   struct cleanup *old_chain, *value_chain;
+   struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+@@ -2128,29 +2291,18 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
    if (size == 0)
-     {
-@@ -900,24 +1069,8 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
-       return retval;
-     }
+     return allocate_optimized_out_value (type);
  
 -  baton.frame = frame;
 -  baton.per_cu = per_cu;
-+  ctx = dwarf_expr_prep_ctx (frame, data, size, per_cu);
--  ctx = new_dwarf_expr_context ();
--  old_chain = make_cleanup_free_dwarf_expr_context (ctx);
 -
+   ctx = new_dwarf_expr_context ();
+   old_chain = make_cleanup_free_dwarf_expr_context (ctx);
+   value_chain = make_cleanup_value_free_to_mark (value_mark ());
 -  ctx->gdbarch = get_objfile_arch (objfile);
 -  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
+-  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
 -  ctx->offset = dwarf2_per_cu_text_offset (per_cu);
 -  ctx->baton = &baton;
--  ctx->read_reg = dwarf_expr_read_reg;
--  ctx->read_mem = dwarf_expr_read_mem;
--  ctx->get_frame_base = dwarf_expr_frame_base;
--  ctx->get_frame_cfa = dwarf_expr_frame_cfa;
--  ctx->get_tls_address = dwarf_expr_tls_address;
--  ctx->dwarf_call = dwarf_expr_dwarf_call;
+-  ctx->funcs = &dwarf_expr_ctx_funcs;
 -
--  dwarf_expr_eval (ctx, data, size);
-   if (ctx->num_pieces > 0)
+   TRY_CATCH (ex, RETURN_MASK_ERROR)
+     {
+-      dwarf_expr_eval (ctx, data, size);
++      dwarf_expr_prep_ctx (ctx, frame, data, size, per_cu);
+     }
+   if (ex.reason < 0)
      {
-       struct piece_closure *c;
-@@ -951,6 +1104,11 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
-           CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
+       if (ex.error == NOT_AVAILABLE_ERROR)
+       {
+-        do_cleanups (old_chain);
+         retval = allocate_value (type);
+         mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type));
+         return retval;
+@@ -2214,6 +2366,16 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
            int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
  
+           do_cleanups (value_chain);
++
++          /* Frame may be needed for check_typedef of TYPE_DYNAMIC.  */
++          make_cleanup_restore_selected_frame ();
++          select_frame (frame);
++
 +          /* object_address_set called here is required in ALLOCATE_VALUE's
 +             CHECK_TYPEDEF for the object's possible
 +             DW_OP_push_object_address.  */
 +          object_address_set (address);
 +
-           retval = allocate_value (type);
+           retval = allocate_value_lazy (type);
            VALUE_LVAL (retval) = lval_memory;
-           set_value_lazy (retval, 1);
-@@ -2590,11 +2748,51 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
-                        dlbaton->per_cu);
+           if (in_stack_memory)
+@@ -4130,8 +4292,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
+                              dlbaton->per_cu);
  }
  
 -/* The set of location functions used with the DWARF-2 expression
@@ -2165,11 +1502,11 @@ index f59bc40..7ff0ef9 100644
 +/* The set of location functions used with the DWARF-2 location lists.  */
  const struct symbol_computed_ops dwarf2_loclist_funcs = {
    loclist_read_variable,
-   loclist_read_needs_frame,
-   loclist_describe_location,
+   loclist_read_variable_at_entry,
+@@ -4140,6 +4301,48 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = {
    loclist_tracepoint_var_ref
  };
-+
 +static struct value *
 +missing_read_variable (struct symbol *symbol, struct frame_info *frame)
 +{
@@ -2206,15 +1543,20 @@ index f59bc40..7ff0ef9 100644
 +   unable to resolve the symbols.  */
 +const struct symbol_computed_ops dwarf2_missing_funcs = {
 +  missing_read_variable,
++  missing_read_variable,      /* read_variable_at_entry */
 +  missing_read_needs_frame,
 +  missing_describe_location,
 +  missing_tracepoint_var_ref
 +};
++
+ /* Provide a prototype to silence -Wmissing-prototypes.  */
+ extern initialize_file_ftype _initialize_dwarf2loc;
 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
-index 826bc45..1e7d8dc 100644
+index e9d06a3..bfa6776 100644
 --- a/gdb/dwarf2loc.h
 +++ b/gdb/dwarf2loc.h
-@@ -86,5 +86,14 @@ struct dwarf2_loclist_baton
+@@ -127,6 +127,15 @@ struct dwarf2_loclist_baton
  
  extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
  extern const struct symbol_computed_ops dwarf2_loclist_funcs;
@@ -2228,146 +1570,150 @@ index 826bc45..1e7d8dc 100644
 +extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
 +                                   struct type *type, CORE_ADDR *addrp);
  
- #endif /* dwarf2loc.h */
+ /* Compile a DWARF location expression to an agent expression.
+    
 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
-index 1e75235..d54e266 100644
+index deee5a2..b2f052b 100644
 --- a/gdb/dwarf2read.c
 +++ b/gdb/dwarf2read.c
-@@ -51,6 +51,9 @@
- #include "typeprint.h"
- #include "jv-lang.h"
- #include "psympriv.h"
-+#include "exceptions.h"
-+#include "gdb_stat.h"
-+#include "completer.h"
+@@ -64,20 +64,12 @@
+ #include "gdbcore.h" /* for gnutarget */
+ #include "gdb/gdb-index.h"
+ #include <ctype.h>
++#include "gdb_bfd.h"
  
  #include <fcntl.h>
  #include "gdb_string.h"
-@@ -129,6 +132,33 @@ struct dwarf2_section_info
+ #include "gdb_assert.h"
+ #include <sys/types.h>
+-#ifdef HAVE_ZLIB_H
+-#include <zlib.h>
+-#endif
+-#ifdef HAVE_MMAP
+-#include <sys/mman.h>
+-#ifndef MAP_FAILED
+-#define MAP_FAILED ((void *) -1)
+-#endif
+-#endif
+ typedef struct symbol *symbolp;
+ DEF_VEC_P (symbolp);
+@@ -95,8 +87,6 @@ static int check_physname = 0;
+ /* When non-zero, do not reject deprecated .gdb_index sections.  */
+ static int use_deprecated_index_sections = 0;
+-static int pagesize;
+-
+ /* When set, the file that we're processing is known to have debugging
+    info for C++ namespaces.  GCC 3.3.x did not produce this information,
+    but later versions do.  */
+@@ -110,10 +100,6 @@ struct dwarf2_section_info
+   asection *asection;
+   gdb_byte *buffer;
+   bfd_size_type size;
+-  /* Not NULL if the section was actually mmapped.  */
+-  void *map_addr;
+-  /* Page aligned size of mmapped area.  */
+-  bfd_size_type map_len;
+   /* True if we have tried to read this section.  */
    int readin;
  };
+@@ -247,6 +233,10 @@ struct dwarf2_per_objfile
+      This is NULL if the table hasn't been allocated yet.  */
+   htab_t dwo_files;
  
-+/* All offsets in the index are of this type.  It must be
-+   architecture-independent.  */
-+typedef uint32_t offset_type;
-+
-+DEF_VEC_I (offset_type);
-+
-+/* A description of the mapped index.  The file format is described in
-+   a comment by the code that writes the index.  */
-+struct mapped_index
-+{
-+  /* The total length of the buffer.  */
-+  off_t total_size;
-+  /* A pointer to the address table data.  */
-+  const gdb_byte *address_table;
-+  /* Size of the address table data in bytes.  */
-+  offset_type address_table_size;
-+  /* The hash table.  */
-+  const offset_type *index_table;
-+  /* Size in slots, each slot is 2 offset_types.  */
-+  offset_type index_table_slots;
-+  /* A pointer to the constant pool.  */
-+  const char *constant_pool;
-+};
-+
-+typedef struct dwarf2_per_cu_data *dwarf2_per_cu_data_ptr;
-+DEF_VEC_P (dwarf2_per_cu_data_ptr);
++  /* The shared '.dwz' file, if one exists.  This is used when the
++     original data was compressed using 'dwz -m'.  */
++  struct dwz_file *dwz_file;
 +
- struct dwarf2_per_objfile
- {
-   struct dwarf2_section_info info;
-@@ -141,6 +171,7 @@ struct dwarf2_per_objfile
-   struct dwarf2_section_info types;
-   struct dwarf2_section_info frame;
-   struct dwarf2_section_info eh_frame;
-+  struct dwarf2_section_info gdb_index;
-   /* Back link.  */
-   struct objfile *objfile;
-@@ -163,6 +194,12 @@ struct dwarf2_per_objfile
    /* A flag indicating wether this objfile has a section loaded at a
       VMA of 0.  */
    int has_section_at_zero;
-+
-+  /* True if we are using the mapped index.  */
-+  unsigned char using_index;
-+
-+  /* The mapped index.  */
-+  struct mapped_index *index_table;
- };
- static struct dwarf2_per_objfile *dwarf2_per_objfile;
-@@ -182,6 +219,7 @@ static struct dwarf2_per_objfile *dwarf2_per_objfile;
- #define TYPES_SECTION    "debug_types"
- #define FRAME_SECTION    "debug_frame"
- #define EH_FRAME_SECTION "eh_frame"
-+#define GDB_INDEX_SECTION "gdb_index"
+@@ -505,15 +495,13 @@ struct dwarf2_cu
  
- /* local data types */
-@@ -307,6 +345,32 @@ struct dwarf2_cu
-   unsigned int has_namespace_info : 1;
+ struct dwarf2_per_cu_data
+ {
+-  /* The start offset and length of this compilation unit.  2**29-1
+-     bytes should suffice to store the length of any compilation unit
+-     - if it doesn't, GDB will fall over anyway.
++  /* The start offset and length of this compilation unit.
+      NOTE: Unlike comp_unit_head.length, this length includes
+      initial_length_size.
+      If the DIE refers to a DWO file, this is always of the original die,
+      not the DWO file.  */
+   sect_offset offset;
+-  unsigned int length : 29;
++  unsigned int length;
+   /* Flag indicating this compilation unit will be read in before
+      any of the current compilation units are processed.  */
+@@ -528,6 +516,9 @@ struct dwarf2_per_cu_data
+   /* Non-zero if this CU is from .debug_types.  */
+   unsigned int is_debug_types : 1;
++  /* Non-zero if this CU is from the .dwz file.  */
++  unsigned int is_dwz : 1;
++
+   /* The section this CU/TU lives in.
+      If the DIE refers to a DWO file, this is always the original die,
+      not the DWO file.  */
+@@ -715,6 +706,22 @@ struct dwo_file
+   htab_t tus;
  };
  
-+/* When using the index (and thus not using psymtabs), each CU has an
-+   object of this type.  This is used to hold information needed by
-+   the various "quick" methods.  */
-+struct dwarf2_per_cu_quick_data
-+{
-+  /* The line table.  This can be NULL if there was no line table.  */
-+  struct line_header *lines;
++/* This represents a '.dwz' file.  */
 +
-+  /* The file names from the line table.  */
-+  const char **file_names;
-+  /* The file names from the line table after being run through
-+     gdb_realpath.  */
-+  const char **full_names;
++struct dwz_file
++{
++  /* A dwz file can only contain a few sections.  */
++  struct dwarf2_section_info abbrev;
++  struct dwarf2_section_info info;
++  struct dwarf2_section_info str;
++  struct dwarf2_section_info line;
++  struct dwarf2_section_info macro;
++  struct dwarf2_section_info gdb_index;
 +
-+  /* The corresponding symbol table.  This is NULL if symbols for this
-+     CU have not yet been read.  */
-+  struct symtab *symtab;
++  /* The dwz's BFD.  */
++  bfd *dwz_bfd;
++};
 +
-+  /* A temporary mark bit used when iterating over all CUs in
-+     expand_symtabs_matching.  */
-+  unsigned int mark : 1;
+ /* Struct used to pass misc. parameters to read_die_and_children, et
+    al.  which are used for both .debug_info and .debug_types dies.
+    All parameters here are unchanging for the life of the call.  This
+@@ -828,6 +835,12 @@ struct partial_die_info
+     /* Flag set if fixup_partial_die has been called on this die.  */
+     unsigned int fixup_called : 1;
++    /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt.  */
++    unsigned int is_dwz : 1;
 +
-+  /* True if we've tried to read the line table.  */
-+  unsigned int read_lines : 1;
-+};
++    /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt.  */
++    unsigned int spec_is_dwz : 1;
 +
- /* Persistent data held for a compilation unit, even when not
-    processing it.  We put a pointer to this structure in the
-    read_symtab_private field of the psymtab.  If we encounter
-@@ -347,10 +411,21 @@ struct dwarf2_per_cu_data
-      it.  */
-   htab_t type_hash;
--  /* The partial symbol table associated with this compilation unit,
--     or NULL for partial units (which do not have an associated
--     symtab).  */
--  struct partial_symtab *psymtab;
-+  /* The corresponding objfile.  */
-+  struct objfile *objfile;
-+
-+  /* When using partial symbol tables, the 'psymtab' field is active.
-+     Otherwise the 'quick' field is active.  */
-+  union
-+  {
-+    /* The partial symbol table associated with this compilation unit,
-+       or NULL for partial units (which do not have an associated
-+       symtab).  */
-+    struct partial_symtab *psymtab;
-+
-+    /* Data needed by the "quick" functions.  */
-+    struct dwarf2_per_cu_quick_data *quick;
-+  } v;
- };
+     /* The name of this DIE.  Normally the value of DW_AT_name, but
+        sometimes a default name for unnamed DIEs.  */
+     char *name;
+@@ -1213,7 +1226,7 @@ static gdb_byte *read_partial_die (const struct die_reader_specs *,
+                                  unsigned int,
+                                  gdb_byte *);
+-static struct partial_die_info *find_partial_die (sect_offset,
++static struct partial_die_info *find_partial_die (sect_offset, int,
+                                                 struct dwarf2_cu *);
  
- /* Entry in the signatured_types hash table.  */
-@@ -1083,6 +1158,9 @@ static int attr_form_is_section_offset (struct attribute *);
+ static void fixup_partial_die (struct partial_die_info *,
+@@ -1258,6 +1271,8 @@ static char *read_indirect_string (bfd *, gdb_byte *,
+                                    const struct comp_unit_head *,
+                                    unsigned int *);
  
- static int attr_form_is_constant (struct attribute *);
++static char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST);
++
+ static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
+ static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
+@@ -1509,6 +1524,9 @@ static void fill_in_loclist_baton (struct dwarf2_cu *cu,
+                                  struct dwarf2_loclist_baton *baton,
+                                  struct attribute *attr);
  
 +static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton
 +  (struct attribute *attr, struct dwarf2_cu *cu);
@@ -2375,9 +1721,18 @@ index 1e75235..d54e266 100644
  static void dwarf2_symbol_mark_computed (struct attribute *attr,
                                         struct symbol *sym,
                                         struct dwarf2_cu *cu);
-@@ -1113,6 +1191,9 @@ static void age_cached_comp_units (void);
+@@ -1524,7 +1542,7 @@ static hashval_t partial_die_hash (const void *item);
+ static int partial_die_eq (const void *item_lhs, const void *item_rhs);
+ static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
+-  (sect_offset offset, struct objfile *objfile);
++  (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile);
+ static void init_one_comp_unit (struct dwarf2_cu *cu,
+                               struct dwarf2_per_cu_data *per_cu);
+@@ -1541,6 +1559,9 @@ static void age_cached_comp_units (void);
  
- static void free_one_cached_comp_unit (void *);
+ static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
  
 +static void fetch_die_type_attrs (struct die_info *die, struct type *type,
 +                                struct dwarf2_cu *cu);
@@ -2385,1508 +1740,1269 @@ index 1e75235..d54e266 100644
  static struct type *set_die_type (struct die_info *, struct type *,
                                  struct dwarf2_cu *);
  
-@@ -1132,6 +1213,56 @@ static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
+@@ -1569,6 +1590,9 @@ static struct type *get_die_type_at_offset (sect_offset,
  
  static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
  
 +static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
 +  (struct attribute *attr, struct dwarf2_cu *cu);
 +
-+static void dwarf2_release_queue (void *dummy);
-+
-+static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
-+                           struct objfile *objfile);
-+
-+static void process_queue (struct objfile *objfile);
-+
-+static void find_file_and_directory (struct die_info *die,
-+                                   struct dwarf2_cu *cu,
-+                                   char **name, char **comp_dir);
-+
-+static char *file_full_name (int file, struct line_header *lh,
-+                           const char *comp_dir);
-+
-+static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
-+                                            gdb_byte *info_ptr,
-+                                            gdb_byte *buffer,
-+                                            unsigned int buffer_size,
-+                                            bfd *abfd);
-+
-+static void init_cu_die_reader (struct die_reader_specs *reader,
-+                              struct dwarf2_cu *cu);
-+
-+#if WORDS_BIGENDIAN
-+
-+/* Convert VALUE between big- and little-endian.  */
-+static offset_type
-+byte_swap (offset_type value)
-+{
-+  offset_type result;
-+
-+  result = (value & 0xff) << 24;
-+  result |= (value & 0xff00) << 8;
-+  result |= (value & 0xff0000) >> 8;
-+  result |= (value & 0xff000000) >> 24;
-+  return result;
-+}
-+
-+#define MAYBE_SWAP(V)  byte_swap (V)
-+
-+#else
-+#define MAYBE_SWAP(V) (V)
-+#endif /* WORDS_BIGENDIAN */
-+
-+/* The suffix for an index file.  */
-+#define INDEX_SUFFIX ".gdb-index"
+ static void dwarf2_release_queue (void *dummy);
+ static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
+@@ -1587,6 +1611,12 @@ static void find_file_and_directory (struct die_info *die,
+ static char *file_full_name (int file, struct line_header *lh,
+                            const char *comp_dir);
++static gdb_byte *read_and_check_comp_unit_head
++  (struct comp_unit_head *header,
++   struct dwarf2_section_info *section,
++   struct dwarf2_section_info *abbrev_section, gdb_byte *info_ptr,
++   int is_debug_types_section);
 +
- /* Try to locate the sections we need for DWARF 2 debugging
-    information and return true if we have enough to do something.  */
+ static void init_cutu_and_read_dies
+   (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table,
+    int use_existing_cu, int keep,
+@@ -1608,8 +1638,6 @@ static struct dwo_unit *lookup_dwo_type_unit
  
-@@ -1230,6 +1361,11 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
-       dwarf2_per_objfile->types.asection = sectp;
-       dwarf2_per_objfile->types.size = bfd_get_section_size (sectp);
-     }
-+  else if (section_is_p (sectp->name, GDB_INDEX_SECTION))
-+    {
-+      dwarf2_per_objfile->gdb_index.asection = sectp;
-+      dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
-+    }
+ static void free_dwo_file_cleanup (void *);
+-static void munmap_section_buffer (struct dwarf2_section_info *);
+-
+ static void process_cu_includes (void);
+ #if WORDS_BIGENDIAN
+@@ -1779,85 +1807,6 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
+     dwarf2_per_objfile->has_section_at_zero = 1;
+ }
+-/* Decompress a section that was compressed using zlib.  Store the
+-   decompressed buffer, and its size, in OUTBUF and OUTSIZE.  */
+-
+-static void
+-zlib_decompress_section (struct objfile *objfile, asection *sectp,
+-                         gdb_byte **outbuf, bfd_size_type *outsize)
+-{
+-  bfd *abfd = sectp->owner;
+-#ifndef HAVE_ZLIB_H
+-  error (_("Support for zlib-compressed DWARF data (from '%s') "
+-           "is disabled in this copy of GDB"),
+-         bfd_get_filename (abfd));
+-#else
+-  bfd_size_type compressed_size = bfd_get_section_size (sectp);
+-  gdb_byte *compressed_buffer = xmalloc (compressed_size);
+-  struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
+-  bfd_size_type uncompressed_size;
+-  gdb_byte *uncompressed_buffer;
+-  z_stream strm;
+-  int rc;
+-  int header_size = 12;
+-
+-  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
+-      || bfd_bread (compressed_buffer,
+-                  compressed_size, abfd) != compressed_size)
+-    error (_("Dwarf Error: Can't read DWARF data from '%s'"),
+-           bfd_get_filename (abfd));
+-
+-  /* Read the zlib header.  In this case, it should be "ZLIB" followed
+-     by the uncompressed section size, 8 bytes in big-endian order.  */
+-  if (compressed_size < header_size
+-      || strncmp (compressed_buffer, "ZLIB", 4) != 0)
+-    error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
+-           bfd_get_filename (abfd));
+-  uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
+-  uncompressed_size += compressed_buffer[11];
+-
+-  /* It is possible the section consists of several compressed
+-     buffers concatenated together, so we uncompress in a loop.  */
+-  strm.zalloc = NULL;
+-  strm.zfree = NULL;
+-  strm.opaque = NULL;
+-  strm.avail_in = compressed_size - header_size;
+-  strm.next_in = (Bytef*) compressed_buffer + header_size;
+-  strm.avail_out = uncompressed_size;
+-  uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
+-                                       uncompressed_size);
+-  rc = inflateInit (&strm);
+-  while (strm.avail_in > 0)
+-    {
+-      if (rc != Z_OK)
+-        error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
+-               bfd_get_filename (abfd), rc);
+-      strm.next_out = ((Bytef*) uncompressed_buffer
+-                       + (uncompressed_size - strm.avail_out));
+-      rc = inflate (&strm, Z_FINISH);
+-      if (rc != Z_STREAM_END)
+-        error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
+-               bfd_get_filename (abfd), rc);
+-      rc = inflateReset (&strm);
+-    }
+-  rc = inflateEnd (&strm);
+-  if (rc != Z_OK
+-      || strm.avail_out != 0)
+-    error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
+-           bfd_get_filename (abfd), rc);
+-
+-  do_cleanups (cleanup);
+-  *outbuf = uncompressed_buffer;
+-  *outsize = uncompressed_size;
+-#endif
+-}
+-
+ /* A helper function that decides whether a section is empty,
+    or not present.  */
  
-   if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
-       && bfd_section_vma (abfd, sectp) == 0)
-@@ -1353,87 +1489,940 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
-   if (pagesize == 0)
-     pagesize = getpagesize ();
+@@ -1884,56 +1833,27 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
+   if (info->readin)
+     return;
+   info->buffer = NULL;
+-  info->map_addr = NULL;
+   info->readin = 1;
+   if (dwarf2_section_empty_p (info))
+     return;
+-  /* Note that ABFD may not be from OBJFILE, e.g. a DWO section.  */
+   abfd = sectp->owner;
  
+-  /* Check if the file has a 4-byte header indicating compression.  */
+-  if (info->size > sizeof (header)
+-      && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
+-      && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
+-    {
+-      /* Upon decompression, update the buffer and its size.  */
+-      if (strncmp (header, "ZLIB", sizeof (header)) == 0)
+-        {
+-          zlib_decompress_section (objfile, sectp, &info->buffer,
+-                                 &info->size);
+-          return;
+-        }
+-    }
+-
+-#ifdef HAVE_MMAP
+-  if (pagesize == 0)
+-    pagesize = getpagesize ();
+-
 -  /* Only try to mmap sections which are large enough: we don't want to
 -     waste space due to fragmentation.  Also, only try mmap for sections
 -     without relocations.  */
-+  /* Only try to mmap sections which are large enough: we don't want to
-+     waste space due to fragmentation.  Also, only try mmap for sections
-+     without relocations.  */
+-
+-  if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
++  /* If the section has relocations, we must read it ourselves.
++     Otherwise we attach it to the BFD.  */
++  if ((sectp->flags & SEC_RELOC) == 0)
+     {
+-      info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
+-                         MAP_PRIVATE, sectp->filepos,
+-                         &info->map_addr, &info->map_len);
++      const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size);
+-      if ((caddr_t)info->buffer != MAP_FAILED)
+-      {
+-#if HAVE_POSIX_MADVISE
+-        posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
+-#endif
+-        return;
+-      }
++      /* We have to cast away const here for historical reasons.
++       Fixing dwarf2read to be const-correct would be quite nice.  */
++      info->buffer = (gdb_byte *) bytes;
++      return;
+     }
+-#endif
+-  /* If we get here, we are a normal, not-compressed section.  */
+-  info->buffer = buf
+-    = obstack_alloc (&objfile->objfile_obstack, info->size);
++  buf = obstack_alloc (&objfile->objfile_obstack, info->size);
++  info->buffer = buf;
+   /* When debugging .o files, we may need to apply relocations; see
+      http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
+@@ -2009,6 +1929,111 @@ dwarf2_get_section_info (struct objfile *objfile,
+   *sizep = info->size;
+ }
++/* A helper function to find the sections for a .dwz file.  */
 +
-+  if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
-+    {
-+      off_t pg_offset = sectp->filepos & ~(pagesize - 1);
-+      size_t map_length = info->size + sectp->filepos - pg_offset;
-+      caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
-+                               MAP_PRIVATE, pg_offset);
++static void
++locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
++{
++  struct dwz_file *dwz_file = arg;
 +
-+      if (retbuf != MAP_FAILED)
-+      {
-+        info->was_mmapped = 1;
-+        info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
-+#if HAVE_POSIX_MADVISE
-+        posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
-+#endif
-+        return;
-+      }
++  /* Note that we only support the standard ELF names, because .dwz
++     is ELF-only (at the time of writing).  */
++  if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
++    {
++      dwz_file->abbrev.asection = sectp;
++      dwz_file->abbrev.size = bfd_get_section_size (sectp);
 +    }
-+#endif
-+
-+  /* If we get here, we are a normal, not-compressed section.  */
-+  info->buffer = buf
-+    = obstack_alloc (&objfile->objfile_obstack, info->size);
-+
-+  /* When debugging .o files, we may need to apply relocations; see
-+     http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
-+     We never compress sections in .o files, so we only need to
-+     try this when the section is not compressed.  */
-+  retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
-+  if (retbuf != NULL)
++  else if (section_is_p (sectp->name, &dwarf2_elf_names.info))
 +    {
-+      info->buffer = retbuf;
-+      return;
++      dwz_file->info.asection = sectp;
++      dwz_file->info.size = bfd_get_section_size (sectp);
++    }
++  else if (section_is_p (sectp->name, &dwarf2_elf_names.str))
++    {
++      dwz_file->str.asection = sectp;
++      dwz_file->str.size = bfd_get_section_size (sectp);
++    }
++  else if (section_is_p (sectp->name, &dwarf2_elf_names.line))
++    {
++      dwz_file->line.asection = sectp;
++      dwz_file->line.size = bfd_get_section_size (sectp);
++    }
++  else if (section_is_p (sectp->name, &dwarf2_elf_names.macro))
++    {
++      dwz_file->macro.asection = sectp;
++      dwz_file->macro.size = bfd_get_section_size (sectp);
++    }
++  else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index))
++    {
++      dwz_file->gdb_index.asection = sectp;
++      dwz_file->gdb_index.size = bfd_get_section_size (sectp);
 +    }
-+
-+  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
-+      || bfd_bread (buf, info->size, abfd) != info->size)
-+    error (_("Dwarf Error: Can't read DWARF data from '%s'"),
-+         bfd_get_filename (abfd));
 +}
 +
-+/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
-+   SECTION_NAME. */
++/* Open the separate '.dwz' debug file, if needed.  Error if the file
++   cannot be found.  */
 +
-+void
-+dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
-+                         asection **sectp, gdb_byte **bufp,
-+                         bfd_size_type *sizep)
++static struct dwz_file *
++dwarf2_get_dwz_file (void)
 +{
-+  struct dwarf2_per_objfile *data
-+    = objfile_data (objfile, dwarf2_objfile_data_key);
-+  struct dwarf2_section_info *info;
++  bfd *abfd, *dwz_bfd;
++  asection *section;
++  gdb_byte *data;
++  struct cleanup *cleanup;
++  const char *filename;
++  struct dwz_file *result;
 +
-+  /* We may see an objfile without any DWARF, in which case we just
-+     return nothing.  */
-+  if (data == NULL)
-+    {
-+      *sectp = NULL;
-+      *bufp = NULL;
-+      *sizep = 0;
-+      return;
-+    }
-+  if (section_is_p (section_name, EH_FRAME_SECTION))
-+    info = &data->eh_frame;
-+  else if (section_is_p (section_name, FRAME_SECTION))
-+    info = &data->frame;
-+  else
-+    gdb_assert (0);
++  if (dwarf2_per_objfile->dwz_file != NULL)
++    return dwarf2_per_objfile->dwz_file;
 +
-+  if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
-+    /* We haven't read this section in yet.  Do it now.  */
-+    dwarf2_read_section (objfile, info);
++  abfd = dwarf2_per_objfile->objfile->obfd;
++  section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink");
++  if (section == NULL)
++    error (_("could not find '.gnu_debugaltlink' section"));
++  if (!bfd_malloc_and_get_section (abfd, section, &data))
++    error (_("could not read '.gnu_debugaltlink' section: %s"),
++         bfd_errmsg (bfd_get_error ()));
++  cleanup = make_cleanup (xfree, data);
 +
-+  *sectp = info->asection;
-+  *bufp = info->buffer;
-+  *sizep = info->size;
-+}
++  filename = data;
++  if (!IS_ABSOLUTE_PATH (filename))
++    {
++      char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name);
++      char *rel;
 +
-+\f
++      make_cleanup (xfree, abs);
++      abs = ldirname (abs);
++      make_cleanup (xfree, abs);
 +
-+/* Read in the symbols for PER_CU.  OBJFILE is the objfile from which
-+   this CU came.  */
-+static void
-+dw2_do_instantiate_symtab (struct objfile *objfile,
-+                         struct dwarf2_per_cu_data *per_cu)
-+{
-+  struct cleanup *back_to;
++      rel = concat (abs, SLASH_STRING, filename, (char *) NULL);
++      make_cleanup (xfree, rel);
++      filename = rel;
++    }
 +
-+  back_to = make_cleanup (dwarf2_release_queue, NULL);
++  /* The format is just a NUL-terminated file name, followed by the
++     build-id.  For now, though, we ignore the build-id.  */
++  dwz_bfd = gdb_bfd_open (filename, gnutarget, -1);
++  if (dwz_bfd == NULL)
++    error (_("could not read '%s': %s"), filename,
++         bfd_errmsg (bfd_get_error ()));
 +
-+  queue_comp_unit (per_cu, objfile);
++  if (!bfd_check_format (dwz_bfd, bfd_object))
++    {
++      gdb_bfd_unref (dwz_bfd);
++      error (_("file '%s' was not usable: %s"), filename,
++           bfd_errmsg (bfd_get_error ()));
++    }
 +
-+  if (per_cu->from_debug_types)
-+    read_signatured_type_at_offset (objfile, per_cu->offset);
-+  else
-+    load_full_comp_unit (per_cu, objfile);
++  result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
++                         struct dwz_file);
++  result->dwz_bfd = dwz_bfd;
 +
-+  process_queue (objfile);
++  bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result);
 +
-+  /* Age the cache, releasing compilation units that have not
-+     been used recently.  */
-+  age_cached_comp_units ();
++  do_cleanups (cleanup);
 +
-+  do_cleanups (back_to);
++  return result;
 +}
-+
-+/* Ensure that the symbols for PER_CU have been read in.  OBJFILE is
-+   the objfile from which this CU came.  Returns the resulting symbol
-+   table.  */
-+static struct symtab *
-+dw2_instantiate_symtab (struct objfile *objfile,
-+                      struct dwarf2_per_cu_data *per_cu)
-+{
-+  if (!per_cu->v.quick->symtab)
-+    {
-+      struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
-+      increment_reading_symtab ();
-+      dw2_do_instantiate_symtab (objfile, per_cu);
-+      do_cleanups (back_to);
-+    }
-+  return per_cu->v.quick->symtab;
-+}
-+
-+/* A helper function that knows how to read a 64-bit value in a way
-+   that doesn't make gdb die.  Returns 1 if the conversion went ok, 0
-+   otherwise.  */
-+static int
-+extract_cu_value (const char *bytes, ULONGEST *result)
-+{
-+  if (sizeof (ULONGEST) < 8)
-+    {
-+      int i;
-+
-+      /* Ignore the upper 4 bytes if they are all zero.  */
-+      for (i = 0; i < 4; ++i)
-+      if (bytes[i + 4] != 0)
-+        return 0;
-+
-+      *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
-+    }
-+  else
-+    *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
-+  return 1;
-+}
-+
\f
+ /* DWARF quick_symbols_functions support.  */
+@@ -2279,23 +2304,19 @@ extract_cu_value (const char *bytes, ULONGEST *result)
+   return 1;
+ }
+-/* Read the CU list from the mapped index, and use it to create all
+-   the CU objects for this objfile.  Return 0 if something went wrong,
+-   1 if everything went ok.  */
++/* A helper for create_cus_from_index that handles a given list of
++   CUs.  */
+ static int
+-create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
+-                     offset_type cu_list_elements)
++create_cus_from_index_list (struct objfile *objfile,
++                          const gdb_byte *cu_list, offset_type n_elements,
++                          struct dwarf2_section_info *section,
++                          int is_dwz,
++                          int base_offset)
+ {
+   offset_type i;
+-  dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
+-  dwarf2_per_objfile->all_comp_units
+-    = obstack_alloc (&objfile->objfile_obstack,
+-                   dwarf2_per_objfile->n_comp_units
+-                   * sizeof (struct dwarf2_per_cu_data *));
+-
+-  for (i = 0; i < cu_list_elements; i += 2)
++  for (i = 0; i < n_elements; i += 2)
+     {
+       struct dwarf2_per_cu_data *the_cu;
+       ULONGEST offset, length;
+@@ -2310,15 +2331,45 @@ create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
+       the_cu->offset.sect_off = offset;
+       the_cu->length = length;
+       the_cu->objfile = objfile;
+-      the_cu->info_or_types_section = &dwarf2_per_objfile->info;
++      the_cu->info_or_types_section = section;
+       the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+                                       struct dwarf2_per_cu_quick_data);
+-      dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
++      the_cu->is_dwz = is_dwz;
++      dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu;
+     }
+   return 1;
+ }
 +/* Read the CU list from the mapped index, and use it to create all
 +   the CU objects for this objfile.  Return 0 if something went wrong,
 +   1 if everything went ok.  */
++
 +static int
-+create_cus_from_index (struct objfile *objfile, struct mapped_index *index,
-+                     const gdb_byte *cu_list, offset_type cu_list_elements)
++create_cus_from_index (struct objfile *objfile,
++                     const gdb_byte *cu_list, offset_type cu_list_elements,
++                     const gdb_byte *dwz_list, offset_type dwz_elements)
 +{
-+  offset_type i;
-+  const char *entry;
++  struct dwz_file *dwz;
 +
-+  dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
++  dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2;
 +  dwarf2_per_objfile->all_comp_units
 +    = obstack_alloc (&objfile->objfile_obstack,
 +                   dwarf2_per_objfile->n_comp_units
 +                   * sizeof (struct dwarf2_per_cu_data *));
 +
-+  for (i = 0; i < cu_list_elements; i += 2)
-+    {
-+      struct dwarf2_per_cu_data *the_cu;
-+      ULONGEST offset, length;
-+
-+      if (!extract_cu_value (cu_list, &offset)
-+        || !extract_cu_value (cu_list + 8, &length))
-+      return 0;
-+      cu_list += 2 * 8;
-+
-+      the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-+                             struct dwarf2_per_cu_data);
-+      the_cu->offset = offset;
-+      the_cu->length = length;
-+      the_cu->objfile = objfile;
-+      the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-+                                      struct dwarf2_per_cu_quick_data);
-+      dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
-+    }
-+
-+  return 1;
-+}
-+
-+/* Read the address map data from the mapped index, and use it to
-+   populate the objfile's psymtabs_addrmap.  */
-+static void
-+create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
-+{
-+  const gdb_byte *iter, *end;
-+  struct obstack temp_obstack;
-+  struct addrmap *mutable_map;
-+  struct cleanup *cleanup;
-+  CORE_ADDR baseaddr;
-+
-+  obstack_init (&temp_obstack);
-+  cleanup = make_cleanup_obstack_free (&temp_obstack);
-+  mutable_map = addrmap_create_mutable (&temp_obstack);
-+
-+  iter = index->address_table;
-+  end = iter + index->address_table_size;
-+
-+  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
++  if (!create_cus_from_index_list (objfile, cu_list, cu_list_elements,
++                                 &dwarf2_per_objfile->info, 0, 0))
++    return 0;
 +
-+  while (iter < end)
-+    {
-+      ULONGEST hi, lo, cu_index;
-+      lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
-+      iter += 8;
-+      hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
-+      iter += 8;
-+      cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
-+      iter += 4;
-+      
-+      addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
-+                       dwarf2_per_objfile->all_comp_units[cu_index]);
-+    }
++  if (dwz_elements == 0)
++    return 1;
 +
-+  objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
-+                                                  &objfile->objfile_obstack);
-+  do_cleanups (cleanup);
++  dwz = dwarf2_get_dwz_file ();
++  return create_cus_from_index_list (objfile, dwz_list, dwz_elements,
++                                   &dwz->info, 1, cu_list_elements / 2);
 +}
 +
-+/* The hash function for strings in the mapped index.  This is the
-+   same as the hashtab.c hash function, but we keep a separate copy to
-+   maintain control over the implementation.  This is necessary
-+   because the hash function is tied to the format of the mapped index
-+   file.  */
-+static hashval_t
-+mapped_index_string_hash (const void *p)
-+{
-+  const unsigned char *str = (const unsigned char *) p;
-+  hashval_t r = 0;
-+  unsigned char c;
+ /* Create the signatured type hash table from the index.  */
+ static int
+@@ -2508,33 +2559,44 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
+     }
+ }
+-/* Read the index file.  If everything went ok, initialize the "quick"
+-   elements of all the CUs and return 1.  Otherwise, return 0.  */
++/* A helper function that reads the .gdb_index from SECTION and fills
++   in MAP.  FILENAME is the name of the file containing the section;
++   it is used for error reporting.  DEPRECATED_OK is nonzero if it is
++   ok to use deprecated sections.
 +
-+  while ((c = *str++) != 0)
-+    r = r * 67 + c - 113;
++   CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
++   out parameters that are filled in with information about the CU and
++   TU lists in the section.
 +
-+  return r;
++   Returns 1 if all went well, 0 otherwise.  */
+ static int
+-dwarf2_read_index (struct objfile *objfile)
++read_index_from_section (struct objfile *objfile,
++                       const char *filename,
++                       int deprecated_ok,
++                       struct dwarf2_section_info *section,
++                       struct mapped_index *map,
++                       const gdb_byte **cu_list,
++                       offset_type *cu_list_elements,
++                       const gdb_byte **types_list,
++                       offset_type *types_list_elements)
+ {
+   char *addr;
+-  struct mapped_index *map;
++  offset_type version;
+   offset_type *metadata;
+-  const gdb_byte *cu_list;
+-  const gdb_byte *types_list = NULL;
+-  offset_type version, cu_list_elements;
+-  offset_type types_list_elements = 0;
+   int i;
+-  if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
++  if (dwarf2_section_empty_p (section))
+     return 0;
+   /* Older elfutils strip versions could keep the section in the main
+      executable while splitting it for the separate debug info file.  */
+-  if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
+-       & SEC_HAS_CONTENTS) == 0)
++  if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0)
+     return 0;
+-  dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
++  dwarf2_read_section (objfile, section);
+-  addr = dwarf2_per_objfile->gdb_index.buffer;
++  addr = section->buffer;
+   /* Version check.  */
+   version = MAYBE_SWAP (*(offset_type *) addr);
+   /* Versions earlier than 3 emitted every copy of a psymbol.  This
+@@ -2547,7 +2609,7 @@ dwarf2_read_index (struct objfile *objfile)
+       if (!warning_printed)
+       {
+         warning (_("Skipping obsolete .gdb_index section in %s."),
+-                 objfile->name);
++                 filename);
+         warning_printed = 1;
+       }
+       return 0;
+@@ -2560,7 +2622,7 @@ dwarf2_read_index (struct objfile *objfile)
+      set breakpoints on inlined functions by name, so we ignore these
+      indices unless the user has done
+      "set use-deprecated-index-sections on".  */
+-  if (version < 6 && !use_deprecated_index_sections)
++  if (version < 6 && !deprecated_ok)
+     {
+       static int warning_printed = 0;
+       if (!warning_printed)
+@@ -2569,7 +2631,7 @@ dwarf2_read_index (struct objfile *objfile)
+ Skipping deprecated .gdb_index section in %s.\n\
+ Do \"set use-deprecated-index-sections on\" before the file is read\n\
+ to use the section anyway."),
+-                 objfile->name);
++                 filename);
+         warning_printed = 1;
+       }
+       return 0;
+@@ -2579,22 +2641,21 @@ to use the section anyway."),
+   if (version > 7)
+     return 0;
+-  map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
+   map->version = version;
+-  map->total_size = dwarf2_per_objfile->gdb_index.size;
++  map->total_size = section->size;
+   metadata = (offset_type *) (addr + sizeof (offset_type));
+   i = 0;
+-  cu_list = addr + MAYBE_SWAP (metadata[i]);
+-  cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
+-                    / 8);
++  *cu_list = addr + MAYBE_SWAP (metadata[i]);
++  *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
++                     / 8);
+   ++i;
+-  types_list = addr + MAYBE_SWAP (metadata[i]);
+-  types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
+-                        - MAYBE_SWAP (metadata[i]))
+-                       / 8);
++  *types_list = addr + MAYBE_SWAP (metadata[i]);
++  *types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
++                         - MAYBE_SWAP (metadata[i]))
++                        / 8);
+   ++i;
+   map->address_table = addr + MAYBE_SWAP (metadata[i]);
+@@ -2610,11 +2671,55 @@ to use the section anyway."),
+   map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
++  return 1;
 +}
 +
-+/* Find a slot in the mapped index INDEX for the object named NAME.
-+   If NAME is found, set *VEC_OUT to point to the CU vector in the
-+   constant pool and return 1.  If NAME cannot be found, return 0.  */
-+static int
-+find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
-+                        offset_type **vec_out)
-+{
-+  offset_type hash = mapped_index_string_hash (name);
-+  offset_type slot, step;
-+
-+  slot = hash & (index->index_table_slots - 1);
-+  step = ((hash * 17) & (index->index_table_slots - 1)) | 1;
-+
-+  for (;;)
-+    {
-+      /* Convert a slot number to an offset into the table.  */
-+      offset_type i = 2 * slot;
-+      const char *str;
-+      if (index->index_table[i] == 0 && index->index_table[i + 1] == 0)
-+      return 0;
-+
-+      str = index->constant_pool + MAYBE_SWAP (index->index_table[i]);
-+      if (!strcmp (name, str))
-+      {
-+        *vec_out = (offset_type *) (index->constant_pool
-+                                    + MAYBE_SWAP (index->index_table[i + 1]));
-+        return 1;
-+      }
-+
-+      slot = (slot + step) & (index->index_table_slots - 1);
-+    }
-+}
 +
 +/* Read the index file.  If everything went ok, initialize the "quick"
 +   elements of all the CUs and return 1.  Otherwise, return 0.  */
++
 +static int
 +dwarf2_read_index (struct objfile *objfile)
 +{
-+  char *addr;
-+  struct mapped_index *map;
-+  offset_type *metadata;
-+  const gdb_byte *cu_list;
-+  offset_type cu_list_elements;
-+
-+  if (dwarf2_per_objfile->gdb_index.asection == NULL
-+      || dwarf2_per_objfile->gdb_index.size == 0)
-+    return 0;
-+  dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
-+
-+  addr = dwarf2_per_objfile->gdb_index.buffer;
-+  /* Version check.  */
-+  if (MAYBE_SWAP (*(offset_type *) addr) != 1)
-+    return 0;
++  struct mapped_index local_map, *map;
++  const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
++  offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
 +
-+  map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
-+  map->total_size = dwarf2_per_objfile->gdb_index.size;
-+
-+  metadata = (offset_type *) (addr + sizeof (offset_type));
-+  cu_list = addr + MAYBE_SWAP (metadata[0]);
-+  cu_list_elements = ((MAYBE_SWAP (metadata[1]) - MAYBE_SWAP (metadata[0]))
-+                    / 8);
-+  map->address_table = addr + MAYBE_SWAP (metadata[1]);
-+  map->address_table_size = (MAYBE_SWAP (metadata[2])
-+                           - MAYBE_SWAP (metadata[1]));
-+  map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[2]));
-+  map->index_table_slots = ((MAYBE_SWAP (metadata[3])
-+                           - MAYBE_SWAP (metadata[2]))
-+                          / (2 * sizeof (offset_type)));
-+  map->constant_pool = addr + MAYBE_SWAP (metadata[3]);
-+
-+  if (!create_cus_from_index (objfile, map, cu_list, cu_list_elements))
++  if (!read_index_from_section (objfile, objfile->name,
++                              use_deprecated_index_sections,
++                              &dwarf2_per_objfile->gdb_index, &local_map,
++                              &cu_list, &cu_list_elements,
++                              &types_list, &types_list_elements))
 +    return 0;
 +
-+  create_addrmap_from_index (objfile, map);
-+
-+  dwarf2_per_objfile->index_table = map;
-+  dwarf2_per_objfile->using_index = 1;
+   /* Don't use the index if it's empty.  */
+-  if (map->symbol_table_slots == 0)
++  if (local_map.symbol_table_slots == 0)
+     return 0;
+-  if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
++  /* If there is a .dwz file, read it so we can get its CU list as
++     well.  */
++  if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
++    {
++      struct dwz_file *dwz = dwarf2_get_dwz_file ();
++      struct mapped_index dwz_map;
++      const gdb_byte *dwz_types_ignore;
++      offset_type dwz_types_elements_ignore;
++
++      if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd),
++                                  1,
++                                  &dwz->gdb_index, &dwz_map,
++                                  &dwz_list, &dwz_list_elements,
++                                  &dwz_types_ignore,
++                                  &dwz_types_elements_ignore))
++      {
++        warning (_("could not read '.gdb_index' section from %s; skipping"),
++                 bfd_get_filename (dwz->dwz_bfd));
++        return 0;
++      }
++    }
 +
-+  return 1;
-+}
++  if (!create_cus_from_index (objfile, cu_list, cu_list_elements,
++                            dwz_list, dwz_list_elements))
+     return 0;
+   if (types_list_elements)
+@@ -2635,7 +2740,10 @@ to use the section anyway."),
+       return 0;
+     }
+-  create_addrmap_from_index (objfile, map);
++  create_addrmap_from_index (objfile, &local_map);
 +
-+/* A helper for the "quick" functions which sets the global
-+   dwarf2_per_objfile according to OBJFILE.  */
-+static void
-+dw2_setup (struct objfile *objfile)
-+{
-+  dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
-+  gdb_assert (dwarf2_per_objfile);
-+}
++  map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index));
++  *map = local_map;
+   dwarf2_per_objfile->index_table = map;
+   dwarf2_per_objfile->using_index = 1;
+@@ -3686,6 +3794,22 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
+   return info_ptr;
+ }
++/* Helper function that returns the proper abbrev section for
++   THIS_CU.  */
 +
-+/* A helper for the "quick" functions which attempts to read the line
-+   table for THIS_CU.  */
-+static void
-+dw2_require_line_header (struct objfile *objfile,
-+                       struct dwarf2_per_cu_data *this_cu)
++static struct dwarf2_section_info *
++get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
 +{
-+  bfd *abfd = objfile->obfd;
-+  struct line_header *lh = NULL;
-+  struct attribute *attr;
-+  struct cleanup *cleanups;
-+  struct die_info *comp_unit_die;
-+  gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
-+  int has_children, i;
-+  struct dwarf2_cu cu;
-+  unsigned int bytes_read, buffer_size;
-+  struct die_reader_specs reader_specs;
-+  char *name, *comp_dir;
-+
-+  if (this_cu->v.quick->read_lines)
-+    return;
-+  this_cu->v.quick->read_lines = 1;
-+
-+  memset (&cu, 0, sizeof (cu));
-+  cu.objfile = objfile;
-+  obstack_init (&cu.comp_unit_obstack);
-+
-+  cleanups = make_cleanup (free_stack_comp_unit, &cu);
-+
-+  dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
-+  buffer_size = dwarf2_per_objfile->info.size;
-+  buffer = dwarf2_per_objfile->info.buffer;
-+  info_ptr = buffer + this_cu->offset;
-+  beg_of_comp_unit = info_ptr;
-+
-+  info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
-+                                        buffer, buffer_size,
-+                                        abfd);
-+
-+  /* Complete the cu_header.  */
-+  cu.header.offset = beg_of_comp_unit - buffer;
-+  cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
-+
-+  this_cu->cu = &cu;
-+  cu.per_cu = this_cu;
-+
-+  dwarf2_read_abbrevs (abfd, &cu);
-+  make_cleanup (dwarf2_free_abbrev_table, &cu);
-+
-+  if (this_cu->from_debug_types)
-+    info_ptr += 8 /*signature*/ + cu.header.offset_size;
-+  init_cu_die_reader (&reader_specs, &cu);
-+  info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
-+                          &has_children);
-+
-+  attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
-+  if (attr)
-+    {
-+      unsigned int line_offset = DW_UNSND (attr);
-+      lh = dwarf_decode_line_header (line_offset, abfd, &cu);
-+    }
-+  if (lh == NULL)
-+    {
-+      do_cleanups (cleanups);
-+      return;
-+    }
-+
-+  find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
++  struct dwarf2_section_info *abbrev;
 +
-+  this_cu->v.quick->lines = lh;
-+
-+  this_cu->v.quick->file_names
-+    = obstack_alloc (&objfile->objfile_obstack,
-+                   lh->num_file_names * sizeof (char *));
-+  for (i = 0; i < lh->num_file_names; ++i)
-+    this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir);
++  if (this_cu->is_dwz)
++    abbrev = &dwarf2_get_dwz_file ()->abbrev;
++  else
++    abbrev = &dwarf2_per_objfile->abbrev;
 +
-+  do_cleanups (cleanups);
++  return abbrev;
 +}
 +
-+/* A helper for the "quick" functions which computes and caches the
-+   real path for a given file name from the line table.
-+   dw2_require_line_header must have been called before this is
-+   invoked.  */
-+static const char *
-+dw2_require_full_path (struct objfile *objfile,
-+                     struct dwarf2_per_cu_data *cu,
-+                     int index)
-+{
-+  if (!cu->v.quick->full_names)
-+    cu->v.quick->full_names
-+      = OBSTACK_CALLOC (&objfile->objfile_obstack,
-+                      cu->v.quick->lines->num_file_names,
-+                      sizeof (char *));
+ /* Subroutine of read_and_check_comp_unit_head and
+    read_and_check_type_unit_head to simplify them.
+    Perform various error checking on the header.  */
+@@ -3704,8 +3828,7 @@ error_check_comp_unit_head (struct comp_unit_head *header,
+          filename);
+   if (header->abbrev_offset.sect_off
+-      >= dwarf2_section_size (dwarf2_per_objfile->objfile,
+-                            &dwarf2_per_objfile->abbrev))
++      >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
+     error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
+          "(offset 0x%lx + 6) [in module %s]"),
+          (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off,
+@@ -3942,6 +4065,7 @@ create_debug_types_hash_table (struct dwo_file *dwo_file,
+     {
+       bfd *abfd;
+       gdb_byte *info_ptr, *end_ptr;
++      struct dwarf2_section_info *abbrev_section;
+       dwarf2_read_section (objfile, section);
+       info_ptr = section->buffer;
+@@ -3953,6 +4077,11 @@ create_debug_types_hash_table (struct dwo_file *dwo_file,
+        not present, in which case section->asection will be NULL.  */
+       abfd = section->asection->owner;
++      if (dwo_file)
++      abbrev_section = &dwo_file->sections.abbrev;
++      else
++      abbrev_section = &dwarf2_per_objfile->abbrev;
 +
-+  if (!cu->v.quick->full_names[index])
-+    cu->v.quick->full_names[index]
-+      = gdb_realpath (cu->v.quick->file_names[index]);
+       if (types_htab == NULL)
+       {
+         if (dwo_file)
+@@ -4192,7 +4321,8 @@ init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
+   dwarf2_read_section (objfile, section);
+   begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
+-  abbrev_section = &dwarf2_per_objfile->abbrev;
 +
-+  return cu->v.quick->full_names[index];
-+}
++  abbrev_section = get_abbrev_section_for_cu (this_cu);
+   if (use_existing_cu && this_cu->cu != NULL)
+     {
+@@ -4574,7 +4704,7 @@ init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu,
+                               void *data)
+ {
+   init_cutu_and_read_dies_no_follow (this_cu,
+-                                   &dwarf2_per_objfile->abbrev,
++                                   get_abbrev_section_for_cu (this_cu),
+                                    NULL,
+                                    die_reader_func, data);
+ }
+@@ -5202,6 +5332,9 @@ set_partial_user (struct objfile *objfile)
+       struct partial_symtab *pst = per_cu->v.psymtab;
+       int j;
++      if (pst == NULL)
++      continue;
 +
-+static struct symtab *
-+dw2_find_last_source_symtab (struct objfile *objfile)
-+{
-+  int index;
-+  dw2_setup (objfile);
-+  index = dwarf2_per_objfile->n_comp_units - 1;
-+  return dw2_instantiate_symtab (objfile,
-+                               dwarf2_per_objfile->all_comp_units[index]);
+       for (j = 0; j < pst->number_of_dependencies; ++j)
+       {
+         /* Set the 'user' field only if it is not already set.  */
+@@ -5296,38 +5429,32 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
+                          load_partial_comp_unit_reader, NULL);
+ }
+-/* Create a list of all compilation units in OBJFILE.
+-   This is only done for -readnow and building partial symtabs.  */
+-
+ static void
+-create_all_comp_units (struct objfile *objfile)
++read_comp_units_from_section (struct objfile *objfile,
++                            struct dwarf2_section_info *section,
++                            unsigned int is_dwz,
++                            int *n_allocated,
++                            int *n_comp_units,
++                            struct dwarf2_per_cu_data ***all_comp_units)
+ {
+-  int n_allocated;
+-  int n_comp_units;
+-  struct dwarf2_per_cu_data **all_comp_units;
+   gdb_byte *info_ptr;
++  bfd *abfd = section->asection->owner;
+-  dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
+-  info_ptr = dwarf2_per_objfile->info.buffer;
++  dwarf2_read_section (objfile, section);
+-  n_comp_units = 0;
+-  n_allocated = 10;
+-  all_comp_units = xmalloc (n_allocated
+-                          * sizeof (struct dwarf2_per_cu_data *));
++  info_ptr = section->buffer;
+-  while (info_ptr < dwarf2_per_objfile->info.buffer
+-       + dwarf2_per_objfile->info.size)
++  while (info_ptr < section->buffer + section->size)
+     {
+       unsigned int length, initial_length_size;
+       struct dwarf2_per_cu_data *this_cu;
+       sect_offset offset;
+-      offset.sect_off = info_ptr - dwarf2_per_objfile->info.buffer;
++      offset.sect_off = info_ptr - section->buffer;
+       /* Read just enough information to find out where the next
+        compilation unit is.  */
+-      length = read_initial_length (objfile->obfd, info_ptr,
+-                                  &initial_length_size);
++      length = read_initial_length (abfd, info_ptr, &initial_length_size);
+       /* Save the compilation unit for later lookup.  */
+       this_cu = obstack_alloc (&objfile->objfile_obstack,
+@@ -5335,20 +5462,50 @@ create_all_comp_units (struct objfile *objfile)
+       memset (this_cu, 0, sizeof (*this_cu));
+       this_cu->offset = offset;
+       this_cu->length = length + initial_length_size;
++      this_cu->is_dwz = is_dwz;
+       this_cu->objfile = objfile;
+-      this_cu->info_or_types_section = &dwarf2_per_objfile->info;
++      this_cu->info_or_types_section = section;
+-      if (n_comp_units == n_allocated)
++      if (*n_comp_units == *n_allocated)
+       {
+-        n_allocated *= 2;
+-        all_comp_units = xrealloc (all_comp_units,
+-                                   n_allocated
+-                                   * sizeof (struct dwarf2_per_cu_data *));
++        *n_allocated *= 2;
++        *all_comp_units = xrealloc (*all_comp_units,
++                                    *n_allocated
++                                    * sizeof (struct dwarf2_per_cu_data *));
+       }
+-      all_comp_units[n_comp_units++] = this_cu;
++      (*all_comp_units)[*n_comp_units] = this_cu;
++      ++*n_comp_units;
+       info_ptr = info_ptr + this_cu->length;
+     }
 +}
 +
++/* Create a list of all compilation units in OBJFILE.
++   This is only done for -readnow and building partial symtabs.  */
++
 +static void
-+dw2_forget_cached_source_info (struct objfile *objfile)
++create_all_comp_units (struct objfile *objfile)
 +{
-+  int i;
-+
-+  dw2_setup (objfile);
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+    {
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
++  int n_allocated;
++  int n_comp_units;
++  struct dwarf2_per_cu_data **all_comp_units;
 +
-+      if (cu->v.quick->full_names)
-+      {
-+        int j;
-+
-+        for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
-+          xfree ((void *) cu->v.quick->full_names[j]);
-+      }
-+    }
-+}
++  n_comp_units = 0;
++  n_allocated = 10;
++  all_comp_units = xmalloc (n_allocated
++                          * sizeof (struct dwarf2_per_cu_data *));
 +
-+static int
-+dw2_lookup_symtab (struct objfile *objfile, const char *name,
-+                 const char *full_path, const char *real_path,
-+                 struct symtab **result)
-+{
-+  int i;
-+  int check_basename = lbasename (name) == name;
-+  struct dwarf2_per_cu_data *base_cu = NULL;
++  read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0,
++                              &n_allocated, &n_comp_units, &all_comp_units);
 +
-+  dw2_setup (objfile);
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
++  if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
 +    {
-+      int j;
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+      if (cu->v.quick->symtab)
-+      continue;
-+
-+      dw2_require_line_header (objfile, cu);
-+      if (!cu->v.quick->lines)
-+      continue;
-+
-+      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
-+      {
-+        const char *this_name = cu->v.quick->file_names[j];
-+
-+        if (FILENAME_CMP (name, this_name) == 0)
-+          {
-+            *result = dw2_instantiate_symtab (objfile, cu);
-+            return 1;
-+          }
-+
-+        if (check_basename && ! base_cu
-+            && FILENAME_CMP (lbasename (this_name), name) == 0)
-+          base_cu = cu;
-+
-+        if (full_path != NULL)
-+          {
-+            const char *this_full_name = dw2_require_full_path (objfile,
-+                                                                cu, j);
-+
-+            if (this_full_name
-+                && FILENAME_CMP (full_path, this_full_name) == 0)
-+              {
-+                *result = dw2_instantiate_symtab (objfile, cu);
-+                return 1;
-+              }
-+          }
++      struct dwz_file *dwz = dwarf2_get_dwz_file ();
 +
-+        if (real_path != NULL)
-+          {
-+            const char *this_full_name = dw2_require_full_path (objfile,
-+                                                                cu, j);
-+
-+            if (this_full_name != NULL)
-+              {
-+                char *rp = gdb_realpath (this_full_name);
-+                if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
-+                  {
-+                    xfree (rp);
-+                    *result = dw2_instantiate_symtab (objfile, cu);
-+                    return 1;
-+                  }
-+                xfree (rp);
-+              }
-+          }
-+      }
-+    }
-+
-+  if (base_cu)
-+    {
-+      *result = dw2_instantiate_symtab (objfile, base_cu);
-+      return 1;
++      read_comp_units_from_section (objfile, &dwz->info, 1,
++                                  &n_allocated, &n_comp_units,
++                                  &all_comp_units);
 +    }
+   dwarf2_per_objfile->all_comp_units
+     = obstack_alloc (&objfile->objfile_obstack,
+@@ -5441,6 +5598,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
+                 }
+               per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset,
++                                                         pdi->is_dwz,
+                                                          cu->objfile);
+               /* Go read the partial unit, if needed.  */
+@@ -5498,7 +5656,8 @@ partial_die_parent_scope (struct partial_die_info *pdi,
+   real_pdi = pdi;
+   while (real_pdi->has_specification)
+-    real_pdi = find_partial_die (real_pdi->spec_offset, cu);
++    real_pdi = find_partial_die (real_pdi->spec_offset,
++                               real_pdi->spec_is_dwz, cu);
+   parent = real_pdi->die_parent;
+   if (parent == NULL)
+@@ -5998,6 +6157,9 @@ skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
+         else
+           info_ptr += cu->header.offset_size;
+         break;
++      case DW_FORM_GNU_ref_alt:
++        info_ptr += cu->header.offset_size;
++        break;
+       case DW_FORM_addr:
+         info_ptr += cu->header.addr_size;
+         break;
+@@ -6027,6 +6189,7 @@ skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
+         break;
+       case DW_FORM_sec_offset:
+       case DW_FORM_strp:
++      case DW_FORM_GNU_strp_alt:
+         info_ptr += cu->header.offset_size;
+         break;
+       case DW_FORM_exprloc:
+@@ -6694,7 +6857,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
+      it, by scanning the DIE's below the compilation unit.  */
+   get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
+-  static_block = end_symtab_get_static_block (highpc + baseaddr, objfile, 0);
++  static_block
++    = end_symtab_get_static_block (highpc + baseaddr, objfile, 0,
++                                 per_cu->s.imported_symtabs != NULL);
+   /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
+      Also, DW_AT_ranges may record ranges not belonging to any child DIEs
+@@ -6845,9 +7010,11 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
+       struct dwarf2_per_cu_data *per_cu;
+       struct symtab *imported_symtab;
+       sect_offset offset;
++      int is_dwz;
+       offset = dwarf2_get_ref_die_offset (attr);
+-      per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
++      is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
++      per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile);
+       /* Queue the unit, if needed.  */
+       if (maybe_queue_comp_unit (cu, per_cu, cu->language))
+@@ -8116,24 +8283,21 @@ try_open_dwo_file (const char *file_name)
+   if (desc < 0)
+     return NULL;
+-  sym_bfd = bfd_fopen (absolute_name, gnutarget, FOPEN_RB, desc);
++  sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
+   if (!sym_bfd)
+     {
+       xfree (absolute_name);
+       return NULL;
+     }
++  xfree (absolute_name);
+   bfd_set_cacheable (sym_bfd, 1);
+   if (!bfd_check_format (sym_bfd, bfd_object))
+     {
+-      bfd_close (sym_bfd); /* This also closes desc.  */
+-      xfree (absolute_name);
++      gdb_bfd_unref (sym_bfd); /* This also closes desc.  */
+       return NULL;
+     }
+-  /* bfd_usrdata exists for applications and libbfd must not touch it.  */
+-  gdb_assert (bfd_usrdata (sym_bfd) == NULL);
+-
+   return sym_bfd;
+ }
+@@ -8325,20 +8489,7 @@ free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
+   struct dwarf2_section_info *section;
+   gdb_assert (dwo_file->dwo_bfd != objfile->obfd);
+-  bfd_close (dwo_file->dwo_bfd);
+-
+-  munmap_section_buffer (&dwo_file->sections.abbrev);
+-  munmap_section_buffer (&dwo_file->sections.info);
+-  munmap_section_buffer (&dwo_file->sections.line);
+-  munmap_section_buffer (&dwo_file->sections.loc);
+-  munmap_section_buffer (&dwo_file->sections.str);
+-  munmap_section_buffer (&dwo_file->sections.str_offsets);
+-
+-  for (ix = 0;
+-       VEC_iterate (dwarf2_section_info_def, dwo_file->sections.types,
+-                  ix, section);
+-       ++ix)
+-    munmap_section_buffer (section);
++  gdb_bfd_unref (dwo_file->dwo_bfd);
+   VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
+ }
+@@ -10721,6 +10872,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
+   new_symbol (die, this_type, cu);
+ }
++/* Create a new array dimension referencing its target type TYPE.
 +
-+  return 0;
-+}
++   Multidimensional arrays are internally represented as a stack of
++   singledimensional arrays being referenced by their TYPE_TARGET_TYPE.  */
 +
-+static struct symtab *
-+dw2_lookup_symbol (struct objfile *objfile, int block_index,
-+                 const char *name, domain_enum domain)
++static struct type *
++create_single_array_dimension (struct type *type, struct type *range_type,
++                             struct die_info *die, struct dwarf2_cu *cu)
 +{
-+  /* We do all the work in the pre_expand_symtabs_matching hook
-+     instead.  */
-+  return NULL;
-+}
++  type = create_array_type (NULL, type, range_type);
 +
-+/* A helper function that expands all symtabs that hold an object
-+   named NAME.  */
-+static void
-+dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
-+{
-+  dw2_setup (objfile);
++  /* These generic type attributes need to be fetched by
++     evaluate_subexp_standard <multi_f77_subscript>'s call of
++     value_subscripted_rvalue only for the innermost array type.  */
++  fetch_die_type_attrs (die, type, cu);
 +
-+  if (dwarf2_per_objfile->index_table)
-+    {
-+      offset_type *vec;
++  /* These generic type attributes are checked for allocated/associated
++     validity while accessing FIELD_LOC_KIND_DWARF_BLOCK.  */
++  fetch_die_type_attrs (die, range_type, cu);
 +
-+      if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
-+                                  name, &vec))
-+      {
-+        offset_type i, len = MAYBE_SWAP (*vec);
-+        for (i = 0; i < len; ++i)
-+          {
-+            offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
-+            struct dwarf2_per_cu_data *cu;
-+            cu = dwarf2_per_objfile->all_comp_units[cu_index];
-+            dw2_instantiate_symtab (objfile, cu);
-+          }
-+      }
-+    }
-+}
-+
-+static void
-+dw2_pre_expand_symtabs_matching (struct objfile *objfile,
-+                               int kind, const char *name,
-+                               domain_enum domain)
-+{
-+  dw2_do_expand_symtabs_matching (objfile, name);
-+}
-+
-+static void
-+dw2_print_stats (struct objfile *objfile)
-+{
-+  int i, count;
-+
-+  dw2_setup (objfile);
-+  count = 0;
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+    {
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+      if (!cu->v.quick->symtab)
-+      ++count;
-+    }
-+  printf_filtered (_("  Number of unread CUs: %d\n"), count);
-+}
-+
-+static void
-+dw2_dump (struct objfile *objfile)
-+{
-+  /* Nothing worth printing.  */
-+}
-+
-+static void
-+dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
-+            struct section_offsets *delta)
-+{
-+  /* There's nothing to relocate here.  */
-+}
-+
-+static void
-+dw2_expand_symtabs_for_function (struct objfile *objfile,
-+                               const char *func_name)
-+{
-+  dw2_do_expand_symtabs_matching (objfile, func_name);
-+}
-+
-+static void
-+dw2_expand_all_symtabs (struct objfile *objfile)
-+{
-+  int i;
-+
-+  dw2_setup (objfile);
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+    {
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+      dw2_instantiate_symtab (objfile, cu);
-+    }
++  return type;
 +}
 +
-+static void
-+dw2_expand_symtabs_with_filename (struct objfile *objfile,
-+                                const char *filename)
-+{
-+  int i;
-+
-+  dw2_setup (objfile);
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+    {
-+      int j;
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
+ /* Extract all information from a DW_TAG_array_type DIE and put it in
+    the DIE's type field.  For now, this only handles one dimensional
+    arrays.  */
+@@ -10734,7 +10908,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
+   struct type *element_type, *range_type, *index_type;
+   struct type **range_types = NULL;
+   struct attribute *attr;
+-  int ndim = 0;
++  int ndim = 0, i;
+   struct cleanup *back_to;
+   char *name;
+@@ -10787,17 +10961,19 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
+   type = element_type;
+   if (read_array_order (die, cu) == DW_ORD_col_major)
+-    {
+-      int i = 0;
+-
+-      while (i < ndim)
+-      type = create_array_type (NULL, type, range_types[i++]);
+-    }
+-  else
+-    {
+-      while (ndim-- > 0)
+-      type = create_array_type (NULL, type, range_types[ndim]);
+-    }
++    for (i = 0; i < ndim; i++)
++      type = create_single_array_dimension (type, range_types[i], die, cu);
++  else /* (read_array_order (die, cu) == DW_ORD_row_major) */
++    for (i = ndim - 1; i >= 0; i--)
++      type = create_single_array_dimension (type, range_types[i], die, cu);
 +
-+      if (cu->v.quick->symtab)
-+      continue;
++  /* Data locations should be set only for the outermost dimension as they
++     would be confusing for the dereferenced offset on the inner ones.  */
++  attr = dwarf2_attr (die, DW_AT_data_location, cu);
++  if (attr_form_is_block (attr))
++    TYPE_DATA_LOCATION_DWARF_BLOCK (type)
++      = dwarf2_attr_to_locexpr_baton (attr, cu);
++  gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
+   /* Understand Dwarf2 support for vector types (like they occur on
+      the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
+@@ -11281,29 +11457,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
+   struct gdbarch *gdbarch = get_objfile_arch (objfile);
+   struct type *type, *range_type, *index_type, *char_type;
+   struct attribute *attr;
+-  unsigned int length;
++  int length;
 +
-+      dw2_require_line_header (objfile, cu);
-+      if (!cu->v.quick->lines)
-+      continue;
++  index_type = objfile_type (objfile)->builtin_int;
++  /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type.  */
++  range_type = alloc_type (objfile);
++  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
++  range_type = create_range_type (range_type, index_type, 0, -1);
 +
-+      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
++  /* C/C++ should probably have the low bound 0 but C/C++ does not use
++     DW_TAG_string_type.  */
++  TYPE_LOW_BOUND (range_type) = 1;
+   attr = dwarf2_attr (die, DW_AT_string_length, cu);
+-  if (attr)
++  if (attr && attr_form_is_block (attr))
+     {
+-      length = DW_UNSND (attr);
++      /* Security check for a size overflow.  */
++      if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
++      TYPE_HIGH_BOUND (range_type) = 1;
++      /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
++       instruction as DW_AT_string_length specifies the length location, not
++       its value.  */
++      else
 +      {
-+        const char *this_name = cu->v.quick->file_names[j];
-+        if (strcmp (this_name, filename) == 0)
-+          {
-+            dw2_instantiate_symtab (objfile, cu);
-+            break;
-+          }
-+      }
-+    }
-+}
-+
-+static const char *
-+dw2_find_symbol_file (struct objfile *objfile, const char *name)
-+{
-+  struct dwarf2_per_cu_data *cu;
-+  offset_type *vec;
-+
-+  dw2_setup (objfile);
-+
-+  if (!dwarf2_per_objfile->index_table)
-+    return NULL;
-+
-+  if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
-+                               name, &vec))
-+    return NULL;
-+
-+  /* Note that this just looks at the very first one named NAME -- but
-+     actually we are looking for a function.  find_main_filename
-+     should be rewritten so that it doesn't require a custom hook.  It
-+     could just use the ordinary symbol tables.  */
-+  /* vec[0] is the length, which must always be >0.  */
-+  cu = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[1])];
-+
-+  dw2_require_line_header (objfile, cu);
-+  if (!cu->v.quick->lines)
-+    return NULL;
-+
-+  return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1];
-+}
-+
-+static void
-+dw2_map_ada_symtabs (struct objfile *objfile,
-+                   int (*wild_match) (const char *, int, const char *),
-+                   int (*is_name_suffix) (const char *),
-+                   void (*callback) (struct objfile *,
-+                                     struct symtab *, void *),
-+                   const char *name, int global,
-+                   domain_enum namespace, int wild,
-+                   void *data)
-+{
-+  /* For now, we don't support Ada, so this function can't be
-+     reached.  */
-+  internal_error (__FILE__, __LINE__,
-+                _("map_ada_symtabs called via index method"));
-+}
-+
-+static void
-+dw2_expand_symtabs_matching (struct objfile *objfile,
-+                           int (*file_matcher) (const char *, void *),
-+                           int (*name_matcher) (const char *, void *),
-+                           domain_enum kind,
-+                           void *data)
-+{
-+  int i;
-+  offset_type iter;
-+
-+  dw2_setup (objfile);
-+  if (!dwarf2_per_objfile->index_table)
-+    return;
-+
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+    {
-+      int j;
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+      cu->v.quick->mark = 0;
-+      if (cu->v.quick->symtab)
-+      continue;
++        struct dwarf2_locexpr_baton *length_baton = NULL;
++        struct dwarf_block *blk = DW_BLOCK (attr);
 +
-+      dw2_require_line_header (objfile, cu);
-+      if (!cu->v.quick->lines)
-+      continue;
++        /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
++           DW_OP_deref* in such case.  */
 +
-+      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
-+      {
-+        if (file_matcher (cu->v.quick->file_names[j], data))
++        if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
++            && blk->data[0] <= DW_OP_reg31)
++          length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
++        else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
 +          {
-+            cu->v.quick->mark = 1;
-+            break;
-+          }
-+      }
-+    }
++            ULONGEST ulongest;
++            const gdb_byte *end;
 +
-+  for (iter = 0;
-+       iter < dwarf2_per_objfile->index_table->index_table_slots;
-+       ++iter)
-+    {
-+      offset_type idx = 2 * iter;
-+      const char *name;
-+      offset_type *vec, vec_len, vec_idx;
++            end = safe_read_uleb128 (&blk->data[1], &blk->data[blk->size],
++                                     &ulongest);
++            if (end == &blk->data[blk->size])
++              length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
++          }
 +
-+      if (dwarf2_per_objfile->index_table->index_table[idx] == 0
-+        && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
-+      continue;
++        if (length_baton == NULL)
++          {
++            struct attribute *size_attr;
++            gdb_byte *data;
 +
-+      name = (dwarf2_per_objfile->index_table->constant_pool
-+            + dwarf2_per_objfile->index_table->index_table[idx]);
++            length_baton = obstack_alloc (&cu->comp_unit_obstack,
++                                          sizeof (*length_baton));
++            length_baton->per_cu = cu->per_cu;
++            length_baton->size = DW_BLOCK (attr)->size + 2;
++            data = obstack_alloc (&cu->comp_unit_obstack,
++                                  length_baton->size);
++            length_baton->data = data;
++            memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
 +
-+      if (! (*name_matcher) (name, data))
-+      continue;
++            /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
++               specifies the size of an integer to fetch.  */
++            size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
++            if (size_attr)
++              {
++                data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
++                data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr);
++                if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr))
++                  complaint (&symfile_complaints,
++                             _("DW_AT_string_length's DW_AT_byte_size "
++                               "integer exceeds the byte size storage"));
++              }
++            else
++              {
++                data[DW_BLOCK (attr)->size] = DW_OP_deref;
++                data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
++              }
++          }
 +
-+      /* The name was matched, now expand corresponding CUs that were
-+       marked.  */
-+      vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool
-+                           + dwarf2_per_objfile->index_table->index_table[idx + 1]);
-+      vec_len = MAYBE_SWAP (vec[0]);
-+      for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
-+      {
-+        struct dwarf2_per_cu_data *cu
-+          = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[vec_idx + 1])];
-+        if (cu->v.quick->mark)
-+          dw2_instantiate_symtab (objfile, cu);
++        TYPE_RANGE_DATA (range_type)->high.kind
++          = RANGE_BOUND_KIND_DWARF_BLOCK;
++        TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton;
++        TYPE_DYNAMIC (range_type) = 1;
 +      }
-+    }
-+}
-+
-+static struct symtab *
-+dw2_find_pc_sect_symtab (struct objfile *objfile,
-+                       struct minimal_symbol *msymbol,
-+                       CORE_ADDR pc,
-+                       struct obj_section *section,
-+                       int warn_if_readin)
-+{
-+  struct dwarf2_per_cu_data *data;
-+
-+  dw2_setup (objfile);
-+
-+  if (!objfile->psymtabs_addrmap)
-+    return NULL;
-+
-+  data = addrmap_find (objfile->psymtabs_addrmap, pc);
-+  if (!data)
-+    return NULL;
-+
-+  if (warn_if_readin && data->v.quick->symtab)
-+    warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"),
-+           paddress (get_objfile_arch (objfile), pc));
-+
-+  return dw2_instantiate_symtab (objfile, data);
-+}
-+
-+static void
-+dw2_map_symbol_names (struct objfile *objfile,
-+                    void (*fun) (const char *, void *),
-+                    void *data)
-+{
-+  offset_type iter;
-+  dw2_setup (objfile);
--  if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
-+  if (!dwarf2_per_objfile->index_table)
-+    return;
-+
-+  for (iter = 0;
-+       iter < dwarf2_per_objfile->index_table->index_table_slots;
-+       ++iter)
-     {
--      off_t pg_offset = sectp->filepos & ~(pagesize - 1);
--      size_t map_length = info->size + sectp->filepos - pg_offset;
--      caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ,
--                               MAP_PRIVATE, pg_offset);
-+      offset_type idx = 2 * iter;
-+      const char *name;
-+      offset_type *vec, vec_len, vec_idx;
--      if (retbuf != MAP_FAILED)
--      {
--        info->was_mmapped = 1;
--        info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ;
--#if HAVE_POSIX_MADVISE
--        posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED);
--#endif
--        return;
--      }
-+      if (dwarf2_per_objfile->index_table->index_table[idx] == 0
-+        && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0)
-+      continue;
-+
-+      name = (dwarf2_per_objfile->index_table->constant_pool
-+            + dwarf2_per_objfile->index_table->index_table[idx]);
-+
-+      (*fun) (name, data);
      }
--#endif
-+}
--  /* If we get here, we are a normal, not-compressed section.  */
--  info->buffer = buf
--    = obstack_alloc (&objfile->objfile_obstack, info->size);
-+static void
-+dw2_map_symbol_filenames (struct objfile *objfile,
-+                        void (*fun) (const char *, const char *, void *),
-+                        void *data)
-+{
-+  int i;
--  /* When debugging .o files, we may need to apply relocations; see
--     http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
--     We never compress sections in .o files, so we only need to
--     try this when the section is not compressed.  */
--  retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
--  if (retbuf != NULL)
-+  dw2_setup (objfile);
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
+   else
      {
--      info->buffer = retbuf;
--      return;
-+      int j;
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+      if (cu->v.quick->symtab)
-+      continue;
-+
-+      dw2_require_line_header (objfile, cu);
-+      if (!cu->v.quick->lines)
-+      continue;
+-      /* Check for the DW_AT_byte_size attribute.  */
++      if (attr && attr_form_is_constant (attr))
++      {
++        /* We currently do not support a constant address where the location
++           should be read from - attr_form_is_block is expected instead.  See
++           DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
++           */
++        /* PASSTHRU */
++      }
 +
-+      for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
+       attr = dwarf2_attr (die, DW_AT_byte_size, cu);
+-      if (attr)
+-        {
+-          length = DW_UNSND (attr);
+-        }
++      if (attr && attr_form_is_block (attr))
 +      {
-+        const char *this_full_name = dw2_require_full_path (objfile, cu, j);
-+        (*fun) (cu->v.quick->file_names[j], this_full_name, data);
++        TYPE_RANGE_DATA (range_type)->high.kind
++          = RANGE_BOUND_KIND_DWARF_BLOCK;
++        TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
++                                      dwarf2_attr_to_locexpr_baton (attr, cu);
++        TYPE_DYNAMIC (range_type) = 1;
 +      }
++      else if (attr && attr_form_is_constant (attr))
++      TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
+       else
+-        {
+-          length = 1;
+-        }
++      TYPE_HIGH_BOUND (range_type) = 1;
      }
-+}
--  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
--      || bfd_bread (buf, info->size, abfd) != info->size)
--    error (_("Dwarf Error: Can't read DWARF data from '%s'"),
--         bfd_get_filename (abfd));
-+static int
-+dw2_has_symbols (struct objfile *objfile)
-+{
-+  return 1;
- }
--/* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
--   SECTION_NAME. */
-+const struct quick_symbol_functions dwarf2_gdb_index_functions =
-+{
-+  dw2_has_symbols,
-+  dw2_find_last_source_symtab,
-+  dw2_forget_cached_source_info,
-+  dw2_lookup_symtab,
-+  dw2_lookup_symbol,
-+  dw2_pre_expand_symtabs_matching,
-+  dw2_print_stats,
-+  dw2_dump,
-+  dw2_relocate,
-+  dw2_expand_symtabs_for_function,
-+  dw2_expand_all_symtabs,
-+  dw2_expand_symtabs_with_filename,
-+  dw2_find_symbol_file,
-+  dw2_map_ada_symtabs,
-+  dw2_expand_symtabs_matching,
-+  dw2_find_pc_sect_symtab,
-+  dw2_map_symbol_names,
-+  dw2_map_symbol_filenames
-+};
--void
--dwarf2_get_section_info (struct objfile *objfile, const char *section_name,
--                         asection **sectp, gdb_byte **bufp,
--                         bfd_size_type *sizep)
--{
--  struct dwarf2_per_objfile *data
--    = objfile_data (objfile, dwarf2_objfile_data_key);
--  struct dwarf2_section_info *info;
-+/* Initialize for reading DWARF for this objfile.  Return 0 if this
-+   file will use psymtabs, or 1 if using the GNU index.  */
--  /* We may see an objfile without any DWARF, in which case we just
--     return nothing.  */
--  if (data == NULL)
-+int
-+dwarf2_initialize_objfile (struct objfile *objfile)
-+{
-+  /* If we're about to read full symbols, don't bother with the
-+     indices.  In this case we also don't care if some other debug
-+     format is making psymtabs, because they are all about to be
-+     expanded anyway.  */
-+  if ((objfile->flags & OBJF_READNOW))
-     {
--      *sectp = NULL;
--      *bufp = NULL;
--      *sizep = 0;
--      return;
-+      int i;
-+
-+      dwarf2_per_objfile->using_index = 1;
-+      create_all_comp_units (objfile);
-+
-+      for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+      {
-+        struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+        cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-+                                      struct dwarf2_per_cu_quick_data);
-+      }
-+
-+      /* Return 1 so that gdb sees the "quick" functions.  However,
-+       these functions will be no-ops because we will have expanded
-+       all symtabs.  */
-+      return 1;
-     }
--  if (section_is_p (section_name, EH_FRAME_SECTION))
--    info = &data->eh_frame;
--  else if (section_is_p (section_name, FRAME_SECTION))
--    info = &data->frame;
--  else
--    gdb_assert (0);
  
--  if (info->asection != NULL && info->size != 0 && info->buffer == NULL)
--    /* We haven't read this section in yet.  Do it now.  */
--    dwarf2_read_section (objfile, info);
-+  if (dwarf2_read_index (objfile))
-+    return 1;
--  *sectp = info->asection;
--  *bufp = info->buffer;
--  *sizep = info->size;
-+  dwarf2_build_psymtabs (objfile);
-+  return 0;
- }
-+\f
-+
- /* Build a partial symbol table.  */
- void
-@@ -1699,6 +2688,7 @@ create_debug_types_hash_table (struct objfile *objfile)
-       type_sig->signature = signature;
-       type_sig->offset = offset;
-       type_sig->type_offset = type_offset;
-+      type_sig->per_cu.objfile = objfile;
-       slot = htab_find_slot (types_htab, type_sig, INSERT);
-       gdb_assert (slot != NULL);
-@@ -1897,7 +2887,7 @@ process_psymtab_comp_unit (struct objfile *objfile,
-   /* Store the function that reads in the rest of the symbol table */
-   pst->read_symtab = dwarf2_psymtab_to_symtab;
--  this_cu->psymtab = pst;
-+  this_cu->v.psymtab = pst;
-   dwarf2_find_base_address (comp_unit_die, &cu);
-@@ -2182,6 +3172,7 @@ create_all_comp_units (struct objfile *objfile)
-       memset (this_cu, 0, sizeof (*this_cu));
-       this_cu->offset = offset;
-       this_cu->length = length + initial_length_size;
-+      this_cu->objfile = objfile;
+-  index_type = objfile_type (objfile)->builtin_int;
+-  range_type = create_range_type (NULL, index_type, 1, length);
+   char_type = language_string_char_type (cu->language_defn, gdbarch);
+   type = create_string_type (NULL, char_type, range_type);
  
-       if (n_comp_units == n_allocated)
-       {
-@@ -2613,7 +3604,7 @@ add_partial_subprogram (struct partial_die_info *pdi,
-             addrmap_set_empty (objfile->psymtabs_addrmap,
-                                pdi->lowpc + baseaddr,
-                                pdi->highpc - 1 + baseaddr,
--                               cu->per_cu->psymtab);
-+                               cu->per_cu->v.psymtab);
-           }
-           if (!pdi->is_declaration)
-           /* Ignore subprogram DIEs that do not have a name, they are
-@@ -2885,7 +3876,6 @@ locate_pdi_sibling (struct partial_die_info *orig_pdi,
- static void
- dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
- {
--  /* FIXME: This is barely more than a stub.  */
-   if (pst != NULL)
-     {
-       if (pst->readin)
-@@ -2958,7 +3948,9 @@ process_queue (struct objfile *objfile)
-      may load a new CU, adding it to the end of the queue.  */
-   for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
-     {
--      if (item->per_cu->psymtab && !item->per_cu->psymtab->readin)
-+      if (dwarf2_per_objfile->using_index
-+        ? !item->per_cu->v.quick->symtab
-+        : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
-       process_full_comp_unit (item->per_cu);
-       item->per_cu->queued = 0;
-@@ -3035,22 +4027,7 @@ psymtab_to_symtab_1 (struct partial_symtab *pst)
-       return;
-     }
+@@ -11607,7 +11868,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
+   struct type *base_type;
+   struct type *range_type;
+   struct attribute *attr;
+-  LONGEST low, high;
++  LONGEST low;
+   int low_default_is_valid;
+   char *name;
+   LONGEST negative_mask;
+@@ -11663,42 +11924,6 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
+                                     "- DIE at 0x%x [in module %s]"),
+              die->offset.sect_off, cu->objfile->name);
  
--  back_to = make_cleanup (dwarf2_release_queue, NULL);
--
--  queue_comp_unit (per_cu, pst->objfile);
+-  attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
+-  if (attr)
+-    {
+-      if (attr_form_is_block (attr) || is_ref_attr (attr))
+-        {
+-          /* GCC encodes arrays with unspecified or dynamic length
+-             with a DW_FORM_block1 attribute or a reference attribute.
+-             FIXME: GDB does not yet know how to handle dynamic
+-             arrays properly, treat them as arrays with unspecified
+-             length for now.
 -
--  if (per_cu->from_debug_types)
--    read_signatured_type_at_offset (pst->objfile, per_cu->offset);
+-             FIXME: jimb/2003-09-22: GDB does not really know
+-             how to handle arrays of unspecified length
+-             either; we just represent them as zero-length
+-             arrays.  Choose an appropriate upper bound given
+-             the lower bound we've computed above.  */
+-          high = low - 1;
+-        }
+-      else
+-        high = dwarf2_get_attr_constant_value (attr, 1);
+-    }
 -  else
--    load_full_comp_unit (per_cu, pst->objfile);
--
--  process_queue (pst->objfile);
--
--  /* Age the cache, releasing compilation units that have not
--     been used recently.  */
--  age_cached_comp_units ();
+-    {
+-      attr = dwarf2_attr (die, DW_AT_count, cu);
+-      if (attr)
+-      {
+-        int count = dwarf2_get_attr_constant_value (attr, 1);
+-        high = low + count - 1;
+-      }
+-      else
+-      {
+-        /* Unspecified array length.  */
+-        high = low - 1;
+-      }
+-    }
 -
--  do_cleanups (back_to);
-+  dw2_do_instantiate_symtab (pst->objfile, per_cu);
- }
- /* Load the DIEs associated with PER_CU into memory.  */
-@@ -3130,9 +4107,8 @@ load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
- static void
- process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
- {
--  struct partial_symtab *pst = per_cu->psymtab;
-   struct dwarf2_cu *cu = per_cu->cu;
--  struct objfile *objfile = pst->objfile;
-+  struct objfile *objfile = per_cu->objfile;
-   CORE_ADDR lowpc, highpc;
-   struct symtab *symtab;
-   struct cleanup *back_to;
-@@ -3165,8 +4141,15 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
-     {
-       symtab->language = cu->language;
+   /* Dwarf-2 specifications explicitly allows to create subrange types
+      without specifying a base type.
+      In that case, the base type must be set to the type of
+@@ -11737,24 +11962,163 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
+       }
      }
--  pst->symtab = symtab;
--  pst->readin = 1;
+-  negative_mask =
++  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
++  range_type = create_range_type (NULL, base_type, 0, -1);
++  TYPE_UNSIGNED (range_type) = 0;
 +
-+  if (dwarf2_per_objfile->using_index)
-+    per_cu->v.quick->symtab = symtab;
-+  else
++  negative_mask = 
+     (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
+-  if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
+-    low |= negative_mask;
+-  if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
+-    high |= negative_mask;
+-  range_type = create_range_type (NULL, base_type, low, high);
++  /* Exclude language_ada from any TYPE_DYNAMIC constructs below.  GDB Ada
++     supports implements the dynamic bounds in a non-DWARF way and the
++     existing DWARF dynamic bounds are invalid, leading to memory access
++     errors.  */
+-  /* Mark arrays with dynamic length at least as an array of unspecified
+-     length.  GDB could check the boundary but before it gets implemented at
+-     least allow accessing the array elements.  */
+-  if (attr && attr_form_is_block (attr))
+-    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
++  attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
++  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
 +    {
-+      struct partial_symtab *pst = per_cu->v.psymtab;
-+      pst->symtab = symtab;
-+      pst->readin = 1;
++      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
++      TYPE_RANGE_DATA (range_type)->low.u.dwarf_block =
++                                      dwarf2_attr_to_locexpr_baton (attr, cu);
++      TYPE_DYNAMIC (range_type) = 1;
++      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
++      low = 0;
 +    }
++  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
++    {
++      struct die_info *target_die;
++      struct dwarf2_cu *target_cu = cu;
++      struct attribute *target_loc_attr;
  
-   do_cleanups (back_to);
- }
-@@ -3557,6 +4540,46 @@ free_cu_line_header (void *arg)
- }
- static void
-+find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
-+                       char **name, char **comp_dir)
-+{
-+  struct attribute *attr;
-+
-+  *name = NULL;
-+  *comp_dir = NULL;
+-  /* Ada expects an empty array on no boundary attributes.  */
+-  if (attr == NULL && cu->language != language_ada)
+-    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
++      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
++      gdb_assert (target_cu->objfile == cu->objfile);
++      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
 +
-+  /* Find the filename.  Do not use dwarf2_name here, since the filename
-+     is not a source language identifier.  */
-+  attr = dwarf2_attr (die, DW_AT_name, cu);
-+  if (attr)
++      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
++      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist
++        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
++      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type
++        = die_type (target_die, target_cu);
++      TYPE_DYNAMIC (range_type) = 1;
++      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
++      low = 0;
++    }
++  else
 +    {
-+      *name = DW_STRING (attr);
++      if (attr && attr_form_is_constant (attr))
++      low = dwarf2_get_attr_constant_value (attr, 0);
++      else
++      {
++        if (cu->language == language_fortran)
++          {
++            /* FORTRAN implies a lower bound of 1, if not given.  */
++            low = 1;
++          }
++        else
++          {
++            /* According to DWARF we should assume the value 0 only for
++               LANGUAGE_C and LANGUAGE_CPLUS.  */
++            low = 0;
++          }
++      }
++      if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
++      low |= negative_mask;
++      TYPE_LOW_BOUND (range_type) = low;
++      if (low >= 0)
++      TYPE_UNSIGNED (range_type) = 1;
 +    }
 +
-+  attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
-+  if (attr)
-+    *comp_dir = DW_STRING (attr);
-+  else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
++  attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
++  if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
++              && !is_ref_attr (attr)))
 +    {
-+      *comp_dir = ldirname (*name);
-+      if (*comp_dir != NULL)
-+      make_cleanup (xfree, *comp_dir);
++      attr = dwarf2_attr (die, DW_AT_count, cu);
++      /* It does not hurt but it is needlessly ineffective in check_typedef.  */
++      if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
++              {
++        TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
++        TYPE_DYNAMIC (range_type) = 1;
++      }
++      /* Pass it now as the regular DW_AT_upper_bound.  */
 +    }
-+  if (*comp_dir != NULL)
-+    {
-+      /* Irix 6.2 native cc prepends <machine>.: to the compilation
-+       directory, get rid of it.  */
-+      char *cp = strchr (*comp_dir, ':');
 +
-+      if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
-+      *comp_dir = cp + 1;
++  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
++    {
++      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
++      TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
++                                      dwarf2_attr_to_locexpr_baton (attr, cu);
++      TYPE_DYNAMIC (range_type) = 1;
 +    }
++  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
++    {
++      struct die_info *target_die;
++      struct dwarf2_cu *target_cu = cu;
++      struct attribute *target_loc_attr;
 +
-+  if (*name == NULL)
-+    *name = "<unknown>";
-+}
-+
-+static void
- read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
- {
-   struct objfile *objfile = cu->objfile;
-@@ -3582,35 +4605,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
-   lowpc += baseaddr;
-   highpc += baseaddr;
--  /* Find the filename.  Do not use dwarf2_name here, since the filename
--     is not a source language identifier.  */
--  attr = dwarf2_attr (die, DW_AT_name, cu);
--  if (attr)
--    {
--      name = DW_STRING (attr);
--    }
--
--  attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
--  if (attr)
--    comp_dir = DW_STRING (attr);
--  else if (name != NULL && IS_ABSOLUTE_PATH (name))
--    {
--      comp_dir = ldirname (name);
--      if (comp_dir != NULL)
--      make_cleanup (xfree, comp_dir);
--    }
--  if (comp_dir != NULL)
--    {
--      /* Irix 6.2 native cc prepends <machine>.: to the compilation
--       directory, get rid of it.  */
--      char *cp = strchr (comp_dir, ':');
--
--      if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
--      comp_dir = cp + 1;
--    }
--
--  if (name == NULL)
--    name = "<unknown>";
-+  find_file_and_directory (die, cu, &name, &comp_dir);
-   attr = dwarf2_attr (die, DW_AT_language, cu);
-   if (attr)
-@@ -5529,6 +6524,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
-   new_symbol (die, this_type, cu);
- }
-+/* Create a new array dimension referencing its target type TYPE.
++      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
++      gdb_assert (target_cu->objfile == cu->objfile);
++      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
 +
-+   Multidimensional arrays are internally represented as a stack of
-+   singledimensional arrays being referenced by their TYPE_TARGET_TYPE.  */
++      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
++      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist
++        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
++      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type
++        = die_type (target_die, target_cu);
++      TYPE_DYNAMIC (range_type) = 1;
++    }
++  else
++    {
++      LONGEST high;
 +
-+static struct type *
-+create_single_array_dimension (struct type *type, struct type *range_type,
-+                             struct die_info *die, struct dwarf2_cu *cu)
-+{
-+  type = create_array_type (NULL, type, range_type);
++      if (attr && attr_form_is_constant (attr))
++      high = dwarf2_get_attr_constant_value (attr, 0);
++      else
++      {
++        /* Ada expects an empty array on no boundary attributes.  */
++        if (cu->language != language_ada)
++          TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
++        high = low - 1;
++      }
++      if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
++      high |= negative_mask;
++      TYPE_HIGH_BOUND (range_type) = high;
++    }
 +
-+  /* These generic type attributes need to be fetched by
-+     evaluate_subexp_standard <multi_f77_subscript>'s call of
-+     value_subscripted_rvalue only for the innermost array type.  */
-+  fetch_die_type_attrs (die, type, cu);
-+
-+  /* These generic type attributes are checked for allocated/associated
-+     validity while accessing FIELD_LOC_KIND_DWARF_BLOCK.  */
-+  fetch_die_type_attrs (die, range_type, cu);
-+
-+  return type;
-+}
-+
- /* Extract all information from a DW_TAG_array_type DIE and put it in
-    the DIE's type field.  For now, this only handles one dimensional
-    arrays.  */
-@@ -5542,7 +6560,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
-   struct type *element_type, *range_type, *index_type;
-   struct type **range_types = NULL;
-   struct attribute *attr;
--  int ndim = 0;
-+  int ndim = 0, i;
-   struct cleanup *back_to;
-   char *name;
-@@ -5595,17 +6613,11 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
-   type = element_type;
-   if (read_array_order (die, cu) == DW_ORD_col_major)
--    {
--      int i = 0;
--
--      while (i < ndim)
--      type = create_array_type (NULL, type, range_types[i++]);
--    }
--  else
--    {
--      while (ndim-- > 0)
--      type = create_array_type (NULL, type, range_types[ndim]);
--    }
-+    for (i = 0; i < ndim; i++)
-+      type = create_single_array_dimension (type, range_types[i], die, cu);
-+  else /* (read_array_order (die, cu) == DW_ORD_row_major) */
-+    for (i = ndim - 1; i >= 0; i--)
-+      type = create_single_array_dimension (type, range_types[i], die, cu);
-   /* Understand Dwarf2 support for vector types (like they occur on
-      the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
-@@ -6059,29 +7071,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
-   struct gdbarch *gdbarch = get_objfile_arch (objfile);
-   struct type *type, *range_type, *index_type, *char_type;
-   struct attribute *attr;
--  unsigned int length;
-+  int length;
-+
-+  index_type = objfile_type (objfile)->builtin_int;
-+  /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type.  */
-+  range_type = alloc_type (objfile);
-+  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
-+  range_type = create_range_type (range_type, index_type, 0, -1);
-+
-+  /* C/C++ should probably have the low bound 0 but C/C++ does not use
-+     DW_TAG_string_type.  */
-+  TYPE_LOW_BOUND (range_type) = 1;
-   attr = dwarf2_attr (die, DW_AT_string_length, cu);
--  if (attr)
--    {
--      length = DW_UNSND (attr);
-+  if (attr && attr_form_is_block (attr))
-+    {
-+      /* Security check for a size overflow.  */
-+      if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
-+      TYPE_HIGH_BOUND (range_type) = 1;
-+      /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
-+       instruction as DW_AT_string_length specifies the length location, not
-+       its value.  */
-+      else
-+      {
-+        struct dwarf2_locexpr_baton *length_baton = NULL;
-+        struct dwarf_block *blk = DW_BLOCK (attr);
-+
-+        /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
-+           DW_OP_deref* in such case.  */
-+
-+        if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
-+            && blk->data[0] <= DW_OP_reg31)
-+          length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
-+        else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
-+          {
-+            ULONGEST ulongest;
-+            const gdb_byte *end;
-+
-+            end = read_uleb128 (&blk->data[1], &blk->data[blk->size],
-+                                &ulongest);
-+            if (end == &blk->data[blk->size])
-+              length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
-+          }
-+
-+        if (length_baton == NULL)
-+          {
-+            struct attribute *size_attr;
-+            gdb_byte *data;
-+
-+            length_baton = obstack_alloc (&cu->comp_unit_obstack,
-+                                          sizeof (*length_baton));
-+            length_baton->per_cu = cu->per_cu;
-+            length_baton->size = DW_BLOCK (attr)->size + 2;
-+            data = obstack_alloc (&cu->comp_unit_obstack,
-+                                  length_baton->size);
-+            length_baton->data = data;
-+            memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
-+
-+            /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
-+               specifies the size of an integer to fetch.  */
-+            size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
-+            if (size_attr)
-+              {
-+                data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
-+                data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr);
-+                if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr))
-+                  complaint (&symfile_complaints,
-+                             _("DW_AT_string_length's DW_AT_byte_size "
-+                               "integer exceeds the byte size storage"));
-+              }
-+            else
-+              {
-+                data[DW_BLOCK (attr)->size] = DW_OP_deref;
-+                data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
-+              }
-+          }
-+
-+        TYPE_RANGE_DATA (range_type)->high.kind
-+          = RANGE_BOUND_KIND_DWARF_BLOCK;
-+        TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton;
-+        TYPE_DYNAMIC (range_type) = 1;
-+      }
-     }
-   else
-     {
--      /* check for the DW_AT_byte_size attribute */
-+      if (attr && attr_form_is_constant (attr))
-+      {
-+        /* We currently do not support a constant address where the location
-+           should be read from - attr_form_is_block is expected instead.  See
-+           DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
-+           */
-+        /* PASSTHRU */
-+      }
-+
-       attr = dwarf2_attr (die, DW_AT_byte_size, cu);
--      if (attr)
--        {
--          length = DW_UNSND (attr);
--        }
-+      if (attr && attr_form_is_block (attr))
-+      {
-+        TYPE_RANGE_DATA (range_type)->high.kind
-+          = RANGE_BOUND_KIND_DWARF_BLOCK;
-+        TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
-+                                      dwarf2_attr_to_locexpr_baton (attr, cu);
-+        TYPE_DYNAMIC (range_type) = 1;
-+      }
-+      else if (attr && attr_form_is_constant (attr))
-+      TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
-       else
--        {
--          length = 1;
--        }
-+      TYPE_HIGH_BOUND (range_type) = 1;
-     }
--  index_type = objfile_type (objfile)->builtin_int;
--  range_type = create_range_type (NULL, index_type, 1, length);
-   char_type = language_string_char_type (cu->language_defn, gdbarch);
-   type = create_string_type (NULL, char_type, range_type);
-@@ -6324,60 +7421,136 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
-   struct type *base_type;
-   struct type *range_type;
-   struct attribute *attr;
--  LONGEST low = 0;
--  LONGEST high = -1;
-+  LONGEST low;
-   char *name;
-   LONGEST negative_mask;
-   base_type = die_type (die, cu);
-+  /* Preserve BASE_TYPE's original type, just set its LENGTH.  */
-+  check_typedef (base_type);
-   /* The die_type call above may have already set the type for this DIE.  */
-   range_type = get_die_type (die, cu);
-   if (range_type)
-     return range_type;
--  if (cu->language == language_fortran)
--    {
--      /* FORTRAN implies a lower bound of 1, if not given.  */
--      low = 1;
--    }
-+  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
-+  range_type = create_range_type (NULL, base_type, 0, -1);
-+
-+  negative_mask = 
-+    (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
-+
-+  /* Exclude language_ada from any TYPE_DYNAMIC constructs below.  GDB Ada
-+     supports implements the dynamic bounds in a non-DWARF way and the
-+     existing DWARF dynamic bounds are invalid, leading to memory access
-+     errors.  */
--  /* FIXME: For variable sized arrays either of these could be
--     a variable rather than a constant value.  We'll allow it,
--     but we don't know how to handle it.  */
-   attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
--  if (attr)
--    low = dwarf2_get_attr_constant_value (attr, 0);
++  /* DW_AT_bit_stride is currently unsupported as we count in bytes.  */
++  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
 +  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
 +    {
-+      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
-+      TYPE_RANGE_DATA (range_type)->low.u.dwarf_block =
++      TYPE_RANGE_DATA (range_type)->byte_stride.kind
++        = RANGE_BOUND_KIND_DWARF_BLOCK;
++      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block =
 +                                      dwarf2_attr_to_locexpr_baton (attr, cu);
 +      TYPE_DYNAMIC (range_type) = 1;
-+      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
-+      low = 0;
 +    }
 +  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
 +    {
@@ -3898,172 +3014,232 @@ index 1e75235..d54e266 100644
 +      gdb_assert (target_cu->objfile == cu->objfile);
 +      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
 +
-+      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
-+      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist
++      TYPE_RANGE_DATA (range_type)->byte_stride.kind
++        = RANGE_BOUND_KIND_DWARF_LOCLIST;
++      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist
 +        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
-+      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type
++      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type
 +        = die_type (target_die, target_cu);
 +      TYPE_DYNAMIC (range_type) = 1;
-+      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
-+      low = 0;
 +    }
-+  else
++  else if (attr && attr_form_is_constant (attr))
 +    {
-+      if (attr && attr_form_is_constant (attr))
-+      low = dwarf2_get_attr_constant_value (attr, 0);
-+      else
-+      {
-+        if (cu->language == language_fortran)
-+          {
-+            /* FORTRAN implies a lower bound of 1, if not given.  */
-+            low = 1;
-+          }
-+        else
++      TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
++      if (TYPE_BYTE_STRIDE (range_type) == 0)
++      complaint (&symfile_complaints,
++                 _("Found DW_AT_byte_stride with unsupported value 0"));
++    }
+   name = dwarf2_name (die, cu);
+   if (name)
+@@ -12544,6 +12908,8 @@ read_partial_die (const struct die_reader_specs *reader,
+       case DW_AT_extension:
+         part_die->has_specification = 1;
+         part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
++        part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
++                                 || cu->per_cu->is_dwz);
+         break;
+       case DW_AT_sibling:
+         /* Ignore absolute siblings, they might point outside of
+@@ -12590,7 +12956,11 @@ read_partial_die (const struct die_reader_specs *reader,
+       case DW_AT_import:
+         if (part_die->tag == DW_TAG_imported_unit)
+-          part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
 +          {
-+            /* According to DWARF we should assume the value 0 only for
-+               LANGUAGE_C and LANGUAGE_CPLUS.  */
-+            low = 0;
++            part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
++            part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt
++                                || cu->per_cu->is_dwz);
 +          }
-+      }
-+      if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
-+      low |= negative_mask;
-+      TYPE_LOW_BOUND (range_type) = low;
-+      if (low >= 0)
-+      TYPE_UNSIGNED (range_type) = 1;
-+    }
+         break;
  
-   attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
--  if (attr)
-+  if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
-+              && !is_ref_attr (attr)))
+       default:
+@@ -12661,13 +13031,14 @@ find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu)
+    DW_FORM_ref_sig8).  */
+ static struct partial_die_info *
+-find_partial_die (sect_offset offset, struct dwarf2_cu *cu)
++find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu)
+ {
+   struct objfile *objfile = cu->objfile;
+   struct dwarf2_per_cu_data *per_cu = NULL;
+   struct partial_die_info *pd = NULL;
+-  if (offset_in_cu_p (&cu->header, offset))
++  if (offset_in_dwz == cu->per_cu->is_dwz
++      && offset_in_cu_p (&cu->header, offset))
      {
--      if (attr->form == DW_FORM_block1 || is_ref_attr (attr))
--        {
--          /* GCC encodes arrays with unspecified or dynamic length
--             with a DW_FORM_block1 attribute or a reference attribute.
--             FIXME: GDB does not yet know how to handle dynamic
--             arrays properly, treat them as arrays with unspecified
--             length for now.
--
--             FIXME: jimb/2003-09-22: GDB does not really know
--             how to handle arrays of unspecified length
--             either; we just represent them as zero-length
--             arrays.  Choose an appropriate upper bound given
--             the lower bound we've computed above.  */
--          high = low - 1;
--        }
--      else
--        high = dwarf2_get_attr_constant_value (attr, 1);
-+      attr = dwarf2_attr (die, DW_AT_count, cu);
-+      /* It does not hurt but it is needlessly ineffective in check_typedef.  */
-+      if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
-+              {
-+        TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
-+        TYPE_DYNAMIC (range_type) = 1;
+       pd = find_partial_die_in_comp_unit (offset, cu);
+       if (pd != NULL)
+@@ -12686,7 +13057,8 @@ find_partial_die (sect_offset offset, struct dwarf2_cu *cu)
+                (long) cu->header.offset.sect_off, (long) offset.sect_off,
+                bfd_get_filename (objfile->obfd));
+       }
+-      per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
++      per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
++                                               objfile);
+       if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
+       load_partial_comp_unit (per_cu);
+@@ -12744,7 +13116,8 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
+   real_pdi = struct_pdi;
+   while (real_pdi->has_specification)
+-    real_pdi = find_partial_die (real_pdi->spec_offset, cu);
++    real_pdi = find_partial_die (real_pdi->spec_offset,
++                               real_pdi->spec_is_dwz, cu);
+   if (real_pdi->die_parent != NULL)
+     return;
+@@ -12792,7 +13165,8 @@ fixup_partial_die (struct partial_die_info *part_die,
+     {
+       struct partial_die_info *spec_die;
+-      spec_die = find_partial_die (part_die->spec_offset, cu);
++      spec_die = find_partial_die (part_die->spec_offset,
++                                 part_die->spec_is_dwz, cu);
+       fixup_partial_die (spec_die, cu);
+@@ -12880,6 +13254,10 @@ read_attribute_value (const struct die_reader_specs *reader,
+                                      &cu->header, &bytes_read);
+       info_ptr += bytes_read;
+       break;
++    case DW_FORM_GNU_ref_alt:
++      DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
++      info_ptr += bytes_read;
++      break;
+     case DW_FORM_addr:
+       DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+       info_ptr += bytes_read;
+@@ -12922,10 +13300,25 @@ read_attribute_value (const struct die_reader_specs *reader,
+       info_ptr += bytes_read;
+       break;
+     case DW_FORM_strp:
+-      DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
+-                                             &bytes_read);
+-      DW_STRING_IS_CANONICAL (attr) = 0;
+-      info_ptr += bytes_read;
++      if (!cu->per_cu->is_dwz)
++      {
++        DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
++                                                 &bytes_read);
++        DW_STRING_IS_CANONICAL (attr) = 0;
++        info_ptr += bytes_read;
++        break;
 +      }
-+      /* Pass it now as the regular DW_AT_upper_bound.  */
-+    }
-+
-+  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
-+    {
-+      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
-+      TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
-+                                      dwarf2_attr_to_locexpr_baton (attr, cu);
-+      TYPE_DYNAMIC (range_type) = 1;
-+    }
-+  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
-+    {
-+      struct die_info *target_die;
-+      struct dwarf2_cu *target_cu = cu;
-+      struct attribute *target_loc_attr;
-+
-+      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
-+      gdb_assert (target_cu->objfile == cu->objfile);
-+      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
++      /* FALLTHROUGH */
++    case DW_FORM_GNU_strp_alt:
++      {
++      struct dwz_file *dwz = dwarf2_get_dwz_file ();
++      LONGEST str_offset = read_offset (abfd, info_ptr, cu_header,
++                                        &bytes_read);
 +
-+      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
-+      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist
-+        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
-+      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type
-+        = die_type (target_die, target_cu);
-+      TYPE_DYNAMIC (range_type) = 1;
++      DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset);
++      DW_STRING_IS_CANONICAL (attr) = 0;
++      info_ptr += bytes_read;
++      }
+       break;
+     case DW_FORM_exprloc:
+     case DW_FORM_block:
+@@ -13037,6 +13430,10 @@ read_attribute_value (const struct die_reader_specs *reader,
+            bfd_get_filename (abfd));
      }
-   else
-     {
--      attr = dwarf2_attr (die, DW_AT_count, cu);
--      if (attr)
-+      LONGEST high;
++  /* Super hack.  */
++  if (cu->per_cu->is_dwz && is_ref_attr (attr))
++    attr->form = DW_FORM_GNU_ref_alt;
 +
-+      if (attr && attr_form_is_constant (attr))
-+      high = dwarf2_get_attr_constant_value (attr, 0);
-+      else
-       {
--        int count = dwarf2_get_attr_constant_value (attr, 1);
--        high = low + count - 1;
-+        TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
-+        high = low - 1;
-       }
-+      if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
-+      high |= negative_mask;
-+      TYPE_HIGH_BOUND (range_type) = high;
-     }
+   /* We have seen instances where the compiler tried to emit a byte
+      size attribute of -1 which ended up being encoded as an unsigned
+      0xffffffff.  Although 0xffffffff is technically a valid size value,
+@@ -13333,6 +13730,30 @@ read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
+   return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
+ }
  
-   /* Dwarf-2 specifications explicitly allows to create subrange types
-@@ -6419,20 +7592,41 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
-       }
-     }
++/* Read a string at offset STR_OFFSET in the .debug_str section from
++   the .dwz file DWZ.  Throw an error if the offset is too large.  If
++   the string consists of a single NUL byte, return NULL; otherwise
++   return a pointer to the string.  */
++
++static char *
++read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset)
++{
++  dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str);
++
++  if (dwz->str.buffer == NULL)
++    error (_("DW_FORM_GNU_strp_alt used without .debug_str "
++           "section [in module %s]"),
++         bfd_get_filename (dwz->dwz_bfd));
++  if (str_offset >= dwz->str.size)
++    error (_("DW_FORM_GNU_strp_alt pointing outside of "
++           ".debug_str section [in module %s]"),
++         bfd_get_filename (dwz->dwz_bfd));
++  gdb_assert (HOST_CHAR_BIT == 8);
++  if (dwz->str.buffer[str_offset] == '\0')
++    return NULL;
++  return (char *) (dwz->str.buffer + str_offset);
++}
++
+ static char *
+ read_indirect_string (bfd *abfd, gdb_byte *buf,
+                     const struct comp_unit_head *cu_header,
+@@ -13804,6 +14225,30 @@ add_file_name (struct line_header *lh,
+   fe->symtab = NULL;
+ }
  
--  negative_mask =
--    (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
--  if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
--    low |= negative_mask;
--  if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
--    high |= negative_mask;
-+  /* DW_AT_bit_stride is currently unsupported as we count in bytes.  */
-+  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
-+  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
++/* A convenience function to find the proper .debug_line section for a
++   CU.  */
++
++static struct dwarf2_section_info *
++get_debug_line_section (struct dwarf2_cu *cu)
++{
++  struct dwarf2_section_info *section;
++
++  /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
++     DWO file.  */
++  if (cu->dwo_unit && cu->per_cu->is_debug_types)
++    section = &cu->dwo_unit->dwo_file->sections.line;
++  else if (cu->per_cu->is_dwz)
 +    {
-+      TYPE_RANGE_DATA (range_type)->byte_stride.kind
-+        = RANGE_BOUND_KIND_DWARF_BLOCK;
-+      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block =
-+                                      dwarf2_attr_to_locexpr_baton (attr, cu);
-+      TYPE_DYNAMIC (range_type) = 1;
++      struct dwz_file *dwz = dwarf2_get_dwz_file ();
++
++      section = &dwz->line;
 +    }
-+  else if (attr && is_ref_attr (attr) && cu->language != language_ada)
-+    {
-+      struct die_info *target_die;
-+      struct dwarf2_cu *target_cu = cu;
-+      struct attribute *target_loc_attr;
++  else
++    section = &dwarf2_per_objfile->line;
++
++  return section;
++}
++
+ /* Read the statement program header starting at OFFSET in
+    .debug_line, or .debug_line.dwo.  Return a pointer
+    to a struct line_header, allocated using xmalloc.
+@@ -13824,13 +14269,7 @@ dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu)
+   struct dwarf2_section_info *section;
+   bfd *abfd;
  
--  range_type = create_range_type (NULL, base_type, low, high);
-+      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
-+      gdb_assert (target_cu->objfile == cu->objfile);
-+      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
+-  /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
+-     DWO file.  */
+-  if (cu->dwo_unit && cu->per_cu->is_debug_types)
+-    section = &cu->dwo_unit->dwo_file->sections.line;
+-  else
+-    section = &dwarf2_per_objfile->line;
+-
++  section = get_debug_line_section (cu);
+   dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+   if (section->buffer == NULL)
+     {
+@@ -14155,7 +14594,7 @@ dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
+                        GCd by the linker.  Ignore it.  PR gdb/12528 */
  
--  /* Mark arrays with dynamic length at least as an array of unspecified
--     length.  GDB could check the boundary but before it gets implemented at
--     least allow accessing the array elements.  */
--  if (attr && attr->form == DW_FORM_block1)
--    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
-+      TYPE_RANGE_DATA (range_type)->byte_stride.kind
-+        = RANGE_BOUND_KIND_DWARF_LOCLIST;
-+      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist
-+        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
-+      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type
-+        = die_type (target_die, target_cu);
-+      TYPE_DYNAMIC (range_type) = 1;
-+    }
-+  else if (attr && attr_form_is_constant (attr))
-+    {
-+      TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
-+      if (TYPE_BYTE_STRIDE (range_type) == 0)
-+      complaint (&symfile_complaints,
-+                 _("Found DW_AT_byte_stride with unsupported value 0"));
-+    }
+                     long line_offset
+-                      = line_ptr - dwarf2_per_objfile->line.buffer;
++                      = line_ptr - get_debug_line_section (cu)->buffer;
  
-   name = dwarf2_name (die, cu);
-   if (name)
-@@ -8712,10 +9906,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
+                     complaint (&symfile_complaints,
+                                _(".debug_line address at offset 0x%lx is 0 "
+@@ -14534,10 +14973,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
       (i.e. when the value of a register or memory location is
       referenced, or a thread-local block, etc.).  Then again, it might
       not be worthwhile.  I'm assuming that it isn't unless performance
@@ -4075,19 +3251,44 @@ index 1e75235..d54e266 100644
 -  dwarf2_symbol_mark_computed (attr, sym, cu);
    SYMBOL_CLASS (sym) = LOC_COMPUTED;
 +  dwarf2_symbol_mark_computed (attr, sym, cu);
- }
  
- /* Given a pointer to a DWARF information entry, figure out if we need
-@@ -8746,6 +9942,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
-                                            sizeof (struct symbol));
+   if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
+     cu->has_loclist = 1;
+@@ -14578,6 +15019,8 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
+       else
+       sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
        OBJSTAT (objfile, n_syms++);
-       memset (sym, 0, sizeof (struct symbol));
 +      /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity.  */
 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
  
        /* Cache this symbol's name and the name's demangled form (if any).  */
-       SYMBOL_LANGUAGE (sym) = cu->language;
-@@ -9375,6 +10573,9 @@ read_type_die (struct die_info *die, struct dwarf2_cu *cu)
+       SYMBOL_SET_LANGUAGE (sym, cu->language);
+@@ -15001,6 +15444,7 @@ dwarf2_const_value_attr (struct attribute *attr, struct type *type,
+     case DW_FORM_string:
+     case DW_FORM_strp:
+     case DW_FORM_GNU_str_index:
++    case DW_FORM_GNU_strp_alt:
+       /* DW_STRING is already allocated on the objfile obstack, point
+        directly to it.  */
+       *bytes = (gdb_byte *) DW_STRING (attr);
+@@ -15187,7 +15631,15 @@ lookup_die_type (struct die_info *die, struct attribute *attr,
+   /* First see if we have it cached.  */
+-  if (is_ref_attr (attr))
++  if (attr->form == DW_FORM_GNU_ref_alt)
++    {
++      struct dwarf2_per_cu_data *per_cu;
++      sect_offset offset = dwarf2_get_ref_die_offset (attr);
++
++      per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile);
++      this_type = get_die_type_at_offset (offset, per_cu);
++    }
++  else if (is_ref_attr (attr))
+     {
+       sect_offset offset = dwarf2_get_ref_die_offset (attr);
+@@ -15352,6 +15804,9 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
        break;
      }
  
@@ -4097,8 +3298,214 @@ index 1e75235..d54e266 100644
    return this_type;
  }
  
-@@ -11979,67 +13180,102 @@ attr_form_is_constant (struct attribute *attr)
+@@ -15960,6 +16415,10 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
+         fprintf_unfiltered (f, "ref address: ");
+         fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
+         break;
++      case DW_FORM_GNU_ref_alt:
++        fprintf_unfiltered (f, "alt ref address: ");
++        fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
++        break;
+       case DW_FORM_ref1:
+       case DW_FORM_ref2:
+       case DW_FORM_ref4:
+@@ -15991,6 +16450,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
+       case DW_FORM_string:
+       case DW_FORM_strp:
+       case DW_FORM_GNU_str_index:
++      case DW_FORM_GNU_strp_alt:
+         fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
+                  DW_STRING (&die->attrs[i])
+                  ? DW_STRING (&die->attrs[i]) : "",
+@@ -16094,6 +16554,7 @@ is_ref_attr (struct attribute *attr)
+     case DW_FORM_ref4:
+     case DW_FORM_ref8:
+     case DW_FORM_ref_udata:
++    case DW_FORM_GNU_ref_alt:
+       return 1;
+     default:
+       return 0;
+@@ -16171,7 +16632,8 @@ follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
+    Returns NULL if OFFSET is invalid.  */
+ static struct die_info *
+-follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu)
++follow_die_offset (sect_offset offset, int offset_in_dwz,
++                 struct dwarf2_cu **ref_cu)
+ {
+   struct die_info temp_die;
+   struct dwarf2_cu *target_cu, *cu = *ref_cu;
+@@ -16188,11 +16650,13 @@ follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu)
+       if (! offset_in_cu_p (&cu->header, offset))
+       return NULL;
      }
+-  else if (! offset_in_cu_p (&cu->header, offset))
++  else if (offset_in_dwz != cu->per_cu->is_dwz
++         || ! offset_in_cu_p (&cu->header, offset))
+     {
+       struct dwarf2_per_cu_data *per_cu;
+-      per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
++      per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
++                                               cu->objfile);
+       /* If necessary, add it to the queue and load its DIEs.  */
+       if (maybe_queue_comp_unit (cu, per_cu, cu->language))
+@@ -16224,7 +16688,10 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr,
+   struct dwarf2_cu *cu = *ref_cu;
+   struct die_info *die;
+-  die = follow_die_offset (offset, ref_cu);
++  die = follow_die_offset (offset,
++                         (attr->form == DW_FORM_GNU_ref_alt
++                          || cu->per_cu->is_dwz),
++                         ref_cu);
+   if (!die)
+     error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
+          "at 0x%x [in module %s]"),
+@@ -16255,7 +16722,7 @@ dwarf2_fetch_die_location_block (cu_offset offset_in_cu,
+     load_cu (per_cu);
+   cu = per_cu->cu;
+-  die = follow_die_offset (offset, &cu);
++  die = follow_die_offset (offset, per_cu->is_dwz, &cu);
+   if (!die)
+     error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
+          offset.sect_off, per_cu->objfile->name);
+@@ -17049,6 +17516,7 @@ skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end,
+     case DW_FORM_sec_offset:
+     case DW_FORM_strp:
++    case DW_FORM_GNU_strp_alt:
+       bytes += offset_size;
+       break;
+@@ -17204,7 +17672,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+                         struct macro_source_file *current_file,
+                         struct line_header *lh, char *comp_dir,
+                         struct dwarf2_section_info *section,
+-                        int section_is_gnu,
++                        int section_is_gnu, int section_is_dwz,
+                         unsigned int offset_size,
+                         struct objfile *objfile,
+                         htab_t include_hash)
+@@ -17255,6 +17723,8 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+         case DW_MACRO_GNU_undef:
+       case DW_MACRO_GNU_define_indirect:
+       case DW_MACRO_GNU_undef_indirect:
++      case DW_MACRO_GNU_define_indirect_alt:
++      case DW_MACRO_GNU_undef_indirect_alt:
+           {
+             unsigned int bytes_read;
+             int line;
+@@ -17277,11 +17747,21 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+               str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
+               mac_ptr += offset_size;
+-              body = read_indirect_string_at_offset (abfd, str_offset);
++              if (macinfo_type == DW_MACRO_GNU_define_indirect_alt
++                  || macinfo_type == DW_MACRO_GNU_undef_indirect_alt
++                  || section_is_dwz)
++                {
++                  struct dwz_file *dwz = dwarf2_get_dwz_file ();
++
++                  body = read_indirect_string_from_dwz (dwz, str_offset);
++                }
++              else
++                body = read_indirect_string_at_offset (abfd, str_offset);
+             }
+           is_define = (macinfo_type == DW_MACRO_GNU_define
+-                       || macinfo_type == DW_MACRO_GNU_define_indirect);
++                       || macinfo_type == DW_MACRO_GNU_define_indirect
++                       || macinfo_type == DW_MACRO_GNU_define_indirect_alt);
+             if (! current_file)
+             {
+               /* DWARF violation as no main source is present.  */
+@@ -17305,7 +17785,8 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+           else
+             {
+               gdb_assert (macinfo_type == DW_MACRO_GNU_undef
+-                          || macinfo_type == DW_MACRO_GNU_undef_indirect);
++                          || macinfo_type == DW_MACRO_GNU_undef_indirect
++                          || macinfo_type == DW_MACRO_GNU_undef_indirect_alt);
+               macro_undef (current_file, line, body);
+             }
+           }
+@@ -17380,6 +17861,7 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+           break;
+       case DW_MACRO_GNU_transparent_include:
++      case DW_MACRO_GNU_transparent_include_alt:
+         {
+           LONGEST offset;
+           void **slot;
+@@ -17398,13 +17880,32 @@ dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
+             }
+           else
+             {
++              bfd *include_bfd = abfd;
++              struct dwarf2_section_info *include_section = section;
++              struct dwarf2_section_info alt_section;
++              gdb_byte *include_mac_end = mac_end;
++              int is_dwz = section_is_dwz;
++
+               *slot = mac_ptr;
+-              dwarf_decode_macro_bytes (abfd,
+-                                        section->buffer + offset,
+-                                        mac_end, current_file,
++              if (macinfo_type == DW_MACRO_GNU_transparent_include_alt)
++                {
++                  struct dwz_file *dwz = dwarf2_get_dwz_file ();
++
++                  dwarf2_read_section (dwarf2_per_objfile->objfile,
++                                       &dwz->macro);
++
++                  include_bfd = dwz->macro.asection->owner;
++                  include_section = &dwz->macro;
++                  include_mac_end = dwz->macro.buffer + dwz->macro.size;
++                  is_dwz = 1;
++                }
++
++              dwarf_decode_macro_bytes (include_bfd,
++                                        include_section->buffer + offset,
++                                        include_mac_end, current_file,
+                                         lh, comp_dir,
+-                                        section, section_is_gnu,
++                                        section, section_is_gnu, is_dwz,
+                                         offset_size, objfile, include_hash);
+               htab_remove_elt (include_hash, mac_ptr);
+@@ -17571,6 +18072,8 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
+       case DW_MACRO_GNU_define_indirect:
+       case DW_MACRO_GNU_undef_indirect:
++      case DW_MACRO_GNU_define_indirect_alt:
++      case DW_MACRO_GNU_undef_indirect_alt:
+         {
+           unsigned int bytes_read;
+@@ -17581,6 +18084,7 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
+         break;
+       case DW_MACRO_GNU_transparent_include:
++      case DW_MACRO_GNU_transparent_include_alt:
+         /* Note that, according to the spec, a transparent include
+            chain cannot call DW_MACRO_GNU_start_file.  So, we can just
+            skip this opcode.  */
+@@ -17623,7 +18127,8 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
+   slot = htab_find_slot (include_hash, mac_ptr, INSERT);
+   *slot = mac_ptr;
+   dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
+-                          current_file, lh, comp_dir, section, section_is_gnu,
++                          current_file, lh, comp_dir, section,
++                          section_is_gnu, 0,
+                           offset_size, objfile, include_hash);
+   do_cleanups (cleanup);
+ }
+@@ -17721,62 +18226,100 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
+   baton->from_dwo = cu->dwo_unit != NULL;
  }
  
 -static void
@@ -4109,36 +3516,16 @@ index 1e75235..d54e266 100644
 +
 +static struct dwarf2_locexpr_baton *
 +dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
- {
--  if (attr_form_is_section_offset (attr)
--      /* ".debug_loc" may not exist at all, or the offset may be outside
--       the section.  If so, fall through to the complaint in the
--       other branch.  */
--      && DW_UNSND (attr) < dwarf2_per_objfile->loc.size)
--    {
--      struct dwarf2_loclist_baton *baton;
++{
++  struct objfile *objfile = dwarf2_per_objfile->objfile;
 +  struct dwarf2_locexpr_baton *baton;
--      baton = obstack_alloc (&cu->objfile->objfile_obstack,
--                           sizeof (struct dwarf2_loclist_baton));
--      baton->per_cu = cu->per_cu;
--      gdb_assert (baton->per_cu);
++
 +  gdb_assert (attr_form_is_block (attr));
--      dwarf2_read_section (dwarf2_per_objfile->objfile,
--                         &dwarf2_per_objfile->loc);
-+  baton = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (*baton));
++
++  baton = obstack_alloc (&objfile->objfile_obstack, sizeof (*baton));
 +  baton->per_cu = cu->per_cu;
 +  gdb_assert (baton->per_cu);
--      /* We don't know how long the location list is, but make sure we
--       don't run off the edge of the section.  */
--      baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
--      baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
--      baton->base_address = cu->base_address;
--      if (cu->base_known == 0)
--      complaint (&symfile_complaints,
--                 _("Location list used without specifying the CU base address."));
++
 +  /* Note that we're just copying the block's data pointer
 +     here, not the actual data.  We're still pointing into the
 +     info_buffer for SYM's objfile; right now we never release
@@ -4153,7 +3540,9 @@ index 1e75235..d54e266 100644
 +
 +static struct dwarf2_loclist_baton *
 +dwarf2_attr_to_loclist_baton (struct attribute *attr, struct dwarf2_cu *cu)
-+{
+ {
+   struct objfile *objfile = dwarf2_per_objfile->objfile;
+   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
 +  struct dwarf2_loclist_baton *baton;
 +
 +  /* DW_AT_location of the referenced DIE may be missing if the referenced
@@ -4161,29 +3550,35 @@ index 1e75235..d54e266 100644
 +  if (!attr)
 +    return NULL;
 +
-+  dwarf2_read_section (dwarf2_per_objfile->objfile,
-+                     &dwarf2_per_objfile->loc);
-+
++  dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+-  if (attr_form_is_section_offset (attr)
 +  if (!(attr_form_is_section_offset (attr)
-+      /* ".debug_loc" may not exist at all, or the offset may be outside
-+         the section.  If so, fall through to the complaint in the
-+         other branch.  */
-+      && DW_UNSND (attr) < dwarf2_per_objfile->loc.size))
+       /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
+        the section.  If so, fall through to the complaint in the
+        other branch.  */
+-      && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
+-    {
+-      struct dwarf2_loclist_baton *baton;
++      && DW_UNSND (attr) < dwarf2_section_size (objfile, section)))
 +    return NULL;
-+
-+  baton = obstack_alloc (&cu->objfile->objfile_obstack,
+-      baton = obstack_alloc (&objfile->objfile_obstack,
+-                           sizeof (struct dwarf2_loclist_baton));
++  baton = obstack_alloc (&objfile->objfile_obstack,
 +                       sizeof (struct dwarf2_loclist_baton));
-+  baton->per_cu = cu->per_cu;
-+  gdb_assert (baton->per_cu);
-+
-+  /* We don't know how long the location list is, but make sure we
-+     don't run off the edge of the section.  */
-+  baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
-+  baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
-+  baton->base_address = cu->base_address;
+-      fill_in_loclist_baton (cu, baton, attr);
++  fill_in_loclist_baton (cu, baton, attr);
+-      if (cu->base_known == 0)
+-      complaint (&symfile_complaints,
+-                 _("Location list used without "
+-                   "specifying the CU base address."));
 +  if (cu->base_known == 0)
 +    complaint (&symfile_complaints,
-+             _("Location list used without specifying the CU base address."));
++             _("Location list used without "
++               "specifying the CU base address."));
 +
 +  return baton;
 +}
@@ -4214,7 +3609,7 @@ index 1e75235..d54e266 100644
 +      dwarf2_invalid_attrib_class_complaint ("location description",
 +                                           SYMBOL_NATURAL_NAME (sym));
  
--      baton = obstack_alloc (&cu->objfile->objfile_obstack,
+-      baton = obstack_alloc (&objfile->objfile_obstack,
 -                           sizeof (struct dwarf2_locexpr_baton));
 -      baton->per_cu = cu->per_cu;
 -      gdb_assert (baton->per_cu);
@@ -4235,7 +3630,6 @@ index 1e75235..d54e266 100644
 -        dwarf2_invalid_attrib_class_complaint ("location description",
 -                                               SYMBOL_NATURAL_NAME (sym));
 -        baton->size = 0;
--        baton->data = NULL;
 -      }
 +      SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
 +      SYMBOL_LOCATION_BATON (sym) = NULL;
@@ -4249,75 +3643,49 @@ index 1e75235..d54e266 100644
      }
  }
  
-@@ -12050,7 +13286,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
- struct objfile *
- dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
+@@ -17878,28 +18421,35 @@ dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
+ static struct dwarf2_per_cu_data *
+ dwarf2_find_containing_comp_unit (sect_offset offset,
++                                unsigned int offset_in_dwz,
+                                 struct objfile *objfile)
  {
--  struct objfile *objfile = per_cu->psymtab->objfile;
-+  struct objfile *objfile = per_cu->objfile;
+   struct dwarf2_per_cu_data *this_cu;
+   int low, high;
++  const sect_offset *cu_off;
  
-   /* Return the master objfile, so that we can report and look up the
-      correct file containing this variable.  */
-@@ -12070,7 +13306,7 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
-   else
+   low = 0;
+   high = dwarf2_per_objfile->n_comp_units - 1;
+   while (high > low)
      {
-       /* If the CU is not currently read in, we re-read its header.  */
--      struct objfile *objfile = per_cu->psymtab->objfile;
-+      struct objfile *objfile = per_cu->objfile;
-       struct dwarf2_per_objfile *per_objfile
-       = objfile_data (objfile, dwarf2_objfile_data_key);
-       gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
-@@ -12092,7 +13328,7 @@ dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
-   else
++      struct dwarf2_per_cu_data *mid_cu;
+       int mid = low + (high - low) / 2;
+-      if (dwarf2_per_objfile->all_comp_units[mid]->offset.sect_off
+-        >= offset.sect_off)
++      mid_cu = dwarf2_per_objfile->all_comp_units[mid];
++      cu_off = &mid_cu->offset;
++      if (mid_cu->is_dwz > offset_in_dwz
++        || (mid_cu->is_dwz == offset_in_dwz
++            && cu_off->sect_off >= offset.sect_off))
+       high = mid;
+       else
+       low = mid + 1;
+     }
+   gdb_assert (low == high);
+-  if (dwarf2_per_objfile->all_comp_units[low]->offset.sect_off
+-      > offset.sect_off)
++  this_cu = dwarf2_per_objfile->all_comp_units[low];
++  cu_off = &this_cu->offset;
++  if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off)
      {
-       /* If the CU is not currently read in, we re-read its header.  */
--      struct objfile *objfile = per_cu->psymtab->objfile;
-+      struct objfile *objfile = per_cu->objfile;
-       struct dwarf2_per_objfile *per_objfile
-       = objfile_data (objfile, dwarf2_objfile_data_key);
-       gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
-@@ -12112,7 +13348,7 @@ dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
- CORE_ADDR
- dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
- {
--  struct objfile *objfile = per_cu->psymtab->objfile;
-+  struct objfile *objfile = per_cu->objfile;
-   return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
- }
-@@ -12334,6 +13570,30 @@ dwarf2_free_objfile (struct objfile *objfile)
-   /* Cached DIE trees use xmalloc and the comp_unit_obstack.  */
-   free_cached_comp_units (NULL);
-+  if (dwarf2_per_objfile->using_index)
-+    {
-+      int i;
-+
-+      for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
-+      {
-+        int j;
-+        struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+
-+        if (!cu->v.quick->lines)
-+          continue;
-+
-+        for (j = 0; j < cu->v.quick->lines->num_file_names; ++j)
-+          {
-+            if (cu->v.quick->file_names)
-+              xfree ((void *) cu->v.quick->file_names[j]);
-+            if (cu->v.quick->full_names)
-+              xfree ((void *) cu->v.quick->full_names[j]);
-+          }
-+
-+        free_line_header (cu->v.quick->lines);
-+      }
-+    }
-+
-   /* Everything else should be on the objfile obstack.  */
- }
-@@ -12368,6 +13628,31 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs)
-   return ofs_lhs->offset == ofs_rhs->offset;
+-      if (low == 0)
++      if (low == 0 || this_cu->is_dwz != offset_in_dwz)
+       error (_("Dwarf Error: could not find partial DIE containing "
+              "offset 0x%lx [in module %s]"),
+              (long) offset.sect_off, bfd_get_filename (objfile->obfd));
+@@ -18140,6 +18690,25 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
+         && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
  }
  
 +/* Fill in generic attributes applicable for type DIEs.  */
@@ -4328,12 +3696,6 @@ index 1e75235..d54e266 100644
 +{
 +  struct attribute *attr;
 +
-+  attr = dwarf2_attr (die, DW_AT_data_location, cu);
-+  if (attr_form_is_block (attr))
-+    TYPE_DATA_LOCATION_DWARF_BLOCK (type) = dwarf2_attr_to_locexpr_baton (attr,
-+                                                                        cu);
-+  gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
-+
 +  attr = dwarf2_attr (die, DW_AT_allocated, cu);
 +  if (attr_form_is_block (attr))
 +    TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
@@ -4348,1058 +3710,464 @@ index 1e75235..d54e266 100644
  /* Set the type associated with DIE to TYPE.  Save it in CU's hash
     table if necessary.  For convenience, return TYPE.
  
-@@ -12391,6 +13676,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
- {
-   struct dwarf2_offset_and_type **slot, ofs;
+@@ -18164,6 +18733,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
+   struct dwarf2_per_cu_offset_and_type **slot, ofs;
+   struct objfile *objfile = cu->objfile;
  
 +  fetch_die_type_attrs (die, type, cu);
 +
    /* For Ada types, make sure that the gnat-specific data is always
       initialized (if not already set).  There are a few types where
       we should not be doing so, because the type-specific area is
-@@ -12591,8 +13878,567 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
-   munmap_section_buffer (&data->types);
-   munmap_section_buffer (&data->frame);
-   munmap_section_buffer (&data->eh_frame);
-+  munmap_section_buffer (&data->gdb_index);
-+}
-+
-+\f
-+
-+/* The contents of the hash table we create when building the string
-+   table.  */
-+struct strtab_entry
-+{
-+  offset_type offset;
-+  const char *str;
-+};
-+
-+/* Hash function for a strtab_entry.  */
-+static hashval_t
-+hash_strtab_entry (const void *e)
-+{
-+  const struct strtab_entry *entry = e;
-+  return mapped_index_string_hash (entry->str);
-+}
-+
-+/* Equality function for a strtab_entry.  */
-+static int
-+eq_strtab_entry (const void *a, const void *b)
-+{
-+  const struct strtab_entry *ea = a;
-+  const struct strtab_entry *eb = b;
-+  return !strcmp (ea->str, eb->str);
-+}
-+
-+/* Create a strtab_entry hash table.  */
-+static htab_t
-+create_strtab (void)
-+{
-+  return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
-+                          xfree, xcalloc, xfree);
-+}
-+
-+/* Add a string to the constant pool.  Return the string's offset in
-+   host order.  */
-+static offset_type
-+add_string (htab_t table, struct obstack *cpool, const char *str)
-+{
-+  void **slot;
-+  struct strtab_entry entry;
-+  struct strtab_entry *result;
-+
-+  entry.str = str;
-+  slot = htab_find_slot (table, &entry, INSERT);
-+  if (*slot)
-+    result = *slot;
-+  else
-+    {
-+      result = XNEW (struct strtab_entry);
-+      result->offset = obstack_object_size (cpool);
-+      result->str = str;
-+      obstack_grow_str0 (cpool, str);
-+      *slot = result;
-+    }
-+  return result->offset;
-+}
-+
-+/* An entry in the symbol table.  */
-+struct symtab_index_entry
-+{
-+  /* The name of the symbol.  */
-+  const char *name;
-+  /* The offset of the name in the constant pool.  */
-+  offset_type index_offset;
-+  /* A sorted vector of the indices of all the CUs that hold an object
-+     of this name.  */
-+  VEC (offset_type) *cu_indices;
-+};
-+
-+/* The symbol table.  This is a power-of-2-sized hash table.  */
-+struct mapped_symtab
-+{
-+  offset_type n_elements;
-+  offset_type size;
-+  struct symtab_index_entry **data;
-+};
-+
-+/* Hash function for a symtab_index_entry.  */
-+static hashval_t
-+hash_symtab_entry (const void *e)
-+{
-+  const struct symtab_index_entry *entry = e;
-+  return iterative_hash (VEC_address (offset_type, entry->cu_indices),
-+                       sizeof (offset_type) * VEC_length (offset_type,
-+                                                          entry->cu_indices),
-+                       0);
-+}
-+
-+/* Equality function for a symtab_index_entry.  */
-+static int
-+eq_symtab_entry (const void *a, const void *b)
-+{
-+  const struct symtab_index_entry *ea = a;
-+  const struct symtab_index_entry *eb = b;
-+  int len = VEC_length (offset_type, ea->cu_indices);
-+  if (len != VEC_length (offset_type, eb->cu_indices))
-+    return 0;
-+  return !memcmp (VEC_address (offset_type, ea->cu_indices),
-+                VEC_address (offset_type, eb->cu_indices),
-+                sizeof (offset_type) * len);
-+}
+@@ -18341,53 +18912,13 @@ show_dwarf2_cmd (char *args, int from_tty)
+   cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
+ }
+-/* If section described by INFO was mmapped, munmap it now.  */
+-
+-static void
+-munmap_section_buffer (struct dwarf2_section_info *info)
+-{
+-  if (info->map_addr != NULL)
+-    {
+-#ifdef HAVE_MMAP
+-      int res;
+-
+-      res = munmap (info->map_addr, info->map_len);
+-      gdb_assert (res == 0);
+-#else
+-      /* Without HAVE_MMAP, we should never be here to begin with.  */
+-      gdb_assert_not_reached ("no mmap support");
+-#endif
+-    }
+-}
+-
+-/* munmap debug sections for OBJFILE, if necessary.  */
++/* Free data associated with OBJFILE, if necessary.  */
+ static void
+ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
+ {
+   struct dwarf2_per_objfile *data = d;
+   int ix;
+-  struct dwarf2_section_info *section;
+-
+-  /* This is sorted according to the order they're defined in to make it easier
+-     to keep in sync.  */
+-  munmap_section_buffer (&data->info);
+-  munmap_section_buffer (&data->abbrev);
+-  munmap_section_buffer (&data->line);
+-  munmap_section_buffer (&data->loc);
+-  munmap_section_buffer (&data->macinfo);
+-  munmap_section_buffer (&data->macro);
+-  munmap_section_buffer (&data->str);
+-  munmap_section_buffer (&data->ranges);
+-  munmap_section_buffer (&data->addr);
+-  munmap_section_buffer (&data->frame);
+-  munmap_section_buffer (&data->eh_frame);
+-  munmap_section_buffer (&data->gdb_index);
+-
+-  for (ix = 0;
+-       VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
+-       ++ix)
+-    munmap_section_buffer (section);
+   for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix)
+     VEC_free (dwarf2_per_cu_ptr,
+@@ -18397,6 +18928,9 @@ dwarf2_per_objfile_free (struct objfile *objfile, void *d)
+   if (data->dwo_files)
+     free_dwo_files (data->dwo_files, objfile);
 +
-+/* Destroy a symtab_index_entry.  */
-+static void
-+delete_symtab_entry (void *p)
-+{
-+  struct symtab_index_entry *entry = p;
-+  VEC_free (offset_type, entry->cu_indices);
-+  xfree (entry);
-+}
++  if (data->dwz_file && data->dwz_file->dwz_bfd)
++    gdb_bfd_unref (data->dwz_file->dwz_bfd);
+ }
\f
+diff --git a/gdb/elfread.c b/gdb/elfread.c
+index 1edfb27..0b54b8a 100644
+--- a/gdb/elfread.c
++++ b/gdb/elfread.c
+@@ -44,6 +44,7 @@
+ #include "gdbthread.h"
+ #include "regcache.h"
+ #include "bcache.h"
++#include "gdb_bfd.h"
+ extern void _initialize_elfread (void);
+@@ -1108,7 +1109,7 @@ build_id_verify (const char *filename, struct build_id *check)
+   int retval = 0;
+   /* We expect to be silent on the non-existing files.  */
+-  abfd = bfd_open_maybe_remote (filename);
++  abfd = gdb_bfd_open_maybe_remote (filename);
+   if (abfd == NULL)
+     return 0;
+@@ -1123,7 +1124,7 @@ build_id_verify (const char *filename, struct build_id *check)
+   else
+     retval = 1;
+-  gdb_bfd_close_or_warn (abfd);
++  gdb_bfd_unref (abfd);
+   xfree (found);
+@@ -1444,10 +1445,12 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
+       if (debugfile)
+       {
++        struct cleanup *cleanup = make_cleanup (xfree, debugfile);
+         bfd *abfd = symfile_bfd_open (debugfile);
++        make_cleanup_bfd_unref (abfd);
+         symbol_file_add_separate (abfd, symfile_flags, objfile);
+-        xfree (debugfile);
++        do_cleanups (cleanup);
+       }
+     }
+diff --git a/gdb/eval.c b/gdb/eval.c
+index 7d3a8b9..f69dff0 100644
+--- a/gdb/eval.c
++++ b/gdb/eval.c
+@@ -41,6 +41,7 @@
+ #include "gdb_obstack.h"
+ #include "objfiles.h"
+ #include "python/python.h"
++#include "dwarf2loc.h"
+ #include "gdb_assert.h"
+@@ -500,27 +501,217 @@ init_array_element (struct value *array, struct value *element,
+ }
+ static struct value *
+-value_f90_subarray (struct value *array,
+-                  struct expression *exp, int *pos, enum noside noside)
++value_f90_subarray (struct value *array, struct expression *exp, int *pos,
++                  int nargs, enum noside noside)
+ {
+-  int pc = (*pos) + 1;
+-  LONGEST low_bound, high_bound;
+-  struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+-  enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
+- 
+-  *pos += 3;
+-
+-  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
+-    low_bound = TYPE_LOW_BOUND (range);
++  /* Type to use for the newly allocated value ARRAY.  */
++  struct type *new_array_type;
 +
-+/* Create a hash table holding symtab_index_entry objects.  */
-+static htab_t
-+create_index_table (void)
-+{
-+  return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
-+                          delete_symtab_entry, xcalloc, xfree);
-+}
++  /* Type being iterated for each dimension.  */
++  struct type *type, *type_last_target;
 +
-+/* Create a new mapped symtab object.  */
-+static struct mapped_symtab *
-+create_mapped_symtab (void)
-+{
-+  struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
-+  symtab->n_elements = 0;
-+  symtab->size = 1024;
-+  symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
-+  return symtab;
-+}
++  /* Pointer in the last holder to the type of current dimension.  */
++  struct type **typep = &new_array_type;
 +
-+/* Destroy a mapped_symtab.  */
-+static void
-+cleanup_mapped_symtab (void *p)
-+{
-+  struct mapped_symtab *symtab = p;
-+  /* The contents of the array are freed when the other hash table is
-+     destroyed.  */
-+  xfree (symtab->data);
-+  xfree (symtab);
-+}
++  struct subscript_index
++    {
++      enum { SUBSCRIPT_RANGE, SUBSCRIPT_NUMBER } kind;
++      union
++      {
++        struct subscript_range
++          {
++            enum f90_range_type f90_range_type;
++            LONGEST low_bound, high_bound;
++          }
++        range;
++        LONGEST number;
++      };
++    }
++  *subscript_array;
++  struct type **type_array;
++  int i;
++  struct cleanup *old_chain;
++  CORE_ADDR value_byte_address, value_byte_offset = 0;
++  htab_t copied_types;
++  struct value *saved_array;
++
++  old_chain = make_cleanup (null_cleanup, 0);
++  object_address_set (value_raw_address (array));
++
++  if (value_optimized_out (array)
++      || (VALUE_LVAL (array) != not_lval
++          && VALUE_LVAL (array) != lval_memory
++        && VALUE_LVAL (array) != lval_internalvar_component
++        && VALUE_LVAL (array) != lval_internalvar))
++    error (_("value being subranged must be in memory"));
++  type = check_typedef (value_type (array));
++  f_object_address_data_valid_or_error (type);
 +
-+/* Find a slot in SYMTAB for the symbol NAME.  Returns a pointer to
-+   the slot.  */
-+static struct symtab_index_entry **
-+find_slot (struct mapped_symtab *symtab, const char *name)
-+{
-+  offset_type index, step, hash = mapped_index_string_hash (name);
++  copied_types = create_copied_types_hash (NULL);
++  type = copy_type_recursive (type, copied_types);
++  htab_delete (copied_types);
 +
-+  index = hash & (symtab->size - 1);
-+  step = ((hash * 17) & (symtab->size - 1)) | 1;
++  if (nargs != calc_f77_array_dims (type))
++    error (_("Wrong number of subscripts"));
 +
-+  for (;;)
++  if (TYPE_DATA_LOCATION_IS_ADDR (type))
 +    {
-+      if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
-+      return &symtab->data[index];
-+      index = (index + step) & (symtab->size - 1);
++      value_byte_address = (TYPE_DATA_LOCATION_ADDR (type)
++                          + value_offset (array));
++      TYPE_DATA_LOCATION_IS_ADDR (type) = 0;
++      TYPE_DATA_LOCATION_DWARF_BLOCK (type) = NULL;
 +    }
- }
-+/* Expand SYMTAB's hash table.  */
-+static void
-+hash_expand (struct mapped_symtab *symtab)
-+{
-+  offset_type old_size = symtab->size;
-+  offset_type i;
-+  struct symtab_index_entry **old_entries = symtab->data;
-+
-+  symtab->size *= 2;
-+  symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
-+
-+  for (i = 0; i < old_size; ++i)
+   else
+-    low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
 +    {
-+      if (old_entries[i])
-+      {
-+        struct symtab_index_entry **slot = find_slot (symtab,
-+                                                      old_entries[i]->name);
-+        *slot = old_entries[i];
-+      }
++      gdb_assert (TYPE_DATA_LOCATION_DWARF_BLOCK (type) == NULL);
++      value_byte_address = value_address (array);
 +    }
 +
-+  xfree (old_entries);
-+}
-+
-+/* Add an entry to SYMTAB.  NAME is the name of the symbol.  CU_INDEX
-+   is the index of the CU in which the symbol appears.  */
-+static void
-+add_index_entry (struct mapped_symtab *symtab, const char *name,
-+               offset_type cu_index)
-+{
-+  struct symtab_index_entry **slot;
++  new_array_type = type;
 +
-+  ++symtab->n_elements;
-+  if (4 * symtab->n_elements / 3 >= symtab->size)
-+    hash_expand (symtab);
++  subscript_array = alloca (sizeof (*subscript_array) * nargs);
 +
-+  slot = find_slot (symtab, name);
-+  if (!*slot)
-+    {
-+      *slot = XNEW (struct symtab_index_entry);
-+      (*slot)->name = name;
-+      (*slot)->cu_indices = NULL;
-+    }
-+  /* Don't push an index twice.  Due to how we add entries we only
-+     have to check the last one.  */ 
-+  if (VEC_empty (offset_type, (*slot)->cu_indices)
-+      || VEC_length (offset_type, (*slot)->cu_indices) != cu_index)
-+    VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
-+}
++  gdb_assert (nargs > 0);
 +
-+/* Add a vector of indices to the constant pool.  */
-+static offset_type
-+add_indices_to_cpool (htab_t index_table, struct obstack *cpool,
-+                    struct symtab_index_entry *entry)
-+{
-+  void **slot;
++  /* Now that we know we have a legal array subscript expression 
++     let us actually find out where this element exists in the array.  */
 +
-+  slot = htab_find_slot (index_table, entry, INSERT);
-+  if (!*slot)
++  /* Take array indices left to right.  */
++  for (i = 0; i < nargs; i++)
 +    {
-+      offset_type len = VEC_length (offset_type, entry->cu_indices);
-+      offset_type val = MAYBE_SWAP (len);
-+      offset_type iter;
-+      int i;
++      struct subscript_index *index = &subscript_array[i];
 +
-+      *slot = entry;
-+      entry->index_offset = obstack_object_size (cpool);
-+
-+      obstack_grow (cpool, &val, sizeof (val));
-+      for (i = 0;
-+         VEC_iterate (offset_type, entry->cu_indices, i, iter);
-+         ++i)
++      if (exp->elts[*pos].opcode == OP_F90_RANGE)
 +      {
-+        val = MAYBE_SWAP (iter);
-+        obstack_grow (cpool, &val, sizeof (val));
-+      }
-+    }
-+  else
-+    {
-+      struct symtab_index_entry *old_entry = *slot;
-+      entry->index_offset = old_entry->index_offset;
-+      entry = old_entry;
-+    }
-+  return entry->index_offset;
-+}
++        int pc = (*pos) + 1;
++        struct subscript_range *range;
 +
-+/* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
-+   constant pool entries going into the obstack CPOOL.  */
-+static void
-+write_hash_table (struct mapped_symtab *symtab,
-+                struct obstack *output, struct obstack *cpool)
-+{
-+  offset_type i;
-+  htab_t index_table;
-+  htab_t str_table;
-+
-+  index_table = create_index_table ();
-+  str_table = create_strtab ();
-+  /* We add all the index vectors to the constant pool first, to
-+     ensure alignment is ok.  */
-+  for (i = 0; i < symtab->size; ++i)
-+    {
-+      if (symtab->data[i])
-+      add_indices_to_cpool (index_table, cpool, symtab->data[i]);
-+    }
++        index->kind = SUBSCRIPT_RANGE;
++        range = &index->range;
 +
-+  /* Now write out the hash table.  */
-+  for (i = 0; i < symtab->size; ++i)
-+    {
-+      offset_type str_off, vec_off;
++        *pos += 3;
++        range->f90_range_type = longest_to_int (exp->elts[pc].longconst);
 +
-+      if (symtab->data[i])
-+      {
-+        str_off = add_string (str_table, cpool, symtab->data[i]->name);
-+        vec_off = symtab->data[i]->index_offset;
++        if (range->f90_range_type == HIGH_BOUND_DEFAULT
++            || range->f90_range_type == NONE_BOUND_DEFAULT)
++          range->low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp,
++                                                             pos, noside));
++
++        if (range->f90_range_type == LOW_BOUND_DEFAULT
++            || range->f90_range_type == NONE_BOUND_DEFAULT)
++          range->high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp,
++                                                              pos, noside));
 +      }
 +      else
 +      {
-+        /* While 0 is a valid constant pool index, it is not valid
-+           to have 0 for both offsets.  */
-+        str_off = 0;
-+        vec_off = 0;
-+      }
-+
-+      str_off = MAYBE_SWAP (str_off);
-+      vec_off = MAYBE_SWAP (vec_off);
++        struct value *val;
 +
-+      obstack_grow (output, &str_off, sizeof (str_off));
-+      obstack_grow (output, &vec_off, sizeof (vec_off));
++        index->kind = SUBSCRIPT_NUMBER;
+-  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
+-    high_bound = TYPE_HIGH_BOUND (range);
++        /* Evaluate each subscript; it must be a legal integer in F77.  */
++        val = evaluate_subexp_with_coercion (exp, pos, noside);
++        index->number = value_as_long (val);
++      }
 +    }
 +
-+  htab_delete (str_table);
-+  htab_delete (index_table);
-+}
-+
-+/* Write an address entry to ADDR_OBSTACK.  The addresses are taken
-+   from PST; CU_INDEX is the index of the CU in the vector of all
-+   CUs.  */
-+static void
-+add_address_entry (struct objfile *objfile,
-+                 struct obstack *addr_obstack, struct partial_symtab *pst,
-+                 unsigned int cu_index)
-+{
-+  offset_type offset;
-+  char addr[8];
-+  CORE_ADDR baseaddr;
-+
-+  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
-+
-+  store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr);
-+  obstack_grow (addr_obstack, addr, 8);
-+  store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr);
-+  obstack_grow (addr_obstack, addr, 8);
-+  offset = MAYBE_SWAP (cu_index);
-+  obstack_grow (addr_obstack, &offset, sizeof (offset_type));
-+}
-+
-+/* Add a list of partial symbols to SYMTAB.  */
-+static void
-+write_psymbols (struct mapped_symtab *symtab,
-+              struct partial_symbol **psymp,
-+              int count,
-+              offset_type cu_index)
-+{
-+  for (; count-- > 0; ++psymp)
++  /* Internal type of array is arranged right to left.  */
++  for (i = nargs - 1; i >= 0; i--)
 +    {
-+      if (SYMBOL_LANGUAGE (*psymp) == language_ada)
-+      error (_("Ada is not currently supported by the index"));
-+      add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
-+    }
-+}
-+
-+/* Write the contents of an ("unfinished") obstack to FILE.  Throw an
-+   exception if there is an error.  */
-+static void
-+write_obstack (FILE *file, struct obstack *obstack)
-+{
-+  if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
-+            file)
-+      != obstack_object_size (obstack))
-+    error (_("couldn't data write to file"));
-+}
-+
-+/* Unlink a file if the argument is not NULL.  */
-+static void
-+unlink_if_set (void *p)
-+{
-+  char **filename = p;
-+  if (*filename)
-+    unlink (*filename);
-+}
-+
-+/* Create an index file for OBJFILE in the directory DIR.  */
-+static void
-+write_psymtabs_to_index (struct objfile *objfile, const char *dir)
-+{
-+  struct cleanup *cleanup;
-+  char *filename, *cleanup_filename;
-+  struct obstack contents, addr_obstack, constant_pool, symtab_obstack, cu_list;
-+  int i;
-+  FILE *out_file;
-+  struct mapped_symtab *symtab;
-+  offset_type val, size_of_contents, total_len;
-+  struct stat st;
-+  char buf[8];
++      struct subscript_index *index = &subscript_array[i];
++      struct type *range_type = TYPE_INDEX_TYPE (type);
 +
-+  if (!objfile->psymtabs)
-+    return;
-+  if (dwarf2_per_objfile->using_index)
-+    error (_("Cannot use an index to create the index"));
++      switch (index->kind)
++      {
++      case SUBSCRIPT_RANGE:
++        {
++          struct subscript_range *range = &index->range;
++          CORE_ADDR byte_offset;
++
++          if (range->f90_range_type == LOW_BOUND_DEFAULT
++              || range->f90_range_type == BOTH_BOUND_DEFAULT)
++            range->low_bound = TYPE_LOW_BOUND (range_type);
++
++          if (range->f90_range_type == HIGH_BOUND_DEFAULT
++              || range->f90_range_type == BOTH_BOUND_DEFAULT)
++            range->high_bound = TYPE_HIGH_BOUND (range_type);
++
++          if (range->low_bound < TYPE_LOW_BOUND (range_type)
++              || (!TYPE_HIGH_BOUND_UNDEFINED (range_type)
++                  && range->high_bound > TYPE_HIGH_BOUND (range_type)))
++            error (_("slice out of range"));
++
++          byte_offset = ((range->low_bound - TYPE_LOW_BOUND (range_type))
++                         * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
++          TYPE_LOW_BOUND (range_type) = range->low_bound;
++          TYPE_HIGH_BOUND (range_type) = range->high_bound;
++          if (range->f90_range_type == LOW_BOUND_DEFAULT
++              || range->f90_range_type == NONE_BOUND_DEFAULT)
++            TYPE_HIGH_BOUND_UNDEFINED (range_type) = 0;
++
++          typep = &TYPE_TARGET_TYPE (type);
++          value_byte_offset += byte_offset;
++          type = TYPE_TARGET_TYPE (type);
++        }
++        break;
 +
-+  if (stat (objfile->name, &st) < 0)
-+    perror_with_name (_("Could not stat"));
++      case SUBSCRIPT_NUMBER:
++        {
++          CORE_ADDR byte_offset;
 +
-+  filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
-+                   INDEX_SUFFIX, (char *) NULL);
-+  cleanup = make_cleanup (xfree, filename);
++          if (index->number < TYPE_LOW_BOUND (range_type)
++              || (!TYPE_HIGH_BOUND_UNDEFINED (range_type)
++                  && index->number > TYPE_HIGH_BOUND (range_type)))
++            error (_("no such vector element"));
 +
-+  out_file = fopen (filename, "wb");
-+  if (!out_file)
-+    error (_("Can't open `%s' for writing"), filename);
++          byte_offset = ((index->number - TYPE_LOW_BOUND (range_type))
++                         * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
 +
-+  cleanup_filename = filename;
-+  make_cleanup (unlink_if_set, &cleanup_filename);
++          type = TYPE_TARGET_TYPE (type);
++          *typep = type;
++          value_byte_offset += byte_offset;
++        }
++        break;
++      }
++    }
 +
-+  symtab = create_mapped_symtab ();
-+  make_cleanup (cleanup_mapped_symtab, symtab);
++  type_last_target = type;
++  type_array = alloca (sizeof (*type_array) * nargs);
++  i = 0;
++  for (type = new_array_type; type != type_last_target;
++       type = TYPE_TARGET_TYPE (type))
++    type_array[i++] = type;
++  while (i > 0)
++    {
++      struct type *type = type_array[--i];
 +
-+  obstack_init (&addr_obstack);
-+  make_cleanup_obstack_free (&addr_obstack);
++      /* Force TYPE_LENGTH (type) recalculation.  */
++      TYPE_TARGET_STUB (type) = 1;
++      check_typedef (type);
++    }
 +
-+  obstack_init (&cu_list);
-+  make_cleanup_obstack_free (&cu_list);
++  saved_array = array;
++  array = allocate_value_lazy (new_array_type);
++  VALUE_LVAL (array) = VALUE_LVAL (saved_array);
++  if (VALUE_LVAL (saved_array) == lval_internalvar_component)
++    VALUE_LVAL (array) = lval_internalvar;
+   else
+-    high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
++    VALUE_LVAL (array) = VALUE_LVAL (saved_array);
++  VALUE_FRAME_ID (array) = VALUE_FRAME_ID (saved_array);
++  if (VALUE_LVAL (array) != lval_internalvar)
++    set_value_address (array, value_byte_address + value_byte_offset);
 +
-+  for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
++  if (!value_lazy (saved_array))
 +    {
-+      struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i];
-+      struct partial_symtab *psymtab = cu->v.psymtab;
-+      gdb_byte val[8];
-+
-+      write_psymbols (symtab,
-+                    objfile->global_psymbols.list + psymtab->globals_offset,
-+                    psymtab->n_global_syms, i);
-+      write_psymbols (symtab,
-+                    objfile->static_psymbols.list + psymtab->statics_offset,
-+                    psymtab->n_static_syms, i);
-+
-+      add_address_entry (objfile, &addr_obstack, psymtab, i);
-+
-+      store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset);
-+      obstack_grow (&cu_list, val, 8);
-+      store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length);
-+      obstack_grow (&cu_list, val, 8);
++      allocate_value_contents (array);
++      set_value_lazy (array, 0);
+-  return value_slice (array, low_bound, high_bound - low_bound + 1);
++      memcpy (value_contents_writeable (array),
++            value_contents (saved_array) + value_byte_offset,
++            TYPE_LENGTH (new_array_type));
 +    }
 +
-+  obstack_init (&constant_pool);
-+  make_cleanup_obstack_free (&constant_pool);
-+  obstack_init (&symtab_obstack);
-+  make_cleanup_obstack_free (&symtab_obstack);
-+  write_hash_table (symtab, &symtab_obstack, &constant_pool);
-+
-+  obstack_init (&contents);
-+  make_cleanup_obstack_free (&contents);
-+  size_of_contents = 5 * sizeof (offset_type);
-+  total_len = size_of_contents;
-+
-+  /* The version number.  */
-+  val = MAYBE_SWAP (1);
-+  obstack_grow (&contents, &val, sizeof (val));
-+
-+  /* The offset of the CU list from the start of the file.  */
-+  val = MAYBE_SWAP (total_len);
-+  obstack_grow (&contents, &val, sizeof (val));
-+  total_len += obstack_object_size (&cu_list);
-+
-+  /* The offset of the address table from the start of the file.  */
-+  val = MAYBE_SWAP (total_len);
-+  obstack_grow (&contents, &val, sizeof (val));
-+  total_len += obstack_object_size (&addr_obstack);
-+
-+  /* The offset of the symbol table from the start of the file.  */
-+  val = MAYBE_SWAP (total_len);
-+  obstack_grow (&contents, &val, sizeof (val));
-+  total_len += obstack_object_size (&symtab_obstack);
-+
-+  /* The offset of the constant pool from the start of the file.  */
-+  val = MAYBE_SWAP (total_len);
-+  obstack_grow (&contents, &val, sizeof (val));
-+  total_len += obstack_object_size (&constant_pool);
-+
-+  gdb_assert (obstack_object_size (&contents) == size_of_contents);
-+
-+  write_obstack (out_file, &contents);
-+  write_obstack (out_file, &cu_list);
-+  write_obstack (out_file, &addr_obstack);
-+  write_obstack (out_file, &symtab_obstack);
-+  write_obstack (out_file, &constant_pool);
-+
-+  fclose (out_file);
-+
-+  /* We want to keep the file, so we set cleanup_filename to NULL
-+     here.  See unlink_if_set.  */
-+  cleanup_filename = NULL;
-+
-+  do_cleanups (cleanup);
-+}
-+
-+/* The mapped index file format is designed to be directly mmap()able
-+   on any architecture.  In most cases, a datum is represented using a
-+   little-endian 32-bit integer value, called an offset_type.  Big
-+   endian machines must byte-swap the values before using them.
-+   Exceptions to this rule are noted.  The data is laid out such that
-+   alignment is always respected.
-+
-+   A mapped index consists of several sections.
-+
-+   1. The file header.  This is a sequence of values, of offset_type
-+   unless otherwise noted:
-+   [0] The version number.  Currently 1.
-+   [1] The offset, from the start of the file, of the CU list.
-+   [2] The offset, from the start of the file, of the address section.
-+   [3] The offset, from the start of the file, of the symbol table.
-+   [4] The offset, from the start of the file, of the constant pool.
-+
-+   2. The CU list.  This is a sequence of pairs of 64-bit
-+   little-endian values.  The first element in each pair is the offset
-+   of a CU in the .debug_info section.  The second element in each
-+   pair is the length of that CU.  References to a CU elsewhere in the
-+   map are done using a CU index, which is just the 0-based index into
-+   this table.
-+
-+   3. The address section.  The address section consists of a sequence
-+   of address entries.  Each address entry has three elements.
-+   [0] The low address.  This is a 64-bit little-endian value.
-+   [1] The high address.  This is a 64-bit little-endian value.
-+   [2] The CU index.  This is an offset_type value.
-+
-+   4. The symbol table.  This is a hash table.  The size of the hash
-+   table is always a power of 2.  The initial hash and the step are
-+   currently defined by the `find_slot' function.
-+
-+   Each slot in the hash table consists of a pair of offset_type
-+   values.  The first value is the offset of the symbol's name in the
-+   constant pool.  The second value is the offset of the CU vector in
-+   the constant pool.
-+
-+   If both values are 0, then this slot in the hash table is empty.
-+   This is ok because while 0 is a valid constant pool index, it
-+   cannot be a valid index for both a string and a CU vector.
-+
-+   A string in the constant pool is stored as a \0-terminated string,
-+   as you'd expect.
-+
-+   A CU vector in the constant pool is a sequence of offset_type
-+   values.  The first value is the number of CU indices in the vector.
-+   Each subsequent value is the index of a CU in the CU list.  This
-+   element in the hash table is used to indicate which CUs define the
-+   symbol.
-+
-+   5. The constant pool.  This is simply a bunch of bytes.  It is
-+   organized so that alignment is correct: CU vectors are stored
-+   first, followed by strings.  */
-+static void
-+save_gdb_index_command (char *arg, int from_tty)
-+{
-+  struct objfile *objfile;
-+
-+  if (!arg || !*arg)
-+    error (_("usage: save gdb-index DIRECTORY"));
-+
-+  ALL_OBJFILES (objfile)
-+  {
-+    struct stat st;
-+
-+    /* If the objfile does not correspond to an actual file, skip it.  */
-+    if (stat (objfile->name, &st) < 0)
-+      continue;
-+
-+    dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
-+    if (dwarf2_per_objfile)
-+      {
-+      volatile struct gdb_exception except;
-+
-+      TRY_CATCH (except, RETURN_MASK_ERROR)
-+        {
-+          write_psymtabs_to_index (objfile, arg);
-+        }
-+      if (except.reason < 0)
-+        exception_fprintf (gdb_stderr, except,
-+                           _("Error while writing index for `%s': "),
-+                           objfile->name);
-+      }
-+  }
-+}
-+
-+\f
-+
- int dwarf2_always_disassemble;
++  do_cleanups (old_chain);
++  return array;
+ }
  
- static void
-@@ -12609,6 +14455,8 @@ void _initialize_dwarf2_read (void);
- void
- _initialize_dwarf2_read (void)
- {
-+  struct cmd_list_element *c;
-+
-   dwarf2_objfile_data_key
-     = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
  
-@@ -12656,4 +14504,9 @@ The value is the maximum depth to print."),
-                           NULL,
-                           NULL,
-                           &setdebuglist, &showdebuglist);
-+
-+  c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
-+             _("Save a .gdb-index file"),
-+             &save_cmdlist);
-+  set_cmd_completer (c, filename_completer);
- }
-diff --git a/gdb/elfread.c b/gdb/elfread.c
-index 8c00938..a250c58 100644
---- a/gdb/elfread.c
-+++ b/gdb/elfread.c
-@@ -37,9 +37,13 @@
- #include "complaints.h"
- #include "demangle.h"
- #include "psympriv.h"
-+#include "gdbtypes.h"
+@@ -818,6 +1009,7 @@ evaluate_subexp_standard (struct type *expect_type,
+   int save_pos1;
+   struct symbol *function = NULL;
+   char *function_name = NULL;
++  struct cleanup *old_chain;
  
- extern void _initialize_elfread (void);
+   pc = (*pos)++;
+   op = exp->elts[pc].opcode;
+@@ -1892,6 +2084,8 @@ evaluate_subexp_standard (struct type *expect_type,
  
-+/* Forward declaration.  */
-+static struct sym_fns elf_sym_fns_gdb_index;
-+
- /* The struct elfinfo is available only during ELF symbol table and
-    psymtab reading.  It is destroyed at the completion of psymtab-reading.
-    It's local to elf_symfile_read.  */
-@@ -180,7 +184,8 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
- {
-   struct gdbarch *gdbarch = get_objfile_arch (objfile);
+       /* First determine the type code we are dealing with.  */
+       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
++      old_chain = make_cleanup (null_cleanup, 0);
++      object_address_set (value_raw_address (arg1));
+       type = check_typedef (value_type (arg1));
+       code = TYPE_CODE (type);
  
--  if (ms_type == mst_text || ms_type == mst_file_text)
-+  if (ms_type == mst_text || ms_type == mst_file_text
-+      || ms_type == mst_text_gnu_ifunc)
-     address = gdbarch_smash_text_address (gdbarch, address);
+@@ -1912,23 +2106,13 @@ evaluate_subexp_standard (struct type *expect_type,
+             code = TYPE_CODE (type);
+           }
+       } 
++      do_cleanups (old_chain);
  
-   return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
-@@ -388,7 +393,10 @@ elf_symtab_read (struct objfile *objfile, int type,
-           {
-             if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
-               {
--                ms_type = mst_text;
-+                if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
-+                  ms_type = mst_text_gnu_ifunc;
-+                else
-+                  ms_type = mst_text;
-               }
-             else if ((sym->name[0] == '.' && sym->name[1] == 'L')
-                      || ((sym->flags & BSF_LOCAL)
-@@ -569,6 +577,250 @@ elf_symtab_read (struct objfile *objfile, int type,
-     }
- }
+       switch (code)
+       {
+       case TYPE_CODE_ARRAY:
+-        if (exp->elts[*pos].opcode == OP_F90_RANGE)
+-          return value_f90_subarray (arg1, exp, pos, noside);
+-        else
+-          goto multi_f77_subscript;
+-
+       case TYPE_CODE_STRING:
+-        if (exp->elts[*pos].opcode == OP_F90_RANGE)
+-          return value_f90_subarray (arg1, exp, pos, noside);
+-        else
+-          {
+-            arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
+-            return value_subscript (arg1, value_as_long (arg2));
+-          }
++        return value_f90_subarray (arg1, exp, pos, nargs, noside);
  
-+/* FIXME: Delay it through elf_sym_fns.  */
-+
-+static void
-+elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
-+{
-+  bfd *obfd = objfile->obfd;
-+  const struct elf_backend_data *bed = get_elf_backend_data (obfd);
-+  asection *plt, *relplt, *got_plt;
-+  unsigned u;
-+  int plt_elf_idx;
-+  bfd_size_type reloc_count, reloc;
-+  char *string_buffer = NULL;
-+  size_t string_buffer_size = 0;
-+  struct cleanup *back_to;
-+  struct gdbarch *gdbarch = objfile->gdbarch;
-+  struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
-+  size_t ptr_size = TYPE_LENGTH (ptr_type);
-+
-+  if (objfile->separate_debug_objfile_backlink)
-+    return;
-+
-+  plt = bfd_get_section_by_name (obfd, ".plt");
-+  if (plt == NULL)
-+    return;
-+  plt_elf_idx = elf_section_data (plt)->this_idx;
-+
-+  got_plt = bfd_get_section_by_name (obfd, ".got.plt");
-+  if (got_plt == NULL)
-+    return;
-+
-+  /* This search algorithm is from _bfd_elf_canonicalize_dynamic_reloc.  */
-+  for (relplt = obfd->sections; relplt != NULL; relplt = relplt->next)
-+    if (elf_section_data (relplt)->this_hdr.sh_info == plt_elf_idx
-+      && (elf_section_data (relplt)->this_hdr.sh_type == SHT_REL
-+          || elf_section_data (relplt)->this_hdr.sh_type == SHT_RELA))
-+      break;
-+  if (relplt == NULL)
-+    return;
-+
-+  if (! bed->s->slurp_reloc_table (obfd, relplt, dyn_symbol_table, TRUE))
-+    return;
-+
-+  back_to = make_cleanup (free_current_contents, &string_buffer);
-+
-+  reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
-+  for (reloc = 0; reloc < reloc_count; reloc++)
-+    {
-+      const char *name, *name_got_plt;
-+      struct minimal_symbol *msym;
-+      CORE_ADDR address;
-+      const char *suffix = "@got.plt";
-+      size_t suffix_len = strlen (suffix);
-+      size_t name_len;
-+
-+      name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
-+      name_len = strlen (name);
-+      address = relplt->relocation[reloc].address;
-+
-+      /* Does the pointer reside in the .got.plt section?  */
-+      if (!(bfd_get_section_vma (obfd, got_plt) <= address
-+            && address < bfd_get_section_vma (obfd, got_plt)
-+                       + bfd_get_section_size (got_plt)))
-+      continue;
-+
-+      /* We cannot check if NAME is a reference to mst_text_gnu_ifunc as in
-+       OBJFILE the symbol is undefined and the objfile having NAME defined
-+       may not yet have been loaded.  */
-+
-+      if (string_buffer_size < name_len + suffix_len)
-+      {
-+        string_buffer_size = 2 * (name_len + suffix_len);
-+        string_buffer = xrealloc (string_buffer, string_buffer_size);
-+      }
-+      memcpy (string_buffer, name, name_len);
-+      memcpy (&string_buffer[name_len], suffix, suffix_len);
-+
-+      msym = record_minimal_symbol (string_buffer, name_len + suffix_len, 1,
-+                                  address, mst_slot_got_plt, got_plt,
-+                                  objfile);
-+      if (msym)
-+      MSYMBOL_SIZE (msym) = ptr_size;
-+    }
-+
-+  do_cleanups (back_to);
-+}
-+
-+/* Function does not check for possibly created duplicities in the cache.
-+   Check it by resolve_gnu_ifunc_by_cache first.  */
-+
-+static struct minimal_symbol *
-+gnu_ifunc_record_cache_unchecked (const char *function_name,
-+                                CORE_ADDR function_address)
-+{
-+  struct minimal_symbol *msym, *msym_new;
-+  asection *sect;
-+  struct objfile *objfile;
-+  char *function_name_gnu_ifunc_tgt;
-+
-+  msym = lookup_minimal_symbol_by_pc (function_address);
-+  if (msym == NULL)
-+    return NULL;
-+  if (SYMBOL_VALUE_ADDRESS (msym) != function_address)
-+    return NULL;
-+  /* minimal symbols have always SYMBOL_OBJ_SECTION non-NULL.  */
-+  sect = SYMBOL_OBJ_SECTION (msym)->the_bfd_section;
-+  objfile = SYMBOL_OBJ_SECTION (msym)->objfile;
-+
-+  /* If .plt jumps back to .plt the symbol is still deferred for later
-+     resolution and it has no use for GDB.  Besides ".text" this symbol can
-+     reside also in ".opd" for ppc64 function descriptor.  */
-+  if (strcmp (bfd_get_section_name (objfile->obfd, sect), ".plt") == 0)
-+    return NULL;
-+
-+  function_name_gnu_ifunc_tgt = alloca (strlen (function_name)
-+                                      + strlen ("@gnu-ifunc-tgt") + 1);
-+  sprintf (function_name_gnu_ifunc_tgt, "%s@gnu-ifunc-tgt", function_name);
-+
-+  /* Create new alias "@gnu-ifunc-tgt" for MSYM.  */
-+  msym_new = record_minimal_symbol (function_name_gnu_ifunc_tgt,
-+                                  strlen (function_name_gnu_ifunc_tgt), 1,
-+                                  SYMBOL_VALUE_ADDRESS (msym),
-+                                  MSYMBOL_TYPE (msym), sect, objfile);
-+  /* Should not happen.  */
-+  if (msym_new == NULL)
-+    return 0;
-+
-+  /* objfile->msymbols array is already allocated on obstack and it cannot be
-+     easily extended.  Therefore <tab>-completion on symbol names will never
-+     show the @gnu-ifunc-tgt symbol.  Link it at least to the hash table so
-+     that resolve_gnu_ifunc_by_cache can find it.  */
-+  add_minsym_to_hash_table (msym_new, objfile->msymbol_hash);
-+    
-+  MSYMBOL_SIZE (msym_new) = MSYMBOL_SIZE (msym);
-+  return msym_new;
-+}
-+
-+/* Check first the cache if it - unlikely - has not been populated since
-+   bp_gnu_ifunc_resolver has been created.  gnu_ifunc_record_cache_unchecked
-+   could create a duplicate symbol otherwise.  */
-+
-+void
-+gnu_ifunc_record_cache (struct gdbarch *gdbarch, const char *function_name,
-+                      CORE_ADDR function_address)
-+{
-+  struct minimal_symbol *msym;
-+
-+  msym = resolve_gnu_ifunc_by_cache (function_name);
-+  if (msym == NULL)
-+    gnu_ifunc_record_cache_unchecked (function_name, function_address);
-+  else if (SYMBOL_VALUE_ADDRESS (msym) != function_address)
-+    {
-+      /* This case indicates buggy inferior program.  GDB would need to update
-+       its MSYM cache symbol for function_address.  Anyway FUNCTION_NAME is
-+       never normally found in the case as in such case no
-+       bp_gnu_ifunc_resolver would be created in the first place.  */
-+
-+      warning (_("gnu-indirect-function \"%s\" has changed its resolved "
-+               "function_address from %s to %s; GDB is using the former one"),
-+             function_name, paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)),
-+             paddress (gdbarch, function_address));
-+    }
-+}
-+
-+static struct minimal_symbol *
-+resolve_gnu_ifunc_by_got (const char *function_name)
-+{
-+  char *function_name_got_plt;
-+  struct objfile *objfile;
-+
-+  function_name_got_plt = alloca (strlen (function_name) + strlen ("@got.plt")
-+                                + 1);
-+  sprintf (function_name_got_plt, "%s@got.plt", function_name);
-+
-+  ALL_PSPACE_OBJFILES (current_program_space, objfile)
-+    {
-+      bfd *obfd = objfile->obfd;
-+      struct gdbarch *gdbarch = objfile->gdbarch;
-+      struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
-+      size_t ptr_size = TYPE_LENGTH (ptr_type);
-+      CORE_ADDR pointer_address, function_address;
-+      asection *plt;
-+      gdb_byte *buf = alloca (ptr_size);
-+      struct minimal_symbol *msym;
-+
-+      msym = lookup_minimal_symbol (function_name_got_plt, NULL, objfile);
-+      if (msym == NULL)
-+      continue;
-+      if (MSYMBOL_TYPE (msym) != mst_slot_got_plt)
-+      continue;
-+      pointer_address = SYMBOL_VALUE_ADDRESS (msym);
-+
-+      plt = bfd_get_section_by_name (obfd, ".plt");
-+      if (plt == NULL)
-+      continue;
-+
-+      if (MSYMBOL_SIZE (msym) != ptr_size)
-+      continue;
-+      if (target_read_memory (pointer_address, buf, ptr_size) != 0)
-+      continue;
-+      function_address = extract_typed_address (buf, ptr_type);
-+
-+      msym = gnu_ifunc_record_cache_unchecked (function_name, function_address);
-+      if (msym == NULL)
-+      continue;
-+      return msym;
-+    }
-+
-+  return NULL;
-+}
-+
-+struct minimal_symbol *
-+resolve_gnu_ifunc_by_cache (const char *function_name)
-+{
-+  char *function_name_gnu_ifunc_tgt;
-+
-+  function_name_gnu_ifunc_tgt = alloca (strlen (function_name)
-+                                      + strlen ("@gnu-ifunc-tgt") + 1);
-+  sprintf (function_name_gnu_ifunc_tgt, "%s@gnu-ifunc-tgt", function_name);
-+
-+  return lookup_minimal_symbol (function_name_gnu_ifunc_tgt, NULL, NULL);
-+}
-+
-+int
-+resolve_gnu_ifunc (const char *function_name, CORE_ADDR *function_addressp)
-+{
-+  struct minimal_symbol *msym;
-+
-+  msym = resolve_gnu_ifunc_by_cache (function_name);
-+  if (msym != NULL)
-+    {
-+      *function_addressp = SYMBOL_VALUE_ADDRESS (msym);
-+      return 1;
-+    }
-+
-+  msym = resolve_gnu_ifunc_by_got (function_name);
-+  if (msym != NULL)
-+    {
-+      *function_addressp = SYMBOL_VALUE_ADDRESS (msym);
-+      return 1;
-+    }
-+
-+  return 0;
-+}
-+
- struct build_id
-   {
-     size_t size;
-@@ -797,6 +1049,8 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
-              bfd_errmsg (bfd_get_error ()));
-       elf_symtab_read (objfile, ST_DYNAMIC, dynsymcount, dyn_symbol_table, 0);
-+
-+      elf_rel_plt_read (objfile, dyn_symbol_table);
-     }
-   /* Add synthetic symbols - for instance, names for any PLT entries.  */
-@@ -869,11 +1123,9 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
-                               str_sect->filepos,
-                               bfd_section_size (abfd, str_sect));
-     }
--  if (dwarf2_has_info (objfile))
--    {
--      /* DWARF 2 sections */
--      dwarf2_build_psymtabs (objfile);
--    }
-+
-+  if (dwarf2_has_info (objfile) && dwarf2_initialize_objfile (objfile))
-+    objfile->sf = &elf_sym_fns_gdb_index;
-   /* If the file has its own symbol tables it has no separate debug info.
-      `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to SYMTABS/PSYMTABS.
-@@ -1049,6 +1301,24 @@ static struct sym_fns elf_sym_fns =
-   NULL                                /* next: pointer to next struct sym_fns */
- };
-+/* The same as elf_sym_fns, but not registered and uses the
-+   DWARF-specific GNU index rather than psymtab.  */
-+static struct sym_fns elf_sym_fns_gdb_index =
-+{
-+  bfd_target_elf_flavour,
-+  elf_new_init,                       /* sym_new_init: init anything gbl to entire symab */
-+  elf_symfile_init,           /* sym_init: read initial info, setup for sym_red() */
-+  elf_symfile_read,           /* sym_read: read a symbol file into symtab */
-+  elf_symfile_finish,         /* sym_finish: finished with file, cleanup */
-+  default_symfile_offsets,    /* sym_offsets:  Translate ext. to int. relocatin */
-+  elf_symfile_segments,               /* sym_segments: Get segment information from
-+                                 a file.  */
-+  NULL,                         /* sym_read_linetable */
-+  default_symfile_relocate,   /* sym_relocate: Relocate a debug section.  */
-+  &dwarf2_gdb_index_functions,
-+  NULL                                /* next: pointer to next struct sym_fns */
-+};
-+
- void
- _initialize_elfread (void)
- {
-diff --git a/gdb/eval.c b/gdb/eval.c
-index ff17c34..7b9e871 100644
---- a/gdb/eval.c
-+++ b/gdb/eval.c
-@@ -44,6 +44,7 @@
- #include "objfiles.h"
- #include "python/python.h"
- #include "wrapper.h"
-+#include "dwarf2loc.h"
- #include "gdb_assert.h"
-@@ -788,6 +789,7 @@ evaluate_subexp_standard (struct type *expect_type,
-   int save_pos1;
-   struct symbol *function = NULL;
-   char *function_name = NULL;
-+  struct cleanup *old_chain;
-   pc = (*pos)++;
-   op = exp->elts[pc].opcode;
-@@ -1772,6 +1774,8 @@ evaluate_subexp_standard (struct type *expect_type,
-             return value_zero (builtin_type (exp->gdbarch)->builtin_int,
-                                not_lval);
-           }
-+        else if (TYPE_GNU_IFUNC (ftype))
-+          return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
-         else if (TYPE_TARGET_TYPE (ftype))
-           return allocate_value (TYPE_TARGET_TYPE (ftype));
-         else
-@@ -1798,6 +1802,8 @@ evaluate_subexp_standard (struct type *expect_type,
-       /* First determine the type code we are dealing with.  */
-       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
-+      old_chain = make_cleanup (null_cleanup, 0);
-+      object_address_set (value_raw_address (arg1));
-       type = check_typedef (value_type (arg1));
-       code = TYPE_CODE (type);
-@@ -1818,6 +1824,7 @@ evaluate_subexp_standard (struct type *expect_type,
-             code = TYPE_CODE (type);
-           }
-       } 
-+      do_cleanups (old_chain);
-       switch (code)
-       {
-@@ -2254,13 +2261,19 @@ evaluate_subexp_standard (struct type *expect_type,
-       {
-       int subscript_array[MAX_FORTRAN_DIMS];
-       int array_size_array[MAX_FORTRAN_DIMS];
-+      int byte_stride_array[MAX_FORTRAN_DIMS];
-       int ndimensions = 1, i;
-       struct type *tmp_type;
-       int offset_item;        /* The array offset where the item lives */
-+      CORE_ADDR offset_byte;  /* byte_stride based offset  */
-+      unsigned element_size;
-       if (nargs > MAX_FORTRAN_DIMS)
-         error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
-+      old_chain = make_cleanup (null_cleanup, 0);
-+      object_address_set (value_raw_address (arg1));
-+
-       tmp_type = check_typedef (value_type (arg1));
-       ndimensions = calc_f77_array_dims (type);
-@@ -2290,6 +2303,9 @@ evaluate_subexp_standard (struct type *expect_type,
-           upper = f77_get_upperbound (tmp_type);
-           lower = f77_get_lowerbound (tmp_type);
-+          byte_stride_array[nargs - i - 1] =
-+                                      TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
-+
-           array_size_array[nargs - i - 1] = upper - lower + 1;
-           /* Zero-normalize subscripts so that offsetting will work. */
-@@ -2308,13 +2324,25 @@ evaluate_subexp_standard (struct type *expect_type,
-             tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
-         }
-+      /* Kept for the f77_get_upperbound / f77_get_lowerbound calls above.  */
-+      do_cleanups (old_chain);
-+
-       /* Now let us calculate the offset for this item */
--      offset_item = subscript_array[ndimensions - 1];
-+      offset_item = 0;
-+      offset_byte = 0;
-+
-+      for (i = ndimensions - 1; i >= 0; --i)
-+        {
-+          offset_item *= array_size_array[i];
-+          if (byte_stride_array[i] == 0)
-+            offset_item += subscript_array[i];
-+          else
-+            offset_byte += subscript_array[i] * byte_stride_array[i];
-+        }
--      for (i = ndimensions - 1; i > 0; --i)
--        offset_item =
--          array_size_array[i - 1] * offset_item + subscript_array[i - 1];
-+      element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tmp_type));
-+      offset_byte += offset_item * element_size;
-       /* Let us now play a dirty trick: we will take arg1 
-          which is a value node pointing to the topmost level
-@@ -2324,7 +2352,7 @@ evaluate_subexp_standard (struct type *expect_type,
-          returns the correct type value */
-       deprecated_set_value_type (arg1, tmp_type);
--      return value_subscripted_rvalue (arg1, offset_item, 0);
-+      return value_subscripted_rvalue (arg1, offset_byte);
-       }
+       case TYPE_CODE_PTR:
+       case TYPE_CODE_FUNC:
+@@ -2361,49 +2545,6 @@ evaluate_subexp_standard (struct type *expect_type,
+       }
+       return (arg1);
  
+-    multi_f77_subscript:
+-      {
+-      LONGEST subscript_array[MAX_FORTRAN_DIMS];
+-      int ndimensions = 1, i;
+-      struct value *array = arg1;
+-
+-      if (nargs > MAX_FORTRAN_DIMS)
+-        error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
+-
+-      ndimensions = calc_f77_array_dims (type);
+-
+-      if (nargs != ndimensions)
+-        error (_("Wrong number of subscripts"));
+-
+-      gdb_assert (nargs > 0);
+-
+-      /* Now that we know we have a legal array subscript expression 
+-         let us actually find out where this element exists in the array.  */
+-
+-      /* Take array indices left to right.  */
+-      for (i = 0; i < nargs; i++)
+-        {
+-          /* Evaluate each subscript; it must be a legal integer in F77.  */
+-          arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
+-
+-          /* Fill in the subscript array.  */
+-
+-          subscript_array[i] = value_as_long (arg2);
+-        }
+-
+-      /* Internal type of array is arranged right to left.  */
+-      for (i = nargs; i > 0; i--)
+-        {
+-          struct type *array_type = check_typedef (value_type (array));
+-          LONGEST index = subscript_array[i - 1];
+-
+-          lower = f77_get_lowerbound (array_type);
+-          array = value_subscripted_rvalue (array, index, lower);
+-        }
+-
+-      return array;
+-      }
+-
      case BINOP_LOGICAL_AND:
-@@ -2558,14 +2586,22 @@ evaluate_subexp_standard (struct type *expect_type,
+       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+       if (noside == EVAL_SKIP)
+@@ -2635,15 +2776,23 @@ evaluate_subexp_standard (struct type *expect_type,
        if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
        expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
        arg1 = evaluate_subexp (expect_type, exp, pos, noside);
@@ -5408,7 +4176,8 @@ index ff17c34..7b9e871 100644
        type = check_typedef (value_type (arg1));
        if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
          || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
-       error (_("Attempt to dereference pointer to member without an object"));
+       error (_("Attempt to dereference pointer "
+                "to member without an object"));
        if (noside == EVAL_SKIP)
 -      goto nosideret;
 +      {
@@ -5424,7 +4193,7 @@ index ff17c34..7b9e871 100644
        else if (noside == EVAL_AVOID_SIDE_EFFECTS)
        {
          type = check_typedef (value_type (arg1));
-@@ -2574,12 +2610,18 @@ evaluate_subexp_standard (struct type *expect_type,
+@@ -2652,12 +2801,18 @@ evaluate_subexp_standard (struct type *expect_type,
          /* In C you can dereference an array to get the 1st elt.  */
              || TYPE_CODE (type) == TYPE_CODE_ARRAY
            )
@@ -5448,7 +4217,7 @@ index ff17c34..7b9e871 100644
          else
            error (_("Attempt to take contents of a non-pointer value."));
        }
-@@ -2589,9 +2631,14 @@ evaluate_subexp_standard (struct type *expect_type,
+@@ -2667,9 +2822,14 @@ evaluate_subexp_standard (struct type *expect_type,
         do.  "long long" variables are rare enough that
         BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
        if (TYPE_CODE (type) == TYPE_CODE_INT)
@@ -5466,7 +4235,7 @@ index ff17c34..7b9e871 100644
  
      case UNOP_ADDR:
        /* C++: check for and handle pointer to members.  */
-@@ -2933,7 +2980,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
+@@ -3011,7 +3171,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
  {
    enum exp_opcode op;
    int pc;
@@ -5475,7 +4244,7 @@ index ff17c34..7b9e871 100644
    struct symbol *var;
    struct type *type;
  
-@@ -2944,12 +2991,17 @@ evaluate_subexp_with_coercion (struct expression *exp,
+@@ -3022,13 +3182,18 @@ evaluate_subexp_with_coercion (struct expression *exp,
      {
      case OP_VAR_VALUE:
        var = exp->elts[pc + 2].symbol;
@@ -5485,6 +4254,7 @@ index ff17c34..7b9e871 100644
 +      val = address_of_variable (var, exp->elts[pc + 1].block);
        type = check_typedef (SYMBOL_TYPE (var));
        if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+         && !TYPE_VECTOR (type)
          && CAST_IS_CONVERSION (exp->language_defn))
        {
          (*pos) += 4;
@@ -5494,7 +4264,7 @@ index ff17c34..7b9e871 100644
          return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
                             val);
        }
-@@ -3001,9 +3053,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
+@@ -3080,9 +3245,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
  
      case OP_VAR_VALUE:
        (*pos) += 4;
@@ -5511,8 +4281,143 @@ index ff17c34..7b9e871 100644
  
      default:
        val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
+@@ -3113,18 +3282,25 @@ parse_and_eval_type (char *p, int length)
+ int
+ calc_f77_array_dims (struct type *array_type)
+ {
+-  int ndimen = 1;
+-  struct type *tmp_type;
++  switch (TYPE_CODE (array_type))
++    {
++    case TYPE_CODE_STRING:
++      return 1;
+-  if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
+-    error (_("Can't get dimensions for a non-array type"));
++    case TYPE_CODE_ARRAY:
++      {
++      int ndimen = 1;
+-  tmp_type = array_type;
++      while ((array_type = TYPE_TARGET_TYPE (array_type)))
++        {
++          if (TYPE_CODE (array_type) == TYPE_CODE_ARRAY)
++            ++ndimen;
++        }
++      return ndimen;
++      }
+-  while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
+-    {
+-      if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
+-      ++ndimen;
++    default:
++      error (_("Can't get dimensions for a non-array/non-string type"));
+     }
+-  return ndimen;
++
+ }
+diff --git a/gdb/exec.c b/gdb/exec.c
+index 6ba1986..e076609 100644
+--- a/gdb/exec.c
++++ b/gdb/exec.c
+@@ -33,6 +33,7 @@
+ #include "arch-utils.h"
+ #include "gdbthread.h"
+ #include "progspace.h"
++#include "gdb_bfd.h"
+ #include <fcntl.h>
+ #include "readline/readline.h"
+@@ -98,10 +99,8 @@ exec_close (void)
+   if (exec_bfd)
+     {
+       bfd *abfd = exec_bfd;
+-      char *name = bfd_get_filename (abfd);
+-      gdb_bfd_close_or_warn (abfd);
+-      xfree (name);
++      gdb_bfd_unref (abfd);
+       /* Removing target sections may close the exec_ops target.
+        Clear exec_bfd before doing so to prevent recursion.  */
+@@ -128,17 +127,13 @@ exec_close_1 (int quitting)
+       vp = nxt;
+       nxt = vp->nxt;
+-      /* if there is an objfile associated with this bfd,
+-         free_objfile() will do proper cleanup of objfile *and* bfd.  */
+-
+       if (vp->objfile)
+       {
+         free_objfile (vp->objfile);
+         need_symtab_cleanup = 1;
+       }
+-      else if (vp->bfd != exec_bfd)
+-      /* FIXME-leak: We should be freeing vp->name too, I think.  */
+-      gdb_bfd_close_or_warn (vp->bfd);
++
++      gdb_bfd_unref (vp->bfd);
+       xfree (vp);
+     }
+@@ -230,11 +225,14 @@ exec_file_attach (char *filename, int from_tty)
+            &scratch_pathname);
+       }
+ #endif
++
++      cleanups = make_cleanup (xfree, scratch_pathname);
++
+       if (scratch_chan < 0)
+       perror_with_name (filename);
+-      exec_bfd = bfd_fopen (scratch_pathname, gnutarget,
+-                          write_files ? FOPEN_RUB : FOPEN_RB,
+-                          scratch_chan);
++      exec_bfd = gdb_bfd_fopen (scratch_pathname, gnutarget,
++                              write_files ? FOPEN_RUB : FOPEN_RB,
++                              scratch_chan);
+       if (!exec_bfd)
+       {
+@@ -242,13 +240,6 @@ exec_file_attach (char *filename, int from_tty)
+                scratch_pathname, bfd_errmsg (bfd_get_error ()));
+       }
+-      /* At this point, scratch_pathname and exec_bfd->name both point to the
+-         same malloc'd string.  However exec_close() will attempt to free it
+-         via the exec_bfd->name pointer, so we need to make another copy and
+-         leave exec_bfd as the new owner of the original copy.  */
+-      scratch_pathname = xstrdup (scratch_pathname);
+-      cleanups = make_cleanup (xfree, scratch_pathname);
+-
+       if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
+       {
+         /* Make sure to close exec_bfd, or else "run" might try to use
+@@ -554,6 +545,7 @@ map_vmap (bfd *abfd, bfd *arch)
+   memset ((char *) vp, '\0', sizeof (*vp));
+   vp->nxt = 0;
+   vp->bfd = abfd;
++  gdb_bfd_ref (abfd);
+   vp->name = bfd_get_filename (arch ? arch : abfd);
+   vp->member = arch ? bfd_get_filename (abfd) : "";
+diff --git a/gdb/f-exp.y b/gdb/f-exp.y
+index 33c7418..4db1bfa 100644
+--- a/gdb/f-exp.y
++++ b/gdb/f-exp.y
+@@ -298,7 +298,9 @@ arglist :  subrange
+                       { arglist_len = 1; }
+       ;
+    
+-arglist       :       arglist ',' exp   %prec ABOVE_COMMA
++arglist       :       arglist ',' exp       %prec ABOVE_COMMA
++                      { arglist_len++; }
++      |       arglist ',' subrange  %prec ABOVE_COMMA
+                       { arglist_len++; }
+       ;
 diff --git a/gdb/f-lang.h b/gdb/f-lang.h
-index f5bb82d..29cf5ba 100644
+index 4aae3c5..51a4e1e 100644
 --- a/gdb/f-lang.h
 +++ b/gdb/f-lang.h
 @@ -28,6 +28,10 @@ extern void f_error (char *);       /* Defined in f-exp.y */
@@ -5523,14 +4428,14 @@ index f5bb82d..29cf5ba 100644
 +  (struct type *type, struct ui_file *stream);
 +extern void f_object_address_data_valid_or_error (struct type *type);
 +
- extern int f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
-                       struct ui_file *, int,
-                       const struct value *,
+ extern void f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
+                        struct ui_file *, int,
+                        const struct value *,
 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
-index d35a255..dec81d5 100644
+index a95ef84..830917d 100644
 --- a/gdb/f-typeprint.c
 +++ b/gdb/f-typeprint.c
-@@ -32,7 +32,7 @@
+@@ -31,7 +31,7 @@
  #include "gdbcore.h"
  #include "target.h"
  #include "f-lang.h"
@@ -5539,7 +4444,7 @@ index d35a255..dec81d5 100644
  #include "gdb_string.h"
  #include <errno.h>
  
-@@ -49,6 +49,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
+@@ -48,6 +48,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
  void f_type_print_base (struct type *, struct ui_file *, int, int);
  \f
  
@@ -5574,7 +4479,7 @@ index d35a255..dec81d5 100644
  /* LEVEL is the depth to indent lines by.  */
  
  void
-@@ -58,6 +86,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
+@@ -57,6 +85,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
    enum type_code code;
    int demangled_args;
  
@@ -5584,7 +4489,7 @@ index d35a255..dec81d5 100644
    f_type_print_base (type, stream, show, level);
    code = TYPE_CODE (type);
    if ((varstring != NULL && *varstring != '\0')
-@@ -165,6 +196,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
+@@ -164,6 +195,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
  
    QUIT;
  
@@ -5595,18 +4500,18 @@ index d35a255..dec81d5 100644
      {
      case TYPE_CODE_ARRAY:
 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
-index 85f698d..2f72b97 100644
+index 4359f6f..8ff834b 100644
 --- a/gdb/f-valprint.c
 +++ b/gdb/f-valprint.c
 @@ -54,15 +54,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
  /* The following macro gives us the size of the nth dimension, Where 
-    n is 1 based. */
+    n is 1 based.  */
  
 -#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
 +#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
  
--/* The following gives us the offset for row n where n is 1-based. */
-+/* The following gives us the element size for row n where n is 1-based. */
+-/* The following gives us the offset for row n where n is 1-based.  */
++/* The following gives us the element size for row n where n is 1-based.  */
  
 -#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
 +#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
@@ -5642,7 +4547,7 @@ index 85f698d..2f72b97 100644
      }
  
    return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
-@@ -134,24 +139,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
+@@ -135,24 +140,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
        upper = f77_get_upperbound (tmp_type);
        lower = f77_get_lowerbound (tmp_type);
  
@@ -5660,8 +4565,8 @@ index 85f698d..2f72b97 100644
 +  /* Now we multiply eltlen by all the BYTE_STRIDEs, so that later we
       can print out array elements correctly.  Up till now we 
 -     know an offset to apply to get the item but we also 
-+     know an eltlen to apply to get the item but we also
-      have to know how much to add to get to the next item */
++     know an eltlen to apply to get the item but we also 
+      have to know how much to add to get to the next item */
  
    ndimen--;
    eltlen = TYPE_LENGTH (tmp_type);
@@ -5678,19 +4583,21 @@ index 85f698d..2f72b97 100644
      }
  }
  
-@@ -172,34 +182,34 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
+@@ -174,37 +184,35 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
  
    if (nss != ndimensions)
      {
--      for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
+-      for (i = 0;
+-         (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max);
+-         i++)
 +      for (i = 0; (i < F77_DIM_COUNT (nss) && (*elts) < options->print_max); i++)
        {
          fprintf_filtered (stream, "( ");
          f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
--                           valaddr + i * F77_DIM_OFFSET (nss),
--                           address + i * F77_DIM_OFFSET (nss),
-+                           valaddr + i * F77_DIM_BYTE_STRIDE (nss),
-+                           address + i * F77_DIM_BYTE_STRIDE (nss),
+                            valaddr,
+-                           embedded_offset + i * F77_DIM_OFFSET (nss),
++                           embedded_offset + i * F77_DIM_BYTE_STRIDE (nss),
+                            address,
                             stream, recurse, val, options, elts);
          fprintf_filtered (stream, ") ");
        }
@@ -5705,12 +4612,11 @@ index 85f698d..2f72b97 100644
           i++, (*elts)++)
        {
          val_print (TYPE_TARGET_TYPE (type),
--                   valaddr + i * F77_DIM_OFFSET (ndimensions),
-+                   valaddr + i * F77_DIM_BYTE_STRIDE (ndimensions),
-                    0,
--                   address + i * F77_DIM_OFFSET (ndimensions),
-+                   address + i * F77_DIM_BYTE_STRIDE (ndimensions),
-                    stream, recurse, val, options, current_language);
+                    valaddr,
+-                   embedded_offset + i * F77_DIM_OFFSET (ndimensions),
++                   embedded_offset + i * F77_DIM_BYTE_STRIDE (ndimensions),
+                    address, stream, recurse,
+                    val, options, current_language);
  
 -        if (i != (F77_DIM_SIZE (nss) - 1))
 +        if (i != (F77_DIM_COUNT (nss) - 1))
@@ -5722,370 +4628,140 @@ index 85f698d..2f72b97 100644
            fprintf_filtered (stream, "...");
        }
      }
-@@ -256,6 +266,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
+@@ -270,6 +278,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
    CORE_ADDR addr;
    int index;
  
 +  if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
-+    return 0;
++    return;
 +
    CHECK_TYPEDEF (type);
    switch (TYPE_CODE (type))
      {
-diff --git a/gdb/findcmd.c b/gdb/findcmd.c
-index ac63a9e..e9ba45c 100644
---- a/gdb/findcmd.c
-+++ b/gdb/findcmd.c
-@@ -45,6 +45,41 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
-     }
+diff --git a/gdb/findvar.c b/gdb/findvar.c
+index 66bcebe..e59e5f2 100644
+--- a/gdb/findvar.c
++++ b/gdb/findvar.c
+@@ -35,6 +35,7 @@
+ #include "block.h"
+ #include "objfiles.h"
+ #include "language.h"
++#include "dwarf2loc.h"
+ /* Basic byte-swapping routines.  All 'extract' functions return a
+    host-format integer from a target-format integer at ADDR which is
+@@ -438,7 +439,10 @@ minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data)
  }
  
-+/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
-+   will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
-+   place as *PATTERN_BUF, indicating that the buffer is initially empty.  */
-+
-+void
-+allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
-+                       ULONGEST *pattern_buf_size)
-+{
-+#define INITIAL_PATTERN_BUF_SIZE 100
-+  *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
-+  *pattern_buf = xmalloc (*pattern_buf_size);
-+  *pattern_buf_end = *pattern_buf;
-+}
-+
-+/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
-+   VAL_BYTES more bytes  or a 64-bit value, whichever is larger.
-+   *PATTERN_BUF_END is updated as necessary.  */
-+
-+void
-+increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
-+                       ULONGEST *pattern_buf_size, int val_bytes)
-+{
-+    /* Keep it simple and assume size == 'g' when watching for when we
-+       need to grow the pattern buf.  */
-+    if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
-+      > *pattern_buf_size)
-+      {
-+      size_t current_offset = *pattern_buf_end - *pattern_buf;
-+
-+      *pattern_buf_size *= 2;
-+      *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
-+      *pattern_buf_end = *pattern_buf + current_offset;
-+      }
-+}
-+
- /* Subroutine of find_command to simplify it.
-    Parse the arguments of the "find" command.  */
-@@ -61,8 +96,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
-   char *pattern_buf;
-   /* Current size of search pattern buffer.
-      We realloc space as needed.  */
--#define INITIAL_PATTERN_BUF_SIZE 100
--  ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
-+  ULONGEST pattern_buf_size;
-   /* Pointer to one past the last in-use part of pattern_buf.  */
-   char *pattern_buf_end;
-   ULONGEST pattern_len;
-@@ -75,8 +109,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
-   if (args == NULL)
-     error (_("Missing search parameters."));
--  pattern_buf = xmalloc (pattern_buf_size);
--  pattern_buf_end = pattern_buf;
-+  allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
-   old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
-   /* Get search granularity and/or max count if specified.
-@@ -175,17 +208,9 @@ parse_find_args (char *args, ULONGEST *max_countp,
-       v = parse_to_comma_and_eval (&s);
-       val_bytes = TYPE_LENGTH (value_type (v));
--      /* Keep it simple and assume size == 'g' when watching for when we
--       need to grow the pattern buf.  */
--      if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
--        > pattern_buf_size)
--      {
--        size_t current_offset = pattern_buf_end - pattern_buf;
-+      increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
-+                             &pattern_buf_size, val_bytes);
+ /* A default implementation for the "la_read_var_value" hook in
+-   the language vector which should work in most situations.  */
++   the language vector which should work in most situations.
++   We have to first find the address of the variable before allocating struct
++   value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly 
++   used by its type.  */
  
--        pattern_buf_size *= 2;
--        pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
--        pattern_buf_end = pattern_buf + current_offset;
--      }
-       if (size != '\0')
-       {
-@@ -240,6 +265,45 @@ parse_find_args (char *args, ULONGEST *max_countp,
-   discard_cleanups (old_cleanups);
- }
-+/* Drives target_search_memory to sweep through the specified search space,
-+   possibly in several iterations (with one call to this function for each
-+   iteration).  *START_ADDR is the address where the search starts, and is
-+   updated to the next starting address to continue the search.
-+   *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
-+   updated for the next iteration. PATTERN_BUF holds the pattern to be searched
-+   for, PATTERN_LEN is the size of the pattern in bytes.  If a match is found,
-+   it's address is put in *FOUND_ADDR.
-+
-+   Returns 1 if found, 0 if not found, and -1 if there was an error requiring
-+   halting of the search (e.g. memory read error).  */
-+
-+int
-+search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
-+             const char *pattern_buf, ULONGEST pattern_len,
-+             CORE_ADDR *found_addr)
-+{
-+  /* Offset from start of this iteration to the next iteration.  */
-+  ULONGEST next_iter_incr;
-+  int found;
-+    
-+  found = target_search_memory (*start_addr, *search_space_len,
-+                              pattern_buf, pattern_len, found_addr);
-+  if (found <= 0)
-+    return found;
-+
-+  /* Begin next iteration at one byte past this match.  */
-+  next_iter_incr = (*found_addr - *start_addr) + 1;
-+
-+  /* For robustness, we don't let search_space_len go -ve here.  */
-+  if (*search_space_len >= next_iter_incr)
-+    *search_space_len -= next_iter_incr;
-+  else
-+    *search_space_len = 0;
-+  *start_addr += next_iter_incr;
-+
-+  return found;
-+}
-+
- static void
- find_command (char *args, int from_tty)
- {
-@@ -270,12 +334,11 @@ find_command (char *args, int from_tty)
-   while (search_space_len >= pattern_len
-        && found_count < max_count)
-     {
--      /* Offset from start of this iteration to the next iteration.  */
--      ULONGEST next_iter_incr;
-       CORE_ADDR found_addr;
--      int found = target_search_memory (start_addr, search_space_len,
--                                      pattern_buf, pattern_len, &found_addr);
-+      int found;
-+      found = search_memory (&start_addr, &search_space_len, pattern_buf,
-+                           pattern_len, &found_addr);
-       if (found <= 0)
-       break;
-@@ -283,16 +346,6 @@ find_command (char *args, int from_tty)
-       printf_filtered ("\n");
-       ++found_count;
-       last_found_addr = found_addr;
--
--      /* Begin next iteration at one byte past this match.  */
--      next_iter_incr = (found_addr - start_addr) + 1;
--
--      /* For robustness, we don't let search_space_len go -ve here.  */
--      if (search_space_len >= next_iter_incr)
--      search_space_len -= next_iter_incr;
--      else
--      search_space_len = 0;
--      start_addr += next_iter_incr;
-     }
-   /* Record and print the results.  */
-diff --git a/gdb/findvar.c b/gdb/findvar.c
-index e0ca12c..de6311a 100644
---- a/gdb/findvar.c
-+++ b/gdb/findvar.c
-@@ -35,6 +35,7 @@
- #include "user-regs.h"
- #include "block.h"
- #include "objfiles.h"
-+#include "dwarf2loc.h"
- /* Basic byte-swapping routines.  All 'extract' functions return a
-    host-format integer from a target-format integer at ADDR which is
-@@ -401,27 +402,16 @@ symbol_read_needs_frame (struct symbol *sym)
- /* Given a struct symbol for a variable,
-    and a stack frame id, read the value of the variable
-    and return a (pointer to a) struct value containing the value. 
--   If the variable cannot be found, return a zero pointer.  */
-+   If the variable cannot be found, return a zero pointer.
-+   We have to first find the address of the variable before allocating struct
-+   value to return as its size may depend on DW_OP_PUSH_OBJECT_ADDRESS possibly
-+   used by its type.  */
- struct value *
- read_var_value (struct symbol *var, struct frame_info *frame)
- {
--  struct value *v;
-   struct type *type = SYMBOL_TYPE (var);
-   CORE_ADDR addr;
--  int len;
--
--  if (SYMBOL_CLASS (var) == LOC_COMPUTED
--      || SYMBOL_CLASS (var) == LOC_REGISTER)
--    /* These cases do not use V.  */
--    v = NULL;
--  else
--    {
--      v = allocate_value (type);
--      VALUE_LVAL (v) = lval_memory;   /* The most likely possibility.  */
--    }
--
--  len = TYPE_LENGTH (type);
+ struct value *
+ default_read_var_value (struct symbol *var, struct frame_info *frame)
+@@ -446,16 +450,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
+   struct value *v;
+   struct type *type = SYMBOL_TYPE (var);
+   CORE_ADDR addr;
+-  int len;
+-
+-  /* Call check_typedef on our type to make sure that, if TYPE is
+-     a TYPE_CODE_TYPEDEF, its length is set to the length of the target type
+-     instead of zero.  However, we do not replace the typedef type by the
+-     target type, because we want to keep the typedef in order to be able to
+-     set the returned value type description correctly.  */
+-  check_typedef (type);
+-
+-  len = TYPE_LENGTH (type);
  
    if (symbol_read_needs_frame (var))
      gdb_assert (frame);
-@@ -429,33 +419,43 @@ read_var_value (struct symbol *var, struct frame_info *frame)
-   switch (SYMBOL_CLASS (var))
-     {
+@@ -465,7 +459,7 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
      case LOC_CONST:
--      /* Put the constant back in target format.  */
+       /* Put the constant back in target format.  */
+       v = allocate_value (type);
 -      store_signed_integer (value_contents_raw (v), len,
--                          gdbarch_byte_order (get_type_arch (type)),
--                          (LONGEST) SYMBOL_VALUE (var));
--      VALUE_LVAL (v) = not_lval;
--      return v;
-+      {
-+      /* Put the constant back in target format.  */
-+      struct value *v = allocate_value (type);
-+      VALUE_LVAL (v) = not_lval;
-+      store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
-+                            gdbarch_byte_order (get_type_arch (type)),
-+                            (LONGEST) SYMBOL_VALUE (var));
-+      return v;
-+      }
-     case LOC_LABEL:
--      /* Put the constant back in target format.  */
--      if (overlay_debugging)
--      {
--        CORE_ADDR addr
--          = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
--                                      SYMBOL_OBJ_SECTION (var));
-+      {
-+      /* Put the constant back in target format.  */
-+      struct value *v = allocate_value (type);
-+      VALUE_LVAL (v) = not_lval;
-+      if (overlay_debugging)
-+        {
-+          CORE_ADDR addr
-+            = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
-+                                        SYMBOL_OBJ_SECTION (var));
--        store_typed_address (value_contents_raw (v), type, addr);
--      }
--      else
--      store_typed_address (value_contents_raw (v), type,
--                            SYMBOL_VALUE_ADDRESS (var));
--      VALUE_LVAL (v) = not_lval;
--      return v;
-+          store_typed_address (value_contents_raw (v), type, addr);
-+        }
-+      else
-+        store_typed_address (value_contents_raw (v), type,
-+                              SYMBOL_VALUE_ADDRESS (var));
-+      return v;
-+      }
++      store_signed_integer (value_contents_raw (v), TYPE_LENGTH (type),
+                           gdbarch_byte_order (get_type_arch (type)),
+                           (LONGEST) SYMBOL_VALUE (var));
+       VALUE_LVAL (v) = not_lval;
+@@ -490,12 +484,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
  
      case LOC_CONST_BYTES:
+       v = allocate_value (type);
 -      memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var), len);
--      VALUE_LVAL (v) = not_lval;
--      return v;
-+      {
-+      struct value *v = allocate_value (type);
-+      VALUE_LVAL (v) = not_lval;
-+      memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
-+              TYPE_LENGTH (type));
-+      return v;
-+      }
++      memcpy (value_contents_raw (v), SYMBOL_VALUE_BYTES (var),
++            TYPE_LENGTH (type));
+       VALUE_LVAL (v) = not_lval;
+       return v;
  
      case LOC_STATIC:
+-      v = allocate_value_lazy (type);
        if (overlay_debugging)
-@@ -496,12 +496,23 @@ read_var_value (struct symbol *var, struct frame_info *frame)
+       addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
+                                        SYMBOL_OBJ_SECTION (var));
+@@ -509,7 +503,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
+       error (_("Unknown argument list address for `%s'."),
+              SYMBOL_PRINT_NAME (var));
+       addr += SYMBOL_VALUE (var);
+-      v = allocate_value_lazy (type);
        break;
  
-     case LOC_BLOCK:
--      if (overlay_debugging)
--      set_value_address (v, symbol_overlayed_address
--        (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var)));
--      else
--      set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
--      return v;
-+      {
-+        CORE_ADDR addr;
-+      struct value *v;
-+
-+      if (overlay_debugging)
-+        addr = symbol_overlayed_address
-+          (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
-+      else
-+        addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var));
-+      /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
-+         DW_OP_push_object_address.  */
-+      object_address_set (addr);
-+      v = allocate_value (type);
-+      VALUE_LVAL (v) = lval_memory;
-+      set_value_address (v, addr);
-+      return v;
-+      }
+     case LOC_REF_ARG:
+@@ -524,14 +517,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
+       argref += SYMBOL_VALUE (var);
+       ref = value_at (lookup_pointer_type (type), argref);
+       addr = value_as_address (ref);
+-      v = allocate_value_lazy (type);
+       break;
+       }
  
-     case LOC_REGISTER:
-     case LOC_REGPARM_ADDR:
-@@ -520,7 +531,6 @@ read_var_value (struct symbol *var, struct frame_info *frame)
-             error (_("Value of register variable not available."));
+     case LOC_LOCAL:
+       addr = get_frame_locals_address (frame);
+       addr += SYMBOL_VALUE (var);
+-      v = allocate_value_lazy (type);
+       break;
+     case LOC_TYPEDEF:
+@@ -540,7 +531,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
+       break;
+     case LOC_BLOCK:
+-      v = allocate_value_lazy (type);
+       if (overlay_debugging)
+       addr = symbol_overlayed_address
+         (BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (var));
+@@ -566,7 +556,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
+                    SYMBOL_PRINT_NAME (var));
  
            addr = value_as_address (regval);
--          VALUE_LVAL (v) = lval_memory;
+-          v = allocate_value_lazy (type);
          }
        else
          {
-@@ -563,18 +573,33 @@ read_var_value (struct symbol *var, struct frame_info *frame)
+@@ -615,7 +604,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
+       if (obj_section
+           && (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
+         addr = target_translate_tls_address (obj_section->objfile, addr);
+-      v = allocate_value_lazy (type);
+       }
        break;
  
-     case LOC_OPTIMIZED_OUT:
--      VALUE_LVAL (v) = not_lval;
--      set_value_optimized_out (v, 1);
--      return v;
-+      {
-+        struct value *v = allocate_value (type);
-+
-+      VALUE_LVAL (v) = not_lval;
-+      set_value_optimized_out (v, 1);
-+      return v;
-+      }
-     default:
-       error (_("Cannot look up value of a botched symbol."));
+@@ -628,6 +616,10 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
        break;
      }
  
--  set_value_address (v, addr);
--  set_value_lazy (v, 1);
--  return v;
-+  {
-+    struct value *v;
-+
-+    /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
-+       DW_OP_PUSH_OBJECT_ADDRESS.  */
-+    object_address_set (addr);
-+    v = allocate_value (type);
-+    VALUE_LVAL (v) = lval_memory;
-+    set_value_address (v, addr);
-+
-+    set_value_lazy (v, 1);
-+
-+    return v;
-+  }
- }
- /* Install default attributes for register values.  */
-@@ -611,10 +636,11 @@ struct value *
++  /* ADDR is set here for ALLOCATE_VALUE's CHECK_TYPEDEF for
++     DW_OP_PUSH_OBJECT_ADDRESS.  */
++  object_address_set (addr);
++  v = allocate_value_lazy (type);
+   VALUE_LVAL (v) = lval_memory;
+   set_value_address (v, addr);
+   return v;
+@@ -723,10 +715,11 @@ struct value *
  value_from_register (struct type *type, int regnum, struct frame_info *frame)
  {
    struct gdbarch *gdbarch = get_frame_arch (frame);
@@ -6097,36 +4773,60 @@ index e0ca12c..de6311a 100644
 +
 +  if (gdbarch_convert_register_p (gdbarch, regnum, type))
      {
-       /* The ISA/ABI need to something weird when obtaining the
-          specified value from this register.  It might need to
-@@ -628,7 +654,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
+       int optim, unavail, ok;
+@@ -741,7 +734,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
+       VALUE_LVAL (v) = lval_register;
        VALUE_FRAME_ID (v) = get_frame_id (frame);
        VALUE_REGNUM (v) = regnum;
-       gdbarch_register_to_value (gdbarch,
--                               frame, regnum, type1, value_contents_raw (v));
-+                               frame, regnum, type, value_contents_raw (v));
-     }
-   else
-     {
-diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
-index 78151dd..da11686 100644
---- a/gdb/gdbcmd.h
-+++ b/gdb/gdbcmd.h
-@@ -124,6 +124,10 @@ extern struct cmd_list_element *setchecklist;
+-      ok = gdbarch_register_to_value (gdbarch, frame, regnum, type1,
++      ok = gdbarch_register_to_value (gdbarch, frame, regnum, type,
+                                     value_contents_raw (v), &optim,
+                                     &unavail);
+diff --git a/gdb/gcore.c b/gdb/gcore.c
+index aedda41..a45e787 100644
+--- a/gdb/gcore.c
++++ b/gdb/gcore.c
+@@ -33,6 +33,7 @@
+ #include <fcntl.h>
+ #include "regcache.h"
+ #include "regset.h"
++#include "gdb_bfd.h"
+ /* The largest amount of memory to read from the target at once.  We
+    must throttle it to limit the amount of memory used by GDB during
+@@ -50,7 +51,7 @@ static int gcore_memory_sections (bfd *);
+ bfd *
+ create_gcore_bfd (char *filename)
+ {
+-  bfd *obfd = bfd_openw (filename, default_gcore_target ());
++  bfd *obfd = gdb_bfd_openw (filename, default_gcore_target ());
+   if (!obfd)
+     error (_("Failed to open '%s' for output."), filename);
+@@ -110,7 +111,7 @@ do_bfd_delete_cleanup (void *arg)
+   bfd *obfd = arg;
+   const char *filename = obfd->filename;
+-  bfd_close (arg);
++  gdb_bfd_unref (arg);
+   unlink (filename);
+ }
  
- extern struct cmd_list_element *showchecklist;
+@@ -154,7 +155,7 @@ gcore_command (char *args, int from_tty)
+   fprintf_filtered (gdb_stdout, "Saved corefile %s\n", corefilename);
  
-+/* Chain containing all defined "save" subcommands.  */
-+
-+extern struct cmd_list_element *save_cmdlist;
-+
- extern void execute_command (char *, int);
- extern char *execute_command_to_string (char *p, int from_tty);
+   discard_cleanups (old_chain);
+-  bfd_close (obfd);
++  gdb_bfd_unref (obfd);
+ }
  
-diff --git a/gdb/gdbinit.in b/gdb/gdbinit.in
+ static unsigned long
+diff --git a/gdb/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
 index ffb7f53..a2e7e94 100644
---- a/gdb/gdbinit.in
-+++ b/gdb/gdbinit.in
+--- a/gdb/gdb-gdb.gdb.in
++++ b/gdb/gdb-gdb.gdb.in
 @@ -1,5 +1,15 @@
  echo Setting up the environment for debugging gdb.\n
  
@@ -6143,5528 +4843,4969 @@ index ffb7f53..a2e7e94 100644
  set complaints 1
  
  b internal_error
-diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
-index cd24eaf..9638368 100644
---- a/gdb/gdbthread.h
-+++ b/gdb/gdbthread.h
-@@ -66,6 +66,9 @@ struct thread_info
-   /* Step-resume or longjmp-resume breakpoint.  */
-   struct breakpoint *step_resume_breakpoint;
-+  /* Exception-resume breakpoint.  */
-+  struct breakpoint *exception_resume_breakpoint;
+diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
+new file mode 100644
+index 0000000..fac8776
+--- /dev/null
++++ b/gdb/gdb_bfd.c
+@@ -0,0 +1,670 @@
++/* Definitions for BFD wrappers used by GDB.
 +
-   /* Range to single step within.
-      If this is nonzero, respond to a single-step signal by continuing
-@@ -185,6 +188,10 @@ struct thread_info
-   /* True if this thread has been explicitly requested to stop.  */
-   int stop_requested;
-+  /* The initiating frame of a nexting operation, used for deciding
-+     which exceptions to intercept.  */
-+  struct frame_id initiating_frame;
++   Copyright (C) 2011, 2012
++   Free Software Foundation, Inc.
 +
-   /* Private data used by the target vector implementation.  */
-   struct private_thread_info *private;
-@@ -221,6 +228,9 @@ extern void delete_thread_silent (ptid_t);
- /* Delete a step_resume_breakpoint from the thread database. */
- extern void delete_step_resume_breakpoint (struct thread_info *);
-+/* Delete an exception_resume_breakpoint from the thread database. */
-+extern void delete_exception_resume_breakpoint (struct thread_info *);
++   This file is part of GDB.
 +
- /* Translate the integer thread id (GDB's homegrown id, not the system's)
-    into a "pid" (which may be overloaded with extra thread information).  */
- extern ptid_t thread_id_to_pid (int);
-diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
-index 443f6f7..d852a14 100644
---- a/gdb/gdbtypes.c
-+++ b/gdb/gdbtypes.c
-@@ -39,6 +39,9 @@
- #include "cp-abi.h"
- #include "gdb_assert.h"
- #include "hashtab.h"
-+#include "observer.h"
-+#include "dwarf2expr.h"
-+#include "dwarf2loc.h"
- /* Floatformat pairs.  */
-@@ -123,6 +126,11 @@ static void print_arg_types (struct field *, int, int);
- static void dump_fn_fieldlists (struct type *, int);
- static void print_cplus_stuff (struct type *, int);
-+/* The hash table holding all discardable `struct type *' references.  */
-+static htab_t type_discardable_table;
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
 +
-+/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE.  */
-+static int type_discardable_age_current;
- /* Allocate a new OBJFILE-associated type structure and fill it
-    with some defaults.  Space for the type structure is allocated
-@@ -153,6 +161,39 @@ alloc_type (struct objfile *objfile)
-   return type;
- }
-+/* Declare TYPE as discardable on next garbage collection by free_all_types.
-+   You must call type_mark_used during each free_all_types to protect TYPE from
-+   being deallocated.  */
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
 +
-+static void
-+set_type_as_discardable (struct type *type)
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
++
++#include "defs.h"
++#include "gdb_bfd.h"
++#include "gdb_assert.h"
++#include "gdb_string.h"
++#include "ui-out.h"
++#include "gdbcmd.h"
++#include "hashtab.h"
++#ifdef HAVE_ZLIB_H
++#include <zlib.h>
++#endif
++#ifdef HAVE_MMAP
++#include <sys/mman.h>
++#ifndef MAP_FAILED
++#define MAP_FAILED ((void *) -1)
++#endif
++#endif
++
++/* An object of this type is stored in the section's user data when
++   mapping a section.  */
++
++struct gdb_bfd_section_data
 +{
-+  void **slot;
++  /* Size of the data.  */
++  bfd_size_type size;
++  /* If the data was mmapped, this is the length of the map.  */
++  bfd_size_type map_len;
++  /* The data.  If NULL, the section data has not been read.  */
++  void *data;
++  /* If the data was mmapped, this is the map address.  */
++  void *map_addr;
++};
 +
-+  gdb_assert (!TYPE_DISCARDABLE (type));
++/* A hash table holding every BFD that gdb knows about.  This is not
++   to be confused with 'gdb_bfd_cache', which is used for sharing
++   BFDs; in contrast, this hash is used just to implement
++   "maint info bfd".  */
 +
-+  TYPE_DISCARDABLE (type) = 1;
-+  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
++static htab_t all_bfds;
 +
-+  slot = htab_find_slot (type_discardable_table, type, INSERT);
-+  gdb_assert (!*slot);
-+  *slot = type;
++/* See gdb_bfd.h.  */
++
++void
++gdb_bfd_stash_filename (struct bfd *abfd)
++{
++  char *name = bfd_get_filename (abfd);
++  char *data;
++
++  data = bfd_alloc (abfd, strlen (name) + 1);
++  strcpy (data, name);
++
++  /* Unwarranted chumminess with BFD.  */
++  abfd->filename = data;
 +}
 +
-+/* Allocate a new type like alloc_type but preserve for it the discardability
-+   state of PARENT_TYPE.  */
++/* An object of this type is stored in each BFD's user data.  */
 +
-+static struct type *
-+alloc_type_as_parent (struct type *parent_type)
++struct gdb_bfd_data
 +{
-+  struct type *new_type = alloc_type_copy (parent_type);
++  /* The reference count.  */
++  int refc;
 +
-+  if (TYPE_DISCARDABLE (parent_type))
-+    set_type_as_discardable (new_type);
++  /* The mtime of the BFD at the point the cache entry was made.  */
++  time_t mtime;
++};
 +
-+  return new_type;
++/* A hash table storing all the BFDs maintained in the cache.  */
++
++static htab_t gdb_bfd_cache;
++
++/* The type of an object being looked up in gdb_bfd_cache.  We use
++   htab's capability of storing one kind of object (BFD in this case)
++   and using a different sort of object for searching.  */
++
++struct gdb_bfd_cache_search
++{
++  /* The filename.  */
++  const char *filename;
++  /* The mtime.  */
++  time_t mtime;
++};
++
++/* A hash function for BFDs.  */
++
++static hashval_t
++hash_bfd (const void *b)
++{
++  const bfd *abfd = b;
++
++  /* It is simplest to just hash the filename.  */
++  return htab_hash_string (bfd_get_filename (abfd));
 +}
 +
- /* Allocate a new GDBARCH-associated type structure and fill it
-    with some defaults.  Space for the type structure is allocated
-    on the heap.  */
-@@ -278,7 +319,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
-   if (typeptr == 0 || *typeptr == 0)  /* We'll need to allocate one.  */
-     {
--      ntype = alloc_type_copy (type);
-+      ntype = alloc_type_as_parent (type);
-       if (typeptr)
-       *typeptr = ntype;
-     }
-@@ -355,7 +396,7 @@ make_reference_type (struct type *type, struct type **typeptr)
-   if (typeptr == 0 || *typeptr == 0)  /* We'll need to allocate one.  */
-     {
--      ntype = alloc_type_copy (type);
-+      ntype = alloc_type_as_parent (type);
-       if (typeptr)
-       *typeptr = ntype;
-     }
-@@ -726,6 +767,7 @@ create_range_type (struct type *result_type, struct type *index_type,
-     TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
-   TYPE_LOW_BOUND (result_type) = low_bound;
-   TYPE_HIGH_BOUND (result_type) = high_bound;
-+  TYPE_BYTE_STRIDE (result_type) = 0;
-   if (low_bound >= 0)
-     TYPE_UNSIGNED (result_type) = 1;
-@@ -825,26 +867,45 @@ create_array_type (struct type *result_type,
-   TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
-   TYPE_TARGET_TYPE (result_type) = element_type;
--  if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
--    low_bound = high_bound = 0;
--  CHECK_TYPEDEF (element_type);
--  /* Be careful when setting the array length.  Ada arrays can be
--     empty arrays with the high_bound being smaller than the low_bound.
--     In such cases, the array length should be zero.  */
--  if (high_bound < low_bound)
--    TYPE_LENGTH (result_type) = 0;
--  else
--    TYPE_LENGTH (result_type) =
--      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
-   TYPE_NFIELDS (result_type) = 1;
-   TYPE_FIELDS (result_type) =
-     (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
-   TYPE_INDEX_TYPE (result_type) = range_type;
-   TYPE_VPTR_FIELDNO (result_type) = -1;
--  /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
-+  /* DWARF blocks may depend on runtime information like
-+     DW_OP_PUSH_OBJECT_ADDRESS not being available during the
-+     CREATE_ARRAY_TYPE time.  */
-+  if (TYPE_RANGE_DATA (range_type)->low.kind != RANGE_BOUND_KIND_CONSTANT
-+      || TYPE_RANGE_DATA (range_type)->high.kind != RANGE_BOUND_KIND_CONSTANT
-+      || TYPE_LOW_BOUND_UNDEFINED (range_type) 
-+      || TYPE_HIGH_BOUND_UNDEFINED (range_type) 
-+      || get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
++/* An equality function for BFDs.  Note that this expects the caller
++   to search using struct gdb_bfd_cache_search only, not BFDs.  */
++
++static int
++eq_bfd (const void *a, const void *b)
++{
++  const bfd *abfd = a;
++  const struct gdb_bfd_cache_search *s = b;
++  struct gdb_bfd_data *gdata = bfd_usrdata (abfd);
++
++  return (gdata->mtime == s->mtime
++        && strcmp (bfd_get_filename (abfd), s->filename) == 0);
++}
++
++/* See gdb_bfd.h.  */
++
++struct bfd *
++gdb_bfd_open (const char *name, const char *target, int fd)
++{
++  hashval_t hash;
++  void **slot;
++  bfd *abfd;
++  struct gdb_bfd_cache_search search;
++  struct stat st;
++
++  if (gdb_bfd_cache == NULL)
++    gdb_bfd_cache = htab_create_alloc (1, hash_bfd, eq_bfd, NULL,
++                                     xcalloc, xfree);
++
++  if (fd == -1)
 +    {
-+      low_bound = 0;
-+      high_bound = -1;
++      fd = open (name, O_RDONLY | O_BINARY);
++      if (fd == -1)
++      {
++        bfd_set_error (bfd_error_system_call);
++        return NULL;
++      }
 +    }
 +
-+  /* Be careful when setting the array length.  Ada arrays can be
-+     empty arrays with the high_bound being smaller than the low_bound.
-+     In such cases, the array length should be zero.  TYPE_TARGET_STUB needs to
-+     be checked as it may have dependencies on DWARF blocks depending on
-+     runtime information not available during the CREATE_ARRAY_TYPE time.  */
-+  if (high_bound < low_bound || TYPE_TARGET_STUB (element_type))
-+    TYPE_LENGTH (result_type) = 0;
-+  else
++  search.filename = name;
++  if (fstat (fd, &st) < 0)
 +    {
-+      CHECK_TYPEDEF (element_type);
-+      TYPE_LENGTH (result_type) =
-+      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
++      /* Weird situation here.  */
++      search.mtime = 0;
 +    }
++  else
++    search.mtime = st.st_mtime;
 +
-   if (TYPE_LENGTH (result_type) == 0)
--    TYPE_TARGET_STUB (result_type) = 1;
++  /* Note that this must compute the same result as hash_bfd.  */
++  hash = htab_hash_string (name);
++  /* Note that we cannot use htab_find_slot_with_hash here, because
++     opening the BFD may fail; and this would violate hashtab
++     invariants.  */
++  abfd = htab_find_with_hash (gdb_bfd_cache, &search, hash);
++  if (abfd != NULL)
 +    {
-+      /* The real size will be computed for specific instances by
-+       CHECK_TYPEDEF.  */
-+      TYPE_TARGET_STUB (result_type) = 1;
++      close (fd);
++      gdb_bfd_ref (abfd);
++      return abfd;
 +    }
-   return result_type;
- }
-@@ -1353,6 +1414,105 @@ stub_noname_complaint (void)
-   complaint (&symfile_complaints, _("stub type has NULL name"));
- }
-+/* Calculate the memory length of array TYPE.
 +
-+   TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
-+   a performance hint.  Feel free to pass NULL.  Set FULL_SPAN to return the
-+   size incl. the possible padding of the last element - it may differ from the
-+   cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
-+   TYPE_BYTE_STRIDE values.  */
++  abfd = bfd_fopen (name, target, FOPEN_RB, fd);
++  if (abfd == NULL)
++    return NULL;
 +
-+static LONGEST
-+type_length_get (struct type *type, struct type *target_type, int full_span)
-+{
-+  struct type *range_type;
-+  LONGEST byte_stride = 0;    /* `= 0' for a false GCC warning.  */
-+  LONGEST count, element_size, retval;
++  slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
++  gdb_assert (!*slot);
++  *slot = abfd;
 +
-+  if (TYPE_CODE (type) != TYPE_CODE_ARRAY
-+      && TYPE_CODE (type) != TYPE_CODE_STRING)
-+    return TYPE_LENGTH (type);
++  gdb_bfd_stash_filename (abfd);
++  gdb_bfd_ref (abfd);
++  return abfd;
++}
 +
-+  /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
-+     Fortran arrays.  The allocated data will never be used so they can be
-+     zero-length.  */
-+  if (object_address_data_not_valid (type))
-+    return 0;
++/* A helper function that releases any section data attached to the
++   BFD.  */
 +
-+  range_type = TYPE_INDEX_TYPE (type);
-+  if (TYPE_LOW_BOUND_UNDEFINED (range_type)
-+      || TYPE_HIGH_BOUND_UNDEFINED (range_type))
-+    return 0;
-+  count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
-+  /* It may happen for wrong DWARF annotations returning garbage data.  */
-+  if (count < 0)
-+    warning (_("Range for type %s has invalid bounds %s..%s"),
-+           TYPE_NAME (type), plongest (TYPE_LOW_BOUND (range_type)),
-+           plongest (TYPE_HIGH_BOUND (range_type)));
-+  /* The code below does not handle count == 0 right.  */
-+  if (count <= 0)
-+    return 0;
-+  if (full_span || count > 1)
++static void
++free_one_bfd_section (bfd *abfd, asection *sectp, void *ignore)
++{
++  struct gdb_bfd_section_data *sect = bfd_get_section_userdata (abfd, sectp);
++
++  if (sect != NULL && sect->data != NULL)
 +    {
-+      /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
-+         force FULL_SPAN to 1.  */
-+      byte_stride = TYPE_BYTE_STRIDE (range_type);
-+      if (byte_stride == 0)
-+        {
-+        if (target_type == NULL)
-+          target_type = check_typedef (TYPE_TARGET_TYPE (type));
-+        byte_stride = type_length_get (target_type, NULL, 1);
++#ifdef HAVE_MMAP
++      if (sect->map_addr != NULL)
++      {
++        int res;
++
++        res = munmap (sect->map_addr, sect->map_len);
++        gdb_assert (res == 0);
 +      }
++      else
++#endif
++      xfree (sect->data);
 +    }
++}
 +
-+  /* For now, we conservatively take the array length to be 0 if its length
-+     exceeds UINT_MAX.  The code below assumes that for x < 0,
-+     (ULONGEST) x == -x + ULONGEST_MAX + 1, which is technically not guaranteed
-+     by C, but is usually true (because it would be true if x were unsigned
-+     with its high-order bit on). It uses the fact that high_bound-low_bound is
-+     always representable in ULONGEST and that if high_bound-low_bound+1
-+     overflows, it overflows to 0.  We must change these tests if we decide to
-+     increase the representation of TYPE_LENGTH from unsigned int to ULONGEST.
-+     */
++/* Close ABFD, and warn if that fails.  */
 +
-+  if (full_span)
++static int
++gdb_bfd_close_or_warn (struct bfd *abfd)
++{
++  int ret;
++  char *name = bfd_get_filename (abfd);
++
++  bfd_map_over_sections (abfd, free_one_bfd_section, NULL);
++
++  ret = bfd_close (abfd);
++
++  if (!ret)
++    warning (_("cannot close \"%s\": %s"),
++           name, bfd_errmsg (bfd_get_error ()));
++
++  return ret;
++}
++
++/* See gdb_bfd.h.  */
++
++void
++gdb_bfd_ref (struct bfd *abfd)
++{
++  struct gdb_bfd_data *gdata;
++  void **slot;
++
++  if (abfd == NULL)
++    return;
++
++  gdata = bfd_usrdata (abfd);
++
++  if (gdata != NULL)
 +    {
-+      retval = count * byte_stride;
-+      if (count == 0 || retval / count != byte_stride || retval > UINT_MAX)
-+      retval = 0;
-+      return retval;
++      gdata->refc += 1;
++      return;
 +    }
-+  if (target_type == NULL)
-+    target_type = check_typedef (TYPE_TARGET_TYPE (type));
-+  element_size = type_length_get (target_type, NULL, 1);
-+  retval = (count - 1) * byte_stride + element_size;
-+  if (retval < element_size
-+      || (byte_stride != 0
-+          && (retval - element_size) / byte_stride != count - 1)
-+      || retval > UINT_MAX)
-+    retval = 0;
-+  return retval;
++
++  gdata = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
++  gdata->refc = 1;
++  gdata->mtime = bfd_get_mtime (abfd);
++  bfd_usrdata (abfd) = gdata;
++
++  /* This is the first we've seen it, so add it to the hash table.  */
++  slot = htab_find_slot (all_bfds, abfd, INSERT);
++  gdb_assert (slot && !*slot);
++  *slot = abfd;
 +}
 +
-+/* Prepare TYPE after being read in by the backend.  Currently this function
-+   only propagates the TYPE_DYNAMIC flag.  */
++/* See gdb_bfd.h.  */
 +
 +void
-+finalize_type (struct type *type)
++gdb_bfd_unref (struct bfd *abfd)
 +{
-+  int i;
++  struct gdb_bfd_data *gdata;
++  struct gdb_bfd_cache_search search;
++  void **slot;
 +
-+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
-+    if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
-+      break;
++  if (abfd == NULL)
++    return;
 +
-+  /* FIXME: cplus_stuff is ignored here.  */
-+  if (i < TYPE_NFIELDS (type)
-+      || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
-+      || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
-+    TYPE_DYNAMIC (type) = 1;
-+}
++  gdata = bfd_usrdata (abfd);
++  gdb_assert (gdata->refc >= 1);
 +
- /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
-    If this is a stubbed struct (i.e. declared as struct foo *), see if
-@@ -1486,52 +1646,36 @@ check_typedef (struct type *type)
-         }
-     }
--  if (TYPE_TARGET_STUB (type))
-+  /* copy_type_recursive automatically makes the resulting type containing only
-+     constant values expected by the callers of this function.  */
-+  if (TYPE_DYNAMIC (type))
++  gdata->refc -= 1;
++  if (gdata->refc > 0)
++    return;
++
++  search.filename = bfd_get_filename (abfd);
++
++  if (gdb_bfd_cache && search.filename)
 +    {
-+      htab_t copied_types;
-+      struct type *type_old = type;
++      hashval_t hash = htab_hash_string (search.filename);
++      void **slot;
 +
-+      copied_types = create_copied_types_hash (NULL);
-+      type = copy_type_recursive (type, copied_types);
-+      htab_delete (copied_types);
++      search.mtime = gdata->mtime;
++      slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash,
++                                     NO_INSERT);
 +
-+      gdb_assert (TYPE_DYNAMIC (type) == 0);
++      if (slot && *slot)
++      htab_clear_slot (gdb_bfd_cache, slot);
 +    }
 +
-+  if (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type))
-     {
--      struct type *range_type;
-       struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
-+      if (TYPE_DYNAMIC (type))
-+      TYPE_TARGET_TYPE (type) = target_type;
-       if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
-       {
-         /* Empty.  */
-       }
-       else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
--             && TYPE_NFIELDS (type) == 1
--             && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
--                 == TYPE_CODE_RANGE))
-+             || TYPE_CODE (type) == TYPE_CODE_STRING)
-       {
-         /* Now recompute the length of the array type, based on its
--           number of elements and the target type's length.
--           Watch out for Ada null Ada arrays where the high bound
--           is smaller than the low bound. */
--        const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
--        const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
--        ULONGEST len;
--
--        if (high_bound < low_bound)
--          len = 0;
--        else
--          {
--            /* For now, we conservatively take the array length to be 0
--               if its length exceeds UINT_MAX.  The code below assumes
--               that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
--               which is technically not guaranteed by C, but is usually true
--               (because it would be true if x were unsigned with its
--               high-order bit on). It uses the fact that
--               high_bound-low_bound is always representable in
--               ULONGEST and that if high_bound-low_bound+1 overflows,
--               it overflows to 0.  We must change these tests if we 
--               decide to increase the representation of TYPE_LENGTH
--               from unsigned int to ULONGEST. */
--            ULONGEST ulow = low_bound, uhigh = high_bound;
--            ULONGEST tlen = TYPE_LENGTH (target_type);
--
--            len = tlen * (uhigh - ulow + 1);
--            if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh 
--                || len > UINT_MAX)
--              len = 0;
--          }
--        TYPE_LENGTH (type) = len;
-+           number of elements and the target type's length.  */
-+        TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
-         TYPE_TARGET_STUB (type) = 0;
-       }
-       else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
-@@ -1539,9 +1683,12 @@ check_typedef (struct type *type)
-         TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
-         TYPE_TARGET_STUB (type) = 0;
-       }
-+      TYPE_DYNAMIC (type) = 0;
-     }
++  bfd_usrdata (abfd) = NULL;  /* Paranoia.  */
 +
-   /* Cache TYPE_LENGTH for future use.  */
-   TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
++  htab_remove_elt (all_bfds, abfd);
 +
-   return type;
- }
-@@ -1811,6 +1958,8 @@ init_type (enum type_code code, int length, int flags,
-     TYPE_NOTTEXT (type) = 1;
-   if (flags & TYPE_FLAG_FIXED_INSTANCE)
-     TYPE_FIXED_INSTANCE (type) = 1;
-+  if (flags & TYPE_FLAG_GNU_IFUNC)
-+    TYPE_GNU_IFUNC (type) = 1;
-   if (name)
-     TYPE_NAME (type) = obsavestring (name, strlen (name),
-@@ -3006,33 +3155,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
- }
- /* Allocate the hash table used by copy_type_recursive to walk
--   types without duplicates.  We use OBJFILE's obstack, because
--   OBJFILE is about to be deleted.  */
-+   types without duplicates.   */
- htab_t
- create_copied_types_hash (struct objfile *objfile)
- {
--  return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
--                             NULL, &objfile->objfile_obstack,
--                             hashtab_obstack_allocate,
--                             dummy_obstack_deallocate);
-+  if (objfile == NULL)
++  gdb_bfd_close_or_warn (abfd);
++}
++
++/* A helper function that returns the section data descriptor
++   associated with SECTION.  If no such descriptor exists, a new one
++   is allocated and cleared.  */
++
++static struct gdb_bfd_section_data *
++get_section_descriptor (asection *section)
++{
++  struct gdb_bfd_section_data *result;
++
++  result = bfd_get_section_userdata (section->owner, section);
++
++  if (result == NULL)
 +    {
-+      /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
-+       OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN.  Table
-+       element entries get allocated by xmalloc - so use xfree.  */
-+      return htab_create (1, type_pair_hash, type_pair_eq, xfree);
++      result = bfd_zalloc (section->owner, sizeof (*result));
++      bfd_set_section_userdata (section->owner, section, result);
 +    }
-+  else
++
++  return result;
++}
++
++/* Decompress a section that was compressed using zlib.  Store the
++   decompressed buffer, and its size, in DESCRIPTOR.  */
++
++static void
++zlib_decompress_section (asection *sectp,
++                       struct gdb_bfd_section_data *descriptor)
++{
++  bfd *abfd = sectp->owner;
++#ifndef HAVE_ZLIB_H
++  error (_("Support for zlib-compressed data (from '%s', section '%s') "
++           "is disabled in this copy of GDB"),
++         bfd_get_filename (abfd),
++       bfd_get_section_name (sectp));
++#else
++  bfd_size_type compressed_size = bfd_get_section_size (sectp);
++  gdb_byte *compressed_buffer = xmalloc (compressed_size);
++  struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
++  struct cleanup *inner_cleanup;
++  bfd_size_type uncompressed_size;
++  gdb_byte *uncompressed_buffer;
++  z_stream strm;
++  int rc;
++  int header_size = 12;
++  struct dwarf2_per_bfd_section *section_data;
++
++  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
++      || bfd_bread (compressed_buffer,
++                  compressed_size, abfd) != compressed_size)
++    error (_("can't read data from '%s', section '%s'"),
++           bfd_get_filename (abfd),
++         bfd_get_section_name (abfd, sectp));
++
++  /* Read the zlib header.  In this case, it should be "ZLIB" followed
++     by the uncompressed section size, 8 bytes in big-endian order.  */
++  if (compressed_size < header_size
++      || strncmp (compressed_buffer, "ZLIB", 4) != 0)
++    error (_("corrupt ZLIB header from '%s', section '%s'"),
++           bfd_get_filename (abfd),
++         bfd_get_section_name (abfd, sectp));
++  uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
++  uncompressed_size += compressed_buffer[11];
++
++  /* It is possible the section consists of several compressed
++     buffers concatenated together, so we uncompress in a loop.  */
++  strm.zalloc = NULL;
++  strm.zfree = NULL;
++  strm.opaque = NULL;
++  strm.avail_in = compressed_size - header_size;
++  strm.next_in = (Bytef*) compressed_buffer + header_size;
++  strm.avail_out = uncompressed_size;
++  uncompressed_buffer = xmalloc (uncompressed_size);
++  inner_cleanup = make_cleanup (xfree, uncompressed_buffer);
++  rc = inflateInit (&strm);
++  while (strm.avail_in > 0)
++    {
++      if (rc != Z_OK)
++        error (_("setting up uncompression in '%s', section '%s': %d"),
++               bfd_get_filename (abfd),
++             bfd_get_section_name (abfd, sectp),
++             rc);
++      strm.next_out = ((Bytef*) uncompressed_buffer
++                       + (uncompressed_size - strm.avail_out));
++      rc = inflate (&strm, Z_FINISH);
++      if (rc != Z_STREAM_END)
++        error (_("zlib error uncompressing from '%s', section '%s': %d"),
++               bfd_get_filename (abfd),
++             bfd_get_section_name (abfd, sectp),
++             rc);
++      rc = inflateReset (&strm);
++    }
++  rc = inflateEnd (&strm);
++  if (rc != Z_OK
++      || strm.avail_out != 0)
++    error (_("concluding uncompression in '%s', section '%s': %d"),
++           bfd_get_filename (abfd),
++         bfd_get_section_name (abfd, sectp),
++         rc);
++
++  discard_cleanups (inner_cleanup);
++  do_cleanups (cleanup);
++
++  /* Attach the data to the BFD section.  */
++  descriptor->data = uncompressed_buffer;
++  descriptor->size = uncompressed_size;
++#endif
++}
++
++/* See gdb_bfd.h.  */
++
++const gdb_byte *
++gdb_bfd_map_section (asection *sectp, bfd_size_type *size)
++{
++  bfd *abfd;
++  gdb_byte *buf, *retbuf;
++  unsigned char header[4];
++  struct gdb_bfd_section_data *descriptor;
++
++  gdb_assert ((sectp->flags & SEC_RELOC) == 0);
++  gdb_assert (size != NULL);
++
++  abfd = sectp->owner;
++
++  descriptor = get_section_descriptor (sectp);
++
++  /* If the data was already read for this BFD, just reuse it.  */
++  if (descriptor->data != NULL)
++    goto done;
++
++  /* Check if the file has a 4-byte header indicating compression.  */
++  if (bfd_get_section_size (sectp) > sizeof (header)
++      && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
++      && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
 +    {
-+      /* Use OBJFILE's obstack, because OBJFILE is about to be deleted.  Table
-+       element entries get allocated by xmalloc - so use xfree.  */
-+      return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
-+                                 xfree, &objfile->objfile_obstack,
-+                                 hashtab_obstack_allocate,
-+                                 dummy_obstack_deallocate);
++      /* Upon decompression, update the buffer and its size.  */
++      if (strncmp (header, "ZLIB", sizeof (header)) == 0)
++        {
++          zlib_decompress_section (sectp, descriptor);
++        goto done;
++        }
 +    }
- }
--/* Recursively copy (deep copy) TYPE, if it is associated with
--   OBJFILE.  Return a new type allocated using malloc, a saved type if
--   we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
--   not associated with OBJFILE.  */
-+/* A helper for copy_type_recursive.  This does all the work.  OBJFILE is used
-+   only for an assertion checking.  */
--struct type *
--copy_type_recursive (struct objfile *objfile, 
--                   struct type *type,
--                   htab_t copied_types)
-+static struct type *
-+copy_type_recursive_1 (struct objfile *objfile, 
-+                     struct type *type,
-+                     htab_t copied_types)
- {
-   struct type_pair *stored, pair;
-   void **slot;
-   struct type *new_type;
--  if (! TYPE_OBJFILE_OWNED (type))
-+  if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
-     return type;
-   /* This type shouldn't be pointing to any types in other objfiles;
-@@ -3047,8 +3205,10 @@ copy_type_recursive (struct objfile *objfile,
-   new_type = alloc_type_arch (get_type_arch (type));
-   /* We must add the new type to the hash table immediately, in case
--     we encounter this type again during a recursive call below.  */
--  stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
-+     we encounter this type again during a recursive call below.  Memory could
-+     be allocated from OBJFILE in the case we will be removing OBJFILE, this
-+     optimization is missed and xfree is called for it from COPIED_TYPES.  */
-+  stored = xmalloc (sizeof (*stored));
-   stored->old = type;
-   stored->new = new_type;
-   *slot = stored;
-@@ -3059,6 +3219,19 @@ copy_type_recursive (struct objfile *objfile,
-   TYPE_OBJFILE_OWNED (new_type) = 0;
-   TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
-+  /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
-+     need to initialize it again.  And even if TYPE was already discardable
-+     NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE.  */
-+  TYPE_DISCARDABLE (new_type) = 0;
-+  set_type_as_discardable (new_type);
 +
-+  /* Pre-clear the fields processed by delete_main_type.  If DWARF block
-+     evaluations below call error we would leave an unfreeable TYPE.  */
-+  TYPE_TARGET_TYPE (new_type) = NULL;
-+  TYPE_VPTR_BASETYPE (new_type) = NULL;
-+  TYPE_NFIELDS (new_type) = 0;
-+  TYPE_FIELDS (new_type) = NULL;
++#ifdef HAVE_MMAP
++  {
++    /* The page size, used when mmapping.  */
++    static int pagesize;
 +
-   if (TYPE_NAME (type))
-     TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
-   if (TYPE_TAG_NAME (type))
-@@ -3067,12 +3240,48 @@ copy_type_recursive (struct objfile *objfile,
-   TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
-   TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
-+  if (TYPE_ALLOCATED (new_type))
++    if (pagesize == 0)
++      pagesize = getpagesize ();
++
++    /* Only try to mmap sections which are large enough: we don't want
++       to waste space due to fragmentation.  */
++
++    if (bfd_get_section_size (sectp) > 4 * pagesize)
++      {
++      descriptor->size = bfd_get_section_size (sectp);
++      descriptor->data = bfd_mmap (abfd, 0, descriptor->size, PROT_READ,
++                                   MAP_PRIVATE, sectp->filepos,
++                                   &descriptor->map_addr,
++                                   &descriptor->map_len);
++
++      if ((caddr_t)descriptor->data != MAP_FAILED)
++        {
++#if HAVE_POSIX_MADVISE
++          posix_madvise (descriptor->map_addr, descriptor->map_len,
++                         POSIX_MADV_WILLNEED);
++#endif
++          goto done;
++        }
++
++      /* On failure, clear out the section data and try again.  */
++      memset (descriptor, 0, sizeof (*descriptor));
++      }
++  }
++#endif /* HAVE_MMAP */
++
++  /* If we get here, we are a normal, not-compressed section.  */
++
++  descriptor->size = bfd_get_section_size (sectp);
++  descriptor->data = xmalloc (descriptor->size);
++
++  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
++      || bfd_bread (descriptor->data, bfd_get_section_size (sectp),
++                  abfd) != bfd_get_section_size (sectp))
 +    {
-+      gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
++      xfree (descriptor->data);
++      descriptor->data = NULL;
++      error (_("Can't read data for section '%s'"),
++           bfd_get_filename (abfd));
++    }
 +
-+      if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
-+        TYPE_NOT_ALLOCATED (new_type) = 1;
-+      TYPE_ALLOCATED (new_type) = NULL;
++ done:
++  gdb_assert (descriptor->data != NULL);
++  *size = descriptor->size;
++  return descriptor->data;
++}
++
++\f
++
++/* See gdb_bfd.h.  */
++
++bfd *
++gdb_bfd_fopen (const char *filename, const char *target, const char *mode,
++             int fd)
++{
++  bfd *result = bfd_fopen (filename, target, mode, fd);
++
++  if (result)
++    {
++      gdb_bfd_stash_filename (result);
++      gdb_bfd_ref (result);
 +    }
 +
-+  if (TYPE_ASSOCIATED (new_type))
++  return result;
++}
++
++/* See gdb_bfd.h.  */
++
++bfd *
++gdb_bfd_openr (const char *filename, const char *target)
++{
++  bfd *result = bfd_openr (filename, target);
++
++  if (result)
 +    {
-+      gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
++      gdb_bfd_stash_filename (result);
++      gdb_bfd_ref (result);
++    }
 +
-+      if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
-+        TYPE_NOT_ASSOCIATED (new_type) = 1;
-+      TYPE_ASSOCIATED (new_type) = NULL;
++  return result;
++}
++
++/* See gdb_bfd.h.  */
++
++bfd *
++gdb_bfd_openw (const char *filename, const char *target)
++{
++  bfd *result = bfd_openw (filename, target);
++
++  if (result)
++    {
++      gdb_bfd_stash_filename (result);
++      gdb_bfd_ref (result);
 +    }
 +
-+  if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
-+      && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
++  return result;
++}
++
++/* See gdb_bfd.h.  */
++
++bfd *
++gdb_bfd_openr_iovec (const char *filename, const char *target,
++                   void *(*open_func) (struct bfd *nbfd,
++                                       void *open_closure),
++                   void *open_closure,
++                   file_ptr (*pread_func) (struct bfd *nbfd,
++                                           void *stream,
++                                           void *buf,
++                                           file_ptr nbytes,
++                                           file_ptr offset),
++                   int (*close_func) (struct bfd *nbfd,
++                                      void *stream),
++                   int (*stat_func) (struct bfd *abfd,
++                                     void *stream,
++                                     struct stat *sb))
++{
++  bfd *result = bfd_openr_iovec (filename, target,
++                               open_func, open_closure,
++                               pread_func, close_func, stat_func);
++
++  if (result)
 +    {
-+      if (TYPE_NOT_ALLOCATED (new_type)
-+          || TYPE_NOT_ASSOCIATED (new_type))
-+      TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
-+      else
-+      {
-+        TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
-+        TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
-+                                  (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
-+      }
++      gdb_bfd_ref (result);
++      gdb_bfd_stash_filename (result);
 +    }
 +
-   /* Copy the fields.  */
-   if (TYPE_NFIELDS (type))
-     {
-       int i, nfields;
-+      /* TYPE_CODE_RANGE uses TYPE_RANGE_DATA of the union with TYPE_FIELDS.  */
-+      gdb_assert (TYPE_CODE (type) != TYPE_CODE_RANGE);
++  return result;
++}
 +
-       nfields = TYPE_NFIELDS (type);
-+      TYPE_NFIELDS (new_type) = nfields;
-       TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
-       for (i = 0; i < nfields; i++)
-       {
-@@ -3081,8 +3290,8 @@ copy_type_recursive (struct objfile *objfile,
-         TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
-         if (TYPE_FIELD_TYPE (type, i))
-           TYPE_FIELD_TYPE (new_type, i)
--            = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
--                                   copied_types);
-+            = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
-+                                     copied_types);
-         if (TYPE_FIELD_NAME (type, i))
-           TYPE_FIELD_NAME (new_type, i) = 
-             xstrdup (TYPE_FIELD_NAME (type, i));
-@@ -3109,24 +3318,166 @@ copy_type_recursive (struct objfile *objfile,
-       }
-     }
-+  /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
-+     possibly converted.  */
-+  TYPE_DYNAMIC (new_type) = 0;
++/* See gdb_bfd.h.  */
 +
-   /* For range types, copy the bounds information. */
--  if (TYPE_CODE (type) == TYPE_CODE_RANGE)
-+  if (TYPE_CODE (new_type) == TYPE_CODE_RANGE)
-     {
-       TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
-       *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
++bfd *
++gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous)
++{
++  bfd *result = bfd_openr_next_archived_file (archive, previous);
 +
-+      switch (TYPE_RANGE_DATA (new_type)->low.kind)
-+      {
-+      case RANGE_BOUND_KIND_CONSTANT:
-+        break;
-+      case RANGE_BOUND_KIND_DWARF_BLOCK:
-+        /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
-+           it is expected to be made constant by CHECK_TYPEDEF.
-+           TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
-+           */
-+        if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
-+            || ! has_stack_frames ())
-+          {
-+            /* We should set 1 for Fortran but how to find the language?  */
-+            TYPE_LOW_BOUND (new_type) = 0;
-+            TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
-+          }
-+        else
-+          TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval
-+                              (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block);
-+        TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
-+        break;
-+      case RANGE_BOUND_KIND_DWARF_LOCLIST:
-+        {
-+          CORE_ADDR addr;
++  if (result)
++    {
++      gdb_bfd_ref (result);
++      /* No need to stash the filename here.  */
++    }
 +
-+          /* `struct dwarf2_loclist_baton' is too bound to its objfile so
-+             it is expected to be made constant by CHECK_TYPEDEF.
-+             TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
-+             */
-+          if (! TYPE_NOT_ALLOCATED (new_type)
-+              && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
-+              && dwarf_loclist_baton_eval
-+                (TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.loclist,
-+                 TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.type, &addr))
-+            TYPE_LOW_BOUND (new_type) = addr;
-+          else
-+            {
-+              /* We should set 1 for Fortran but how to find the language?  */
-+              TYPE_LOW_BOUND (new_type) = 0;
-+              TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
-+            }
-+          TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
-+        }
-+        break;
-+      }
++  return result;
++}
 +
-+      switch (TYPE_RANGE_DATA (new_type)->high.kind)
-+      {
-+      case RANGE_BOUND_KIND_CONSTANT:
-+        break;
-+      case RANGE_BOUND_KIND_DWARF_BLOCK:
-+        /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
-+           it is expected to be made constant by CHECK_TYPEDEF.
-+           TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
-+           */
-+        if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
-+            || ! has_stack_frames ())
-+          {
-+            TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
-+            TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
-+          }
-+        else
-+          TYPE_HIGH_BOUND (new_type) = dwarf_locexpr_baton_eval
-+                             (TYPE_RANGE_DATA (new_type)->high.u.dwarf_block);
-+        TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
-+        break;
-+      case RANGE_BOUND_KIND_DWARF_LOCLIST:
-+        {
-+          CORE_ADDR addr;
++/* See gdb_bfd.h.  */
 +
-+          /* `struct dwarf2_loclist_baton' is too bound to its objfile so
-+             it is expected to be made constant by CHECK_TYPEDEF.
-+             TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
-+             */
-+          if (! TYPE_NOT_ALLOCATED (new_type)
-+              && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
-+              && dwarf_loclist_baton_eval
-+                    (TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.loclist,
-+                     TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.type,
-+                     &addr))
-+            TYPE_HIGH_BOUND (new_type) = addr;
-+          else
-+            {
-+              TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
-+              TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
-+            }
-+          TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
-+        }
-+        break;
-+      }
++bfd *
++gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
++{
++  bfd *result = bfd_fdopenr (filename, target, fd);
 +
-+      switch (TYPE_RANGE_DATA (new_type)->byte_stride.kind)
-+      {
-+      case RANGE_BOUND_KIND_CONSTANT:
-+        break;
-+      case RANGE_BOUND_KIND_DWARF_BLOCK:
-+        /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
-+           it is expected to be made constant by CHECK_TYPEDEF.
-+           TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
-+           */
-+        if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
-+            || ! has_stack_frames ())
-+          TYPE_BYTE_STRIDE (new_type) = 0;
-+        else
-+          TYPE_BYTE_STRIDE (new_type) = dwarf_locexpr_baton_eval
-+                      (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_block);
-+        TYPE_RANGE_DATA (new_type)->byte_stride.kind
-+          = RANGE_BOUND_KIND_CONSTANT;
-+        break;
-+      case RANGE_BOUND_KIND_DWARF_LOCLIST:
-+        {
-+          CORE_ADDR addr = 0;
-+
-+          /* `struct dwarf2_loclist_baton' is too bound to its objfile so
-+             it is expected to be made constant by CHECK_TYPEDEF.
-+             TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
-+             */
-+          if (! TYPE_NOT_ALLOCATED (new_type)
-+              && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ())
-+            dwarf_loclist_baton_eval
-+             (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.loclist,
-+              TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.type,
-+              &addr);
-+          TYPE_BYTE_STRIDE (new_type) = addr;
-+          TYPE_RANGE_DATA (new_type)->byte_stride.kind
-+            = RANGE_BOUND_KIND_CONSTANT;
-+        }
-+        break;
-+      }
-+
-+      /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound.  */
-+      if (TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type))
-+      {
-+        TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type)
-+                                     + TYPE_HIGH_BOUND (new_type) - 1;
-+        TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
-+      }
-     }
-   /* Copy pointers to other types.  */
-   if (TYPE_TARGET_TYPE (type))
-     TYPE_TARGET_TYPE (new_type) = 
--      copy_type_recursive (objfile, 
--                         TYPE_TARGET_TYPE (type),
--                         copied_types);
-+      copy_type_recursive_1 (objfile, 
-+                           TYPE_TARGET_TYPE (type),
-+                           copied_types);
-   if (TYPE_VPTR_BASETYPE (type))
-     TYPE_VPTR_BASETYPE (new_type) = 
--      copy_type_recursive (objfile,
--                         TYPE_VPTR_BASETYPE (type),
--                         copied_types);
-+      copy_type_recursive_1 (objfile,
-+                           TYPE_VPTR_BASETYPE (type),
-+                           copied_types);
-   /* Maybe copy the type_specific bits.
-      NOTE drow/2005-12-09: We do not copy the C++-specific bits like
-@@ -3143,6 +3494,17 @@ copy_type_recursive (struct objfile *objfile,
-   return new_type;
- }
-+/* Recursively copy (deep copy) TYPE.  Return a new type allocated using
-+   malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
-+   or TYPE if it is not associated with OBJFILE.  */
++  if (result)
++    {
++      gdb_bfd_ref (result);
++      gdb_bfd_stash_filename (result);
++    }
 +
-+struct type *
-+copy_type_recursive (struct type *type,
-+                   htab_t copied_types)
-+{
-+  return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
++  return result;
 +}
 +
- /* Make a copy of the given TYPE, except that the pointer & reference
-    types are not preserved.
-    
-@@ -3165,6 +3527,199 @@ copy_type (const struct type *type)
-   return new_type;
- }
-+/* Callback type for main_type_crawl.  */
-+typedef int (*main_type_crawl_iter) (struct type *type, void *data);
++\f
 +
-+/* Iterate all main_type structures reachable through any `struct type *' from
-+   TYPE.  ITER will be called only for one type of each main_type, use
-+   TYPE_CHAIN traversal to find all the type instances.  ITER is being called
-+   for each main_type found.  ITER returns non-zero if main_type_crawl should
-+   depth-first enter the specific type.  ITER must provide some detection for
-+   reentering the same main_type as this function would otherwise endlessly
-+   loop.  */
++/* A callback for htab_traverse that prints a single BFD.  */
 +
-+static void
-+main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
++static int
++print_one_bfd (void **slot, void *data)
 +{
-+  struct type *type_iter;
-+  int i;
-+
-+  if (!type)
-+    return;
++  bfd *abfd = *slot;
++  struct gdb_bfd_data *gdata = bfd_usrdata (abfd);
++  struct ui_out *uiout = data;
++  struct cleanup *inner;
 +
-+  gdb_assert (TYPE_OBJFILE (type) == NULL);
-+
-+  /* `struct cplus_struct_type' handling is unsupported by this function.  */
-+  gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
-+             && TYPE_CODE (type) != TYPE_CODE_UNION)
-+            || !HAVE_CPLUS_STRUCT (type));
-+
-+  if (!(*iter) (type, data))
-+    return;
-+
-+  /* Iterate all the type instances of this main_type.  */
-+  type_iter = type;
-+  do
-+    {
-+      gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
-+
-+      main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
-+      main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
-+
-+      type_iter = TYPE_CHAIN (type_iter);
-+    }
-+  while (type_iter != type);
-+
-+  for (i = 0; i < TYPE_NFIELDS (type); i++)
-+    main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
++  inner = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
++  ui_out_field_int (uiout, "refcount", gdata->refc);
++  ui_out_field_string (uiout, "addr", host_address_to_string (abfd));
++  ui_out_field_string (uiout, "filename", bfd_get_filename (abfd));
++  ui_out_text (uiout, "\n");
++  do_cleanups (inner);
 +
-+  main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
-+  main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
++  return 1;
 +}
 +
-+/* A helper for delete_type which deletes a main_type and the things to which
-+   it refers.  TYPE is a type whose main_type we wish to destroy.  */
++/* Implement the 'maint info bfd' command.  */
 +
 +static void
-+delete_main_type (struct type *type)
++maintenance_info_bfds (char *arg, int from_tty)
 +{
-+  int i;
-+
-+  gdb_assert (TYPE_DISCARDABLE (type));
-+  gdb_assert (TYPE_OBJFILE (type) == NULL);
-+
-+  xfree (TYPE_NAME (type));
-+  xfree (TYPE_TAG_NAME (type));
-+
-+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
-+    {
-+      xfree (TYPE_FIELD_NAME (type, i));
++  struct cleanup *cleanup;
++  struct ui_out *uiout = current_uiout;
 +
-+      if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
-+      xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
-+    }
-+  xfree (TYPE_FIELDS (type));
++  cleanup = make_cleanup_ui_out_table_begin_end (uiout, 3, -1, "bfds");
++  ui_out_table_header (uiout, 10, ui_left, "refcount", "Refcount");
++  ui_out_table_header (uiout, 18, ui_left, "addr", "Address");
++  ui_out_table_header (uiout, 40, ui_left, "filename", "Filename");
 +
-+  gdb_assert (!HAVE_CPLUS_STRUCT (type));
++  ui_out_table_body (uiout);
++  htab_traverse (all_bfds, print_one_bfd, uiout);
 +
-+  xfree (TYPE_MAIN_TYPE (type));
++  do_cleanups (cleanup);
 +}
 +
-+/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
-+   main_type.  TYPE must be a reclaimable type - neither permanent nor objfile
-+   associated.  */
++/* -Wmissing-prototypes */
++extern initialize_file_ftype _initialize_gdb_bfd;
 +
-+static void
-+delete_type_chain (struct type *type)
++void
++_initialize_gdb_bfd (void)
 +{
-+  struct type *type_iter, *type_iter_to_free;
++  all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
++                              NULL, xcalloc, xfree);
 +
-+  gdb_assert (TYPE_DISCARDABLE (type));
-+  gdb_assert (TYPE_OBJFILE (type) == NULL);
++  add_cmd ("bfds", class_maintenance, maintenance_info_bfds, _("\
++List the BFDs that are currently open."),
++         &maintenanceinfolist);
++}
+diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
+new file mode 100644
+index 0000000..f131ba7
+--- /dev/null
++++ b/gdb/gdb_bfd.h
+@@ -0,0 +1,106 @@
++/* Definitions for BFD wrappers used by GDB.
 +
-+  delete_main_type (type);
++   Copyright (C) 2011, 2012
++   Free Software Foundation, Inc.
 +
-+  type_iter = type;
-+  do
-+    {
-+      type_iter_to_free = type_iter;
-+      type_iter = TYPE_CHAIN (type_iter);
-+      xfree (type_iter_to_free);
-+    }
-+  while (type_iter != type);
-+}
++   This file is part of GDB.
 +
-+/* Hash function for type_discardable_table.  */
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
 +
-+static hashval_t
-+type_discardable_hash (const void *p)
-+{
-+  const struct type *type = p;
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
 +
-+  return htab_hash_pointer (TYPE_MAIN_TYPE (type));
-+}
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+/* Equality function for type_discardable_table.  */
++#ifndef GDB_BFD_H
++#define GDB_BFD_H
 +
-+static int
-+type_discardable_equal (const void *a, const void *b)
-+{
-+  const struct type *left = a;
-+  const struct type *right = b;
++/* Make a copy ABFD's filename using bfd_alloc, and reassign it to the
++   BFD.  This ensures that the BFD's filename has the same lifetime as
++   the BFD itself.  */
 +
-+  return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
-+}
++void gdb_bfd_stash_filename (struct bfd *abfd);
 +
-+/* A helper for type_mark_used.  */
++/* Open a read-only (FOPEN_RB) BFD given arguments like bfd_fopen.
++   Returns NULL on error.  On success, returns a new reference to the
++   BFD, which must be freed with gdb_bfd_unref.  BFDs returned by this
++   call are shared among all callers opening the same file.  If FD is
++   not -1, then after this call it is owned by BFD.  */
 +
-+static int
-+type_mark_used_crawl (struct type *type, void *unused)
-+{
-+  if (!TYPE_DISCARDABLE (type))
-+    return 0;
++struct bfd *gdb_bfd_open (const char *name, const char *target, int fd);
 +
-+  if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
-+    return 0;
++/* Increment the reference count of ABFD.  It is fine for ABFD to be
++   NULL; in this case the function does nothing.  */
 +
-+  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
++void gdb_bfd_ref (struct bfd *abfd);
 +
-+  /* Continue the traversal.  */
-+  return 1;
-+}
++/* Decrement the reference count of ABFD.  If this is the last
++   reference, ABFD will be freed.  If ABFD is NULL, this function does
++   nothing.  */
 +
-+/* Mark TYPE and its connected types as used in this free_all_types pass.  */
++void gdb_bfd_unref (struct bfd *abfd);
 +
-+void
-+type_mark_used (struct type *type)
-+{
-+  if (type == NULL)
-+    return;
++/* Try to read or map the contents of the section SECT.  If
++   successful, the section data is returned and *SIZE is set to the
++   size of the section data; this may not be the same as the size
++   according to bfd_get_section_size if the section was compressed.
++   The returned section data is associated with the BFD and will be
++   destroyed when the BFD is destroyed.  There is no other way to free
++   it; for temporary uses of section data, see
++   bfd_malloc_and_get_section.  SECT may not have relocations.  This
++   function will throw on error.  */
 +
-+  if (!TYPE_DISCARDABLE (type))
-+    return;
++const gdb_byte *gdb_bfd_map_section (asection *section, bfd_size_type *size);
 +
-+  main_type_crawl (type, type_mark_used_crawl, NULL);
-+}
++\f
 +
-+/* A traverse callback for type_discardable_table which removes any
-+   type_discardable whose reference count is now zero (unused link).  */
++/* A wrapper for bfd_fopen that initializes the gdb-specific reference
++   count and calls gdb_bfd_stash_filename.  */
 +
-+static int
-+type_discardable_remove (void **slot, void *unused)
-+{
-+  struct type *type = *slot;
++bfd *gdb_bfd_fopen (const char *, const char *, const char *, int);
 +
-+  gdb_assert (TYPE_DISCARDABLE (type));
++/* A wrapper for bfd_openr that initializes the gdb-specific reference
++   count and calls gdb_bfd_stash_filename.  */
 +
-+  if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
-+    {
-+      delete_type_chain (type);
++bfd *gdb_bfd_openr (const char *, const char *);
 +
-+      htab_clear_slot (type_discardable_table, slot);
-+    }
++/* A wrapper for bfd_openw that initializes the gdb-specific reference
++   count and calls gdb_bfd_stash_filename.  */
 +
-+  return 1;
-+}
++bfd *gdb_bfd_openw (const char *, const char *);
 +
-+/* Free all the reclaimable types that have been allocated and that have
-+   currently zero reference counter.
++/* A wrapper for bfd_openr_iovec that initializes the gdb-specific
++   reference count and calls gdb_bfd_stash_filename.  */
 +
-+   This function is called after each command, successful or not.  Use this
-+   cleanup only in the GDB idle state as GDB only marks those types used by
-+   globally tracked objects (with no autovariable references tracking).  */
++bfd *gdb_bfd_openr_iovec (const char *filename, const char *target,
++                        void *(*open_func) (struct bfd *nbfd,
++                                            void *open_closure),
++                        void *open_closure,
++                        file_ptr (*pread_func) (struct bfd *nbfd,
++                                                void *stream,
++                                                void *buf,
++                                                file_ptr nbytes,
++                                                file_ptr offset),
++                        int (*close_func) (struct bfd *nbfd,
++                                           void *stream),
++                        int (*stat_func) (struct bfd *abfd,
++                                          void *stream,
++                                          struct stat *sb));
 +
-+void
-+free_all_types (void)
-+{
-+  /* Mark a new pass.  As GDB checks all the entries were visited after each
-+     pass there cannot be any stale entries already containing the changed
-+     value.  */
-+  type_discardable_age_current ^= 1;
++/* A wrapper for bfd_openr_next_archived_file that initializes the
++   gdb-specific reference count and calls gdb_bfd_stash_filename.  */
 +
-+  observer_notify_mark_used ();
++bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous);
 +
-+  htab_traverse (type_discardable_table, type_discardable_remove, NULL);
-+}
- /* Helper functions to initialize architecture-specific types.  */
-@@ -3511,6 +4066,8 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
-     = lookup_pointer_type (builtin_type->builtin_void);
-   builtin_type->builtin_func_ptr
-     = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
-+  builtin_type->builtin_func_func
-+    = lookup_function_type (builtin_type->builtin_func_ptr);
-   /* This type represents a GDB internal function.  */
-   builtin_type->internal_fn
-@@ -3624,6 +4181,18 @@ objfile_type (struct objfile *objfile)
-                "<text variable, no debug info>", objfile);
-   TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
-     = objfile_type->builtin_int;
-+  objfile_type->nodebug_text_gnu_ifunc_symbol
-+    = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
-+               "<text gnu-indirect-function variable, no debug info>",
-+               objfile);
-+  TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
-+    = objfile_type->nodebug_text_symbol;
-+  objfile_type->nodebug_got_plt_symbol
-+    = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
-+               "<text from jump slot in .got.plt, no debug info>",
-+               objfile);
-+  TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
-+    = objfile_type->nodebug_text_symbol;
-   objfile_type->nodebug_data_symbol
-     = init_type (TYPE_CODE_INT,
-                gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
-@@ -3678,6 +4247,11 @@ void
- _initialize_gdbtypes (void)
- {
-   gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
++/* A wrapper for bfd_fdopenr that initializes the gdb-specific
++   reference count and calls gdb_bfd_stash_filename.  */
 +
-+  type_discardable_table = htab_create_alloc (20, type_discardable_hash,
-+                                           type_discardable_equal, NULL,
-+                                           xcalloc, xfree);
++bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
 +
-   objfile_type_data = register_objfile_data ();
-   add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
-diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
-index 085270e..cb2b88e 100644
---- a/gdb/gdbtypes.h
-+++ b/gdb/gdbtypes.h
-@@ -171,6 +171,7 @@ enum type_flag_value
-   TYPE_FLAG_FIXED_INSTANCE = (1 << 15),
-   TYPE_FLAG_STUB_SUPPORTED = (1 << 16),
-   TYPE_FLAG_NOTTEXT = (1 << 17),
-+  TYPE_FLAG_GNU_IFUNC = (1 << 18),
++#endif /* GDB_BFD_H */
+diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
+index 8142ab9..a2953cc 100644
+--- a/gdb/gdbtypes.c
++++ b/gdb/gdbtypes.c
+@@ -37,6 +37,9 @@
+ #include "gdb_assert.h"
+ #include "hashtab.h"
+ #include "exceptions.h"
++#include "observer.h"
++#include "dwarf2expr.h"
++#include "dwarf2loc.h"
  
-   /* Used for error-checking.  */
-   TYPE_FLAG_MIN = TYPE_FLAG_UNSIGNED
-@@ -214,6 +215,11 @@ enum type_instance_flag_value
+ /* Initialize BADNESS constants.  */
  
- #define TYPE_TARGET_STUB(t)   (TYPE_MAIN_TYPE (t)->flag_target_stub)
+@@ -141,7 +144,16 @@ static void print_bit_vector (B_TYPE *, int);
+ static void print_arg_types (struct field *, int, int);
+ static void dump_fn_fieldlists (struct type *, int);
+ static void print_cplus_stuff (struct type *, int);
++static LONGEST type_length_get (struct type *type, struct type *target_type,
++                              int full_span);
  
-+/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
-+   sticky.  */
-+
-+#define TYPE_DYNAMIC(t)               (TYPE_MAIN_TYPE (t)->flag_dynamic)
++#if 0
++/* The hash table holding all discardable `struct type *' references.  */
++static htab_t type_discardable_table;
 +
- /* Static type.  If this is set, the corresponding type had 
-  * a static modifier.
-  * Note: This may be unnecessary, since static data members
-@@ -271,6 +277,12 @@ enum type_instance_flag_value
++/* Current type_discardable_check pass used for TYPE_DISCARDABLE_AGE.  */
++static int type_discardable_age_current;
++#endif
  
- #define TYPE_NOTTEXT(t)               (TYPE_MAIN_TYPE (t)->flag_nottext)
+ /* Allocate a new OBJFILE-associated type structure and fill it
+    with some defaults.  Space for the type structure is allocated
+@@ -172,6 +184,43 @@ alloc_type (struct objfile *objfile)
+   return type;
+ }
  
-+/* Used only for TYPE_CODE_FUNC where it specifies the real function
-+   address is returned by this function call.  TYPE_TARGET_TYPE determines the
-+   final returned function type to be presented to user.  */
++#if 0
++/* Declare TYPE as discardable on next garbage collection by free_all_types.
++   You must call type_mark_used during each free_all_types to protect TYPE from
++   being deallocated.  */
 +
-+#define TYPE_GNU_IFUNC(t)     (TYPE_MAIN_TYPE (t)->flag_gnu_ifunc)
++static void
++set_type_as_discardable (struct type *type)
++{
++  void **slot;
 +
- /* Type owner.  If TYPE_OBJFILE_OWNED is true, the type is owned by
-    the objfile retrieved as TYPE_OBJFILE.  Otherweise, the type is
-    owned by an architecture; TYPE_OBJFILE is NULL in this case.  */
-@@ -285,6 +297,48 @@ enum type_instance_flag_value
- #define TYPE_DECLARED_CLASS(t) (TYPE_MAIN_TYPE (t)->flag_declared_class)
-+/* Define this type as being reclaimable during free_all_types.  Type is
-+   required to be have TYPE_OBJFILE set to NULL.  Setting this flag requires
-+   initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable.  */
++  gdb_assert (!TYPE_DISCARDABLE (type));
 +
-+#define TYPE_DISCARDABLE(t)   (TYPE_MAIN_TYPE (t)->flag_discardable)
++  TYPE_DISCARDABLE (type) = 1;
++  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
 +
-+/* Marker this type has been visited by the type_mark_used by this
-+   mark-and-sweep types garbage collecting pass.  Current pass is represented
-+   by TYPE_DISCARDABLE_AGE_CURRENT.  */
++  slot = htab_find_slot (type_discardable_table, type, INSERT);
++  gdb_assert (!*slot);
++  *slot = type;
++}
++#endif
 +
-+#define TYPE_DISCARDABLE_AGE(t)       (TYPE_MAIN_TYPE (t)->flag_discardable_age)
++/* Allocate a new type like alloc_type but preserve for it the discardability
++   state of PARENT_TYPE.  */
 +
-+/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)?  */
++static struct type *
++alloc_type_as_parent (struct type *parent_type)
++{
++  struct type *new_type = alloc_type_copy (parent_type);
 +
-+#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
-+  (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
++#if 0
++  if (TYPE_DISCARDABLE (parent_type))
++    set_type_as_discardable (new_type);
++#endif
 +
-+/* Not allocated.  TYPE_ALLOCATED(t) must be NULL in such case.  If this flag
-+   is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated.  If this
-+   flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
-+   determines the actual allocation state.  */
++  return new_type;
++}
 +
-+#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
+ /* Allocate a new GDBARCH-associated type structure and fill it
+    with some defaults.  Space for the type structure is allocated
+    on the heap.  */
+@@ -297,7 +346,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
+   if (typeptr == 0 || *typeptr == 0)  /* We'll need to allocate one.  */
+     {
+-      ntype = alloc_type_copy (type);
++      ntype = alloc_type_as_parent (type);
+       if (typeptr)
+       *typeptr = ntype;
+     }
+@@ -374,7 +423,7 @@ make_reference_type (struct type *type, struct type **typeptr)
+   if (typeptr == 0 || *typeptr == 0)  /* We'll need to allocate one.  */
+     {
+-      ntype = alloc_type_copy (type);
++      ntype = alloc_type_as_parent (type);
+       if (typeptr)
+       *typeptr = ntype;
+     }
+@@ -784,6 +833,7 @@ create_range_type (struct type *result_type, struct type *index_type,
+     TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
+   TYPE_LOW_BOUND (result_type) = low_bound;
+   TYPE_HIGH_BOUND (result_type) = high_bound;
++  TYPE_BYTE_STRIDE (result_type) = 0;
+   if (low_bound >= 0)
+     TYPE_UNSIGNED (result_type) = 1;
+@@ -927,26 +977,31 @@ create_array_type (struct type *result_type,
+   TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
+   TYPE_TARGET_TYPE (result_type) = element_type;
+-  if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+-    low_bound = high_bound = 0;
+-  CHECK_TYPEDEF (element_type);
+-  /* Be careful when setting the array length.  Ada arrays can be
+-     empty arrays with the high_bound being smaller than the low_bound.
+-     In such cases, the array length should be zero.  */
+-  if (high_bound < low_bound)
+-    TYPE_LENGTH (result_type) = 0;
+-  else
+-    TYPE_LENGTH (result_type) =
+-      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
+   TYPE_NFIELDS (result_type) = 1;
+   TYPE_FIELDS (result_type) =
+     (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+   TYPE_INDEX_TYPE (result_type) = range_type;
+   TYPE_VPTR_FIELDNO (result_type) = -1;
+-  /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays.  */
++  /* DWARF blocks may depend on runtime information like
++     DW_OP_PUSH_OBJECT_ADDRESS not being available during the
++     CREATE_ARRAY_TYPE time.  */
++  if (TYPE_RANGE_DATA (range_type)->low.kind != RANGE_BOUND_KIND_CONSTANT
++      || TYPE_RANGE_DATA (range_type)->high.kind != RANGE_BOUND_KIND_CONSTANT
++      || TYPE_DYNAMIC (element_type))
++    TYPE_LENGTH (result_type) = 0;
++  else
++    {
++      CHECK_TYPEDEF (element_type);
++      TYPE_LENGTH (result_type) = type_length_get (result_type, element_type,
++                                                 0);
++    }
+   if (TYPE_LENGTH (result_type) == 0)
+-    TYPE_TARGET_STUB (result_type) = 1;
++    {
++      /* The real size will be computed for specific instances by
++       CHECK_TYPEDEF.  */
++      TYPE_TARGET_STUB (result_type) = 1;
++    }
+   return result_type;
+ }
+@@ -1468,6 +1523,105 @@ stub_noname_complaint (void)
+   complaint (&symfile_complaints, _("stub type has NULL name"));
+ }
++/* Calculate the memory length of array TYPE.
 +
-+/* Not associated.  TYPE_ASSOCIATED(t) must be NULL in such case.  If this flag
-+   is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated.  If
-+   this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
-+   determines the actual association state.  */
++   TARGET_TYPE should be set to `check_typedef (TYPE_TARGET_TYPE (type))' as
++   a performance hint.  Feel free to pass NULL.  Set FULL_SPAN to return the
++   size incl. the possible padding of the last element - it may differ from the
++   cleared FULL_SPAN return value (the expected SIZEOF) for non-zero
++   TYPE_BYTE_STRIDE values.  */
 +
-+#define TYPE_NOT_ASSOCIATED(t)        (TYPE_MAIN_TYPE (t)->flag_not_associated)
++static LONGEST
++type_length_get (struct type *type, struct type *target_type, int full_span)
++{
++  struct type *range_type;
++  LONGEST byte_stride = 0;    /* `= 0' for a false GCC warning.  */
++  LONGEST count, element_size, retval;
 +
-+/* Address of the actual data as for DW_AT_data_location.  Its dwarf block must
-+   not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
-+   false.  If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
-+   is the actual data address value.  If unset and
-+   TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
-+   value_raw_address.  If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
-+   then its DWARF block determines the actual data address.  */
++  if (TYPE_CODE (type) != TYPE_CODE_ARRAY
++      && TYPE_CODE (type) != TYPE_CODE_STRING)
++    return TYPE_LENGTH (type);
 +
-+#define TYPE_DATA_LOCATION_IS_ADDR(t) \
-+  (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
++  /* Avoid executing TYPE_HIGH_BOUND for invalid (unallocated/unassociated)
++     Fortran arrays.  The allocated data will never be used so they can be
++     zero-length.  */
++  if (object_address_data_not_valid (type))
++    return 0;
 +
- /* Constant type.  If this is set, the corresponding type has a
-  * const modifier.
-  */
-@@ -389,11 +443,19 @@ struct main_type
-   unsigned int flag_vector : 1;
-   unsigned int flag_stub_supported : 1;
-   unsigned int flag_nottext : 1;
-+  unsigned int flag_gnu_ifunc : 1;
-   unsigned int flag_fixed_instance : 1;
-   unsigned int flag_objfile_owned : 1;
-   /* True if this type was declared with "class" rather than
-      "struct".  */
-   unsigned int flag_declared_class : 1;
-+  unsigned int flag_discardable : 1;
-+  unsigned int flag_discardable_age : 1;
-+  unsigned int flag_dynamic : 1;
-+  unsigned int flag_range_high_bound_is_count : 1;
-+  unsigned int flag_not_allocated : 1;
-+  unsigned int flag_not_associated : 1;
-+  unsigned int flag_data_location_is_addr : 1;
-   /* A discriminant telling us which field of the type_specific union
-      is being used for this type, if any.  */
-@@ -467,6 +529,20 @@ struct main_type
-   struct type *target_type;
-+  /* For DW_AT_data_location.  */
-+  union
++  range_type = TYPE_INDEX_TYPE (type);
++  if (TYPE_LOW_BOUND_UNDEFINED (range_type)
++      || TYPE_HIGH_BOUND_UNDEFINED (range_type))
++    return 0;
++  count = TYPE_HIGH_BOUND (range_type) - TYPE_LOW_BOUND (range_type) + 1;
++  /* It may happen for wrong DWARF annotations returning garbage data.  */
++  if (count < 0)
++    warning (_("Range for type %s has invalid bounds %s..%s"),
++           TYPE_ERROR_NAME (type), plongest (TYPE_LOW_BOUND (range_type)),
++           plongest (TYPE_HIGH_BOUND (range_type)));
++  /* The code below does not handle count == 0 right.  */
++  if (count <= 0)
++    return 0;
++  if (full_span || count > 1)
 +    {
-+      struct dwarf2_locexpr_baton *dwarf_block;
-+      CORE_ADDR addr;
++      /* We do not use TYPE_ARRAY_BYTE_STRIDE_VALUE (type) here as we want to
++         force FULL_SPAN to 1.  */
++      byte_stride = TYPE_BYTE_STRIDE (range_type);
++      if (byte_stride == 0)
++        {
++        if (target_type == NULL)
++          target_type = check_typedef (TYPE_TARGET_TYPE (type));
++        byte_stride = type_length_get (target_type, NULL, 1);
++      }
 +    }
-+  data_location;
 +
-+  /* For DW_AT_allocated.  */
-+  struct dwarf2_locexpr_baton *allocated;
++  /* For now, we conservatively take the array length to be 0 if its length
++     exceeds UINT_MAX.  The code below assumes that for x < 0,
++     (ULONGEST) x == -x + ULONGEST_MAX + 1, which is technically not guaranteed
++     by C, but is usually true (because it would be true if x were unsigned
++     with its high-order bit on). It uses the fact that high_bound-low_bound is
++     always representable in ULONGEST and that if high_bound-low_bound+1
++     overflows, it overflows to 0.  We must change these tests if we decide to
++     increase the representation of TYPE_LENGTH from unsigned int to ULONGEST.
++     */
 +
-+  /* For DW_AT_associated.  */
-+  struct dwarf2_locexpr_baton *associated;
++  if (full_span)
++    {
++      retval = count * byte_stride;
++      if (count == 0 || retval / count != byte_stride || retval > UINT_MAX)
++      retval = 0;
++      return retval;
++    }
++  if (target_type == NULL)
++    target_type = check_typedef (TYPE_TARGET_TYPE (type));
++  element_size = type_length_get (target_type, NULL, 1);
++  retval = (count - 1) * byte_stride + element_size;
++  if (retval < element_size
++      || (byte_stride != 0
++          && (retval - element_size) / byte_stride != count - 1)
++      || retval > UINT_MAX)
++    retval = 0;
++  return retval;
++}
 +
-   /* For structure and union types, a description of each field.
-      For set and pascal array types, there is one "field",
-      whose type is the domain type of the set or array.
-@@ -540,13 +616,34 @@ struct main_type
-     struct range_bounds
-     {
-+      struct
-+      {
-+        union
-+          {
-+            LONGEST constant;
-+            struct dwarf2_locexpr_baton *dwarf_block;
-+            struct
-+              {
-+                struct dwarf2_loclist_baton *loclist;
-+                struct type *type;
-+              }
-+            dwarf_loclist;
-+          }
-+        u;
-+        enum range_bound_kind
-+          {
-+            RANGE_BOUND_KIND_CONSTANT,
-+            RANGE_BOUND_KIND_DWARF_BLOCK,
-+            RANGE_BOUND_KIND_DWARF_LOCLIST
-+          }
-+        kind;
-+      }
-       /* Low bound of range. */
--
--      LONGEST low;
--
-+      low,
-       /* High bound of range. */
--
--      LONGEST high;
-+      high,
-+      /* Byte stride of range. */
-+      byte_stride;
-       /* Flags indicating whether the values of low and high are
-          valid.  When true, the respective range value is
-@@ -889,9 +986,9 @@ extern void allocate_gnat_aux_type (struct type *);
- #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
- #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
- #define TYPE_CHAIN(thistype) (thistype)->chain
--/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
--   But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
--   so you only have to call check_typedef once.  Since allocate_value
-+/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
-+   check_typedef.  But check_typedef does set the TYPE_LENGTH of the TYPEDEF
-+   type, so you only have to call check_typedef once.  Since allocate_value
-    calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe.  */
- #define TYPE_LENGTH(thistype) (thistype)->length
- /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
-@@ -899,11 +996,16 @@ extern void allocate_gnat_aux_type (struct type *);
- #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
- #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
- #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
-+#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
-+#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
-+#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
-+#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
- #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
- #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
--#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
--#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
-+#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low.u.constant
-+#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high.u.constant
-+#define TYPE_BYTE_STRIDE(range_type) TYPE_RANGE_DATA(range_type)->byte_stride.u.constant
- #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
-    TYPE_RANGE_DATA(range_type)->low_undefined
- #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
-@@ -920,7 +1022,14 @@ extern void allocate_gnat_aux_type (struct type *);
-    (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
- #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
--   (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
-+  TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
-+
-+/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
-+   element size if no specific stride value is known.  */
-+#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype)               \
-+  (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0        \
-+   ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype))               \
-+   : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
- /* C++ */
-@@ -1141,6 +1250,10 @@ struct builtin_type
-      (*) () can server as a generic function pointer.  */
-   struct type *builtin_func_ptr;
-+  /* `function returning pointer to function (returning void)' type.
-+     The final void return type is not significant for it.  */
-+  struct type *builtin_func_func;
-+
-   /* Special-purpose types.  */
-@@ -1181,6 +1294,8 @@ struct objfile_type
-   /* Types used for symbols with no debug information.  */
-   struct type *nodebug_text_symbol;
-+  struct type *nodebug_text_gnu_ifunc_symbol;
-+  struct type *nodebug_got_plt_symbol;
-   struct type *nodebug_data_symbol;
-   struct type *nodebug_unknown_symbol;
-   struct type *nodebug_tls_symbol;
-@@ -1328,6 +1443,18 @@ extern struct type *create_array_type (struct type *, struct type *,
-                                      struct type *);
- extern struct type *lookup_array_range_type (struct type *, int, int);
-+extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
-+                                              int fieldno);
-+
-+extern int type_range_high_bound_internal (struct type *range_type);
-+
-+extern int type_range_count_bound_internal (struct type *range_type);
-+
-+extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
-+                                                struct type *element_type);
-+
-+extern void finalize_type (struct type *type);
-+
- extern struct type *create_string_type (struct type *, struct type *,
-                                       struct type *);
- extern struct type *lookup_string_range_type (struct type *, int, int);
-@@ -1370,6 +1497,8 @@ extern int is_public_ancestor (struct type *, struct type *);
- extern int is_unique_ancestor (struct type *, struct value *);
-+extern void type_mark_used (struct type *type);
-+
- /* Overload resolution */
- #define LENGTH_MATCH(bv) ((bv)->rank[0])
-@@ -1432,10 +1561,11 @@ extern void maintenance_print_type (char *, int);
- extern htab_t create_copied_types_hash (struct objfile *objfile);
--extern struct type *copy_type_recursive (struct objfile *objfile,
--                                       struct type *type,
-+extern struct type *copy_type_recursive (struct type *type,
-                                        htab_t copied_types);
- extern struct type *copy_type (const struct type *type);
-+extern void free_all_types (void);
-+
- #endif /* GDBTYPES_H */
-diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
-index 4fce1ac..144a899 100644
---- a/gdb/i386-linux-nat.c
-+++ b/gdb/i386-linux-nat.c
-@@ -747,6 +747,21 @@ i386_linux_dr_unset_status (unsigned long mask)
-     }
- }
-+/* See i386_dr_low_type.detach.  Do not use wrappers i386_linux_dr_set_control
-+   or i386_linux_dr_reset_addr as they would modify the register cache
-+   (i386_linux_dr).  */
++/* Prepare TYPE after being read in by the backend.  Currently this function
++   only propagates the TYPE_DYNAMIC flag.  */
 +
-+static void
-+i386_linux_dr_detach (void)
++void
++finalize_type (struct type *type)
 +{
-+  int regnum;
-+
-+  i386_linux_dr_set (inferior_ptid, DR_CONTROL, 0);
-+  i386_linux_dr_unset_status (~0UL);
-+  for (regnum = DR_FIRSTADDR; regnum <= DR_LASTADDR; regnum++)
-+    i386_linux_dr_set (inferior_ptid, regnum, 0);
-+}
-+
- static void
- i386_linux_new_thread (ptid_t ptid)
- {
-@@ -976,6 +991,7 @@ _initialize_i386_linux_nat (void)
-   i386_dr_low.reset_addr = i386_linux_dr_reset_addr;
-   i386_dr_low.get_status = i386_linux_dr_get_status;
-   i386_dr_low.unset_status = i386_linux_dr_unset_status;
-+  i386_dr_low.detach = i386_linux_dr_detach;
-   i386_set_debug_register_length (4);
-   /* Override the default ptrace resume method.  */
-diff --git a/gdb/i386-nat.c b/gdb/i386-nat.c
-index eaa3644..0921c7e 100644
---- a/gdb/i386-nat.c
-+++ b/gdb/i386-nat.c
-@@ -533,6 +533,17 @@ i386_remove_watchpoint (CORE_ADDR addr, int len, int type,
-   return retval;
- }
-+/* See target_detach_watchpoints.  */
++  int i;
 +
-+static int
-+i386_detach_watchpoints (void)
-+{
-+  if (i386_dr_low.detach)
-+    i386_dr_low.detach ();
++  for (i = 0; i < TYPE_NFIELDS (type); ++i)
++    if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
++      break;
 +
-+  return 0;
++  /* FIXME: cplus_stuff is ignored here.  */
++  if (i < TYPE_NFIELDS (type)
++      || (TYPE_VPTR_BASETYPE (type) && TYPE_DYNAMIC (TYPE_VPTR_BASETYPE (type)))
++      || (TYPE_TARGET_TYPE (type) && TYPE_DYNAMIC (TYPE_TARGET_TYPE (type))))
++    TYPE_DYNAMIC (type) = 1;
 +}
 +
- /* Return non-zero if we can watch a memory region that starts at
-    address ADDR and whose length is LEN bytes.  */
-@@ -685,6 +696,7 @@ i386_use_watchpoints (struct target_ops *t)
-   t->to_stopped_data_address = i386_stopped_data_address;
-   t->to_insert_watchpoint = i386_insert_watchpoint;
-   t->to_remove_watchpoint = i386_remove_watchpoint;
-+  t->to_detach_watchpoints = i386_detach_watchpoints;
-   t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
-   t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
- }
-diff --git a/gdb/i386-nat.h b/gdb/i386-nat.h
-index 7317e7d..ea914a5 100644
---- a/gdb/i386-nat.h
-+++ b/gdb/i386-nat.h
-@@ -62,6 +62,10 @@ extern void i386_use_watchpoints (struct target_ops *);
-       unset_status             -- unset the specified bits of the debug
-                                 status (DR6) register for all LWPs
-+      detach                   -- clear all debug registers of only the
-+                                INFERIOR_PTID task without affecting any
-+                                register caches.
-+
-    Additionally, the native file should set the debug_register_length
-    field to 4 or 8 depending on the number of bytes used for
-    deubg registers.  */
-@@ -73,6 +77,7 @@ struct i386_dr_low_type
-     void (*reset_addr) (int);
-     unsigned long (*get_status) (void);
-     void (*unset_status) (unsigned long);
-+    void (*detach) (void);
-     int debug_register_length;
-   };
-diff --git a/gdb/infcall.c b/gdb/infcall.c
-index 0c9a3af..957ec1d 100644
---- a/gdb/infcall.c
-+++ b/gdb/infcall.c
-@@ -225,6 +225,56 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
-   return value_cast (type, arg);
- }
+ /* Find the real type of TYPE.  This function returns the real type,
+    after removing all layers of typedefs, and completing opaque or stub
+    types.  Completion changes the TYPE argument, but stripping of
+@@ -1634,52 +1788,37 @@ check_typedef (struct type *type)
+         }
+     }
  
-+/* Call gnu-ifunc (STT_GNU_IFUNC - a function returning addresss of a real
-+   function to call).  PC is the gnu-ifunc function entry.  Function returns
-+   function entry of the gnu-ifunc-resolved function to call.  If RETVAL_TYPEP
-+   is not NULL fill in *RETVAL_TYPEP with return type of the gnu-ifunc-resolved
-+   function to call.  Keep *RETVAL_TYPEP intact if the return type could not be
-+   found.  */
-+
-+static CORE_ADDR
-+gnu_ifunc_resolve (struct gdbarch *gdbarch, CORE_ADDR pc)
-+{
-+  char *name_at_pc;
-+  CORE_ADDR start_at_pc, address;
-+  struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
-+  struct value *function, *address_val;
-+
-+  if (find_pc_partial_function (pc, &name_at_pc, &start_at_pc, NULL)
-+      && start_at_pc == pc)
+-  if (TYPE_TARGET_STUB (type))
++  /* copy_type_recursive automatically makes the resulting type containing only
++     constant values expected by the callers of this function.  */
++  if (TYPE_DYNAMIC (type))
 +    {
-+      if (resolve_gnu_ifunc (name_at_pc, &address))
-+      return address;
-+    }
-+  else
-+    name_at_pc = NULL;
-+
-+  function = allocate_value (func_func_type);
-+  set_value_address (function, pc);
-+
-+  /* gnu-ifuncs have no arguments.  FUNCTION is the function entry address
-+     while ADDRESS is a possible function descriptor..  */
-+  address_val = call_function_by_hand (function, 0, NULL);
-+  address = value_as_address (address_val);
-+
-+  if (name_at_pc)
-+    gnu_ifunc_record_cache (gdbarch, name_at_pc, address);
-+
-+  return gdbarch_convert_from_func_ptr_addr (gdbarch, address, &current_target);
-+}
-+
-+static struct type *
-+find_function_return_type (CORE_ADDR pc)
-+{
-+  struct symbol *sym = find_pc_function (pc);
-+
-+  if (sym != NULL && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) == pc
-+      && SYMBOL_TYPE (sym) != NULL)
-+    return TYPE_TARGET_TYPE (SYMBOL_TYPE (sym));
++      htab_t copied_types;
 +
-+  return NULL;
-+}
++      copied_types = create_copied_types_hash (NULL);
++      type = copy_type_recursive (type, copied_types);
++      htab_delete (copied_types);
 +
- /* Determine a function's address and its return type from its value.
-    Calls error() if the function is not valid for calling.  */
-@@ -233,7 +283,6 @@ find_function_addr (struct value *function, struct type **retval_type)
- {
-   struct type *ftype = check_typedef (value_type (function));
-   struct gdbarch *gdbarch = get_type_arch (ftype);
--  enum type_code code = TYPE_CODE (ftype);
-   struct type *value_type = NULL;
-   CORE_ADDR funaddr;
-@@ -241,24 +290,34 @@ find_function_addr (struct value *function, struct type **retval_type)
-      part of it.  */
-   /* Determine address to call.  */
--  if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
--    {
--      funaddr = value_address (function);
--      value_type = TYPE_TARGET_TYPE (ftype);
--    }
--  else if (code == TYPE_CODE_PTR)
-+  if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
-+      || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
-+    funaddr = value_address (function);
-+  else if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
-     {
-       funaddr = value_as_address (function);
-       ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
-       if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
-         || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
-+      funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
-+                                                    &current_target);
++      gdb_assert (TYPE_DYNAMIC (type) == 0);
++      /* Force TYPE_LENGTH (type) recalculation.  */
++      TYPE_DYNAMIC (type) = 1;
 +    }
-+  if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
-+      || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
-+    {
-+      value_type = TYPE_TARGET_TYPE (ftype);
 +
-+      if (TYPE_GNU_IFUNC (ftype))
++  if (TYPE_TARGET_STUB (type) || TYPE_DYNAMIC (type))
+     {
+-      struct type *range_type;
+       struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
++      if (TYPE_DYNAMIC (type))
++      TYPE_TARGET_TYPE (type) = target_type;
+       if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
        {
--        funaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funaddr,
--                                                      &current_target);
--        value_type = TYPE_TARGET_TYPE (ftype);
-+        funaddr = gnu_ifunc_resolve (gdbarch, funaddr);
-+
-+        /* Skip querying the function symbol if no RETVAL_TYPE has been
-+           asked for.  */
-+        if (retval_type)
-+          value_type = find_function_return_type (funaddr);
+         /* Nothing we can do.  */
+       }
+       else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+-             && TYPE_NFIELDS (type) == 1
+-             && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
+-                 == TYPE_CODE_RANGE))
++             || TYPE_CODE (type) == TYPE_CODE_STRING)
+       {
+         /* Now recompute the length of the array type, based on its
+-           number of elements and the target type's length.
+-           Watch out for Ada null Ada arrays where the high bound
+-           is smaller than the low bound.  */
+-        const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
+-        const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
+-        ULONGEST len;
+-
+-        if (high_bound < low_bound)
+-          len = 0;
+-        else
+-          {
+-            /* For now, we conservatively take the array length to be 0
+-               if its length exceeds UINT_MAX.  The code below assumes
+-               that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1,
+-               which is technically not guaranteed by C, but is usually true
+-               (because it would be true if x were unsigned with its
+-               high-order bit on).  It uses the fact that
+-               high_bound-low_bound is always representable in
+-               ULONGEST and that if high_bound-low_bound+1 overflows,
+-               it overflows to 0.  We must change these tests if we 
+-               decide to increase the representation of TYPE_LENGTH
+-               from unsigned int to ULONGEST.  */
+-            ULONGEST ulow = low_bound, uhigh = high_bound;
+-            ULONGEST tlen = TYPE_LENGTH (target_type);
+-
+-            len = tlen * (uhigh - ulow + 1);
+-            if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh 
+-                || len > UINT_MAX)
+-              len = 0;
+-          }
+-        TYPE_LENGTH (type) = len;
++           number of elements and the target type's length.  */
++        TYPE_LENGTH (type) = type_length_get (type, target_type, 0);
+         TYPE_TARGET_STUB (type) = 0;
+       }
+       else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
+@@ -1687,6 +1826,7 @@ check_typedef (struct type *type)
+         TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
+         TYPE_TARGET_STUB (type) = 0;
        }
++      TYPE_DYNAMIC (type) = 0;
      }
--  else if (code == TYPE_CODE_INT)
-+  else if (TYPE_CODE (ftype) == TYPE_CODE_INT)
-     {
-       /* Handle the case of functions lacking debugging info.
-          Their values are characters since their addresses are char */
-diff --git a/gdb/infcmd.c b/gdb/infcmd.c
-index c4cdb06..d213f6a 100644
---- a/gdb/infcmd.c
-+++ b/gdb/infcmd.c
-@@ -822,7 +822,7 @@ nexti_command (char *count_string, int from_tty)
-   step_1 (1, 1, count_string);
- }
--static void
-+void
- delete_longjmp_breakpoint_cleanup (void *arg)
- {
-   int thread = * (int *) arg;
-@@ -862,10 +862,13 @@ step_1 (int skip_subroutines, int single_inst, char *count_string)
-   if (!single_inst || skip_subroutines)               /* leave si command alone */
-     {
-+      struct thread_info *tp = inferior_thread ();
-+
-       if (in_thread_list (inferior_ptid))
-       thread = pid_to_thread_id (inferior_ptid);
-       set_longjmp_breakpoint (thread);
-+      tp->initiating_frame = get_frame_id (get_current_frame ());
  
-       make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
-     }
-@@ -1219,6 +1222,15 @@ signal_command (char *signum_exp, int from_tty)
-   proceed ((CORE_ADDR) -1, oursig, 0);
+   type = make_qualified_type (type, instance_flags, NULL);
+@@ -3345,33 +3485,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
  }
  
-+/* A continuation callback for until_next_command.  */
-+
-+static void
-+until_next_continuation (void *arg)
-+{
-+  struct thread_info *tp = arg;
-+  delete_longjmp_breakpoint (tp->num);
-+}
-+
- /* Proceed until we reach a different source line with pc greater than
-    our current one or exit the function.  We skip calls in both cases.
-@@ -1235,6 +1247,8 @@ until_next_command (int from_tty)
-   struct symbol *func;
-   struct symtab_and_line sal;
-   struct thread_info *tp = inferior_thread ();
-+  int thread = tp->num;
-+  struct cleanup *old_chain;
-   clear_proceed_status ();
-   set_step_frame ();
-@@ -1270,7 +1284,19 @@ until_next_command (int from_tty)
-   tp->step_multi = 0;         /* Only one call to proceed */
+ /* Allocate the hash table used by copy_type_recursive to walk
+-   types without duplicates.  We use OBJFILE's obstack, because
+-   OBJFILE is about to be deleted.  */
++   types without duplicates.   */
  
-+  set_longjmp_breakpoint (thread);
-+  tp->initiating_frame = get_frame_id (frame);
-+  old_chain = make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
-+
-   proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 1);
-+
-+  if (target_can_async_p () && is_running (inferior_ptid))
+ htab_t
+ create_copied_types_hash (struct objfile *objfile)
+ {
+-  return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
+-                             NULL, &objfile->objfile_obstack,
+-                             hashtab_obstack_allocate,
+-                             dummy_obstack_deallocate);
++  if (objfile == NULL)
 +    {
-+      discard_cleanups (old_chain);
-+      add_continuation (tp, until_next_continuation, tp, NULL);
++      /* NULL OBJFILE is for TYPE_DYNAMIC types already contained in
++       OBJFILE_MALLOC memory, such as those from VALUE_HISTORY_CHAIN.  Table
++       element entries get allocated by xmalloc - so use xfree.  */
++      return htab_create (1, type_pair_hash, type_pair_eq, xfree);
 +    }
 +  else
-+    do_cleanups (old_chain);
- }
- static void
-@@ -1463,6 +1489,7 @@ finish_command_continuation (void *arg)
-   if (bs != NULL && tp->proceed_to_finish)
-     observer_notify_normal_stop (bs, 1 /* print frame */);
-   delete_breakpoint (a->breakpoint);
-+  delete_longjmp_breakpoint (inferior_thread ()->num);
++    {
++      /* Use OBJFILE's obstack, because OBJFILE is about to be deleted.  Table
++       element entries get allocated by xmalloc - so use xfree.  */
++      return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
++                                 xfree, &objfile->objfile_obstack,
++                                 hashtab_obstack_allocate,
++                                 dummy_obstack_deallocate);
++    }
  }
  
- static void
-@@ -1546,6 +1573,7 @@ finish_forward (struct symbol *function, struct frame_info *frame)
-   struct breakpoint *breakpoint;
-   struct cleanup *old_chain;
-   struct finish_command_continuation_args *cargs;
-+  int thread = tp->num;
-   sal = find_pc_line (get_frame_pc (frame), 0);
-   sal.pc = get_frame_pc (frame);
-@@ -1556,6 +1584,10 @@ finish_forward (struct symbol *function, struct frame_info *frame)
-   old_chain = make_cleanup_delete_breakpoint (breakpoint);
-+  set_longjmp_breakpoint (thread);
-+  tp->initiating_frame = get_frame_id (frame);
-+  make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
-+
-   tp->proceed_to_finish = 1;    /* We want stop_registers, please...  */
-   cargs = xmalloc (sizeof (*cargs));
-diff --git a/gdb/inferior.h b/gdb/inferior.h
-index 5abec68..e309277 100644
---- a/gdb/inferior.h
-+++ b/gdb/inferior.h
-@@ -291,6 +291,8 @@ extern void interrupt_target_command (char *args, int from_tty);
- extern void interrupt_target_1 (int all_threads);
-+extern void delete_longjmp_breakpoint_cleanup (void *arg);
-+
- extern void detach_command (char *, int);
- extern void notice_new_inferior (ptid_t, int, int);
-diff --git a/gdb/infrun.c b/gdb/infrun.c
-index 54b1d9f..58d045a 100644
---- a/gdb/infrun.c
-+++ b/gdb/infrun.c
-@@ -45,6 +45,8 @@
- #include "language.h"
- #include "solib.h"
- #include "main.h"
-+#include "dictionary.h"
-+#include "block.h"
- #include "gdb_assert.h"
- #include "mi/mi-common.h"
- #include "event-top.h"
-@@ -367,6 +369,7 @@ follow_fork (void)
-      parent thread structure's run control related fields, not just these.
-      Initialized to avoid "may be used uninitialized" warnings from gcc.  */
-   struct breakpoint *step_resume_breakpoint = NULL;
-+  struct breakpoint *exception_resume_breakpoint = NULL;
-   CORE_ADDR step_range_start = 0;
-   CORE_ADDR step_range_end = 0;
-   struct frame_id step_frame_id = { 0 };
-@@ -419,6 +422,8 @@ follow_fork (void)
-           step_range_start = tp->step_range_start;
-           step_range_end = tp->step_range_end;
-           step_frame_id = tp->step_frame_id;
-+          exception_resume_breakpoint
-+            = clone_momentary_breakpoint (tp->exception_resume_breakpoint);
-           /* For now, delete the parent's sr breakpoint, otherwise,
-              parent/child sr breakpoints are considered duplicates,
-@@ -429,6 +434,7 @@ follow_fork (void)
-           tp->step_range_start = 0;
-           tp->step_range_end = 0;
-           tp->step_frame_id = null_frame_id;
-+          delete_exception_resume_breakpoint (tp);
-         }
-       parent = inferior_ptid;
-@@ -470,6 +476,8 @@ follow_fork (void)
-                   tp->step_range_start = step_range_start;
-                   tp->step_range_end = step_range_end;
-                   tp->step_frame_id = step_frame_id;
-+                  tp->exception_resume_breakpoint
-+                    = exception_resume_breakpoint;
-                 }
-               else
-                 {
-@@ -523,6 +531,9 @@ follow_inferior_reset_breakpoints (void)
-   if (tp->step_resume_breakpoint)
-     breakpoint_re_set_thread (tp->step_resume_breakpoint);
-+  if (tp->exception_resume_breakpoint)
-+    breakpoint_re_set_thread (tp->exception_resume_breakpoint);
-+
-   /* Reinsert all breakpoints in the child.  The user may have set
-      breakpoints after catching the fork, in which case those
-      were never set in the child, but only in the parent.  This makes
-@@ -760,6 +771,7 @@ follow_exec (ptid_t pid, char *execd_pathname)
-   /* If there was one, it's gone now.  We cannot truly step-to-next
-      statement through an exec(). */
-   th->step_resume_breakpoint = NULL;
-+  th->exception_resume_breakpoint = NULL;
-   th->step_range_start = 0;
-   th->step_range_end = 0;
-@@ -2190,6 +2202,8 @@ static void insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
-                                                 struct symtab_and_line sr_sal,
-                                                 struct frame_id sr_id);
- static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
-+static void check_exception_resume (struct execution_control_state *,
-+                                  struct frame_info *, struct symbol *);
- static void stop_stepping (struct execution_control_state *ecs);
- static void prepare_to_wait (struct execution_control_state *ecs);
-@@ -2313,6 +2327,7 @@ delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
-     return 0;
+-/* Recursively copy (deep copy) TYPE, if it is associated with
+-   OBJFILE.  Return a new type allocated using malloc, a saved type if
+-   we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
+-   not associated with OBJFILE.  */
++/* A helper for copy_type_recursive.  This does all the work.  OBJFILE is used
++   only for an assertion checking.  */
  
-   delete_step_resume_breakpoint (info);
-+  delete_exception_resume_breakpoint (info);
-   return 0;
- }
+-struct type *
+-copy_type_recursive (struct objfile *objfile, 
+-                   struct type *type,
+-                   htab_t copied_types)
++static struct type *
++copy_type_recursive_1 (struct objfile *objfile, 
++                     struct type *type,
++                     htab_t copied_types)
+ {
+   struct type_pair *stored, pair;
+   void **slot;
+   struct type *new_type;
  
-@@ -2337,6 +2352,7 @@ delete_step_thread_step_resume_breakpoint (void)
-       struct thread_info *tp = inferior_thread ();
+-  if (! TYPE_OBJFILE_OWNED (type))
++  if (! TYPE_OBJFILE_OWNED (type) && !TYPE_DYNAMIC (type))
+     return type;
  
-       delete_step_resume_breakpoint (tp);
-+      delete_exception_resume_breakpoint (tp);
-     }
-   else
-     /* In all-stop mode, delete all step-resume and longjmp-resume
-@@ -3241,6 +3257,10 @@ handle_inferior_event (struct execution_control_state *ecs)
+   /* This type shouldn't be pointing to any types in other objfiles;
+@@ -3386,9 +3535,10 @@ copy_type_recursive (struct objfile *objfile,
+   new_type = alloc_type_arch (get_type_arch (type));
  
-       stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
+   /* We must add the new type to the hash table immediately, in case
+-     we encounter this type again during a recursive call below.  */
+-  stored
+-    = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
++     we encounter this type again during a recursive call below.  Memory could
++     be allocated from OBJFILE in the case we will be removing OBJFILE, this
++     optimization is missed and xfree is called for it from COPIED_TYPES.  */
++  stored = xmalloc (sizeof (*stored));
+   stored->old = type;
+   stored->new = new_type;
+   *slot = stored;
+@@ -3399,6 +3549,21 @@ copy_type_recursive (struct objfile *objfile,
+   TYPE_OBJFILE_OWNED (new_type) = 0;
+   TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
  
-+      /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
-+       confuse bpstat_stop_status and bpstat_explains_signal.  */
-+      watchpoints_triggered (&ecs->ws);
++#if 0
++  /* TYPE_MAIN_TYPE memory copy above rewrote the TYPE_DISCARDABLE flag so we
++     need to initialize it again.  And even if TYPE was already discardable
++     NEW_TYPE so far is not registered in TYPE_DISCARDABLE_TABLE.  */
++  TYPE_DISCARDABLE (new_type) = 0;
++  set_type_as_discardable (new_type);
++#endif
 +
-       ecs->event_thread->stop_bpstat
-       = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
-                             stop_pc, ecs->ptid);
-@@ -3328,6 +3348,10 @@ handle_inferior_event (struct execution_control_state *ecs)
-       stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
-+      /* Clear WATCHPOINT_TRIGGERED values from previous stop which could
-+       confuse bpstat_stop_status and bpstat_explains_signal.  */
-+      watchpoints_triggered (&ecs->ws);
++  /* Pre-clear the fields processed by delete_main_type.  If DWARF block
++     evaluations below call error we would leave an unfreeable TYPE.  */
++  TYPE_TARGET_TYPE (new_type) = NULL;
++  TYPE_VPTR_BASETYPE (new_type) = NULL;
++  TYPE_NFIELDS (new_type) = 0;
++  TYPE_FIELDS (new_type) = NULL;
 +
-       /* Do whatever is necessary to the parent branch of the vfork.  */
-       handle_vfork_child_exec_or_exit (1);
-@@ -4076,23 +4100,33 @@ process_event_stop_test:
-       ecs->event_thread->stepping_over_breakpoint = 1;
--      if (!gdbarch_get_longjmp_target_p (gdbarch)
--          || !gdbarch_get_longjmp_target (gdbarch, frame, &jmp_buf_pc))
-+      if (what.is_longjmp)
-         {
--          if (debug_infrun)
--            fprintf_unfiltered (gdb_stdlog, "\
-+          if (!gdbarch_get_longjmp_target_p (gdbarch)
-+              || !gdbarch_get_longjmp_target (gdbarch,
-+                                              frame, &jmp_buf_pc))
-+            {
-+              if (debug_infrun)
-+                fprintf_unfiltered (gdb_stdlog, "\
- infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
--          keep_going (ecs);
--          return;
--        }
-+              keep_going (ecs);
-+              return;
-+            }
--      /* We're going to replace the current step-resume breakpoint
--         with a longjmp-resume breakpoint.  */
--      delete_step_resume_breakpoint (ecs->event_thread);
-+          /* We're going to replace the current step-resume breakpoint
-+             with a longjmp-resume breakpoint.  */
-+          delete_step_resume_breakpoint (ecs->event_thread);
--      /* Insert a breakpoint at resume address.  */
--      insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
-+          /* Insert a breakpoint at resume address.  */
-+          insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
-+        }
-+      else
-+        {
-+          struct symbol *func = get_frame_function (frame);
-+          if (func)
-+            check_exception_resume (ecs, frame, func);
-+        }
-       keep_going (ecs);
-       return;
-@@ -4101,8 +4135,52 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
-         fprintf_unfiltered (gdb_stdlog,
-                             "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
+   if (TYPE_NAME (type))
+     TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
+   if (TYPE_TAG_NAME (type))
+@@ -3407,12 +3572,48 @@ copy_type_recursive (struct objfile *objfile,
+   TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
+   TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
  
--      gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
--      delete_step_resume_breakpoint (ecs->event_thread);
-+      if (what.is_longjmp)
-+        {
-+          gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
-+          delete_step_resume_breakpoint (ecs->event_thread);
-+        }
-+      else
-+        {
-+          /* There are several cases to consider.
-+
-+             1. The initiating frame no longer exists.  In this case
-+             we must stop, because the exception has gone too far.
-+
-+             2. The initiating frame exists, and is the same as the
-+             current frame.  We stop, because the exception has been
-+             caught.
-+
-+             3. The initiating frame exists and is different from
-+             the current frame.  This means the exception has been
-+             caught beneath the initiating frame, so keep going.  */
-+          struct frame_info *init_frame
-+            = frame_find_by_id (ecs->event_thread->initiating_frame);
-+
-+          gdb_assert (ecs->event_thread->exception_resume_breakpoint != NULL);
-+          delete_exception_resume_breakpoint (ecs->event_thread);
++  if (TYPE_ALLOCATED (new_type))
++    {
++      gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
 +
-+          if (init_frame)
-+            {
-+              struct frame_id current_id
-+                = get_frame_id (get_current_frame ());
-+              if (frame_id_eq (current_id,
-+                               ecs->event_thread->initiating_frame))
-+                {
-+                  /* Case 2.  Fall through.  */
-+                }
-+              else
-+                {
-+                  /* Case 3.  */
-+                  keep_going (ecs);
-+                  return;
-+                }
-+            }
++      if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
++        TYPE_NOT_ALLOCATED (new_type) = 1;
++      TYPE_ALLOCATED (new_type) = NULL;
++    }
 +
-+          /* For Cases 1 and 2, remove the step-resume breakpoint,
-+             if it exists.  */
-+          delete_step_resume_breakpoint (ecs->event_thread);
-+        }
-       ecs->event_thread->stop_step = 1;
-       print_stop_reason (END_STEPPING_RANGE, 0);
-@@ -5070,6 +5148,97 @@ insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
-     set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
- }
-+/* Insert an exception resume breakpoint.  TP is the thread throwing
-+   the exception.  The block B is the block of the unwinder debug hook
-+   function.  FRAME is the frame corresponding to the call to this
-+   function.  SYM is the symbol of the function argument holding the
-+   target PC of the exception.  */
++  if (TYPE_ASSOCIATED (new_type))
++    {
++      gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
 +
-+static void
-+insert_exception_resume_breakpoint (struct thread_info *tp,
-+                                  struct block *b,
-+                                  struct frame_info *frame,
-+                                  struct symbol *sym)
-+{
-+  struct gdb_exception e;
++      if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
++        TYPE_NOT_ASSOCIATED (new_type) = 1;
++      TYPE_ASSOCIATED (new_type) = NULL;
++    }
 +
-+  /* We want to ignore errors here.  */
-+  TRY_CATCH (e, RETURN_MASK_ALL)
++  if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
++      && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
 +    {
-+      struct symbol *vsym;
-+      struct value *value;
-+      CORE_ADDR handler;
-+      struct breakpoint *bp;
-+
-+      vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
-+      value = read_var_value (vsym, frame);
-+      /* If the value was optimized out, revert to the old behavior.  */
-+      if (! value_optimized_out (value))
++      if (TYPE_NOT_ALLOCATED (new_type)
++          || TYPE_NOT_ASSOCIATED (new_type))
++      TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
++      else
 +      {
-+        handler = value_as_address (value);
-+
-+        if (debug_infrun)
-+          fprintf_unfiltered (gdb_stdlog,
-+                              "infrun: exception resume at %lx\n",
-+                              (unsigned long) handler);
-+
-+        bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
-+                                             handler, bp_exception_resume);
-+        bp->thread = tp->num;
-+        inferior_thread ()->exception_resume_breakpoint = bp;
++        TYPE_DATA_LOCATION_IS_ADDR (new_type) = 1;
++        TYPE_DATA_LOCATION_ADDR (new_type) = dwarf_locexpr_baton_eval
++                                  (TYPE_DATA_LOCATION_DWARF_BLOCK (new_type));
 +      }
 +    }
-+}
 +
-+/* This is called when an exception has been intercepted.  Check to
-+   see whether the exception's destination is of interest, and if so,
-+   set an exception resume breakpoint there.  */
+   /* Copy the fields.  */
+   if (TYPE_NFIELDS (type))
+     {
+       int i, nfields;
++      /* TYPE_CODE_RANGE uses TYPE_RANGE_DATA of the union with TYPE_FIELDS.  */
++      gdb_assert (TYPE_CODE (type) != TYPE_CODE_RANGE);
 +
-+static void
-+check_exception_resume (struct execution_control_state *ecs,
-+                      struct frame_info *frame, struct symbol *func)
-+{
-+  struct gdb_exception e;
+       nfields = TYPE_NFIELDS (type);
++      TYPE_NFIELDS (new_type) = nfields;
+       TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
+       for (i = 0; i < nfields; i++)
+       {
+@@ -3421,8 +3622,8 @@ copy_type_recursive (struct objfile *objfile,
+         TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
+         if (TYPE_FIELD_TYPE (type, i))
+           TYPE_FIELD_TYPE (new_type, i)
+-            = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
+-                                   copied_types);
++            = copy_type_recursive_1 (objfile, TYPE_FIELD_TYPE (type, i),
++                                     copied_types);
+         if (TYPE_FIELD_NAME (type, i))
+           TYPE_FIELD_NAME (new_type, i) = 
+             xstrdup (TYPE_FIELD_NAME (type, i));
+@@ -3453,24 +3654,184 @@ copy_type_recursive (struct objfile *objfile,
+       }
+     }
++  /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
++     possibly converted.  */
++  TYPE_DYNAMIC (new_type) = 0;
 +
-+  TRY_CATCH (e, RETURN_MASK_ALL)
-+    {
-+      struct block *b;
-+      struct dict_iterator iter;
-+      struct symbol *sym;
-+      int argno = 0;
-+
-+      /* The exception breakpoint is a thread-specific breakpoint on
-+       the unwinder's debug hook, declared as:
-+       
-+       void _Unwind_DebugHook (void *cfa, void *handler);
-+       
-+       The CFA argument indicates the frame to which control is
-+       about to be transferred.  HANDLER is the destination PC.
-+       
-+       We ignore the CFA and set a temporary breakpoint at HANDLER.
-+       This is not extremely efficient but it avoids issues in gdb
-+       with computing the DWARF CFA, and it also works even in weird
-+       cases such as throwing an exception from inside a signal
-+       handler.  */
-+
-+      b = SYMBOL_BLOCK_VALUE (func);
-+      ALL_BLOCK_SYMBOLS (b, iter, sym)
-+      {
-+        if (!SYMBOL_IS_ARGUMENT (sym))
-+          continue;
+   /* For range types, copy the bounds information.  */
+-  if (TYPE_CODE (type) == TYPE_CODE_RANGE)
++  if (TYPE_CODE (new_type) == TYPE_CODE_RANGE)
+     {
+       TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds));
+       *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
 +
-+        if (argno == 0)
-+          ++argno;
++      switch (TYPE_RANGE_DATA (new_type)->low.kind)
++      {
++      case RANGE_BOUND_KIND_CONSTANT:
++        break;
++      case RANGE_BOUND_KIND_DWARF_BLOCK:
++        /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
++           it is expected to be made constant by CHECK_TYPEDEF.
++           TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
++           */
++        if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
++            || ! has_stack_frames ())
++          {
++            /* We should set 1 for Fortran but how to find the language?  */
++            TYPE_LOW_BOUND (new_type) = 0;
++            TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
++          }
 +        else
 +          {
-+            insert_exception_resume_breakpoint (ecs->event_thread,
-+                                                b, frame, sym);
-+            break;
++            TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval
++                              (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block);
++            if (TYPE_LOW_BOUND (new_type) >= 0)
++              TYPE_UNSIGNED (new_type) = 1;
 +          }
++        TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
++        break;
++      case RANGE_BOUND_KIND_DWARF_LOCLIST:
++        {
++          CORE_ADDR addr;
++
++          /* `struct dwarf2_loclist_baton' is too bound to its objfile so
++             it is expected to be made constant by CHECK_TYPEDEF.
++             TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
++             */
++          if (! TYPE_NOT_ALLOCATED (new_type)
++              && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
++              && dwarf_loclist_baton_eval
++                (TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.loclist,
++                 TYPE_RANGE_DATA (new_type)->low.u.dwarf_loclist.type, &addr))
++            {
++              TYPE_LOW_BOUND (new_type) = addr;
++              if (TYPE_LOW_BOUND (new_type) >= 0)
++                TYPE_UNSIGNED (new_type) = 1;
++            }
++          else
++            {
++              /* We should set 1 for Fortran but how to find the language?  */
++              TYPE_LOW_BOUND (new_type) = 0;
++              TYPE_LOW_BOUND_UNDEFINED (new_type) = 1;
++            }
++          TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
++        }
++        break;
 +      }
-+    }
-+}
 +
- static void
- stop_stepping (struct execution_control_state *ecs)
- {
-diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
-index 93adfcd..34412a6 100644
---- a/gdb/linux-nat.c
-+++ b/gdb/linux-nat.c
-@@ -2587,6 +2587,39 @@ linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
-   return lp->stopped_data_address_p;
++      switch (TYPE_RANGE_DATA (new_type)->high.kind)
++      {
++      case RANGE_BOUND_KIND_CONSTANT:
++        break;
++      case RANGE_BOUND_KIND_DWARF_BLOCK:
++        /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
++           it is expected to be made constant by CHECK_TYPEDEF.
++           TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
++           */
++        if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
++            || ! has_stack_frames ())
++          {
++            TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
++            TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
++          }
++        else
++          TYPE_HIGH_BOUND (new_type) = dwarf_locexpr_baton_eval
++                             (TYPE_RANGE_DATA (new_type)->high.u.dwarf_block);
++        TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
++        break;
++      case RANGE_BOUND_KIND_DWARF_LOCLIST:
++        {
++          CORE_ADDR addr;
++
++          /* `struct dwarf2_loclist_baton' is too bound to its objfile so
++             it is expected to be made constant by CHECK_TYPEDEF.
++             TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
++             */
++          if (! TYPE_NOT_ALLOCATED (new_type)
++              && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ()
++              && dwarf_loclist_baton_eval
++                    (TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.loclist,
++                     TYPE_RANGE_DATA (new_type)->high.u.dwarf_loclist.type,
++                     &addr))
++            TYPE_HIGH_BOUND (new_type) = addr;
++          else
++            {
++              TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type) - 1;
++              TYPE_HIGH_BOUND_UNDEFINED (new_type) = 1;
++            }
++          TYPE_RANGE_DATA (new_type)->high.kind = RANGE_BOUND_KIND_CONSTANT;
++        }
++        break;
++      }
++
++      switch (TYPE_RANGE_DATA (new_type)->byte_stride.kind)
++      {
++      case RANGE_BOUND_KIND_CONSTANT:
++        break;
++      case RANGE_BOUND_KIND_DWARF_BLOCK:
++        /* `struct dwarf2_locexpr_baton' is too bound to its objfile so
++           it is expected to be made constant by CHECK_TYPEDEF.
++           TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
++           */
++        if (TYPE_NOT_ALLOCATED (new_type) || TYPE_NOT_ASSOCIATED (new_type)
++            || ! has_stack_frames ())
++          TYPE_BYTE_STRIDE (new_type) = 0;
++        else
++          TYPE_BYTE_STRIDE (new_type) = dwarf_locexpr_baton_eval
++                      (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_block);
++        TYPE_RANGE_DATA (new_type)->byte_stride.kind
++          = RANGE_BOUND_KIND_CONSTANT;
++        break;
++      case RANGE_BOUND_KIND_DWARF_LOCLIST:
++        {
++          CORE_ADDR addr = 0;
++
++          /* `struct dwarf2_loclist_baton' is too bound to its objfile so
++             it is expected to be made constant by CHECK_TYPEDEF.
++             TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are not valid for TYPE.
++             */
++          if (! TYPE_NOT_ALLOCATED (new_type)
++              && ! TYPE_NOT_ASSOCIATED (new_type) && has_stack_frames ())
++            dwarf_loclist_baton_eval
++             (TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.loclist,
++              TYPE_RANGE_DATA (new_type)->byte_stride.u.dwarf_loclist.type,
++              &addr);
++          TYPE_BYTE_STRIDE (new_type) = addr;
++          TYPE_RANGE_DATA (new_type)->byte_stride.kind
++            = RANGE_BOUND_KIND_CONSTANT;
++        }
++        break;
++      }
++
++      /* Convert TYPE_RANGE_HIGH_BOUND_IS_COUNT into a regular bound.  */
++      if (TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type))
++      {
++        TYPE_HIGH_BOUND (new_type) = TYPE_LOW_BOUND (new_type)
++                                     + TYPE_HIGH_BOUND (new_type) - 1;
++        TYPE_RANGE_HIGH_BOUND_IS_COUNT (new_type) = 0;
++      }
+     }
+   /* Copy pointers to other types.  */
+   if (TYPE_TARGET_TYPE (type))
+     TYPE_TARGET_TYPE (new_type) = 
+-      copy_type_recursive (objfile, 
+-                         TYPE_TARGET_TYPE (type),
+-                         copied_types);
++      copy_type_recursive_1 (objfile, 
++                           TYPE_TARGET_TYPE (type),
++                           copied_types);
+   if (TYPE_VPTR_BASETYPE (type))
+     TYPE_VPTR_BASETYPE (new_type) = 
+-      copy_type_recursive (objfile,
+-                         TYPE_VPTR_BASETYPE (type),
+-                         copied_types);
++      copy_type_recursive_1 (objfile,
++                           TYPE_VPTR_BASETYPE (type),
++                           copied_types);
++
++  if (TYPE_CODE (new_type) == TYPE_CODE_ARRAY)
++    {
++      struct type *new_index_type = TYPE_INDEX_TYPE (new_type);
++
++      if (TYPE_BYTE_STRIDE (new_index_type) == 0)
++      TYPE_BYTE_STRIDE (new_index_type)
++        = TYPE_LENGTH (TYPE_TARGET_TYPE (new_type));
++    }
++
+   /* Maybe copy the type_specific bits.
+      NOTE drow/2005-12-09: We do not copy the C++-specific bits like
+@@ -3487,6 +3848,17 @@ copy_type_recursive (struct objfile *objfile,
+   return new_type;
  }
  
-+/* In `set follow-fork-mode child' with multithreaded parent we need to detach
-+   watchpoints from all the LWPs.  In such case INFERIOR_PTID will be the
-+   non-threaded new child while LWP_LIST will still contain all the threads of
-+   the parent being detached.  */
++/* Recursively copy (deep copy) TYPE.  Return a new type allocated using
++   malloc, a saved type if we have already visited TYPE (using COPIED_TYPES),
++   or TYPE if it is not associated with OBJFILE.  */
 +
-+static int
-+linux_nat_detach_watchpoints (void)
++struct type *
++copy_type_recursive (struct type *type,
++                   htab_t copied_types)
++{
++  return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
++}
++
+ /* Make a copy of the given TYPE, except that the pointer & reference
+    types are not preserved.
+    
+@@ -3509,6 +3881,201 @@ copy_type (const struct type *type)
+   return new_type;
+ }
++#if 0
++/* Callback type for main_type_crawl.  */
++typedef int (*main_type_crawl_iter) (struct type *type, void *data);
++
++/* Iterate all main_type structures reachable through any `struct type *' from
++   TYPE.  ITER will be called only for one type of each main_type, use
++   TYPE_CHAIN traversal to find all the type instances.  ITER is being called
++   for each main_type found.  ITER returns non-zero if main_type_crawl should
++   depth-first enter the specific type.  ITER must provide some detection for
++   reentering the same main_type as this function would otherwise endlessly
++   loop.  */
++
++static void
++main_type_crawl (struct type *type, main_type_crawl_iter iter, void *data)
 +{
-+  struct lwp_info *lp;
-+  int found = 0, retval = 0;
-+  ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
-+  struct cleanup *old_chain = save_inferior_ptid ();
++  struct type *type_iter;
++  int i;
 +
-+  for (lp = lwp_list; lp; lp = lp->next)
-+    if (ptid_match (lp->ptid, filter))
-+      {
-+      inferior_ptid = lp->ptid;
-+      retval |= linux_ops->to_detach_watchpoints ();
-+      found = 1;
-+      }
++  if (!type)
++    return;
 +
-+  do_cleanups (old_chain);
++  gdb_assert (TYPE_OBJFILE (type) == NULL);
++
++  /* `struct cplus_struct_type' handling is unsupported by this function.  */
++  gdb_assert ((TYPE_CODE (type) != TYPE_CODE_STRUCT
++             && TYPE_CODE (type) != TYPE_CODE_UNION)
++            || !HAVE_CPLUS_STRUCT (type));
 +
-+  if (!found)
++  if (!(*iter) (type, data))
++    return;
++
++  /* Iterate all the type instances of this main_type.  */
++  type_iter = type;
++  do
 +    {
-+      gdb_assert (!is_lwp (inferior_ptid));
++      gdb_assert (TYPE_MAIN_TYPE (type_iter) == TYPE_MAIN_TYPE (type));
++
++      main_type_crawl (TYPE_POINTER_TYPE (type), iter, data);
++      main_type_crawl (TYPE_REFERENCE_TYPE (type), iter, data);
 +
-+      retval |= linux_ops->to_detach_watchpoints ();
++      type_iter = TYPE_CHAIN (type_iter);
 +    }
++  while (type_iter != type);
 +
-+  return retval;
++  for (i = 0; i < TYPE_NFIELDS (type); i++)
++    main_type_crawl (TYPE_FIELD_TYPE (type, i), iter, data);
++
++  main_type_crawl (TYPE_TARGET_TYPE (type), iter, data);
++  main_type_crawl (TYPE_VPTR_BASETYPE (type), iter, data);
 +}
 +
- /* Wait until LP is stopped.  */
- static int
-@@ -5606,6 +5639,8 @@ linux_nat_add_target (struct target_ops *t)
-   t->to_thread_address_space = linux_nat_thread_address_space;
-   t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint;
-   t->to_stopped_data_address = linux_nat_stopped_data_address;
-+  if (linux_ops->to_detach_watchpoints)
-+    t->to_detach_watchpoints = linux_nat_detach_watchpoints;
-   t->to_can_async_p = linux_nat_can_async_p;
-   t->to_is_async_p = linux_nat_is_async_p;
-diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
-index 07fd67c..2524250 100644
---- a/gdb/linux-tdep.c
-+++ b/gdb/linux-tdep.c
-@@ -23,6 +23,8 @@
- #include "auxv.h"
- #include "target.h"
- #include "elf/common.h"
-+#include "value.h"
-+#include "infcall.h"
- /* This function is suitable for architectures that don't
-    extend/override the standard siginfo structure.  */
-diff --git a/gdb/main.c b/gdb/main.c
-index bfd1213..72faabd 100644
---- a/gdb/main.c
-+++ b/gdb/main.c
-@@ -39,6 +39,7 @@
- #include "interps.h"
- #include "main.h"
-+#include "python/python.h"
- #include "source.h"
- #include "cli/cli-cmds.h"
- #include "python/python.h"
-@@ -259,6 +260,8 @@ captured_main (void *data)
-   char *cdarg = NULL;
-   char *ttyarg = NULL;
-+  int python_script = 0;
++/* A helper for delete_type which deletes a main_type and the things to which
++   it refers.  TYPE is a type whose main_type we wish to destroy.  */
 +
-   /* These are static so that we can take their address in an initializer.  */
-   static int print_help;
-   static int print_version;
-@@ -443,10 +446,14 @@ captured_main (void *data)
-       {"args", no_argument, &set_args, 1},
-       {"l", required_argument, 0, 'l'},
-       {"return-child-result", no_argument, &return_child_result, 1},
-+#if HAVE_PYTHON
-+      {"python", no_argument, 0, 'P'},
-+      {"P", no_argument, 0, 'P'},
-+#endif
-       {0, no_argument, 0, 0}
-     };
--    while (1)
-+    while (!python_script)
-       {
-       int option_index;
-@@ -464,6 +471,9 @@ captured_main (void *data)
-         case 0:
-           /* Long option that just sets a flag.  */
-           break;
-+        case 'P':
-+          python_script = 1;
-+          break;
-         case OPT_SE:
-           symarg = optarg;
-           execarg = optarg;
-@@ -650,7 +660,31 @@ extern int gdbtk_test (char *);
-   /* Now that gdb_init has created the initial inferior, we're in position
-      to set args for that inferior.  */
--  if (set_args)
-+  if (python_script)
++static void
++delete_main_type (struct type *type)
++{
++  int i;
++
++  gdb_assert (TYPE_DISCARDABLE (type));
++  gdb_assert (TYPE_OBJFILE (type) == NULL);
++
++  xfree (TYPE_NAME (type));
++  xfree (TYPE_TAG_NAME (type));
++
++  for (i = 0; i < TYPE_NFIELDS (type); ++i)
 +    {
-+      /* The first argument is a python script to evaluate, and
-+       subsequent arguments are passed to the script for
-+       processing there.  */
-+      if (optind >= argc)
-+      {
-+        fprintf_unfiltered (gdb_stderr,
-+                            _("%s: Python script file name required\n"),
-+                            argv[0]);
-+        exit (1);
-+      }
++      xfree (TYPE_FIELD_NAME (type, i));
 +
-+      /* FIXME: should handle inferior I/O intelligently here.
-+       E.g., should be possible to run gdb in pipeline and have
-+       Python (and gdb) output go to stderr or file; and if a
-+       prompt is needed, open the tty.  */
-+      quiet = 1;
-+      /* FIXME: should read .gdbinit if, and only if, a prompt is
-+       requested by the script.  Though... maybe this is not
-+       ideal?  */
-+      /* FIXME: likewise, reading in history.  */
-+      inhibit_gdbinit = 1;
-+    }
-+  else if (set_args)
-     {
-       /* The remaining options are the command-line options for the
-        inferior.  The first one is the sym/exec file, and the rest
-@@ -890,7 +924,8 @@ Can't attach to process and specify a core file at the same time."));
-   xfree (cmdarg);
-   /* Read in the old history after all the command files have been read. */
--  init_history ();
-+  if (!python_script)
-+    init_history ();
-   if (batch_flag)
-     {
-@@ -901,13 +936,25 @@ Can't attach to process and specify a core file at the same time."));
-   /* Show time and/or space usage.  */
-   do_cleanups (pre_stat_chain);
--  /* NOTE: cagney/1999-11-07: There is probably no reason for not
--     moving this loop and the code found in captured_command_loop()
--     into the command_loop() proper.  The main thing holding back that
--     change - SET_TOP_LEVEL() - has been eliminated. */
--  while (1)
-+#if HAVE_PYTHON
-+  if (python_script)
-     {
--      catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
-+      extern int pagination_enabled;
-+      pagination_enabled = 0;
-+      run_python_script (argc - optind, &argv[optind]);
-+      return 1;
++      if (TYPE_FIELD_LOC_KIND (type, i) == FIELD_LOC_KIND_PHYSNAME)
++      xfree (TYPE_FIELD_STATIC_PHYSNAME (type, i));
 +    }
-+  else
-+#endif
++  xfree (TYPE_FIELDS (type));
++
++  gdb_assert (!HAVE_CPLUS_STRUCT (type));
++
++  xfree (TYPE_MAIN_TYPE (type));
++}
++
++/* Delete all the instances on TYPE_CHAIN of TYPE, including their referenced
++   main_type.  TYPE must be a reclaimable type - neither permanent nor objfile
++   associated.  */
++
++static void
++delete_type_chain (struct type *type)
++{
++  struct type *type_iter, *type_iter_to_free;
++
++  gdb_assert (TYPE_DISCARDABLE (type));
++  gdb_assert (TYPE_OBJFILE (type) == NULL);
++
++  delete_main_type (type);
++
++  type_iter = type;
++  do
 +    {
-+      /* NOTE: cagney/1999-11-07: There is probably no reason for not
-+       moving this loop and the code found in captured_command_loop()
-+       into the command_loop() proper.  The main thing holding back that
-+       change - SET_TOP_LEVEL() - has been eliminated. */
-+      while (1)
-+      {
-+        catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
-+      }
-     }
-   /* No exit -- exit is through quit_command.  */
- }
-@@ -939,7 +986,12 @@ print_gdb_help (struct ui_file *stream)
-   fputs_unfiltered (_("\
- This is the GNU debugger.  Usage:\n\n\
-     gdb [options] [executable-file [core-file or process-id]]\n\
--    gdb [options] --args executable-file [inferior-arguments ...]\n\n\
-+    gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
-+#if HAVE_PYTHON
-+  fputs_unfiltered (_("\
-+    gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
-+#endif
-+  fputs_unfiltered (_("\n\
- Options:\n\n\
- "), stream);
-   fputs_unfiltered (_("\
-@@ -977,7 +1029,13 @@ Options:\n\n\
-   --nw                     Do not use a window interface.\n\
-   --nx               Do not read "), stream);
-   fputs_unfiltered (gdbinit, stream);
--  fputs_unfiltered (_(" file.\n\
-+  fputs_unfiltered (_(" file.\n"), stream);
-+#if HAVE_PYTHON
-+  fputs_unfiltered (_("\
-+  --python, -P       Following argument is Python script file; remaining\n\
-+                     arguments are passed to script.\n"), stream);
-+#endif
-+  fputs_unfiltered (_("\
-   --quiet            Do not print version number on startup.\n\
-   --readnow          Fully read symbol files on first access.\n\
- "), stream);
-diff --git a/gdb/maint.c b/gdb/maint.c
-index 28fd610..4e21476 100644
---- a/gdb/maint.c
-+++ b/gdb/maint.c
-@@ -909,4 +909,12 @@ When enabled GDB is profiled."),
-                          show_maintenance_profile_p,
-                          &maintenance_set_cmdlist,
-                          &maintenance_show_cmdlist);
-+  add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
-+                           &gdb_datadir, _("Set GDB's datadir path."),
-+                           _("Show GDB's datadir path."),
-+                           _("\
-+When set, GDB uses the specified path to search for data files."),
-+                           NULL, NULL,
-+                           &maintenance_set_cmdlist,
-+                           &maintenance_show_cmdlist);
- }
-diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
-index 310ade9..d8710a1 100644
---- a/gdb/mi/mi-cmd-var.c
-+++ b/gdb/mi/mi-cmd-var.c
-@@ -702,7 +702,6 @@ mi_cmd_var_update (char *command, char **argv, int argc)
-     }
-   else
-     {
--      /* Get varobj handle, if a valid var obj name was specified */
-       struct varobj *var = varobj_get_handle (name);
-       varobj_update_one (var, print_values, 1 /* explicit */);
-diff --git a/gdb/minsyms.c b/gdb/minsyms.c
-index cb4545c..92d4027 100644
---- a/gdb/minsyms.c
-+++ b/gdb/minsyms.c
-@@ -337,8 +337,9 @@ lookup_minimal_symbol_text (const char *name, struct objfile *objf)
-              msymbol = msymbol->hash_next)
-           {
-             if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 &&
--                (MSYMBOL_TYPE (msymbol) == mst_text ||
--                 MSYMBOL_TYPE (msymbol) == mst_file_text))
-+                (MSYMBOL_TYPE (msymbol) == mst_text
-+                 || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
-+                 || MSYMBOL_TYPE (msymbol) == mst_file_text))
-               {
-                 switch (MSYMBOL_TYPE (msymbol))
-                   {
-@@ -700,6 +701,16 @@ lookup_minimal_symbol_by_pc (CORE_ADDR pc)
-   return lookup_minimal_symbol_by_pc_section (pc, NULL);
- }
-+/* Return non-zero iff PC is in function implementing gnu-ifunc selection.  */
++      type_iter_to_free = type_iter;
++      type_iter = TYPE_CHAIN (type_iter);
++      xfree (type_iter_to_free);
++    }
++  while (type_iter != type);
++}
 +
-+int
-+in_gnu_ifunc_stub (CORE_ADDR pc)
++/* Hash function for type_discardable_table.  */
++
++static hashval_t
++type_discardable_hash (const void *p)
 +{
-+  struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
++  const struct type *type = p;
 +
-+  return msymbol && MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
++  return htab_hash_pointer (TYPE_MAIN_TYPE (type));
 +}
 +
- /* Find the minimal symbol named NAME, and return both the minsym
-    struct and its objfile.  This only checks the linkage name.  Sets
-    *OBJFILE_P and returns the minimal symbol, if it is found.  If it
-@@ -769,6 +780,7 @@ prim_record_minimal_symbol (const char *name, CORE_ADDR address,
-   switch (ms_type)
-     {
-     case mst_text:
-+    case mst_text_gnu_ifunc:
-     case mst_file_text:
-     case mst_solib_trampoline:
-       section = SECT_OFF_TEXT (objfile);
-@@ -1235,7 +1247,8 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
-     {
-       ALL_MSYMBOLS (objfile, msymbol)
-       {
--      if (MSYMBOL_TYPE (msymbol) == mst_text
-+      if ((MSYMBOL_TYPE (msymbol) == mst_text
-+          || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc)
-           && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
-                      SYMBOL_LINKAGE_NAME (tsymbol)) == 0)
-         return SYMBOL_VALUE_ADDRESS (msymbol);
-diff --git a/gdb/p-lang.c b/gdb/p-lang.c
-index 08738ac..64d2e9f 100644
---- a/gdb/p-lang.c
-+++ b/gdb/p-lang.c
-@@ -222,7 +222,11 @@ pascal_printstr (struct ui_file *stream, struct type *type,
-   unsigned int things_printed = 0;
-   int in_quotes = 0;
-   int need_comma = 0;
--  int width = TYPE_LENGTH (type);
-+  int width;
++/* Equality function for type_discardable_table.  */
 +
-+  /* Preserve TYPE's original type, just set its LENGTH.  */
-+  check_typedef (type);
-+  width = TYPE_LENGTH (type);
-   /* If the string was not truncated due to `set print elements', and
-      the last byte of it is a null, we don't print that, in traditional C
-diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
-index 4d39bed..d0ddebc 100644
---- a/gdb/p-valprint.c
-+++ b/gdb/p-valprint.c
-@@ -38,6 +38,7 @@
- #include "p-lang.h"
- #include "cp-abi.h"
- #include "cp-support.h"
-+#include "dwarf2loc.h"
\f
-@@ -68,8 +69,27 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
-   struct type *char_type;
-   LONGEST val;
-   CORE_ADDR addr;
-+  struct cleanup *back_to;
-+  struct type *saved_type = type;
-+  CORE_ADDR saved_address = address;
-+  
-+  back_to = make_cleanup (null_cleanup, 0);
-+  type = object_address_get_data (type, &address);
++static int
++type_discardable_equal (const void *a, const void *b)
++{
++  const struct type *left = a;
++  const struct type *right = b;
++
++  return TYPE_MAIN_TYPE (left) == TYPE_MAIN_TYPE (right);
++}
++
++/* A helper for type_mark_used.  */
++
++static int
++type_mark_used_crawl (struct type *type, void *unused)
++{
++  if (!TYPE_DISCARDABLE (type))
++    return 0;
++
++  if (TYPE_DISCARDABLE_AGE (type) == type_discardable_age_current)
++    return 0;
++
++  TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
++
++  /* Continue the traversal.  */
++  return 1;
++}
++
++/* Mark TYPE and its connected types as used in this free_all_types pass.  */
++
++void
++type_mark_used (struct type *type)
++{
 +  if (type == NULL)
++    return;
++
++  if (!TYPE_DISCARDABLE (type))
++    return;
++
++  main_type_crawl (type, type_mark_used_crawl, NULL);
++}
++
++/* A traverse callback for type_discardable_table which removes any
++   type_discardable whose reference count is now zero (unused link).  */
++
++static int
++type_discardable_remove (void **slot, void *unused)
++{
++  struct type *type = *slot;
++
++  gdb_assert (TYPE_DISCARDABLE (type));
++
++  if (TYPE_DISCARDABLE_AGE (type) != type_discardable_age_current)
 +    {
-+      fputs_filtered (object_address_data_not_valid (saved_type), stream);
-+      gdb_flush (stream);
-+      do_cleanups (back_to);
-+      return 0;
-+    }
-+  if (address != saved_address)
-+    {
-+      size_t length = TYPE_LENGTH (type);
--  CHECK_TYPEDEF (type);
-+      valaddr = xmalloc (length);
-+      make_cleanup (xfree, (gdb_byte *) valaddr);
-+      read_memory (address, (gdb_byte *) valaddr, length);
++      delete_type_chain (type);
++
++      htab_clear_slot (type_discardable_table, slot);
 +    }
-   switch (TYPE_CODE (type))
-     {
-     case TYPE_CODE_ARRAY:
-@@ -125,8 +145,9 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
-               {
-                 i = 0;
-               }
--            val_print_array_elements (type, valaddr + embedded_offset, address, stream,
--                                      recurse, original_value, options, i);
-+            val_print_array_elements (saved_type, valaddr + embedded_offset,
-+                                      saved_address, stream, recurse,
-+                                      original_value, options, i);
-             fprintf_filtered (stream, "}");
-           }
-         break;
-@@ -164,6 +185,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
-         /* Try to print what function it points to.  */
-         print_address_demangle (gdbarch, addr, stream, demangle);
-         /* Return value is irrelevant except for string pointers.  */
-+        do_cleanups (back_to);
-         return (0);
-       }
-@@ -252,6 +274,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
-       /* Return number of characters printed, including the terminating
-        '\0' if we reached the end.  val_print_string takes care including
-        the terminating '\0' if necessary.  */
-+      do_cleanups (back_to);
-       return i;
-       break;
-@@ -554,6 +577,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
-       error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type));
-     }
-   gdb_flush (stream);
-+  do_cleanups (back_to);
-   return (0);
- }
\f
-diff --git a/gdb/parse.c b/gdb/parse.c
-index c885c6a..cbf9c65 100644
---- a/gdb/parse.c
-+++ b/gdb/parse.c
-@@ -487,9 +487,21 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
-   pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, &current_target);
-   if (pc != addr)
-     {
-+      struct minimal_symbol *ifunc_msym = lookup_minimal_symbol_by_pc (pc);
 +
-       /* In this case, assume we have a code symbol instead of
-        a data symbol.  */
--      type = mst_text;
++  return 1;
++}
 +
-+      if (ifunc_msym != NULL && MSYMBOL_TYPE (ifunc_msym) == mst_text_gnu_ifunc
-+        && SYMBOL_VALUE_ADDRESS (ifunc_msym) == pc)
-+      {
-+        /* A function descriptor has been resolved but PC is still in the
-+           gnu-ifunc resolver body (such as because inferior does not run to
-+           be able to call it).  */
-+        type = mst_text_gnu_ifunc;
-+      }
-+      else
-+      type = mst_text;
-       section = NULL;
-       addr = pc;
-     }
-@@ -521,6 +533,11 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
-       write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
-       break;
-+    case mst_text_gnu_ifunc:
-+      write_exp_elt_type (objfile_type (objfile)
-+                                             ->nodebug_text_gnu_ifunc_symbol);
-+      break;
++/* Free all the reclaimable types that have been allocated and that have
++   currently zero reference counter.
 +
-     case mst_data:
-     case mst_file_data:
-     case mst_bss:
-@@ -528,6 +545,10 @@ write_exp_msymbol (struct minimal_symbol *msymbol)
-       write_exp_elt_type (objfile_type (objfile)->nodebug_data_symbol);
-       break;
-+    case mst_slot_got_plt:
-+      write_exp_elt_type (objfile_type (objfile)->nodebug_got_plt_symbol);
-+      break;
++   This function is called after each command, successful or not.  Use this
++   cleanup only in the GDB idle state as GDB only marks those types used by
++   globally tracked objects (with no autovariable references tracking).  */
 +
-     default:
-       write_exp_elt_type (objfile_type (objfile)->nodebug_unknown_symbol);
-       break;
-@@ -1412,6 +1433,7 @@ parser_fprintf (FILE *x, const char *y, ...)
- int
- operator_check_standard (struct expression *exp, int pos,
-+                       int (*type_func) (struct type *type, void *data),
-                        int (*objfile_func) (struct objfile *objfile,
-                                             void *data),
-                        void *data)
-@@ -1453,7 +1475,7 @@ operator_check_standard (struct expression *exp, int pos,
-           struct type *type = elts[pos + 2 + arg].type;
-           struct objfile *objfile = TYPE_OBJFILE (type);
--          if (objfile && (*objfile_func) (objfile, data))
-+          if (objfile && objfile_func && (*objfile_func) (objfile, data))
-             return 1;
-         }
-       }
-@@ -1471,7 +1493,8 @@ operator_check_standard (struct expression *exp, int pos,
-       /* Check objfile where the variable itself is placed.
-          SYMBOL_OBJ_SECTION (symbol) may be NULL.  */
--      if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
-+      if (objfile_func
-+          && (*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
-         return 1;
-       /* Check objfile where is placed the code touching the variable.  */
-@@ -1484,24 +1507,27 @@ operator_check_standard (struct expression *exp, int pos,
-   /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
--  if (type && TYPE_OBJFILE (type)
-+  if (type && type_func && (*type_func) (type, data))
-+    return 1;
-+  if (type && TYPE_OBJFILE (type) && objfile_func
-       && (*objfile_func) (TYPE_OBJFILE (type), data))
-     return 1;
--  if (objfile && (*objfile_func) (objfile, data))
-+  if (objfile && objfile_func && (*objfile_func) (objfile, data))
-     return 1;
-   return 0;
- }
++void
++free_all_types (void)
++{
++  /* Mark a new pass.  As GDB checks all the entries were visited after each
++     pass there cannot be any stale entries already containing the changed
++     value.  */
++  type_discardable_age_current ^= 1;
++
++  observer_notify_mark_used ();
++
++  htab_traverse (type_discardable_table, type_discardable_remove, NULL);
++}
++#endif
  
--/* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP.
--   The functions are never called with NULL OBJFILE.  Functions get passed an
--   arbitrary caller supplied DATA pointer.  If any of the functions returns
--   non-zero value then (any other) non-zero value is immediately returned to
--   the caller.  Otherwise zero is returned after iterating through whole EXP.
--   */
-+/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
-+   referenced by EXP.  The functions are never called with NULL TYPE or NULL
-+   OBJFILE.  Functions get passed an arbitrary caller supplied DATA pointer.
-+   If any of the functions returns non-zero value then (any other) non-zero
-+   value is immediately returned to the caller.  Otherwise zero is returned
-+   after iterating through whole EXP.  */
+ /* Helper functions to initialize architecture-specific types.  */
  
- static int
- exp_iterate (struct expression *exp,
-+           int (*type_func) (struct type *type, void *data),
-            int (*objfile_func) (struct objfile *objfile, void *data),
-            void *data)
+@@ -4042,6 +4609,13 @@ void
+ _initialize_gdbtypes (void)
  {
-@@ -1516,7 +1542,9 @@ exp_iterate (struct expression *exp,
+   gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
++
++#if 0
++  type_discardable_table = htab_create_alloc (20, type_discardable_hash,
++                                           type_discardable_equal, NULL,
++                                           xcalloc, xfree);
++#endif
++
+   objfile_type_data = register_objfile_data ();
  
-       pos = endpos - oplen;
-       if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
--                                                         objfile_func, data))
-+                                                         type_func,
-+                                                         objfile_func,
-+                                                         data))
-       return 1;
+   add_setshow_zinteger_cmd ("overload", no_class, &overload_debug,
+diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
+index 17bfbc5..72e9cc5 100644
+--- a/gdb/gdbtypes.h
++++ b/gdb/gdbtypes.h
+@@ -228,6 +228,11 @@ enum type_instance_flag_value
  
-       endpos = pos;
-@@ -1547,7 +1575,26 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
- {
-   gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
+ #define TYPE_TARGET_STUB(t)   (TYPE_MAIN_TYPE (t)->flag_target_stub)
  
--  return exp_iterate (exp, exp_uses_objfile_iter, objfile);
-+  return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
-+}
-+
-+/* Helper for exp_types_mark_used.  */
-+
-+static int
-+exp_types_mark_used_iter (struct type *type, void *unused)
-+{
-+  type_mark_used (type);
-+
-+  /* Continue the traversal.  */
-+  return 0;
-+}
++/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
++   sticky.  */
 +
-+/* Call type_mark_used for any type contained in EXP.  */
++#define TYPE_DYNAMIC(t)               (TYPE_MAIN_TYPE (t)->flag_dynamic)
 +
-+void
-+exp_types_mark_used (struct expression *exp)
-+{
-+  exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
- }
- void
-diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
-index bb79ae1..fbbd600 100644
---- a/gdb/parser-defs.h
-+++ b/gdb/parser-defs.h
-@@ -194,6 +194,8 @@ extern void operator_length_standard (const struct expression *, int, int *,
-                                     int *);
- extern int operator_check_standard (struct expression *exp, int pos,
-+                                  int (*type_func) (struct type *type,
-+                                                    void *data),
-                                   int (*objfile_func)
-                                     (struct objfile *objfile, void *data),
-                                   void *data);
-@@ -285,6 +287,7 @@ struct exp_descriptor
-        value should be immediately returned to the caller.  Otherwise zero
-        should be returned.  */
-     int (*operator_check) (struct expression *exp, int pos,
-+                         int (*type_func) (struct type *type, void *data),
-                          int (*objfile_func) (struct objfile *objfile,
-                                               void *data),
-                          void *data);
-@@ -323,4 +326,8 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
+ /* Static type.  If this is set, the corresponding type had 
+    a static modifier.
+    Note: This may be unnecessary, since static data members
+@@ -311,6 +316,50 @@ enum type_instance_flag_value
  
- extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
+ #define TYPE_FLAG_ENUM(t) (TYPE_MAIN_TYPE (t)->flag_flag_enum)
  
-+extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
++#if 0
++/* Define this type as being reclaimable during free_all_types.  Type is
++   required to be have TYPE_OBJFILE set to NULL.  Setting this flag requires
++   initializing TYPE_DISCARDABLE_AGE, see alloc_type_discardable.  */
 +
-+extern void exp_types_mark_used (struct expression *exp);
++#define TYPE_DISCARDABLE(t)   (TYPE_MAIN_TYPE (t)->flag_discardable)
 +
- #endif /* PARSER_DEFS_H */
-diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
-index 18ddee7..652b02a 100644
---- a/gdb/ppc-linux-nat.c
-+++ b/gdb/ppc-linux-nat.c
-@@ -2010,6 +2010,24 @@ ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
-   return ret;
- }
-+/* See target_detach_watchpoints.  Do not use wrapper
-+   ppc_linux_remove_watchpoint as it would modify the register cache
-+   (saved_dabr_value).  */
++/* Marker this type has been visited by the type_mark_used by this
++   mark-and-sweep types garbage collecting pass.  Current pass is represented
++   by TYPE_DISCARDABLE_AGE_CURRENT.  */
 +
-+static int
-+ppc_linux_detach_watchpoints (void)
-+{
-+  pid_t tid;
++#define TYPE_DISCARDABLE_AGE(t)       (TYPE_MAIN_TYPE (t)->flag_discardable_age)
++#endif
 +
-+  tid = TIDGET (inferior_ptid);
-+  if (tid == 0)
-+    tid = PIDGET (inferior_ptid);
++/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)?  */
 +
-+  if (ptrace (PTRACE_SET_DEBUGREG, tid, NULL, NULL) < 0)
-+    return -1;
-+  return 0;
-+}
++#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
++  (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
 +
- static void
- ppc_linux_new_thread (ptid_t ptid)
- {
-@@ -2349,6 +2367,7 @@ _initialize_ppc_linux_nat (void)
-   t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
-   t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
-   t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
-+  t->to_detach_watchpoints = ppc_linux_detach_watchpoints;
-   t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
-   t->to_stopped_data_address = ppc_linux_stopped_data_address;
-   t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
-diff --git a/gdb/printcmd.c b/gdb/printcmd.c
-index 5ffa099..58d9c79 100644
---- a/gdb/printcmd.c
-+++ b/gdb/printcmd.c
-@@ -971,6 +971,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
-   else
-     val = access_value_history (0);
-+  /* Do not try to OBJECT_ADDRESS_SET here anything.  We are interested in the
-+     source variable base addresses as found by READ_VAR_VALUE.  The value here
-+     can be already a calculated expression address inappropriate for
-+     DW_OP_push_object_address.  */
++/* Not allocated.  TYPE_ALLOCATED(t) must be NULL in such case.  If this flag
++   is unset and TYPE_ALLOCATED(t) is NULL then the type is allocated.  If this
++   flag is unset and TYPE_ALLOCATED(t) is not NULL then its DWARF block
++   determines the actual allocation state.  */
 +
-   if (voidprint || (val && value_type (val) &&
-                   TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
-     {
-@@ -1471,6 +1476,22 @@ x_command (char *exp, int from_tty)
-       set_internalvar (lookup_internalvar ("__"), last_examine_value);
-     }
- }
++#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
 +
-+/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
++/* Not associated.  TYPE_ASSOCIATED(t) must be NULL in such case.  If this flag
++   is unset and TYPE_ASSOCIATED(t) is NULL then the type is associated.  If
++   this flag is unset and TYPE_ASSOCIATED(t) is not NULL then its DWARF block
++   determines the actual association state.  */
 +
-+static void
-+print_types_mark_used (void)
-+{
-+  struct display *d;
++#define TYPE_NOT_ASSOCIATED(t)        (TYPE_MAIN_TYPE (t)->flag_not_associated)
 +
-+  if (last_examine_value)
-+    type_mark_used (value_type (last_examine_value));
++/* Address of the actual data as for DW_AT_data_location.  Its dwarf block must
++   not be evaluated unless both TYPE_NOT_ALLOCATED and TYPE_NOT_ASSOCIATED are
++   false.  If TYPE_DATA_LOCATION_IS_ADDR set then TYPE_DATA_LOCATION_ADDR value
++   is the actual data address value.  If unset and
++   TYPE_DATA_LOCATION_DWARF_BLOCK is NULL then the value is the normal
++   value_raw_address.  If unset and TYPE_DATA_LOCATION_DWARF_BLOCK is not NULL
++   then its DWARF block determines the actual data address.  */
 +
-+  for (d = display_chain; d; d = d->next)
-+    if (d->exp)
-+      exp_types_mark_used (d->exp);
-+}
++#define TYPE_DATA_LOCATION_IS_ADDR(t) \
++  (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
 +
\f
+ /* Constant type.  If this is set, the corresponding type has a
+    const modifier.  */
  
- /* Add an expression to the auto-display chain.
-@@ -2869,4 +2890,6 @@ Show printing of source filename and line number with <symbol>."), NULL,
-   add_com ("eval", no_class, eval_command, _("\
- Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
- a command line, and call it."));
-+
-+  observer_attach_mark_used (print_types_mark_used);
- }
-diff --git a/gdb/psymtab.c b/gdb/psymtab.c
-index 97a4eec..fce19c9 100644
---- a/gdb/psymtab.c
-+++ b/gdb/psymtab.c
-@@ -421,6 +421,14 @@ lookup_symbol_aux_psymtabs (struct objfile *objfile,
-   return NULL;
- }
+@@ -421,6 +470,15 @@ struct main_type
+   /* True if this type was declared with "class" rather than
+      "struct".  */
+   unsigned int flag_declared_class : 1;
++#if 0
++  unsigned int flag_discardable : 1;
++  unsigned int flag_discardable_age : 1;
++#endif
++  unsigned int flag_dynamic : 1;
++  unsigned int flag_range_high_bound_is_count : 1;
++  unsigned int flag_not_allocated : 1;
++  unsigned int flag_not_associated : 1;
++  unsigned int flag_data_location_is_addr : 1;
  
-+static void
-+pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
-+                                    int kind, const char *name,
-+                                    domain_enum domain)
-+{
-+  /* Nothing.  */
-+}
-+
- /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
-    Check the global symbols if GLOBAL, the static symbols if not. */
+   /* True if this is an enum type with disjoint values.  This affects
+      how the enum is printed.  */
+@@ -501,6 +559,20 @@ struct main_type
  
-@@ -941,7 +949,7 @@ psymtab_to_fullname (struct partial_symtab *ps)
-   return NULL;
- }
+   struct type *target_type;
  
--static char *
-+static const char *
- find_symbol_file_from_partial (struct objfile *objfile, const char *name)
- {
-   struct partial_symtab *pst;
-@@ -1199,6 +1207,7 @@ const struct quick_symbol_functions psym_functions =
-   forget_cached_source_info_partial,
-   lookup_symtab_via_partial_symtab,
-   lookup_symbol_aux_psymtabs,
-+  pre_expand_symtabs_matching_psymtabs,
-   print_psymtab_stats_for_objfile,
-   dump_psymtabs_for_objfile,
-   relocate_psymtabs,
-diff --git a/gdb/psymtab.h b/gdb/psymtab.h
-index 9b8c8df..de8b67e 100644
---- a/gdb/psymtab.h
-+++ b/gdb/psymtab.h
-@@ -1,6 +1,6 @@
- /* Public partial symbol table definitions.
--   Copyright (C) 2009 Free Software Foundation, Inc.
-+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
-    This file is part of GDB.
-@@ -28,4 +28,6 @@ void map_partial_symbol_filenames (void (*) (const char *, const char *,
- extern const struct quick_symbol_functions psym_functions;
-+extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
-+
- #endif /* PSYMTAB_H */
-diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
-new file mode 100644
-index 0000000..5654546
---- /dev/null
-+++ b/gdb/python/lib/gdb/FrameIterator.py
-@@ -0,0 +1,33 @@
-+# Iterator over frames.
++  /* For DW_AT_data_location.  */
++  union
++    {
++      struct dwarf2_locexpr_baton *dwarf_block;
++      CORE_ADDR addr;
++    }
++  data_location;
 +
-+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
++  /* For DW_AT_allocated.  */
++  struct dwarf2_locexpr_baton *allocated;
 +
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+class FrameIterator:
-+    """An iterator that iterates over frames."""
-+
-+    def __init__ (self, frame):
-+        "Initialize a FrameIterator.  FRAME is the starting frame."
-+        self.frame = frame
-+
-+    def __iter__ (self):
-+        return self
-+
-+    def next (self):
-+        result = self.frame
-+        if result is None:
-+            raise StopIteration
-+        self.frame = result.older ()
-+        return result
-diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
-new file mode 100644
-index 0000000..b790a54
---- /dev/null
-+++ b/gdb/python/lib/gdb/FrameWrapper.py
-@@ -0,0 +1,112 @@
-+# Wrapper API for frames.
-+
-+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++  /* For DW_AT_associated.  */
++  struct dwarf2_locexpr_baton *associated;
 +
-+import gdb
+   /* For structure and union types, a description of each field.
+      For set and pascal array types, there is one "field",
+      whose type is the domain type of the set or array.
+@@ -583,13 +655,34 @@ struct main_type
+     struct range_bounds
+     {
++      struct
++      {
++        union
++          {
++            LONGEST constant;
++            struct dwarf2_locexpr_baton *dwarf_block;
++            struct
++              {
++                struct dwarf2_loclist_baton *loclist;
++                struct type *type;
++              }
++            dwarf_loclist;
++          }
++        u;
++        enum range_bound_kind
++          {
++            RANGE_BOUND_KIND_CONSTANT,
++            RANGE_BOUND_KIND_DWARF_BLOCK,
++            RANGE_BOUND_KIND_DWARF_LOCLIST
++          }
++        kind;
++      }
+       /* Low bound of range.  */
+-
+-      LONGEST low;
+-
++      low,
+       /* High bound of range.  */
+-
+-      LONGEST high;
++      high,
++      /* Byte stride of range.  */
++      byte_stride;
+       /* Flags indicating whether the values of low and high are
+          valid.  When true, the respective range value is
+@@ -1054,9 +1147,9 @@ extern void allocate_gnat_aux_type (struct type *);
+ #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
+ #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
+ #define TYPE_CHAIN(thistype) (thistype)->chain
+-/* Note that if thistype is a TYPEDEF type, you have to call check_typedef.
+-   But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
+-   so you only have to call check_typedef once.  Since allocate_value
++/* Note that if thistype is a TYPEDEF, ARRAY or STRING type, you have to call
++   check_typedef.  But check_typedef does set the TYPE_LENGTH of the TYPEDEF
++   type, so you only have to call check_typedef once.  Since allocate_value
+    calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe.  */
+ #define TYPE_LENGTH(thistype) (thistype)->length
+ /* Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
+@@ -1064,11 +1157,16 @@ extern void allocate_gnat_aux_type (struct type *);
+ #define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
+ #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
+ #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
++#define TYPE_DATA_LOCATION_DWARF_BLOCK(thistype) TYPE_MAIN_TYPE (thistype)->data_location.dwarf_block
++#define TYPE_DATA_LOCATION_ADDR(thistype) TYPE_MAIN_TYPE (thistype)->data_location.addr
++#define TYPE_ALLOCATED(thistype) TYPE_MAIN_TYPE (thistype)->allocated
++#define TYPE_ASSOCIATED(thistype) TYPE_MAIN_TYPE (thistype)->associated
+ #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
+ #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
+-#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low
+-#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high
++#define TYPE_LOW_BOUND(range_type) TYPE_RANGE_DATA(range_type)->low.u.constant
++#define TYPE_HIGH_BOUND(range_type) TYPE_RANGE_DATA(range_type)->high.u.constant
++#define TYPE_BYTE_STRIDE(range_type) TYPE_RANGE_DATA(range_type)->byte_stride.u.constant
+ #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
+    TYPE_RANGE_DATA(range_type)->low_undefined
+ #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
+@@ -1085,7 +1183,14 @@ extern void allocate_gnat_aux_type (struct type *);
+    (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
+ #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
+-   (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
++  TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arraytype))
 +
-+# FIXME: arguably all this should be on Frame somehow.
-+class FrameWrapper:
-+    def __init__ (self, frame):
-+        self.frame = frame;
++/* TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) with a fallback to the
++   element size if no specific stride value is known.  */
++#define TYPE_ARRAY_BYTE_STRIDE_VALUE(arraytype)               \
++  (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)) == 0        \
++   ? TYPE_LENGTH (TYPE_TARGET_TYPE (arraytype))               \
++   : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (arraytype)))
+ /* C++ */
+@@ -1531,6 +1636,18 @@ extern struct type *create_array_type (struct type *, struct type *,
+                                      struct type *);
+ extern struct type *lookup_array_range_type (struct type *, int, int);
++extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
++                                              int fieldno);
 +
-+    def write_symbol (self, stream, sym, block):
-+        if len (sym.linkage_name):
-+            nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
-+            if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
-+                sym = nsym
++extern int type_range_high_bound_internal (struct type *range_type);
 +
-+        stream.write (sym.print_name + "=")
-+        try:
-+            val = self.read_var (sym)
-+            if val != None:
-+                val = str (val)
-+        # FIXME: would be nice to have a more precise exception here.
-+        except RuntimeError, text:
-+            val = text
-+        if val == None:
-+            stream.write ("???")
-+        else:
-+            stream.write (str (val))
++extern int type_range_count_bound_internal (struct type *range_type);
 +
-+    def print_frame_locals (self, stream, func):
-+        if not func:
-+            return
++extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
++                                                struct type *element_type);
 +
-+        first = True
-+        block = func.value
++extern void finalize_type (struct type *type);
 +
-+        for sym in block:
-+            if sym.is_argument:
-+                continue;
+ extern struct type *create_string_type (struct type *, struct type *,
+                                       struct type *);
+ extern struct type *lookup_string_range_type (struct type *, int, int);
+@@ -1576,6 +1693,10 @@ extern int is_public_ancestor (struct type *, struct type *);
+ extern int is_unique_ancestor (struct type *, struct value *);
++#if 0
++extern void type_mark_used (struct type *type);
++#endif
 +
-+            self.write_symbol (stream, sym, block)
-+            stream.write ('\n')
+ /* Overload resolution */
+ #define LENGTH_MATCH(bv) ((bv)->rank[0])
+@@ -1651,10 +1772,13 @@ extern void maintenance_print_type (char *, int);
+ extern htab_t create_copied_types_hash (struct objfile *objfile);
+-extern struct type *copy_type_recursive (struct objfile *objfile,
+-                                       struct type *type,
++extern struct type *copy_type_recursive (struct type *type,
+                                        htab_t copied_types);
+ extern struct type *copy_type (const struct type *type);
++#if 0
++extern void free_all_types (void);
++#endif
 +
-+    def print_frame_args (self, stream, func):
-+        if not func:
-+            return
+ #endif /* GDBTYPES_H */
+diff --git a/gdb/jit.c b/gdb/jit.c
+index 568d17b..cdd9f49 100644
+--- a/gdb/jit.c
++++ b/gdb/jit.c
+@@ -38,6 +38,7 @@
+ #include "gdb-dlfcn.h"
+ #include "gdb_stat.h"
+ #include "exceptions.h"
++#include "gdb_bfd.h"
+ static const char *jit_reader_dir = NULL;
+@@ -132,17 +133,16 @@ mem_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
+ static struct bfd *
+ bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size, char *target)
+ {
+-  const char *filename = xstrdup ("<in-memory>");
+   struct target_buffer *buffer = xmalloc (sizeof (struct target_buffer));
+   buffer->base = addr;
+   buffer->size = size;
+-  return bfd_openr_iovec (filename, target,
+-                          mem_bfd_iovec_open,
+-                          buffer,
+-                          mem_bfd_iovec_pread,
+-                          mem_bfd_iovec_close,
+-                          mem_bfd_iovec_stat);
++  return gdb_bfd_openr_iovec ("<in-memory>", target,
++                            mem_bfd_iovec_open,
++                            buffer,
++                            mem_bfd_iovec_pread,
++                            mem_bfd_iovec_close,
++                            mem_bfd_iovec_stat);
+ }
+ /* One reader that has been loaded successfully, and can potentially be used to
+@@ -868,7 +868,7 @@ jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
+     {
+       printf_unfiltered (_("\
+ JITed symbol file is not an object file, ignoring it.\n"));
+-      bfd_close (nbfd);
++      gdb_bfd_unref (nbfd);
+       return;
+     }
+@@ -896,7 +896,8 @@ JITed symbol file is not an object file, ignoring it.\n"));
+         ++i;
+       }
+-  /* This call takes ownership of NBFD.  It does not take ownership of SAI.  */
++  /* This call does not take ownership of SAI.  */
++  make_cleanup_bfd_unref (nbfd);
+   objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);
+   do_cleanups (old_cleanups);
+diff --git a/gdb/m32r-rom.c b/gdb/m32r-rom.c
+index 76e4bf1..9a2f5aa 100644
+--- a/gdb/m32r-rom.c
++++ b/gdb/m32r-rom.c
+@@ -40,6 +40,7 @@
+ #include "inferior.h"
+ #include <ctype.h>
+ #include "regcache.h"
++#include "gdb_bfd.h"
+ /*
+  * All this stuff just to get my host computer's IP address!
+@@ -124,13 +125,15 @@ m32r_load (char *filename, int from_tty)
+   bfd *abfd;
+   unsigned int data_count = 0;
+   struct timeval start_time, end_time;
++  struct cleanup *cleanup;
+   if (filename == NULL || filename[0] == 0)
+     filename = get_exec_file (1);
+-  abfd = bfd_openr (filename, 0);
++  abfd = gdb_bfd_openr (filename, 0);
+   if (!abfd)
+     error (_("Unable to open file %s."), filename);
++  cleanup = make_cleanup_bfd_unref (abfd);
+   if (bfd_check_format (abfd, bfd_object) == 0)
+     error (_("File is not an object file."));
+   gettimeofday (&start_time, NULL);
+@@ -188,6 +191,7 @@ m32r_load (char *filename, int from_tty)
+      confused...  */
+   clear_symtab_users (0);
++  do_cleanups (cleanup);
+ }
+ static void
+@@ -434,6 +438,7 @@ m32r_upload_command (char *args, int from_tty)
+   char buf[1024];
+   struct hostent *hostent;
+   struct in_addr inet_addr;
++  struct cleanup *cleanup;
+   /* First check to see if there's an ethernet port!  */
+   monitor_printf ("ust\r");
+@@ -524,7 +529,8 @@ m32r_upload_command (char *args, int from_tty)
+     printf_filtered (" -- Ethernet load complete.\n");
+   gettimeofday (&end_time, NULL);
+-  abfd = bfd_openr (args, 0);
++  abfd = gdb_bfd_openr (args, 0);
++  cleanup = make_cleanup_bfd_unref (abfd);
+   if (abfd != NULL)
+     {         /* Download is done -- print section statistics.  */
+       if (bfd_check_format (abfd, bfd_object) == 0)
+@@ -565,6 +571,7 @@ m32r_upload_command (char *args, int from_tty)
+      confused...  */
+   clear_symtab_users (0);
++  do_cleanups (cleanup);
+ }
+ /* Provide a prototype to silence -Wmissing-prototypes.  */
+diff --git a/gdb/machoread.c b/gdb/machoread.c
+index 22530ab..0d7578a 100644
+--- a/gdb/machoread.c
++++ b/gdb/machoread.c
+@@ -454,6 +454,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
+   asymbol **symp;
+   struct bfd_hash_table table;
+   int nbr_sections;
++  struct cleanup *cleanup;
+   /* Per section flag to mark which section have been rebased.  */
+   unsigned char *sections_rebased;
+@@ -466,14 +467,14 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
+     {
+       warning (_("`%s': can't read symbols: %s."), oso->name,
+                bfd_errmsg (bfd_get_error ()));
+-      bfd_close (abfd);
++      gdb_bfd_unref (abfd);
+       return;
+     }
+   if (abfd->my_archive == NULL && oso->mtime != bfd_get_mtime (abfd))
+     {
+       warning (_("`%s': file time stamp mismatch."), oso->name);
+-      bfd_close (abfd);
++      gdb_bfd_unref (abfd);
+       return;
+     }
+@@ -482,7 +483,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
+                               oso->nbr_syms))
+     {
+       warning (_("`%s': can't create hash table"), oso->name);
+-      bfd_close (abfd);
++      gdb_bfd_unref (abfd);
+       return;
+     }
+@@ -629,18 +630,15 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
+   bfd_hash_table_free (&table);
+-  /* Make sure that the filename was malloc'ed.  The current filename comes
+-     either from an OSO symbol name or from an archive name.  Memory for both
+-     is not managed by gdb.  */
+-  abfd->filename = xstrdup (abfd->filename);
+-
+   /* We need to clear SYMFILE_MAINLINE to avoid interractive question
+      from symfile.c:symbol_file_add_with_addrs_or_offsets.  */
++  cleanup = make_cleanup_bfd_unref (abfd);
+   symbol_file_add_from_bfd
+     (abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
+      main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
+                           | OBJF_READNOW | OBJF_USERLOADED),
+      main_objfile);
++  do_cleanups (cleanup);
+ }
+ /* Read symbols from the vector of oso files.  */
+@@ -651,6 +649,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+   int ix;
+   VEC (oso_el) *vec;
+   oso_el *oso;
++  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+   vec = oso_vector;
+   oso_vector = NULL;
+@@ -677,6 +676,8 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+         memcpy (archive_name, oso->name, pfx_len);
+         archive_name[pfx_len] = '\0';
++        make_cleanup (xfree, archive_name);
++
+           /* Compute number of oso for this archive.  */
+           for (last_ix = ix;
+                VEC_iterate (oso_el, vec, last_ix, oso2); last_ix++)
+@@ -686,7 +687,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+             }
+         /* Open the archive and check the format.  */
+-        archive_bfd = bfd_openr (archive_name, gnutarget);
++        archive_bfd = gdb_bfd_openr (archive_name, gnutarget);
+         if (archive_bfd == NULL)
+           {
+             warning (_("Could not open OSO archive file \"%s\""),
+@@ -698,17 +699,18 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+           {
+             warning (_("OSO archive file \"%s\" not an archive."),
+                      archive_name);
+-            bfd_close (archive_bfd);
++            gdb_bfd_unref (archive_bfd);
+               ix = last_ix;
+             continue;
+           }
+-        member_bfd = bfd_openr_next_archived_file (archive_bfd, NULL);
 +
-+        first = True
-+        block = func.value
-+
-+        for sym in block:
-+            if not sym.is_argument:
-+                continue;
-+
-+            if not first:
-+                stream.write (", ")
-+
-+            self.write_symbol (stream, sym, block)
-+            first = False
-+
-+    # FIXME: this should probably just be a method on gdb.Frame.
-+    # But then we need stream wrappers.
-+    def describe (self, stream, full):
-+        if self.type () == gdb.DUMMY_FRAME:
-+            stream.write (" <function called from gdb>\n")
-+        elif self.type () == gdb.SIGTRAMP_FRAME:
-+            stream.write (" <signal handler called>\n")
-+        else:
-+            sal = self.find_sal ()
-+            pc = self.pc ()
-+            name = self.name ()
-+            if not name:
-+                name = "??"
-+            if pc != sal.pc or not sal.symtab:
-+                stream.write (" 0x%08x in" % pc)
-+            stream.write (" " + name + " (")
-+
-+            func = self.function ()
-+            self.print_frame_args (stream, func)
-+
-+            stream.write (")")
-+
-+            if sal.symtab and sal.symtab.filename:
-+                stream.write (" at " + sal.symtab.filename)
-+                stream.write (":" + str (sal.line))
-+
-+            if not self.name () or (not sal.symtab or not sal.symtab.filename):
-+                lib = gdb.solib_address (pc)
-+                if lib:
-+                    stream.write (" from " + lib)
-+
-+            stream.write ("\n")
-+
-+            if full:
-+                self.print_frame_locals (stream, func)
-+
-+    def __getattr__ (self, name):
-+        return getattr (self.frame, name)
-diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
-new file mode 100644
-index 0000000..b375c68
---- /dev/null
-+++ b/gdb/python/lib/gdb/__init__.py
-@@ -0,0 +1,19 @@
-+# Startup code.
-+
-+# Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+# Load the require command by default.
-+import gdb.command.require
-diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
-new file mode 100644
-index 0000000..2baab5f
---- /dev/null
-+++ b/gdb/python/lib/gdb/backtrace.py
-@@ -0,0 +1,42 @@
-+# Filtering backtrace.
-+
-+# Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+import itertools
-+
-+# Our only exports.
-+__all__ = ['push_frame_filter', 'create_frame_filter']
-+
-+frame_filter = None
-+
-+def push_frame_filter (constructor):
-+    """Register a new backtrace filter class with the 'backtrace' command.
-+The filter will be passed an iterator as an argument.  The iterator
-+will return gdb.Frame-like objects.  The filter should in turn act as
-+an iterator returning such objects."""
-+    global frame_filter
-+    if frame_filter == None:
-+        frame_filter = constructor
-+    else:
-+        frame_filter = lambda iterator: constructor (frame_filter (iterator))
-+
-+def create_frame_filter (iter):
-+    global frame_filter
-+    if frame_filter is None:
-+        return iter
-+    return frame_filter (iter)
-+
-diff --git a/gdb/python/lib/gdb/command/__init__.py b/gdb/python/lib/gdb/command/__init__.py
-new file mode 100644
-index 0000000..8b13789
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/__init__.py
-@@ -0,0 +1 @@
-+
-diff --git a/gdb/python/lib/gdb/command/alias.py b/gdb/python/lib/gdb/command/alias.py
-new file mode 100644
-index 0000000..96b6618
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/alias.py
-@@ -0,0 +1,59 @@
-+# Alias command.
-+
-+# Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+
-+class AliasImplementation (gdb.Command):
-+    def __init__ (self, name, real, doc):
-+        # Have to set __doc__ before the super init call.
-+        # It would be nice if gdb's help looked up __doc__ dynamically.
-+        self.__doc__ = doc
-+        # Note: no good way to complete :(
-+        super (AliasImplementation, self).__init__ (name, gdb.COMMAND_NONE)
-+        self.real = real
-+
-+    def invoke(self, arg, from_tty):
-+        gdb.execute (self.real + ' ' + arg, from_tty)
-+
-+class AliasCommand (gdb.Command):
-+    """Alias one command to another.
-+In the simplest form, the first word is the name of the alias, and
-+the remaining words are the the expansion.
-+An '=' by itself can be used to define a multi-word alias; words
-+before the '=' are the name of the new command."""
-+
-+    def __init__ (self):
-+        # Completion is not quite right here.
-+        super (AliasCommand, self).__init__ ("alias", gdb.COMMAND_NONE,
-+                                             gdb.COMPLETE_COMMAND)
-+
-+    def invoke (self, arg, from_tty):
-+        self.dont_repeat ()
-+        # Without some form of quoting we can't alias a multi-word
-+        # command to another command.
-+        args = arg.split()
-+        try:
-+            start = args.index ('=')
-+            end = start + 1
-+        except ValueError:
-+            start = 1
-+            end = 1
-+        target = " ".join(args[end:])
-+        AliasImplementation (" ".join (args[0:start]), target,
-+                             "This command is an alias for '%s'." % target)
-+
-+AliasCommand()
-diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
-new file mode 100644
-index 0000000..ec9a527
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/backtrace.py
-@@ -0,0 +1,106 @@
-+# New backtrace command.
-+
-+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+import gdb.backtrace
-+import itertools
-+from gdb.FrameIterator import FrameIterator
-+from gdb.FrameWrapper import FrameWrapper
-+import sys
-+
-+class ReverseBacktraceParameter (gdb.Parameter):
-+    """The new-backtrace command can show backtraces in 'reverse' order.
-+This means that the innermost frame will be printed last.
-+Note that reverse backtraces are more expensive to compute."""
++        member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd, NULL);
+         if (member_bfd == NULL)
+           {
+             warning (_("Could not read archive members out of "
+                        "OSO archive \"%s\""), archive_name);
+-            bfd_close (archive_bfd);
++            gdb_bfd_unref (archive_bfd);
+               ix = last_ix;
+             continue;
+           }
+@@ -738,12 +740,12 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+                 }
+               prev = member_bfd;
+-            member_bfd = bfd_openr_next_archived_file
+-              (archive_bfd, member_bfd);
++            member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd,
++                                                           member_bfd);
+               /* Free previous member if not referenced by an oso.  */
+               if (ix2 >= last_ix)
+-                bfd_close (prev);
++                gdb_bfd_unref (prev);
+           }
+           for (ix2 = ix; ix2 < last_ix; ix2++)
+             {
+@@ -759,7 +761,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+       {
+           bfd *abfd;
+-        abfd = bfd_openr (oso->name, gnutarget);
++        abfd = gdb_bfd_openr (oso->name, gnutarget);
+         if (!abfd)
+             warning (_("`%s': can't open to read symbols: %s."), oso->name,
+                      bfd_errmsg (bfd_get_error ()));
+@@ -771,6 +773,7 @@ macho_symfile_read_all_oso (struct objfile *main_objfile, int symfile_flags)
+     }
+   VEC_free (oso_el, vec);
++  do_cleanups (cleanup);
+ }
+ /* DSYM (debug symbols) files contain the debug info of an executable.
+@@ -808,20 +811,17 @@ macho_check_dsym (struct objfile *objfile)
+       warning (_("can't find UUID in %s"), objfile->name);
+       return NULL;
+     }
+-  dsym_filename = xstrdup (dsym_filename);
+-  dsym_bfd = bfd_openr (dsym_filename, gnutarget);
++  dsym_bfd = gdb_bfd_openr (dsym_filename, gnutarget);
+   if (dsym_bfd == NULL)
+     {
+       warning (_("can't open dsym file %s"), dsym_filename);
+-      xfree (dsym_filename);
+       return NULL;
+     }
+   if (!bfd_check_format (dsym_bfd, bfd_object))
+     {
+-      bfd_close (dsym_bfd);
++      gdb_bfd_unref (dsym_bfd);
+       warning (_("bad dsym file format: %s"), bfd_errmsg (bfd_get_error ()));
+-      xfree (dsym_filename);
+       return NULL;
+     }
+@@ -829,16 +829,14 @@ macho_check_dsym (struct objfile *objfile)
+                                  BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
+     {
+       warning (_("can't find UUID in %s"), dsym_filename);
+-      bfd_close (dsym_bfd);
+-      xfree (dsym_filename);
++      gdb_bfd_unref (dsym_bfd);
+       return NULL;
+     }
+   if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
+               sizeof (main_uuid->command.uuid.uuid)))
+     {
+       warning (_("dsym file UUID doesn't match the one in %s"), objfile->name);
+-      bfd_close (dsym_bfd);
+-      xfree (dsym_filename);
++      gdb_bfd_unref (dsym_bfd);
+       return NULL;
+     }
+   return dsym_bfd;
+@@ -902,6 +900,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
+         int ix;
+         oso_el *oso;
+           struct bfd_section *asect, *dsect;
++        struct cleanup *cleanup;
+         if (mach_o_debug_level > 0)
+           printf_unfiltered (_("dsym file found\n"));
+@@ -922,7 +921,9 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
+             }
+         /* Add the dsym file as a separate file.  */
++        cleanup = make_cleanup_bfd_unref (dsym_bfd);
+           symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
++        do_cleanups (cleanup);
+         /* Don't try to read dwarf2 from main file or shared libraries.  */
+           return;
+diff --git a/gdb/main.c b/gdb/main.c
+index d075694..e4da3f1 100644
+--- a/gdb/main.c
++++ b/gdb/main.c
+@@ -37,6 +37,7 @@
+ #include "interps.h"
+ #include "main.h"
++#include "python/python.h"
+ #include "source.h"
+ #include "cli/cli-cmds.h"
+ #include "python/python.h"
+@@ -283,6 +284,8 @@ captured_main (void *data)
+   char *cdarg = NULL;
+   char *ttyarg = NULL;
++  int python_script = 0;
 +
-+    set_doc = "Enable or disable reverse backtraces."
-+    show_doc = "Show whether backtraces will be printed in reverse order."
+   /* These are static so that we can take their address in an
+      initializer.  */
+   static int print_help;
+@@ -471,10 +474,14 @@ captured_main (void *data)
+       {"args", no_argument, &set_args, 1},
+       {"l", required_argument, 0, 'l'},
+       {"return-child-result", no_argument, &return_child_result, 1},
++#if HAVE_PYTHON
++      {"python", no_argument, 0, 'P'},
++      {"P", no_argument, 0, 'P'},
++#endif
+       {0, no_argument, 0, 0}
+     };
+-    while (1)
++    while (!python_script)
+       {
+       int option_index;
+@@ -492,6 +499,9 @@ captured_main (void *data)
+         case 0:
+           /* Long option that just sets a flag.  */
+           break;
++        case 'P':
++          python_script = 1;
++          break;
+         case OPT_SE:
+           symarg = optarg;
+           execarg = optarg;
+@@ -699,7 +709,31 @@ captured_main (void *data)
+   /* Now that gdb_init has created the initial inferior, we're in
+      position to set args for that inferior.  */
+-  if (set_args)
++  if (python_script)
++    {
++      /* The first argument is a python script to evaluate, and
++       subsequent arguments are passed to the script for
++       processing there.  */
++      if (optind >= argc)
++      {
++        fprintf_unfiltered (gdb_stderr,
++                            _("%s: Python script file name required\n"),
++                            argv[0]);
++        exit (1);
++      }
 +
-+    def __init__(self):
-+        gdb.Parameter.__init__ (self, "reverse-backtrace",
-+                                gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
-+        # Default to compatibility with gdb.
-+        self.value = False
-+
-+class FilteringBacktrace (gdb.Command):
-+    """Print backtrace of all stack frames, or innermost COUNT frames.
-+With a negative argument, print outermost -COUNT frames.
-+Use of the 'full' qualifier also prints the values of the local variables.
-+Use of the 'raw' qualifier avoids any filtering by loadable modules.
-+"""
-+
-+    def __init__ (self):
-+        # FIXME: this is not working quite well enough to replace
-+        # "backtrace" yet.
-+        gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
-+        self.reverse = ReverseBacktraceParameter()
-+
-+    def reverse_iter (self, iter):
-+        result = []
-+        for item in iter:
-+            result.append (item)
-+        result.reverse()
-+        return result
-+
-+    def final_n (self, iter, x):
-+        result = []
-+        for item in iter:
-+            result.append (item)
-+        return result[x:]
-+
-+    def invoke (self, arg, from_tty):
-+        i = 0
-+        count = 0
-+        filter = True
-+        full = False
-+
-+        for word in arg.split (" "):
-+            if word == '':
-+                continue
-+            elif word == 'raw':
-+                filter = False
-+            elif word == 'full':
-+                full = True
-+            else:
-+                count = int (word)
-+
-+        # FIXME: provide option to start at selected frame
-+        # However, should still number as if starting from newest
-+      newest_frame = gdb.selected_thread ().newest_frame ()
-+        iter = itertools.imap (FrameWrapper,
-+                               FrameIterator (newest_frame))
-+        if filter:
-+            iter = gdb.backtrace.create_frame_filter (iter)
-+
-+        # Now wrap in an iterator that numbers the frames.
-+        iter = itertools.izip (itertools.count (0), iter)
-+
-+        # Reverse if the user wanted that.
-+        if self.reverse.value:
-+            iter = self.reverse_iter (iter)
-+
-+        # Extract sub-range user wants.
-+        if count < 0:
-+            iter = self.final_n (iter, count)
-+        elif count > 0:
-+            iter = itertools.islice (iter, 0, count)
-+
-+        for pair in iter:
-+            sys.stdout.write ("#%-2d" % pair[0])
-+            pair[1].describe (sys.stdout, full)
-+
-+FilteringBacktrace()
-diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
-new file mode 100644
-index 0000000..6fa48ff
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/ignore_errors.py
-@@ -0,0 +1,37 @@
-+# Ignore errors in user commands.
-+
-+# Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+
-+class IgnoreErrorsCommand (gdb.Command):
-+    """Execute a single command, ignoring all errors.
-+Only one-line commands are supported.
-+This is primarily useful in scripts."""
-+
-+    def __init__ (self):
-+        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
-+                                                    gdb.COMMAND_OBSCURE,
-+                                                    # FIXME...
-+                                                    gdb.COMPLETE_COMMAND)
-+
-+    def invoke (self, arg, from_tty):
-+        try:
-+            gdb.execute (arg, from_tty)
-+        except:
-+            pass
-+
-+IgnoreErrorsCommand ()
-diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
-new file mode 100644
-index 0000000..21a0bf0
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/pahole.py
-@@ -0,0 +1,75 @@
-+# pahole command for gdb
-+
-+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+
-+class Pahole (gdb.Command):
-+    """Show the holes in a structure.
-+This command takes a single argument, a type name.
-+It prints the type and displays comments showing where holes are."""
-+
-+    def __init__ (self):
-+        super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
-+                                       gdb.COMPLETE_SYMBOL)
-+
-+    def pahole (self, type, level, name):
-+        if name is None:
-+            name = ''
-+        tag = type.tag
-+        if tag is None:
-+            tag = ''
-+        print '%sstruct %s {' % (' ' * (2 * level), tag)
-+        bitpos = 0
-+        for field in type.fields ():
-+            # Skip static fields.
-+            if not hasattr (field, ('bitpos')):
-+                continue
-+
-+            ftype = field.type.strip_typedefs()
-+
-+            if bitpos != field.bitpos:
-+                hole = field.bitpos - bitpos
-+                print '  /* XXX %d bit hole, try to pack */' % hole
-+                bitpos = field.bitpos
-+            if field.bitsize > 0:
-+                fieldsize = field.bitsize
-+            else:
-+                # TARGET_CHAR_BIT here...
-+                fieldsize = 8 * ftype.sizeof
-+
-+            # TARGET_CHAR_BIT
-+            print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
-+            bitpos = bitpos + fieldsize
-+
-+            if ftype.code == gdb.TYPE_CODE_STRUCT:
-+                self.pahole (ftype, level + 1, field.name)
-+            else:
-+                print ' ' * (2 + 2 * level),
-+                print '%s %s' % (str (ftype), field.name)
-+
-+        print ' ' * (14 + 2 * level),
-+        print '} %s' % name
-+
-+    def invoke (self, arg, from_tty):
-+        type = gdb.lookup_type (arg)
-+        type = type.strip_typedefs ()
-+        if type.code != gdb.TYPE_CODE_STRUCT:
-+            raise TypeError, '%s is not a struct type' % arg
-+        print ' ' * 14,
-+        self.pahole (type, 0, '')
-+
-+Pahole()
-diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
-new file mode 100644
-index 0000000..1fbc1e8
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/require.py
-@@ -0,0 +1,57 @@
-+# Demand-loading commands.
-+
-+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+import os
-+
-+class RequireCommand (gdb.Command):
-+    """Prefix command for requiring features."""
-+
-+    def __init__ (self):
-+        super (RequireCommand, self).__init__ ("require",
-+                                               gdb.COMMAND_SUPPORT,
-+                                               gdb.COMPLETE_NONE,
-+                                               True)
-+
-+class RequireSubcommand (gdb.Command):
-+    """Demand-load a command by name."""
-+
-+    def __init__ (self, name):
-+        self.__doc__ = "Demand-load a %s by name." % name
-+        super (RequireSubcommand, self).__init__ ("require %s" % name,
-+                                                  gdb.COMMAND_SUPPORT)
-+        self.name = name
-+
-+    def invoke (self, arg, from_tty):
-+        for cmd in arg.split():
-+            exec ('import gdb.' + self.name + '.' + cmd, globals ())
-+
-+    def complete (self, text, word):
-+        dir = gdb.pythondir + '/gdb/' + self.name
-+        result = []
-+        for file in os.listdir(dir):
-+            if not file.startswith (word) or not file.endswith ('.py'):
-+                continue
-+            feature = file[0:-3]
-+            if feature == 'require' or feature == '__init__':
-+                continue
-+            result.append (feature)
-+        return result
-+
-+RequireCommand()
-+RequireSubcommand("command")
-+RequireSubcommand("function")
-diff --git a/gdb/python/lib/gdb/command/save_breakpoints.py b/gdb/python/lib/gdb/command/save_breakpoints.py
-new file mode 100644
-index 0000000..6143187
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/save_breakpoints.py
-@@ -0,0 +1,65 @@
-+# Save breakpoints.
-+
-+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+from __future__ import with_statement
-+import gdb
-+
-+class SavePrefixCommand (gdb.Command):
-+  "Prefix command for saving things."
-+
-+  def __init__ (self):
-+    super (SavePrefixCommand, self).__init__ ("save",
-+                                              gdb.COMMAND_SUPPORT,
-+                                              gdb.COMPLETE_NONE, True)
-+
-+class SaveBreakpointsCommand (gdb.Command):
-+    """Save the current breakpoints to a file.
-+This command takes a single argument, a file name.
-+The breakpoints can be restored using the 'source' command."""
-+
-+    def __init__ (self):
-+        super (SaveBreakpointsCommand, self).__init__ ("save breakpoints",
-+                                                       gdb.COMMAND_SUPPORT,
-+                                                       gdb.COMPLETE_FILENAME)
-+
-+    def invoke (self, arg, from_tty):
-+        self.dont_repeat ()
-+        bps = gdb.breakpoints ()
-+        if bps is None:
-+            raise RuntimeError, 'No breakpoints to save'
-+        with open (arg.strip (), 'w') as f:
-+            for bp in bps:
-+                print >> f, "break", bp.location,
-+                if bp.thread is not None:
-+                    print >> f, " thread", bp.thread,
-+                if bp.condition is not None:
-+                    print >> f, " if", bp.condition,
-+                print >> f
-+                if not bp.enabled:
-+                    print >> f, "disable $bpnum"
-+                # Note: we don't save the ignore count; there doesn't
-+                # seem to be much point.
-+                commands = bp.commands
-+                if commands is not None:
-+                    print >> f, "commands"
-+                    # Note that COMMANDS has a trailing newline.
-+                    print >> f, commands,
-+                    print >> f, "end"
-+                print >> f
-+
-+SavePrefixCommand ()
-+SaveBreakpointsCommand ()
-diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
-new file mode 100644
-index 0000000..faf54ed
---- /dev/null
-+++ b/gdb/python/lib/gdb/command/upto.py
-@@ -0,0 +1,129 @@
-+# upto command.
-+
-+# Copyright (C) 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+import re
-+from gdb.FrameIterator import FrameIterator
-+from gdb.FrameWrapper import FrameWrapper
-+
-+class UptoPrefix (gdb.Command):
-+    def __init__ (self):
-+        super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
-+                                           prefix = True)
-+
-+class UptoImplementation (gdb.Command):
-+    def __init__ (self, subcommand):
-+        super (UptoImplementation, self).__init__ ("upto " + subcommand,
-+                                                   gdb.COMMAND_STACK)
-+
-+    def search (self):
-+        saved = gdb.selected_frame ()
-+        iter = FrameIterator (saved)
-+        found = False
-+        try:
-+            for frame in iter:
-+                frame.select ()
-+                try:
-+                    if self.filter (frame):
-+                        wrapper = FrameWrapper (frame)
-+                        wrapper.describe (sys.stdout, False)
-+                        return
-+                except:
-+                    pass
-+        except:
-+            pass
-+        saved.select ()
-+        raise RuntimeError, 'Could not find a matching frame'
-+
-+    def invoke (self, arg, from_tty):
-+        self.rx = re.compile (arg)
-+        self.search ()
-+
-+class UptoSymbolCommand (UptoImplementation):
-+    """Select and print some calling stack frame, based on symbol.
-+The argument is a regular expression.  This command moves up the
-+stack, stopping at the first frame whose symbol matches the regular
-+expression."""
-+
-+    def __init__ (self):
-+        super (UptoSymbolCommand, self).__init__ ("symbol")
-+
-+    def filter (self, frame):
-+        name = frame.name ()
-+        if name is not None:
-+            if self.rx.search (name) is not None:
-+                return True
-+        return False
-+
-+class UptoSourceCommand (UptoImplementation):
-+    """Select and print some calling stack frame, based on source file.
-+The argument is a regular expression.  This command moves up the
-+stack, stopping at the first frame whose source file name matches the
-+regular expression."""
-+
-+    def __init__ (self):
-+        super (UptoSourceCommand, self).__init__ ("source")
-+
-+    def filter (self, frame):
-+        name = frame.find_sal ().symtab.filename
-+        if name is not None:
-+            if self.rx.search (name) is not None:
-+                return True
-+        return False
-+
-+class UptoObjectCommand (UptoImplementation):
-+    """Select and print some calling stack frame, based on object file.
-+The argument is a regular expression.  This command moves up the
-+stack, stopping at the first frame whose object file name matches the
-+regular expression."""
-+
-+    def __init__ (self):
-+        super (UptoObjectCommand, self).__init__ ("object")
-+
-+    def filter (self, frame):
-+        name = frame.find_sal ().symtab.objfile.filename
-+        if name is not None:
-+            if self.rx.search (name) is not None:
-+                return True
-+        return False
-+
-+class UptoWhereCommand (UptoImplementation):
-+    """Select and print some calling stack frame, based on expression.
-+The argument is an expression.  This command moves up the stack,
-+parsing and evaluating the expression in each frame.  This stops when
-+the expression evaluates to a non-zero (true) value."""
-+
-+    def __init__ (self):
-+        super (UptoWhereCommand, self).__init__ ("where")
-+
-+    def filter (self, frame):
-+        try:
-+            if gdb.parse_and_eval (self.expression):
-+                return True
-+        except:
-+            pass
-+        return False
-+
-+    def invoke (self, arg, from_tty):
-+        self.expression = arg
-+        self.search ()
-+
-+UptoPrefix ()
-+UptoSymbolCommand ()
-+UptoSourceCommand ()
-+UptoObjectCommand ()
-+UptoWhereCommand ()
-diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
-new file mode 100644
-index 0000000..8b13789
---- /dev/null
-+++ b/gdb/python/lib/gdb/function/__init__.py
-@@ -0,0 +1 @@
-+
-diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
-new file mode 100644
-index 0000000..2b9c5c7
---- /dev/null
-+++ b/gdb/python/lib/gdb/function/caller_is.py
-@@ -0,0 +1,58 @@
-+# Caller-is functions.
-+
-+# Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+import re
-+
-+class CallerIs (gdb.Function):
-+    """Return True if the calling function's name is equal to a string.
-+This function takes one or two arguments.
-+The first argument is the name of a function; if the calling function's
-+name is equal to this argument, this function returns True.
-+The optional second argument tells this function how many stack frames
-+to traverse to find the calling function.  The default is 1."""
-+
-+    def __init__ (self):
-+        super (CallerIs, self).__init__ ("caller_is")
-+
-+    def invoke (self, name, nframes = 1):
-+        frame = gdb.selected_frame ()
-+        while nframes > 0:
-+            frame = frame.older ()
-+            nframes = nframes - 1
-+        return frame.name () == name.string ()
-+
-+class CallerMatches (gdb.Function):
-+    """Return True if the calling function's name matches a string.
-+This function takes one or two arguments.
-+The first argument is a regular expression; if the calling function's
-+name is matched by this argument, this function returns True.
-+The optional second argument tells this function how many stack frames
-+to traverse to find the calling function.  The default is 1."""
-+
-+    def __init__ (self):
-+        super (CallerMatches, self).__init__ ("caller_matches")
-+
-+    def invoke (self, name, nframes = 1):
-+        frame = gdb.selected_frame ()
-+        while nframes > 0:
-+            frame = frame.older ()
-+            nframes = nframes - 1
-+        return re.match (name.string (), frame.name ()) is not None
-+
-+CallerIs()
-+CallerMatches()
-diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
-new file mode 100644
-index 0000000..debb3bb
---- /dev/null
-+++ b/gdb/python/lib/gdb/function/in_scope.py
-@@ -0,0 +1,47 @@
-+# In-scope function.
-+
-+# Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+import gdb
-+
-+class InScope (gdb.Function):
-+    """Return True if all the given variables or macros are in scope.
-+Takes one argument for each variable name to be checked."""
-+
-+    def __init__ (self):
-+      super (InScope, self).__init__ ("in_scope")
-+
-+    def invoke (self, *vars):
-+        if len (vars) == 0:
-+          raise TypeError, "in_scope takes at least one argument"
-+
-+        # gdb.Value isn't hashable so it can't be put in a map.
-+      # Convert to string first.
-+      wanted = set (map (lambda x: x.string (), vars))
-+      found = set ()
-+      block = gdb.selected_frame ().block ()
-+      while block:
-+          for sym in block:
-+              if (sym.is_argument or sym.is_constant
-+                    or sym.is_function or sym.is_variable):
-+                  if sym.name in wanted:
-+                      found.add (sym.name)
-+
-+          block = block.superblock
-+
-+      return wanted == found
-+
-+InScope ()
-diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
-index 2cff4ba..9255336 100644
---- a/gdb/python/py-cmd.c
-+++ b/gdb/python/py-cmd.c
-@@ -49,8 +49,7 @@ static struct cmdpy_completer completers[] =
- #define N_COMPLETERS (sizeof (completers) / sizeof (completers[0]))
--/* A gdb command.  For the time being only ordinary commands (not
--   set/show commands) are allowed.  */
-+/* A gdb command.  */
- struct cmdpy_object
- {
-   PyObject_HEAD
-diff --git a/gdb/python/py-hooks.c b/gdb/python/py-hooks.c
-new file mode 100644
-index 0000000..a3140bc
---- /dev/null
-+++ b/gdb/python/py-hooks.c
-@@ -0,0 +1,50 @@
-+/* Notifications from gdb to Python
-+
-+   Copyright (C) 2008 Free Software Foundation, Inc.
-+
-+   This file is part of GDB.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-+
-+#include "defs.h"
-+#include "cli/cli-decode.h"
-+#include "charset.h"
-+#include "python.h"
-+#include "python-internal.h"
-+#include "observer.h"
-+
-+PyObject *
-+gdbpy_get_hook_function (const char *name)
-+{
-+  PyObject *hooks;
-+  PyObject *result;
-+
-+  if (! PyObject_HasAttrString (gdb_module, "hooks"))
-+    return NULL;
-+  hooks = PyObject_GetAttrString (gdb_module, "hooks");
-+  if (! hooks)
-+    return NULL;
-+  /* The cast is because the Python function doesn't declare const argument.
-+     This is a problem in Python version 2.4, but not in 2.5.  */
-+  if (! PyObject_HasAttrString (hooks, (char *) name))
-+    {
-+      Py_DECREF (hooks);
-+      return NULL;
-+    }
-+  /* The cast is because the Python function doesn't declare const argument.
-+     This is a problem in Python version 2.4, but not in 2.5.  */
-+  result = PyObject_GetAttrString (hooks, (char *) name);
-+  Py_DECREF (hooks);
-+  return result;
-+}
-diff --git a/gdb/python/py-membuf.c b/gdb/python/py-membuf.c
-new file mode 100644
-index 0000000..7bc294c
---- /dev/null
-+++ b/gdb/python/py-membuf.c
-@@ -0,0 +1,268 @@
-+/* Python interface to the inferior memory.
-+
-+   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-+
-+   This file is part of GDB.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-+
-+#include "defs.h"
-+#include "exceptions.h"
-+#include "gdbcore.h"
-+#include "python-internal.h"
-+
-+typedef struct {
-+  PyObject_HEAD
-+  void *buffer;
-+
-+  /* These are kept just for mbpy_str.  */
-+  CORE_ADDR addr;
-+  CORE_ADDR length;
-+} membuf_object;
-+
-+static PyTypeObject membuf_object_type;
-+
-+/* Implementation of gdb.read_memory (address, length).
-+   Returns a Python buffer object with LENGTH bytes of the inferior's memory
-+   at ADDRESS. Both arguments are integers.  */
-+
-+PyObject *
-+gdbpy_read_memory (PyObject *self, PyObject *args)
-+{
-+  int error = 0;
-+  CORE_ADDR addr, length;
-+  void *buffer = NULL;
-+  membuf_object *membuf_obj;
-+  PyObject *addr_obj, *length_obj;
-+  struct cleanup *cleanups = NULL;
-+  volatile struct gdb_exception except;
-+
-+  if (! PyArg_ParseTuple (args, "OO", &addr_obj, &length_obj))
-+    return NULL;
-+
-+  TRY_CATCH (except, RETURN_MASK_ALL)
-+    {
-+      if (!get_addr_from_python (addr_obj, &addr)
-+        || !get_addr_from_python (length_obj, &length))
-+      {
-+        error = 1;
-+        break;
-+      }
-+
-+      buffer = xmalloc (length);
-+      cleanups = make_cleanup (xfree, buffer);
-+
-+      read_memory (addr, buffer, length);
-+    }
-+  GDB_PY_HANDLE_EXCEPTION (except);
-+
-+  if (error)
-+    return NULL;
-+
-+  discard_cleanups (cleanups);
-+
-+  membuf_obj = PyObject_New (membuf_object, &membuf_object_type);
-+  if (membuf_obj == NULL)
-+    {
-+      xfree (buffer);
-+      PyErr_SetString (PyExc_MemoryError,
-+                     "Could not allocate memory buffer object.");
-+      return NULL;
-+    }
-+
-+  membuf_obj->buffer = buffer;
-+  membuf_obj->addr = addr;
-+  membuf_obj->length = length;
-+
-+  return PyBuffer_FromReadWriteObject ((PyObject *) membuf_obj, 0,
-+                                     Py_END_OF_BUFFER);
-+}
-+
-+/* Implementation of gdb.write_memory (address, buffer [, length]).
-+   Writes the contents of BUFFER (a Python object supporting the read buffer
-+   protocol) at ADDRESS in the inferior's memory.  Write LENGTH bytes from
-+   BUFFER, or its entire contents if the argument is not provided.  The
-+   function returns nothing.  */
-+
-+PyObject *
-+gdbpy_write_memory (PyObject *self, PyObject *args)
-+{
-+  int buf_len, error = 0;
-+  const char *buffer;
-+  CORE_ADDR addr, length;
-+  PyObject *addr_obj, *length_obj = NULL;
-+  volatile struct gdb_exception except;
-+
-+  if (! PyArg_ParseTuple (args, "Os#|O", &addr_obj, &buffer, &buf_len,
-+                        &length_obj))
-+    return NULL;
-+
-+  TRY_CATCH (except, RETURN_MASK_ALL)
-+    {
-+      if (!get_addr_from_python (addr_obj, &addr))
-+      {
-+        error = 1;
-+        break;
-+      }
-+      
-+      if (!length_obj)
-+      length = buf_len;
-+      else if (!get_addr_from_python (length_obj, &length))
-+      {
-+        error = 1;
-+        break;
-+      }
-+
-+      write_memory (addr, buffer, length);
-+    }
-+  GDB_PY_HANDLE_EXCEPTION (except);
-+
-+  if (error)
-+    return NULL;
-+
-+  Py_RETURN_NONE;
-+}
-+
-+/* Destructor of Membuf objects.  */
-+
-+static void
-+mbpy_dealloc (PyObject *self)
-+{
-+  xfree (((membuf_object *) self)->buffer);
-+  self->ob_type->tp_free (self);
-+}
-+
-+/* Return a description of the Membuf object.  */
-+
-+static PyObject *
-+mbpy_str (PyObject *self)
-+{
-+  membuf_object *membuf_obj = (membuf_object *) self;
-+
-+  return PyString_FromFormat ("memory buffer for address %s, %s bytes long",
-+                            paddress (membuf_obj->addr),
-+                            pulongest (membuf_obj->length));
-+}
-+
-+static Py_ssize_t
-+get_read_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
-+{
-+  membuf_object *membuf_obj = (membuf_object *) self;
-+
-+  if (segment)
-+    {
-+      PyErr_SetString (PyExc_SystemError,
-+                     "The memory buffer supports only one segment.");
-+      return -1;
-+    }
-+
-+  *ptrptr = membuf_obj->buffer;
-+
-+  return membuf_obj->length;
-+}
-+
-+static Py_ssize_t
-+get_write_buffer (PyObject *self, Py_ssize_t segment, void **ptrptr)
-+{
-+  return get_read_buffer (self, segment, ptrptr);
-+}
-+
-+static Py_ssize_t
-+get_seg_count (PyObject *self, Py_ssize_t *lenp)
-+{
-+  if (lenp)
-+    *lenp = ((membuf_object *) self)->length;
-+
-+  return 1;
-+}
-+
-+static Py_ssize_t
-+get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr)
-+{
-+  void *ptr = NULL;
-+  Py_ssize_t ret;
-+
-+  ret = get_read_buffer (self, segment, &ptr);
-+  *ptrptr = (char *) ptr;
-+
-+  return ret;
-+}
-+
-+/* Python doesn't provide a decent way to get compatibility here.  */
-+#if HAVE_LIBPYTHON2_4
-+#define CHARBUFFERPROC_NAME getcharbufferproc
-+#else
-+#define CHARBUFFERPROC_NAME charbufferproc
-+#endif
-+
-+static PyBufferProcs buffer_procs = {
-+  get_read_buffer,
-+  get_write_buffer,
-+  get_seg_count,
-+  /* The cast here works around a difference between Python 2.4 and
-+     Python 2.5.  */
-+  (CHARBUFFERPROC_NAME) get_char_buffer
-+};
-+
-+static PyTypeObject membuf_object_type = {
-+  PyObject_HEAD_INIT (NULL)
-+  0,                            /*ob_size*/
-+  "gdb.Membuf",                         /*tp_name*/
-+  sizeof (membuf_object),       /*tp_basicsize*/
-+  0,                            /*tp_itemsize*/
-+  mbpy_dealloc,                         /*tp_dealloc*/
-+  0,                            /*tp_print*/
-+  0,                            /*tp_getattr*/
-+  0,                            /*tp_setattr*/
-+  0,                            /*tp_compare*/
-+  0,                            /*tp_repr*/
-+  0,                            /*tp_as_number*/
-+  0,                            /*tp_as_sequence*/
-+  0,                            /*tp_as_mapping*/
-+  0,                            /*tp_hash */
-+  0,                            /*tp_call*/
-+  mbpy_str,                     /*tp_str*/
-+  0,                            /*tp_getattro*/
-+  0,                            /*tp_setattro*/
-+  &buffer_procs,                /*tp_as_buffer*/
-+  Py_TPFLAGS_DEFAULT,           /*tp_flags*/
-+  "GDB memory buffer object",           /*tp_doc*/
-+  0,                            /* tp_traverse */
-+  0,                            /* tp_clear */
-+  0,                            /* tp_richcompare */
-+  0,                            /* tp_weaklistoffset */
-+  0,                            /* tp_iter */
-+  0,                            /* tp_iternext */
-+  0,                            /* tp_methods */
-+  0,                            /* tp_members */
-+  0,                            /* tp_getset */
-+  0,                            /* tp_base */
-+  0,                            /* tp_dict */
-+  0,                            /* tp_descr_get */
-+  0,                            /* tp_descr_set */
-+  0,                            /* tp_dictoffset */
-+  0,                            /* tp_init */
-+  0,                            /* tp_alloc */
-+  PyType_GenericNew             /* tp_new */
-+};
-+
-+void
-+gdbpy_initialize_membuf (void)
-+{
-+  if (PyType_Ready (&membuf_object_type) < 0)
-+    return;
-+
-+  Py_INCREF (&membuf_object_type);
-+  PyModule_AddObject (gdb_module, "Membuf", (PyObject *) &membuf_object_type);
-+}
-diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
-index 434c8a5..b22c557 100644
---- a/gdb/python/py-prettyprint.c
-+++ b/gdb/python/py-prettyprint.c
-@@ -204,10 +204,10 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
-             && result != Py_None)
-           {
-             *out_value = convert_value_from_python (result);
--            if (PyErr_Occurred ())
--              *out_value = NULL;
--            Py_DECREF (result);
--            result = NULL;
-+            if (PyErr_Occurred ())
-+              *out_value = NULL;
-+            Py_DECREF (result);
-+            result = NULL;
-           }
-       }
-     }
-@@ -700,14 +700,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
- {
-   PyObject *val_obj;
-   PyObject *pretty_printer = NULL;
--  volatile struct gdb_exception except;
--  TRY_CATCH (except, RETURN_MASK_ALL)
--    {
--      value = value_copy (value);
--    }
--  GDB_PY_HANDLE_EXCEPTION (except);
--  
-   val_obj = value_to_value_object (value);
-   if (! val_obj)
-     return NULL;
-diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
-index b901255..4ff18e5 100644
---- a/gdb/python/py-type.c
-+++ b/gdb/python/py-type.c
-@@ -27,6 +27,8 @@
- #include "demangle.h"
- #include "objfiles.h"
- #include "language.h"
-+#include "observer.h"
-+#include "gdb_assert.h"
- typedef struct pyty_type_object
- {
-@@ -35,11 +37,17 @@ typedef struct pyty_type_object
-   /* If a Type object is associated with an objfile, it is kept on a
-      doubly-linked list, rooted in the objfile.  This lets us copy the
--     underlying struct type when the objfile is deleted.  */
-+     underlying struct type when the objfile is deleted.
-+
-+     With NULL objfile Type still can be doubly-linked in the list
-+     PYTY_OBJECTS_DISCARDABLE.  */
-   struct pyty_type_object *prev;
-   struct pyty_type_object *next;
- } type_object;
-+/* First element of a doubly-linked list of TYPE_DISCARDABLE Types.  */
-+static type_object *pyty_objects_discardable;
-+
- static PyTypeObject type_object_type;
- /* A Field object.  */
-@@ -618,8 +626,59 @@ typy_str (PyObject *self)
\f
-+/* Key associated with each objfile pointing to the first element of
-+   a doubly-linked list of Types associated with this objfile.  */
- static const struct objfile_data *typy_objfile_data_key;
-+/* Link TYPE_OBJ to its appropriate list.  Either to its objfile associated one
-+   or at least to the global list for TYPE_DISCARDABLE Types.  Permanent types
-+   do not get linked anywhere.  */
-+static void
-+typy_link (type_object *type_obj)
-+{
-+  type_obj->prev = NULL;
-+
-+  if (type_obj->type && TYPE_OBJFILE (type_obj->type))
-+    {
-+      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
-+
-+      type_obj->next = objfile_data (objfile, typy_objfile_data_key);
-+      if (type_obj->next)
-+      type_obj->next->prev = type_obj;
-+      set_objfile_data (objfile, typy_objfile_data_key, type_obj);
-+    }
-+  else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
-+    {
-+      type_obj->next = pyty_objects_discardable;
-+      if (type_obj->next)
-+      type_obj->next->prev = type_obj;
-+      pyty_objects_discardable = type_obj;
-+    }
-+  else
-+    type_obj->next = NULL;
-+}
-+
-+/* Unlink TYPE_OBJ from its current list.  Permanent types are not linked
-+   anywhere and this function has no effect on them.  */
-+static void
-+typy_unlink (type_object *type_obj)
-+{
-+  if (type_obj->prev)
-+    type_obj->prev->next = type_obj->next;
-+  else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
-+    {
-+      /* Must reset head of list.  */
-+      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
-+
-+      set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
-+    }
-+  else if (pyty_objects_discardable == type_obj)
-+    pyty_objects_discardable = type_obj->next;
-+
-+  if (type_obj->next)
-+    type_obj->next->prev = type_obj->prev;
-+}
-+
- static void
- save_objfile_types (struct objfile *objfile, void *datum)
- {
-@@ -637,12 +696,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
-     {
-       type_object *next = obj->next;
--      htab_empty (copied_types);
-+      gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
-+      typy_unlink (obj);
--      obj->type = copy_type_recursive (objfile, obj->type, copied_types);
-+      obj->type = copy_type_recursive (obj->type, copied_types);
--      obj->next = NULL;
--      obj->prev = NULL;
-+      gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
-+      typy_link (obj);
-       obj = next;
-     }
-@@ -653,42 +713,25 @@ save_objfile_types (struct objfile *objfile, void *datum)
- }
- static void
--set_type (type_object *obj, struct type *type)
-+typy_dealloc (PyObject *obj)
- {
--  obj->type = type;
--  obj->prev = NULL;
--  if (type && TYPE_OBJFILE (type))
--    {
--      struct objfile *objfile = TYPE_OBJFILE (type);
-+  type_object *type_obj = (type_object *) obj;
--      obj->next = objfile_data (objfile, typy_objfile_data_key);
--      if (obj->next)
--      obj->next->prev = obj;
--      set_objfile_data (objfile, typy_objfile_data_key, obj);
--    }
--  else
--    obj->next = NULL;
-+  typy_unlink (type_obj);
-+
-+  type_obj->ob_type->tp_free (obj);
- }
-+/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
- static void
--typy_dealloc (PyObject *obj)
-+typy_types_mark_used (void)
- {
--  type_object *type = (type_object *) obj;
--
--  if (type->prev)
--    type->prev->next = type->next;
--  else if (type->type && TYPE_OBJFILE (type->type))
--    {
--      /* Must reset head of list.  */
--      struct objfile *objfile = TYPE_OBJFILE (type->type);
--
--      if (objfile)
--      set_objfile_data (objfile, typy_objfile_data_key, type->next);
--    }
--  if (type->next)
--    type->next->prev = type->prev;
-+  type_object *type_obj;
--  type->ob_type->tp_free (type);
-+  for (type_obj = pyty_objects_discardable;
-+       type_obj != NULL;
-+       type_obj = type_obj->next)
-+    type_mark_used (type_obj->type);
- }
- /* Create a new Type referring to TYPE.  */
-@@ -699,7 +742,10 @@ type_to_type_object (struct type *type)
-   type_obj = PyObject_New (type_object, &type_object_type);
-   if (type_obj)
--    set_type (type_obj, type);
-+    {
-+      type_obj->type = type;
-+      typy_link (type_obj);
-+    }
-   return (PyObject *) type_obj;
- }
-@@ -773,6 +819,8 @@ gdbpy_initialize_types (void)
-   Py_INCREF (&field_object_type);
-   PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
-+
-+  observer_attach_mark_used (typy_types_mark_used);
- }
\f
-diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
-index 2024021..e8be12d 100644
---- a/gdb/python/py-value.c
-+++ b/gdb/python/py-value.c
-@@ -25,6 +25,7 @@
- #include "language.h"
- #include "dfp.h"
- #include "valprint.h"
-+#include "observer.h"
- #ifdef HAVE_PYTHON
-@@ -1067,6 +1068,17 @@ gdbpy_is_value_object (PyObject *obj)
-   return PyObject_TypeCheck (obj, &value_object_type);
- }
-+/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
-+
-+static void
-+python_types_mark_used (void)
-+{
-+  value_object *iter;
-+
-+  for (iter = values_in_python; iter; iter = iter->next)
-+    type_mark_used (value_type (iter->value));
-+}
-+
- void
- gdbpy_initialize_values (void)
- {
-@@ -1077,6 +1089,8 @@ gdbpy_initialize_values (void)
-   PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
-   values_in_python = NULL;
-+
-+  observer_attach_mark_used (python_types_mark_used);
- }
\f
-diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
-index 2b8d301..0af99c8 100644
---- a/gdb/python/python-internal.h
-+++ b/gdb/python/python-internal.h
-@@ -82,10 +82,11 @@ struct language_defn;
- struct program_space;
- extern PyObject *gdb_module;
--extern PyTypeObject value_object_type;
- extern PyTypeObject block_object_type;
-+extern PyTypeObject value_object_type;
- extern PyTypeObject symbol_object_type;
-+/* Used in python-inferior.c.  */
- typedef struct
- {
-   PyObject_HEAD
-@@ -126,6 +127,10 @@ PyObject *block_to_block_object (struct block *block, struct objfile *objfile);
- PyObject *value_to_value_object (struct value *v);
- PyObject *type_to_type_object (struct type *);
- PyObject *frame_info_to_frame_object (struct frame_info *frame);
-+PyObject *frame_info_to_frame_object (struct frame_info *frame);
-+thread_object *create_thread_object (struct thread_info *tp);
-+thread_object *find_thread_object (ptid_t ptid);
-+PyObject *find_inferior_object (int pid);
- PyObject *pspace_to_pspace_object (struct program_space *);
- PyObject *pspy_get_printers (PyObject *, void *);
-@@ -145,8 +150,11 @@ struct type *type_object_to_type (PyObject *obj);
- struct symtab *symtab_object_to_symtab (PyObject *obj);
- struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj);
-+PyObject *gdbpy_get_hook_function (const char *);
- void gdbpy_initialize_auto_load (void);
-+
- void gdbpy_initialize_values (void);
-+void gdbpy_initialize_breakpoints (void);
- void gdbpy_initialize_frames (void);
- void gdbpy_initialize_symtabs (void);
- void gdbpy_initialize_commands (void);
-@@ -154,6 +162,7 @@ void gdbpy_initialize_symbols (void);
- void gdbpy_initialize_symtabs (void);
- void gdbpy_initialize_blocks (void);
- void gdbpy_initialize_types (void);
-+void gdbpy_initialize_blocks (void);
- void gdbpy_initialize_functions (void);
- void gdbpy_initialize_pspace (void);
- void gdbpy_initialize_objfile (void);
-@@ -171,6 +180,12 @@ struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
- extern struct gdbarch *python_gdbarch;
- extern const struct language_defn *python_language;
-+char *gdbpy_parse_command_name (char *text,
-+                              struct cmd_list_element ***base_list,
-+                              struct cmd_list_element **start_list);
-+
-+PyObject *gdbpy_parameter_value (enum var_types, void *);
-+
- /* Use this after a TRY_EXCEPT to throw the appropriate Python
-    exception.  */
- #define GDB_PY_HANDLE_EXCEPTION(Exception)                            \
-@@ -221,13 +236,14 @@ int gdbpy_is_value_object (PyObject *obj);
- PyObject *apply_varobj_pretty_printer (PyObject *print_obj,
-                                      struct value **replacement);
- PyObject *gdbpy_get_varobj_pretty_printer (struct value *value);
-+PyObject *gdbpy_instantiate_printer (PyObject *cons, PyObject *value);
- char *gdbpy_get_display_hint (PyObject *printer);
- PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args);
--extern PyObject *gdbpy_doc_cst;
- extern PyObject *gdbpy_children_cst;
- extern PyObject *gdbpy_to_string_cst;
- extern PyObject *gdbpy_display_hint_cst;
-+extern PyObject *gdbpy_doc_cst;
- extern PyObject *gdbpy_enabled_cst;
- extern PyObject *gdbpy_gdberror_exc;
-diff --git a/gdb/python/python.c b/gdb/python/python.c
-index 7346fba..34708c4 100644
---- a/gdb/python/python.c
-+++ b/gdb/python/python.c
-@@ -28,6 +28,7 @@
- #include "value.h"
- #include "language.h"
- #include "exceptions.h"
-+#include "event-loop.h"
- #include <ctype.h>
-@@ -42,10 +43,17 @@ static int gdbpy_should_print_stack = 1;
- #include "cli/cli-decode.h"
- #include "charset.h"
- #include "top.h"
-+#include "solib.h"
- #include "python-internal.h"
-+#include "linespec.h"
-+#include "symtab.h"
-+#include "source.h"
- #include "version.h"
-+#include "inferior.h"
-+#include "gdbthread.h"
- #include "target.h"
- #include "gdbthread.h"
-+#include "event-top.h"
- static PyMethodDef GdbMethods[];
-@@ -374,6 +382,105 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
-   Py_RETURN_NONE;
- }
-+/* Implementation of gdb.solib_address (Long) -> String.
-+   Returns the name of the shared library holding a given address, or None.  */
-+
-+static PyObject *
-+gdbpy_solib_address (PyObject *self, PyObject *args)
-+{
-+  unsigned long long pc;
-+  char *soname;
-+  PyObject *str_obj;
-+
-+  if (!PyArg_ParseTuple (args, "K", &pc))
-+    return NULL;
-+
-+  soname = solib_name_from_address (current_program_space, pc);
-+  if (soname)
-+    str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
-+  else
-+    {
-+      str_obj = Py_None;
-+      Py_INCREF (Py_None);
-+    }
-+
-+  return str_obj;
-+}
-+
-+/* A Python function which is a wrapper for decode_line_1.  */
-+
-+static PyObject *
-+gdbpy_decode_line (PyObject *self, PyObject *args)
-+{
-+  struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc.  */
-+  struct symtab_and_line sal;
-+  char *arg = NULL;
-+  int free_sals = 0, i;
-+  PyObject *result = NULL;
-+  volatile struct gdb_exception except;
-+
-+  if (! PyArg_ParseTuple (args, "|s", &arg))
-+    return NULL;
-+
-+  TRY_CATCH (except, RETURN_MASK_ALL)
-+    {
-+      if (arg)
-+      {
-+        char *copy;
-+
-+        arg = strdup (arg);
-+        copy = arg;
-+
-+        sals = decode_line_1 (&copy, 0, 0, 0, 0, 0);
-+        free_sals = 1;
-+      }
-+      else
-+      {
-+        set_default_source_symtab_and_line ();
-+        sal = get_current_source_symtab_and_line ();
-+        sals.sals = &sal;
-+        sals.nelts = 1;
-+      }
-+    }
-+  if (arg)
-+    xfree (arg);
-+
-+  if (except.reason < 0)
-+    {
-+      if (free_sals)
-+      xfree (sals.sals);
-+      /* We know this will always throw.  */
-+      GDB_PY_HANDLE_EXCEPTION (except);
-+    }
-+
-+  if (sals.nelts)
-+    {
-+      result = PyTuple_New (sals.nelts);
-+      for (i = 0; i < sals.nelts; ++i)
-+      {
-+        PyObject *obj;
-+        char *str;
-+
-+        obj = symtab_and_line_to_sal_object (sals.sals[i]);
-+        if (! obj)
-+          {
-+            Py_DECREF (result);
-+            result = NULL;
-+            break;
-+          }
-+
-+        PyTuple_SetItem (result, i, obj);
-+      }
-+    }
-+
-+  if (free_sals)
-+    xfree (sals.sals);
-+
-+  if (result)
-+    return result;
-+  Py_RETURN_NONE;
-+}
-+
- /* Parse a string and evaluate it as an expression.  */
- static PyObject *
- gdbpy_parse_and_eval (PyObject *self, PyObject *args)
-@@ -414,6 +521,114 @@ source_python_script (FILE *stream, const char *file)
\f
-+/* Posting and handling events.  */
-+
-+/* A single event.  */
-+struct gdbpy_event
-+{
-+  /* The Python event.  This is just a callable object.  */
-+  PyObject *event;
-+  /* The next event.  */
-+  struct gdbpy_event *next;
-+};
-+
-+/* All pending events.  */
-+static struct gdbpy_event *gdbpy_event_list;
-+/* The final link of the event list.  */
-+static struct gdbpy_event **gdbpy_event_list_end;
-+
-+/* We use a file handler, and not an async handler, so that we can
-+   wake up the main thread even when it is blocked in poll().  */
-+static int gdbpy_event_fds[2];
-+
-+/* The file handler callback.  This reads from the internal pipe, and
-+   then processes the Python event queue.  This will always be run in
-+   the main gdb thread.  */
-+static void
-+gdbpy_run_events (int err, gdb_client_data ignore)
-+{
-+  struct cleanup *cleanup;
-+  char buffer[100];
-+  int r;
-+
-+  cleanup = ensure_python_env (get_current_arch (), current_language);
-+
-+  /* Just read whatever is available on the fd.  It is relatively
-+     harmless if there are any bytes left over.  */
-+  r = read (gdbpy_event_fds[0], buffer, sizeof (buffer));
-+
-+  while (gdbpy_event_list)
-+    {
-+      /* Dispatching the event might push a new element onto the event
-+       loop, so we update here "atomically enough".  */
-+      struct gdbpy_event *item = gdbpy_event_list;
-+      gdbpy_event_list = gdbpy_event_list->next;
-+      if (gdbpy_event_list == NULL)
-+      gdbpy_event_list_end = &gdbpy_event_list;
-+
-+      /* Ignore errors.  */
-+      PyObject_CallObject (item->event, NULL);
-+
-+      Py_DECREF (item->event);
-+      xfree (item);
-+    }
-+
-+  do_cleanups (cleanup);
-+}
-+
-+/* Submit an event to the gdb thread.  */
-+static PyObject *
-+gdbpy_post_event (PyObject *self, PyObject *args)
-+{
-+  struct gdbpy_event *event;
-+  PyObject *func;
-+  int wakeup;
-+
-+  if (!PyArg_ParseTuple (args, "O", &func))
-+    return NULL;
-+
-+  if (!PyCallable_Check (func))
-+    {
-+      PyErr_SetString (PyExc_RuntimeError, "Posted event is not callable");
-+      return NULL;
-+    }
-+
-+  Py_INCREF (func);
-+
-+  /* From here until the end of the function, we have the GIL, so we
-+     can operate on our global data structures without worrying.  */
-+  wakeup = gdbpy_event_list == NULL;
-+
-+  event = XNEW (struct gdbpy_event);
-+  event->event = func;
-+  event->next = NULL;
-+  *gdbpy_event_list_end = event;
-+  gdbpy_event_list_end = &event->next;
-+
-+  /* Wake up gdb when needed.  */
-+  if (wakeup)
-+    {
-+      char c = 'q';           /* Anything. */
-+      if (write (gdbpy_event_fds[1], &c, 1) != 1)
-+        return PyErr_SetFromErrno (PyExc_IOError);
-+    }
-+
-+  Py_RETURN_NONE;
-+}
-+
-+/* Initialize the Python event handler.  */
-+static void
-+gdbpy_initialize_events (void)
-+{
-+  if (!pipe (gdbpy_event_fds))
-+    {
-+      gdbpy_event_list_end = &gdbpy_event_list;
-+      add_file_handler (gdbpy_event_fds[0], gdbpy_run_events, NULL);
-+    }
-+}
-+
-+\f
-+
- /* Printing.  */
- /* A python function to write a single string using gdb's filtered
-@@ -459,6 +674,53 @@ gdbpy_print_stack (void)
- /* Return the current Progspace.
-    There always is one.  */
-+/* True if 'gdb -P' was used, false otherwise.  */
-+static int running_python_script;
-+
-+/* True if we are currently in a call to 'gdb.cli', false otherwise.  */
-+static int in_cli;
-+
-+/* Enter the command loop.  */
-+
-+static PyObject *
-+gdbpy_cli (PyObject *unused1, PyObject *unused2)
-+{
-+  if (! running_python_script || in_cli)
-+    return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
-+
-+  in_cli = 1;
-+  cli_command_loop ();
-+  in_cli = 0;
-+
-+  Py_RETURN_NONE;
-+}
-+
-+/* Set up the Python argument vector and evaluate a script.  This is
-+   used to implement 'gdb -P'.  */
-+
-+void
-+run_python_script (int argc, char **argv)
-+{
-+  FILE *input;
-+
-+  /* We never free this, since we plan to exit at the end.  */
-+  ensure_python_env (get_current_arch (), current_language);
-+
-+  running_python_script = 1;
-+  PySys_SetArgv (argc - 1, argv + 1);
-+  input = fopen (argv[0], "r");
-+  if (! input)
-+    {
-+      fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
-+      exit (1);
-+    }
-+  PyRun_SimpleFile (input, argv[0]);
-+  fclose (input);
-+  exit (0);
-+}
-+
-+\f
-+
- static PyObject *
- gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
-@@ -720,6 +982,7 @@ Enables or disables printing of Python stack traces."),
-   gdbpy_initialize_lazy_string ();
-   gdbpy_initialize_thread ();
-   gdbpy_initialize_inferior ();
-+  gdbpy_initialize_events ();
-   PyRun_SimpleString ("import gdb");
-   PyRun_SimpleString ("gdb.pretty_printers = []");
-@@ -787,6 +1050,8 @@ static PyMethodDef GdbMethods[] =
-     "Get a value from history" },
-   { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
-     "Execute a gdb command" },
-+  { "cli", gdbpy_cli, METH_NOARGS,
-+    "Enter the gdb CLI" },
-   { "parameter", gdbpy_parameter, METH_VARARGS,
-     "Return a gdb parameter's value" },
++      /* FIXME: should handle inferior I/O intelligently here.
++       E.g., should be possible to run gdb in pipeline and have
++       Python (and gdb) output go to stderr or file; and if a
++       prompt is needed, open the tty.  */
++      quiet = 1;
++      /* FIXME: should read .gdbinit if, and only if, a prompt is
++       requested by the script.  Though... maybe this is not
++       ideal?  */
++      /* FIXME: likewise, reading in history.  */
++      inhibit_gdbinit = 1;
++    }
++  else if (set_args)
+     {
+       /* The remaining options are the command-line options for the
+        inferior.  The first one is the sym/exec file, and the rest
+@@ -979,7 +1013,8 @@ captured_main (void *data)
  
-@@ -825,11 +1090,21 @@ a boolean indicating if name is a field of the current implied argument\n\
- `this' (when the current language is object-oriented)." },
-   { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
-     "Return the block containing the given pc value, or None." },
-+  { "solib_address", gdbpy_solib_address, METH_VARARGS,
-+    "solib_address (Long) -> String.\n\
-+Return the name of the shared library holding a given address, or None." },
-+  { "decode_line", gdbpy_decode_line, METH_VARARGS,
-+    "Decode a string argument the way that 'break' or 'edit' does.\n\
-+Return a tuple holding the file name (or None) and line number (or None).\n\
-+Note: may later change to return an object." },
-   { "parse_and_eval", gdbpy_parse_and_eval, METH_VARARGS,
-     "parse_and_eval (String) -> Value.\n\
- Parse String as an expression, evaluate it, and return the result as a Value."
-   },
-+  { "post_event", gdbpy_post_event, METH_VARARGS,
-+    "Post an event into gdb's event loop." },
-+
-   { "target_charset", gdbpy_target_charset, METH_NOARGS,
-     "target_charset () -> string.\n\
- Return the name of the current target charset." },
-diff --git a/gdb/python/python.h b/gdb/python/python.h
-index affd4a4..5407878 100644
---- a/gdb/python/python.h
-+++ b/gdb/python/python.h
-@@ -28,6 +28,8 @@ void eval_python_from_control_command (struct command_line *);
+   /* Read in the old history after all the command files have been
+      read.  */
+-  init_history ();
++  if (!python_script)
++    init_history ();
  
- void source_python_script (FILE *stream, const char *file);
+   if (batch_flag)
+     {
+@@ -990,13 +1025,25 @@ captured_main (void *data)
+   /* Show time and/or space usage.  */
+   do_cleanups (pre_stat_chain);
  
-+void run_python_script (int argc, char **argv);
-+
- int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
-                             int embedded_offset, CORE_ADDR address,
-                             struct ui_file *stream, int recurse,
-diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
-index 1f135d4..489838d 100644
---- a/gdb/solib-svr4.c
-+++ b/gdb/solib-svr4.c
-@@ -1278,7 +1278,8 @@ svr4_in_dynsym_resolve_code (CORE_ADDR pc)
-          && pc < info->interp_text_sect_high)
-         || (pc >= info->interp_plt_sect_low
-             && pc < info->interp_plt_sect_high)
--        || in_plt_section (pc, NULL));
-+        || in_plt_section (pc, NULL)
-+        || in_gnu_ifunc_stub (pc));
+-  /* NOTE: cagney/1999-11-07: There is probably no reason for not
+-     moving this loop and the code found in captured_command_loop()
+-     into the command_loop() proper.  The main thing holding back that
+-     change - SET_TOP_LEVEL() - has been eliminated.  */
+-  while (1)
++#if HAVE_PYTHON
++  if (python_script)
+     {
+-      catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
++      extern int pagination_enabled;
++      pagination_enabled = 0;
++      run_python_script (argc - optind, &argv[optind]);
++      return 1;
++    }
++  else
++#endif
++    {
++      /* NOTE: cagney/1999-11-07: There is probably no reason for not
++       moving this loop and the code found in captured_command_loop()
++       into the command_loop() proper.  The main thing holding back that
++       change - SET_TOP_LEVEL() - has been eliminated. */
++      while (1)
++      {
++        catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
++      }
+     }
+   /* No exit -- exit is through quit_command.  */
  }
+@@ -1028,7 +1075,12 @@ print_gdb_help (struct ui_file *stream)
+   fputs_unfiltered (_("\
+ This is the GNU debugger.  Usage:\n\n\
+     gdb [options] [executable-file [core-file or process-id]]\n\
+-    gdb [options] --args executable-file [inferior-arguments ...]\n\n\
++    gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
++#if HAVE_PYTHON
++  fputs_unfiltered (_("\
++    gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
++#endif
++  fputs_unfiltered (_("\n\
+ Options:\n\n\
+ "), stream);
+   fputs_unfiltered (_("\
+@@ -1068,7 +1120,13 @@ Options:\n\n\
+   --nw                     Do not use a window interface.\n\
+   --nx               Do not read "), stream);
+   fputs_unfiltered (gdbinit, stream);
+-  fputs_unfiltered (_(" file.\n\
++  fputs_unfiltered (_(" file.\n"), stream);
++#if HAVE_PYTHON
++  fputs_unfiltered (_("\
++  --python, -P       Following argument is Python script file; remaining\n\
++                     arguments are passed to script.\n"), stream);
++#endif
++  fputs_unfiltered (_("\
+   --quiet            Do not print version number on startup.\n\
+   --readnow          Fully read symbol files on first access.\n\
+ "), stream);
+diff --git a/gdb/objfiles.c b/gdb/objfiles.c
+index f5e5c75..411618f 100644
+--- a/gdb/objfiles.c
++++ b/gdb/objfiles.c
+@@ -53,6 +53,7 @@
+ #include "complaints.h"
+ #include "psymtab.h"
+ #include "solist.h"
++#include "gdb_bfd.h"
  
- /* Given an executable's ABFD and target, compute the entry-point
-diff --git a/gdb/symfile.c b/gdb/symfile.c
-index 42f7ae3..371db0d 100644
---- a/gdb/symfile.c
-+++ b/gdb/symfile.c
-@@ -1059,6 +1059,9 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
-   const char *name = bfd_get_filename (abfd);
-   const int from_tty = add_flags & SYMFILE_VERBOSE;
-+  if (readnow_symbol_files)
-+    flags |= OBJF_READNOW;
-+
-   my_cleanups = make_cleanup_bfd_close (abfd);
+ /* Prototypes for local functions */
  
-   /* Give user a chance to burp if we'd be
-@@ -1095,7 +1098,7 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
-      the gdb startup command line or on a per symbol file basis.  Expand
-      all partial symbol tables for this objfile if so. */
+@@ -195,7 +196,8 @@ allocate_objfile (bfd *abfd, int flags)
+      that any data that is reference is saved in the per-objfile data
+      region.  */
  
--  if ((flags & OBJF_READNOW) || readnow_symbol_files)
-+  if ((flags & OBJF_READNOW))
+-  objfile->obfd = gdb_bfd_ref (abfd);
++  objfile->obfd = abfd;
++  gdb_bfd_ref (abfd);
+   if (abfd != NULL)
      {
-       if (from_tty || info_verbose)
-       {
-@@ -1533,7 +1536,7 @@ symbol_file_command (char *args, int from_tty)
- void
- set_initial_language (void)
- {
--  char *filename;
-+  const char *filename;
-   enum language lang = language_unknown;
-   filename = find_main_filename ();
-@@ -2660,7 +2663,7 @@ init_filename_language_table (void)
+       /* Look up the gdbarch associated with the BFD.  */
+@@ -1456,75 +1458,6 @@ objfiles_changed (void)
+   get_objfile_pspace_data (current_program_space)->objfiles_changed_p = 1;
  }
  
- enum language
--deduce_language_from_filename (char *filename)
-+deduce_language_from_filename (const char *filename)
- {
-   int i;
-   char *cp;
-diff --git a/gdb/symfile.h b/gdb/symfile.h
-index d53c465..5815354 100644
---- a/gdb/symfile.h
-+++ b/gdb/symfile.h
-@@ -171,6 +171,15 @@ struct quick_symbol_functions
-                                  int kind, const char *name,
-                                  domain_enum domain);
-+  /* This is called to expand symbol tables before looking up a
-+     symbol.  A backend can choose to implement this and then have its
-+     `lookup_symbol' hook always return NULL, or the reverse.  (It
-+     doesn't make sense to implement both.)  The arguments are as for
-+     `lookup_symbol'.  */
-+  void (*pre_expand_symtabs_matching) (struct objfile *objfile,
-+                                     int kind, const char *name,
-+                                     domain_enum domain);
-+
-   /* Print statistics about any indices loaded for OBJFILE.  The
-      statistics should be printed to gdb_stdout.  This is used for
-      "maint print statistics".  */
-@@ -201,7 +210,7 @@ struct quick_symbol_functions
-   /* Return the file name of the file holding the symbol in OBJFILE
-      named NAME.  If no such symbol exists in OBJFILE, return NULL.  */
--  char *(*find_symbol_file) (struct objfile *objfile, const char *name);
-+  const char *(*find_symbol_file) (struct objfile *objfile, const char *name);
-   /* This method is specific to Ada.  It walks the partial symbol
-      tables of OBJFILE looking for a name match.  WILD_MATCH and
-@@ -566,6 +575,7 @@ extern struct cleanup *increment_reading_symtab (void);
- extern int dwarf2_has_info (struct objfile *);
-+extern int dwarf2_initialize_objfile (struct objfile *);
- extern void dwarf2_build_psymtabs (struct objfile *);
- extern void dwarf2_build_frame_info (struct objfile *);
-diff --git a/gdb/symmisc.c b/gdb/symmisc.c
-index 62e6b97..00dc613 100644
---- a/gdb/symmisc.c
-+++ b/gdb/symmisc.c
-@@ -262,6 +262,9 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
-       case mst_text:
-         ms_type = 'T';
-         break;
-+      case mst_text_gnu_ifunc:
-+        ms_type = 'i';
-+        break;
-       case mst_solib_trampoline:
-         ms_type = 'S';
-         break;
-diff --git a/gdb/symtab.c b/gdb/symtab.c
-index 2c4c9e4..28f0450 100644
---- a/gdb/symtab.c
-+++ b/gdb/symtab.c
-@@ -1295,16 +1295,25 @@ lookup_symbol_aux_symtabs (int block_index, const char *name,
-   const struct block *block;
-   struct symtab *s;
--  ALL_PRIMARY_SYMTABS (objfile, s)
-+  ALL_OBJFILES (objfile)
-   {
--    bv = BLOCKVECTOR (s);
--    block = BLOCKVECTOR_BLOCK (bv, block_index);
--    sym = lookup_block_symbol (block, name, domain);
--    if (sym)
--      {
--      block_found = block;
--      return fixup_symbol_section (sym, objfile);
--      }
-+    if (objfile->sf)
-+      objfile->sf->qf->pre_expand_symtabs_matching (objfile,
-+                                                  block_index,
-+                                                  name, domain);
-+
-+    ALL_OBJFILE_SYMTABS (objfile, s)
-+      if (s->primary)
-+      {
-+        bv = BLOCKVECTOR (s);
-+        block = BLOCKVECTOR_BLOCK (bv, block_index);
-+        sym = lookup_block_symbol (block, name, domain);
-+        if (sym)
-+          {
-+            block_found = block;
-+            return fixup_symbol_section (sym, objfile);
-+          }
-+      }
-   }
-   return NULL;
-@@ -1547,15 +1556,24 @@ basic_lookup_transparent_type (const char *name)
-      of the desired name as a global, then do psymtab-to-symtab
-      conversion on the fly and return the found symbol.  */
--  ALL_PRIMARY_SYMTABS (objfile, s)
-+  ALL_OBJFILES (objfile)
-   {
--    bv = BLOCKVECTOR (s);
--    block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
--    sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
--    if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
--      {
--      return SYMBOL_TYPE (sym);
--      }
-+    if (objfile->sf)
-+      objfile->sf->qf->pre_expand_symtabs_matching (objfile,
-+                                                  GLOBAL_BLOCK,
-+                                                  name, STRUCT_DOMAIN);
-+
-+    ALL_OBJFILE_SYMTABS (objfile, s)
-+      if (s->primary)
-+      {
-+        bv = BLOCKVECTOR (s);
-+        block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
-+        sym = lookup_block_symbol (block, name, STRUCT_DOMAIN);
-+        if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
-+          {
-+            return SYMBOL_TYPE (sym);
-+          }
-+      }
-   }
-   ALL_OBJFILES (objfile)
-@@ -1599,14 +1617,16 @@ basic_lookup_transparent_type (const char *name)
- /* FIXME:  What about languages without main() or specially linked
-    executables that have no main() ? */
--char *
-+const char *
- find_main_filename (void)
- {
-   struct objfile *objfile;
--  char *result, *name = main_name ();
-+  char *name = main_name ();
-   ALL_OBJFILES (objfile)
-   {
-+    const char *result;
-+
-     if (!objfile->sf)
-       continue;
-     result = objfile->sf->qf->find_symbol_file (objfile, name);
-@@ -2914,7 +2934,7 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[],
-   static enum minimal_symbol_type types3[]
-     = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
-   static enum minimal_symbol_type types4[]
--    = {mst_file_bss, mst_text, mst_abs, mst_unknown};
-+    = {mst_file_bss, mst_text_gnu_ifunc, mst_abs, mst_unknown};
-   enum minimal_symbol_type ourtype;
-   enum minimal_symbol_type ourtype2;
-   enum minimal_symbol_type ourtype3;
-diff --git a/gdb/symtab.h b/gdb/symtab.h
-index bedc10a..dc284e4 100644
---- a/gdb/symtab.h
-+++ b/gdb/symtab.h
-@@ -277,6 +277,9 @@ enum minimal_symbol_type
- {
-   mst_unknown = 0,            /* Unknown type, the default */
-   mst_text,                   /* Generally executable instructions */
-+  mst_text_gnu_ifunc,         /* Executable code returning address
-+                                 of executable code */
-+  mst_slot_got_plt,
-   mst_data,                   /* Generally initialized data */
-   mst_bss,                    /* Generally uninitialized data */
-   mst_abs,                    /* Generally absolute (nonrelocatable) */
-@@ -917,11 +920,25 @@ extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
- /* lookup function from address, return name, start addr and end addr */
--extern int find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *,
--                                   CORE_ADDR *);
-+extern enum find_pc_partial_function_type
-+  {
-+    FIND_PC_PARTIAL_FUNCTION_NOT_FOUND = 0,
-+    FIND_PC_PARTIAL_FUNCTION_NORMAL,
-+    FIND_PC_PARTIAL_FUNCTION_GNU_IFUNC
-+  } find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *, CORE_ADDR *);
+-/* Close ABFD, and warn if that fails.  */
+-
+-int
+-gdb_bfd_close_or_warn (struct bfd *abfd)
+-{
+-  int ret;
+-  char *name = bfd_get_filename (abfd);
+-
+-  ret = bfd_close (abfd);
+-
+-  if (!ret)
+-    warning (_("cannot close \"%s\": %s"),
+-           name, bfd_errmsg (bfd_get_error ()));
+-
+-  return ret;
+-}
+-
+-/* Add reference to ABFD.  Returns ABFD.  */
+-struct bfd *
+-gdb_bfd_ref (struct bfd *abfd)
+-{
+-  int *p_refcount;
+-
+-  if (abfd == NULL)
+-    return NULL;
+-
+-  p_refcount = bfd_usrdata (abfd);
+-
+-  if (p_refcount != NULL)
+-    {
+-      *p_refcount += 1;
+-      return abfd;
+-    }
+-
+-  p_refcount = xmalloc (sizeof (*p_refcount));
+-  *p_refcount = 1;
+-  bfd_usrdata (abfd) = p_refcount;
+-
+-  return abfd;
+-}
+-
+-/* Unreference and possibly close ABFD.  */
+-void
+-gdb_bfd_unref (struct bfd *abfd)
+-{
+-  int *p_refcount;
+-  char *name;
+-
+-  if (abfd == NULL)
+-    return;
+-
+-  p_refcount = bfd_usrdata (abfd);
+-
+-  /* Valid range for p_refcount: a pointer to int counter, which has a
+-     value of 1 (single owner) or 2 (shared).  */
+-  gdb_assert (*p_refcount == 1 || *p_refcount == 2);
+-
+-  *p_refcount -= 1;
+-  if (*p_refcount > 0)
+-    return;
+-
+-  xfree (p_refcount);
+-  bfd_usrdata (abfd) = NULL;  /* Paranoia.  */
+-
+-  name = bfd_get_filename (abfd);
+-  gdb_bfd_close_or_warn (abfd);
+-  xfree (name);
+-}
+-
+ /* The default implementation for the "iterate_over_objfiles_in_search_order"
+    gdbarch method.  It is equivalent to use the ALL_OBJFILES macro,
+    searching the objfiles in the order they are stored internally,
+diff --git a/gdb/objfiles.h b/gdb/objfiles.h
+index 01c3aea..0df5798 100644
+--- a/gdb/objfiles.h
++++ b/gdb/objfiles.h
+@@ -522,10 +522,6 @@ extern void set_objfile_data (struct objfile *objfile,
+ extern void *objfile_data (struct objfile *objfile,
+                          const struct objfile_data *data);
+-extern struct bfd *gdb_bfd_ref (struct bfd *abfd);
+-extern void gdb_bfd_unref (struct bfd *abfd);
+-extern int gdb_bfd_close_or_warn (struct bfd *abfd);
+-
+ extern void default_iterate_over_objfiles_in_search_order
+   (struct gdbarch *gdbarch,
+    iterate_over_objfiles_in_search_order_cb_ftype *cb,
+diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
+index b8434ed..98a076d 100644
+--- a/gdb/p-valprint.c
++++ b/gdb/p-valprint.c
+@@ -39,6 +39,7 @@
+ #include "cp-abi.h"
+ #include "cp-support.h"
+ #include "exceptions.h"
++#include "dwarf2loc.h"
\f
  
- extern void clear_pc_function_cache (void);
+ /* Decorations for Pascal.  */
+@@ -74,8 +75,31 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
+   struct type *char_type;
+   CORE_ADDR addr;
+   int want_space = 0;
++  struct cleanup *back_to;
++  struct type *saved_type = type;
++  CORE_ADDR saved_address = address;
++  
++  back_to = make_cleanup (null_cleanup, 0);
++  address += embedded_offset;
++  type = object_address_get_data (type, &address);
++  if (type == NULL)
++    {
++      fputs_filtered (object_address_data_not_valid (saved_type), stream);
++      gdb_flush (stream);
++      do_cleanups (back_to);
++      return;
++    }
++  if (address != saved_address + embedded_offset)
++    {
++      size_t length = TYPE_LENGTH (type);
  
-+extern int resolve_gnu_ifunc (const char *function_name,
-+                            CORE_ADDR *function_addressp);
-+
-+extern struct minimal_symbol *resolve_gnu_ifunc_by_cache
-+  (const char *function_name);
-+
-+extern void gnu_ifunc_record_cache (struct gdbarch *gdbarch,
-+                                  const char *function_name,
-+                                  CORE_ADDR function_address);
-+
- /* lookup partial symbol table by address and section */
+-  CHECK_TYPEDEF (type);
++      valaddr = xmalloc (length);
++      make_cleanup (xfree, (gdb_byte *) valaddr);
++      read_memory (address, (gdb_byte *) valaddr, length);
++      embedded_offset = 0;
++    }
++  else
++    address -= embedded_offset;
+   switch (TYPE_CODE (type))
+     {
+     case TYPE_CODE_ARRAY:
+@@ -131,8 +155,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
+               {
+                 i = 0;
+               }
+-            val_print_array_elements (type, valaddr, embedded_offset,
+-                                      address, stream, recurse,
++            val_print_array_elements (saved_type, valaddr, embedded_offset,
++                                      saved_address, stream, recurse,
+                                       original_value, options, i);
+             fprintf_filtered (stream, "}");
+           }
+@@ -170,6 +194,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
+       {
+         /* Try to print what function it points to.  */
+         print_address_demangle (options, gdbarch, addr, stream, demangle);
++        do_cleanups (back_to);
+         return;
+       }
  
- extern struct symtab *find_pc_sect_symtab_via_partial (CORE_ADDR,
-@@ -996,6 +1013,8 @@ extern struct minimal_symbol *lookup_minimal_symbol_by_pc_name
+@@ -271,6 +296,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
+           }
+       }
  
- extern struct minimal_symbol *lookup_minimal_symbol_by_pc (CORE_ADDR);
++      do_cleanups (back_to);
+       return;
  
-+extern int in_gnu_ifunc_stub (CORE_ADDR pc);
-+
- extern struct minimal_symbol *
-     lookup_minimal_symbol_and_objfile (const char *,
-                                      struct objfile **);
-@@ -1137,7 +1156,7 @@ extern char **make_source_files_completion_list (char *, char *);
+     case TYPE_CODE_REF:
+@@ -421,6 +447,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
+            TYPE_CODE (type));
+     }
+   gdb_flush (stream);
++  do_cleanups (back_to);
+ }
\f
+ void
+diff --git a/gdb/parse.c b/gdb/parse.c
+index 529c517..6326a01 100644
+--- a/gdb/parse.c
++++ b/gdb/parse.c
+@@ -1708,6 +1708,7 @@ parser_fprintf (FILE *x, const char *y, ...)
  
- int matching_obj_sections (struct obj_section *, struct obj_section *);
+ int
+ operator_check_standard (struct expression *exp, int pos,
++                       int (*type_func) (struct type *type, void *data),
+                        int (*objfile_func) (struct objfile *objfile,
+                                             void *data),
+                        void *data)
+@@ -1749,7 +1750,7 @@ operator_check_standard (struct expression *exp, int pos,
+           struct type *type = elts[pos + 2 + arg].type;
+           struct objfile *objfile = TYPE_OBJFILE (type);
  
--extern char *find_main_filename (void);
-+extern const char *find_main_filename (void);
+-          if (objfile && (*objfile_func) (objfile, data))
++          if (objfile && objfile_func && (*objfile_func) (objfile, data))
+             return 1;
+         }
+       }
+@@ -1767,7 +1768,8 @@ operator_check_standard (struct expression *exp, int pos,
  
- extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
+       /* Check objfile where the variable itself is placed.
+          SYMBOL_OBJ_SECTION (symbol) may be NULL.  */
+-      if ((*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
++      if (objfile_func
++          && (*objfile_func) (SYMBOL_SYMTAB (symbol)->objfile, data))
+         return 1;
  
-@@ -1150,7 +1169,7 @@ extern void skip_prologue_sal (struct symtab_and_line *);
+       /* Check objfile where is placed the code touching the variable.  */
+@@ -1780,24 +1782,27 @@ operator_check_standard (struct expression *exp, int pos,
  
- extern void clear_symtab_users (void);
+   /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
  
--extern enum language deduce_language_from_filename (char *);
-+extern enum language deduce_language_from_filename (const char *);
+-  if (type && TYPE_OBJFILE (type)
++  if (type && type_func && (*type_func) (type, data))
++    return 1;
++  if (type && TYPE_OBJFILE (type) && objfile_func
+       && (*objfile_func) (TYPE_OBJFILE (type), data))
+     return 1;
+-  if (objfile && (*objfile_func) (objfile, data))
++  if (objfile && objfile_func && (*objfile_func) (objfile, data))
+     return 1;
  
- /* symtab.c */
+   return 0;
+ }
  
-diff --git a/gdb/target.c b/gdb/target.c
-index 4cabcbd..34b3b60 100644
---- a/gdb/target.c
-+++ b/gdb/target.c
-@@ -123,6 +123,8 @@ static int debug_to_insert_watchpoint (CORE_ADDR, int, int,
- static int debug_to_remove_watchpoint (CORE_ADDR, int, int,
-                                      struct expression *);
+-/* Call OBJFILE_FUNC for any TYPE and OBJFILE found being referenced by EXP.
+-   The functions are never called with NULL OBJFILE.  Functions get passed an
+-   arbitrary caller supplied DATA pointer.  If any of the functions returns
+-   non-zero value then (any other) non-zero value is immediately returned to
+-   the caller.  Otherwise zero is returned after iterating through whole EXP.
+-   */
++/* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being
++   referenced by EXP.  The functions are never called with NULL TYPE or NULL
++   OBJFILE.  Functions get passed an arbitrary caller supplied DATA pointer.
++   If any of the functions returns non-zero value then (any other) non-zero
++   value is immediately returned to the caller.  Otherwise zero is returned
++   after iterating through whole EXP.  */
  
-+static int debug_to_detach_watchpoints (void);
-+
- static int debug_to_stopped_by_watchpoint (void);
+ static int
+ exp_iterate (struct expression *exp,
++           int (*type_func) (struct type *type, void *data),
+            int (*objfile_func) (struct objfile *objfile, void *data),
+            void *data)
+ {
+@@ -1812,7 +1817,9 @@ exp_iterate (struct expression *exp,
  
- static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
-@@ -606,6 +608,7 @@ update_current_target (void)
-       INHERIT (to_remove_hw_breakpoint, t);
-       INHERIT (to_insert_watchpoint, t);
-       INHERIT (to_remove_watchpoint, t);
-+      INHERIT (to_detach_watchpoints, t);
-       INHERIT (to_stopped_data_address, t);
-       INHERIT (to_have_steppable_watchpoint, t);
-       INHERIT (to_have_continuable_watchpoint, t);
-@@ -739,6 +742,9 @@ update_current_target (void)
-   de_fault (to_remove_watchpoint,
-           (int (*) (CORE_ADDR, int, int, struct expression *))
-           return_minus_one);
-+  de_fault (to_detach_watchpoints,
-+          (int (*) (void))
-+          return_zero);
-   de_fault (to_stopped_by_watchpoint,
-           (int (*) (void))
-           return_zero);
-@@ -3440,6 +3446,19 @@ debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type,
-   return retval;
- }
+       pos = endpos - oplen;
+       if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
+-                                                         objfile_func, data))
++                                                         type_func,
++                                                         objfile_func,
++                                                         data))
+       return 1;
  
-+static int
-+debug_to_detach_watchpoints (void)
-+{
-+  int retval;
-+
-+  retval = debug_target.to_detach_watchpoints ();
-+
-+  fprintf_unfiltered (gdb_stdlog,
-+                    "target_detach_watchpoints () = %ld\n",
-+                    (unsigned long) retval);
-+  return retval;
-+}
-+
- static void
- debug_to_terminal_init (void)
- {
-@@ -3687,6 +3706,7 @@ setup_target_debug (void)
-   current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
-   current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
-   current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
-+  current_target.to_detach_watchpoints = debug_to_detach_watchpoints;
-   current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
-   current_target.to_stopped_data_address = debug_to_stopped_data_address;
-   current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
-diff --git a/gdb/target.h b/gdb/target.h
-index 3c8c017..608a742 100644
---- a/gdb/target.h
-+++ b/gdb/target.h
-@@ -433,6 +433,7 @@ struct target_ops
-        provided with the corresponding target_* macros.  */
-     int (*to_remove_watchpoint) (CORE_ADDR, int, int, struct expression *);
-     int (*to_insert_watchpoint) (CORE_ADDR, int, int, struct expression *);
-+    int (*to_detach_watchpoints) (void);
-     int (*to_stopped_by_watchpoint) (void);
-     int to_have_steppable_watchpoint;
-@@ -1316,6 +1317,15 @@ extern char *normal_pid_to_str (ptid_t ptid);
- #define       target_remove_watchpoint(addr, len, type, cond) \
-      (*current_target.to_remove_watchpoint) (addr, len, type, cond)
-+/* Clear all debug registers without affecting any register caches.  Function
-+   acts on INFERIOR_PTID which should be the forked-off process, either the
-+   non-threaded child one or the threaded parent one, depending on `set
-+   follow-fork-mode'.  Both watchpoints and hardware breakpoints get removed.
-+   Return 0 on success, -1 on failure.  */
-+
-+#define       target_detach_watchpoints()     \
-+     (*current_target.to_detach_watchpoints) ()
-+
- #define target_insert_hw_breakpoint(gdbarch, bp_tgt) \
-      (*current_target.to_insert_hw_breakpoint) (gdbarch, bp_tgt)
-@@ -1369,6 +1379,18 @@ extern int target_search_memory (CORE_ADDR start_addr,
-                                  ULONGEST pattern_len,
-                                  CORE_ADDR *found_addrp);
-+/* Utility functions which can be used by search_memory implementations.  */
-+
-+void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
-+                            ULONGEST *pattern_buf_size);
-+
-+void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
-+                            ULONGEST *pattern_buf_size, int val_bytes);
-+
-+int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
-+                 const char *pattern_buf, ULONGEST pattern_len,
-+                 CORE_ADDR *found_addr);
-+
- /* Tracepoint-related operations.  */
- #define target_trace_init() \
-diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
-new file mode 100644
-index 0000000..83faaf6
---- /dev/null
-+++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
-@@ -0,0 +1,457 @@
-+      .file   "x86_64-vla-pointer.c"
-+      .section        .debug_abbrev,"",@progbits
-+.Ldebug_abbrev0:
-+      .section        .debug_info,"",@progbits
-+.Ldebug_info0:
-+      .section        .debug_line,"",@progbits
-+.Ldebug_line0:
-+      .text
-+.Ltext0:
-+.globl foo
-+      .type   foo, @function
-+foo:
-+.LFB2:
-+      .file 1 "x86_64-vla-pointer.c"
-+      .loc 1 22 0
-+      pushq   %rbp
-+.LCFI0:
-+      movq    %rsp, %rbp
-+.LCFI1:
-+      subq    $64, %rsp
-+.LCFI2:
-+      movl    %edi, -36(%rbp)
-+      .loc 1 22 0
-+      movq    %rsp, %rax
-+      movq    %rax, -48(%rbp)
-+      .loc 1 23 0
-+      movl    -36(%rbp), %edx
-+      movslq  %edx,%rax
-+      subq    $1, %rax
-+      movq    %rax, -24(%rbp)
-+      .loc 1 24 0
-+      movslq  %edx,%rax
-+      addq    $15, %rax
-+      addq    $15, %rax
-+      shrq    $4, %rax
-+      salq    $4, %rax
-+      subq    %rax, %rsp
-+      movq    %rsp, -56(%rbp)
-+      movq    -56(%rbp), %rax
-+      addq    $15, %rax
-+      shrq    $4, %rax
-+      salq    $4, %rax
-+      movq    %rax, -56(%rbp)
-+      movq    -56(%rbp), %rax
-+      movq    %rax, -16(%rbp)
-+      .loc 1 27 0
-+      movl    $0, -4(%rbp)
-+      jmp     .L2
-+.L3:
-+      .loc 1 28 0
-+      movl    -4(%rbp), %esi
-+      movl    -4(%rbp), %eax
-+      movl    %eax, %ecx
-+      movq    -16(%rbp), %rdx
-+      movslq  %esi,%rax
-+      movb    %cl, (%rdx,%rax)
-+      .loc 1 27 0
-+      addl    $1, -4(%rbp)
-+.L2:
-+      movl    -4(%rbp), %eax
-+      cmpl    -36(%rbp), %eax
-+      jl      .L3
-+      .loc 1 30 0
-+      .globl  break_here
-+break_here:
-+      movq    -16(%rbp), %rax
-+      movb    $0, (%rax)
-+      movq    -48(%rbp), %rsp
-+      .loc 1 31 0
-+      leave
-+      ret
-+.LFE2:
-+      .size   foo, .-foo
-+      .section        .debug_frame,"",@progbits
-+.Lframe0:
-+      .long   .LECIE0-.LSCIE0
-+.LSCIE0:
-+      .long   0xffffffff
-+      .byte   0x1
-+      .string ""
-+      .uleb128 0x1
-+      .sleb128 -8
-+      .byte   0x10
-+      .byte   0xc
-+      .uleb128 0x7
-+      .uleb128 0x8
-+      .byte   0x90
-+      .uleb128 0x1
-+      .align 8
-+.LECIE0:
-+.LSFDE0:
-+      .long   .LEFDE0-.LASFDE0
-+.LASFDE0:
-+      .long   .Lframe0
-+      .quad   .LFB2
-+      .quad   .LFE2-.LFB2
-+      .byte   0x4
-+      .long   .LCFI0-.LFB2
-+      .byte   0xe
-+      .uleb128 0x10
-+      .byte   0x86
-+      .uleb128 0x2
-+      .byte   0x4
-+      .long   .LCFI1-.LCFI0
-+      .byte   0xd
-+      .uleb128 0x6
-+      .align 8
-+.LEFDE0:
-+      .section        .eh_frame,"a",@progbits
-+.Lframe1:
-+      .long   .LECIE1-.LSCIE1
-+.LSCIE1:
-+      .long   0x0
-+      .byte   0x1
-+      .string "zR"
-+      .uleb128 0x1
-+      .sleb128 -8
-+      .byte   0x10
-+      .uleb128 0x1
-+      .byte   0x3
-+      .byte   0xc
-+      .uleb128 0x7
-+      .uleb128 0x8
-+      .byte   0x90
-+      .uleb128 0x1
-+      .align 8
-+.LECIE1:
-+.LSFDE1:
-+      .long   .LEFDE1-.LASFDE1
-+.LASFDE1:
-+      .long   .LASFDE1-.Lframe1
-+      .long   .LFB2
-+      .long   .LFE2-.LFB2
-+      .uleb128 0x0
-+      .byte   0x4
-+      .long   .LCFI0-.LFB2
-+      .byte   0xe
-+      .uleb128 0x10
-+      .byte   0x86
-+      .uleb128 0x2
-+      .byte   0x4
-+      .long   .LCFI1-.LCFI0
-+      .byte   0xd
-+      .uleb128 0x6
-+      .align 8
-+.LEFDE1:
-+      .text
-+.Letext0:
-+      .section        .debug_loc,"",@progbits
-+.Ldebug_loc0:
-+.LLST0:
-+      .quad   .LFB2-.Ltext0
-+      .quad   .LCFI0-.Ltext0
-+      .value  0x2
-+      .byte   0x77
-+      .sleb128 8
-+      .quad   .LCFI0-.Ltext0
-+      .quad   .LCFI1-.Ltext0
-+      .value  0x2
-+      .byte   0x77
-+      .sleb128 16
-+      .quad   .LCFI1-.Ltext0
-+      .quad   .LFE2-.Ltext0
-+      .value  0x2
-+      .byte   0x76
-+      .sleb128 16
-+      .quad   0x0
-+      .quad   0x0
-+      .section        .debug_info
-+.Ldebug_relative:
-+      .long   .Ldebug_end - .Ldebug_start
-+.Ldebug_start:
-+      .value  0x2
-+      .long   .Ldebug_abbrev0
-+      .byte   0x8
-+      .uleb128 0x1
-+      .long   .LASF2
-+      .byte   0x1
-+      .long   .LASF3
-+      .long   .LASF4
-+      .quad   .Ltext0
-+      .quad   .Letext0
-+      .long   .Ldebug_line0
-+      .uleb128 0x2
-+      .byte   0x1
-+      .string "foo"
-+      .byte   0x1
-+      .byte   0x16
-+      .byte   0x1
-+      .quad   .LFB2
-+      .quad   .LFE2
-+      .long   .LLST0
-+      .long   .Ltype_int - .Ldebug_relative
-+      .uleb128 0x3
-+      .long   .LASF5
-+      .byte   0x1
-+      .byte   0x15
-+      .long   .Ltype_int - .Ldebug_relative
-+      .byte   0x2
-+      .byte   0x91
-+      .sleb128 -52
-+.Ltag_pointer:
-+      .uleb128 0x4
-+      .byte   0x8     /* DW_AT_byte_size */
-+      .long   .Ltag_array_type - .debug_info  /* DW_AT_type */
-+      .uleb128 0x5    /* Abbrev Number: 5 (DW_TAG_variable) */
-+      .long   .LASF0
-+      .byte   0x1
-+      .byte   0x18
-+#if 1
-+      .long   .Ltag_pointer - .debug_info
-+#else
-+      /* Debugging only: Skip the typedef indirection.  */
-+      .long   .Ltag_array_type - .debug_info
-+#endif
-+      /* DW_AT_location: DW_FORM_block1: start */
-+      .byte   0x3
-+      .byte   0x91
-+      .sleb128 -32
+       endpos = pos;
+@@ -1843,8 +1850,29 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
+ {
+   gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
+-  return exp_iterate (exp, exp_uses_objfile_iter, objfile);
++  return exp_iterate (exp, NULL, exp_uses_objfile_iter, objfile);
++}
++
++/* Helper for exp_types_mark_used.  */
++
 +#if 0
-+      .byte   0x6     /* DW_OP_deref */
-+#else
-+      .byte   0x96    /* DW_OP_nop */
-+#endif
-+      /* DW_AT_location: DW_FORM_block1: end */
-+      .uleb128 0x6
-+      .string "i"
-+      .byte   0x1
-+      .byte   0x19
-+      .long   .Ltype_int - .Ldebug_relative
-+      .byte   0x2
-+      .byte   0x91
-+      .sleb128 -20
-+      .byte   0x0
-+.Ltype_int:
-+      .uleb128 0x7
-+      .byte   0x4
-+      .byte   0x5
-+      .string "int"
-+.Ltag_array_type:
-+      .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
-+      .long   .Ltype_char - .Ldebug_relative
-+      .long   .Ltype_ulong - .Ldebug_relative /* DW_AT_sibling: DW_FORM_ref4 */
-+1:    /* DW_AT_data_location: DW_FORM_block1: start */
-+      .byte   2f - 3f /* length */
-+3:
-+      .byte   0x97    /* DW_OP_push_object_address */
-+#if 1
-+      .byte   0x6     /* DW_OP_deref */
-+#else
-+      .byte   0x96    /* DW_OP_nop */
-+#endif
-+2:    /* DW_AT_data_location: DW_FORM_block1: end */
-+      .uleb128 0x9
-+      .long   .Ltype_char - .Ldebug_relative  /* DW_AT_type: DW_FORM_ref4 */
-+      .byte   0x3
-+      .byte   0x91
-+      .sleb128 -40
-+      .byte   0x6
-+      .byte   0x0
-+.Ltype_ulong:
-+      .uleb128 0xa
-+      .byte   0x8
-+      .byte   0x7
-+.Ltype_char:
-+      .uleb128 0xb
-+      .byte   0x1
-+      .byte   0x6
-+      .long   .LASF1
-+      .byte   0x0
-+.Ldebug_end:
-+      .section        .debug_abbrev
-+      .uleb128 0x1
-+      .uleb128 0x11
-+      .byte   0x1
-+      .uleb128 0x25
-+      .uleb128 0xe
-+      .uleb128 0x13
-+      .uleb128 0xb
-+      .uleb128 0x3
-+      .uleb128 0xe
-+      .uleb128 0x1b
-+      .uleb128 0xe
-+      .uleb128 0x11
-+      .uleb128 0x1
-+      .uleb128 0x12
-+      .uleb128 0x1
-+      .uleb128 0x10
-+      .uleb128 0x6
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x2
-+      .uleb128 0x2e
-+      .byte   0x1
-+      .uleb128 0x3f
-+      .uleb128 0xc
-+      .uleb128 0x3
-+      .uleb128 0x8
-+      .uleb128 0x3a
-+      .uleb128 0xb
-+      .uleb128 0x3b
-+      .uleb128 0xb
-+      .uleb128 0x27
-+      .uleb128 0xc
-+      .uleb128 0x11
-+      .uleb128 0x1
-+      .uleb128 0x12
-+      .uleb128 0x1
-+      .uleb128 0x40
-+      .uleb128 0x6
-+      .uleb128 0x1
-+      .uleb128 0x13
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x3
-+      .uleb128 0x5
-+      .byte   0x0
-+      .uleb128 0x3
-+      .uleb128 0xe
-+      .uleb128 0x3a
-+      .uleb128 0xb
-+      .uleb128 0x3b
-+      .uleb128 0xb
-+      .uleb128 0x49
-+      .uleb128 0x13
-+      .uleb128 0x2
-+      .uleb128 0xa
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x4    /* .Ltag_pointer abbrev */
-+      .uleb128 0x0f   /* DW_TAG_pointer_type */
-+      .byte   0x0
-+      .uleb128 0x0b
-+      .uleb128 0xb
-+      .uleb128 0x49
-+      .uleb128 0x13
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x5
-+      .uleb128 0x34
-+      .byte   0x0
-+      .uleb128 0x3
-+      .uleb128 0xe
-+      .uleb128 0x3a
-+      .uleb128 0xb
-+      .uleb128 0x3b
-+      .uleb128 0xb
-+      .uleb128 0x49
-+      .uleb128 0x13
-+      .uleb128 0x2
-+      .uleb128 0xa
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x6
-+      .uleb128 0x34
-+      .byte   0x0
-+      .uleb128 0x3
-+      .uleb128 0x8
-+      .uleb128 0x3a
-+      .uleb128 0xb
-+      .uleb128 0x3b
-+      .uleb128 0xb
-+      .uleb128 0x49
-+      .uleb128 0x13
-+      .uleb128 0x2
-+      .uleb128 0xa
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x7
-+      .uleb128 0x24
-+      .byte   0x0
-+      .uleb128 0xb
-+      .uleb128 0xb
-+      .uleb128 0x3e
-+      .uleb128 0xb
-+      .uleb128 0x3
-+      .uleb128 0x8
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
-+      .uleb128 0x1
-+      .byte   0x1
-+      .uleb128 0x49   /* DW_AT_type */
-+      .uleb128 0x13   /* DW_FORM_ref4 */
-+      .uleb128 0x1    /* DW_AT_sibling */
-+      .uleb128 0x13   /* DW_FORM_ref4 */
-+      .uleb128 0x50   /* DW_AT_data_location */
-+      .uleb128 0xa    /* DW_FORM_block1 */
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0x9
-+      .uleb128 0x21
-+      .byte   0x0
-+      .uleb128 0x49   /* DW_AT_type */
-+      .uleb128 0x13   /* DW_FORM_ref4 */
-+      .uleb128 0x2f
-+      .uleb128 0xa
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0xa
-+      .uleb128 0x24
-+      .byte   0x0
-+      .uleb128 0xb
-+      .uleb128 0xb
-+      .uleb128 0x3e
-+      .uleb128 0xb
-+      .byte   0x0
-+      .byte   0x0
-+      .uleb128 0xb
-+      .uleb128 0x24
-+      .byte   0x0
-+      .uleb128 0xb
-+      .uleb128 0xb
-+      .uleb128 0x3e
-+      .uleb128 0xb
-+      .uleb128 0x3
-+      .uleb128 0xe
-+      .byte   0x0
-+      .byte   0x0
-+      .byte   0x0
-+      .section        .debug_pubnames,"",@progbits
-+      .long   0x16
-+      .value  0x2
-+      .long   .Ldebug_info0
-+      .long   0xa8
-+      .long   0x2d
-+      .string "foo"
-+      .long   0x0
-+      .section        .debug_aranges,"",@progbits
-+      .long   0x2c
-+      .value  0x2
-+      .long   .Ldebug_info0
-+      .byte   0x8
-+      .byte   0x0
-+      .value  0x0
-+      .value  0x0
-+      .quad   .Ltext0
-+      .quad   .Letext0-.Ltext0
-+      .quad   0x0
-+      .quad   0x0
-+      .section        .debug_str,"MS",@progbits,1
-+.LASF0:
-+      .string "array"
-+.LASF5:
-+      .string "size"
-+.LASF3:
-+      .string "x86_64-vla-pointer.c"
-+.LASF6:
-+      .string "array_t"
-+.LASF1:
-+      .string "char"
-+.LASF4:
-+      .string "gdb.arch"
-+.LASF2:
-+      .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
-+      .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
-+      .section        .note.GNU-stack,"",@progbits
-diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
++static int
++exp_types_mark_used_iter (struct type *type, void *unused)
++{
++  type_mark_used (type);
++
++  /* Continue the traversal.  */
++  return 0;
++}
++
++/* Call type_mark_used for any type contained in EXP.  */
++
++void
++exp_types_mark_used (struct expression *exp)
++{
++  exp_iterate (exp, exp_types_mark_used_iter, NULL, NULL);
+ }
++#endif
+ void
+ _initialize_parse (void)
+diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
+index 86f3bdf..f908a61 100644
+--- a/gdb/parser-defs.h
++++ b/gdb/parser-defs.h
+@@ -245,6 +245,8 @@ extern void operator_length_standard (const struct expression *, int, int *,
+                                     int *);
+ extern int operator_check_standard (struct expression *exp, int pos,
++                                  int (*type_func) (struct type *type,
++                                                    void *data),
+                                   int (*objfile_func)
+                                     (struct objfile *objfile, void *data),
+                                   void *data);
+@@ -331,6 +333,7 @@ struct exp_descriptor
+        value should be immediately returned to the caller.  Otherwise zero
+        should be returned.  */
+     int (*operator_check) (struct expression *exp, int pos,
++                         int (*type_func) (struct type *type, void *data),
+                          int (*objfile_func) (struct objfile *objfile,
+                                               void *data),
+                          void *data);
+@@ -369,4 +372,10 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
+ extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
++extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
++
++#if 0
++extern void exp_types_mark_used (struct expression *exp);
++#endif
++
+ #endif /* PARSER_DEFS_H */
+diff --git a/gdb/printcmd.c b/gdb/printcmd.c
+index d5b5b63..4bc2b5b 100644
+--- a/gdb/printcmd.c
++++ b/gdb/printcmd.c
+@@ -50,6 +50,7 @@
+ #include "arch-utils.h"
+ #include "cli/cli-utils.h"
+ #include "format.h"
++#include "dwarf2loc.h"
+ #ifdef TUI
+ #include "tui/tui.h"          /* For tui_active et al.   */
+@@ -968,6 +969,11 @@ print_command_1 (char *exp, int inspect, int voidprint)
+   else
+     val = access_value_history (0);
++  /* Do not try to OBJECT_ADDRESS_SET here anything.  We are interested in the
++     source variable base addresses as found by READ_VAR_VALUE.  The value here
++     can be already a calculated expression address inappropriate for
++     DW_OP_push_object_address.  */
++
+   if (voidprint || (val && value_type (val) &&
+                   TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
+     {
+@@ -1056,6 +1062,9 @@ output_command (char *exp, int from_tty)
+   val = evaluate_expression (expr);
++  if (VALUE_LVAL (val) == lval_memory)
++    object_address_set (value_raw_address (val));
++
+   annotate_value_begin (value_type (val));
+   get_formatted_print_options (&opts, format);
+@@ -1485,6 +1494,24 @@ x_command (char *exp, int from_tty)
+       set_internalvar (lookup_internalvar ("__"), last_examine_value);
+     }
+ }
++
++#if 0
++/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
++
++static void
++print_types_mark_used (void)
++{
++  struct display *d;
++
++  if (last_examine_value)
++    type_mark_used (value_type (last_examine_value));
++
++  for (d = display_chain; d; d = d->next)
++    if (d->exp)
++      exp_types_mark_used (d->exp);
++}
++#endif
++
\f
+ /* Add an expression to the auto-display chain.
+@@ -1982,6 +2009,10 @@ print_variable_and_value (const char *name, struct symbol *var,
+       struct value_print_options opts;
+       val = read_var_value (var, frame);
++
++      make_cleanup_restore_selected_frame ();
++      select_frame (frame);
++
+       get_user_print_options (&opts);
+       opts.deref_ref = 1;
+       common_val_print (val, stream, indent, &opts, current_language);
+@@ -2626,4 +2657,8 @@ Show printing of source filename and line number with <symbol>."), NULL,
+   add_com ("eval", no_class, eval_command, _("\
+ Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
+ a command line, and call it."));
++
++#if 0
++  observer_attach_mark_used (print_types_mark_used);
++#endif
+ }
+diff --git a/gdb/procfs.c b/gdb/procfs.c
+index 774df2e..4409e5b 100644
+--- a/gdb/procfs.c
++++ b/gdb/procfs.c
+@@ -3486,7 +3486,7 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
+   long storage_needed;
+   CORE_ADDR sym_addr;
+-  abfd = bfd_fdopenr ("unamed", 0, fd);
++  abfd = gdb_bfd_fdopenr ("unamed", 0, fd);
+   if (abfd == NULL)
+     {
+       warning (_("Failed to create a bfd: %s."), bfd_errmsg (bfd_get_error ()));
+@@ -3497,7 +3497,7 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
+     {
+       /* Not the correct format, so we can not possibly find the dbx_link
+        symbol in it.  */
+-      bfd_close (abfd);
++      gdb_bfd_unref (abfd);
+       return 0;
+     }
+@@ -3511,14 +3511,14 @@ insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
+       if (dbx_link_bpt == NULL)
+       {
+         warning (_("Failed to insert dbx_link breakpoint."));
+-        bfd_close (abfd);
++        gdb_bfd_unref (abfd);
+         return 0;
+       }
+-      bfd_close (abfd);
++      gdb_bfd_unref (abfd);
+       return 1;
+     }
+-  bfd_close (abfd);
++  gdb_bfd_unref (abfd);
+   return 0;
+ }
+diff --git a/gdb/python/lib/gdb/FrameIterator.py b/gdb/python/lib/gdb/FrameIterator.py
+new file mode 100644
+index 0000000..5654546
+--- /dev/null
++++ b/gdb/python/lib/gdb/FrameIterator.py
+@@ -0,0 +1,33 @@
++# Iterator over frames.
++
++# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++class FrameIterator:
++    """An iterator that iterates over frames."""
++
++    def __init__ (self, frame):
++        "Initialize a FrameIterator.  FRAME is the starting frame."
++        self.frame = frame
++
++    def __iter__ (self):
++        return self
++
++    def next (self):
++        result = self.frame
++        if result is None:
++            raise StopIteration
++        self.frame = result.older ()
++        return result
+diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
+new file mode 100644
+index 0000000..b790a54
+--- /dev/null
++++ b/gdb/python/lib/gdb/FrameWrapper.py
+@@ -0,0 +1,112 @@
++# Wrapper API for frames.
++
++# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++
++# FIXME: arguably all this should be on Frame somehow.
++class FrameWrapper:
++    def __init__ (self, frame):
++        self.frame = frame;
++
++    def write_symbol (self, stream, sym, block):
++        if len (sym.linkage_name):
++            nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
++            if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
++                sym = nsym
++
++        stream.write (sym.print_name + "=")
++        try:
++            val = self.read_var (sym)
++            if val != None:
++                val = str (val)
++        # FIXME: would be nice to have a more precise exception here.
++        except RuntimeError, text:
++            val = text
++        if val == None:
++            stream.write ("???")
++        else:
++            stream.write (str (val))
++
++    def print_frame_locals (self, stream, func):
++        if not func:
++            return
++
++        first = True
++        block = func.value
++
++        for sym in block:
++            if sym.is_argument:
++                continue;
++
++            self.write_symbol (stream, sym, block)
++            stream.write ('\n')
++
++    def print_frame_args (self, stream, func):
++        if not func:
++            return
++
++        first = True
++        block = func.value
++
++        for sym in block:
++            if not sym.is_argument:
++                continue;
++
++            if not first:
++                stream.write (", ")
++
++            self.write_symbol (stream, sym, block)
++            first = False
++
++    # FIXME: this should probably just be a method on gdb.Frame.
++    # But then we need stream wrappers.
++    def describe (self, stream, full):
++        if self.type () == gdb.DUMMY_FRAME:
++            stream.write (" <function called from gdb>\n")
++        elif self.type () == gdb.SIGTRAMP_FRAME:
++            stream.write (" <signal handler called>\n")
++        else:
++            sal = self.find_sal ()
++            pc = self.pc ()
++            name = self.name ()
++            if not name:
++                name = "??"
++            if pc != sal.pc or not sal.symtab:
++                stream.write (" 0x%08x in" % pc)
++            stream.write (" " + name + " (")
++
++            func = self.function ()
++            self.print_frame_args (stream, func)
++
++            stream.write (")")
++
++            if sal.symtab and sal.symtab.filename:
++                stream.write (" at " + sal.symtab.filename)
++                stream.write (":" + str (sal.line))
++
++            if not self.name () or (not sal.symtab or not sal.symtab.filename):
++                lib = gdb.solib_address (pc)
++                if lib:
++                    stream.write (" from " + lib)
++
++            stream.write ("\n")
++
++            if full:
++                self.print_frame_locals (stream, func)
++
++    def __getattr__ (self, name):
++        return getattr (self.frame, name)
+diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
+new file mode 100644
+index 0000000..6bb4fb1
+--- /dev/null
++++ b/gdb/python/lib/gdb/backtrace.py
+@@ -0,0 +1,42 @@
++# Filtering backtrace.
++
++# Copyright (C) 2008, 2011 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++import itertools
++
++# Our only exports.
++__all__ = ['push_frame_filter', 'create_frame_filter']
++
++frame_filter = None
++
++def push_frame_filter (constructor):
++    """Register a new backtrace filter class with the 'backtrace' command.
++The filter will be passed an iterator as an argument.  The iterator
++will return gdb.Frame-like objects.  The filter should in turn act as
++an iterator returning such objects."""
++    global frame_filter
++    if frame_filter == None:
++        frame_filter = constructor
++    else:
++        frame_filter = lambda iterator, filter = frame_filter: constructor (filter (iterator))
++
++def create_frame_filter (iter):
++    global frame_filter
++    if frame_filter is None:
++        return iter
++    return frame_filter (iter)
++
+diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
+new file mode 100644
+index 0000000..eeea909
+--- /dev/null
++++ b/gdb/python/lib/gdb/command/backtrace.py
+@@ -0,0 +1,106 @@
++# New backtrace command.
++
++# Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++import gdb.backtrace
++import itertools
++from gdb.FrameIterator import FrameIterator
++from gdb.FrameWrapper import FrameWrapper
++import sys
++
++class ReverseBacktraceParameter (gdb.Parameter):
++    """The new-backtrace command can show backtraces in 'reverse' order.
++This means that the innermost frame will be printed last.
++Note that reverse backtraces are more expensive to compute."""
++
++    set_doc = "Enable or disable reverse backtraces."
++    show_doc = "Show whether backtraces will be printed in reverse order."
++
++    def __init__(self):
++        gdb.Parameter.__init__ (self, "reverse-backtrace",
++                                gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
++        # Default to compatibility with gdb.
++        self.value = False
++
++class FilteringBacktrace (gdb.Command):
++    """Print backtrace of all stack frames, or innermost COUNT frames.
++With a negative argument, print outermost -COUNT frames.
++Use of the 'full' qualifier also prints the values of the local variables.
++Use of the 'raw' qualifier avoids any filtering by loadable modules.
++"""
++
++    def __init__ (self):
++        # FIXME: this is not working quite well enough to replace
++        # "backtrace" yet.
++        gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
++        self.reverse = ReverseBacktraceParameter()
++
++    def reverse_iter (self, iter):
++        result = []
++        for item in iter:
++            result.append (item)
++        result.reverse()
++        return result
++
++    def final_n (self, iter, x):
++        result = []
++        for item in iter:
++            result.append (item)
++        return result[x:]
++
++    def invoke (self, arg, from_tty):
++        i = 0
++        count = 0
++        filter = True
++        full = False
++
++        for word in arg.split (" "):
++            if word == '':
++                continue
++            elif word == 'raw':
++                filter = False
++            elif word == 'full':
++                full = True
++            else:
++                count = int (word)
++
++        # FIXME: provide option to start at selected frame
++        # However, should still number as if starting from newest
++        newest_frame = gdb.newest_frame()
++        iter = itertools.imap (FrameWrapper,
++                               FrameIterator (newest_frame))
++        if filter:
++            iter = gdb.backtrace.create_frame_filter (iter)
++
++        # Now wrap in an iterator that numbers the frames.
++        iter = itertools.izip (itertools.count (0), iter)
++
++        # Reverse if the user wanted that.
++        if self.reverse.value:
++            iter = self.reverse_iter (iter)
++
++        # Extract sub-range user wants.
++        if count < 0:
++            iter = self.final_n (iter, count)
++        elif count > 0:
++            iter = itertools.islice (iter, 0, count)
++
++        for pair in iter:
++            sys.stdout.write ("#%-2d" % pair[0])
++            pair[1].describe (sys.stdout, full)
++
++FilteringBacktrace()
+diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
+new file mode 100644
+index 0000000..6fa48ff
+--- /dev/null
++++ b/gdb/python/lib/gdb/command/ignore_errors.py
+@@ -0,0 +1,37 @@
++# Ignore errors in user commands.
++
++# Copyright (C) 2008 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++
++class IgnoreErrorsCommand (gdb.Command):
++    """Execute a single command, ignoring all errors.
++Only one-line commands are supported.
++This is primarily useful in scripts."""
++
++    def __init__ (self):
++        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
++                                                    gdb.COMMAND_OBSCURE,
++                                                    # FIXME...
++                                                    gdb.COMPLETE_COMMAND)
++
++    def invoke (self, arg, from_tty):
++        try:
++            gdb.execute (arg, from_tty)
++        except:
++            pass
++
++IgnoreErrorsCommand ()
+diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
+new file mode 100644
+index 0000000..21a0bf0
+--- /dev/null
++++ b/gdb/python/lib/gdb/command/pahole.py
+@@ -0,0 +1,75 @@
++# pahole command for gdb
++
++# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++
++class Pahole (gdb.Command):
++    """Show the holes in a structure.
++This command takes a single argument, a type name.
++It prints the type and displays comments showing where holes are."""
++
++    def __init__ (self):
++        super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
++                                       gdb.COMPLETE_SYMBOL)
++
++    def pahole (self, type, level, name):
++        if name is None:
++            name = ''
++        tag = type.tag
++        if tag is None:
++            tag = ''
++        print '%sstruct %s {' % (' ' * (2 * level), tag)
++        bitpos = 0
++        for field in type.fields ():
++            # Skip static fields.
++            if not hasattr (field, ('bitpos')):
++                continue
++
++            ftype = field.type.strip_typedefs()
++
++            if bitpos != field.bitpos:
++                hole = field.bitpos - bitpos
++                print '  /* XXX %d bit hole, try to pack */' % hole
++                bitpos = field.bitpos
++            if field.bitsize > 0:
++                fieldsize = field.bitsize
++            else:
++                # TARGET_CHAR_BIT here...
++                fieldsize = 8 * ftype.sizeof
++
++            # TARGET_CHAR_BIT
++            print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
++            bitpos = bitpos + fieldsize
++
++            if ftype.code == gdb.TYPE_CODE_STRUCT:
++                self.pahole (ftype, level + 1, field.name)
++            else:
++                print ' ' * (2 + 2 * level),
++                print '%s %s' % (str (ftype), field.name)
++
++        print ' ' * (14 + 2 * level),
++        print '} %s' % name
++
++    def invoke (self, arg, from_tty):
++        type = gdb.lookup_type (arg)
++        type = type.strip_typedefs ()
++        if type.code != gdb.TYPE_CODE_STRUCT:
++            raise TypeError, '%s is not a struct type' % arg
++        print ' ' * 14,
++        self.pahole (type, 0, '')
++
++Pahole()
+diff --git a/gdb/python/lib/gdb/command/require.py b/gdb/python/lib/gdb/command/require.py
+new file mode 100644
+index 0000000..1fbc1e8
+--- /dev/null
++++ b/gdb/python/lib/gdb/command/require.py
+@@ -0,0 +1,57 @@
++# Demand-loading commands.
++
++# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++import os
++
++class RequireCommand (gdb.Command):
++    """Prefix command for requiring features."""
++
++    def __init__ (self):
++        super (RequireCommand, self).__init__ ("require",
++                                               gdb.COMMAND_SUPPORT,
++                                               gdb.COMPLETE_NONE,
++                                               True)
++
++class RequireSubcommand (gdb.Command):
++    """Demand-load a command by name."""
++
++    def __init__ (self, name):
++        self.__doc__ = "Demand-load a %s by name." % name
++        super (RequireSubcommand, self).__init__ ("require %s" % name,
++                                                  gdb.COMMAND_SUPPORT)
++        self.name = name
++
++    def invoke (self, arg, from_tty):
++        for cmd in arg.split():
++            exec ('import gdb.' + self.name + '.' + cmd, globals ())
++
++    def complete (self, text, word):
++        dir = gdb.pythondir + '/gdb/' + self.name
++        result = []
++        for file in os.listdir(dir):
++            if not file.startswith (word) or not file.endswith ('.py'):
++                continue
++            feature = file[0:-3]
++            if feature == 'require' or feature == '__init__':
++                continue
++            result.append (feature)
++        return result
++
++RequireCommand()
++RequireSubcommand("command")
++RequireSubcommand("function")
+diff --git a/gdb/python/lib/gdb/command/upto.py b/gdb/python/lib/gdb/command/upto.py
+new file mode 100644
+index 0000000..faf54ed
+--- /dev/null
++++ b/gdb/python/lib/gdb/command/upto.py
+@@ -0,0 +1,129 @@
++# upto command.
++
++# Copyright (C) 2009 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++import re
++from gdb.FrameIterator import FrameIterator
++from gdb.FrameWrapper import FrameWrapper
++
++class UptoPrefix (gdb.Command):
++    def __init__ (self):
++        super (UptoPrefix, self).__init__ ("upto", gdb.COMMAND_STACK,
++                                           prefix = True)
++
++class UptoImplementation (gdb.Command):
++    def __init__ (self, subcommand):
++        super (UptoImplementation, self).__init__ ("upto " + subcommand,
++                                                   gdb.COMMAND_STACK)
++
++    def search (self):
++        saved = gdb.selected_frame ()
++        iter = FrameIterator (saved)
++        found = False
++        try:
++            for frame in iter:
++                frame.select ()
++                try:
++                    if self.filter (frame):
++                        wrapper = FrameWrapper (frame)
++                        wrapper.describe (sys.stdout, False)
++                        return
++                except:
++                    pass
++        except:
++            pass
++        saved.select ()
++        raise RuntimeError, 'Could not find a matching frame'
++
++    def invoke (self, arg, from_tty):
++        self.rx = re.compile (arg)
++        self.search ()
++
++class UptoSymbolCommand (UptoImplementation):
++    """Select and print some calling stack frame, based on symbol.
++The argument is a regular expression.  This command moves up the
++stack, stopping at the first frame whose symbol matches the regular
++expression."""
++
++    def __init__ (self):
++        super (UptoSymbolCommand, self).__init__ ("symbol")
++
++    def filter (self, frame):
++        name = frame.name ()
++        if name is not None:
++            if self.rx.search (name) is not None:
++                return True
++        return False
++
++class UptoSourceCommand (UptoImplementation):
++    """Select and print some calling stack frame, based on source file.
++The argument is a regular expression.  This command moves up the
++stack, stopping at the first frame whose source file name matches the
++regular expression."""
++
++    def __init__ (self):
++        super (UptoSourceCommand, self).__init__ ("source")
++
++    def filter (self, frame):
++        name = frame.find_sal ().symtab.filename
++        if name is not None:
++            if self.rx.search (name) is not None:
++                return True
++        return False
++
++class UptoObjectCommand (UptoImplementation):
++    """Select and print some calling stack frame, based on object file.
++The argument is a regular expression.  This command moves up the
++stack, stopping at the first frame whose object file name matches the
++regular expression."""
++
++    def __init__ (self):
++        super (UptoObjectCommand, self).__init__ ("object")
++
++    def filter (self, frame):
++        name = frame.find_sal ().symtab.objfile.filename
++        if name is not None:
++            if self.rx.search (name) is not None:
++                return True
++        return False
++
++class UptoWhereCommand (UptoImplementation):
++    """Select and print some calling stack frame, based on expression.
++The argument is an expression.  This command moves up the stack,
++parsing and evaluating the expression in each frame.  This stops when
++the expression evaluates to a non-zero (true) value."""
++
++    def __init__ (self):
++        super (UptoWhereCommand, self).__init__ ("where")
++
++    def filter (self, frame):
++        try:
++            if gdb.parse_and_eval (self.expression):
++                return True
++        except:
++            pass
++        return False
++
++    def invoke (self, arg, from_tty):
++        self.expression = arg
++        self.search ()
++
++UptoPrefix ()
++UptoSymbolCommand ()
++UptoSourceCommand ()
++UptoObjectCommand ()
++UptoWhereCommand ()
+diff --git a/gdb/python/lib/gdb/function/__init__.py b/gdb/python/lib/gdb/function/__init__.py
+new file mode 100644
+index 0000000..8b13789
+--- /dev/null
++++ b/gdb/python/lib/gdb/function/__init__.py
+@@ -0,0 +1 @@
++
+diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py
+new file mode 100644
+index 0000000..2b9c5c7
+--- /dev/null
++++ b/gdb/python/lib/gdb/function/caller_is.py
+@@ -0,0 +1,58 @@
++# Caller-is functions.
++
++# Copyright (C) 2008 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++import re
++
++class CallerIs (gdb.Function):
++    """Return True if the calling function's name is equal to a string.
++This function takes one or two arguments.
++The first argument is the name of a function; if the calling function's
++name is equal to this argument, this function returns True.
++The optional second argument tells this function how many stack frames
++to traverse to find the calling function.  The default is 1."""
++
++    def __init__ (self):
++        super (CallerIs, self).__init__ ("caller_is")
++
++    def invoke (self, name, nframes = 1):
++        frame = gdb.selected_frame ()
++        while nframes > 0:
++            frame = frame.older ()
++            nframes = nframes - 1
++        return frame.name () == name.string ()
++
++class CallerMatches (gdb.Function):
++    """Return True if the calling function's name matches a string.
++This function takes one or two arguments.
++The first argument is a regular expression; if the calling function's
++name is matched by this argument, this function returns True.
++The optional second argument tells this function how many stack frames
++to traverse to find the calling function.  The default is 1."""
++
++    def __init__ (self):
++        super (CallerMatches, self).__init__ ("caller_matches")
++
++    def invoke (self, name, nframes = 1):
++        frame = gdb.selected_frame ()
++        while nframes > 0:
++            frame = frame.older ()
++            nframes = nframes - 1
++        return re.match (name.string (), frame.name ()) is not None
++
++CallerIs()
++CallerMatches()
+diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
 new file mode 100644
-index 0000000..fe2c8f7
+index 0000000..debb3bb
 --- /dev/null
-+++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
-@@ -0,0 +1,43 @@
-+/* This testcase is part of GDB, the GNU debugger.
++++ b/gdb/python/lib/gdb/function/in_scope.py
+@@ -0,0 +1,47 @@
++# In-scope function.
++
++# Copyright (C) 2008 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++import gdb
++
++class InScope (gdb.Function):
++    """Return True if all the given variables or macros are in scope.
++Takes one argument for each variable name to be checked."""
++
++    def __init__ (self):
++      super (InScope, self).__init__ ("in_scope")
++
++    def invoke (self, *vars):
++        if len (vars) == 0:
++          raise TypeError, "in_scope takes at least one argument"
++
++        # gdb.Value isn't hashable so it can't be put in a map.
++      # Convert to string first.
++      wanted = set (map (lambda x: x.string (), vars))
++      found = set ()
++      block = gdb.selected_frame ().block ()
++      while block:
++          for sym in block:
++              if (sym.is_argument or sym.is_constant
++                    or sym.is_function or sym.is_variable):
++                  if sym.name in wanted:
++                      found.add (sym.name)
++
++          block = block.superblock
++
++      return wanted == found
++
++InScope ()
+diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
+index 98030a6..9870eec 100644
+--- a/gdb/python/py-type.c
++++ b/gdb/python/py-type.c
+@@ -30,6 +30,8 @@
+ #include "vec.h"
+ #include "bcache.h"
+ #include "dwarf2loc.h"
++#include "observer.h"
++#include "gdb_assert.h"
+ typedef struct pyty_type_object
+ {
+@@ -38,11 +40,19 @@ typedef struct pyty_type_object
+   /* If a Type object is associated with an objfile, it is kept on a
+      doubly-linked list, rooted in the objfile.  This lets us copy the
+-     underlying struct type when the objfile is deleted.  */
++     underlying struct type when the objfile is deleted.
++
++     With NULL objfile Type still can be doubly-linked in the list
++     PYTY_OBJECTS_DISCARDABLE.  */
+   struct pyty_type_object *prev;
+   struct pyty_type_object *next;
+ } type_object;
++#if 0
++/* First element of a doubly-linked list of TYPE_DISCARDABLE Types.  */
++static type_object *pyty_objects_discardable;
++#endif
++
+ static PyTypeObject type_object_type;
+ /* A Field object.  */
+@@ -1166,8 +1176,63 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
\f
++/* Key associated with each objfile pointing to the first element of
++   a doubly-linked list of Types associated with this objfile.  */
+ static const struct objfile_data *typy_objfile_data_key;
++/* Link TYPE_OBJ to its appropriate list.  Either to its objfile associated one
++   or at least to the global list for TYPE_DISCARDABLE Types.  Permanent types
++   do not get linked anywhere.  */
++static void
++typy_link (type_object *type_obj)
++{
++  type_obj->prev = NULL;
++
++  if (type_obj->type && TYPE_OBJFILE (type_obj->type))
++    {
++      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
++
++      type_obj->next = objfile_data (objfile, typy_objfile_data_key);
++      if (type_obj->next)
++      type_obj->next->prev = type_obj;
++      set_objfile_data (objfile, typy_objfile_data_key, type_obj);
++    }
++#if 0
++  else if (type_obj->type && TYPE_DISCARDABLE (type_obj->type))
++    {
++      type_obj->next = pyty_objects_discardable;
++      if (type_obj->next)
++      type_obj->next->prev = type_obj;
++      pyty_objects_discardable = type_obj;
++    }
++#endif
++  else
++    type_obj->next = NULL;
++}
++
++/* Unlink TYPE_OBJ from its current list.  Permanent types are not linked
++   anywhere and this function has no effect on them.  */
++static void
++typy_unlink (type_object *type_obj)
++{
++  if (type_obj->prev)
++    type_obj->prev->next = type_obj->next;
++  else if (type_obj->type && TYPE_OBJFILE (type_obj->type))
++    {
++      /* Must reset head of list.  */
++      struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
++
++      set_objfile_data (objfile, typy_objfile_data_key, type_obj->next);
++    }
++#if 0
++  else if (pyty_objects_discardable == type_obj)
++    pyty_objects_discardable = type_obj->next;
++#endif
++
++  if (type_obj->next)
++    type_obj->next->prev = type_obj->prev;
++}
++
+ static void
+ save_objfile_types (struct objfile *objfile, void *datum)
+ {
+@@ -1185,12 +1250,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
+     {
+       type_object *next = obj->next;
+-      htab_empty (copied_types);
++      gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
++      typy_unlink (obj);
+-      obj->type = copy_type_recursive (objfile, obj->type, copied_types);
++      obj->type = copy_type_recursive (obj->type, copied_types);
+-      obj->next = NULL;
+-      obj->prev = NULL;
++      gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
++      typy_link (obj);
+       obj = next;
+     }
+@@ -1201,43 +1267,28 @@ save_objfile_types (struct objfile *objfile, void *datum)
+ }
+ static void
+-set_type (type_object *obj, struct type *type)
++typy_dealloc (PyObject *obj)
+ {
+-  obj->type = type;
+-  obj->prev = NULL;
+-  if (type && TYPE_OBJFILE (type))
+-    {
+-      struct objfile *objfile = TYPE_OBJFILE (type);
++  type_object *type_obj = (type_object *) obj;
+-      obj->next = objfile_data (objfile, typy_objfile_data_key);
+-      if (obj->next)
+-      obj->next->prev = obj;
+-      set_objfile_data (objfile, typy_objfile_data_key, obj);
+-    }
+-  else
+-    obj->next = NULL;
++  typy_unlink (type_obj);
++
++  type_obj->ob_type->tp_free (obj);
+ }
++#if 0
++/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
+ static void
+-typy_dealloc (PyObject *obj)
++typy_types_mark_used (void)
+ {
+-  type_object *type = (type_object *) obj;
+-
+-  if (type->prev)
+-    type->prev->next = type->next;
+-  else if (type->type && TYPE_OBJFILE (type->type))
+-    {
+-      /* Must reset head of list.  */
+-      struct objfile *objfile = TYPE_OBJFILE (type->type);
+-
+-      if (objfile)
+-      set_objfile_data (objfile, typy_objfile_data_key, type->next);
+-    }
+-  if (type->next)
+-    type->next->prev = type->prev;
++  type_object *type_obj;
+-  type->ob_type->tp_free (type);
++  for (type_obj = pyty_objects_discardable;
++       type_obj != NULL;
++       type_obj = type_obj->next)
++    type_mark_used (type_obj->type);
+ }
++#endif
+ /* Return number of fields ("length" of the field dictionary).  */
+@@ -1457,7 +1508,10 @@ type_to_type_object (struct type *type)
+   type_obj = PyObject_New (type_object, &type_object_type);
+   if (type_obj)
+-    set_type (type_obj, type);
++    {
++      type_obj->type = type;
++      typy_link (type_obj);
++    }
+   return (PyObject *) type_obj;
+ }
+@@ -1537,6 +1591,10 @@ gdbpy_initialize_types (void)
+   Py_INCREF (&field_object_type);
+   PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
 +
-+   Copyright 2009 Free Software Foundation, Inc.
++#if 0
++  observer_attach_mark_used (typy_types_mark_used);
++#endif
+ }
\f
+diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
+index 6f67bdb..5ddd6bc 100644
+--- a/gdb/python/py-value.c
++++ b/gdb/python/py-value.c
+@@ -29,6 +29,7 @@
+ #include "expression.h"
+ #include "cp-abi.h"
+ #include "python.h"
++#include "observer.h"
+ #ifdef HAVE_PYTHON
+@@ -1378,6 +1379,19 @@ gdbpy_is_value_object (PyObject *obj)
+   return PyObject_TypeCheck (obj, &value_object_type);
+ }
++#if 0
++/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
 +
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
++static void
++python_types_mark_used (void)
++{
++  value_object *iter;
 +
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
++  for (iter = values_in_python; iter; iter = iter->next)
++    type_mark_used (value_type (iter->value));
++}
++#endif
 +
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+ void
+ gdbpy_initialize_values (void)
+ {
+@@ -1388,6 +1402,10 @@ gdbpy_initialize_values (void)
+   PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
+   values_in_python = NULL;
 +
 +#if 0
++  observer_attach_mark_used (python_types_mark_used);
++#endif
+ }
\f
+diff --git a/gdb/python/python.c b/gdb/python/python.c
+index c66efe4..0211fcb 100644
+--- a/gdb/python/python.c
++++ b/gdb/python/python.c
+@@ -66,10 +66,13 @@ static const char *gdbpy_should_print_stack = python_excp_message;
+ #include "linespec.h"
+ #include "source.h"
+ #include "version.h"
++#include "inferior.h"
++#include "gdbthread.h"
+ #include "target.h"
+ #include "gdbthread.h"
+ #include "observer.h"
+ #include "interps.h"
++#include "event-top.h"
+ static PyMethodDef GdbMethods[];
+@@ -979,6 +982,53 @@ gdbpy_print_stack (void)
+ /* Return the current Progspace.
+    There always is one.  */
++/* True if 'gdb -P' was used, false otherwise.  */
++static int running_python_script;
 +
-+void
-+foo (int size)
++/* True if we are currently in a call to 'gdb.cli', false otherwise.  */
++static int in_cli;
++
++/* Enter the command loop.  */
++
++static PyObject *
++gdbpy_cli (PyObject *unused1, PyObject *unused2)
 +{
-+  typedef char array_t[size];
-+  array_t array;
-+  int i;
++  if (! running_python_script || in_cli)
++    return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
 +
-+  for (i = 0; i < size; i++)
-+    array[i] = i;
++  in_cli = 1;
++  cli_command_loop ();
++  in_cli = 0;
 +
-+  array[0] = 0;       /* break-here */
++  Py_RETURN_NONE;
 +}
 +
-+#else
++/* Set up the Python argument vector and evaluate a script.  This is
++   used to implement 'gdb -P'.  */
 +
-+int
-+main (void)
++void
++run_python_script (int argc, char **argv)
 +{
-+  foo (26);
-+  foo (78);
-+  return 0;
++  FILE *input;
++
++  /* We never free this, since we plan to exit at the end.  */
++  ensure_python_env (get_current_arch (), current_language);
++
++  running_python_script = 1;
++  PySys_SetArgv (argc - 1, argv + 1);
++  input = fopen (argv[0], "r");
++  if (! input)
++    {
++      fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
++      exit (1);
++    }
++  PyRun_SimpleFile (input, argv[0]);
++  fclose (input);
++  exit (0);
 +}
 +
-+#endif
-diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
-new file mode 100644
-index 0000000..d243cf1
---- /dev/null
-+++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
-@@ -0,0 +1,66 @@
-+# Copyright 2009 Free Software Foundation, Inc.
++\f
 +
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ static PyObject *
+ gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
+@@ -1420,6 +1470,8 @@ static PyMethodDef GdbMethods[] =
+     "Get a value from history" },
+   { "execute", (PyCFunction) execute_gdb_command, METH_VARARGS | METH_KEYWORDS,
+     "Execute a gdb command" },
++  { "cli", gdbpy_cli, METH_NOARGS,
++    "Enter the gdb CLI" },
+   { "parameter", gdbpy_parameter, METH_VARARGS,
+     "Return a gdb parameter's value" },
+diff --git a/gdb/python/python.h b/gdb/python/python.h
+index dd7066f..f0f6e90 100644
+--- a/gdb/python/python.h
++++ b/gdb/python/python.h
+@@ -30,6 +30,8 @@ void eval_python_from_control_command (struct command_line *);
+ void source_python_script (FILE *file, const char *filename);
++void run_python_script (int argc, char **argv);
 +
-+if ![istarget "x86_64-*-*"] then {
-+    verbose "Skipping over gdb.arch/x86_64-vla-pointer.exp test made only for x86_64."
-+    return
-+}
+ int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
+                             int embedded_offset, CORE_ADDR address,
+                             struct ui_file *stream, int recurse,
+diff --git a/gdb/record.c b/gdb/record.c
+index bb0fe52..ec42aac 100644
+--- a/gdb/record.c
++++ b/gdb/record.c
+@@ -32,6 +32,7 @@
+ #include "gcore.h"
+ #include "event-loop.h"
+ #include "inf-loop.h"
++#include "gdb_bfd.h"
+ #include <signal.h>
+@@ -2638,7 +2639,7 @@ record_save_cleanups (void *data)
+   bfd *obfd = data;
+   char *pathname = xstrdup (bfd_get_filename (obfd));
+-  bfd_close (obfd);
++  gdb_bfd_unref (obfd);
+   unlink (pathname);
+   xfree (pathname);
+ }
+@@ -2854,7 +2855,7 @@ cmd_record_save (char *args, int from_tty)
+     }
+   do_cleanups (set_cleanups);
+-  bfd_close (obfd);
++  gdb_bfd_unref (obfd);
+   discard_cleanups (old_cleanups);
+   /* Succeeded.  */
+diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c
+index 47f4405..85268b6 100644
+--- a/gdb/remote-m32r-sdi.c
++++ b/gdb/remote-m32r-sdi.c
+@@ -39,6 +39,7 @@
+ #include <sys/time.h>
+ #include <signal.h>
+ #include <time.h>
++#include "gdb_bfd.h"
+ #include "serial.h"
+@@ -1257,13 +1258,13 @@ m32r_load (char *args, int from_tty)
+   if (!filename)
+     filename = get_exec_file (1);
+-  pbfd = bfd_openr (filename, gnutarget);
++  pbfd = gdb_bfd_openr (filename, gnutarget);
+   if (pbfd == NULL)
+     {
+       perror_with_name (filename);
+       return;
+     }
+-  old_chain = make_cleanup_bfd_close (pbfd);
++  old_chain = make_cleanup_bfd_unref (pbfd);
+   if (!bfd_check_format (pbfd, bfd_object))
+     error (_("\"%s\" is not an object file: %s"), filename,
+diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c
+index babbf19..db4381b 100644
+--- a/gdb/remote-mips.c
++++ b/gdb/remote-mips.c
+@@ -36,6 +36,7 @@
+ #include <ctype.h>
+ #include "mips-tdep.h"
+ #include "gdbthread.h"
++#include "gdb_bfd.h"
\f
+ /* Breakpoint types.  Values 0, 1, and 2 must agree with the watch
+@@ -2783,20 +2784,23 @@ mips_load_srec (char *args)
+   unsigned int i;
+   unsigned int srec_frame = 200;
+   int reclen;
++  struct cleanup *cleanup;
+   static int hashmark = 1;
+   buffer = alloca (srec_frame * 2 + 256);
+-  abfd = bfd_openr (args, 0);
++  abfd = gdb_bfd_openr (args, 0);
+   if (!abfd)
+     {
+       printf_filtered ("Unable to open file %s\n", args);
+       return;
+     }
++  cleanup = make_cleanup_bfd_unref (abfd);
+   if (bfd_check_format (abfd, bfd_object) == 0)
+     {
+       printf_filtered ("File is not an object file\n");
++      do_cleanups (cleanup);
+       return;
+     }
+@@ -2850,6 +2854,7 @@ mips_load_srec (char *args)
+   send_srec (srec, reclen, abfd->start_address);
+   serial_flush_input (mips_desc);
++  do_cleanups (cleanup);
+ }
+ /*
+@@ -3366,20 +3371,23 @@ pmon_load_fast (char *file)
+   int bintotal = 0;
+   int final = 0;
+   int finished = 0;
++  struct cleanup *cleanup;
+   buffer = (char *) xmalloc (MAXRECSIZE + 1);
+   binbuf = (unsigned char *) xmalloc (BINCHUNK);
+-  abfd = bfd_openr (file, 0);
++  abfd = gdb_bfd_openr (file, 0);
+   if (!abfd)
+     {
+       printf_filtered ("Unable to open file %s\n", file);
+       return;
+     }
++  cleanup = make_cleanup_bfd_unref (abfd);
+   if (bfd_check_format (abfd, bfd_object) == 0)
+     {
+       printf_filtered ("File is not an object file\n");
++      do_cleanups (cleanup);
+       return;
+     }
+@@ -3503,6 +3511,7 @@ pmon_load_fast (char *file)
+       pmon_end_download (final, bintotal);
+     }
++  do_cleanups (cleanup);
+   return;
+ }
+diff --git a/gdb/remote.c b/gdb/remote.c
+index 1c9367d..f2b5e7b 100644
+--- a/gdb/remote.c
++++ b/gdb/remote.c
+@@ -42,6 +42,7 @@
+ #include "cli/cli-decode.h"
+ #include "cli/cli-setshow.h"
+ #include "target-descriptions.h"
++#include "gdb_bfd.h"
+ #include <ctype.h>
+ #include <sys/time.h>
+@@ -9823,11 +9824,13 @@ remote_filename_p (const char *filename)
+ bfd *
+ remote_bfd_open (const char *remote_file, const char *target)
+ {
+-  return bfd_openr_iovec (remote_file, target,
+-                        remote_bfd_iovec_open, NULL,
+-                        remote_bfd_iovec_pread,
+-                        remote_bfd_iovec_close,
+-                        remote_bfd_iovec_stat);
++  bfd *abfd = gdb_bfd_openr_iovec (remote_file, target,
++                                 remote_bfd_iovec_open, NULL,
++                                 remote_bfd_iovec_pread,
++                                 remote_bfd_iovec_close,
++                                 remote_bfd_iovec_stat);
++
++  return abfd;
+ }
+ void
+diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c
+index 0a2000a..9b8efd3 100644
+--- a/gdb/rs6000-nat.c
++++ b/gdb/rs6000-nat.c
+@@ -730,7 +730,7 @@ static struct vmap *
+ add_vmap (LdInfo *ldi)
+ {
+   bfd *abfd, *last;
+-  char *mem, *objname, *filename;
++  char *mem, *filename;
+   struct objfile *obj;
+   struct vmap *vp;
+   int fd;
+@@ -743,19 +743,18 @@ add_vmap (LdInfo *ldi)
+   filename = LDI_FILENAME (ldi, arch64);
+   mem = filename + strlen (filename) + 1;
+   mem = xstrdup (mem);
+-  objname = xstrdup (filename);
+   fd = LDI_FD (ldi, arch64);
+   if (fd < 0)
+     /* Note that this opens it once for every member; a possible
+        enhancement would be to only open it once for every object.  */
+-    abfd = bfd_openr (objname, gnutarget);
++    abfd = gdb_bfd_openr (filename, gnutarget);
+   else
+-    abfd = bfd_fdopenr (objname, gnutarget, fd);
++    abfd = gdb_bfd_fdopenr (filename, gnutarget, fd);
+   if (!abfd)
+     {
+       warning (_("Could not open `%s' as an executable file: %s"),
+-             objname, bfd_errmsg (bfd_get_error ()));
++             filename, bfd_errmsg (bfd_get_error ()));
+       return NULL;
+     }
+@@ -766,35 +765,44 @@ add_vmap (LdInfo *ldi)
+   else if (bfd_check_format (abfd, bfd_archive))
+     {
+-      last = 0;
+-      /* FIXME??? am I tossing BFDs?  bfd?  */
+-      while ((last = bfd_openr_next_archived_file (abfd, last)))
+-      if (strcmp (mem, last->filename) == 0)
+-        break;
++      last = gdb_bfd_openr_next_archived_file (abfd, NULL);
++      while (last != NULL)
++      {
++        bfd *next;
++
++        if (strcmp (mem, last->filename) == 0)
++          break;
++
++        next = gdb_bfd_openr_next_archived_file (abfd, last);
++        gdb_bfd_unref (last);
++      }
+       if (!last)
+       {
+-        warning (_("\"%s\": member \"%s\" missing."), objname, mem);
+-        bfd_close (abfd);
++        warning (_("\"%s\": member \"%s\" missing."), filename, mem);
++        gdb_bfd_unref (abfd);
+         return NULL;
+       }
+       if (!bfd_check_format (last, bfd_object))
+       {
+         warning (_("\"%s\": member \"%s\" not in executable format: %s."),
+-                 objname, mem, bfd_errmsg (bfd_get_error ()));
+-        bfd_close (last);
+-        bfd_close (abfd);
++                 filename, mem, bfd_errmsg (bfd_get_error ()));
++        gdb_bfd_unref (last);
++        gdb_bfd_unref (abfd);
+         return NULL;
+       }
+       vp = map_vmap (last, abfd);
++      /* map_vmap acquired a reference to LAST, so we can release
++       ours.  */
++      gdb_bfd_unref (last);
+     }
+   else
+     {
+       warning (_("\"%s\": not in executable format: %s."),
+-             objname, bfd_errmsg (bfd_get_error ()));
+-      bfd_close (abfd);
++             filename, bfd_errmsg (bfd_get_error ()));
++      gdb_bfd_unref (abfd);
+       return NULL;
+     }
+   obj = allocate_objfile (vp->bfd, 0);
+@@ -803,6 +811,11 @@ add_vmap (LdInfo *ldi)
+   /* Always add symbols for the main objfile.  */
+   if (vp == vmap || auto_solib_add)
+     vmap_add_symbols (vp);
 +
-+set testfile x86_64-vla-pointer
-+set srcasmfile ${testfile}-foo.S
-+set srcfile ${testfile}.c
-+set binfile ${objdir}/${subdir}/${testfile}
-+set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
-+    untested "Couldn't compile test program"
-+    return -1
-+}
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
-+    untested "Couldn't compile test program"
-+    return -1
-+}
++  /* Anything needing a reference to ABFD has already acquired it, so
++     release our local reference.  */
++  gdb_bfd_unref (abfd);
 +
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
+   return vp;
+ }
\f
+diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
+index d52fb46..db8f187 100644
+--- a/gdb/solib-darwin.c
++++ b/gdb/solib-darwin.c
+@@ -28,6 +28,7 @@
+ #include "inferior.h"
+ #include "regcache.h"
+ #include "gdbthread.h"
++#include "gdb_bfd.h"
+ #include "gdb_assert.h"
+@@ -356,6 +357,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
+   gdb_byte *interp_name;
+   CORE_ADDR load_addr = 0;
+   bfd *dyld_bfd = NULL;
++  struct cleanup *cleanup;
+   /* This method doesn't work with an attached process.  */
+   if (current_inferior ()->attach_flag)
+@@ -366,24 +368,31 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
+   if (!interp_name)
+     return;
++  cleanup = make_cleanup (null_cleanup, NULL);
 +
-+if ![runto_main] {
-+    untested x86_64-vla-pointer
-+    return -1
-+}
+   /* Create a bfd for the interpreter.  */
+-  dyld_bfd = bfd_openr (interp_name, gnutarget);
++  dyld_bfd = gdb_bfd_openr (interp_name, gnutarget);
+   if (dyld_bfd)
+     {
+       bfd *sub;
++      make_cleanup_bfd_unref (dyld_bfd);
+       sub = bfd_mach_o_fat_extract (dyld_bfd, bfd_object,
+                                   gdbarch_bfd_arch_info (target_gdbarch));
+       if (sub)
+-      dyld_bfd = sub;
+-      else
+       {
+-        bfd_close (dyld_bfd);
+-        dyld_bfd = NULL;
++        dyld_bfd = sub;
++        gdb_bfd_ref (sub);
++        make_cleanup_bfd_unref (sub);
+       }
++      else
++      dyld_bfd = NULL;
+     }
+   if (!dyld_bfd)
+-    return;
++    {
++      do_cleanups (cleanup);
++      return;
++    }
+   /* We find the dynamic linker's base address by examining
+      the current pc (which should point at the entry point for the
+@@ -395,7 +404,7 @@ darwin_solib_get_all_image_info_addr_at_init (struct darwin_info *info)
+   info->all_image_addr =
+     lookup_symbol_from_bfd (dyld_bfd, "_dyld_all_image_infos");
+-  bfd_close (dyld_bfd);
++  do_cleanups (cleanup);
+   if (info->all_image_addr == 0)
+     return;
+@@ -509,17 +518,10 @@ darwin_bfd_open (char *pathname)
+                               gdbarch_bfd_arch_info (target_gdbarch));
+   if (!res)
+     {
+-      bfd_close (abfd);
+-      make_cleanup (xfree, found_pathname);
++      make_cleanup_bfd_unref (abfd);
+       error (_("`%s': not a shared-library: %s"),
+-           found_pathname, bfd_errmsg (bfd_get_error ()));
++           bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
+     }
+-
+-  /* Make sure that the filename is malloc'ed.  The current filename
+-     for fat-binaries BFDs is a name that was generated by BFD, usually
+-     a static string containing the name of the architecture.  */
+-  res->filename = xstrdup (pathname);
+-
+   return res;
+ }
+diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
+index 2500c1f..fcc01a8 100644
+--- a/gdb/solib-dsbt.c
++++ b/gdb/solib-dsbt.c
+@@ -30,6 +30,7 @@
+ #include "gdbcmd.h"
+ #include "elf-bfd.h"
+ #include "exceptions.h"
++#include "gdb_bfd.h"
+ #define GOT_MODULE_OFFSET 4
+@@ -899,7 +900,7 @@ enable_break2 (void)
+       {
+         warning (_("Could not find symbol _dl_debug_addr in dynamic linker"));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+@@ -948,13 +949,13 @@ enable_break2 (void)
+                    "(at address %s) from dynamic linker"),
+                  hex_string_custom (addr + 8, 8));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+       addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
+       /* We're done with the temporary bfd.  */
+-      bfd_close (tmp_bfd);
++      gdb_bfd_unref (tmp_bfd);
+       /* We're also done with the loadmap.  */
+       xfree (ldm);
+diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
+index 2f2c8b0..0f59535 100644
+--- a/gdb/solib-frv.c
++++ b/gdb/solib-frv.c
+@@ -31,6 +31,7 @@
+ #include "gdbcmd.h"
+ #include "elf/frv.h"
+ #include "exceptions.h"
++#include "gdb_bfd.h"
+ /* Flag which indicates whether internal debug messages should be printed.  */
+ static int solib_frv_debug;
+@@ -574,7 +575,7 @@ enable_break2 (void)
+       {
+         warning (_("Unable to determine dynamic linker loadmap address."));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+@@ -589,7 +590,7 @@ enable_break2 (void)
+         warning (_("Unable to load dynamic linker loadmap at address %s."),
+                  hex_string_custom (interp_loadmap_addr, 8));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+@@ -623,7 +624,7 @@ enable_break2 (void)
+         warning (_("Could not find symbol _dl_debug_addr "
+                    "in dynamic linker"));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+@@ -674,7 +675,7 @@ enable_break2 (void)
+                    "(at address %s) from dynamic linker"),
+                  hex_string_custom (addr + 8, 8));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+       addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
+@@ -686,13 +687,13 @@ enable_break2 (void)
+                    "(at address %s) from dynamic linker"),
+                  hex_string_custom (addr, 8));
+         enable_break_failure_warning ();
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return 0;
+       }
+       addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
+       /* We're done with the temporary bfd.  */
+-      bfd_close (tmp_bfd);
++      gdb_bfd_unref (tmp_bfd);
+       /* We're also done with the loadmap.  */
+       xfree (ldm);
+diff --git a/gdb/solib-pa64.c b/gdb/solib-pa64.c
+index 2b8d061..00ed8a5 100644
+--- a/gdb/solib-pa64.c
++++ b/gdb/solib-pa64.c
+@@ -362,7 +362,7 @@ manpage for methods to privately map shared library text."));
+        to find any magic formula to find it for Solaris (appears to
+        be trivial on GNU/Linux).  Therefore, we have to try an alternate
+        mechanism to find the dynamic linker's base address.  */
+-      tmp_bfd = bfd_openr (buf, gnutarget);
++      tmp_bfd = gdb_bfd_openr (buf, gnutarget);
+       if (tmp_bfd == NULL)
+       return;
+@@ -371,7 +371,7 @@ manpage for methods to privately map shared library text."));
+       {
+         warning (_("Unable to grok dynamic linker %s as an object file"),
+                  buf);
+-        bfd_close (tmp_bfd);
++        gdb_bfd_unref (tmp_bfd);
+         return;
+       }
+@@ -401,7 +401,7 @@ manpage for methods to privately map shared library text."));
+       }
+       /* We're done with the temporary bfd.  */
+-      bfd_close (tmp_bfd);
++      gdb_bfd_unref (tmp_bfd);
+     }
+ }
+diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
+index b5454e7..f62d96c 100644
+--- a/gdb/solib-spu.c
++++ b/gdb/solib-spu.c
+@@ -36,6 +36,7 @@
+ #include "breakpoint.h"
+ #include "gdbthread.h"
+ #include "exceptions.h"
++#include "gdb_bfd.h"
+ #include "spu-tdep.h"
+@@ -325,16 +326,16 @@ spu_bfd_fopen (char *name, CORE_ADDR addr)
+   CORE_ADDR *open_closure = xmalloc (sizeof (CORE_ADDR));
+   *open_closure = addr;
+-  nbfd = bfd_openr_iovec (xstrdup (name), "elf32-spu",
+-                          spu_bfd_iovec_open, open_closure,
+-                          spu_bfd_iovec_pread, spu_bfd_iovec_close,
+-                        spu_bfd_iovec_stat);
++  nbfd = gdb_bfd_openr_iovec (name, "elf32-spu",
++                            spu_bfd_iovec_open, open_closure,
++                            spu_bfd_iovec_pread, spu_bfd_iovec_close,
++                            spu_bfd_iovec_stat);
+   if (!nbfd)
+     return NULL;
+   if (!bfd_check_format (nbfd, bfd_object))
+     {
+-      bfd_close (nbfd);
++      gdb_bfd_unref (nbfd);
+       return NULL;
+     }
+diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
+index 307e483..76bd872 100644
+--- a/gdb/solib-svr4.c
++++ b/gdb/solib-svr4.c
+@@ -46,6 +46,7 @@
+ #include "exec.h"
+ #include "auxv.h"
+ #include "exceptions.h"
++#include "gdb_bfd.h"
+ static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
+ static int svr4_have_link_map_offsets (void);
+@@ -1558,9 +1559,11 @@ enable_break (struct svr4_info *info, int from_tty)
+       goto bkpt_at_symbol;
+       /* Now convert the TMP_BFD into a target.  That way target, as
+-         well as BFD operations can be used.  Note that closing the
+-         target will also close the underlying bfd.  */
++         well as BFD operations can be used.  */
+       tmp_bfd_target = target_bfd_reopen (tmp_bfd);
++      /* target_bfd_reopen acquired its own reference, so we can
++         release ours now.  */
++      gdb_bfd_unref (tmp_bfd);
+       /* On a running target, we can get the dynamic linker's base
+          address from the shared library table.  */
+@@ -1670,8 +1673,9 @@ enable_break (struct svr4_info *info, int from_tty)
+                                                      sym_addr,
+                                                      tmp_bfd_target);
+-      /* We're done with both the temporary bfd and target.  Remember,
+-         closing the target closes the underlying bfd.  */
++      /* We're done with both the temporary bfd and target.  Closing
++         the target closes the underlying bfd, because it holds the
++         only remaining reference.  */
+       target_close (tmp_bfd_target, 0);
+       if (sym_addr != 0)
+diff --git a/gdb/solib.c b/gdb/solib.c
+index 90439ba..73773f1 100644
+--- a/gdb/solib.c
++++ b/gdb/solib.c
+@@ -46,6 +46,7 @@
+ #include "solib.h"
+ #include "interps.h"
+ #include "filesystem.h"
++#include "gdb_bfd.h"
+ /* Architecture-specific operations.  */
+@@ -360,9 +361,9 @@ solib_find (char *in_pathname, int *fd)
+    it is used as file handle to open the file.  Throws an error if the file
+    could not be opened.  Handles both local and remote file access.
+-   PATHNAME must be malloc'ed by the caller.  If successful, the new BFD's
+-   name will point to it.  If unsuccessful, PATHNAME will be freed and the
+-   FD will be closed (unless FD was -1).  */
++   PATHNAME must be malloc'ed by the caller.  It will be freed by this
++   function.  If unsuccessful, the FD will be closed (unless FD was
++   -1).  */
+ bfd *
+ solib_bfd_fopen (char *pathname, int fd)
+@@ -376,7 +377,7 @@ solib_bfd_fopen (char *pathname, int fd)
+     }
+   else
+     {
+-      abfd = bfd_fopen (pathname, gnutarget, FOPEN_RB, fd);
++      abfd = gdb_bfd_fopen (pathname, gnutarget, FOPEN_RB, fd);
+       if (abfd)
+       bfd_set_cacheable (abfd, 1);
+@@ -389,6 +390,8 @@ solib_bfd_fopen (char *pathname, int fd)
+            pathname, bfd_errmsg (bfd_get_error ()));
+     }
++  xfree (pathname);
 +
-+gdb_breakpoint "break_here"
+   return abfd;
+ }
+@@ -420,17 +423,16 @@ solib_bfd_open (char *pathname)
+   /* Check bfd format.  */
+   if (!bfd_check_format (abfd, bfd_object))
+     {
+-      bfd_close (abfd);
+-      make_cleanup (xfree, found_pathname);
++      make_cleanup_bfd_unref (abfd);
+       error (_("`%s': not in executable format: %s"),
+-           found_pathname, bfd_errmsg (bfd_get_error ()));
++           bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
+     }
+   /* Check bfd arch.  */
+   b = gdbarch_bfd_arch_info (target_gdbarch);
+   if (!b->compatible (b, bfd_get_arch_info (abfd)))
+     warning (_("`%s': Shared library architecture %s is not compatible "
+-               "with target architecture %s."), found_pathname,
++               "with target architecture %s."), bfd_get_filename (abfd),
+              bfd_get_arch_info (abfd)->printable_name, b->printable_name);
+   return abfd;
+@@ -466,7 +468,7 @@ solib_map_sections (struct so_list *so)
+     return 0;
+   /* Leave bfd open, core_xfer_memory and "info files" need it.  */
+-  so->abfd = gdb_bfd_ref (abfd);
++  so->abfd = abfd;
+   /* copy full path name into so_name, so that later symbol_file_add
+      can find it.  */
+@@ -1233,7 +1235,7 @@ reload_shared_libraries_1 (int from_tty)
+       {
+         found_pathname = xstrdup (bfd_get_filename (abfd));
+         make_cleanup (xfree, found_pathname);
+-        gdb_bfd_close_or_warn (abfd);
++        gdb_bfd_unref (abfd);
+       }
+       /* If this shared library is no longer associated with its previous
+diff --git a/gdb/spu-linux-nat.c b/gdb/spu-linux-nat.c
+index 2dfec8c..999f1ab 100644
+--- a/gdb/spu-linux-nat.c
++++ b/gdb/spu-linux-nat.c
+@@ -315,16 +315,16 @@ spu_bfd_open (ULONGEST addr)
+   ULONGEST *open_closure = xmalloc (sizeof (ULONGEST));
+   *open_closure = addr;
+-  nbfd = bfd_openr_iovec (xstrdup ("<in-memory>"), "elf32-spu",
+-                        spu_bfd_iovec_open, open_closure,
+-                        spu_bfd_iovec_pread, spu_bfd_iovec_close,
+-                        spu_bfd_iovec_stat);
++  nbfd = gdb_bfd_openr_iovec ("<in-memory>", "elf32-spu",
++                            spu_bfd_iovec_open, open_closure,
++                            spu_bfd_iovec_pread, spu_bfd_iovec_close,
++                            spu_bfd_iovec_stat);
+   if (!nbfd)
+     return NULL;
+   if (!bfd_check_format (nbfd, bfd_object))
+     {
+-      bfd_close (nbfd);
++      gdb_bfd_unref (nbfd);
+       return NULL;
+     }
+@@ -374,8 +374,13 @@ spu_symbol_file_add_from_memory (int inferior_fd)
+   /* Open BFD representing SPE executable and read its symbols.  */
+   nbfd = spu_bfd_open (addr);
+   if (nbfd)
+-    symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
+-                              NULL, 0, NULL);
++    {
++      struct cleanup *cleanup = make_cleanup_bfd_unref (nbfd);
 +
-+gdb_continue_to_breakpoint "break_here"
++      symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
++                              NULL, 0, NULL);
++      do_cleanups (cleanup);
++    }
+ }
+diff --git a/gdb/stack.c b/gdb/stack.c
+index 35d379d..04aab5e 100644
+--- a/gdb/stack.c
++++ b/gdb/stack.c
+@@ -509,6 +509,10 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
+   stb = mem_fileopen ();
+   old_chain = make_cleanup_ui_file_delete (stb);
++  /* Frame may be needed for check_typedef of TYPE_DYNAMIC.  */
++  make_cleanup_restore_selected_frame ();
++  select_frame (frame);
 +
-+gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array"
-+gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array"
+   if (func)
+     {
+       struct block *b = SYMBOL_BLOCK_VALUE (func);
+diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
+index e80fd25..2e53be0 100644
+--- a/gdb/symfile-mem.c
++++ b/gdb/symfile-mem.c
+@@ -54,6 +54,7 @@
+ #include "observer.h"
+ #include "auxv.h"
+ #include "elf/common.h"
++#include "gdb_bfd.h"
+ /* Verify parameters of target_read_memory_bfd and target_read_memory are
+    compatible.  */
+@@ -100,23 +101,24 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name,
+   if (nbfd == NULL)
+     error (_("Failed to read a valid object file image from memory."));
++  gdb_bfd_ref (nbfd);
+   if (name == NULL)
+-    nbfd->filename = xstrdup ("shared object read from target memory");
++    nbfd->filename = "shared object read from target memory";
+   else
+-    nbfd->filename = name;
+-
+-  if (!bfd_check_format (nbfd, bfd_object))
+     {
+-      /* FIXME: should be checking for errors from bfd_close (for one thing,
+-         on error it does not free all the storage associated with the
+-         bfd).  */
+-      bfd_close (nbfd);
+-      error (_("Got object file from memory but can't read symbols: %s."),
+-           bfd_errmsg (bfd_get_error ()));
++      nbfd->filename = name;
++      gdb_bfd_stash_filename (nbfd);
++      xfree (name);
+     }
++  cleanup = make_cleanup_bfd_unref (nbfd);
 +
-+gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array"
-+gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array"
++  if (!bfd_check_format (nbfd, bfd_object))
++    error (_("Got object file from memory but can't read symbols: %s."),
++         bfd_errmsg (bfd_get_error ()));
 +
-+gdb_test "p (*array)\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
-+gdb_test "p (*array)\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
-+gdb_test "p (*array)\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
-+gdb_test "p (*array)\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
+   sai = alloc_section_addr_info (bfd_count_sections (nbfd));
+-  cleanup = make_cleanup (xfree, sai);
++  make_cleanup (xfree, sai);
+   i = 0;
+   for (sec = nbfd->sections; sec != NULL; sec = sec->next)
+     if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
+diff --git a/gdb/symfile.c b/gdb/symfile.c
+index 01252e2..95ed480 100644
+--- a/gdb/symfile.c
++++ b/gdb/symfile.c
+@@ -55,6 +55,7 @@
+ #include "solib.h"
+ #include "remote.h"
+ #include "stack.h"
++#include "gdb_bfd.h"
+ #include <sys/types.h>
+ #include <fcntl.h>
+@@ -1036,7 +1037,7 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
+    loaded file.
+    ABFD is a BFD already open on the file, as from symfile_bfd_open.
+-   This BFD will be closed on error, and is always consumed by this function.
++   A new reference is acquired by this function.
+    ADD_FLAGS encodes verbosity, whether this is main symbol file or
+    extra, such as dynamically loaded code, and what to do with breakpoins.
+@@ -1060,7 +1061,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
+                                        int flags, struct objfile *parent)
+ {
+   struct objfile *objfile;
+-  struct cleanup *my_cleanups;
+   const char *name = bfd_get_filename (abfd);
+   const int from_tty = add_flags & SYMFILE_VERBOSE;
+   const int mainline = add_flags & SYMFILE_MAINLINE;
+@@ -1074,8 +1074,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
+       add_flags &= ~SYMFILE_NO_READ;
+     }
+-  my_cleanups = make_cleanup_bfd_close (abfd);
+-
+   /* Give user a chance to burp if we'd be
+      interactively wiping out any existing symbols.  */
+@@ -1086,7 +1084,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
+     error (_("Not confirmed."));
+   objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0));
+-  discard_cleanups (my_cleanups);
+   if (parent)
+     add_separate_debug_objfile (objfile, parent);
+@@ -1207,8 +1204,13 @@ struct objfile *
+ symbol_file_add (char *name, int add_flags, struct section_addr_info *addrs,
+                int flags)
+ {
+-  return symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs,
+-                                   flags, NULL);
++  bfd *bfd = symfile_bfd_open (name);
++  struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
++  struct objfile *objf;
 +
-+gdb_continue_to_breakpoint "break_here"
++  objf = symbol_file_add_from_bfd (bfd, add_flags, addrs, flags, NULL);
++  do_cleanups (cleanup);
++  return objf;
+ }
+@@ -1350,7 +1352,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
+   if (filename_cmp (name, parent_objfile->name) == 0)
+     return 0;
+-  abfd = bfd_open_maybe_remote (name);
++  abfd = gdb_bfd_open_maybe_remote (name);
+   if (!abfd)
+     return 0;
+@@ -1372,7 +1374,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
+       if (abfd_stat.st_dev == parent_stat.st_dev
+         && abfd_stat.st_ino == parent_stat.st_ino)
+       {
+-        bfd_close (abfd);
++        gdb_bfd_unref (abfd);
+         return 0;
+       }
+       verified_as_different = 1;
+@@ -1382,7 +1384,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
+   file_crc_p = get_file_crc (abfd, &file_crc);
+-  bfd_close (abfd);
++  gdb_bfd_unref (abfd);
+   if (!file_crc_p)
+     return 0;
+@@ -1690,15 +1692,20 @@ set_initial_language (void)
+ }
+ /* If NAME is a remote name open the file using remote protocol, otherwise
+-   open it normally.  */
++   open it normally.  Returns a new reference to the BFD.  On error,
++   returns NULL with the BFD error set.  */
+ bfd *
+-bfd_open_maybe_remote (const char *name)
++gdb_bfd_open_maybe_remote (const char *name)
+ {
++  bfd *result;
 +
-+gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array"
-+gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array"
+   if (remote_filename_p (name))
+-    return remote_bfd_open (name, gnutarget);
++    result = remote_bfd_open (name, gnutarget);
+   else
+-    return bfd_openr (name, gnutarget);
++    result = gdb_bfd_openr (name, gnutarget);
 +
-+gdb_test "whatis *array" "type = char \\\[78\\\]" "second: whatis *array"
-+gdb_test "ptype *array" "type = char \\\[78\\\]" "second: ptype *array"
-diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
++  return result;
+ }
+@@ -1716,19 +1723,14 @@ symfile_bfd_open (char *name)
+   if (remote_filename_p (name))
+     {
+-      name = xstrdup (name);
+       sym_bfd = remote_bfd_open (name, gnutarget);
+       if (!sym_bfd)
+-      {
+-        make_cleanup (xfree, name);
+-        error (_("`%s': can't open to read symbols: %s."), name,
+-               bfd_errmsg (bfd_get_error ()));
+-      }
++      error (_("`%s': can't open to read symbols: %s."), name,
++             bfd_errmsg (bfd_get_error ()));
+       if (!bfd_check_format (sym_bfd, bfd_object))
+       {
+-        bfd_close (sym_bfd);
+-        make_cleanup (xfree, name);
++        make_cleanup_bfd_unref (sym_bfd);
+         error (_("`%s': can't read symbols: %s."), name,
+                bfd_errmsg (bfd_get_error ()));
+       }
+@@ -1757,12 +1759,11 @@ symfile_bfd_open (char *name)
+       perror_with_name (name);
+     }
+-  /* Free 1st new malloc'd copy, but keep the 2nd malloc'd copy in
+-     bfd.  It'll be freed in free_objfile().  */
+   xfree (name);
+   name = absolute_name;
++  make_cleanup (xfree, name);
+-  sym_bfd = bfd_fopen (name, gnutarget, FOPEN_RB, desc);
++  sym_bfd = gdb_bfd_fopen (name, gnutarget, FOPEN_RB, desc);
+   if (!sym_bfd)
+     {
+       make_cleanup (xfree, name);
+@@ -1773,18 +1774,11 @@ symfile_bfd_open (char *name)
+   if (!bfd_check_format (sym_bfd, bfd_object))
+     {
+-      /* FIXME: should be checking for errors from bfd_close (for one
+-         thing, on error it does not free all the storage associated
+-         with the bfd).  */
+-      bfd_close (sym_bfd);    /* This also closes desc.  */
+-      make_cleanup (xfree, name);
++      make_cleanup_bfd_unref (sym_bfd);
+       error (_("`%s': can't read symbols: %s."), name,
+            bfd_errmsg (bfd_get_error ()));
+     }
+-  /* bfd_usrdata exists for applications and libbfd must not touch it.  */
+-  gdb_assert (bfd_usrdata (sym_bfd) == NULL);
+-
+   return sym_bfd;
+ }
+@@ -2109,17 +2103,14 @@ generic_load (char *args, int from_tty)
+     }
+   /* Open the file for loading.  */
+-  loadfile_bfd = bfd_openr (filename, gnutarget);
++  loadfile_bfd = gdb_bfd_openr (filename, gnutarget);
+   if (loadfile_bfd == NULL)
+     {
+       perror_with_name (filename);
+       return;
+     }
+-  /* FIXME: should be checking for errors from bfd_close (for one thing,
+-     on error it does not free all the storage associated with the
+-     bfd).  */
+-  make_cleanup_bfd_close (loadfile_bfd);
++  make_cleanup_bfd_unref (loadfile_bfd);
+   if (!bfd_check_format (loadfile_bfd, bfd_object))
+     {
+@@ -2518,15 +2509,18 @@ reread_symbols (void)
+         /* Clean up any state BFD has sitting around.  We don't need
+            to close the descriptor but BFD lacks a way of closing the
+            BFD without closing the descriptor.  */
+-        obfd_filename = bfd_get_filename (objfile->obfd);
+-        if (!bfd_close (objfile->obfd))
+-          error (_("Can't close BFD for %s: %s"), objfile->name,
+-                 bfd_errmsg (bfd_get_error ()));
+-        objfile->obfd = bfd_open_maybe_remote (obfd_filename);
++        {
++          struct bfd *obfd = objfile->obfd;
++
++          obfd_filename = bfd_get_filename (objfile->obfd);
++          /* Open the new BFD before freeing the old one, so that
++             the filename remains live.  */
++          objfile->obfd = gdb_bfd_open_maybe_remote (obfd_filename);
++          gdb_bfd_unref (obfd);
++        }
++
+         if (objfile->obfd == NULL)
+           error (_("Can't open %s to read symbols."), objfile->name);
+-        else
+-          objfile->obfd = gdb_bfd_ref (objfile->obfd);
+         /* bfd_openr sets cacheable to true, which is what we want.  */
+         if (!bfd_check_format (objfile->obfd, bfd_object))
+           error (_("Can't read symbols from %s: %s."), objfile->name,
+diff --git a/gdb/symfile.h b/gdb/symfile.h
+index aca7359..184a83e 100644
+--- a/gdb/symfile.h
++++ b/gdb/symfile.h
+@@ -553,7 +553,7 @@ extern void find_lowest_section (bfd *, asection *, void *);
+ extern bfd *symfile_bfd_open (char *);
+-extern bfd *bfd_open_maybe_remote (const char *);
++extern bfd *gdb_bfd_open_maybe_remote (const char *);
+ extern int get_section_index (struct objfile *, char *);
+diff --git a/gdb/testsuite/gdb.ada/packed_array.exp b/gdb/testsuite/gdb.ada/packed_array.exp
+index 678639c..47a2202 100644
+--- a/gdb/testsuite/gdb.ada/packed_array.exp
++++ b/gdb/testsuite/gdb.ada/packed_array.exp
+@@ -60,5 +60,11 @@ gdb_test_multiple "$test" "$test" {
+         # are.  Observed with (FSF GNU Ada 4.5.3 20110124).
+         xfail $test
+     }
++    -re "= \\(\\)\[\r\n\]+$gdb_prompt $" {
++      # archer-jankratochvil-vla resolves it as a dynamic type resolved as an
++      # empty array [0..-1].
++      # DW_AT_upper_bound : (DW_OP_fbreg: -48; DW_OP_deref)
++        xfail $test
++    }
+ }
+diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
 new file mode 100644
-index 0000000..66f7a39
+index 0000000..83faaf6
 --- /dev/null
-+++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
-@@ -0,0 +1,455 @@
-+      .file   "x86_64-vla-typedef.c"
++++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer-foo.S
+@@ -0,0 +1,457 @@
++      .file   "x86_64-vla-pointer.c"
 +      .section        .debug_abbrev,"",@progbits
 +.Ldebug_abbrev0:
 +      .section        .debug_info,"",@progbits
@@ -11677,7 +9818,7 @@ index 0000000..66f7a39
 +      .type   foo, @function
 +foo:
 +.LFB2:
-+      .file 1 "x86_64-vla-typedef.c"
++      .file 1 "x86_64-vla-pointer.c"
 +      .loc 1 22 0
 +      pushq   %rbp
 +.LCFI0:
@@ -11833,6 +9974,7 @@ index 0000000..66f7a39
 +      .quad   0x0
 +      .quad   0x0
 +      .section        .debug_info
++.Ldebug_relative:
 +      .long   .Ldebug_end - .Ldebug_start
 +.Ldebug_start:
 +      .value  0x2
@@ -11855,27 +9997,25 @@ index 0000000..66f7a39
 +      .quad   .LFB2
 +      .quad   .LFE2
 +      .long   .LLST0
-+      .long   0x83
++      .long   .Ltype_int - .Ldebug_relative
 +      .uleb128 0x3
 +      .long   .LASF5
 +      .byte   0x1
 +      .byte   0x15
-+      .long   0x83
++      .long   .Ltype_int - .Ldebug_relative
 +      .byte   0x2
 +      .byte   0x91
 +      .sleb128 -52
-+.Ltag_typedef:
++.Ltag_pointer:
 +      .uleb128 0x4
-+      .long   .LASF6
-+      .byte   0x1
-+      .byte   0x17
-+      .long   .Ltag_array_type - .debug_info
++      .byte   0x8     /* DW_AT_byte_size */
++      .long   .Ltag_array_type - .debug_info  /* DW_AT_type */
 +      .uleb128 0x5    /* Abbrev Number: 5 (DW_TAG_variable) */
 +      .long   .LASF0
 +      .byte   0x1
 +      .byte   0x18
 +#if 1
-+      .long   .Ltag_typedef - .debug_info
++      .long   .Ltag_pointer - .debug_info
 +#else
 +      /* Debugging only: Skip the typedef indirection.  */
 +      .long   .Ltag_array_type - .debug_info
@@ -11894,35 +10034,42 @@ index 0000000..66f7a39
 +      .string "i"
 +      .byte   0x1
 +      .byte   0x19
-+      .long   0x83
++      .long   .Ltype_int - .Ldebug_relative
 +      .byte   0x2
 +      .byte   0x91
 +      .sleb128 -20
 +      .byte   0x0
++.Ltype_int:
 +      .uleb128 0x7
 +      .byte   0x4
 +      .byte   0x5
 +      .string "int"
 +.Ltag_array_type:
 +      .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
-+      .long   0xa0 + (2f - 1f)        /* DW_AT_type: DW_FORM_ref4 */
-+      .long   0x9d + (2f - 1f)        /* DW_AT_sibling: DW_FORM_ref4 */
++      .long   .Ltype_char - .Ldebug_relative
++      .long   .Ltype_ulong - .Ldebug_relative /* DW_AT_sibling: DW_FORM_ref4 */
 +1:    /* DW_AT_data_location: DW_FORM_block1: start */
 +      .byte   2f - 3f /* length */
 +3:
 +      .byte   0x97    /* DW_OP_push_object_address */
++#if 1
 +      .byte   0x6     /* DW_OP_deref */
++#else
++      .byte   0x96    /* DW_OP_nop */
++#endif
 +2:    /* DW_AT_data_location: DW_FORM_block1: end */
 +      .uleb128 0x9
-+      .long   0x9d + (2b - 1b)        /* DW_AT_type: DW_FORM_ref4 */
++      .long   .Ltype_char - .Ldebug_relative  /* DW_AT_type: DW_FORM_ref4 */
 +      .byte   0x3
 +      .byte   0x91
 +      .sleb128 -40
 +      .byte   0x6
 +      .byte   0x0
++.Ltype_ulong:
 +      .uleb128 0xa
 +      .byte   0x8
 +      .byte   0x7
++.Ltype_char:
 +      .uleb128 0xb
 +      .byte   0x1
 +      .byte   0x6
@@ -11987,14 +10134,10 @@ index 0000000..66f7a39
 +      .uleb128 0xa
 +      .byte   0x0
 +      .byte   0x0
-+      .uleb128 0x4
-+      .uleb128 0x16
++      .uleb128 0x4    /* .Ltag_pointer abbrev */
++      .uleb128 0x0f   /* DW_TAG_pointer_type */
 +      .byte   0x0
-+      .uleb128 0x3
-+      .uleb128 0xe
-+      .uleb128 0x3a
-+      .uleb128 0xb
-+      .uleb128 0x3b
++      .uleb128 0x0b
 +      .uleb128 0xb
 +      .uleb128 0x49
 +      .uleb128 0x13
@@ -12075,253 +10218,59 @@ index 0000000..66f7a39
 +      .byte   0x0
 +      .uleb128 0xb
 +      .uleb128 0xb
-+      .uleb128 0x3e
-+      .uleb128 0xb
-+      .uleb128 0x3
-+      .uleb128 0xe
-+      .byte   0x0
-+      .byte   0x0
-+      .byte   0x0
-+      .section        .debug_pubnames,"",@progbits
-+      .long   0x16
-+      .value  0x2
-+      .long   .Ldebug_info0
-+      .long   0xa8
-+      .long   0x2d
-+      .string "foo"
-+      .long   0x0
-+      .section        .debug_aranges,"",@progbits
-+      .long   0x2c
-+      .value  0x2
-+      .long   .Ldebug_info0
-+      .byte   0x8
-+      .byte   0x0
-+      .value  0x0
-+      .value  0x0
-+      .quad   .Ltext0
-+      .quad   .Letext0-.Ltext0
-+      .quad   0x0
-+      .quad   0x0
-+      .section        .debug_str,"MS",@progbits,1
-+.LASF0:
-+      .string "array"
-+.LASF5:
-+      .string "size"
-+.LASF3:
-+      .string "x86_64-vla-typedef.c"
-+.LASF6:
-+      .string "array_t"
-+.LASF1:
-+      .string "char"
-+.LASF4:
-+      .string "gdb.arch"
-+.LASF2:
-+      .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
-+      .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
-+      .section        .note.GNU-stack,"",@progbits
-diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
-new file mode 100644
-index 0000000..b809c4e
---- /dev/null
-+++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
-@@ -0,0 +1,43 @@
-+/* This testcase is part of GDB, the GNU debugger.
-+
-+   Copyright 2008 Free Software Foundation, Inc.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-+
-+#if 0
-+
-+void
-+foo (int size)
-+{
-+  typedef char array_t[size];
-+  array_t array;
-+  int i;
-+
-+  for (i = 0; i < size; i++)
-+    array[i] = i;
-+
-+  array[0] = 0;       /* break-here */
-+}
-+
-+#else
-+
-+int
-+main (void)
-+{
-+  foo (26);
-+  foo (78);
-+  return 0;
-+}
-+
-+#endif
-diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
-new file mode 100644
-index 0000000..b05411e
---- /dev/null
-+++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
-@@ -0,0 +1,64 @@
-+# Copyright 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
-+
-+if ![istarget "x86_64-*-*"] then {
-+    verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
-+    return
-+}
-+
-+set testfile x86_64-vla-typedef
-+set srcasmfile ${testfile}-foo.S
-+set srcfile ${testfile}.c
-+set binfile ${objdir}/${subdir}/${testfile}
-+set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
-+    untested "Couldn't compile test program"
-+    return -1
-+}
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
-+    untested "Couldn't compile test program"
-+    return -1
-+}
-+
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+
-+if ![runto_main] {
-+    untested x86_64-vla-typedef
-+    return -1
-+}
-+
-+gdb_breakpoint "break_here"
-+
-+gdb_continue_to_breakpoint "break_here"
-+
-+gdb_test "whatis array" "type = array_t" "first: whatis array"
-+
-+gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
-+
-+gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
-+gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
-+gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
-+gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
-+
-+gdb_continue_to_breakpoint "break_here"
-+
-+gdb_test "whatis array" "type = array_t" "second: whatis array"
-+
-+gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
-diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
-index ecc3289..f79ad40 100644
---- a/gdb/testsuite/gdb.base/arrayidx.c
-+++ b/gdb/testsuite/gdb.base/arrayidx.c
-@@ -17,6 +17,13 @@
- int array[] = {1, 2, 3, 4};
-+#ifdef __GNUC__
-+struct
-+  {
-+    int a[0];
-+  } unbound;
-+#endif
-+
- int
- main (void)
- {
-diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
-index 3a33618..f2e11dd 100644
---- a/gdb/testsuite/gdb.base/arrayidx.exp
-+++ b/gdb/testsuite/gdb.base/arrayidx.exp
-@@ -57,4 +57,12 @@ gdb_test "print array" \
-          "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
-          "Print array with array-indexes on"
--
-+set test "p unbound.a == &unbound.a\[0\]"
-+gdb_test_multiple $test $test {
-+    -re " = 1\r\n$gdb_prompt $" {
-+      pass $test
-+    }
-+    -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
-+      unsupported "$test (no GCC)"
-+    }
-+}
-diff --git a/gdb/testsuite/gdb.base/gnu-ifunc-lib.c b/gdb/testsuite/gdb.base/gnu-ifunc-lib.c
-new file mode 100644
-index 0000000..680530a
---- /dev/null
-+++ b/gdb/testsuite/gdb.base/gnu-ifunc-lib.c
-@@ -0,0 +1,33 @@
-+/* This testcase is part of GDB, the GNU debugger.
-+
-+   Copyright 2009, 2010 Free Software Foundation, Inc.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-+
-+extern volatile int gnu_ifunc_initialized;
-+extern int init_stub (int arg);
-+extern int final (int arg);
-+
-+typedef int (*final_t) (int arg);
-+
-+asm (".type gnu_ifunc, @gnu_indirect_function");
-+
-+final_t
-+gnu_ifunc (void)
-+{
-+  if (! gnu_ifunc_initialized)
-+    return init_stub;
-+  else
-+    return final;
-+}
-diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.c b/gdb/testsuite/gdb.base/gnu-ifunc.c
++      .uleb128 0x3e
++      .uleb128 0xb
++      .uleb128 0x3
++      .uleb128 0xe
++      .byte   0x0
++      .byte   0x0
++      .byte   0x0
++      .section        .debug_pubnames,"",@progbits
++      .long   0x16
++      .value  0x2
++      .long   .Ldebug_info0
++      .long   0xa8
++      .long   0x2d
++      .string "foo"
++      .long   0x0
++      .section        .debug_aranges,"",@progbits
++      .long   0x2c
++      .value  0x2
++      .long   .Ldebug_info0
++      .byte   0x8
++      .byte   0x0
++      .value  0x0
++      .value  0x0
++      .quad   .Ltext0
++      .quad   .Letext0-.Ltext0
++      .quad   0x0
++      .quad   0x0
++      .section        .debug_str,"MS",@progbits,1
++.LASF0:
++      .string "array"
++.LASF5:
++      .string "size"
++.LASF3:
++      .string "x86_64-vla-pointer.c"
++.LASF6:
++      .string "array_t"
++.LASF1:
++      .string "char"
++.LASF4:
++      .string "gdb.arch"
++.LASF2:
++      .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
++      .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
++      .section        .note.GNU-stack,"",@progbits
+diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
 new file mode 100644
-index 0000000..106271f
+index 0000000..fe2c8f7
 --- /dev/null
-+++ b/gdb/testsuite/gdb.base/gnu-ifunc.c
-@@ -0,0 +1,61 @@
++++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
+@@ -0,0 +1,43 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
-+   Copyright 2009, 2010 Free Software Foundation, Inc.
++   Copyright 2009 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
@@ -12336,198 +10285,38 @@ index 0000000..106271f
 +   You should have received a copy of the GNU General Public License
 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+#include <assert.h>
-+
-+int
-+init_stub (int arg)
-+{
-+  return 0;
-+}
++#if 0
 +
-+int
-+final (int arg)
++void
++foo (int size)
 +{
-+  return arg + 1;
-+}
-+
-+/* Make differentiation of how the gnu_ifunc call resolves before and after
-+   calling gnu_ifunc_pre.  This ensures the resolved function address is not
-+   being cached anywhere for the debugging purposes.  */
-+
-+volatile int gnu_ifunc_initialized;
++  typedef char array_t[size];
++  array_t array;
++  int i;
 +
-+static void
-+gnu_ifunc_pre (void)
-+{
-+  assert (!gnu_ifunc_initialized);
++  for (i = 0; i < size; i++)
++    array[i] = i;
 +
-+  gnu_ifunc_initialized = 1;
++  array[0] = 0;       /* break-here */
 +}
 +
-+extern int gnu_ifunc (int arg);
++#else
 +
 +int
 +main (void)
 +{
-+  int i;
-+
-+  gnu_ifunc_pre ();
-+  
-+  i = gnu_ifunc (1);  /* break-at-call */
-+  assert (i == 2);
-+
-+  gnu_ifunc (2);      /* break-at-nextcall */
-+
-+  return 0;   /* break-at-exit */
-+}
-diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp
-new file mode 100644
-index 0000000..8ecf558
---- /dev/null
-+++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp
-@@ -0,0 +1,110 @@
-+# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+if {[skip_shlib_tests]} {
-+    return 0
-+}
-+
-+set testfile "gnu-ifunc"
-+set srcfile ${testfile}.c
-+set binfile ${objdir}/${subdir}/${testfile}
-+
-+set libfile "${testfile}-lib"
-+set libsrc ${libfile}.c
-+set lib_so ${objdir}/${subdir}/${libfile}.so
-+
-+# We need DWARF for the "final" function as we "step" into the function and GDB
-+# would step-over the "final" function if there would be no line number debug
-+# information (DWARF) available.
-+#
-+# We must not have DWARF for the "gnu_ifunc" function as DWARF has no way to
-+# express the gnu-ifunc type and it would be considered as a regular function
-+# due to DWARF by GDB.  In ELF gnu-ifunc is expressed by the STT_GNU_IFUNC type.
-+#
-+# Both functions need to be in the same shared library file but
-+# gdb_compile_shlib has no way to specify source-specific compilation options.
-+#
-+# Therefore $libfile contains only the gnu-ifunc function with no DWARF
-+# referencing all the other parts from the main executable with DWARF.
-+
-+set lib_opts {}
-+set exec_opts [list debug shlib=$lib_so]
-+
-+if [get_compiler_info ${binfile}] {
-+    return -1
-+}
-+
-+if { [gdb_compile_shlib ${srcdir}/${subdir}/$libsrc $lib_so $lib_opts] != ""
-+     || [gdb_compile ${srcdir}/${subdir}/$srcfile $binfile executable $exec_opts] != ""} {
-+    untested "Could not compile either $libsrc or $srcfile."
-+    return -1
-+}
-+
-+# Start with a fresh gdb.
-+
-+clean_restart $testfile
-+gdb_load_shlibs ${lib_so}
-+
-+if ![runto_main] then {
-+    fail "Can't run to main"
-+    return 1;
-+}
-+
-+# The "if" condition is artifical to test regression of a former patch.
-+gdb_breakpoint "[gdb_get_line_number "break-at-nextcall"] if i && gnu_ifunc (i) != 42"
-+
-+gdb_breakpoint [gdb_get_line_number "break-at-call"]
-+gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*"
-+
-+# Test GDB will automatically indirect the call.
-+
-+gdb_test "p gnu_ifunc (3)" " = 4"
-+
-+# Test GDB will skip the gnu_ifunc resolver on first call.
-+
-+gdb_test "step" "\r\nfinal .*"
-+
-+# Test GDB will not break before the final chosen implementation.
-+
-+# Also test a former patch regression:
-+# Continuing.
-+# Error in testing breakpoint condition:
-+# Attempt to take address of value not located in memory.
-+# 
-+# Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33
-+
-+gdb_test "continue" "Continuing.\r\n\r\nBreakpoint .* (at|in) .*break-at-nextcall.*" \
-+       "continue to break-at-nextcall"
-+
-+gdb_breakpoint "gnu_ifunc"
-+
-+gdb_continue_to_breakpoint "nextcall gnu_ifunc"
-+
-+gdb_test "frame" "#0 +(0x\[0-9a-f\]+ in +)?final \\(.*" "nextcall gnu_ifunc skipped"
-+
-+
-+# Check any commands not doing an inferior call still compute with address of
-+# the gnu-ifunc resolver.
-+
-+gdb_test "p gnu_ifunc" " = {<text gnu-indirect-function variable, no debug info>} 0x\[0-9a-f\]+ <gnu_ifunc>" "p gnu_ifunc executing"
-+gdb_test "info sym gnu_ifunc" "gnu_ifunc in section .*" "info sym gnu_ifunc executing"
-+
-+set test "info addr gnu_ifunc"
-+gdb_test_multiple $test $test {
-+    -re "Symbol \"gnu_ifunc\" is at (0x\[0-9a-f\]+) in .*$gdb_prompt $" {
-+      pass $test
-+    }
++  foo (26);
++  foo (78);
++  return 0;
 +}
-+gdb_test "info sym $expect_out(1,string)" "gnu_ifunc in section .*" "info sym <gnu_ifunc-address>"
-diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.c b/gdb/testsuite/gdb.base/internal-var-field-address.c
-new file mode 100644
-index 0000000..eeb7b85
---- /dev/null
-+++ b/gdb/testsuite/gdb.base/internal-var-field-address.c
-@@ -0,0 +1,20 @@
-+/* This testcase is part of GDB, the GNU debugger.
-+
-+   Copyright 2009 Free Software Foundation, Inc.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+struct {
-+  int field;
-+} staticstruct = { 1 };
-diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.exp b/gdb/testsuite/gdb.base/internal-var-field-address.exp
++#endif
+diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
 new file mode 100644
-index 0000000..6d82e73
+index 0000000..d243cf1
 --- /dev/null
-+++ b/gdb/testsuite/gdb.base/internal-var-field-address.exp
-@@ -0,0 +1,26 @@
++++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
+@@ -0,0 +1,66 @@
 +# Copyright 2009 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
@@ -12540,177 +10329,527 @@ index 0000000..6d82e73
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
 +#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+set test internal-var-field-address
-+set binfile ${test}.x
-+if  { [gdb_compile "${srcdir}/${subdir}/${test}.c" "${objdir}/${subdir}/${binfile}" object {debug}] != "" } {
-+    untested "Couldn't compile test program"
-+    return -1
-+}
-+
-+clean_restart $binfile
-+
-+gdb_test {set $varstruct = staticstruct}
-+gdb_test {p $varstruct.field} " = 1"
-diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
-new file mode 100644
-index 0000000..c5d5ee0
---- /dev/null
-+++ b/gdb/testsuite/gdb.base/vla-overflow.c
-@@ -0,0 +1,30 @@
-+/* This testcase is part of GDB, the GNU debugger.
-+
-+   Copyright 2008 Free Software Foundation, Inc.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-+
-+#include <stdlib.h>
-+
-+int
-+main (int argc, char **argv)
-+{
-+  int array[argc];
-+
-+  array[0] = array[0];
-+
-+  abort ();
-+
-+  return 0;
-+}
-diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
-new file mode 100644
-index 0000000..24a608f
---- /dev/null
-+++ b/gdb/testsuite/gdb.base/vla-overflow.exp
-@@ -0,0 +1,109 @@
-+# Copyright 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+# We could crash in:
-+# #0  block_linkage_function (bl=0x0) at ../../gdb/block.c:69
-+# #1  in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
-+#   97          framefunc = block_linkage_function (get_frame_block (frame, NULL));
-+# #2  in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
-+# #3  in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
-+# #4  dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
-+# #5  in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
-+# #6  in create_array_type (...) at ../../gdb/gdbtypes.c:840
-+# ...
-+# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
-+# ...
-+# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+set testfile vla-overflow
-+set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
++if ![istarget "x86_64-*-*"] then {
++    verbose "Skipping over gdb.arch/x86_64-vla-pointer.exp test made only for x86_64."
++    return
++}
++
++set testfile x86_64-vla-pointer
++set srcasmfile ${testfile}-foo.S
 +set srcfile ${testfile}.c
 +set binfile ${objdir}/${subdir}/${testfile}
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
++set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
++if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
++    untested "Couldn't compile test program"
++    return -1
++}
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
 +    untested "Couldn't compile test program"
 +    return -1
 +}
-+
-+set f [open "|getconf PAGESIZE" "r"]
-+gets $f pagesize
-+close $f
 +
 +gdb_exit
 +gdb_start
 +gdb_reinitialize_dir $srcdir/$subdir
 +gdb_load ${binfile}
 +
-+set pid_of_gdb [exp_pid -i [board_info host fileid]]
-+
-+if { [runto_main] < 0 } {
-+    untested vla-overflow
++if ![runto_main] {
++    untested x86_64-vla-pointer
 +    return -1
 +}
 +
-+# Get the GDB memory size when we stay at main.
-+
-+proc memory_v_pages_get {} {
-+    global pid_of_gdb pagesize
-+    set fd [open "/proc/$pid_of_gdb/statm"]
-+    gets $fd line
-+    close $fd
-+    # number of pages of virtual memory
-+    scan $line "%d" drs
-+    return $drs
-+}
-+
-+set pages_found [memory_v_pages_get]
-+
-+# s390x with glibc-debuginfo.s390x installed used approx. 16MB.
-+set mb_reserve 40
-+verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
-+set kb_found [expr $pages_found * $pagesize / 1024]
-+set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
-+verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
-+
-+# Create the ulimit wrapper.
-+set f [open $shfile "w"]
-+puts $f "#! /bin/sh"
-+puts $f "ulimit -v $kb_permit"
-+puts $f "exec $GDB \"\$@\""
-+close $f
-+remote_exec host "chmod +x $shfile"
-+
-+gdb_exit
-+set GDBold $GDB
-+set GDB "$shfile"
-+gdb_start
-+set GDB $GDBold
-+
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+
-+set pid_of_gdb [exp_pid -i [board_info host fileid]]
++gdb_breakpoint "break_here"
 +
-+# Check the size again after the second run.
-+# We must not stop in main as it would cache `array' and never crash later.
++gdb_continue_to_breakpoint "break_here"
 +
-+gdb_run_cmd
++gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array"
++gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array"
 +
-+verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
++gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array"
++gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array"
 +
-+gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
++gdb_test "p (*array)\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
++gdb_test "p (*array)\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
++gdb_test "p (*array)\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
++gdb_test "p (*array)\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
 +
-+verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
++gdb_continue_to_breakpoint "break_here"
 +
-+# `abort' can get expressed as `*__GI_abort'.
-+gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
++gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array"
++gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array"
 +
-+verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
-diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
++gdb_test "whatis *array" "type = char \\\[78\\\]" "second: whatis *array"
++gdb_test "ptype *array" "type = char \\\[78\\\]" "second: ptype *array"
+diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
+new file mode 100644
+index 0000000..66f7a39
+--- /dev/null
++++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef-foo.S
+@@ -0,0 +1,455 @@
++      .file   "x86_64-vla-typedef.c"
++      .section        .debug_abbrev,"",@progbits
++.Ldebug_abbrev0:
++      .section        .debug_info,"",@progbits
++.Ldebug_info0:
++      .section        .debug_line,"",@progbits
++.Ldebug_line0:
++      .text
++.Ltext0:
++.globl foo
++      .type   foo, @function
++foo:
++.LFB2:
++      .file 1 "x86_64-vla-typedef.c"
++      .loc 1 22 0
++      pushq   %rbp
++.LCFI0:
++      movq    %rsp, %rbp
++.LCFI1:
++      subq    $64, %rsp
++.LCFI2:
++      movl    %edi, -36(%rbp)
++      .loc 1 22 0
++      movq    %rsp, %rax
++      movq    %rax, -48(%rbp)
++      .loc 1 23 0
++      movl    -36(%rbp), %edx
++      movslq  %edx,%rax
++      subq    $1, %rax
++      movq    %rax, -24(%rbp)
++      .loc 1 24 0
++      movslq  %edx,%rax
++      addq    $15, %rax
++      addq    $15, %rax
++      shrq    $4, %rax
++      salq    $4, %rax
++      subq    %rax, %rsp
++      movq    %rsp, -56(%rbp)
++      movq    -56(%rbp), %rax
++      addq    $15, %rax
++      shrq    $4, %rax
++      salq    $4, %rax
++      movq    %rax, -56(%rbp)
++      movq    -56(%rbp), %rax
++      movq    %rax, -16(%rbp)
++      .loc 1 27 0
++      movl    $0, -4(%rbp)
++      jmp     .L2
++.L3:
++      .loc 1 28 0
++      movl    -4(%rbp), %esi
++      movl    -4(%rbp), %eax
++      movl    %eax, %ecx
++      movq    -16(%rbp), %rdx
++      movslq  %esi,%rax
++      movb    %cl, (%rdx,%rax)
++      .loc 1 27 0
++      addl    $1, -4(%rbp)
++.L2:
++      movl    -4(%rbp), %eax
++      cmpl    -36(%rbp), %eax
++      jl      .L3
++      .loc 1 30 0
++      .globl  break_here
++break_here:
++      movq    -16(%rbp), %rax
++      movb    $0, (%rax)
++      movq    -48(%rbp), %rsp
++      .loc 1 31 0
++      leave
++      ret
++.LFE2:
++      .size   foo, .-foo
++      .section        .debug_frame,"",@progbits
++.Lframe0:
++      .long   .LECIE0-.LSCIE0
++.LSCIE0:
++      .long   0xffffffff
++      .byte   0x1
++      .string ""
++      .uleb128 0x1
++      .sleb128 -8
++      .byte   0x10
++      .byte   0xc
++      .uleb128 0x7
++      .uleb128 0x8
++      .byte   0x90
++      .uleb128 0x1
++      .align 8
++.LECIE0:
++.LSFDE0:
++      .long   .LEFDE0-.LASFDE0
++.LASFDE0:
++      .long   .Lframe0
++      .quad   .LFB2
++      .quad   .LFE2-.LFB2
++      .byte   0x4
++      .long   .LCFI0-.LFB2
++      .byte   0xe
++      .uleb128 0x10
++      .byte   0x86
++      .uleb128 0x2
++      .byte   0x4
++      .long   .LCFI1-.LCFI0
++      .byte   0xd
++      .uleb128 0x6
++      .align 8
++.LEFDE0:
++      .section        .eh_frame,"a",@progbits
++.Lframe1:
++      .long   .LECIE1-.LSCIE1
++.LSCIE1:
++      .long   0x0
++      .byte   0x1
++      .string "zR"
++      .uleb128 0x1
++      .sleb128 -8
++      .byte   0x10
++      .uleb128 0x1
++      .byte   0x3
++      .byte   0xc
++      .uleb128 0x7
++      .uleb128 0x8
++      .byte   0x90
++      .uleb128 0x1
++      .align 8
++.LECIE1:
++.LSFDE1:
++      .long   .LEFDE1-.LASFDE1
++.LASFDE1:
++      .long   .LASFDE1-.Lframe1
++      .long   .LFB2
++      .long   .LFE2-.LFB2
++      .uleb128 0x0
++      .byte   0x4
++      .long   .LCFI0-.LFB2
++      .byte   0xe
++      .uleb128 0x10
++      .byte   0x86
++      .uleb128 0x2
++      .byte   0x4
++      .long   .LCFI1-.LCFI0
++      .byte   0xd
++      .uleb128 0x6
++      .align 8
++.LEFDE1:
++      .text
++.Letext0:
++      .section        .debug_loc,"",@progbits
++.Ldebug_loc0:
++.LLST0:
++      .quad   .LFB2-.Ltext0
++      .quad   .LCFI0-.Ltext0
++      .value  0x2
++      .byte   0x77
++      .sleb128 8
++      .quad   .LCFI0-.Ltext0
++      .quad   .LCFI1-.Ltext0
++      .value  0x2
++      .byte   0x77
++      .sleb128 16
++      .quad   .LCFI1-.Ltext0
++      .quad   .LFE2-.Ltext0
++      .value  0x2
++      .byte   0x76
++      .sleb128 16
++      .quad   0x0
++      .quad   0x0
++      .section        .debug_info
++      .long   .Ldebug_end - .Ldebug_start
++.Ldebug_start:
++      .value  0x2
++      .long   .Ldebug_abbrev0
++      .byte   0x8
++      .uleb128 0x1
++      .long   .LASF2
++      .byte   0x1
++      .long   .LASF3
++      .long   .LASF4
++      .quad   .Ltext0
++      .quad   .Letext0
++      .long   .Ldebug_line0
++      .uleb128 0x2
++      .byte   0x1
++      .string "foo"
++      .byte   0x1
++      .byte   0x16
++      .byte   0x1
++      .quad   .LFB2
++      .quad   .LFE2
++      .long   .LLST0
++      .long   0x83
++      .uleb128 0x3
++      .long   .LASF5
++      .byte   0x1
++      .byte   0x15
++      .long   0x83
++      .byte   0x2
++      .byte   0x91
++      .sleb128 -52
++.Ltag_typedef:
++      .uleb128 0x4
++      .long   .LASF6
++      .byte   0x1
++      .byte   0x17
++      .long   .Ltag_array_type - .debug_info
++      .uleb128 0x5    /* Abbrev Number: 5 (DW_TAG_variable) */
++      .long   .LASF0
++      .byte   0x1
++      .byte   0x18
++#if 1
++      .long   .Ltag_typedef - .debug_info
++#else
++      /* Debugging only: Skip the typedef indirection.  */
++      .long   .Ltag_array_type - .debug_info
++#endif
++      /* DW_AT_location: DW_FORM_block1: start */
++      .byte   0x3
++      .byte   0x91
++      .sleb128 -32
++#if 0
++      .byte   0x6     /* DW_OP_deref */
++#else
++      .byte   0x96    /* DW_OP_nop */
++#endif
++      /* DW_AT_location: DW_FORM_block1: end */
++      .uleb128 0x6
++      .string "i"
++      .byte   0x1
++      .byte   0x19
++      .long   0x83
++      .byte   0x2
++      .byte   0x91
++      .sleb128 -20
++      .byte   0x0
++      .uleb128 0x7
++      .byte   0x4
++      .byte   0x5
++      .string "int"
++.Ltag_array_type:
++      .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
++      .long   0xa0 + (2f - 1f)        /* DW_AT_type: DW_FORM_ref4 */
++      .long   0x9d + (2f - 1f)        /* DW_AT_sibling: DW_FORM_ref4 */
++1:    /* DW_AT_data_location: DW_FORM_block1: start */
++      .byte   2f - 3f /* length */
++3:
++      .byte   0x97    /* DW_OP_push_object_address */
++      .byte   0x6     /* DW_OP_deref */
++2:    /* DW_AT_data_location: DW_FORM_block1: end */
++      .uleb128 0x9
++      .long   0x9d + (2b - 1b)        /* DW_AT_type: DW_FORM_ref4 */
++      .byte   0x3
++      .byte   0x91
++      .sleb128 -40
++      .byte   0x6
++      .byte   0x0
++      .uleb128 0xa
++      .byte   0x8
++      .byte   0x7
++      .uleb128 0xb
++      .byte   0x1
++      .byte   0x6
++      .long   .LASF1
++      .byte   0x0
++.Ldebug_end:
++      .section        .debug_abbrev
++      .uleb128 0x1
++      .uleb128 0x11
++      .byte   0x1
++      .uleb128 0x25
++      .uleb128 0xe
++      .uleb128 0x13
++      .uleb128 0xb
++      .uleb128 0x3
++      .uleb128 0xe
++      .uleb128 0x1b
++      .uleb128 0xe
++      .uleb128 0x11
++      .uleb128 0x1
++      .uleb128 0x12
++      .uleb128 0x1
++      .uleb128 0x10
++      .uleb128 0x6
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x2
++      .uleb128 0x2e
++      .byte   0x1
++      .uleb128 0x3f
++      .uleb128 0xc
++      .uleb128 0x3
++      .uleb128 0x8
++      .uleb128 0x3a
++      .uleb128 0xb
++      .uleb128 0x3b
++      .uleb128 0xb
++      .uleb128 0x27
++      .uleb128 0xc
++      .uleb128 0x11
++      .uleb128 0x1
++      .uleb128 0x12
++      .uleb128 0x1
++      .uleb128 0x40
++      .uleb128 0x6
++      .uleb128 0x1
++      .uleb128 0x13
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x3
++      .uleb128 0x5
++      .byte   0x0
++      .uleb128 0x3
++      .uleb128 0xe
++      .uleb128 0x3a
++      .uleb128 0xb
++      .uleb128 0x3b
++      .uleb128 0xb
++      .uleb128 0x49
++      .uleb128 0x13
++      .uleb128 0x2
++      .uleb128 0xa
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x4
++      .uleb128 0x16
++      .byte   0x0
++      .uleb128 0x3
++      .uleb128 0xe
++      .uleb128 0x3a
++      .uleb128 0xb
++      .uleb128 0x3b
++      .uleb128 0xb
++      .uleb128 0x49
++      .uleb128 0x13
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x5
++      .uleb128 0x34
++      .byte   0x0
++      .uleb128 0x3
++      .uleb128 0xe
++      .uleb128 0x3a
++      .uleb128 0xb
++      .uleb128 0x3b
++      .uleb128 0xb
++      .uleb128 0x49
++      .uleb128 0x13
++      .uleb128 0x2
++      .uleb128 0xa
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x6
++      .uleb128 0x34
++      .byte   0x0
++      .uleb128 0x3
++      .uleb128 0x8
++      .uleb128 0x3a
++      .uleb128 0xb
++      .uleb128 0x3b
++      .uleb128 0xb
++      .uleb128 0x49
++      .uleb128 0x13
++      .uleb128 0x2
++      .uleb128 0xa
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x7
++      .uleb128 0x24
++      .byte   0x0
++      .uleb128 0xb
++      .uleb128 0xb
++      .uleb128 0x3e
++      .uleb128 0xb
++      .uleb128 0x3
++      .uleb128 0x8
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x8    /* Abbrev Number: 8 (DW_TAG_array_type) */
++      .uleb128 0x1
++      .byte   0x1
++      .uleb128 0x49   /* DW_AT_type */
++      .uleb128 0x13   /* DW_FORM_ref4 */
++      .uleb128 0x1    /* DW_AT_sibling */
++      .uleb128 0x13   /* DW_FORM_ref4 */
++      .uleb128 0x50   /* DW_AT_data_location */
++      .uleb128 0xa    /* DW_FORM_block1 */
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0x9
++      .uleb128 0x21
++      .byte   0x0
++      .uleb128 0x49   /* DW_AT_type */
++      .uleb128 0x13   /* DW_FORM_ref4 */
++      .uleb128 0x2f
++      .uleb128 0xa
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0xa
++      .uleb128 0x24
++      .byte   0x0
++      .uleb128 0xb
++      .uleb128 0xb
++      .uleb128 0x3e
++      .uleb128 0xb
++      .byte   0x0
++      .byte   0x0
++      .uleb128 0xb
++      .uleb128 0x24
++      .byte   0x0
++      .uleb128 0xb
++      .uleb128 0xb
++      .uleb128 0x3e
++      .uleb128 0xb
++      .uleb128 0x3
++      .uleb128 0xe
++      .byte   0x0
++      .byte   0x0
++      .byte   0x0
++      .section        .debug_pubnames,"",@progbits
++      .long   0x16
++      .value  0x2
++      .long   .Ldebug_info0
++      .long   0xa8
++      .long   0x2d
++      .string "foo"
++      .long   0x0
++      .section        .debug_aranges,"",@progbits
++      .long   0x2c
++      .value  0x2
++      .long   .Ldebug_info0
++      .byte   0x8
++      .byte   0x0
++      .value  0x0
++      .value  0x0
++      .quad   .Ltext0
++      .quad   .Letext0-.Ltext0
++      .quad   0x0
++      .quad   0x0
++      .section        .debug_str,"MS",@progbits,1
++.LASF0:
++      .string "array"
++.LASF5:
++      .string "size"
++.LASF3:
++      .string "x86_64-vla-typedef.c"
++.LASF6:
++      .string "array_t"
++.LASF1:
++      .string "char"
++.LASF4:
++      .string "gdb.arch"
++.LASF2:
++      .string "GNU C 4.3.2 20081105 (Red Hat 4.3.2-7)"
++      .ident  "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
++      .section        .note.GNU-stack,"",@progbits
+diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
 new file mode 100644
-index 0000000..e1f3ed1
+index 0000000..b809c4e
 --- /dev/null
-+++ b/gdb/testsuite/gdb.base/vla.c
-@@ -0,0 +1,55 @@
++++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
+@@ -0,0 +1,43 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
 +   Copyright 2008 Free Software Foundation, Inc.
@@ -12728,305 +10867,39 @@ index 0000000..e1f3ed1
 +   You should have received a copy of the GNU General Public License
 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+#include <string.h>
-+
-+void
-+marker (void)
-+{
-+}
-+
-+void
-+bar (char *a, char *b, char *c, int size)
-+{
-+  memset (a, '1', size);
-+  memset (b, '2', size);
-+  memset (c, '3', 48);
-+}
++#if 0
 +
 +void
 +foo (int size)
 +{
-+  char temp1[size];
-+  char temp3[48];
-+
-+  temp1[size - 1] = '\0';
-+  {
-+    char temp2[size];
-+
-+    bar (temp1, temp2, temp3, size);
-+
-+    marker ();        /* break-here */
-+  }
-+}
-+
-+int
-+main (void)
-+{
-+  foo (26);
-+  foo (78);
-+  return 0;
-+}
-diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
-new file mode 100644
-index 0000000..5da7378
---- /dev/null
-+++ b/gdb/testsuite/gdb.base/vla.exp
-@@ -0,0 +1,62 @@
-+# Copyright 2008 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+set testfile vla
-+set srcfile ${testfile}.c
-+set binfile ${objdir}/${subdir}/${testfile}
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-+    untested "Couldn't compile test program"
-+    return -1
-+}
++  typedef char array_t[size];
++  array_t array;
++  int i;
 +
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
++  for (i = 0; i < size; i++)
++    array[i] = i;
 +
-+if ![runto_main] {
-+    untested vla
-+    return -1
++  array[0] = 0;       /* break-here */
 +}
 +
-+gdb_breakpoint [gdb_get_line_number "break-here"]
-+
-+gdb_continue_to_breakpoint "break-here"
-+
-+gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
-+gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
-+gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
-+
-+gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
-+gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
-+gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
-+
-+gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
-+gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
-+gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
-+
-+gdb_continue_to_breakpoint "break-here"
-+
-+gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
-+gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
-+gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
-+
-+gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
-+gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
-+gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
-+
-+gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
-+gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
-+gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
-diff --git a/gdb/testsuite/gdb.cp/gdb9593.cc b/gdb/testsuite/gdb.cp/gdb9593.cc
-new file mode 100644
-index 0000000..783c962
---- /dev/null
-+++ b/gdb/testsuite/gdb.cp/gdb9593.cc
-@@ -0,0 +1,180 @@
-+/* This testcase is part of GDB, the GNU debugger.
-+
-+   Copyright 2008, 2009 Free Software Foundation, Inc.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+   */
-+#include <iostream>
-+
-+using namespace std;
-+
-+class NextOverThrowDerivates
-+{
-+
-+public:
-+
-+
-+  // Single throw an exception in this function.
-+  void function1() 
-+  {
-+    throw 20;
-+  }
-+
-+  // Throw an exception in another function.
-+  void function2() 
-+  {
-+    function1();
-+  }
-+
-+  // Throw an exception in another function, but handle it
-+  // locally.
-+  void function3 () 
-+  {
-+    {
-+      try
-+      {
-+        function1 ();
-+      }
-+      catch (...) 
-+      {
-+        cout << "Caught and handled function1 exception" << endl;
-+      }
-+    }
-+  }
-+
-+  void rethrow ()
-+  {
-+    try
-+      {
-+      function1 ();
-+      }
-+    catch (...)
-+      {
-+      throw;
-+      }
-+  }
-+
-+  void finish ()
-+  {
-+    // We use this to test that a "finish" here does not end up in
-+    // this frame, but in the one above.
-+    try
-+      {
-+      function1 ();
-+      }
-+    catch (int x)
-+      {
-+      }
-+    function1 ();             // marker for until
-+  }
-+
-+  void until ()
-+  {
-+    function1 ();
-+    function1 ();             // until here
-+  }
-+
-+};
-+NextOverThrowDerivates next_cases;
-+
-+
-+int main () 
-+{ 
-+  try
-+    {
-+      next_cases.function1 ();
-+    }
-+  catch (...)
-+    {
-+      // Discard
-+    }
-+
-+  try
-+    {
-+      next_cases.function2 ();
-+    }
-+  catch (...)
-+    {
-+      // Discard
-+    }
-+
-+  try
-+    {
-+      // This is duplicated so we can next over one but step into
-+      // another.
-+      next_cases.function2 ();
-+    }
-+  catch (...)
-+    {
-+      // Discard
-+    }
-+
-+  next_cases.function3 ();
-+
-+  try
-+    {
-+      next_cases.rethrow ();
-+    }
-+  catch (...)
-+    {
-+      // Discard
-+    }
-+
-+  try
-+    {
-+      // Another duplicate so we can test "finish".
-+      next_cases.function2 ();
-+    }
-+  catch (...)
-+    {
-+      // Discard
-+    }
-+
-+  // Another test for "finish".
-+  try
-+    {
-+      next_cases.finish ();
-+    }
-+  catch (...)
-+    {
-+    }
-+
-+  // Test of "until".
-+  try
-+    {
-+      next_cases.finish ();
-+    }
-+  catch (...)
-+    {
-+    }
-+
-+  // Test of "until" with an argument.
-+  try
-+    {
-+      next_cases.until ();
-+    }
-+  catch (...)
-+    {
-+    }
++#else
 +
-+  // Test of "advance".
-+  try
-+    {
-+      next_cases.until ();
-+    }
-+  catch (...)
-+    {
-+    }
++int
++main (void)
++{
++  foo (26);
++  foo (78);
++  return 0;
 +}
 +
-diff --git a/gdb/testsuite/gdb.cp/gdb9593.exp b/gdb/testsuite/gdb.cp/gdb9593.exp
++#endif
+diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
 new file mode 100644
-index 0000000..3dad7ca
+index 0000000..b05411e
 --- /dev/null
-+++ b/gdb/testsuite/gdb.cp/gdb9593.exp
-@@ -0,0 +1,182 @@
-+# Copyright 2008, 2009 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
+@@ -0,0 +1,64 @@
++# Copyright 2009 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -13041,182 +10914,100 @@ index 0000000..3dad7ca
 +# You should have received a copy of the GNU General Public License
 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
++# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
 +
-+if $tracelevel then {
-+    strace $tracelevel
++if ![istarget "x86_64-*-*"] then {
++    verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
++    return
 +}
 +
-+if { [skip_cplus_tests] } { continue }
-+
-+set testfile "gdb9593"
-+set srcfile ${testfile}.cc
-+set binfile $objdir/$subdir/$testfile
-+
-+# Create and source the file that provides information about the compiler
-+# used to compile the test case.
-+if [get_compiler_info ${binfile} "c++"] {
-+    untested gdb9593.exp
++set testfile x86_64-vla-typedef
++set srcasmfile ${testfile}-foo.S
++set srcfile ${testfile}.c
++set binfile ${objdir}/${subdir}/${testfile}
++set binobjfile ${objdir}/${subdir}/${testfile}-foo.o
++if  { [gdb_compile "${srcdir}/${subdir}/${srcasmfile}" "${binobjfile}" object {}] != "" } {
++    untested "Couldn't compile test program"
 +    return -1
 +}
-+
-+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
-+    untested gdb9593.exp
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${binobjfile}" "${binfile}" executable {debug}] != "" } {
++    untested "Couldn't compile test program"
 +    return -1
 +}
 +
-+# Some targets can't do function calls, so don't even bother with this
-+# test.
-+if [target_info exists gdb,cannot_call_functions] {
-+    setup_xfail "*-*-*" 9593
-+    fail "This target can not call functions"
-+    continue
-+}
-+
 +gdb_exit
 +gdb_start
 +gdb_reinitialize_dir $srcdir/$subdir
 +gdb_load ${binfile}
 +
-+if ![runto_main] then {
-+    perror "couldn't run to main"
-+    continue
-+} 
-+
-+# See whether we have the needed unwinder hooks.
-+set ok 1
-+gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
-+    -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
-+      pass "check for unwinder hook"
-+    }
-+    -re "No symbol .* in current context.\r\n$gdb_prompt $" {
-+      # Pass the test so we don't get bogus fails in the results.
-+      pass "check for unwinder hook"
-+      set ok 0
-+    }
-+}
-+if {!$ok} {
-+    untested gdb9593.exp
++if ![runto_main] {
++    untested x86_64-vla-typedef
 +    return -1
 +}
 +
-+# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
-+
-+gdb_test "next" \
-+    ".*catch (...).*" \
-+    "next over a throw 1"
-+
-+gdb_test "next" \
-+  ".*next_cases.function2.*" \
-+  "next past catch 1"
-+
-+gdb_test "next" \
-+    ".*catch (...).*" \
-+    "next over a throw 2"
-+
-+gdb_test "next" \
-+  ".*next_cases.function2.*" \
-+  "next past catch 2"
-+
-+gdb_test "step" \
-+  ".*function1().*" \
-+  "step into function2 1"
-+
-+gdb_test "next" \
-+    ".*catch (...).*" \
-+    "next over a throw 3"
-+
-+gdb_test "next" \
-+  ".*next_cases.function3.*" \
-+  "next past catch 3"
-+
-+gdb_test "next" \
-+  ".*next_cases.rethrow.*" \
-+    "next over a throw 4"
-+
-+gdb_test "next" \
-+  ".*catch (...).*" \
-+  "next over a rethrow"
-+
-+gdb_test "next" \
-+  ".*next_cases.function2.*" \
-+  "next after a rethrow"
-+
-+gdb_test "step" \
-+  ".*function1().*" \
-+  "step into function2 2"
-+
-+gdb_test "finish" \
-+  ".*catch (...).*" \
-+  "finish 1"
-+
-+gdb_test "next" \
-+  ".*next_cases.finish ().*" \
-+  "next past catch 4"
-+
-+gdb_test "step" \
-+  ".*function1 ().*" \
-+  "step into finish method"
-+
-+gdb_test "finish" \
-+  ".*catch (...).*" \
-+  "finish 2"
-+
-+gdb_test "next" \
-+  ".*next_cases.finish ().*" \
-+  "next past catch 5"
-+
-+gdb_test "step" \
-+  ".*function1 ().*" \
-+  "step into finish, for until"
-+
-+gdb_test "until" \
-+  ".*function1 ().*" \
-+  "until with no argument 1"
-+
-+set line [gdb_get_line_number "marker for until" $testfile.cc]
-+
-+gdb_test "until $line" \
-+  ".*function1 ().*" \
-+  "next past catch 6"
++gdb_breakpoint "break_here"
 +
-+gdb_test "until" \
-+  ".*catch (...).*" \
-+  "until with no argument 2"
++gdb_continue_to_breakpoint "break_here"
 +
-+set line [gdb_get_line_number "until here" $testfile.cc]
++gdb_test "whatis array" "type = array_t" "first: whatis array"
 +
-+gdb_test "next" \
-+  ".*next_cases.until ().*" \
-+  "next past catch 6"
++gdb_test "ptype array" "type = char \\\[26\\\]" "first: ptype array"
 +
-+gdb_test "step" \
-+  ".*function1 ().*" \
-+  "step into until"
++gdb_test "p array\[1\]" "\\$\[0-9\] = 1 '\\\\001'"
++gdb_test "p array\[2\]" "\\$\[0-9\] = 2 '\\\\002'"
++gdb_test "p array\[3\]" "\\$\[0-9\] = 3 '\\\\003'"
++gdb_test "p array\[4\]" "\\$\[0-9\] = 4 '\\\\004'"
 +
-+gdb_test "until $line" \
-+  ".*catch (...).*" \
-+  "until-over-throw"
++gdb_continue_to_breakpoint "break_here"
 +
-+gdb_test "next" \
-+  ".*next_cases.until ().*" \
-+  "next past catch 7"
++gdb_test "whatis array" "type = array_t" "second: whatis array"
 +
-+gdb_test "step" \
-+  ".*function1 ().*" \
-+  "step into until, for advance"
++gdb_test "ptype array" "type = char \\\[78\\\]" "second: ptype array"
+diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
+index a99137e..c3dc2d9 100644
+--- a/gdb/testsuite/gdb.base/arrayidx.c
++++ b/gdb/testsuite/gdb.base/arrayidx.c
+@@ -17,6 +17,13 @@
+ int array[] = {1, 2, 3, 4};
++#ifdef __GNUC__
++struct
++  {
++    int a[0];
++  } unbound;
++#endif
 +
-+gdb_test "advance $line" \
-+  ".*catch (...).*" \
-+  "advance-over-throw"
-diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
+ int
+ main (void)
+ {
+diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
+index cba0024..0dc0e46 100644
+--- a/gdb/testsuite/gdb.base/arrayidx.exp
++++ b/gdb/testsuite/gdb.base/arrayidx.exp
+@@ -53,4 +53,12 @@ gdb_test "print array" \
+          "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
+          "Print array with array-indexes on"
+-
++set test "p unbound.a == &unbound.a\[0\]"
++gdb_test_multiple $test $test {
++    -re " = 1\r\n$gdb_prompt $" {
++      pass $test
++    }
++    -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
++      unsupported "$test (no GCC)"
++    }
++}
+diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.c b/gdb/testsuite/gdb.base/internal-var-field-address.c
 new file mode 100644
-index 0000000..7fb00ea
+index 0000000..eeb7b85
 --- /dev/null
-+++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
-@@ -0,0 +1,212 @@
++++ b/gdb/testsuite/gdb.base/internal-var-field-address.c
+@@ -0,0 +1,20 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
-+   Copyright 2010 Free Software Foundation, Inc.
++   Copyright 2009 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
@@ -13231,208 +11022,165 @@ index 0000000..7fb00ea
 +   You should have received a copy of the GNU General Public License
 +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+/* Debug information */
-+
-+/* We will `break *main' at the very first instruction.  */
-+#define main_length 1
-+
-+      .section        .data
-+vardata:
-+      /* See DW_OP_lit3 + 1 (0-based).  */
-+      .string         "seennotseen"
++struct {
++  int field;
++} staticstruct = { 1 };
+diff --git a/gdb/testsuite/gdb.base/internal-var-field-address.exp b/gdb/testsuite/gdb.base/internal-var-field-address.exp
+new file mode 100644
+index 0000000..6d82e73
+--- /dev/null
++++ b/gdb/testsuite/gdb.base/internal-var-field-address.exp
+@@ -0,0 +1,26 @@
++# Copyright 2009 Free Software Foundation, Inc.
 +
-+      .section        .debug_info
-+.Lcu1_begin:
-+      .4byte          .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
-+.Lcu1_start:
-+      .2byte          2                       /* DWARF version number */
-+      .4byte          .Ldebug_abbrev0         /* Offset Into Abbrev. Section */
-+      .byte           4                       /* Pointer Size (in bytes) */
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+      /* CU die */
-+      .uleb128        1                       /* Abbrev: DW_TAG_compile_unit */
-+      .4byte          .Lproducer              /* DW_AT_producer */
-+      /* Use C++ to exploit a bug in parsing DW_AT_name "".  */
-+      .byte           4                       /* DW_AT_language (C++) -  */
-+      .4byte          main                    /* DW_AT_low_pc */
-+      .byte           main_length             /* DW_AT_high_pc */
++set test internal-var-field-address
++set binfile ${test}.x
++if  { [gdb_compile "${srcdir}/${subdir}/${test}.c" "${objdir}/${subdir}/${binfile}" object {debug}] != "" } {
++    untested "Couldn't compile test program"
++    return -1
++}
 +
-+.Larray_type:
-+      .uleb128        2                       /* Abbrev: DW_TAG_array_type */
-+      .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
++clean_restart $binfile
 +
-+      .uleb128        3                       /* Abbrev: DW_TAG_subrange_type */
-+      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
-+      .byte           0                       /* DW_AT_lower_bound */
-+      .4byte          .Llen_var-.Lcu1_begin   /* DW_AT_upper_bound */
-+      .byte           0                       /* End of children of die */
++gdb_test {set $varstruct = staticstruct}
++gdb_test {p $varstruct.field} " = 1"
+diff --git a/gdb/testsuite/gdb.base/vla-frame.c b/gdb/testsuite/gdb.base/vla-frame.c
+new file mode 100644
+index 0000000..5750f68
+--- /dev/null
++++ b/gdb/testsuite/gdb.base/vla-frame.c
+@@ -0,0 +1,31 @@
++/* This testcase is part of GDB, the GNU debugger.
 +
-+      /* DW_AT_upper_bound is referencing an optimized-out variable.  */
-+.Larrayb_type:
-+      .uleb128        2                       /* Abbrev: DW_TAG_array_type */
-+      .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
++   Copyright 2011 Free Software Foundation, Inc.
 +
-+      .uleb128        3                       /* Abbrev: DW_TAG_subrange_type */
-+      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
-+      .byte           0                       /* DW_AT_lower_bound */
-+      .4byte          .Llenb_var-.Lcu1_begin  /* DW_AT_upper_bound */
-+      .byte           0                       /* End of children of die */
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
 +
-+.Luint_type:
-+      .uleb128        4                       /* Abbrev: DW_TAG_base_type */
-+      .4byte          .Luint_str              /* DW_AT_name */
-+      .byte           4                       /* DW_AT_byte_size */
-+      .byte           7                       /* DW_AT_encoding */
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
 +
-+.Lchar_type:
-+      .uleb128        4                       /* Abbrev: DW_TAG_base_type */
-+      .4byte          .Lchar_str              /* DW_AT_name */
-+      .byte           1                       /* DW_AT_byte_size */
-+      .byte           6                       /* DW_AT_encoding */
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+.Llen_var:
-+      .uleb128        5                       /* Abbrev: DW_TAG_variable artificial */
-+      .byte           1                       /* DW_AT_artificial */
-+      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
-+      .4byte          .Llen_loclist-.Lloclist /* DW_AT_location */
++#include <string.h>
 +
-+      /* optimized-out variable for b_string.  */
-+.Llenb_var:
-+      .uleb128        7                       /* Abbrev: DW_TAG_variable artificial no DW_AT_location */
-+      .byte           1                       /* DW_AT_artificial */
-+      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
++int
++main (int argc, char **argv)
++{
++  char s[2 + argc];
++  void (*f) (char *) = 0;
 +
-+      .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
-+      .string         "a_string"              /* DW_AT_name */
-+      .4byte          .Larray_type-.Lcu1_begin /* DW_AT_type */
-+      .byte           2f - 1f                 /* DW_AT_location */
-+1:    .byte           3                       /*   DW_OP_addr */
-+      .4byte          vardata                 /*   <addr> */
-+2:
++  memset (s, 0, sizeof (s));
++  s[0] = 'X';
 +
-+      /* DW_AT_upper_bound is referencing an optimized-out variable.  */
-+      .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
-+      .string         "b_string"              /* DW_AT_name */
-+      .4byte          .Larrayb_type-.Lcu1_begin /* DW_AT_type */
-+      .byte           2f - 1f                 /* DW_AT_location */
-+1:    .byte           3                       /*   DW_OP_addr */
-+      .4byte          vardata                 /*   <addr> */
-+2:
++  f (s);
++  return 0;
++}
+diff --git a/gdb/testsuite/gdb.base/vla-frame.exp b/gdb/testsuite/gdb.base/vla-frame.exp
+new file mode 100644
+index 0000000..47736c7
+--- /dev/null
++++ b/gdb/testsuite/gdb.base/vla-frame.exp
+@@ -0,0 +1,38 @@
++# Copyright 2011 Free Software Foundation, Inc.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+      .byte           0                       /* End of children of CU */
-+.Lcu1_end:
++set testfile vla-frame
++set executable ${testfile}
 +
-+      .section        .debug_loc
-+.Lloclist:
-+.Llen_loclist:
-+      .4byte  0                       # Location list begin address
-+      .4byte  main_length             # Location list end address
-+      .value  2f-1f   # Location expression size
-+1:    .byte   0x33    # DW_OP_lit3
-+      .byte   0x9f    # DW_OP_stack_value
-+2:
-+      .quad   0x0     # Location list terminator begin (*.LLST2)
-+      .quad   0x0     # Location list terminator end (*.LLST2)
++if { [prepare_for_testing ${testfile}.exp ${executable}] } {
++    return -1
++}
 +
-+      .section .debug_abbrev
-+.Ldebug_abbrev0:
-+      .uleb128        1                       /* Abbrev code */
-+      .uleb128        0x11                    /* DW_TAG_compile_unit */
-+      .byte           0x1                     /* has_children */
-+      .uleb128        0x25                    /* DW_AT_producer */
-+      .uleb128        0xe                     /* DW_FORM_strp */
-+      .uleb128        0x13                    /* DW_AT_language */
-+      .uleb128        0xb                     /* DW_FORM_data1 */
-+      .uleb128        0x11                    /* DW_AT_low_pc */
-+      .uleb128        0x1                     /* DW_FORM_addr */
-+      .uleb128        0x12                    /* DW_AT_high_pc */
-+      .uleb128        0xb                     /* DW_FORM_data1 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++if ![runto_main] {
++    return -1
++}
 +
-+      .uleb128        2                       /* Abbrev code */
-+      .uleb128        0x1                     /* TAG: DW_TAG_array_type */
-+      .byte           0x1                     /* DW_children_yes */
-+      .uleb128        0x49                    /* DW_AT_type */
-+      .uleb128        0x13                    /* DW_FORM_ref4 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++set test "continue"
++gdb_test_multiple $test $test {
++    -re "Continuing\\.\r\n\r\nProgram received signal SIGSEGV, Segmentation fault\\.\r\n0x0+ in \\?\\? \\(\\)\r\n$gdb_prompt $" {
++      pass $test
++    }
++    -re "\r\n$gdb_prompt $" {
++      untested ${testfile}.exp
++      return
++    }
++}
 +
-+      .uleb128        3                       /* Abbrev code */
-+      .uleb128        0x21                    /* DW_TAG_subrange_type */
-+      .byte           0x0                     /* no children */
-+      .uleb128        0x49                    /* DW_AT_type */
-+      .uleb128        0x13                    /* DW_FORM_ref4 */
-+      .uleb128        0x22                    /* DW_AT_lower_bound */
-+      .uleb128        0xb                     /* DW_FORM_data1 */
-+      .uleb128        0x2f                    /* DW_AT_upper_bound */
-+      .uleb128        0x13                    /* DW_FORM_ref4 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++gdb_test "bt full" "\r\n +s = \"X\\\\000\"\r\n.*"
+diff --git a/gdb/testsuite/gdb.base/vla-overflow.c b/gdb/testsuite/gdb.base/vla-overflow.c
+new file mode 100644
+index 0000000..c5d5ee0
+--- /dev/null
++++ b/gdb/testsuite/gdb.base/vla-overflow.c
+@@ -0,0 +1,30 @@
++/* This testcase is part of GDB, the GNU debugger.
 +
-+      .uleb128        4                       /* Abbrev code */
-+      .uleb128        0x24                    /* DW_TAG_base_type */
-+      .byte           0x0                     /* no_children */
-+      .uleb128        0x3                     /* DW_AT_name */
-+      .uleb128        0xe                     /* DW_FORM_strp */
-+      .uleb128        0xb                     /* DW_AT_byte_size */
-+      .uleb128        0xb                     /* DW_FORM_data1 */
-+      .uleb128        0x3e                    /* DW_AT_encoding */
-+      .uleb128        0xb                     /* DW_FORM_data1 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++   Copyright 2008 Free Software Foundation, Inc.
 +
-+      .uleb128        5                       /* Abbrev code */
-+      .uleb128        0x34                    /* DW_TAG_variable */
-+      .byte           0x0                     /* no_children */
-+      .uleb128        0x34                    /* DW_AT_artificial */
-+      .uleb128        0x0c                    /* DW_FORM_flag */
-+      .uleb128        0x49                    /* DW_AT_type */
-+      .uleb128        0x13                    /* DW_FORM_ref4 */
-+      .uleb128        0x02                    /* DW_AT_location */
-+      .uleb128        0x06                    /* DW_FORM_data4 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
 +
-+      .uleb128        6                       /* Abbrev code */
-+      .uleb128        0x34                    /* DW_TAG_variable */
-+      .byte           0x0                     /* no_children */
-+      .uleb128        0x3                     /* DW_AT_name */
-+      .uleb128        0x8                     /* DW_FORM_string */
-+      .uleb128        0x49                    /* DW_AT_type */
-+      .uleb128        0x13                    /* DW_FORM_ref4 */
-+      .uleb128        0x2                     /* DW_AT_location */
-+      .uleb128        0xa                     /* DW_FORM_block1 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
 +
-+      .uleb128        7                       /* Abbrev code */
-+      .uleb128        0x34                    /* DW_TAG_variable */
-+      .byte           0x0                     /* no_children */
-+      .uleb128        0x34                    /* DW_AT_artificial */
-+      .uleb128        0x0c                    /* DW_FORM_flag */
-+      .uleb128        0x49                    /* DW_AT_type */
-+      .uleb128        0x13                    /* DW_FORM_ref4 */
-+      .byte           0x0                     /* Terminator */
-+      .byte           0x0                     /* Terminator */
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+      .byte           0x0                     /* Terminator */
++#include <stdlib.h>
 +
-+/* String table */
-+      .section .debug_str
-+.Lproducer:
-+      .string         "GNU C 3.3.3"
-+.Lchar_str:
-+      .string         "char"
-+.Luint_str:
-+      .string         "unsigned int"
-diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
++int
++main (int argc, char **argv)
++{
++  int array[argc];
++
++  array[0] = array[0];
++
++  abort ();
++
++  return 0;
++}
+diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
 new file mode 100644
-index 0000000..5dbed3f
+index 0000000..24a608f
 --- /dev/null
-+++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
-@@ -0,0 +1,51 @@
-+# Copyright 2010 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.base/vla-overflow.exp
+@@ -0,0 +1,109 @@
++# Copyright 2008 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -13447,184 +11195,238 @@ index 0000000..5dbed3f
 +# You should have received a copy of the GNU General Public License
 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+# Test printing variable with dynamic bounds which reference a different
-+# (artificial in the GCC case) variable containing loclist as its location.
-+# This testcase uses value (not address) of the referenced variable:
-+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
-+
-+# This test can only be run on targets which support DWARF-2 and use gas.
-+# For now pick a sampling of likely targets.
-+if {![istarget *-*-linux*]
-+    && ![istarget *-*-gnu*]
-+    && ![istarget *-*-elf*]
-+    && ![istarget *-*-openbsd*]
-+    && ![istarget arm-*-eabi*]
-+    && ![istarget powerpc-*-eabi*]} {
-+    return 0
-+}
++# We could crash in:
++# #0  block_linkage_function (bl=0x0) at ../../gdb/block.c:69
++# #1  in dwarf_block_get_frame_base (...) at ../../gdb/dwarf2block.c:97
++#   97          framefunc = block_linkage_function (get_frame_block (frame, NULL));
++# #2  in execute_stack_op (...) at ../../gdb/dwarf2expr.c:496
++# #3  in dwarf_block_exec_core () at ../../gdb/dwarf2block.c:156
++# #4  dwarf_block_exec (...) at ../../gdb/dwarf2block.c:206
++# #5  in range_type_count_bound_internal (...) at ../../gdb/gdbtypes.c:1430
++# #6  in create_array_type (...) at ../../gdb/gdbtypes.c:840
++# ...
++# #21 in psymtab_to_symtab (...) at ../../gdb/symfile.c:292
++# ...
++# #29 in backtrace_command_1 () at ../../gdb/stack.c:1273
 +
-+set testfile dw2-bound-loclist
-+if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
++set testfile vla-overflow
++set shfile ${objdir}/${subdir}/${testfile}-gdb.sh
++set srcfile ${testfile}.c
++set binfile ${objdir}/${subdir}/${testfile}
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
++    untested "Couldn't compile test program"
 +    return -1
 +}
 +
-+# Verify it behaves at least as an unbound array without inferior.
++set f [open "|getconf PAGESIZE" "r"]
++gets $f pagesize
++close $f
 +
-+gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"}
-+gdb_test "ptype a_string" {type = char \[\]}
++gdb_exit
++gdb_start
++gdb_reinitialize_dir $srcdir/$subdir
++gdb_load ${binfile}
 +
-+# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
-+if ![runto "*main"] {
++set pid_of_gdb [exp_pid -i [board_info host fileid]]
++
++if { [runto_main] < 0 } {
++    untested vla-overflow
 +    return -1
 +}
 +
-+gdb_test "p a_string" { = "seen"}
-+gdb_test "ptype a_string" {type = char \[4\]}
++# Get the GDB memory size when we stay at main.
 +
-+gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"}
-+gdb_test "ptype b_string" {type = char \[\]}
-diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
++proc memory_v_pages_get {} {
++    global pid_of_gdb pagesize
++    set fd [open "/proc/$pid_of_gdb/statm"]
++    gets $fd line
++    close $fd
++    # number of pages of virtual memory
++    scan $line "%d" drs
++    return $drs
++}
++
++set pages_found [memory_v_pages_get]
++
++# s390x with glibc-debuginfo.s390x installed used approx. 16MB.
++set mb_reserve 40
++verbose -log "pages_found = $pages_found, mb_reserve = $mb_reserve"
++set kb_found [expr $pages_found * $pagesize / 1024]
++set kb_permit [expr $kb_found + 1 * 1024 + $mb_reserve * 1024]
++verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
++
++# Create the ulimit wrapper.
++set f [open $shfile "w"]
++puts $f "#! /bin/sh"
++puts $f "ulimit -v $kb_permit"
++puts $f "exec $GDB \"\$@\""
++close $f
++remote_exec host "chmod +x $shfile"
++
++gdb_exit
++set GDBold $GDB
++set GDB "$shfile"
++gdb_start
++set GDB $GDBold
++
++gdb_reinitialize_dir $srcdir/$subdir
++gdb_load ${binfile}
++
++set pid_of_gdb [exp_pid -i [board_info host fileid]]
++
++# Check the size again after the second run.
++# We must not stop in main as it would cache `array' and never crash later.
++
++gdb_run_cmd
++
++verbose -log "kb_found before abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
++
++gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
++
++verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
++
++# `abort' can get expressed as `*__GI_abort'.
++gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
++
++verbose -log "kb_found in bt after abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
+diff --git a/gdb/testsuite/gdb.base/vla.c b/gdb/testsuite/gdb.base/vla.c
 new file mode 100644
-index 0000000..1f02d90
+index 0000000..e1f3ed1
 --- /dev/null
-+++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
-@@ -0,0 +1,42 @@
++++ b/gdb/testsuite/gdb.base/vla.c
+@@ -0,0 +1,55 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
-+   Copyright 2004 Free Software Foundation, Inc.
++   Copyright 2008 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 2 of the License, or
++   the Free Software Foundation; either version 3 of the License, or
 +   (at your option) any later version.
 +
 +   This program is distributed in the hope that it will be useful,
 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +   GNU General Public License for more details.
-+ 
-+   You should have received a copy of the GNU General Public License
-+   along with this program; if not, write to the Free Software
-+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-+   USA.  */
 +
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+/* The function `func1' traced into must have debug info on offset > 0;
-+   (DW_UNSND (attr)).  This is the reason of `func0' existence.  */
++#include <string.h>
 +
 +void
-+func0(int a, int b)
++marker (void)
 +{
 +}
 +
-+/* `func1' being traced into must have some arguments to dump.  */
++void
++bar (char *a, char *b, char *c, int size)
++{
++  memset (a, '1', size);
++  memset (b, '2', size);
++  memset (c, '3', 48);
++}
 +
 +void
-+func1(int a, int b)
++foo (int size)
 +{
-+  func0 (a,b);
++  char temp1[size];
++  char temp3[48];
++
++  temp1[size - 1] = '\0';
++  {
++    char temp2[size];
++
++    bar (temp1, temp2, temp3, size);
++
++    marker ();        /* break-here */
++  }
 +}
 +
 +int
-+main(void)
++main (void)
 +{
-+  func1 (1, 2);
++  foo (26);
++  foo (78);
 +  return 0;
 +}
-diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
+diff --git a/gdb/testsuite/gdb.base/vla.exp b/gdb/testsuite/gdb.base/vla.exp
 new file mode 100644
-index 0000000..1c6e84a
+index 0000000..5da7378
 --- /dev/null
-+++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
-@@ -0,0 +1,79 @@
-+# Copyright 2006 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.base/vla.exp
+@@ -0,0 +1,62 @@
++# Copyright 2008 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 2 of the License, or
++# the Free Software Foundation; either version 3 of the License, or
 +# (at your option) any later version.
-+# 
++#
 +# This program is distributed in the hope that it will be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
-+# 
++#
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+
-+# Minimal DWARF-2 unit test
-+
-+# This test can only be run on targets which support DWARF-2.
-+# For now pick a sampling of likely targets.
-+if {![istarget *-*-linux*]
-+    && ![istarget *-*-gnu*]
-+    && ![istarget *-*-elf*]
-+    && ![istarget *-*-openbsd*]
-+    && ![istarget arm-*-eabi*]
-+    && ![istarget powerpc-*-eabi*]} {
-+    return 0  
-+}
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+set testfile "dw2-stripped"
++set testfile vla
 +set srcfile ${testfile}.c
-+set binfile ${objdir}/${subdir}/${testfile}.x
-+
-+remote_exec build "rm -f ${binfile}"
-+
-+# get the value of gcc_compiled
-+if [get_compiler_info ${binfile}] {
++set binfile ${objdir}/${subdir}/${testfile}
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
++    untested "Couldn't compile test program"
 +    return -1
 +}
 +
-+# This test can only be run on gcc as we use additional_flags=FIXME
-+if {$gcc_compiled == 0} {
-+    return 0
-+}
++gdb_exit
++gdb_start
++gdb_reinitialize_dir $srcdir/$subdir
++gdb_load ${binfile}
 +
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
++if ![runto_main] {
++    untested vla
 +    return -1
 +}
 +
-+remote_exec build "objcopy -R .debug_loc ${binfile}"
-+set strip_output [remote_exec build "objdump -h ${binfile}"]
++gdb_breakpoint [gdb_get_line_number "break-here"]
 +
-+set test "stripping test file preservation"
-+if [ regexp ".debug_info " $strip_output]  {
-+    pass "$test (.debug_info preserved)"
-+} else {
-+    fail "$test (.debug_info got also stripped)"
-+}
++gdb_continue_to_breakpoint "break-here"
 +
-+set test "stripping test file functionality"
-+if [ regexp ".debug_loc " $strip_output]  {
-+    fail "$test (.debug_loc still present)"
-+} else {
-+    pass "$test (.debug_loc stripped)"
-+}
++gdb_test "whatis temp1" "type = char \\\[variable\\\]" "first: whatis temp1"
++gdb_test "whatis temp2" "type = char \\\[variable\\\]" "first: whatis temp2"
++gdb_test "whatis temp3" "type = char \\\[48\\\]" "first: whatis temp3"
 +
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
++gdb_test "ptype temp1" "type = char \\\[26\\\]" "first: ptype temp1"
++gdb_test "ptype temp2" "type = char \\\[26\\\]" "first: ptype temp2"
++gdb_test "ptype temp3" "type = char \\\[48\\\]" "first: ptype temp3"
 +
-+# For C programs, "start" should stop in main().
++gdb_test "p temp1" " = '1' <repeats 26 times>" "first: print temp1"
++gdb_test "p temp2" " = '2' <repeats 26 times>" "first: print temp2"
++gdb_test "p temp3" " = '3' <repeats 48 times>" "first: print temp3"
 +
-+gdb_test "start" \
-+         ".*main \\(\\) at .*" \
-+         "start"
-+gdb_test "step" \
-+         "func.* \\(.*\\) at .*" \
-+         "step"
-diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
++gdb_continue_to_breakpoint "break-here"
++
++gdb_test "whatis temp1" "type = char \\\[variable\\\]" "second: whatis temp1"
++gdb_test "whatis temp2" "type = char \\\[variable\\\]" "second: whatis temp2"
++gdb_test "whatis temp3" "type = char \\\[48\\\]" "second: whatis temp3"
++
++gdb_test "ptype temp1" "type = char \\\[78\\\]" "second: ptype temp1"
++gdb_test "ptype temp2" "type = char \\\[78\\\]" "second: ptype temp2"
++gdb_test "ptype temp3" "type = char \\\[48\\\]" "second: ptype temp3"
++
++gdb_test "p temp1" " = '1' <repeats 78 times>" "second: print temp1"
++gdb_test "p temp2" " = '2' <repeats 78 times>" "second: print temp2"
++gdb_test "p temp3" " = '3' <repeats 48 times>" "second: print temp3"
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
 new file mode 100644
-index 0000000..5fcdd84
+index 0000000..aac3baa
 --- /dev/null
-+++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
-@@ -0,0 +1,83 @@
++++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
+@@ -0,0 +1,246 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
-+   Copyright 2009 Free Software Foundation, Inc.
++   Copyright 2010 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
@@ -13641,469 +11443,348 @@ index 0000000..5fcdd84
 +
 +/* Debug information */
 +
-+      .section .debug_info
++/* We will `break *main' at the very first instruction.  */
++#define main_length 1
++
++      .section        .data
++vardata:
++      /* See DW_OP_lit3 + 1 (0-based).  */
++      .string         "seennotseen"
++
++      .section        .debug_info
 +.Lcu1_begin:
-+      /* CU header */
-+      .4byte  .Lcu1_end - .Lcu1_start         /* Length of Compilation Unit */
++      .4byte          .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
 +.Lcu1_start:
-+      .2byte  2                               /* DWARF Version */
-+      .4byte  .Labbrev1_begin                 /* Offset into abbrev section */
-+      .byte   4                               /* Pointer size */
++      .2byte          2                       /* DWARF version number */
++      .4byte          .Ldebug_abbrev0         /* Offset Into Abbrev. Section */
++      .byte           4                       /* Pointer Size (in bytes) */
 +
 +      /* CU die */
-+      .uleb128 1                              /* Abbrev: DW_TAG_compile_unit */
-+      .ascii  "dw2-struct-member-data-location.c\0"   /* DW_AT_name */
-+      .ascii  "GNU C 4.3.2\0"                 /* DW_AT_producer */
-+      .byte   1                               /* DW_AT_language (C) */
++      .uleb128        1                       /* Abbrev: DW_TAG_compile_unit */
++      .4byte          .Lproducer              /* DW_AT_producer */
++      /* Use C++ to exploit a bug in parsing DW_AT_name "".  */
++      .byte           4                       /* DW_AT_language (C++) -  */
++      .4byte          main                    /* DW_AT_low_pc */
++      .byte           main_length             /* DW_AT_high_pc */
 +
-+.Ltype_uchar:
-+      .uleb128        2                       /* Abbrev: DW_TAG_structure_type */
-+      .ascii          "some_struct\0"         /* DW_AT_name */
++.Larray_type:
++      .uleb128        2                       /* Abbrev: DW_TAG_array_type */
++      .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
++
++      .uleb128        3                       /* Abbrev: DW_TAG_subrange_type */
++      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
++      .byte           0                       /* DW_AT_lower_bound */
++      .4byte          .Llen_var-.Lcu1_begin   /* DW_AT_upper_bound */
++      .byte           0                       /* End of children of die */
++
++      /* DW_AT_upper_bound is referencing an optimized-out variable.  */
++.Larrayb_type:
++      .uleb128        2                       /* Abbrev: DW_TAG_array_type */
++      .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
++
++      .uleb128        3                       /* Abbrev: DW_TAG_subrange_type */
++      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
++      .byte           0                       /* DW_AT_lower_bound */
++      .4byte          .Llenb_var-.Lcu1_begin  /* DW_AT_upper_bound */
++      .byte           0                       /* End of children of die */
++
++      /* DW_AT_upper_bound is referencing register.  */
++.Larrayreg_type:
++      .uleb128        2                       /* Abbrev: DW_TAG_array_type */
++      .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
++
++      .uleb128        8                       /* Abbrev: DW_TAG_subrange_type with block */
++      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
++      .byte           0                       /* DW_AT_lower_bound */
++      .byte           2f - 1f                 /* DW_AT_upper_bound */
++1:    .byte           0x50                    /* DW_OP_reg0 */
++2:
++      .byte           0                       /* End of children of die */
++
++.Luint_type:
++      .uleb128        4                       /* Abbrev: DW_TAG_base_type */
++      .4byte          .Luint_str              /* DW_AT_name */
++      .byte           4                       /* DW_AT_byte_size */
++      .byte           7                       /* DW_AT_encoding */
++
++.Lchar_type:
++      .uleb128        4                       /* Abbrev: DW_TAG_base_type */
++      .4byte          .Lchar_str              /* DW_AT_name */
++      .byte           1                       /* DW_AT_byte_size */
++      .byte           6                       /* DW_AT_encoding */
++
++.Llen_var:
++      .uleb128        5                       /* Abbrev: DW_TAG_variable artificial */
++      .byte           1                       /* DW_AT_artificial */
++      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
++      .4byte          .Llen_loclist-.Lloclist /* DW_AT_location */
++
++      /* optimized-out variable for b_string.  */
++.Llenb_var:
++      .uleb128        7                       /* Abbrev: DW_TAG_variable artificial no DW_AT_location */
++      .byte           1                       /* DW_AT_artificial */
++      .4byte          .Luint_type-.Lcu1_begin /* DW_AT_type */
++
++      .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
++      .string         "a_string"              /* DW_AT_name */
++      .4byte          .Larray_type-.Lcu1_begin /* DW_AT_type */
++      .byte           2f - 1f                 /* DW_AT_location */
++1:    .byte           3                       /*   DW_OP_addr */
++      .4byte          vardata                 /*   <addr> */
++2:
 +
-+      .uleb128        3                       /* Abbrev: DW_TAG_member */
-+      .ascii          "field\0"               /* DW_AT_name */
-+      .byte           0                       /* DW_AT_data_member_location */
++      /* DW_AT_upper_bound is referencing an optimized-out variable.  */
++      .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
++      .string         "b_string"              /* DW_AT_name */
++      .4byte          .Larrayb_type-.Lcu1_begin /* DW_AT_type */
++      .byte           2f - 1f                 /* DW_AT_location */
++1:    .byte           3                       /*   DW_OP_addr */
++      .4byte          vardata                 /*   <addr> */
++2:
 +
-+      .byte           0                       /* End of children of some_struct */
++      /* DW_AT_upper_bound is referencing register.  */
++      .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
++      .string         "reg_string"            /* DW_AT_name */
++      .4byte          .Larrayreg_type-.Lcu1_begin /* DW_AT_type */
++      .byte           2f - 1f                 /* DW_AT_location */
++1:    .byte           3                       /*   DW_OP_addr */
++      .4byte          vardata                 /*   <addr> */
++2:
 +
 +      .byte           0                       /* End of children of CU */
-+
 +.Lcu1_end:
 +
-+/* Abbrev table */
++      .section        .debug_loc
++.Lloclist:
++.Llen_loclist:
++      .4byte  0                       # Location list begin address
++      .4byte  main_length             # Location list end address
++      .value  2f-1f   # Location expression size
++1:    .byte   0x33    # DW_OP_lit3
++      .byte   0x9f    # DW_OP_stack_value
++2:
++      .quad   0x0     # Location list terminator begin (*.LLST2)
++      .quad   0x0     # Location list terminator end (*.LLST2)
++
 +      .section .debug_abbrev
-+.Labbrev1_begin:
++.Ldebug_abbrev0:
 +      .uleb128        1                       /* Abbrev code */
 +      .uleb128        0x11                    /* DW_TAG_compile_unit */
-+      .byte           1                       /* has_children */
-+      .uleb128        0x3                     /* DW_AT_name */
-+      .uleb128        0x8                     /* DW_FORM_string */
++      .byte           0x1                     /* has_children */
 +      .uleb128        0x25                    /* DW_AT_producer */
-+      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0xe                     /* DW_FORM_strp */
 +      .uleb128        0x13                    /* DW_AT_language */
 +      .uleb128        0xb                     /* DW_FORM_data1 */
++      .uleb128        0x11                    /* DW_AT_low_pc */
++      .uleb128        0x1                     /* DW_FORM_addr */
++      .uleb128        0x12                    /* DW_AT_high_pc */
++      .uleb128        0xb                     /* DW_FORM_data1 */
 +      .byte           0x0                     /* Terminator */
 +      .byte           0x0                     /* Terminator */
 +
 +      .uleb128        2                       /* Abbrev code */
-+      .uleb128        0x13                    /* DW_TAG_structure_type */
-+      .byte           1                       /* has_children */
-+      .uleb128        0x3                     /* DW_AT_name */
-+      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x1                     /* TAG: DW_TAG_array_type */
++      .byte           0x1                     /* DW_children_yes */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
 +      .byte           0x0                     /* Terminator */
 +      .byte           0x0                     /* Terminator */
 +
 +      .uleb128        3                       /* Abbrev code */
-+      .uleb128        0x0d                    /* DW_TAG_member */
-+      .byte           0                       /* has_children */
-+      .uleb128        0x3                     /* DW_AT_name */
-+      .uleb128        0x8                     /* DW_FORM_string */
-+      .uleb128        0x38                    /* DW_AT_data_member_location */
-+      .uleb128        0x0b                    /* DW_FORM_data1 */
++      .uleb128        0x21                    /* DW_TAG_subrange_type */
++      .byte           0x0                     /* no children */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .uleb128        0x22                    /* DW_AT_lower_bound */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .uleb128        0x2f                    /* DW_AT_upper_bound */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
 +      .byte           0x0                     /* Terminator */
 +      .byte           0x0                     /* Terminator */
 +
++      .uleb128        4                       /* Abbrev code */
++      .uleb128        0x24                    /* DW_TAG_base_type */
++      .byte           0x0                     /* no_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0xe                     /* DW_FORM_strp */
++      .uleb128        0xb                     /* DW_AT_byte_size */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .uleb128        0x3e                    /* DW_AT_encoding */
++      .uleb128        0xb                     /* DW_FORM_data1 */
 +      .byte           0x0                     /* Terminator */
 +      .byte           0x0                     /* Terminator */
-diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
-new file mode 100644
-index 0000000..c41151c
---- /dev/null
-+++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
-@@ -0,0 +1,37 @@
-+# Copyright 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+# This test can only be run on targets which support DWARF-2 and use gas.
-+# For now pick a sampling of likely targets.
-+if {![istarget *-*-linux*]
-+    && ![istarget *-*-gnu*]
-+    && ![istarget *-*-elf*]
-+    && ![istarget *-*-openbsd*]
-+    && ![istarget arm-*-eabi*]
-+    && ![istarget powerpc-*-eabi*]} {
-+    return 0  
-+}
-+
-+set testfile "dw2-struct-member-data-location"
-+set srcfile ${testfile}.S
-+set binfile ${testfile}.x
-+
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
-+    return -1
-+}
-+
-+clean_restart $binfile
-+
-+gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
-diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
-new file mode 100644
-index 0000000..cd3486b
---- /dev/null
-+++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
-@@ -0,0 +1,42 @@
-+# Copyright 2009 Free Software Foundation, Inc.
-+
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 2 of the License, or
-+# (at your option) any later version.
-+# 
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+# 
-+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
-+
-+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
-+
-+# This file is part of the gdb testsuite.  Array element stride must not be
-+# specified in the number of elements but in a number of bytes instead.
-+# Original problem:
-+# (gdb) p c40pt(1)
-+# $1 = '0-hello', ' ' <repeats 33 times>
-+# (gdb) p c40pt(2)
-+# warning: Fortran array stride not divisible by the element size
-+
-+set testfile dwarf-stride
-+set srcfile ${testfile}.f90
-+
-+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f77}] } {
-+    return -1
-+}
-+
-+if ![runto MAIN__] then {
-+    perror "couldn't run to breakpoint MAIN__"
-+    continue
-+}
-+
-+gdb_breakpoint [gdb_get_line_number "break-here"]
-+gdb_continue_to_breakpoint "break-here" ".*break-here.*"
-+gdb_test "p c40pt(1)" " = '0-hello.*"
-+gdb_test "p c40pt(2)" " = '1-hello.*"
-diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
-new file mode 100644
-index 0000000..e492b3a
---- /dev/null
-+++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
-@@ -0,0 +1,40 @@
-+! Copyright 2009 Free Software Foundation, Inc.
-+!
-+! This program is free software; you can redistribute it and/or modify
-+! it under the terms of the GNU General Public License as published by
-+! the Free Software Foundation; either version 2 of the License, or
-+! (at your option) any later version.
-+!
-+! This program is distributed in the hope that it will be useful,
-+! but WITHOUT ANY WARRANTY; without even the implied warranty of
-+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+! GNU General Public License for more details.
-+!
-+! You should have received a copy of the GNU General Public License
-+! along with this program; if not, write to the Free Software
-+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+!
-+! File written by Alan Matsuoka.
-+
-+program repro
-+
-+  type small_stride
-+     character*40 long_string
-+     integer      small_pad
-+  end type small_stride
 +
-+  type(small_stride), dimension (20), target :: unpleasant
-+  character*40, pointer, dimension(:):: c40pt
++      .uleb128        5                       /* Abbrev code */
++      .uleb128        0x34                    /* DW_TAG_variable */
++      .byte           0x0                     /* no_children */
++      .uleb128        0x34                    /* DW_AT_artificial */
++      .uleb128        0x0c                    /* DW_FORM_flag */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .uleb128        0x02                    /* DW_AT_location */
++      .uleb128        0x06                    /* DW_FORM_data4 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
 +
-+  integer i
++      .uleb128        6                       /* Abbrev code */
++      .uleb128        0x34                    /* DW_TAG_variable */
++      .byte           0x0                     /* no_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .uleb128        0x2                     /* DW_AT_location */
++      .uleb128        0xa                     /* DW_FORM_block1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
 +
-+  do i = 0,19
-+     unpleasant(i+1)%small_pad = i+1
-+     unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
-+  end do
++      .uleb128        7                       /* Abbrev code */
++      .uleb128        0x34                    /* DW_TAG_variable */
++      .byte           0x0                     /* no_children */
++      .uleb128        0x34                    /* DW_AT_artificial */
++      .uleb128        0x0c                    /* DW_FORM_flag */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
 +
-+  c40pt => unpleasant%long_string
++      .uleb128        8                       /* Abbrev code */
++      .uleb128        0x21                    /* DW_TAG_subrange_type with block */
++      .byte           0x0                     /* no children */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .uleb128        0x22                    /* DW_AT_lower_bound */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .uleb128        0x2f                    /* DW_AT_upper_bound */
++      .uleb128        0xa                     /* DW_FORM_block1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
 +
-+  print *, c40pt  ! break-here
++      .byte           0x0                     /* Terminator */
 +
-+end program repro
-diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
++/* String table */
++      .section .debug_str
++.Lproducer:
++      .string         "GNU C 3.3.3"
++.Lchar_str:
++      .string         "char"
++.Luint_str:
++      .string         "unsigned int"
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
 new file mode 100644
-index 0000000..0ccebe0
+index 0000000..815ed93
 --- /dev/null
-+++ b/gdb/testsuite/gdb.fortran/dynamic.exp
-@@ -0,0 +1,145 @@
-+# Copyright 2007 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
+@@ -0,0 +1,54 @@
++# Copyright 2010 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 2 of the License, or
++# the Free Software Foundation; either version 3 of the License, or
 +# (at your option) any later version.
-+# 
++#
 +# This program is distributed in the hope that it will be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
-+# 
++#
 +# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
-+
-+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
-+
-+# This file is part of the gdb testsuite.  It contains tests for dynamically
-+# allocated Fortran arrays.
-+# It depends on the GCC dynamic Fortran arrays DWARF support:
-+#     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+set testfile "dynamic"
-+set srcfile ${testfile}.f90
-+set binfile ${objdir}/${subdir}/${testfile}
++# Test printing variable with dynamic bounds which reference a different
++# (artificial in the GCC case) variable containing loclist as its location.
++# This testcase uses value (not address) of the referenced variable:
++# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43762
 +
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
-+    untested "Couldn't compile ${srcfile}"
-+    return -1
++# This test can only be run on targets which support DWARF-2 and use gas.
++# For now pick a sampling of likely targets.
++if {![istarget *-*-linux*]
++    && ![istarget *-*-gnu*]
++    && ![istarget *-*-elf*]
++    && ![istarget *-*-openbsd*]
++    && ![istarget arm-*-eabi*]
++    && ![istarget powerpc-*-eabi*]} {
++    return 0
 +}
 +
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+
-+if ![runto MAIN__] then {
-+    perror "couldn't run to breakpoint MAIN__"
-+    continue
++set testfile dw2-bound-loclist
++if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
++    return -1
 +}
 +
-+gdb_breakpoint [gdb_get_line_number "varx-init"]
-+gdb_continue_to_breakpoint "varx-init"
-+gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
-+gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
-+gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) unallocated"
-+gdb_test "p varx(1,5,17)=1" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17)=1 unallocated"
-+gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) unallocated"
-+
-+gdb_breakpoint [gdb_get_line_number "varx-allocated"]
-+gdb_continue_to_breakpoint "varx-allocated"
-+# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
-+gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
-+# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
-+gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
-+
-+gdb_breakpoint [gdb_get_line_number "varx-filled"]
-+gdb_continue_to_breakpoint "varx-filled"
-+gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
-+gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
-+gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
-+gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
-+# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
-+gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv unassociated"
-+gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv unassociated"
-+
-+gdb_breakpoint [gdb_get_line_number "varv-associated"]
-+gdb_continue_to_breakpoint "varv-associated"
-+gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
-+gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
-+# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
-+gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
-+gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
-+# Intel Fortran Compiler 10.1.008 uses the pointer type.
-+gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
-+
-+gdb_breakpoint [gdb_get_line_number "varv-filled"]
-+gdb_continue_to_breakpoint "varv-filled"
-+gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
-+gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
-+
-+gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
-+gdb_continue_to_breakpoint "varv-deassociated"
-+# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
-+gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv deassociated"
-+gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv deassociated"
-+gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
-+gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
-+gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
-+
-+gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
-+gdb_continue_to_breakpoint "varx-deallocated"
-+gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
-+gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
-+gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
-+gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) deallocated"
-+gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) deallocated"
-+
-+gdb_breakpoint [gdb_get_line_number "vary-passed"]
-+gdb_continue_to_breakpoint "vary-passed"
-+# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
-+gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
-+
-+gdb_breakpoint [gdb_get_line_number "vary-filled"]
-+gdb_continue_to_breakpoint "vary-filled"
-+gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
-+gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
-+gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
-+gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
-+# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
-+gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
-+
-+gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
-+gdb_continue_to_breakpoint "varw-almostfilled"
-+gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
-+gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
-+# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
-+gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
-+# "up" works with GCC but other Fortran compilers may copy the values into the
-+# outer function only on the exit of the inner function.
-+# We need both variants as depending on the arch we optionally may still be
-+# executing the caller line or not after `finish'.
-+gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
-+gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
-+gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
-+gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
-+gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
++# Verify it behaves at least as an unbound array without inferior.
 +
-+gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
-+gdb_continue_to_breakpoint "varz-almostfilled"
-+# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
-+gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
-+# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
-+# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
-+gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
-+gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
-+gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
-+gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
-+# maps to foo::vary(1,1)
-+gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
-+# maps to foo::vary(2,2)
-+gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
-+# maps to foo::vary(1,3)
-+gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
-diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
-new file mode 100644
-index 0000000..0f43564
---- /dev/null
-+++ b/gdb/testsuite/gdb.fortran/dynamic.f90
-@@ -0,0 +1,98 @@
-+! Copyright 2007 Free Software Foundation, Inc.
-+!
-+! This program is free software; you can redistribute it and/or modify
-+! it under the terms of the GNU General Public License as published by
-+! the Free Software Foundation; either version 2 of the License, or
-+! (at your option) any later version.
-+!
-+! This program is distributed in the hope that it will be useful,
-+! but WITHOUT ANY WARRANTY; without even the implied warranty of
-+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+! GNU General Public License for more details.
-+!
-+! You should have received a copy of the GNU General Public License
-+! along with this program; if not, write to the Free Software
-+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+!
-+! Ihis file is the Fortran source file for dynamic.exp.
-+! Original file written by Jakub Jelinek <jakub@redhat.com>.
-+! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
++gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"}
++gdb_test "ptype a_string" {type = char \[\]}
 +
-+subroutine baz
-+  real, target, allocatable :: varx (:, :, :)
-+  real, pointer :: varv (:, :, :)
-+  real, target :: varu (1, 2, 3)
-+  logical :: l
-+  allocate (varx (1:6, 5:15, 17:28))            ! varx-init
-+  l = allocated (varx)
-+  varx(:, :, :) = 6                             ! varx-allocated
-+  varx(1, 5, 17) = 7
-+  varx(2, 6, 18) = 8
-+  varx(6, 15, 28) = 9
-+  varv => varx                                  ! varx-filled
-+  l = associated (varv)
-+  varv(3, 7, 19) = 10                           ! varv-associated
-+  varv => null ()                               ! varv-filled
-+  l = associated (varv)
-+  deallocate (varx)                             ! varv-deassociated
-+  l = allocated (varx)
-+  varu(:, :, :) = 10                            ! varx-deallocated
-+  allocate (varv (1:6, 5:15, 17:28))
-+  l = associated (varv)
-+  varv(:, :, :) = 6
-+  varv(1, 5, 17) = 7
-+  varv(2, 6, 18) = 8
-+  varv(6, 15, 28) = 9
-+  deallocate (varv)
-+  l = associated (varv)
-+  varv => varu
-+  varv(1, 1, 1) = 6
-+  varv(1, 2, 3) = 7
-+  l = associated (varv)
-+end subroutine baz
-+subroutine foo (vary, varw)
-+  real :: vary (:, :)
-+  real :: varw (:, :, :)
-+  vary(:, :) = 4                                ! vary-passed
-+  vary(1, 1) = 8
-+  vary(2, 2) = 9
-+  vary(1, 3) = 10
-+  varw(:, :, :) = 5                             ! vary-filled
-+  varw(1, 1, 1) = 6
-+  varw(2, 2, 2) = 7                             ! varw-almostfilled
-+end subroutine foo
-+subroutine bar (varz, vart)
-+  real :: varz (*)
-+  real :: vart (2:11, 7:*)
-+  varz(1:3) = 4
-+  varz(2) = 5                                   ! varz-almostfilled
-+  vart(2,7) = vart(2,7)
-+end subroutine bar
-+program test
-+  interface
-+    subroutine foo (vary, varw)
-+    real :: vary (:, :)
-+    real :: varw (:, :, :)
-+    end subroutine
-+  end interface
-+  interface
-+    subroutine bar (varz, vart)
-+    real :: varz (*)
-+    real :: vart (2:11, 7:*)
-+    end subroutine
-+  end interface
-+  real :: x (10, 10), y (5), z(8, 8, 8)
-+  x(:,:) = 1
-+  y(:) = 2
-+  z(:,:,:) = 3
-+  call baz
-+  call foo (x, z(2:6, 4:7, 6:8))
-+  call bar (y, x)
-+  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
-+  if (x (1, 3) .ne. 10) call abort
-+  if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
-+  if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
-+  call foo (transpose (x), z)
-+  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
-+  if (x (3, 1) .ne. 10) call abort
-+end
-diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
++# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
++if ![runto "*main"] {
++    return -1
++}
++
++gdb_test "p a_string" { = "seen"}
++gdb_test "ptype a_string" {type = char \[4\]}
++
++gdb_test "p b_string" { = (0x[0-9a-f]+ )?"seennotseen"}
++gdb_test "ptype b_string" {type = char \[\]}
++
++# The register contains unpredictable value - the array size.
++gdb_test "ptype reg_string" {type = char \[-?[0-9]+\]}
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.c b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
 new file mode 100644
-index 0000000..b1120c3
+index 0000000..1f02d90
 --- /dev/null
-+++ b/gdb/testsuite/gdb.fortran/string.exp
-@@ -0,0 +1,59 @@
-+# Copyright 2008 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
+@@ -0,0 +1,42 @@
++/* This testcase is part of GDB, the GNU debugger.
++
++   Copyright 2004 Free Software Foundation, Inc.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 2 of the License, or
++   (at your option) any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++ 
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software
++   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
++   USA.  */
++
++
++/* The function `func1' traced into must have debug info on offset > 0;
++   (DW_UNSND (attr)).  This is the reason of `func0' existence.  */
++
++void
++func0(int a, int b)
++{
++}
++
++/* `func1' being traced into must have some arguments to dump.  */
++
++void
++func1(int a, int b)
++{
++  func0 (a,b);
++}
++
++int
++main(void)
++{
++  func1 (1, 2);
++  return 0;
++}
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
+new file mode 100644
+index 0000000..1c6e84a
+--- /dev/null
++++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
+@@ -0,0 +1,79 @@
++# Copyright 2006 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -14117,115 +11798,166 @@ index 0000000..b1120c3
 +# 
 +# You should have received a copy of the GNU General Public License
 +# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
++# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 +
-+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
++# Minimal DWARF-2 unit test
 +
-+# This file is part of the gdb testsuite.  It contains tests for Fortran
-+# strings with dynamic length.
++# This test can only be run on targets which support DWARF-2.
++# For now pick a sampling of likely targets.
++if {![istarget *-*-linux*]
++    && ![istarget *-*-gnu*]
++    && ![istarget *-*-elf*]
++    && ![istarget *-*-openbsd*]
++    && ![istarget arm-*-eabi*]
++    && ![istarget powerpc-*-eabi*]} {
++    return 0  
++}
 +
-+set testfile "string"
-+set srcfile ${testfile}.f90
-+set binfile ${objdir}/${subdir}/${testfile}
++set testfile "dw2-stripped"
++set srcfile ${testfile}.c
++set binfile ${objdir}/${subdir}/${testfile}.x
 +
-+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
-+    untested "Couldn't compile ${srcfile}"
++remote_exec build "rm -f ${binfile}"
++
++# get the value of gcc_compiled
++if [get_compiler_info ${binfile}] {
++    return -1
++}
++
++# This test can only be run on gcc as we use additional_flags=FIXME
++if {$gcc_compiled == 0} {
++    return 0
++}
++
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
 +    return -1
 +}
 +
++remote_exec build "objcopy -R .debug_loc ${binfile}"
++set strip_output [remote_exec build "objdump -h ${binfile}"]
++
++set test "stripping test file preservation"
++if [ regexp ".debug_info " $strip_output]  {
++    pass "$test (.debug_info preserved)"
++} else {
++    fail "$test (.debug_info got also stripped)"
++}
++
++set test "stripping test file functionality"
++if [ regexp ".debug_loc " $strip_output]  {
++    fail "$test (.debug_loc still present)"
++} else {
++    pass "$test (.debug_loc stripped)"
++}
++
 +gdb_exit
 +gdb_start
 +gdb_reinitialize_dir $srcdir/$subdir
 +gdb_load ${binfile}
 +
-+if ![runto MAIN__] then {
-+    perror "couldn't run to breakpoint MAIN__"
-+    continue
-+}
-+
-+gdb_breakpoint [gdb_get_line_number "var-init"]
-+gdb_continue_to_breakpoint "var-init"
-+gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
-+gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
-+gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
-+gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
-+gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
-+gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
-+gdb_test "p c" "\\$\[0-9\]* = 'c'"
-+gdb_test "p d" "\\$\[0-9\]* = 'd       '"
-+gdb_test "p e" "\\$\[0-9\]* = 'g   '"
-+gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\)"
-+gdb_test "p *e" "Attempt to take contents of a non-pointer value."
-+gdb_test "p *f" "Attempt to take contents of a non-pointer value."
++# For C programs, "start" should stop in main().
 +
-+gdb_breakpoint [gdb_get_line_number "var-finish"]
-+gdb_continue_to_breakpoint "var-finish"
-+gdb_test "p e" "\\$\[0-9\]* = 'e   '" "p e re-set"
-+gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\( 'f2  ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\( 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\)" "p *f re-set"
-diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
++gdb_test "start" \
++         ".*main \\(\\) at .*" \
++         "start"
++gdb_test "step" \
++         "func.* \\(.*\\) at .*" \
++         "step"
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
 new file mode 100644
-index 0000000..226dc5d
+index 0000000..5fcdd84
 --- /dev/null
-+++ b/gdb/testsuite/gdb.fortran/string.f90
-@@ -0,0 +1,37 @@
-+! Copyright 2008 Free Software Foundation, Inc.
-+!
-+! This program is free software; you can redistribute it and/or modify
-+! it under the terms of the GNU General Public License as published by
-+! the Free Software Foundation; either version 2 of the License, or
-+! (at your option) any later version.
-+!
-+! This program is distributed in the hope that it will be useful,
-+! but WITHOUT ANY WARRANTY; without even the implied warranty of
-+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+! GNU General Public License for more details.
-+!
-+! You should have received a copy of the GNU General Public License
-+! along with this program; if not, write to the Free Software
-+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+!
-+! Ihis file is the Fortran source file for dynamic.exp.
-+! Original file written by Jakub Jelinek <jakub@redhat.com>.
-+! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
++++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
+@@ -0,0 +1,83 @@
++/* This testcase is part of GDB, the GNU debugger.
++
++   Copyright 2009 Free Software Foundation, Inc.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
++
++/* Debug information */
++
++      .section .debug_info
++.Lcu1_begin:
++      /* CU header */
++      .4byte  .Lcu1_end - .Lcu1_start         /* Length of Compilation Unit */
++.Lcu1_start:
++      .2byte  2                               /* DWARF Version */
++      .4byte  .Labbrev1_begin                 /* Offset into abbrev section */
++      .byte   4                               /* Pointer size */
++
++      /* CU die */
++      .uleb128 1                              /* Abbrev: DW_TAG_compile_unit */
++      .ascii  "dw2-struct-member-data-location.c\0"   /* DW_AT_name */
++      .ascii  "GNU C 4.3.2\0"                 /* DW_AT_producer */
++      .byte   1                               /* DW_AT_language (C) */
++
++.Ltype_uchar:
++      .uleb128        2                       /* Abbrev: DW_TAG_structure_type */
++      .ascii          "some_struct\0"         /* DW_AT_name */
++
++      .uleb128        3                       /* Abbrev: DW_TAG_member */
++      .ascii          "field\0"               /* DW_AT_name */
++      .byte           0                       /* DW_AT_data_member_location */
++
++      .byte           0                       /* End of children of some_struct */
++
++      .byte           0                       /* End of children of CU */
++
++.Lcu1_end:
++
++/* Abbrev table */
++      .section .debug_abbrev
++.Labbrev1_begin:
++      .uleb128        1                       /* Abbrev code */
++      .uleb128        0x11                    /* DW_TAG_compile_unit */
++      .byte           1                       /* has_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x25                    /* DW_AT_producer */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x13                    /* DW_AT_language */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .uleb128        2                       /* Abbrev code */
++      .uleb128        0x13                    /* DW_TAG_structure_type */
++      .byte           1                       /* has_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .uleb128        3                       /* Abbrev code */
++      .uleb128        0x0d                    /* DW_TAG_member */
++      .byte           0                       /* has_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x38                    /* DW_AT_data_member_location */
++      .uleb128        0x0b                    /* DW_FORM_data1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
 +
-+subroutine foo (e, f)
-+  character (len=1) :: c
-+  character (len=8) :: d
-+  character (len=*) :: e
-+  character (len=*) :: f (1:7, 8:10)
-+  c = 'c'
-+  d = 'd'
-+  e = 'e'                                       ! var-init
-+  f = 'f'
-+  f(1,9) = 'f2'
-+  c = 'c'                                       ! var-finish
-+end subroutine foo
-+  character (len=4) :: g, h (1:7, 8:10)
-+  g = 'g'
-+  h = 'h'
-+  call foo (g, h)
-+end
-diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
-index fc8bccc..e053813 100644
---- a/gdb/testsuite/gdb.gdb/selftest.exp
-+++ b/gdb/testsuite/gdb.gdb/selftest.exp
-@@ -92,6 +92,10 @@ proc do_steps_and_nexts {} {
-               set description "step over ttyarg initialization"
-               set command "step"
-           }
-+          -re ".*python_script = 0.*$gdb_prompt $" {
-+              set description "step over python_script initialization"
-+              set command "step"
-+          }
-           -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
-               set description "next over make_command_stats_cleanup and everything it calls"
-               set command "next"
-diff --git a/gdb/testsuite/gdb.java/jnpe.exp b/gdb/testsuite/gdb.java/jnpe.exp
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
 new file mode 100644
-index 0000000..55aa80d
+index 0000000..c41151c
 --- /dev/null
-+++ b/gdb/testsuite/gdb.java/jnpe.exp
-@@ -0,0 +1,74 @@
++++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
+@@ -0,0 +1,37 @@
 +# Copyright 2009 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
@@ -14241,75 +11973,37 @@ index 0000000..55aa80d
 +# You should have received a copy of the GNU General Public License
 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+if $tracelevel then {
-+  strace $tracelevel
-+}
-+
-+load_lib "java.exp"
-+
-+set testfile "jnpe"
-+set srcfile ${testfile}.java
-+set binfile ${objdir}/${subdir}/${testfile}
-+if  { [compile_java_from_source ${srcdir}/$subdir/${srcfile} ${binfile} "-g"] != "" } {
-+    untested "Couldn't compile ${srcdir}/$subdir/${srcfile}"
-+    return -1
++# This test can only be run on targets which support DWARF-2 and use gas.
++# For now pick a sampling of likely targets.
++if {![istarget *-*-linux*]
++    && ![istarget *-*-gnu*]
++    && ![istarget *-*-elf*]
++    && ![istarget *-*-openbsd*]
++    && ![istarget arm-*-eabi*]
++    && ![istarget powerpc-*-eabi*]} {
++    return 0  
 +}
 +
-+# Start with a fresh gdb.
-+
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+
-+set line [gdb_get_line_number "break here" $testfile.java]
-+gdb_test "break $testfile.java:$line" ""
-+
-+gdb_test "run" \
-+  "// break here.*" \
-+  "run java next-over-throw"
++set testfile "dw2-struct-member-data-location"
++set srcfile ${testfile}.S
++set binfile ${testfile}.x
 +
-+# See whether we have the needed unwinder hooks.
-+set ok 1
-+gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook in java" {
-+    -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
-+      pass "check for unwinder hook in java"
-+    }
-+    -re "No symbol .* in current context.?\r\n$gdb_prompt $" {
-+      # Pass the test so we don't get bogus fails in the results.
-+      setup_xfail *-*-*
-+      fail "check for unwinder hook in java"
-+      set ok 0
-+    }
-+}
-+if {!$ok} {
-+    untested jnpe.exp
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
 +    return -1
 +}
 +
-+gdb_test "handle SIGSEGV nostop noprint" \
-+  "SIGSEGV.*fault" \
-+  "disable SIGSEGV for next-over-NPE"
-+
-+# The line where we stop differ according to gcj; check just we did not already
-+# execute the catch point.
-+
-+gdb_test "next" \
-+  "" \
-+  "next over NPE"
++clean_restart $binfile
 +
-+gdb_breakpoint [gdb_get_line_number "catch point"]
-+gdb_continue_to_breakpoint "catch point" ".*// catch point.*"
-diff --git a/gdb/testsuite/gdb.java/jnpe.java b/gdb/testsuite/gdb.java/jnpe.java
++gdb_test "ptype struct some_struct" "type = struct some_struct {\[\r\n \t\]*void field;\[\r\n \t\]*}"
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S
 new file mode 100644
-index 0000000..3524830
+index 0000000..9dbbf3c
 --- /dev/null
-+++ b/gdb/testsuite/gdb.java/jnpe.java
-@@ -0,0 +1,38 @@
-+// Test next-over-NPE.
++++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S
+@@ -0,0 +1,121 @@
 +/* This testcase is part of GDB, the GNU debugger.
 +
-+   Copyright 2009 Free Software Foundation, Inc.
++   Copyright 2012 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
@@ -14322,136 +12016,373 @@ index 0000000..3524830
 +   GNU General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+   */
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+public class jnpe
-+{
-+  public static String npe ()
-+  {
-+    return ((Object) null).toString();
-+  }
++/* Debug information */
 +
-+  public static void main (String[] args)
-+  {
-+    try
-+      {
-+      System.out.println (npe ()); // break here
-+      }
-+    catch (NullPointerException n)
-+      {
-+      System.out.println ("success"); // catch point
-+      }
-+  }
++      .section        .data
++vardata:
++      .rept           129
++      .ascii          "x"
++      .endr
++      .ascii          "UNSEEN\0"
++
++      .section        .debug_info
++.Lcu1_begin:
++      .4byte          .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */
++.Lcu1_start:
++      .2byte          2                       /* DWARF version number */
++      .4byte          .Ldebug_abbrev0         /* Offset Into Abbrev. Section */
++      .byte           4                       /* Pointer Size (in bytes) */
++
++      /* CU die */
++      .uleb128        1                       /* Abbrev: DW_TAG_compile_unit */
++      .ascii          "GNU C 3.3.3\0"         /* DW_AT_producer */
++      .byte           2                       /* DW_AT_language (C) -  */
++
++.Larray_type:
++      .uleb128        2                       /* Abbrev: DW_TAG_array_type */
++      .4byte          .Lchar_type-.Lcu1_begin /* DW_AT_type */
++
++      .uleb128        8                       /* Abbrev: DW_TAG_subrange_type without DW_AT_type */
++      .byte           0                       /* DW_AT_lower_bound */
++      .byte           128                     /* DW_AT_upper_bound */
++
++      .byte           0                       /* End of children of die */
++
++.Lchar_type:
++      .uleb128        4                       /* Abbrev: DW_TAG_base_type */
++      .ascii          "char\0"                /* DW_AT_name */
++      .byte           1                       /* DW_AT_byte_size */
++      .byte           6                       /* DW_AT_encoding */
++
++      .uleb128        6                       /* Abbrev: DW_TAG_variable DW_FORM_string */
++      .ascii          "notype_string\0"       /* DW_AT_name */
++      .4byte          .Larray_type-.Lcu1_begin /* DW_AT_type */
++      .byte           2f - 1f                 /* DW_AT_location */
++1:    .byte           3                       /*   DW_OP_addr */
++      .4byte          vardata                 /*   <addr> */
++2:
++
++      .byte           0                       /* End of children of CU */
++.Lcu1_end:
++
++      .section .debug_abbrev
++.Ldebug_abbrev0:
++      .uleb128        1                       /* Abbrev code */
++      .uleb128        0x11                    /* DW_TAG_compile_unit */
++      .byte           0x1                     /* has_children */
++      .uleb128        0x25                    /* DW_AT_producer */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x13                    /* DW_AT_language */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .uleb128        2                       /* Abbrev code */
++      .uleb128        0x1                     /* TAG: DW_TAG_array_type */
++      .byte           0x1                     /* DW_children_yes */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .uleb128        4                       /* Abbrev code */
++      .uleb128        0x24                    /* DW_TAG_base_type */
++      .byte           0x0                     /* no_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0xb                     /* DW_AT_byte_size */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .uleb128        0x3e                    /* DW_AT_encoding */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .uleb128        6                       /* Abbrev code */
++      .uleb128        0x34                    /* DW_TAG_variable */
++      .byte           0x0                     /* no_children */
++      .uleb128        0x3                     /* DW_AT_name */
++      .uleb128        0x8                     /* DW_FORM_string */
++      .uleb128        0x49                    /* DW_AT_type */
++      .uleb128        0x13                    /* DW_FORM_ref4 */
++      .uleb128        0x2                     /* DW_AT_location */
++      .uleb128        0xa                     /* DW_FORM_block1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .uleb128        8                       /* Abbrev code */
++      .uleb128        0x21                    /* DW_TAG_subrange_type without DW_AT_type */
++      .byte           0x0                     /* no children */
++      .uleb128        0x22                    /* DW_AT_lower_bound */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .uleb128        0x2f                    /* DW_AT_upper_bound */
++      .uleb128        0xb                     /* DW_FORM_data1 */
++      .byte           0x0                     /* Terminator */
++      .byte           0x0                     /* Terminator */
++
++      .byte           0x0                     /* Terminator */
+diff --git a/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp
+new file mode 100644
+index 0000000..a13e346
+--- /dev/null
++++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp
+@@ -0,0 +1,39 @@
++# Copyright 2012 Free Software Foundation, Inc.
++
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
++load_lib dwarf.exp
++
++# https://bugzilla.redhat.com/show_bug.cgi?id=806920
++# read_subrange_type <TYPE_CODE (base_type) == TYPE_CODE_VOID> reinitialization
++# of BASE_TYPE was done too late, it affects DW_TAG_subrange_type without
++# specified DW_AT_type, present only in XLF produced code.
++
++# This test can only be run on targets which support DWARF-2 and use gas.
++if {![dwarf2_support]} {
++    return 0  
 +}
-diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
++
++set testfile dw2-subrange-no-type
++set srcfile ${testfile}.S
++set executable ${testfile}.x
++set binfile ${objdir}/${subdir}/${executable}
++
++if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {}] != "" } {
++    return -1
++}
++
++clean_restart $executable
++
++gdb_test "ptype notype_string" {type = char \[129\]}
++gdb_test "p notype_string" " = 'x' <repeats 129 times>"
+diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.exp b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
 new file mode 100644
-index 0000000..729f457
+index 0000000..d7b8bea
 --- /dev/null
-+++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
-@@ -0,0 +1,22 @@
-+/* This file is part of GDB, the GNU debugger.
++++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
+@@ -0,0 +1,42 @@
++# Copyright 2009 Free Software Foundation, Inc.
 +
-+   Copyright 2009 Free Software Foundation, Inc.
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 2 of the License, or
++# (at your option) any later version.
++# 
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++# 
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 +
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
++# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
 +
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
++# This file is part of the gdb testsuite.  Array element stride must not be
++# specified in the number of elements but in a number of bytes instead.
++# Original problem:
++# (gdb) p c40pt(1)
++# $1 = '0-hello', ' ' <repeats 33 times>
++# (gdb) p c40pt(2)
++# warning: Fortran array stride not divisible by the element size
 +
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
++set testfile dwarf-stride
++set srcfile ${testfile}.f90
 +
-+int
-+func (int *arr)
-+{
-+  return arr[0];
++if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}] } {
++    return -1
 +}
-diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
++
++if ![runto MAIN__] then {
++    perror "couldn't run to breakpoint MAIN__"
++    continue
++}
++
++gdb_breakpoint [gdb_get_line_number "break-here"]
++gdb_continue_to_breakpoint "break-here" ".*break-here.*"
++gdb_test "p c40pt(1)" " = '0-hello.*"
++gdb_test "p c40pt(2)" " = '1-hello.*"
+diff --git a/gdb/testsuite/gdb.fortran/dwarf-stride.f90 b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
 new file mode 100644
-index 0000000..3090e7e
+index 0000000..e492b3a
 --- /dev/null
-+++ b/gdb/testsuite/gdb.opt/array-from-register.c
-@@ -0,0 +1,28 @@
-+/* This file is part of GDB, the GNU debugger.
++++ b/gdb/testsuite/gdb.fortran/dwarf-stride.f90
+@@ -0,0 +1,40 @@
++! Copyright 2009 Free Software Foundation, Inc.
++!
++! This program is free software; you can redistribute it and/or modify
++! it under the terms of the GNU General Public License as published by
++! the Free Software Foundation; either version 2 of the License, or
++! (at your option) any later version.
++!
++! This program is distributed in the hope that it will be useful,
++! but WITHOUT ANY WARRANTY; without even the implied warranty of
++! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++! GNU General Public License for more details.
++!
++! You should have received a copy of the GNU General Public License
++! along with this program; if not, write to the Free Software
++! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++!
++! File written by Alan Matsuoka.
 +
-+   Copyright 2009 Free Software Foundation, Inc.
++program repro
 +
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 3 of the License, or
-+   (at your option) any later version.
++  type small_stride
++     character*40 long_string
++     integer      small_pad
++  end type small_stride
 +
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
++  type(small_stride), dimension (20), target :: unpleasant
++  character*40, pointer, dimension(:):: c40pt
 +
-+   You should have received a copy of the GNU General Public License
-+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
++  integer i
 +
-+extern int func (int *arr);
++  do i = 0,19
++     unpleasant(i+1)%small_pad = i+1
++     unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
++  end do
 +
-+int
-+main (void)
-+{
-+  int arr[] = { 42 };
++  c40pt => unpleasant%long_string
 +
-+  func (arr);
++  print *, c40pt  ! break-here
 +
-+  return 0;
-+}
-diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
++end program repro
+diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90 b/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
 new file mode 100644
-index 0000000..f2de718
+index 0000000..261ce17
 --- /dev/null
-+++ b/gdb/testsuite/gdb.opt/array-from-register.exp
-@@ -0,0 +1,33 @@
-+# Copyright 2009 Free Software Foundation, Inc.
-+#
++++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame-stub.f90
+@@ -0,0 +1,24 @@
++! Copyright 2010 Free Software Foundation, Inc.
++!
++! This program is free software; you can redistribute it and/or modify
++! it under the terms of the GNU General Public License as published by
++! the Free Software Foundation; either version 2 of the License, or
++! (at your option) any later version.
++!
++! This program is distributed in the hope that it will be useful,
++! but WITHOUT ANY WARRANTY; without even the implied warranty of
++! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++! GNU General Public License for more details.
++!
++! You should have received a copy of the GNU General Public License
++! along with this program; if not, write to the Free Software
++! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++!
++! Ihis file is the Fortran source file for dynamic.exp.
++! Original file written by Jakub Jelinek <jakub@redhat.com>.
++! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
++
++subroutine bar
++  real :: dummy
++  dummy = 1
++end subroutine bar
+diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp b/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
+new file mode 100644
+index 0000000..fa41b80
+--- /dev/null
++++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame.exp
+@@ -0,0 +1,37 @@
++# Copyright 2010 Free Software Foundation, Inc.
++
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
 +# the Free Software Foundation; either version 2 of the License, or
 +# (at your option) any later version.
-+#
++# 
 +# This program is distributed in the hope that it will be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
-+#
++# 
 +# You should have received a copy of the GNU General Public License
 +# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-+#
-+# This file is part of the gdb testsuite.
++# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 +
-+if { [prepare_for_testing array-from-register.exp "array-from-register"      \
-+                        {array-from-register.c array-from-register-func.c} \
-+                        {debug optimize=-O2}] } {
++set testfile "dynamic-other-frame"
++set srcfile1 ${testfile}.f90
++set srcfile2 ${testfile}-stub.f90
++set objfile2 ${objdir}/${subdir}/${testfile}-stub.o
++set executable ${testfile}
++set binfile ${objdir}/${subdir}/${executable}
++
++if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${objfile2}" object {f90}] != ""
++     || [gdb_compile "${srcdir}/${subdir}/${srcfile1} ${objfile2}" "${binfile}" executable {debug f90}] != "" } {
++    untested "Couldn't compile ${srcfile1} or ${srcfile2}"
 +    return -1
 +}
 +
-+if ![runto func] then {
-+    return -1
++clean_restart ${executable}
++
++if ![runto bar_] then {
++    perror "couldn't run to bar_"
++    continue
 +}
 +
-+gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
++gdb_test "bt" {foo \(string='hello'.*}
+diff --git a/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90 b/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
+new file mode 100644
+index 0000000..2bc637d
+--- /dev/null
++++ b/gdb/testsuite/gdb.fortran/dynamic-other-frame.f90
+@@ -0,0 +1,36 @@
++! Copyright 2010 Free Software Foundation, Inc.
++!
++! This program is free software; you can redistribute it and/or modify
++! it under the terms of the GNU General Public License as published by
++! the Free Software Foundation; either version 2 of the License, or
++! (at your option) any later version.
++!
++! This program is distributed in the hope that it will be useful,
++! but WITHOUT ANY WARRANTY; without even the implied warranty of
++! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++! GNU General Public License for more details.
++!
++! You should have received a copy of the GNU General Public License
++! along with this program; if not, write to the Free Software
++! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++!
++! Ihis file is the Fortran source file for dynamic.exp.
++! Original file written by Jakub Jelinek <jakub@redhat.com>.
++! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
 +
-+# Seen regression:
-+# Address requested for identifier "arr" which is in register $rdi
-+gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
-diff --git a/gdb/testsuite/gdb.opt/fortran-string.exp b/gdb/testsuite/gdb.opt/fortran-string.exp
++subroutine foo (string)
++  interface
++    subroutine bar
++    end subroutine
++  end interface
++  character string*(*)
++  call bar                                ! stop-here
++end subroutine foo
++program test
++  interface
++    subroutine foo (string)
++    character string*(*)
++    end subroutine
++  end interface
++  call foo ('hello')
++end
+diff --git a/gdb/testsuite/gdb.fortran/dynamic.exp b/gdb/testsuite/gdb.fortran/dynamic.exp
 new file mode 100644
-index 0000000..f997eec
+index 0000000..e79e94a
 --- /dev/null
-+++ b/gdb/testsuite/gdb.opt/fortran-string.exp
-@@ -0,0 +1,41 @@
-+# Copyright 2009 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.fortran/dynamic.exp
+@@ -0,0 +1,152 @@
++# Copyright 2007 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -14469,36 +12400,147 @@ index 0000000..f997eec
 +
 +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
 +
-+# Test GDB can cope with Fortran strings having their length present in a CPU
-+# register.  With -O0 the string length is passed on the stack.  To make this
-+# test meaningful the follow assertion should pass.  It is not being checked
-+# here as the "_s" symbol is compiler dependent:
-+#   (gdb) info address _s
-+#   Symbol "_s" is a variable in register XX.
++# This file is part of the gdb testsuite.  It contains tests for dynamically
++# allocated Fortran arrays.
++# It depends on the GCC dynamic Fortran arrays DWARF support:
++#     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22244
++
++set testfile "dynamic"
++set srcfile ${testfile}.f90
++set binfile ${objdir}/${subdir}/${testfile}
 +
-+set test fortran-string
-+set srcfile ${test}.f90
-+if { [prepare_for_testing ${test}.exp ${test} ${srcfile} {debug f77 additional_flags=-O2}] } {
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f90 quiet}] != "" } {
++    untested "Couldn't compile ${srcfile}"
 +    return -1
 +}
 +
++gdb_exit
++gdb_start
++gdb_reinitialize_dir $srcdir/$subdir
++gdb_load ${binfile}
++
 +if ![runto MAIN__] then {
 +    perror "couldn't run to breakpoint MAIN__"
 +    continue
 +}
 +
-+gdb_breakpoint [gdb_get_line_number "s = s"]
-+gdb_continue_to_breakpoint "s = s"
-+gdb_test "frame" ".*s='foo'.*"
-+gdb_test "ptype s" "type = character\\*3"
-+gdb_test "p s" "\\$\[0-9\]* = 'foo'"
-diff --git a/gdb/testsuite/gdb.opt/fortran-string.f90 b/gdb/testsuite/gdb.opt/fortran-string.f90
++gdb_breakpoint [gdb_get_line_number "varx-init"]
++gdb_continue_to_breakpoint "varx-init"
++gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx unallocated"
++gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx unallocated"
++gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) unallocated"
++gdb_test "p varx(1,5,17)=1" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17)=1 unallocated"
++gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) unallocated"
++
++gdb_breakpoint [gdb_get_line_number "varx-allocated"]
++gdb_continue_to_breakpoint "varx-allocated"
++# $1 = (( ( 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0) --- , 0) ) ( ( 0, 0, ...) ...) ...)
++gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx allocated"
++# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
++gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varx allocated"
++
++gdb_breakpoint [gdb_get_line_number "varx-filled"]
++gdb_continue_to_breakpoint "varx-filled"
++gdb_test "p varx(2, 5, 17)" "\\$\[0-9\]* = 6"
++gdb_test "p varx(1, 5, 17)" "\\$\[0-9\]* = 7"
++gdb_test "p varx(2, 6, 18)" "\\$\[0-9\]* = 8"
++gdb_test "p varx(6, 15, 28)" "\\$\[0-9\]* = 9"
++# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
++gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv unassociated"
++gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv unassociated"
++
++set test "output varx"
++gdb_test_multiple $test $test {
++    -re "^output varx\r\n\[() ,6789.\]*$gdb_prompt $" {
++      pass $test
++    }
++}
++
++gdb_breakpoint [gdb_get_line_number "varv-associated"]
++gdb_continue_to_breakpoint "varv-associated"
++gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 6" "p varx(3, 7, 19) with varv associated"
++gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 6" "p varv(3, 7, 19) associated"
++# Intel Fortran Compiler 10.1.008 uses -1 there, GCC uses 1.
++gdb_test "p l" "\\$\[0-9\]* = (\\.TRUE\\.|4294967295)" "p l if varv associated"
++gdb_test "ptype varx" "type = real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)" "ptype varx with varv associated"
++# Intel Fortran Compiler 10.1.008 uses the pointer type.
++gdb_test "ptype varv" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(6,5:15,17:28\\)\\)?" "ptype varv associated"
++
++gdb_breakpoint [gdb_get_line_number "varv-filled"]
++gdb_continue_to_breakpoint "varv-filled"
++gdb_test "p varx(3, 7, 19)" "\\$\[0-9\]* = 10" "p varx(3, 7, 19) with varv filled"
++gdb_test "p varv(3, 7, 19)" "\\$\[0-9\]* = 10" "p varv(3, 7, 19) filled"
++
++gdb_breakpoint [gdb_get_line_number "varv-deassociated"]
++gdb_continue_to_breakpoint "varv-deassociated"
++# The latter one is for the Intel Fortran Compiler 10.1.008 pointer type.
++gdb_test "p varv" "\\$\[0-9\]* = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "p varv deassociated"
++gdb_test "ptype varv" "type = (<(object|the array) is not associated>|.*(Cannot access it|Unable to access the object) because the object is not associated.)" "ptype varv deassociated"
++gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varv deassociated"
++gdb_test "p varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
++gdb_test "ptype varv(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not associated\\."
++
++gdb_breakpoint [gdb_get_line_number "varx-deallocated"]
++gdb_continue_to_breakpoint "varx-deallocated"
++gdb_test "p varx" "\\$\[0-9\]* = <(object|the array) is not allocated>" "p varx deallocated"
++gdb_test "ptype varx" "type = <(object|the array) is not allocated>" "ptype varx deallocated"
++gdb_test "p l" "\\$\[0-9\]* = \\.FALSE\\." "p l if varx deallocated"
++gdb_test "p varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "p varx(1,5,17) deallocated"
++gdb_test "ptype varx(1,5,17)" "(Cannot access it|Unable to access the object) because the (object|array) is not allocated\\." "ptype varx(1,5,17) deallocated"
++
++gdb_breakpoint [gdb_get_line_number "vary-passed"]
++gdb_continue_to_breakpoint "vary-passed"
++# $1 = (( ( 1, 1, 1, 1, 1, 1) ( 1, 1, 1, 1, 1, 1) --- , 1) ) ( ( 1, 1, ...) ...) ...)
++gdb_test "p vary" "\\$\[0-9\]* = \\(\[()1, .\]*\\)"
++
++gdb_breakpoint [gdb_get_line_number "vary-filled"]
++gdb_continue_to_breakpoint "vary-filled"
++gdb_test "ptype vary" "type = real(\\(kind=4\\)|\\*4) \\(10,10\\)"
++gdb_test "p vary(1, 1)" "\\$\[0-9\]* = 8"
++gdb_test "p vary(2, 2)" "\\$\[0-9\]* = 9"
++gdb_test "p vary(1, 3)" "\\$\[0-9\]* = 10"
++# $1 = (( ( 3, 3, 3, 3, 3, 3) ( 3, 3, 3, 3, 3, 3) --- , 3) ) ( ( 3, 3, ...) ...) ...)
++gdb_test "p varw" "\\$\[0-9\]* = \\(\[()3, .\]*\\)"
++
++gdb_breakpoint [gdb_get_line_number "varw-almostfilled"]
++gdb_continue_to_breakpoint "varw-almostfilled"
++gdb_test "ptype varw" "type = real(\\(kind=4\\)|\\*4) \\(5,4,3\\)"
++gdb_test "p varw(3,1,1)=1" "\\$\[0-9\]* = 1"
++# $1 = (( ( 6, 5, 1, 5, 5, 5) ( 5, 5, 5, 5, 5, 5) --- , 5) ) ( ( 5, 5, ...) ...) ...)
++gdb_test "p varw" "\\$\[0-9\]* = \\( *\\( *\\( *6, *5, *1,\[()5, .\]*\\)" "p varw filled"
++# "up" works with GCC but other Fortran compilers may copy the values into the
++# outer function only on the exit of the inner function.
++# We need both variants as depending on the arch we optionally may still be
++# executing the caller line or not after `finish'.
++gdb_test "finish" ".*(call bar \\(y, x\\)|call foo \\(x, z\\(2:6, 4:7, 6:8\\)\\))"
++gdb_test "p z(2,4,5)" "\\$\[0-9\]* = 3"
++gdb_test "p z(2,4,6)" "\\$\[0-9\]* = 6"
++gdb_test "p z(2,4,7)" "\\$\[0-9\]* = 5"
++gdb_test "p z(4,4,6)" "\\$\[0-9\]* = 1"
++
++gdb_breakpoint [gdb_get_line_number "varz-almostfilled"]
++gdb_continue_to_breakpoint "varz-almostfilled"
++# GCC uses the pointer type here, Intel Fortran Compiler 10.1.008 does not.
++gdb_test "ptype varz" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(\\*\\)\\)?"
++# Intel Fortran Compiler 10.1.008 has a bug here - (2:11,7:7)
++# as it produces DW_AT_lower_bound == DW_AT_upper_bound == 7.
++gdb_test "ptype vart" "type = (PTR TO -> \\( )?real(\\(kind=4\\)|\\*4) \\(2:11,7:\\*\\)\\)?"
++gdb_test "p varz" "\\$\[0-9\]* = \\(\\)"
++gdb_test "p vart" "\\$\[0-9\]* = \\(\\)"
++gdb_test "p varz(3)" "\\$\[0-9\]* = 4"
++# maps to foo::vary(1,1)
++gdb_test "p vart(2,7)" "\\$\[0-9\]* = 8"
++# maps to foo::vary(2,2)
++gdb_test "p vart(3,8)" "\\$\[0-9\]* = 9"
++# maps to foo::vary(1,3)
++gdb_test "p vart(2,9)" "\\$\[0-9\]* = 10"
+diff --git a/gdb/testsuite/gdb.fortran/dynamic.f90 b/gdb/testsuite/gdb.fortran/dynamic.f90
 new file mode 100644
-index 0000000..e48d520
+index 0000000..0f43564
 --- /dev/null
-+++ b/gdb/testsuite/gdb.opt/fortran-string.f90
-@@ -0,0 +1,28 @@
-+! Copyright 2009 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.fortran/dynamic.f90
+@@ -0,0 +1,98 @@
++! Copyright 2007 Free Software Foundation, Inc.
 +!
 +! This program is free software; you can redistribute it and/or modify
 +! it under the terms of the GNU General Public License as published by
@@ -14518,337 +12560,199 @@ index 0000000..e48d520
 +! Original file written by Jakub Jelinek <jakub@redhat.com>.
 +! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
 +
-+  subroutine f(s)
-+  character*(*) s
-+  s = s
-+  end
-+
-+  program main
-+  call f ('foo')
-+  end
-diff --git a/gdb/testsuite/gdb.pascal/arrays.exp b/gdb/testsuite/gdb.pascal/arrays.exp
++subroutine baz
++  real, target, allocatable :: varx (:, :, :)
++  real, pointer :: varv (:, :, :)
++  real, target :: varu (1, 2, 3)
++  logical :: l
++  allocate (varx (1:6, 5:15, 17:28))            ! varx-init
++  l = allocated (varx)
++  varx(:, :, :) = 6                             ! varx-allocated
++  varx(1, 5, 17) = 7
++  varx(2, 6, 18) = 8
++  varx(6, 15, 28) = 9
++  varv => varx                                  ! varx-filled
++  l = associated (varv)
++  varv(3, 7, 19) = 10                           ! varv-associated
++  varv => null ()                               ! varv-filled
++  l = associated (varv)
++  deallocate (varx)                             ! varv-deassociated
++  l = allocated (varx)
++  varu(:, :, :) = 10                            ! varx-deallocated
++  allocate (varv (1:6, 5:15, 17:28))
++  l = associated (varv)
++  varv(:, :, :) = 6
++  varv(1, 5, 17) = 7
++  varv(2, 6, 18) = 8
++  varv(6, 15, 28) = 9
++  deallocate (varv)
++  l = associated (varv)
++  varv => varu
++  varv(1, 1, 1) = 6
++  varv(1, 2, 3) = 7
++  l = associated (varv)
++end subroutine baz
++subroutine foo (vary, varw)
++  real :: vary (:, :)
++  real :: varw (:, :, :)
++  vary(:, :) = 4                                ! vary-passed
++  vary(1, 1) = 8
++  vary(2, 2) = 9
++  vary(1, 3) = 10
++  varw(:, :, :) = 5                             ! vary-filled
++  varw(1, 1, 1) = 6
++  varw(2, 2, 2) = 7                             ! varw-almostfilled
++end subroutine foo
++subroutine bar (varz, vart)
++  real :: varz (*)
++  real :: vart (2:11, 7:*)
++  varz(1:3) = 4
++  varz(2) = 5                                   ! varz-almostfilled
++  vart(2,7) = vart(2,7)
++end subroutine bar
++program test
++  interface
++    subroutine foo (vary, varw)
++    real :: vary (:, :)
++    real :: varw (:, :, :)
++    end subroutine
++  end interface
++  interface
++    subroutine bar (varz, vart)
++    real :: varz (*)
++    real :: vart (2:11, 7:*)
++    end subroutine
++  end interface
++  real :: x (10, 10), y (5), z(8, 8, 8)
++  x(:,:) = 1
++  y(:) = 2
++  z(:,:,:) = 3
++  call baz
++  call foo (x, z(2:6, 4:7, 6:8))
++  call bar (y, x)
++  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
++  if (x (1, 3) .ne. 10) call abort
++  if (z (2, 4, 6) .ne. 6 .or. z (3, 5, 7) .ne. 7 .or. z (2, 4, 7) .ne. 5) call abort
++  if (any (y .ne. (/4, 5, 4, 2, 2/))) call abort
++  call foo (transpose (x), z)
++  if (x (1, 1) .ne. 8 .or. x (2, 2) .ne. 9 .or. x (1, 2) .ne. 4) call abort
++  if (x (3, 1) .ne. 10) call abort
++end
+diff --git a/gdb/testsuite/gdb.fortran/string.exp b/gdb/testsuite/gdb.fortran/string.exp
 new file mode 100644
-index 0000000..ccc6e1e
+index 0000000..39de2c4
 --- /dev/null
-+++ b/gdb/testsuite/gdb.pascal/arrays.exp
-@@ -0,0 +1,104 @@
-+# Copyright 2008, 2009 Free Software Foundation, Inc.
-+#
++++ b/gdb/testsuite/gdb.fortran/string.exp
+@@ -0,0 +1,59 @@
++# Copyright 2008 Free Software Foundation, Inc.
++
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
++# the Free Software Foundation; either version 2 of the License, or
 +# (at your option) any later version.
-+#
++# 
 +# This program is distributed in the hope that it will be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
-+#
++# 
 +# You should have received a copy of the GNU General Public License
-+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+
-+if $tracelevel then {
-+    strace $tracelevel
-+}
-+
-+load_lib "pascal.exp"
-+
-+set testfile "arrays"
-+set srcfile ${testfile}.pas
-+set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
-+
-+# These tests only work with fpc, using the -gw3 compile-option
-+pascal_init
-+if { $pascal_compiler_is_fpc != 1 } {
-+  return -1
-+}
-+
-+# Detect if the fpc version is below 2.3.0
-+set fpc_generates_dwarf_for_dynamic_arrays 1
-+if { ($fpcversion_major < 2) || ( ($fpcversion_major == 2) && ($fpcversion_minor < 3))}  {
-+  set fpc_generates_dwarf_for_dynamic_arrays 0
-+}
-+
-+
-+if {[gdb_compile_pascal "-gw3 ${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
-+  return -1
-+}
-+
-+gdb_exit
-+gdb_start
-+gdb_reinitialize_dir $srcdir/$subdir
-+gdb_load ${binfile}
-+set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
-+set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
-+
-+
-+if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
-+    pass "setting breakpoint 1"
-+}
-+if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
-+    pass "setting breakpoint 2"
-+}
-+
-+# Verify that "start" lands inside the right procedure.
-+if { [gdb_start_cmd] < 0 } {
-+    untested start
-+    return -1
-+}
-+
-+gdb_test "" ".* at .*${srcfile}.*" "start"
-+
-+gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
-+
-+gdb_test "print StatArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer type"
-+gdb_test "print StatArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer"
-+
-+gdb_test "cont" "Breakpoint .*:${bp_location2}.*" "Going to second breakpoint"
-+
-+gdb_test "print StatArrChar" ".* = 'abcdefghijkl'" "Print static array of char"
-+gdb_test "print Stat2dArrInt" ".* = \\{\\{0, 1, 2, 3, 4\\}, \\{1, 2, 3, 4, 5\\}, \\{2, 3, 4, 5, 6\\}, \\{3, 4, 5, 6, 7\\}, \\{4, 5, 6, 7, 8\\}, \\{5, 6, 7, 8, 9\\}, \\{6, 7, 8, 9, 10\\}, \\{7, 8, 9, 10, 11\\}, \\{8, 9, 10, 11, 12\\}, \\{9, 10, 11, 12, 13\\}, \\{10, 11, 12, 13, 14\\}, \\{11, 12, 13, 14, 15\\}\\}" "Print static 2-dimensional array of integer"
-+
-+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
-+  setup_xfail "*-*-*"
-+}
-+gdb_test "print DynArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer type"
-+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
-+  setup_xfail "*-*-*"
-+}
-+gdb_test "print DynArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer"
-+
-+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
-+  setup_xfail "*-*-*"
-+}
-+gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char"
-+
-+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
-+  setup_xfail "*-*-*"
-+}
-+gdb_test "print DynArrStr" ".* = \\{'dstr0', 'dstr1', 'dstr2', 'dstr3', 'dstr4', 'dstr5', 'dstr6', 'dstr7', 'dstr8', 'dstr9', 'dstr10', 'dstr11', 'dstr12'\\}" "Print dynamic array of string"
-+
-+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
-+  setup_xfail "*-*-*"
-+}
-+gdb_test "print StatArrStr" ".* = \\{'str0', 'str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9', 'str10', 'str11', 'str12'\\}" "Print static array of string"
-+
-+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
-+  setup_xfail "*-*-*"
-+}
-+gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char"
-+
-diff --git a/gdb/testsuite/gdb.pascal/arrays.pas b/gdb/testsuite/gdb.pascal/arrays.pas
-new file mode 100644
-index 0000000..295602d
---- /dev/null
-+++ b/gdb/testsuite/gdb.pascal/arrays.pas
-@@ -0,0 +1,82 @@
-+{
-+ Copyright 2008, 2009 Free Software Foundation, Inc.
-+
-+ This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 3 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+}
-+
-+program arrays;
-+
-+{$mode objfpc}{$h+}
-+
-+uses sysutils;
-+
-+type TStatArrInt= array[0..11] of integer;
-+     TDynArrInt= array of integer;
-+     TStatArrStr= array[0..12] of string;
-+     TDynArrStr= array of string;
-+     TDynArrChar = array of char;
-+     TStatArrChar = array [0..11] of char;
-+
-+     TStat2dArrInt = array[0..11,0..4] of integer;
-+
-+var StatArrInt: TStatArrInt;
-+    StatArrInt_: Array[0..11] of integer;
-+    DynArrInt:  TDynArrInt;
-+    DynArrInt_: Array of integer;
-+    StatArrStr: TStatArrStr;
-+    DynArrStr: TDynArrStr;
-+    StatArrChar: TStatArrChar;
-+    DynArrChar: TDynArrChar;
-+
-+    Stat2dArrInt: TStat2dArrInt;
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
 +
-+    s: string;
-+      
-+    i,j : integer;
++# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
 +
-+begin
-+  for i := 0 to 11 do
-+    begin
-+    StatArrInt[i]:= i+50;
-+    StatArrInt_[i]:= i+50;
-+    StatArrChar[i]:= chr(ord('a')+i);
-+    for j := 0 to 4 do
-+      Stat2dArrInt[i,j]:=i+j;
-+    end;
-+  writeln(StatArrInt_[0]);
-+  writeln(StatArrInt[0]); { set breakpoint 1 here }
-+  writeln(StatArrChar[0]);
-+  writeln(Stat2dArrInt[0,0]);
++# This file is part of the gdb testsuite.  It contains tests for Fortran
++# strings with dynamic length.
 +
-+  setlength(DynArrInt,13);
-+  setlength(DynArrInt_,13);
-+  setlength(DynArrStr,13);
-+  setlength(DynArrChar,13);
-+  for i := 0 to 12 do
-+    begin
-+    DynArrInt[i]:= i+50;
-+    DynArrInt_[i]:= i+50;
-+    DynArrChar[i]:= chr(ord('a')+i);
-+    StatArrStr[i]:='str'+inttostr(i);
-+    DynArrStr[i]:='dstr'+inttostr(i);
-+    end;
-+  writeln(DynArrInt_[1]);
-+  writeln(DynArrInt[1]); 
-+  writeln(DynArrStr[1]); 
-+  writeln(StatArrStr[1]);
-+  writeln(DynArrChar[1]);
++set testfile "string"
++set srcfile ${testfile}.f90
++set binfile ${objdir}/${subdir}/${testfile}
 +
-+  s := 'test'#0'string';
-+  writeln(s); { set breakpoint 2 here }
-+end.
-diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
-index 0f250d2..84e5038 100644
---- a/gdb/testsuite/gdb.python/py-cmd.exp
-+++ b/gdb/testsuite/gdb.python/py-cmd.exp
-@@ -20,24 +20,6 @@ if $tracelevel then {
-     strace $tracelevel
- }
--# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
--# Run a test named NAME, consisting of multiple lines of input.
--# After each input line INPUT, search for result line RESULT.
--# Succeed if all results are seen; fail otherwise.
--proc gdb_py_test_multiple {name args} {
--    global gdb_prompt
--    foreach {input result} $args {
--      if {[gdb_test_multiple $input "$name - $input" {
--          -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
--              pass "$name - $input"
--          }
--      }]} {
--          return 1
--      }
--    }
--    return 0
--}
--
- # Start with a fresh gdb.
- gdb_exit
-diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
-index e1212d3..77f44f5 100644
---- a/gdb/testsuite/gdb.python/py-frame.exp
-+++ b/gdb/testsuite/gdb.python/py-frame.exp
-@@ -89,8 +89,6 @@ gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
- gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
- gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
--gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
--gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
- gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
- gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
- gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
-@@ -105,3 +103,5 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
- gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
- gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
++if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f90 quiet}] != "" } {
++    untested "Couldn't compile ${srcfile}"
++    return -1
++}
 +
-+gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
-diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
-index 38c5693..e7f0037 100644
---- a/gdb/testsuite/gdb.python/py-function.exp
-+++ b/gdb/testsuite/gdb.python/py-function.exp
-@@ -20,24 +20,6 @@ if $tracelevel then {
-     strace $tracelevel
- }
--# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
--# Run a test named NAME, consisting of multiple lines of input.
--# After each input line INPUT, search for result line RESULT.
--# Succeed if all results are seen; fail otherwise.
--proc gdb_py_test_multiple {name args} {
--    global gdb_prompt
--    foreach {input result} $args {
--      if {[gdb_test_multiple $input "$name - $input" {
--          -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
--              pass "$name - $input"
--          }
--      }]} {
--          return 1
--      }
--    }
--    return 0
--}
--
- # Start with a fresh gdb.
- gdb_exit
-diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
-index 3b2aadd..03bbf3e 100644
---- a/gdb/testsuite/gdb.python/py-prettyprint.exp
-+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
-@@ -102,6 +102,8 @@ proc run_lang_tests {lang} {
-     gdb_test "print estring" "\"embedded x\\\\201\\\\202\\\\203\\\\204\""
-     gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
-+    gdb_test "print nullstr" "RuntimeError: Error reading string from inferior.*"
++gdb_exit
++gdb_start
++gdb_reinitialize_dir $srcdir/$subdir
++gdb_load ${binfile}
 +
-     gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
-     gdb_test "continue" "Program exited normally\."
-diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
-index a24bc11..e3043bc 100644
---- a/gdb/testsuite/gdb.python/py-value.exp
-+++ b/gdb/testsuite/gdb.python/py-value.exp
-@@ -313,6 +313,15 @@ proc test_value_after_death {} {
-     "print value's type"
- }
-+# Regression test for a cast failure.  The bug was that if we cast a
-+# value to its own type, gdb could crash.  This happened because we
-+# could end up double-freeing a struct value.
-+proc test_cast_regression {} {
-+  gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
-+  gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
-+  gdb_test "python print v" "5" "print value for cast test"
++if ![runto MAIN__] then {
++    perror "couldn't run to breakpoint MAIN__"
++    continue
 +}
 +
- # Regression test for invalid subscript operations.  The bug was that
- # the type of the value was not being checked before allowing a
- # subscript operation to proceed.
-@@ -437,6 +446,7 @@ if ![runto_main] then {
- test_value_in_inferior
- test_lazy_strings
- test_value_after_death
-+test_cast_regression
- # The following test recompiles the binary to test either C or C++
- # values. 
-diff --git a/gdb/testsuite/gdb.python/rh634108-solib_address.exp b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
++gdb_breakpoint [gdb_get_line_number "var-init"]
++gdb_continue_to_breakpoint "var-init"
++gdb_test "ptype c" "type = character(\\(kind=1\\)|\\*1)"
++gdb_test "ptype d" "type = character(\\(kind=8\\)|\\*8)"
++gdb_test "ptype e" "type = character(\\(kind=4\\)|\\*4)"
++gdb_test "ptype f" "type = character(\\(kind=4\\)|\\*4) \\(7,8:10\\)"
++gdb_test "ptype *e" "Attempt to take contents of a non-pointer value."
++gdb_test "ptype *f" "type = character(\\(kind=4\\)|\\*4) \\(7\\)"
++gdb_test "p c" "\\$\[0-9\]* = 'c'"
++gdb_test "p d" "\\$\[0-9\]* = 'd       '"
++gdb_test "p e" "\\$\[0-9\]* = 'g   '"
++gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\( 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   ', 'h   '\\) \\)"
++gdb_test "p *e" "Attempt to take contents of a non-pointer value."
++gdb_test "p *f" "Attempt to take contents of a non-pointer value."
++
++gdb_breakpoint [gdb_get_line_number "var-finish"]
++gdb_continue_to_breakpoint "var-finish"
++gdb_test "p e" "\\$\[0-9\]* = 'e   '" "p e re-set"
++gdb_test "p f" "\\$\[0-9\]* = \\(\\( 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\( 'f2  ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\( 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   ', 'f   '\\) \\)" "p *f re-set"
+diff --git a/gdb/testsuite/gdb.fortran/string.f90 b/gdb/testsuite/gdb.fortran/string.f90
 new file mode 100644
-index 0000000..70319ff
+index 0000000..226dc5d
 --- /dev/null
-+++ b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
-@@ -0,0 +1,24 @@
-+# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.fortran/string.f90
+@@ -0,0 +1,37 @@
++! Copyright 2008 Free Software Foundation, Inc.
++!
++! This program is free software; you can redistribute it and/or modify
++! it under the terms of the GNU General Public License as published by
++! the Free Software Foundation; either version 2 of the License, or
++! (at your option) any later version.
++!
++! This program is distributed in the hope that it will be useful,
++! but WITHOUT ANY WARRANTY; without even the implied warranty of
++! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++! GNU General Public License for more details.
++!
++! You should have received a copy of the GNU General Public License
++! along with this program; if not, write to the Free Software
++! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++!
++! Ihis file is the Fortran source file for dynamic.exp.
++! Original file written by Jakub Jelinek <jakub@redhat.com>.
++! Modified for the GDB testcase by Jan Kratochvil <jan.kratochvil@redhat.com>.
++
++subroutine foo (e, f)
++  character (len=1) :: c
++  character (len=8) :: d
++  character (len=*) :: e
++  character (len=*) :: f (1:7, 8:10)
++  c = 'c'
++  d = 'd'
++  e = 'e'                                       ! var-init
++  f = 'f'
++  f(1,9) = 'f2'
++  c = 'c'                                       ! var-finish
++end subroutine foo
++  character (len=4) :: g, h (1:7, 8:10)
++  g = 'g'
++  h = 'h'
++  call foo (g, h)
++end
+diff --git a/gdb/testsuite/gdb.fortran/subrange.exp b/gdb/testsuite/gdb.fortran/subrange.exp
+new file mode 100644
+index 0000000..c819e23
+--- /dev/null
++++ b/gdb/testsuite/gdb.fortran/subrange.exp
+@@ -0,0 +1,60 @@
++# Copyright 2011 Free Software Foundation, Inc.
 +
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
@@ -14863,211 +12767,113 @@ index 0000000..70319ff
 +# You should have received a copy of the GNU General Public License
 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+# https://bugzilla.redhat.com/show_bug.cgi?id=634108
-+
-+gdb_exit
-+gdb_start
-+
-+# Skip all tests if Python scripting is not enabled.
-+if { [skip_python_tests] } { continue }
-+
-+gdb_test "python print gdb.solib_address(-1)" "None" "gdb.solib_address exists"
-diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
-new file mode 100644
-index 0000000..4dc308b
---- /dev/null
-+++ b/gdb/testsuite/gdb.threads/watchpoint-fork-forkoff.c
-@@ -0,0 +1,175 @@
-+/* Test case for forgotten hw-watchpoints after fork()-off of a process.
-+
-+   Copyright 2008, 2009 Free Software Foundation, Inc.
-+
-+   This file is part of GDB.
-+
-+   This program is free software; you can redistribute it and/or modify
-+   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 2 of the License, or
-+   (at your option) any later version.
-+
-+   This program is distributed in the hope that it will be useful,
-+   but WITHOUT ANY WARRANTY; without even the implied warranty of
-+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+   GNU General Public License for more details.
-+
-+   You should have received a copy of the GNU General Public License
-+   along with this program; if not, write to the Free Software
-+   Foundation, Inc., 59 Temple Place - Suite 330,
-+   Boston, MA 02111-1307, USA.  */
-+
-+#include <string.h>
-+#include <errno.h>
-+
-+static void
-+delay (void)
-+{
-+  int i = usleep (1000000 / 100);
-+  assert (i == 0 || errno == EINTR);
-+}
-+
-+#if defined FOLLOW_PARENT
-+
-+static void
-+forkoff (int nr)
-+{
-+  pid_t child, pid_got;
-+  int exit_code = 42 + nr;
-+  int status, i;
++if { [skip_fortran_tests] } { return -1 }
 +
-+  child = fork ();
-+  switch (child)
-+    {
-+    case -1:
-+      assert (0);
-+    case 0:
-+      printf ("child%d: %d\n", nr, (int) getpid ());
-+      /* Delay to get both the "child%d" and "parent%d" message printed without
-+       a race breaking expect by its endless wait on `$gdb_prompt$':
-+       Breakpoint 3, breakpoint () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
-+       33      }
-+       (gdb) parent2: 14223  */
-+      i = sleep (1);
-+      assert (i == 0);
-+
-+      /* We must not get caught here (against a forgotten breakpoint).  */
-+      var++;
-+      breakpoint ();
-+
-+      _exit (exit_code);
-+    default:
-+      printf ("parent%d: %d\n", nr, (int) child);
-+      /* Delay to get both the "child%d" and "parent%d" message printed, see
-+       above.  */
-+      i = sleep (1);
-+      assert (i == 0);
-+
-+      pid_got = wait (&status);
-+      assert (pid_got == child);
-+      assert (WIFEXITED (status));
-+      assert (WEXITSTATUS (status) == exit_code);
-+
-+      /* We must get caught here (against a false watchpoint removal).  */
-+      breakpoint ();
-+    }
++set testfile "subrange"
++set srcfile ${testfile}.f90
++if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}] } {
++    return -1
 +}
 +
-+#elif defined FOLLOW_CHILD
-+
-+static volatile int usr1_got;
-+
-+static void
-+handler_usr1 (int signo)
-+{
-+  usr1_got++;
++if ![runto MAIN__] {
++    perror "Couldn't run to MAIN__"
++    continue
 +}
 +
-+static void
-+forkoff (int nr)
-+{
-+  pid_t child;
-+  int i, loop;
-+  struct sigaction act, oldact;
-+#ifdef THREAD
-+  void *thread_result;
-+#endif
-+
-+  memset (&act, 0, sizeof act);
-+  act.sa_flags = SA_RESTART;
-+  act.sa_handler = handler_usr1;
-+  sigemptyset (&act.sa_mask);
-+  i = sigaction (SIGUSR1, &act, &oldact);
-+  assert (i == 0);
-+
-+  child = fork ();
-+  switch (child)
-+    {
-+    case -1:
-+      assert (0);
-+    default:
-+      printf ("parent%d: %d\n", nr, (int) child);
-+
-+      /* Sleep for a while to possibly get incorrectly ATTACH_THREADed by GDB
-+       tracing the child fork with no longer valid thread/lwp entries of the
-+       parent.  */
-+
-+      i = sleep (2);
-+      assert (i == 0);
-+
-+      /* We must not get caught here (against a forgotten breakpoint).  */
-+
-+      var++;
-+      breakpoint ();
-+
-+#ifdef THREAD
-+      /* And neither got caught our thread.  */
-+
-+      step = 99;
-+      i = pthread_join (thread, &thread_result);
-+      assert (i == 0);
-+      assert (thread_result == (void *) 99UL);
-+#endif
-+
-+      /* Be sure our child knows we did not get caught above.  */
-+
-+      i = kill (child, SIGUSR1);
-+      assert (i == 0);
-+
-+      /* Sleep for a while to check GDB's `info threads' no longer tracks us in
-+       the child fork.  */
-+
-+      i = sleep (2);
-+      assert (i == 0);
-+
-+      _exit (0);
-+    case 0:
-+      printf ("child%d: %d\n", nr, (int) getpid ());
-+
-+      /* Let the parent signal us about its success.  Be careful of races.  */
-+
-+      for (loop = 0; loop < 1000; loop++)
-+      {
-+        /* Parent either died (and USR1_GOT is zero) or it succeeded.  */
-+        if (kill (getppid (), 0) != 0)
-+          break;
-+        /* Parent succeeded?  */
-+        if (usr1_got)
-+          break;
-+
-+        delay ();
-+      }
-+      assert (usr1_got);
-+
-+      /* We must get caught here (against a false watchpoint removal).  */
-+
-+      breakpoint ();
-+    }
++# Depending on the compiler version being used, the name of the 4-byte integer
++# and real types can be printed differently.  For instance, gfortran-4.1 uses
++# "int4" whereas gfortran-4.3 uses "int(kind=4)".
++set int4 "(int4|integer\\(kind=4\\))"
 +
-+  i = sigaction (SIGUSR1, &oldact, NULL);
-+  assert (i == 0);
-+}
++gdb_breakpoint [gdb_get_line_number "break-static"]
++gdb_continue_to_breakpoint "break-static" ".*break-static.*"
 +
-+#else
-+# error "!FOLLOW_PARENT && !FOLLOW_CHILD"
-+#endif
-diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
++foreach var {a alloc ptr} {
++    global pf_prefix
++    set old_prefix $pf_prefix
++    lappend pf_prefix "$var:"
++
++    gdb_test "p $var (2, 2:3)" { = \(22, 32\)}
++    gdb_test "p $var (2:3, 3)" { = \(32, 33\)}
++    gdb_test "p $var (1, 2:)" { = \(21, 31\)}
++    gdb_test "p $var (2, :2)" { = \(12, 22\)}
++    gdb_test "p $var (3, 2:2)" { = \(23\)}
++    gdb_test "ptype $var (3, 2:2)" " = $int4 \\(2:2\\)"
++    gdb_test "p $var (4, :)" { = \(14, 24, 34\)}
++    gdb_test "p $var (:, :)" { = \(\( *11, 12, 13, 14\) \( *21, 22, 23, 24\) \( *31, 32, 33, 34\) *\)}
++    gdb_test "ptype $var (:, :)" " = $int4 \\(4,3\\)"
++    gdb_test "p $var (:)" "Wrong number of subscripts"
++    gdb_test "p $var (:, :, :)" "Wrong number of subscripts"
++
++    set pf_prefix $old_prefix
++}
++
++gdb_test_no_output {set $a=a}
++delete_breakpoints
++gdb_unload
++gdb_test {p $a (3, 2:2)} { = \(23\)}
+diff --git a/gdb/testsuite/gdb.fortran/subrange.f90 b/gdb/testsuite/gdb.fortran/subrange.f90
+new file mode 100644
+index 0000000..4747ea9
+--- /dev/null
++++ b/gdb/testsuite/gdb.fortran/subrange.f90
+@@ -0,0 +1,28 @@
++! Copyright 2011 Free Software Foundation, Inc.
++!
++! This program is free software; you can redistribute it and/or modify
++! it under the terms of the GNU General Public License as published by
++! the Free Software Foundation; either version 3 of the License, or
++! (at your option) any later version.
++! 
++! This program is distributed in the hope that it will be useful,
++! but WITHOUT ANY WARRANTY; without even the implied warranty of
++! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++! GNU General Public License for more details.
++! 
++! You should have received a copy of the GNU General Public License
++! along with this program.  If not, see <http://www.gnu.org/licenses/>.
++
++program test
++  integer, target :: a (4, 3)
++  integer, allocatable :: alloc (:, :)
++  integer, pointer :: ptr (:, :)
++  do 1 i = 1, 4
++  do 1 j = 1, 3
++    a (i, j) = j * 10 + i
++1 continue
++  allocate (alloc (4, 3))
++  alloc = a
++  ptr => a
++  write (*,*) a                 ! break-static
++end
+diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
+index 7645caf..f4f9c1f 100644
+--- a/gdb/testsuite/gdb.gdb/selftest.exp
++++ b/gdb/testsuite/gdb.gdb/selftest.exp
+@@ -92,6 +92,10 @@ proc do_steps_and_nexts {} {
+               set description "step over cmdarg_vec initialization"
+               set command "step"
+           }
++          -re ".*python_script = 0.*$gdb_prompt $" {
++              set description "step over python_script initialization"
++              set command "step"
++          }
+           -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
+               set description "next over make_command_stats_cleanup and everything it calls"
+               set command "next"
+diff --git a/gdb/testsuite/gdb.mi/mi2-var-stale-type.c b/gdb/testsuite/gdb.mi/mi2-var-stale-type.c
 new file mode 100644
-index 0000000..edacfc0
+index 0000000..ebced3c
 --- /dev/null
-+++ b/gdb/testsuite/gdb.threads/watchpoint-fork-mt.c
-@@ -0,0 +1,157 @@
-+/* Test case for forgotten hw-watchpoints after fork()-off of a process.
-+
-+   Copyright 2008, 2009 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.mi/mi2-var-stale-type.c
+@@ -0,0 +1,26 @@
++/* Copyright 2011 Free Software Foundation, Inc.
 +
 +   This file is part of GDB.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 2 of the License, or
++   the Free Software Foundation; either version 3 of the License, or
 +   (at your option) any later version.
 +
 +   This program is distributed in the hope that it will be useful,
@@ -15076,161 +12882,121 @@ index 0000000..edacfc0
 +   GNU General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License
-+   along with this program; if not, write to the Free Software
-+   Foundation, Inc., 59 Temple Place - Suite 330,
-+   Boston, MA 02111-1307, USA.  */
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+#include <assert.h>
-+#include <unistd.h>
-+#include <sys/wait.h>
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <pthread.h>
++int
++main (int argc, char **argv)
++{
++  char vla[argc];
 +
-+#include <asm/unistd.h>
-+#include <unistd.h>
-+#define gettid() syscall (__NR_gettid)
++  vla[0] = 0; /* break-here */
 +
-+/* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
-+   variable.  Hit-comments need to be duplicite there to catch both at-stops
-+   and behind-stops, depending on the target.  */
++  return 0;
++}
+diff --git a/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp b/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp
+new file mode 100644
+index 0000000..74a104e
+--- /dev/null
++++ b/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp
+@@ -0,0 +1,57 @@
++# Copyright 2011 Free Software Foundation, Inc.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+static volatile int var;
++load_lib mi-support.exp
++set MIFLAGS "-i=mi2"
 +
-+static void
-+dummy (void)
-+{
++gdb_exit
++if [mi_gdb_start] {
++    continue
 +}
 +
-+static void
-+breakpoint (void)
-+{
++set testfile "mi2-var-stale-type"
++set srcfile ${testfile}.c
++set binfile ${objdir}/${subdir}/${testfile}
++if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} {
++    return -1
 +}
 +
-+/* Include here the functions:
-+   static void forkoff (int nr);
-+   static void delay (void);  */
++mi_delete_breakpoints
++mi_gdb_reinitialize_dir $srcdir/$subdir
++mi_gdb_load ${binfile}
 +
-+static pthread_t thread;
-+static volatile int step;
-+#define THREAD
++mi_gdb_test {-interpreter-exec console "maintenance set internal-error quit yes"} \
++  {\^done} \
++  "maintenance set internal-error quit yes"
 +
-+#include "watchpoint-fork-forkoff.c"
++mi_gdb_test {-interpreter-exec console "maintenance set internal-error corefile yes"} \
++  {\^done} \
++  "maintenance set internal-error corefile yes"
 +
-+static void *
-+start (void *arg)
-+{
-+  if (step >= 3)
-+    goto step_3;
++set line [gdb_get_line_number "break-here"]
++set func "main"
 +
-+  while (step != 1)
-+    delay ();
++mi_gdb_test "-break-insert -t $srcfile:$line" \
++  "\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"$func\(\\\(.*\\\)\)?\",file=\".*\",line=\"$line\",times=\"0\",original-location=\".*\"\}" \
++  "breakpoint at $func"
 +
-+  var++;      /* validity-thread-B */
-+  dummy ();   /* validity-thread-B */
-+  step = 2;
-+  while (step != 3)
-+    {
-+      if (step == 99)
-+      goto step_99;
-+      delay ();
-+    }
++if { [mi_run_cmd] < 0 } {
++    return -1
++}
++mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "stop after initializing vla"
 +
-+step_3:
-+  if (step >= 5)
-+    goto step_5;
++mi_create_varobj "vla" "vla" "create local variable vla"
 +
-+  var++;      /* after-fork1-B */
-+  dummy ();   /* after-fork1-B */
-+  step = 4;
-+  while (step != 5)
-+    {
-+      if (step == 99)
-+      goto step_99;
-+      delay ();
-+    }
++mi_gdb_test "-var-update *" "\\^done,changelist=.*" "-var-update *"
+diff --git a/gdb/testsuite/gdb.opt/array-from-register-func.c b/gdb/testsuite/gdb.opt/array-from-register-func.c
+new file mode 100644
+index 0000000..729f457
+--- /dev/null
++++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
+@@ -0,0 +1,22 @@
++/* This file is part of GDB, the GNU debugger.
 +
-+step_5:
-+  var++;      /* after-fork2-B */
-+  dummy ();   /* after-fork2-B */
-+  return (void *) 5UL;
++   Copyright 2009 Free Software Foundation, Inc.
 +
-+step_99:
-+  /* We must not get caught here (against a forgotten breakpoint).  */
-+  var++;
-+  breakpoint ();
-+  return (void *) 99UL;
-+}
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3 of the License, or
++   (at your option) any later version.
 +
-+int
-+main (void)
-+{
-+  int i;
-+  void *thread_result;
-+
-+  setbuf (stdout, NULL);
-+  printf ("main: %d\n", (int) gettid ());
-+
-+  /* General watchpoints validity.  */
-+  var++;      /* validity-first */
-+  dummy ();   /* validity-first */
-+
-+  i = pthread_create (&thread, NULL, start, NULL);
-+  assert (i == 0);
-+
-+  var++;      /* validity-thread-A */
-+  dummy ();   /* validity-thread-A */
-+  step = 1;
-+  while (step != 2)
-+    delay ();
-+
-+  /* Hardware watchpoints got disarmed here.  */
-+  forkoff (1);
-+
-+  var++;      /* after-fork1-A */
-+  dummy ();   /* after-fork1-A */
-+  step = 3;
-+#ifdef FOLLOW_CHILD
-+  /* Spawn new thread as it was deleted in the child of FORK.  */
-+  i = pthread_create (&thread, NULL, start, NULL);
-+  assert (i == 0);
-+#endif
-+  while (step != 4)
-+    delay ();
-+
-+  /* A sanity check for double hardware watchpoints removal.  */
-+  forkoff (2);
-+
-+  var++;      /* after-fork2-A */
-+  dummy ();   /* after-fork2-A */
-+  step = 5;
-+#ifdef FOLLOW_CHILD
-+  /* Spawn new thread as it was deleted in the child of FORK.  */
-+  i = pthread_create (&thread, NULL, start, NULL);
-+  assert (i == 0);
-+#endif
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
 +
-+  i = pthread_join (thread, &thread_result);
-+  assert (i == 0);
-+  assert (thread_result == (void *) 5UL);
++   You should have received a copy of the GNU General Public License
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+  return 0;
++int
++func (int *arr)
++{
++  return arr[0];
 +}
-diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.c b/gdb/testsuite/gdb.threads/watchpoint-fork.c
+diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
 new file mode 100644
-index 0000000..5f62e7f
+index 0000000..3090e7e
 --- /dev/null
-+++ b/gdb/testsuite/gdb.threads/watchpoint-fork.c
-@@ -0,0 +1,57 @@
-+/* Test case for forgotten hw-watchpoints after fork()-off of a process.
-+
-+   Copyright 2008, 2009 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.opt/array-from-register.c
+@@ -0,0 +1,28 @@
++/* This file is part of GDB, the GNU debugger.
 +
-+   This file is part of GDB.
++   Copyright 2009 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
-+   the Free Software Foundation; either version 2 of the License, or
++   the Free Software Foundation; either version 3 of the License, or
 +   (at your option) any later version.
 +
 +   This program is distributed in the hope that it will be useful,
@@ -15239,54 +13005,66 @@ index 0000000..5f62e7f
 +   GNU General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License
-+   along with this program; if not, write to the Free Software
-+   Foundation, Inc., 59 Temple Place - Suite 330,
-+   Boston, MA 02111-1307, USA.  */
-+
-+#include <assert.h>
-+#include <unistd.h>
-+#include <sys/wait.h>
-+#include <stdio.h>
-+#include <stdlib.h>
-+
-+static volatile int var;
-+
-+static void
-+breakpoint (void)
-+{
-+}
-+
-+/* Include here the function:
-+   static void forkoff (int nr);  */
++   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 +
-+#include "watchpoint-fork-forkoff.c"
++extern int func (int *arr);
 +
 +int
 +main (void)
 +{
-+  setbuf (stdout, NULL);
-+  printf ("main: %d\n", (int) getpid ());
-+
-+  /* General watchpoints validity.  */
-+  var++;
-+  /* Hardware watchpoints got disarmed here.  */
-+  forkoff (1);
-+  /* This watchpoint got lost before.  */
-+  var++;
-+  /* A sanity check for double hardware watchpoints removal.  */
-+  forkoff (2);
-+  var++;
++  int arr[] = { 42 };
++
++  func (arr);
 +
 +  return 0;
 +}
-diff --git a/gdb/testsuite/gdb.threads/watchpoint-fork.exp b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
+diff --git a/gdb/testsuite/gdb.opt/array-from-register.exp b/gdb/testsuite/gdb.opt/array-from-register.exp
 new file mode 100644
-index 0000000..1dc93ab
+index 0000000..f2de718
 --- /dev/null
-+++ b/gdb/testsuite/gdb.threads/watchpoint-fork.exp
-@@ -0,0 +1,130 @@
-+# Copyright 2008, 2009 Free Software Foundation, Inc.
++++ b/gdb/testsuite/gdb.opt/array-from-register.exp
+@@ -0,0 +1,33 @@
++# Copyright 2009 Free Software Foundation, Inc.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 2 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++#
++# This file is part of the gdb testsuite.
++
++if { [prepare_for_testing array-from-register.exp "array-from-register"      \
++                        {array-from-register.c array-from-register-func.c} \
++                        {debug optimize=-O2}] } {
++    return -1
++}
++
++if ![runto func] then {
++    return -1
++}
++
++gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
 +
++# Seen regression:
++# Address requested for identifier "arr" which is in register $rdi
++gdb_test "p arr\[0\]" "\\$\[0-9\]+ = 42"
+diff --git a/gdb/testsuite/gdb.pascal/arrays.exp b/gdb/testsuite/gdb.pascal/arrays.exp
+new file mode 100644
+index 0000000..ccc6e1e
+--- /dev/null
++++ b/gdb/testsuite/gdb.pascal/arrays.exp
+@@ -0,0 +1,104 @@
++# Copyright 2008, 2009 Free Software Foundation, Inc.
++#
 +# This program is free software; you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
 +# the Free Software Foundation; either version 3 of the License, or
@@ -15300,135 +13078,248 @@ index 0000000..1dc93ab
 +# You should have received a copy of the GNU General Public License
 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
-+# Test case for forgotten hw-watchpoints after fork()-off of a process.
++if $tracelevel then {
++    strace $tracelevel
++}
 +
-+proc test {type symbol} {
-+    global objdir subdir srcdir
++load_lib "pascal.exp"
 +
-+    set test watchpoint-fork
++set testfile "arrays"
++set srcfile ${testfile}.pas
++set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
 +
-+    global pf_prefix
-+    set prefix_test $pf_prefix
-+    lappend pf_prefix "$type:"
-+    set prefix_mt $pf_prefix
++# These tests only work with fpc, using the -gw3 compile-option
++pascal_init
++if { $pascal_compiler_is_fpc != 1 } {
++  return -1
++}
++
++# Detect if the fpc version is below 2.3.0
++set fpc_generates_dwarf_for_dynamic_arrays 1
++if { ($fpcversion_major < 2) || ( ($fpcversion_major == 2) && ($fpcversion_minor < 3))}  {
++  set fpc_generates_dwarf_for_dynamic_arrays 0
++}
 +
-+    # no threads
 +
-+    set pf_prefix $prefix_mt
-+    lappend pf_prefix "singlethreaded:"
++if {[gdb_compile_pascal "-gw3 ${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
++  return -1
++}
 +
-+    set executable ${test}-${type}
-+    if { [gdb_compile ${srcdir}/${subdir}/${test}.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
-+      untested ${test}.exp
-+      return -1
-+    }
-+    clean_restart $executable
++gdb_exit
++gdb_start
++gdb_reinitialize_dir $srcdir/$subdir
++gdb_load ${binfile}
++set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
++set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
 +
-+    gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on."
-+    gdb_test "set follow-fork-mode $type"
-+    gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"."
-+    # Testcase uses it for the `follow-fork-mode child' type.
-+    gdb_test "handle SIGUSR1 nostop noprint pass"
 +
-+    if { ![runto_main] } then {
-+      gdb_suppress_tests
-+      return
-+    }
++if { [gdb_breakpoint ${srcfile}:${bp_location1}] } {
++    pass "setting breakpoint 1"
++}
++if { [gdb_breakpoint ${srcfile}:${bp_location2}] } {
++    pass "setting breakpoint 2"
++}
++
++# Verify that "start" lands inside the right procedure.
++if { [gdb_start_cmd] < 0 } {
++    untested start
++    return -1
++}
++
++gdb_test "" ".* at .*${srcfile}.*" "start"
++
++gdb_test "cont" "Breakpoint .*:${bp_location1}.*" "Going to first breakpoint"
++
++gdb_test "print StatArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer type"
++gdb_test "print StatArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61\\}" "Print static array of integer"
++
++gdb_test "cont" "Breakpoint .*:${bp_location2}.*" "Going to second breakpoint"
++
++gdb_test "print StatArrChar" ".* = 'abcdefghijkl'" "Print static array of char"
++gdb_test "print Stat2dArrInt" ".* = \\{\\{0, 1, 2, 3, 4\\}, \\{1, 2, 3, 4, 5\\}, \\{2, 3, 4, 5, 6\\}, \\{3, 4, 5, 6, 7\\}, \\{4, 5, 6, 7, 8\\}, \\{5, 6, 7, 8, 9\\}, \\{6, 7, 8, 9, 10\\}, \\{7, 8, 9, 10, 11\\}, \\{8, 9, 10, 11, 12\\}, \\{9, 10, 11, 12, 13\\}, \\{10, 11, 12, 13, 14\\}, \\{11, 12, 13, 14, 15\\}\\}" "Print static 2-dimensional array of integer"
++
++if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
++  setup_xfail "*-*-*"
++}
++gdb_test "print DynArrInt" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer type"
++if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
++  setup_xfail "*-*-*"
++}
++gdb_test "print DynArrInt_" ".* = \\{50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62\\}" "Print dynamic array of integer"
 +
-+    # Install the watchpoint only after getting into MAIN - workaround some PPC
-+    # problem.
-+    gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
++if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
++  setup_xfail "*-*-*"
++}
++gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char"
++
++if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
++  setup_xfail "*-*-*"
++}
++gdb_test "print DynArrStr" ".* = \\{'dstr0', 'dstr1', 'dstr2', 'dstr3', 'dstr4', 'dstr5', 'dstr6', 'dstr7', 'dstr8', 'dstr9', 'dstr10', 'dstr11', 'dstr12'\\}" "Print dynamic array of string"
++
++if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
++  setup_xfail "*-*-*"
++}
++gdb_test "print StatArrStr" ".* = \\{'str0', 'str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9', 'str10', 'str11', 'str12'\\}" "Print static array of string"
++
++if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
++  setup_xfail "*-*-*"
++}
++gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char"
++
+diff --git a/gdb/testsuite/gdb.pascal/arrays.pas b/gdb/testsuite/gdb.pascal/arrays.pas
+new file mode 100644
+index 0000000..295602d
+--- /dev/null
++++ b/gdb/testsuite/gdb.pascal/arrays.pas
+@@ -0,0 +1,82 @@
++{
++ Copyright 2008, 2009 Free Software Foundation, Inc.
++
++ This program is free software; you can redistribute it and/or modify
++ it under the terms of the GNU General Public License as published by
++ the Free Software Foundation; either version 3 of the License, or
++ (at your option) any later version.
 +
-+    # It is never hit but it should not be left over in the fork()ed-off child.
-+    gdb_breakpoint "breakpoint"
++ This program is distributed in the hope that it will be useful,
++ but WITHOUT ANY WARRANTY; without even the implied warranty of
++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ GNU General Public License for more details.
 +
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
-+    gdb_test "continue" \
-+           "reakpoint 3, breakpoint.*" "breakpoint after the first fork"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
-+    gdb_test "continue" \
-+           "reakpoint 3, breakpoint.*" "breakpoint after the second fork"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 2.*New value = 3.*return *0;" "watchpoint after the second fork"
-+    gdb_test "continue" "Continuing..*Program exited normally." "finish"
++ You should have received a copy of the GNU General Public License
++ along with this program.  If not, see <http://www.gnu.org/licenses/>.
++}
 +
++program arrays;
 +
-+    # threads
++{$mode objfpc}{$h+}
 +
-+    set pf_prefix $prefix_mt
-+    lappend pf_prefix "multithreaded:"
++uses sysutils;
 +
-+    set executable ${test}-mt-${type}
-+    if { [gdb_compile_pthreads ${srcdir}/${subdir}/${test}-mt.c ${objdir}/${subdir}/${executable} executable [list debug additional_flags=-D$symbol]] != "" } {
-+      untested ${test}.exp
-+      return -1
-+    }
-+    clean_restart $executable
++type TStatArrInt= array[0..11] of integer;
++     TDynArrInt= array of integer;
++     TStatArrStr= array[0..12] of string;
++     TDynArrStr= array of string;
++     TDynArrChar = array of char;
++     TStatArrChar = array [0..11] of char;
 +
-+    gdb_test "set follow-fork-mode $type"
-+    # Testcase uses it for the `follow-fork-mode child' type.
-+    gdb_test "handle SIGUSR1 nostop noprint pass"
++     TStat2dArrInt = array[0..11,0..4] of integer;
 +
-+    if { ![runto_main] } then {
-+      gdb_suppress_tests
-+      return
-+    }
++var StatArrInt: TStatArrInt;
++    StatArrInt_: Array[0..11] of integer;
++    DynArrInt:  TDynArrInt;
++    DynArrInt_: Array of integer;
++    StatArrStr: TStatArrStr;
++    DynArrStr: TDynArrStr;
++    StatArrChar: TStatArrChar;
++    DynArrChar: TDynArrChar;
 +
-+    # Install the watchpoint only after getting into MAIN - workaround some PPC
-+    # problem.
-+    gdb_test "watch var" "atchpoint 2: var" "Set the watchpoint"
++    Stat2dArrInt: TStat2dArrInt;
 +
-+    # It is never hit but it should not be left over in the fork()ed-off child.
-+    gdb_breakpoint "breakpoint"
++    s: string;
++      
++    i,j : integer;
 +
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
-+    gdb_test "continue" \
-+           "reakpoint 3, breakpoint.*" "breakpoint (A) after the first fork"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
-+    gdb_test "continue" \
-+           "reakpoint 3, breakpoint.*" "breakpoint (A) after the second fork"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
-+    gdb_test "continue" \
-+           "atchpoint 2: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
-+    gdb_test "continue" "Continuing..*Program exited normally." "finish"
++begin
++  for i := 0 to 11 do
++    begin
++    StatArrInt[i]:= i+50;
++    StatArrInt_[i]:= i+50;
++    StatArrChar[i]:= chr(ord('a')+i);
++    for j := 0 to 4 do
++      Stat2dArrInt[i,j]:=i+j;
++    end;
++  writeln(StatArrInt_[0]);
++  writeln(StatArrInt[0]); { set breakpoint 1 here }
++  writeln(StatArrChar[0]);
++  writeln(Stat2dArrInt[0,0]);
 +
++  setlength(DynArrInt,13);
++  setlength(DynArrInt_,13);
++  setlength(DynArrStr,13);
++  setlength(DynArrChar,13);
++  for i := 0 to 12 do
++    begin
++    DynArrInt[i]:= i+50;
++    DynArrInt_[i]:= i+50;
++    DynArrChar[i]:= chr(ord('a')+i);
++    StatArrStr[i]:='str'+inttostr(i);
++    DynArrStr[i]:='dstr'+inttostr(i);
++    end;
++  writeln(DynArrInt_[1]);
++  writeln(DynArrInt[1]); 
++  writeln(DynArrStr[1]); 
++  writeln(StatArrStr[1]);
++  writeln(DynArrChar[1]);
 +
-+    # cleanup
++  s := 'test'#0'string';
++  writeln(s); { set breakpoint 2 here }
++end.
+diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
+index 993e774..52dbd17 100644
+--- a/gdb/testsuite/gdb.python/py-frame.exp
++++ b/gdb/testsuite/gdb.python/py-frame.exp
+@@ -74,8 +74,6 @@ gdb_test "python print bframe == gdb.newest_frame()" True \
+ gdb_test "python print 'result =', f0 == f1" " = False" "test equality comparison (false)"
+ gdb_test "python print 'result =', f0 == f0" " = True" "test equality comparison (true)"
+-gdb_test "python print 'result =', f0 != f1" " = True" "test inequality comparison (true)"
+-gdb_test "python print 'result =', f0 != f0" " = False" "test inequality comparison (false)"
+ gdb_test "python print 'result =', f0.is_valid ()" " = True" "test Frame.is_valid"
+ gdb_test "python print 'result =', f0.name ()" " = f2" "test Frame.name"
+ gdb_test "python print 'result =', f0.type () == gdb.NORMAL_FRAME" " = True" "test Frame.type"
+@@ -90,3 +88,5 @@ gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_ex
+ gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"
+ gdb_test "python print 'result =', gdb.selected_frame () == f1" " = True" "test gdb.selected_frame"
 +
-+    set pf_prefix $prefix_test
++gdb_test "python print 'result =', f0.block ()" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
+diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
+index acfd89b..c77d9c2 100644
+--- a/gdb/testsuite/gdb.python/py-value.exp
++++ b/gdb/testsuite/gdb.python/py-value.exp
+@@ -358,6 +358,15 @@ proc test_value_after_death {} {
+     "print value's type"
+ }
++# Regression test for a cast failure.  The bug was that if we cast a
++# value to its own type, gdb could crash.  This happened because we
++# could end up double-freeing a struct value.
++proc test_cast_regression {} {
++  gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
++  gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
++  gdb_test "python print v" "5" "print value for cast test"
 +}
 +
-+test parent FOLLOW_PARENT
-+
-+# Only GNU/Linux is known to support `set follow-fork-mode child'.
-+if {[istarget "*-*-linux*"]} {
-+    test child FOLLOW_CHILD
-+}
+ # Regression test for invalid subscript operations.  The bug was that
+ # the type of the value was not being checked before allowing a
+ # subscript operation to proceed.
+@@ -494,6 +503,7 @@ test_value_in_inferior
+ test_inferior_function_call
+ test_lazy_strings
+ test_value_after_death
++test_cast_regression
+ # Test either C or C++ values. 
+ test_subscript_regression "${binfile}" "c"
 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
-index 20e2fb7..b27d25c 100644
+index 4f2b7c9..0daef25 100644
 --- a/gdb/testsuite/lib/gdb.exp
 +++ b/gdb/testsuite/lib/gdb.exp
-@@ -27,6 +27,7 @@ if {$tool == ""} {
- }
- load_lib libgloss.exp
-+load_lib python-support.exp
- global GDB
+@@ -142,6 +142,11 @@ proc gdb_unload {} {
+           send_gdb "y\n"
+           exp_continue
+       }
++      -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $"\
++          { send_gdb "y\n"
++              verbose "\t\tUnloading symbols for program being debugged"
++          exp_continue
++      }
+       -re "Discard symbol table from .*y or n.*$" {
+           send_gdb "y\n"
+           exp_continue
 diff --git a/gdb/testsuite/lib/pascal.exp b/gdb/testsuite/lib/pascal.exp
-index 9691bc1..13ea8b5 100644
+index dd18d37..f973485 100644
 --- a/gdb/testsuite/lib/pascal.exp
 +++ b/gdb/testsuite/lib/pascal.exp
 @@ -37,6 +37,9 @@ proc pascal_init {} {
@@ -15462,116 +13353,25 @@ index 9691bc1..13ea8b5 100644
      }
      set pascal_init_done 1
  }   
-diff --git a/gdb/testsuite/lib/python-support.exp b/gdb/testsuite/lib/python-support.exp
-new file mode 100644
-index 0000000..b8e9836
---- /dev/null
-+++ b/gdb/testsuite/lib/python-support.exp
-@@ -0,0 +1,53 @@
-+global python_supported_saved
-+
-+# Return 1 if Python scripting is supported in GDB, 0 if not.
-+proc python_supported { } {
-+  global gdb_prompt
-+  global python_supported_saved
-+
-+  if [info exists python_supported_saved] {
-+      verbose "python_supported:  returning saved $python_supported_saved" 2
-+      return $python_supported_saved
-+  }
-+
-+  gdb_test_multiple "python print 'hello, world!'" "verify python support" {
-+    -re "not supported.*$gdb_prompt $"        {
-+      return [set python_supported_saved 0]
-+    }
-+    -re "$gdb_prompt $"       {
-+      return [set python_supported_saved 1]
-+    }
-+  }
-+
-+  return [set python_supported_saved 0]
-+}
-+
-+# Run a command in GDB, and report a failure if a Python exception is thrown.
-+# If report_pass is true, report a pass if no exception is thrown.
-+proc gdb_py_test_silent_cmd {cmd name report_pass} {
-+  global gdb_prompt
-+
-+  gdb_test_multiple $cmd $name {
-+      -re "Traceback.*$gdb_prompt $"  { fail $name }
-+      -re "$gdb_prompt $"           { if $report_pass { pass $name } }
-+  }
-+}
-+
-+# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
-+# Run a test named NAME, consisting of multiple lines of input.
-+# After each input line INPUT, search for result line RESULT.
-+# Succeed if all results are seen; fail otherwise.
-+proc gdb_py_test_multiple {name args} {
-+    global gdb_prompt
-+
-+    foreach {input result} $args {
-+      if {[gdb_test_multiple $input "$name - $input" {
-+          -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
-+              pass "$name - $input"
-+          }
-+      }]} {
-+          return 1
-+      }
-+    }
-+    return 0
-+}
-diff --git a/gdb/thread.c b/gdb/thread.c
-index 0b291ba..ae3e4ff 100644
---- a/gdb/thread.c
-+++ b/gdb/thread.c
-@@ -90,6 +90,16 @@ delete_step_resume_breakpoint (struct thread_info *tp)
-     }
- }
-+void
-+delete_exception_resume_breakpoint (struct thread_info *tp)
-+{
-+  if (tp && tp->exception_resume_breakpoint)
-+    {
-+      delete_breakpoint (tp->exception_resume_breakpoint);
-+      tp->exception_resume_breakpoint = NULL;
-+    }
-+}
-+
- static void
- clear_thread_inferior_resources (struct thread_info *tp)
- {
-@@ -103,6 +113,12 @@ clear_thread_inferior_resources (struct thread_info *tp)
-       tp->step_resume_breakpoint = NULL;
-     }
-+  if (tp->exception_resume_breakpoint)
-+    {
-+      tp->exception_resume_breakpoint->disposition = disp_del_at_next_stop;
-+      tp->exception_resume_breakpoint = NULL;
-+    }
-+
-   bpstat_clear (&tp->stop_bpstat);
-   discard_all_intermediate_continuations_thread (tp);
 diff --git a/gdb/top.c b/gdb/top.c
-index b29e68d..8edac70 100644
+index 061ad48..d615cfc 100644
 --- a/gdb/top.c
 +++ b/gdb/top.c
-@@ -337,6 +337,7 @@ void
- prepare_execute_command (void)
- {
-   free_all_values ();
+@@ -352,6 +352,9 @@ prepare_execute_command (void)
+   mark = value_mark ();
+   cleanup = make_cleanup_value_free_to_mark (mark);
++#if 0
 +  free_all_types ();
++#endif
  
-   /* With multiple threads running while the one we're examining is stopped,
-      the dcache can get stale without us being able to detect it.
+   /* With multiple threads running while the one we're examining is
+      stopped, the dcache can get stale without us being able to detect
 diff --git a/gdb/typeprint.c b/gdb/typeprint.c
-index ce9f551..5f9d739 100644
+index c25e705..498958a 100644
 --- a/gdb/typeprint.c
 +++ b/gdb/typeprint.c
-@@ -36,6 +36,7 @@
+@@ -35,6 +35,7 @@
  #include "gdb_string.h"
  #include "exceptions.h"
  #include "valprint.h"
@@ -15579,17 +13379,17 @@ index ce9f551..5f9d739 100644
  #include <errno.h>
  
  extern void _initialize_typeprint (void);
-@@ -77,6 +78,9 @@ void
- type_print (struct type *type, char *varstring, struct ui_file *stream,
+@@ -76,6 +77,9 @@ void
+ type_print (struct type *type, const char *varstring, struct ui_file *stream,
            int show)
  {
-+  if (show >= 0)
++  if (show >= 0 && current_language->la_language != language_ada)
 +    type = check_typedef (type);
 +
    LA_PRINT_TYPE (type, varstring, stream, show, 0);
  }
  
-@@ -115,7 +119,8 @@ whatis_exp (char *exp, int show)
+@@ -114,7 +118,8 @@ whatis_exp (char *exp, int show)
  {
    struct expression *expr;
    struct value *val;
@@ -15599,7 +13399,7 @@ index ce9f551..5f9d739 100644
    struct type *real_type = NULL;
    struct type *type;
    int full = 0;
-@@ -126,12 +131,13 @@ whatis_exp (char *exp, int show)
+@@ -125,12 +130,13 @@ whatis_exp (char *exp, int show)
    if (exp)
      {
        expr = parse_expression (exp);
@@ -15614,7 +13414,7 @@ index ce9f551..5f9d739 100644
    type = value_type (val);
  
    get_user_print_options (&opts);
-@@ -168,8 +174,7 @@ whatis_exp (char *exp, int show)
+@@ -158,8 +164,7 @@ whatis_exp (char *exp, int show)
    type_print (type, "", gdb_stdout, show);
    printf_filtered ("\n");
  
@@ -15624,90 +13424,86 @@ index ce9f551..5f9d739 100644
  }
  
  static void
-diff --git a/gdb/valarith.c b/gdb/valarith.c
-index 0c40905..a781636 100644
---- a/gdb/valarith.c
-+++ b/gdb/valarith.c
-@@ -161,12 +161,26 @@ value_subscript (struct value *array, LONGEST index)
-       get_discrete_bounds (range_type, &lowerbound, &upperbound);
-       if (VALUE_LVAL (array) != lval_memory)
--      return value_subscripted_rvalue (array, index, lowerbound);
-+      {
-+        if (index >= lowerbound && index <= upperbound)
-+          {
-+            CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
-+            CORE_ADDR offset = (index - lowerbound) * element_size;
-+
-+            return value_subscripted_rvalue (array, offset);
-+          }
-+        error (_("array or string index out of range"));
-+      }
+diff --git a/gdb/utils.c b/gdb/utils.c
+index 5566149..6e1aa34 100644
+--- a/gdb/utils.c
++++ b/gdb/utils.c
+@@ -27,6 +27,7 @@
+ #include "exceptions.h"
+ #include "gdbthread.h"
+ #include "fnmatch.h"
++#include "gdb_bfd.h"
+ #ifdef HAVE_SYS_RESOURCE_H
+ #include <sys/resource.h>
+ #endif /* HAVE_SYS_RESOURCE_H */
+@@ -198,11 +199,11 @@ make_cleanup_dyn_string_delete (dyn_string_t arg)
+ static void
+ do_bfd_close_cleanup (void *arg)
+ {
+-  bfd_close (arg);
++  gdb_bfd_unref (arg);
+ }
  
-       if (c_style == 0)
-       {
-         if (index >= lowerbound && index <= upperbound)
--          return value_subscripted_rvalue (array, index, lowerbound);
-+          {
-+            CORE_ADDR element_size = TYPE_LENGTH (TYPE_TARGET_TYPE (tarray));
-+            CORE_ADDR offset = (index - lowerbound) * element_size;
-+
-+            return value_subscripted_rvalue (array, offset);
-+          }
-         /* Emit warning unless we have an array of unknown size.
-            An array of unknown size has lowerbound 0 and upperbound -1.  */
-         if (upperbound > -1)
-@@ -185,34 +199,37 @@ value_subscript (struct value *array, LONGEST index)
-     error (_("not an array or string"));
+ struct cleanup *
+-make_cleanup_bfd_close (bfd *abfd)
++make_cleanup_bfd_unref (bfd *abfd)
+ {
+   return make_cleanup (do_bfd_close_cleanup, abfd);
+ }
+@@ -1738,6 +1739,36 @@ set_batch_flag_and_make_cleanup_restore_page_info (void)
+   return back_to;
  }
  
--/* Return the value of EXPR[IDX], expr an aggregate rvalue
--   (eg, a vector register).  This routine used to promote floats
--   to doubles, but no longer does.  */
-+/* Return the value of *((void *) ARRAY + ELEMENT), ARRAY an aggregate rvalue
-+   (eg, a vector register).  This routine used to promote floats to doubles,
-+   but no longer does.  OFFSET is zero-based with 0 for the lowermost existing
-+   element, it must be expressed in bytes (therefore multiplied by
-+   check_typedef (TYPE_TARGET_TYPE (array_type)).  */
++/* Helper for make_cleanup_restore_page_info.  */
++
++static void
++do_restore_selected_frame_cleanup (void *arg)
++{
++  struct frame_id *frame_idp = arg;
++
++  select_frame (frame_find_by_id (*frame_idp));
++
++  xfree (frame_idp);
++}
++
++/* Provide cleanup for restoring currently selected frame.  Use frame_id for
++   the case the current frame becomes stale in the meantime.  */
++
++struct cleanup *
++make_cleanup_restore_selected_frame (void)
++{
++  struct frame_id *frame_idp;
++
++  /* get_selected_frame->get_current_frame would error otherwise.  */
++  if (!has_stack_frames ())
++    return make_cleanup (null_cleanup, NULL);
++
++  frame_idp = xmalloc (sizeof (*frame_idp));
++  *frame_idp = get_frame_id (get_selected_frame (NULL));
++
++  return make_cleanup (do_restore_selected_frame_cleanup, frame_idp);
++}
++
+ /* Set the screen size based on LINES_PER_PAGE and CHARS_PER_LINE.  */
  
- struct value *
--value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
-+value_subscripted_rvalue (struct value *array, CORE_ADDR offset)
- {
+ static void
+diff --git a/gdb/valarith.c b/gdb/valarith.c
+index 96d5411..37bd464 100644
+--- a/gdb/valarith.c
++++ b/gdb/valarith.c
+@@ -197,7 +197,10 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
    struct type *array_type = check_typedef (value_type (array));
    struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
--  unsigned int elt_size = TYPE_LENGTH (elt_type);
+   unsigned int elt_size = TYPE_LENGTH (elt_type);
 -  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
++  unsigned int elt_stride
++    = (TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type)) == 0
++       ? elt_size : TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type)));
++  unsigned int elt_offs = elt_stride * longest_to_int (index - lowerbound);
    struct value *v;
  
--  if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
--                           && elt_offs >= TYPE_LENGTH (array_type)))
--    error (_("no such vector element"));
-+  /* Do not check TYPE_LENGTH (array_type) as we may have been given the
-+     innermost dimension of a multi-dimensional Fortran array where its length
-+     is shorter than the possibly accessed element offset.  */
-   v = allocate_value (elt_type);
-   if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
-     set_value_lazy (v, 1);
-   else
--    memcpy (value_contents_writeable (v),
--          value_contents (array) + elt_offs, elt_size);
-+    {
-+      unsigned int elt_size = TYPE_LENGTH (elt_type);
-+      memcpy (value_contents_writeable (v),
-+            value_contents (array) + offset, elt_size);
-+    }
-   set_value_component_location (v, array);
-   VALUE_REGNUM (v) = VALUE_REGNUM (array);
-   VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
--  set_value_offset (v, value_offset (array) + elt_offs);
-+  set_value_offset (v, value_offset (array) + offset);
-   return v;
- }
-@@ -292,6 +309,10 @@ int
+   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
+@@ -297,6 +300,10 @@ int
  binop_user_defined_p (enum exp_opcode op,
                      struct value *arg1, struct value *arg2)
  {
@@ -15719,18 +13515,18 @@ index 0c40905..a781636 100644
  }
  
 diff --git a/gdb/valops.c b/gdb/valops.c
-index 7fbad10..8e32405 100644
+index 97d889b..6ae77b8 100644
 --- a/gdb/valops.c
 +++ b/gdb/valops.c
-@@ -38,6 +38,7 @@
- #include "cp-support.h"
- #include "dfp.h"
- #include "user-regs.h"
+@@ -45,6 +45,7 @@
+ #include "objfiles.h"
+ #include "symtab.h"
+ #include "exceptions.h"
 +#include "dwarf2loc.h"
  
- #include <errno.h>
- #include "gdb_string.h"
-@@ -858,6 +859,65 @@ value_one (struct type *type, enum lval_type lv)
+ extern int overload_debug;
+ /* Local functions.  */
+@@ -919,6 +920,65 @@ value_one (struct type *type)
    return val;
  }
  
@@ -15796,7 +13592,17 @@ index 7fbad10..8e32405 100644
  /* Helper function for value_at, value_at_lazy, and value_at_lazy_stack.  */
  
  static struct value *
-@@ -956,15 +1016,21 @@ value_fetch_lazy (struct value *val)
+@@ -981,7 +1041,8 @@ int
+ value_fetch_lazy (struct value *val)
+ {
+   gdb_assert (value_lazy (val));
+-  allocate_value_contents (val);
++  if (VALUE_LVAL (val) != lval_memory)
++    allocate_value_contents (val);
+   if (value_bitsize (val))
+     {
+       /* To read a lazy bitfield, read the entire enclosing value.  This
+@@ -1015,12 +1076,24 @@ value_fetch_lazy (struct value *val)
      }
    else if (VALUE_LVAL (val) == lval_memory)
      {
@@ -15805,27 +13611,28 @@ index 7fbad10..8e32405 100644
 +      CORE_ADDR addr = value_raw_address (val);
  
 -      if (length)
+-      read_value_memory (val, 0, value_stack (val),
+-                         addr, value_contents_all_raw (val), length);
 +      if (object_address_get_data (value_type (val), &addr))
-       {
--        if (value_stack (val))
--          read_stack (addr, value_contents_all_raw (val), length);
--        else
--          read_memory (addr, value_contents_all_raw (val), length);
++      {
 +        struct type *type = value_enclosing_type (val);
 +        int length = TYPE_LENGTH (check_typedef (type));
 +
 +        if (length)
 +          {
++            /* Delay it after object_address_get_data above.  */
++            allocate_value_contents (val);
 +            addr += value_offset (val);
-+            if (value_stack (val))
-+              read_stack (addr, value_contents_all_raw (val), length);
-+            else
-+              read_memory (addr, value_contents_all_raw (val), length);
++            read_value_memory (val, 0, value_stack (val),
++                               addr, value_contents_all_raw (val), length);
 +          }
-       }
++      }
++      /* Just to be sure it has been called.  */
++      allocate_value_contents (val);
      }
    else if (VALUE_LVAL (val) == lval_register)
-@@ -1374,7 +1440,18 @@ address_of_variable (struct symbol *var, struct block *b)
+     {
+@@ -1530,7 +1603,18 @@ address_of_variable (struct symbol *var, struct block *b)
    if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
        || TYPE_CODE (type) == TYPE_CODE_FUNC)
      {
@@ -15845,7 +13652,7 @@ index 7fbad10..8e32405 100644
  
        return value_from_pointer (lookup_pointer_type (type), addr);
      }
-@@ -1481,6 +1558,7 @@ struct value *
+@@ -1637,6 +1721,7 @@ struct value *
  value_coerce_array (struct value *arg1)
  {
    struct type *type = check_typedef (value_type (arg1));
@@ -15853,7 +13660,7 @@ index 7fbad10..8e32405 100644
  
    /* If the user tries to do something requiring a pointer with an
       array that has not yet been pushed to the target, then this would
-@@ -1490,8 +1568,12 @@ value_coerce_array (struct value *arg1)
+@@ -1646,8 +1731,12 @@ value_coerce_array (struct value *arg1)
    if (VALUE_LVAL (arg1) != lval_memory)
      error (_("Attempt to take address of value not located in memory."));
  
@@ -15867,19 +13674,28 @@ index 7fbad10..8e32405 100644
  }
  
  /* Given a value which is a function, return a value which is a pointer
+@@ -3769,6 +3858,8 @@ value_slice (struct value *array, int lowbound, int length)
+                                       TYPE_TARGET_TYPE (range_type),
+                                       lowbound, 
+                                       lowbound + length - 1);
++  TYPE_BYTE_STRIDE (slice_range_type) = TYPE_BYTE_STRIDE (range_type);
++
+   if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING)
+     {
+       int i;
 diff --git a/gdb/valprint.c b/gdb/valprint.c
-index ad6268e..fb0ef7a 100644
+index fc5942d..8333eb4 100644
 --- a/gdb/valprint.c
 +++ b/gdb/valprint.c
-@@ -36,6 +36,7 @@
- #include "dfp.h"
- #include "python/python.h"
- #include "ada-lang.h"
+@@ -37,6 +37,7 @@
+ #include "gdb_obstack.h"
+ #include "charset.h"
+ #include <ctype.h>
 +#include "dwarf2loc.h"
  
  #include <errno.h>
  
-@@ -237,7 +238,6 @@ scalar_type_p (struct type *type)
+@@ -251,7 +252,6 @@ scalar_type_p (struct type *type)
      case TYPE_CODE_STRUCT:
      case TYPE_CODE_UNION:
      case TYPE_CODE_SET:
@@ -15887,7 +13703,7 @@ index ad6268e..fb0ef7a 100644
      case TYPE_CODE_BITSTRING:
        return 0;
      default:
-@@ -1142,6 +1142,7 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
+@@ -1570,6 +1570,7 @@ val_print_array_elements (struct type *type,
  {
    unsigned int things_printed = 0;
    unsigned len;
@@ -15895,10 +13711,10 @@ index ad6268e..fb0ef7a 100644
    struct type *elttype, *index_type;
    unsigned eltlen;
    /* Position of the array element we are examining to see
-@@ -1150,9 +1151,33 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
+@@ -1578,9 +1579,33 @@ val_print_array_elements (struct type *type,
    /* Number of repetitions we have detected so far.  */
    unsigned int reps;
-   LONGEST low_bound_index = 0;
+   LONGEST low_bound, high_bound;
 +  struct cleanup *back_to;
 +  CORE_ADDR saved_address = address;
 +  
@@ -15930,18 +13746,8 @@ index ad6268e..fb0ef7a 100644
 +  eltlen = TYPE_ARRAY_BYTE_STRIDE_VALUE (type);
    index_type = TYPE_INDEX_TYPE (type);
  
-   /* Compute the number of elements in the array.  On most arrays,
-@@ -1160,9 +1185,6 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
-      is simply the size of the array divided by the size of the elements.
-      But for arrays of elements whose size is zero, we need to look at
-      the bounds.  */
--  if (eltlen != 0)
--    len = TYPE_LENGTH (type) / eltlen;
--  else
-     {
-       LONGEST low, hi;
-@@ -1236,6 +1258,8 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
+   if (get_array_bounds (type, &low_bound, &high_bound))
+@@ -1667,6 +1692,8 @@ val_print_array_elements (struct type *type,
      {
        fprintf_filtered (stream, "...");
      }
@@ -15951,18 +13757,18 @@ index ad6268e..fb0ef7a 100644
  
  /* Read LEN bytes of target memory at address MEMADDR, placing the
 diff --git a/gdb/value.c b/gdb/value.c
-index d552402..b10269c 100644
+index a6bb718..7b08d1f 100644
 --- a/gdb/value.c
 +++ b/gdb/value.c
-@@ -39,6 +39,7 @@
- #include "objfiles.h"
- #include "valprint.h"
- #include "cli/cli-decode.h"
+@@ -42,6 +42,7 @@
+ #include <ctype.h>
+ #include "tracepoint.h"
+ #include "cp-abi.h"
 +#include "observer.h"
  
- #include "python/python.h"
+ /* Prototypes for exported functions.  */
  
-@@ -828,12 +829,15 @@ void
+@@ -1437,12 +1438,15 @@ void
  set_value_component_location (struct value *component,
                              const struct value *whole)
  {
@@ -15977,8 +13783,8 @@ index d552402..b10269c 100644
 +
    if (whole->lval == lval_computed)
      {
-       struct lval_funcs *funcs = whole->location.computed.funcs;
-@@ -841,6 +845,12 @@ set_value_component_location (struct value *component,
+       const struct lval_funcs *funcs = whole->location.computed.funcs;
+@@ -1450,6 +1454,12 @@ set_value_component_location (struct value *component,
        if (funcs->copy_closure)
          component->location.computed.closure = funcs->copy_closure (whole);
      }
@@ -15991,7 +13797,7 @@ index d552402..b10269c 100644
  }
  
  \f
-@@ -973,6 +983,29 @@ show_values (char *num_exp, int from_tty)
+@@ -1583,6 +1593,31 @@ show_values (char *num_exp, int from_tty)
        num_exp[1] = '\0';
      }
  }
@@ -16016,15 +13822,18 @@ index d552402..b10269c 100644
 +
 +  /* Free the unreferenced types above.  */
 +  free_all_values ();
++#if 0
 +  free_all_types ();
++#endif
 +}
  \f
  /* Internal variables.  These are variables within the debugger
     that hold values assigned by debugger commands.
-@@ -1451,6 +1484,40 @@ call_internal_function (struct gdbarch *gdbarch,
+@@ -2118,6 +2153,38 @@ call_internal_function (struct gdbarch *gdbarch,
    return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
  }
  
++#if 0
 +/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
 +
 +static void
@@ -16043,10 +13852,6 @@ index d552402..b10269c 100644
 +      case INTERNALVAR_INTEGER:
 +      type_mark_used (var->u.integer.type);
 +      break;
-+
-+      case INTERNALVAR_POINTER:
-+      type_mark_used (var->u.pointer.type);
-+      break;
 +      }
 +
 +  for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
@@ -16058,11 +13863,12 @@ index d552402..b10269c 100644
 +        type_mark_used (value_type (chunk->values[i]));
 +    }
 +}
++#endif
 +
  /* The 'function' command.  This does nothing -- it is just a
     placeholder to let "help function NAME" work.  This is also used as
     the implementation of the sub-command that is created when
-@@ -1498,11 +1565,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
+@@ -2165,11 +2232,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
                    htab_t copied_types)
  {
    if (TYPE_OBJFILE (value->type) == objfile)
@@ -16076,7 +13882,7 @@ index d552402..b10269c 100644
                                                 copied_types);
  }
  
-@@ -1517,13 +1583,13 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
+@@ -2184,7 +2250,7 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
      case INTERNALVAR_INTEGER:
        if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
        var->u.integer.type
@@ -16084,21 +13890,16 @@ index d552402..b10269c 100644
 +        = copy_type_recursive (var->u.integer.type, copied_types);
        break;
  
-     case INTERNALVAR_POINTER:
-       if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
-       var->u.pointer.type
--        = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
-+        = copy_type_recursive (var->u.pointer.type, copied_types);
-       break;
      case INTERNALVAR_VALUE:
-@@ -2387,7 +2453,24 @@ value_from_decfloat (struct type *type, const gdb_byte *dec)
+@@ -3276,10 +3342,27 @@ readjust_indirect_value_type (struct value *value, struct type *enc_type,
  struct value *
  coerce_ref (struct value *arg)
  {
 -  struct type *value_type_arg_tmp = check_typedef (value_type (arg));
 +  struct type *value_type_arg_tmp;
-+
+   struct value *retval;
+   struct type *enc_type;
 +  if (TYPE_DYNAMIC (value_type (arg)))
 +    {
 +      struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
@@ -16115,25 +13916,28 @@ index d552402..b10269c 100644
 +    }
 +  else
 +    value_type_arg_tmp = check_typedef (value_type (arg));
-   if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
-     arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
-@@ -2485,4 +2568,8 @@ VARIABLE is already initialized."));
++
+   retval = coerce_ref_if_computed (arg);
+   if (retval)
+     return retval;
+@@ -3386,4 +3469,10 @@ VARIABLE is already initialized."));
    add_prefix_cmd ("function", no_class, function_command, _("\
  Placeholder command for showing help on convenience functions."),
                  &functionlist, "function ", 0, &cmdlist);
 +
 +  make_final_cleanup (value_history_cleanup, NULL);
 +
++#if 0
 +  observer_attach_mark_used (value_types_mark_used);
++#endif
  }
 diff --git a/gdb/value.h b/gdb/value.h
-index 12cbc0a..a508bf6 100644
+index d8b157f..f49e827 100644
 --- a/gdb/value.h
 +++ b/gdb/value.h
-@@ -372,6 +372,10 @@ extern struct value *value_from_double (struct type *type, DOUBLEST num);
- extern struct value *value_from_decfloat (struct type *type,
+@@ -533,6 +533,10 @@ extern struct value *value_from_decfloat (struct type *type,
                                          const gdb_byte *decbytes);
+ extern struct value *value_from_history_ref (char *, char **);
  
 +extern const char *object_address_data_not_valid (struct type *type);
 +extern struct type *object_address_get_data (struct type *type,
@@ -16142,25 +13946,34 @@ index 12cbc0a..a508bf6 100644
  extern struct value *value_at (struct type *type, CORE_ADDR addr);
  extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
  
-@@ -729,7 +733,7 @@ extern struct value *value_allocate_space_in_inferior (int);
- extern struct value *value_of_local (const char *name, int complain);
+diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
+index f16588a..afef615 100644
+--- a/gdb/windows-nat.c
++++ b/gdb/windows-nat.c
+@@ -752,7 +752,7 @@ windows_make_so (const char *name, LPVOID load_addr)
+       asection *text = NULL;
+       CORE_ADDR text_vma;
  
- extern struct value *value_subscripted_rvalue (struct value *array,
--                                             LONGEST index, int lowerbound);
-+                                             CORE_ADDR offset);
+-      abfd = bfd_openr (so->so_name, "pei-i386");
++      abfd = gdb_bfd_openr (so->so_name, "pei-i386");
  
- /* User function handler.  */
+       if (!abfd)
+       return so;
+@@ -762,7 +762,7 @@ windows_make_so (const char *name, LPVOID load_addr)
  
-diff --git a/gdb/varobj.c b/gdb/varobj.c
-index b9b8e91..a81d25c 100644
---- a/gdb/varobj.c
-+++ b/gdb/varobj.c
-@@ -26,6 +26,8 @@
- #include "gdbcmd.h"
- #include "block.h"
- #include "valprint.h"
-+#include "objfiles.h"
-+#include "parser-defs.h"
+       if (!text)
+       {
+-        bfd_close (abfd);
++        gdb_bfd_unref (abfd);
+         return so;
+       }
+@@ -773,7 +773,7 @@ windows_make_so (const char *name, LPVOID load_addr)
+                                                  load_addr + 0x1000);
+       cygwin_load_end = cygwin_load_start + bfd_section_size (abfd, text);
+-      bfd_close (abfd);
++      gdb_bfd_unref (abfd);
+     }
+ #endif
  
- #include "gdb_assert.h"
- #include "gdb_string.h"
This page took 1.0336 seconds and 4 git commands to generate.