36474ab
http://sourceware.org/gdb/wiki/ProjectArcher
36474ab
http://sourceware.org/gdb/wiki/ArcherBranchManagement
36474ab
36474ab
GIT snapshot:
872aab0
commit a980be3b9cc66774adfb9a25da805f65cfed4245
36474ab
872aab0
branch jankratochvil/fedora20 - the merge of branches:
1054fa6
jankratochvil/vla
1054fa6
tromey/python
36474ab
36474ab
1054fa6
diff --git a/README.archer b/README.archer
1054fa6
new file mode 100644
872aab0
index 0000000..21357e4
1054fa6
--- /dev/null
1054fa6
+++ b/README.archer
1054fa6
@@ -0,0 +1,13 @@
872aab0
+Merge for Fedora 20: http://pkgs.fedoraproject.org/cgit/gdb.git/
1054fa6
+
1054fa6
+jankratochvil/vla
1054fa6
+tromey/python
1054fa6
+
1054fa6
+================================================================
1054fa6
+This branch originally held the Python code for gdb.  It still exists
1054fa6
+because a small amount of code here has not yet been merged upstream.
1054fa6
+
1054fa6
+================================================================
1054fa6
+C variable length arrays / DW_FORM_block / Fortran dynamic arrays.
1054fa6
+implementation plan:             http://sourceware.org/ml/gdb/2012-11/msg00094.html
1054fa6
+explanation of its merge status: http://sourceware.org/ml/gdb/2011-03/msg00021.html
254f0e9
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
872aab0
index 8f4ee9e..e914dfb 100644
254f0e9
--- a/gdb/Makefile.in
254f0e9
+++ b/gdb/Makefile.in
872aab0
@@ -1351,6 +1351,12 @@ stamp-h: $(srcdir)/config.in config.status
33ff709
 	  CONFIG_LINKS= \
33ff709
 	  $(SHELL) config.status
33ff709
 
33ff709
+.gdbinit: $(srcdir)/gdbinit.in config.status
33ff709
+	CONFIG_FILES=".gdbinit:gdbinit.in" \
33ff709
+	  CONFIG_COMMANDS= \
33ff709
+	  CONFIG_HEADERS= \
33ff709
+	  $(SHELL) config.status
33ff709
+
872aab0
 config.status: $(srcdir)/configure configure.tgt configure.host development.sh
33ff709
 	$(SHELL) config.status --recheck
33ff709
 
254f0e9
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
872aab0
index dc5f2b6..5feac49 100644
254f0e9
--- a/gdb/ada-lang.c
254f0e9
+++ b/gdb/ada-lang.c
872aab0
@@ -12309,6 +12309,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
79563d6
 
dd46ae6
 static int
dd46ae6
 ada_operator_check (struct expression *exp, int pos,
dd46ae6
+		    int (*type_func) (struct type *type, void *data),
dd46ae6
 		    int (*objfile_func) (struct objfile *objfile, void *data),
dd46ae6
 		    void *data)
79563d6
 {
872aab0
@@ -12323,12 +12324,15 @@ ada_operator_check (struct expression *exp, int pos,
dd46ae6
 	break;
1592379
 
dd46ae6
       default:
dd46ae6
-	return operator_check_standard (exp, pos, objfile_func, data);
e5611bf
+	return operator_check_standard (exp, pos, type_func, objfile_func,
e5611bf
+					data);
dd46ae6
     }
dd46ae6
 
dd46ae6
   /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
dd46ae6
 
dd46ae6
-  if (type && TYPE_OBJFILE (type)
e5611bf
+  if (type && type_func && (*type_func) (type, data))
e5611bf
+    return 1;
e5611bf
+  if (type && TYPE_OBJFILE (type) && objfile_func
dd46ae6
       && (*objfile_func) (TYPE_OBJFILE (type), data))
dd46ae6
     return 1;
45f7971
 
254f0e9
diff --git a/gdb/block.c b/gdb/block.c
872aab0
index 643e144..74c516b 100644
254f0e9
--- a/gdb/block.c
254f0e9
+++ b/gdb/block.c
872aab0
@@ -693,3 +693,21 @@ block_iter_match_next (const char *name,
6fcb74e
 
f8eee05
   return block_iter_match_step (iterator, name, compare, 0);
6fcb74e
 }
e5611bf
+
e5611bf
+/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
e5611bf
+   whatever reason.  */
e5611bf
+
e5611bf
+struct objfile *
e5611bf
+block_objfile (const struct block *block)
e5611bf
+{
e5611bf
+  struct symbol *func;
e5611bf
+
e5611bf
+  if (block == NULL)
e5611bf
+    return NULL;
e5611bf
+
e5611bf
+  func = block_linkage_function (block);
e5611bf
+  if (func == NULL)
e5611bf
+    return NULL;
e5611bf
+
e5611bf
+  return SYMBOL_SYMTAB (func)->objfile;
e5611bf
+}
254f0e9
diff --git a/gdb/block.h b/gdb/block.h
556378e
index 02e7e8b..2931401 100644
254f0e9
--- a/gdb/block.h
254f0e9
+++ b/gdb/block.h
f8eee05
@@ -279,4 +279,6 @@ extern struct symbol *block_iter_match_next (const char *name,
f8eee05
        (sym);						\
f8eee05
        (sym) = block_iterator_next (&(iter)))
6fcb74e
 
e5611bf
+extern struct objfile *block_objfile (const struct block *block);
e5611bf
+
e5611bf
 #endif /* BLOCK_H */
254f0e9
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
872aab0
index 1e89407..1f4de33 100644
254f0e9
--- a/gdb/breakpoint.c
254f0e9
+++ b/gdb/breakpoint.c
872aab0
@@ -15605,6 +15605,24 @@ all_tracepoints (void)
8c4c91e
   return tp_vec;
806f8c8
 }
806f8c8
 
d515913
+#if 0
8c4c91e
+/* Call type_mark_used for any TYPEs referenced from this GDB source file.  */
806f8c8
+
806f8c8
+static void
806f8c8
+breakpoint_types_mark_used (void)
806f8c8
+{
806f8c8
+  struct breakpoint *b;
806f8c8
+
806f8c8
+  ALL_BREAKPOINTS (b)
806f8c8
+    {
806f8c8
+      if (b->exp)
806f8c8
+	exp_types_mark_used (b->exp);
806f8c8
+      if (b->val)
806f8c8
+	type_mark_used (value_type (b->val));
806f8c8
+    }
806f8c8
+}
d515913
+#endif
806f8c8
+
806f8c8
 
6fa2f55
 /* This help string is used for the break, hbreak, tbreak and thbreak
6fa2f55
    commands.  It is defined as a macro to prevent duplication.
872aab0
@@ -16568,4 +16586,7 @@ agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
806f8c8
   automatic_hardware_breakpoints = 1;
806f8c8
 
806f8c8
   observer_attach_about_to_proceed (breakpoint_about_to_proceed);
d515913
+#if 0
806f8c8
+  observer_attach_mark_used (breakpoint_types_mark_used);
d515913
+#endif
806f8c8
 }
254f0e9
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
872aab0
index bf4564f..e8d0281 100644
254f0e9
--- a/gdb/c-typeprint.c
254f0e9
+++ b/gdb/c-typeprint.c
ab333d9
@@ -689,7 +689,13 @@ c_type_print_varspec_suffix (struct type *type,
20f9f67
 
556378e
 	fprintf_filtered (stream, (is_vector ?
556378e
 				   " __attribute__ ((vector_size(" : "["));
e00e5ea
-	if (get_array_bounds (type, &low_bound, &high_bound))
e00e5ea
+	if (TYPE_RANGE_DATA (TYPE_INDEX_TYPE (type))->high.kind
e00e5ea
+	    != RANGE_BOUND_KIND_CONSTANT)
e00e5ea
+	  {
e00e5ea
+	    /* No _() - printed sources should not be locale dependent.  */
e00e5ea
+	    fprintf_filtered (stream, "variable");
e00e5ea
+	  }
e00e5ea
+	else if (get_array_bounds (type, &low_bound, &high_bound))
556378e
 	  fprintf_filtered (stream, "%s", 
556378e
 			    plongest (high_bound - low_bound + 1));
556378e
 	fprintf_filtered (stream, (is_vector ? ")))" : "]"));
872aab0
diff --git a/gdb/cleanups.c b/gdb/cleanups.c
872aab0
index 898e526..18ebaee 100644
872aab0
--- a/gdb/cleanups.c
872aab0
+++ b/gdb/cleanups.c
872aab0
@@ -261,9 +261,11 @@ save_final_cleanups (void)
872aab0
 static void
872aab0
 restore_my_cleanups (struct cleanup **pmy_chain, struct cleanup *chain)
872aab0
 {
872aab0
+#if 0 /* archer-jankratochvil-vla */
872aab0
   if (*pmy_chain != SENTINEL_CLEANUP)
872aab0
     internal_warning (__FILE__, __LINE__,
872aab0
 		      _("restore_my_cleanups has found a stale cleanup"));
872aab0
+#endif
872aab0
 
872aab0
   *pmy_chain = chain;
872aab0
 }
254f0e9
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
872aab0
index dec6207..fbb4dc0 100644
254f0e9
--- a/gdb/data-directory/Makefile.in
254f0e9
+++ b/gdb/data-directory/Makefile.in
872aab0
@@ -61,13 +61,21 @@ PYTHON_FILES = \
872aab0
 	gdb/printing.py \
872aab0
 	gdb/prompt.py \
33ff709
 	gdb/command/__init__.py \
33ff709
+	gdb/command/ignore_errors.py \
33ff709
+	gdb/command/pahole.py \
872aab0
 	gdb/command/frame_filters.py \
556378e
 	gdb/command/type_printers.py \
254f0e9
 	gdb/command/pretty_printers.py \
f8eee05
 	gdb/command/prompt.py \
556378e
 	gdb/command/explore.py \
556378e
 	gdb/function/__init__.py \
556378e
-	gdb/function/strfns.py
556378e
+	gdb/function/strfns.py \
33ff709
+	gdb/function/__init__.py \
33ff709
+	gdb/function/caller_is.py \
33ff709
+	gdb/function/in_scope.py \
33ff709
+	gdb/printing.py \
254f0e9
+	gdb/prompt.py \
33ff709
+	gdb/types.py
33ff709
 
872aab0
 SYSTEM_GDBINIT_DIR = system-gdbinit
872aab0
 SYSTEM_GDBINIT_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(SYSTEM_GDBINIT_DIR)
254f0e9
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
872aab0
index cb393e8..1dfca22 100644
254f0e9
--- a/gdb/doc/gdb.texinfo
254f0e9
+++ b/gdb/doc/gdb.texinfo
872aab0
@@ -1221,6 +1221,16 @@ for remote debugging.
33ff709
 Run using @var{device} for your program's standard input and output.
33ff709
 @c FIXME: kingdon thinks there is more to -tty.  Investigate.
33ff709
 
33ff709
+@item -P
33ff709
+@cindex @code{-P}
33ff709
+@itemx --python
33ff709
+@cindex @code{--python}
33ff709
+Change interpretation of command line so that the argument immediately
33ff709
+following this switch is taken to be the name of a Python script file.
33ff709
+This option stops option processing; subsequent options are passed to
33ff709
+Python as @code{sys.argv}.  This option is only available if Python
33ff709
+scripting support was enabled when @value{GDBN} was configured.
33ff709
+
33ff709
 @c resolve the situation of these eventually
33ff709
 @item -tui
33ff709
 @cindex @code{--tui}
872aab0
@@ -23189,8 +23199,6 @@ containing @code{end}.  For example:
33ff709
 
33ff709
 @smallexample
33ff709
 (@value{GDBP}) python
33ff709
-Type python script
33ff709
-End with a line saying just "end".
33ff709
 >print 23
33ff709
 >end
33ff709
 23
872aab0
@@ -23204,6 +23212,14 @@ controlled using @code{set python print-stack}: if @code{full}, then
254f0e9
 full Python stack printing is enabled; if @code{none}, then Python stack
254f0e9
 and message printing is disabled; if @code{message}, the default, only
254f0e9
 the message component of the error is printed.
33ff709
+
33ff709
+@kindex maint set python auto-load
33ff709
+@item maint set python auto-load
33ff709
+By default, @value{GDBN} will attempt to automatically load Python
33ff709
+code when an object file is opened.  This can be controlled using
33ff709
+@code{maint set python auto-load}: if @code{on}, the default, then
33ff709
+Python auto-loading is enabled; if @code{off}, then Python
33ff709
+auto-loading is disabled.
33ff709
 @end table
33ff709
 
33ff709
 It is also possible to execute a Python script from the @value{GDBN}
254f0e9
diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
872aab0
index 60805ad..5411012 100644
254f0e9
--- a/gdb/doc/gdbint.texinfo
254f0e9
+++ b/gdb/doc/gdbint.texinfo
872aab0
@@ -2146,6 +2146,18 @@ time, and so we attempt to handle symbols incrementally.  For instance,
dd46ae6
 we create @dfn{partial symbol tables} consisting of only selected
dd46ae6
 symbols, and only expand them to full symbol tables when necessary.
dd46ae6
 
dd46ae6
+@menu
dd46ae6
+* Symbol Reading::
dd46ae6
+* Partial Symbol Tables::
dd46ae6
+* Types::
dd46ae6
+* Object File Formats::
dd46ae6
+* Debugging File Formats::
dd46ae6
+* Adding a New Symbol Reader to GDB::
dd46ae6
+* Memory Management for Symbol Files::
dd46ae6
+* Memory Management for Types::
dd46ae6
+@end menu
e5611bf
+
dd46ae6
+@node Symbol Reading
dd46ae6
 @section Symbol Reading
1592379
 
dd46ae6
 @cindex symbol reading
872aab0
@@ -2238,6 +2250,7 @@ symtab.  Upon return, @code{pst->readin} should have been set to 1, and
dd46ae6
 zero if there were no symbols in that part of the symbol file.
dd46ae6
 @end table
1592379
 
dd46ae6
+@node Partial Symbol Tables
dd46ae6
 @section Partial Symbol Tables
1592379
 
dd46ae6
 @value{GDBN} has three types of symbol tables:
872aab0
@@ -2339,6 +2352,7 @@ and partial symbol tables behind a set of function pointers known as
dd46ae6
 the @dfn{quick symbol functions}.  These are documented in
dd46ae6
 @file{symfile.h}.
1592379
 
dd46ae6
+@node Types
dd46ae6
 @section Types
1592379
 
dd46ae6
 @unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
872aab0
@@ -2361,6 +2375,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
dd46ae6
 other members of the type struct, such as whether the type is signed
dd46ae6
 or unsigned, and how many bits it uses.
79563d6
 
dd46ae6
+@anchor{Builtin Types}
dd46ae6
 @unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
79563d6
 
dd46ae6
 These are instances of type structs that roughly correspond to
872aab0
@@ -2375,6 +2390,7 @@ only one instance exists, while @file{c-lang.c} builds as many
dd46ae6
 @code{TYPE_CODE_INT} types as needed, with each one associated with
dd46ae6
 some particular objfile.
79563d6
 
dd46ae6
+@node Object File Formats
dd46ae6
 @section Object File Formats
dd46ae6
 @cindex object file formats
79563d6
 
872aab0
@@ -2460,6 +2476,7 @@ SOM, which is a cross-language ABI).
79563d6
 
dd46ae6
 The SOM reader is in @file{somread.c}.
ee681d3
 
dd46ae6
+@node Debugging File Formats
dd46ae6
 @section Debugging File Formats
ee681d3
 
dd46ae6
 This section describes characteristics of debugging information that
872aab0
@@ -2531,6 +2548,7 @@ DWARF 3 is an improved version of DWARF 2.
dd46ae6
 @cindex SOM debugging info
dd46ae6
 Like COFF, the SOM definition includes debugging information.
79563d6
 
dd46ae6
+@node Adding a New Symbol Reader to GDB
dd46ae6
 @section Adding a New Symbol Reader to @value{GDBN}
79563d6
 
dd46ae6
 @cindex adding debugging info reader
872aab0
@@ -2553,6 +2571,7 @@ will only ever be implemented by one object file format may be called
dd46ae6
 directly.  This interface should be described in a file
dd46ae6
 @file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
dd46ae6
 
dd46ae6
+@node Memory Management for Symbol Files
dd46ae6
 @section Memory Management for Symbol Files
dd46ae6
 
dd46ae6
 Most memory associated with a loaded symbol file is stored on
872aab0
@@ -2564,10 +2583,45 @@ released when the objfile is unloaded or reloaded.  Therefore one
dd46ae6
 objfile must not reference symbol or type data from another objfile;
dd46ae6
 they could be unloaded at different times.
dd46ae6
 
dd46ae6
-User convenience variables, et cetera, have associated types.  Normally
dd46ae6
-these types live in the associated objfile.  However, when the objfile
dd46ae6
-is unloaded, those types are deep copied to global memory, so that
dd46ae6
-the values of the user variables and history items are not lost.
dd46ae6
+@node Memory Management for Types
dd46ae6
+@section Memory Management for Types
dd46ae6
+@cindex memory management for types
45f7971
+
dd46ae6
+@findex TYPE_OBJFILE
dd46ae6
+@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
dd46ae6
+Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
dd46ae6
+obstack) and in such case the type remains valid till the objfile is unloaded
dd46ae6
+or reloaded.  For such types with an associated objfile no reference counting
dd46ae6
+is being made.
45f7971
+
dd46ae6
+User convenience variables, et cetera, have associated types.  Normally these
dd46ae6
+types live in the associated objfile.  However, when the objfile is unloaded,
dd46ae6
+those types are deep copied to global memory, so that the values of the user
dd46ae6
+variables and history items are not lost.  During the copy they will get their
dd46ae6
+@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
dd46ae6
+types.
45f7971
+
dd46ae6
+Types with null @code{TYPE_OBJFILE} can be either permanent types
dd46ae6
+(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
dd46ae6
+first idle @value{GDBN} moment if the last object referencing them is removed.
dd46ae6
+Permanent types are allocated by the function @code{alloc_type} (and its
dd46ae6
+derivations like @code{init_type}) specifying objfile as @code{NULL}.  The
dd46ae6
+reclaimable types are created the same way but moreover they need to have
dd46ae6
+@code{type_init_group} called to start their tracking as being possibly
dd46ae6
+deallocatable.
45f7971
+
dd46ae6
+@findex free_all_types
dd46ae6
+When @value{GDBN} gets idle it always calls the @code{free_all_types} function
dd46ae6
+which deallocates any unused types.  All types currently not owned by an
dd46ae6
+objfile must be marked as used on each @code{free_all_types} call as they would
dd46ae6
+get deallocated as unused otherwise.
45f7971
+
dd46ae6
+@code{free_all_types} automatically checks for any cross-type references such
dd46ae6
+as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
dd46ae6
+prevents early deallocation for any such existing references.  Reclaimable
dd46ae6
+types may reference any other reclaimable types or even permanent types.  But
dd46ae6
+permanent types must not reference reclaimable types (nor an objfile associated
dd46ae6
+type).
79563d6
 
45f7971
 
dd46ae6
 @node Language Support
254f0e9
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
ab333d9
index adb7085..5ec5b5a 100644
254f0e9
--- a/gdb/doc/observer.texi
254f0e9
+++ b/gdb/doc/observer.texi
ab333d9
@@ -249,6 +249,11 @@ The trace state variable @var{tsv} is deleted.  If @var{tsv} is
ab333d9
 The trace state value @var{tsv} is modified.
dd46ae6
 @end deftypefun
45f7971
 
d515913
+@c @deftypefun void mark_used (void)
d515913
+@c Mark any possibly reclaimable objects as used during a mark-and-sweep garbage
d515913
+@c collector pass.  Currently only @code{type_mark_used} marker is supported.
d515913
+@c @end deftypefun
ee681d3
+
dd46ae6
 @deftypefun void test_notification (int @var{somearg})
dd46ae6
 This observer is used for internal testing.  Do not use.  
dd46ae6
 See testsuite/gdb.gdb/observer.exp.
254f0e9
diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
556378e
index 752d782..ab0a3eb 100644
254f0e9
--- a/gdb/dwarf2expr.c
254f0e9
+++ b/gdb/dwarf2expr.c
556378e
@@ -1479,6 +1479,14 @@ execute_stack_op (struct dwarf_expr_context *ctx,
3b55f78
 	  }
3b55f78
 	  break;
dd46ae6
 
dd46ae6
+	case DW_OP_push_object_address:
3b55f78
+	  if (ctx->funcs->get_object_address == NULL)
dd46ae6
+	    error (_("DWARF-2 expression error: DW_OP_push_object_address must "
dd46ae6
+	           "have a value to push."));
3b55f78
+	  result = (ctx->funcs->get_object_address) (ctx->baton);
3b55f78
+	  result_val = value_from_ulongest (address_type, result);
dd46ae6
+	  break;
ee681d3
+
dd46ae6
 	default:
dd46ae6
 	  error (_("Unhandled dwarf expression opcode 0x%x"), op);
79563d6
 	}
254f0e9
diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
556378e
index e85486a..e7ac799 100644
254f0e9
--- a/gdb/dwarf2expr.h
254f0e9
+++ b/gdb/dwarf2expr.h
556378e
@@ -77,12 +77,8 @@ struct dwarf_expr_context_funcs
f8eee05
      This can throw an exception if the index is out of range.  */
f8eee05
   CORE_ADDR (*get_addr_index) (void *baton, unsigned int index);
3b55f78
 
3b55f78
-#if 0
f8eee05
-  /* Not yet implemented.  */
f8eee05
-
dd46ae6
   /* Return the `object address' for DW_OP_push_object_address.  */
dd46ae6
   CORE_ADDR (*get_object_address) (void *baton);
dd46ae6
-#endif
3b55f78
 };
79563d6
 
3b55f78
 /* The location of a value.  */
254f0e9
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
872aab0
index 02afcdf..5a21629 100644
254f0e9
--- a/gdb/dwarf2loc.c
254f0e9
+++ b/gdb/dwarf2loc.c
872aab0
@@ -306,6 +306,9 @@ struct dwarf_expr_baton
79563d6
 {
dd46ae6
   struct frame_info *frame;
dd46ae6
   struct dwarf2_per_cu_data *per_cu;
dd46ae6
+  /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
dd46ae6
+     DW_AT_data_location) for DW_OP_push_object_address.  */
dd46ae6
+  CORE_ADDR object_address;
dd46ae6
 };
79563d6
 
dd46ae6
 /* Helper functions for dwarf2_evaluate_loc_desc.  */
872aab0
@@ -421,7 +424,7 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
79563d6
 
254f0e9
   if (*length == 0)
dd46ae6
     error (_("Could not find the frame base for \"%s\"."),
dd46ae6
-	   SYMBOL_NATURAL_NAME (framefunc));
dd46ae6
+	   SYMBOL_PRINT_NAME (framefunc));
79563d6
 }
79563d6
 
dd46ae6
 /* Helper function for dwarf2_evaluate_loc_desc.  Computes the CFA for
872aab0
@@ -488,6 +491,85 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset)
3b55f78
 		     ctx->funcs->get_frame_pc, ctx->baton);
ee681d3
 }
dd46ae6
 
dd46ae6
+static CORE_ADDR
dd46ae6
+dwarf_expr_object_address (void *baton)
dd46ae6
+{
dd46ae6
+  struct dwarf_expr_baton *debaton = baton;
dd46ae6
+
dd46ae6
+  /* The message is suppressed in DWARF_BLOCK_EXEC.  */
dd46ae6
+  if (debaton->object_address == 0)
dd46ae6
+    error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
dd46ae6
+
dd46ae6
+  return debaton->object_address;
dd46ae6
+}
dd46ae6
+
dd46ae6
+/* Address of the variable we are currently referring to.  It is set from
dd46ae6
+   DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
dd46ae6
+   DW_OP_push_object_address.  */
dd46ae6
+
dd46ae6
+static CORE_ADDR object_address;
dd46ae6
+
dd46ae6
+/* Callers use object_address_set while their callers use the result set so we
dd46ae6
+   cannot run the cleanup at the local block of our direct caller.  Still we
dd46ae6
+   should reset OBJECT_ADDRESS at least for the next GDB command.  */
ee681d3
+
ee681d3
+static void
dd46ae6
+object_address_cleanup (void *prev_save_voidp)
ee681d3
+{
dd46ae6
+  CORE_ADDR *prev_save = prev_save_voidp;
ee681d3
+
dd46ae6
+  object_address = *prev_save;
dd46ae6
+  xfree (prev_save);
dd46ae6
+}
dd46ae6
+
dd46ae6
+/* Set the base address - DW_AT_location - of a variable.  It is being later
dd46ae6
+   used to derive other object addresses by DW_OP_push_object_address.
dd46ae6
+
dd46ae6
+   It would be useful to sanity check ADDRESS - such as for some objects with
dd46ae6
+   unset value_raw_address - but some valid addresses may be zero (such as first
dd46ae6
+   objects in relocatable .o files).  */
dd46ae6
+
dd46ae6
+void
dd46ae6
+object_address_set (CORE_ADDR address)
dd46ae6
+{
dd46ae6
+  CORE_ADDR *prev_save;
dd46ae6
+
dd46ae6
+  prev_save = xmalloc (sizeof *prev_save);
dd46ae6
+  *prev_save = object_address;
dd46ae6
+  make_cleanup (object_address_cleanup, prev_save);
dd46ae6
+
dd46ae6
+  object_address = address;
ee681d3
+}
ee681d3
+
3b55f78
+/* Evaluate DWARF location list at DLLBATON expecting it produces exactly one
3b55f78
+   CORE_ADDR result stored to *ADDRP on the DWARF stack stack.  If the result
3b55f78
+   could not be found return zero and keep *ADDRP unchanged.  */
3b55f78
+
3b55f78
+int
3b55f78
+dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
3b55f78
+			  struct type *type, CORE_ADDR *addrp)
3b55f78
+{
3b55f78
+  struct frame_info *frame = get_selected_frame (NULL);
3b55f78
+  const gdb_byte *data;
3b55f78
+  size_t size;
3b55f78
+  struct value *val;
3b55f78
+
3b55f78
+  if (!dllbaton)
3b55f78
+    return 0;
3b55f78
+
3b55f78
+  data = dwarf2_find_location_expression (dllbaton, &size,
3b55f78
+					  get_frame_address_in_block (frame));
3b55f78
+  if (data == NULL)
3b55f78
+    return 0;
3b55f78
+
3b55f78
+  val = dwarf2_evaluate_loc_desc (type, frame, data, size, dllbaton->per_cu);
3b55f78
+  if (value_optimized_out (val))
3b55f78
+    return 0;
3b55f78
+
3b55f78
+  *addrp = value_as_address (val);
3b55f78
+  return 1;
3b55f78
+}
3b55f78
+
3b55f78
 /* Callback function for dwarf2_evaluate_loc_desc.  */
3b55f78
 
3b55f78
 static struct type *
872aab0
@@ -1202,10 +1284,12 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
254f0e9
 
254f0e9
   saved_ctx.gdbarch = ctx->gdbarch;
254f0e9
   saved_ctx.addr_size = ctx->addr_size;
254f0e9
+  saved_ctx.ref_addr_size = ctx->ref_addr_size;
254f0e9
   saved_ctx.offset = ctx->offset;
254f0e9
   saved_ctx.baton = ctx->baton;
254f0e9
   ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (baton_local.per_cu));
254f0e9
   ctx->addr_size = dwarf2_per_cu_addr_size (baton_local.per_cu);
254f0e9
+  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (baton_local.per_cu);
254f0e9
   ctx->offset = dwarf2_per_cu_text_offset (baton_local.per_cu);
254f0e9
   ctx->baton = &baton_local;
254f0e9
 
872aab0
@@ -1213,10 +1297,95 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
254f0e9
 
254f0e9
   ctx->gdbarch = saved_ctx.gdbarch;
254f0e9
   ctx->addr_size = saved_ctx.addr_size;
254f0e9
+  ctx->ref_addr_size = saved_ctx.ref_addr_size;
254f0e9
   ctx->offset = saved_ctx.offset;
254f0e9
   ctx->baton = saved_ctx.baton;
3b55f78
 }
3b55f78
 
f8eee05
+static CORE_ADDR dwarf_expr_get_addr_index (void *baton, unsigned int index);
f8eee05
+
3b55f78
+/* Virtual method table for dwarf2_evaluate_loc_desc_full below.  */
3b55f78
+
3b55f78
+static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
3b55f78
+{
3b55f78
+  dwarf_expr_read_reg,
3b55f78
+  dwarf_expr_read_mem,
3b55f78
+  dwarf_expr_frame_base,
3b55f78
+  dwarf_expr_frame_cfa,
3b55f78
+  dwarf_expr_frame_pc,
3b55f78
+  dwarf_expr_tls_address,
3b55f78
+  dwarf_expr_dwarf_call,
3b55f78
+  dwarf_expr_get_base_type,
254f0e9
+  dwarf_expr_push_dwarf_reg_entry_value,
f8eee05
+  dwarf_expr_get_addr_index,
3b55f78
+  dwarf_expr_object_address
3b55f78
+};
3b55f78
+
dd46ae6
+/* Evaluate DWARF expression at DATA ... DATA + SIZE with its result readable
dd46ae6
+   by dwarf_expr_fetch (RETVAL, 0).  FRAME parameter can be NULL to call
dd46ae6
+   get_selected_frame to find it.  Returned dwarf_expr_context freeing is
dd46ae6
+   pushed on the cleanup chain.  */
dd46ae6
+
3b55f78
+static void
3b55f78
+dwarf_expr_prep_ctx (struct dwarf_expr_context *ctx, struct frame_info *frame,
3b55f78
+		     const gdb_byte *data, size_t size,
3b55f78
+		     struct dwarf2_per_cu_data *per_cu)
ee681d3
+{
dd46ae6
+  struct dwarf_expr_baton baton;
dd46ae6
+  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
48cf710
+  volatile struct gdb_exception ex;
dd46ae6
+
dd46ae6
+  baton.frame = frame;
dd46ae6
+  baton.per_cu = per_cu;
dd46ae6
+  baton.object_address = object_address;
dd46ae6
+
dd46ae6
+  ctx->gdbarch = get_objfile_arch (objfile);
dd46ae6
+  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
254f0e9
+  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
dd46ae6
+  ctx->offset = dwarf2_per_cu_text_offset (per_cu);
dd46ae6
+  ctx->baton = &baton;
3b55f78
+  ctx->funcs = &dwarf_expr_ctx_funcs;
ee681d3
+
3b55f78
+  dwarf_expr_eval (ctx, data, size);
dd46ae6
+}
dd46ae6
+
dd46ae6
+/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
dd46ae6
+   CORE_ADDR result on the DWARF stack stack.  */
dd46ae6
+
dd46ae6
+CORE_ADDR
dd46ae6
+dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
dd46ae6
+{
dd46ae6
+  struct dwarf_expr_context *ctx;
dd46ae6
+  CORE_ADDR retval;
3b55f78
+  struct cleanup *back_to;
3b55f78
+
3b55f78
+  ctx = new_dwarf_expr_context ();
3b55f78
+  back_to = make_cleanup_free_dwarf_expr_context (ctx);
3b55f78
+
3b55f78
+  dwarf_expr_prep_ctx (ctx, get_selected_frame (NULL), dlbaton->data,
3b55f78
+		       dlbaton->size, dlbaton->per_cu);
ee681d3
+
dd46ae6
+  if (ctx->num_pieces > 0)
dd46ae6
+    error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
ee681d3
+
3b55f78
+  retval = dwarf_expr_fetch_address (ctx, 0);
ee681d3
+
dd46ae6
+  if (ctx->location == DWARF_VALUE_REGISTER)
ee681d3
+    {
dd46ae6
+      /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
dd46ae6
+
dd46ae6
+      int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
dd46ae6
+      struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
dd46ae6
+      struct frame_info *frame = get_selected_frame (NULL);
ee681d3
+
dd46ae6
+      retval = address_from_register (type, gdb_regnum, frame);
ee681d3
+    }
ee681d3
+
dd46ae6
+  do_cleanups (back_to);
ee681d3
+
dd46ae6
+  return retval;
ee681d3
+}
ee681d3
+
f8eee05
 /* Callback function for dwarf2_evaluate_loc_desc.
f8eee05
    Fetch the address indexed by DW_OP_GNU_addr_index.  */
f8eee05
 
872aab0
@@ -2177,22 +2346,6 @@ static const struct lval_funcs pieced_value_funcs = {
872aab0
   free_pieced_value_closure
872aab0
 };
3b55f78
 
3b55f78
-/* Virtual method table for dwarf2_evaluate_loc_desc_full below.  */
3b55f78
-
3b55f78
-static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
3b55f78
-{
3b55f78
-  dwarf_expr_read_reg,
3b55f78
-  dwarf_expr_read_mem,
3b55f78
-  dwarf_expr_frame_base,
3b55f78
-  dwarf_expr_frame_cfa,
3b55f78
-  dwarf_expr_frame_pc,
3b55f78
-  dwarf_expr_tls_address,
3b55f78
-  dwarf_expr_dwarf_call,
254f0e9
-  dwarf_expr_get_base_type,
f8eee05
-  dwarf_expr_push_dwarf_reg_entry_value,
f8eee05
-  dwarf_expr_get_addr_index
3b55f78
-};
3b55f78
-
3b55f78
 /* Evaluate a location description, starting at DATA and with length
3b55f78
    SIZE, to find the current location of variable of TYPE in the
3b55f78
    context of FRAME.  BYTE_OFFSET is applied after the contents are
872aab0
@@ -2205,7 +2358,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
6fa2f55
 			       LONGEST byte_offset)
dd46ae6
 {
dd46ae6
   struct value *retval;
dd46ae6
-  struct dwarf_expr_baton baton;
dd46ae6
   struct dwarf_expr_context *ctx;
3b55f78
   struct cleanup *old_chain, *value_chain;
254f0e9
   struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
872aab0
@@ -2217,29 +2369,18 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
3b55f78
   if (size == 0)
3b55f78
     return allocate_optimized_out_value (type);
ee681d3
 
dd46ae6
-  baton.frame = frame;
dd46ae6
-  baton.per_cu = per_cu;
48cf710
-
3b55f78
   ctx = new_dwarf_expr_context ();
3b55f78
   old_chain = make_cleanup_free_dwarf_expr_context (ctx);
3b55f78
   value_chain = make_cleanup_value_free_to_mark (value_mark ());
3b55f78
 
dd46ae6
-  ctx->gdbarch = get_objfile_arch (objfile);
dd46ae6
-  ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
254f0e9
-  ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
dd46ae6
-  ctx->offset = dwarf2_per_cu_text_offset (per_cu);
dd46ae6
-  ctx->baton = &baton;
3b55f78
-  ctx->funcs = &dwarf_expr_ctx_funcs;
3b55f78
-
3b55f78
   TRY_CATCH (ex, RETURN_MASK_ERROR)
48cf710
     {
3b55f78
-      dwarf_expr_eval (ctx, data, size);
3b55f78
+      dwarf_expr_prep_ctx (ctx, frame, data, size, per_cu);
48cf710
     }
3b55f78
   if (ex.reason < 0)
3b55f78
     {
3b55f78
       if (ex.error == NOT_AVAILABLE_ERROR)
3b55f78
 	{
3b55f78
-	  do_cleanups (old_chain);
3b55f78
 	  retval = allocate_value (type);
3b55f78
 	  mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type));
3b55f78
 	  return retval;
872aab0
@@ -2303,6 +2444,16 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
dd46ae6
 	    int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
e5611bf
 
3b55f78
 	    do_cleanups (value_chain);
3b55f78
+
6fa2f55
+	    /* Frame may be needed for check_typedef of TYPE_DYNAMIC.  */
6fa2f55
+	    make_cleanup_restore_selected_frame ();
6fa2f55
+	    select_frame (frame);
6fa2f55
+
dd46ae6
+	    /* object_address_set called here is required in ALLOCATE_VALUE's
dd46ae6
+	       CHECK_TYPEDEF for the object's possible
dd46ae6
+	       DW_OP_push_object_address.  */
dd46ae6
+	    object_address_set (address);
e5611bf
+
b0e03f5
 	    retval = allocate_value_lazy (type);
dd46ae6
 	    VALUE_LVAL (retval) = lval_memory;
b0e03f5
 	    if (in_stack_memory)
872aab0
@@ -4204,8 +4355,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
3080c0e
 			       dlbaton->per_cu);
dd46ae6
 }
e5611bf
 
dd46ae6
-/* The set of location functions used with the DWARF-2 expression
dd46ae6
-   evaluator and location lists.  */
dd46ae6
+/* The set of location functions used with the DWARF-2 location lists.  */
dd46ae6
 const struct symbol_computed_ops dwarf2_loclist_funcs = {
dd46ae6
   loclist_read_variable,
254f0e9
   loclist_read_variable_at_entry,
254f0e9
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
872aab0
index 9bc8ca5..28467dc 100644
254f0e9
--- a/gdb/dwarf2loc.h
254f0e9
+++ b/gdb/dwarf2loc.h
872aab0
@@ -137,6 +137,15 @@ struct dwarf2_loclist_baton
e5611bf
 
dd46ae6
 extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
dd46ae6
 extern const struct symbol_computed_ops dwarf2_loclist_funcs;
dd46ae6
+extern const struct symbol_computed_ops dwarf2_missing_funcs;
dd46ae6
+
dd46ae6
+extern void object_address_set (CORE_ADDR address);
dd46ae6
+
dd46ae6
+extern CORE_ADDR dwarf_locexpr_baton_eval
dd46ae6
+  (struct dwarf2_locexpr_baton *dlbaton);
dd46ae6
+
dd46ae6
+extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
dd46ae6
+				     struct type *type, CORE_ADDR *addrp);
e5611bf
 
872aab0
 extern const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs;
872aab0
 extern const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs;
254f0e9
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
872aab0
index d18eaed..91c476c 100644
254f0e9
--- a/gdb/dwarf2read.c
254f0e9
+++ b/gdb/dwarf2read.c
872aab0
@@ -1661,6 +1661,9 @@ static void fill_in_loclist_baton (struct dwarf2_cu *cu,
6fa2f55
 				   struct dwarf2_loclist_baton *baton,
872aab0
 				   const struct attribute *attr);
e5611bf
 
dd46ae6
+static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton
872aab0
+  (const struct attribute *attr, struct dwarf2_cu *cu);
dd46ae6
+
872aab0
 static void dwarf2_symbol_mark_computed (const struct attribute *attr,
dd46ae6
 					 struct symbol *sym,
872aab0
 					 struct dwarf2_cu *cu,
872aab0
@@ -1694,6 +1697,9 @@ static void age_cached_comp_units (void);
e5611bf
 
f8eee05
 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
e5611bf
 
dd46ae6
+static void fetch_die_type_attrs (struct die_info *die, struct type *type,
dd46ae6
+				  struct dwarf2_cu *cu);
dd46ae6
+
dd46ae6
 static struct type *set_die_type (struct die_info *, struct type *,
dd46ae6
 				  struct dwarf2_cu *);
e5611bf
 
872aab0
@@ -1722,6 +1728,9 @@ static struct type *get_die_type_at_offset (sect_offset,
e5611bf
 
dd46ae6
 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
e5611bf
 
dd46ae6
+static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
872aab0
+  (const struct attribute *attr, struct dwarf2_cu *cu);
dd46ae6
+
e00e5ea
 static void dwarf2_release_queue (void *dummy);
e00e5ea
 
f8eee05
 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
872aab0
@@ -12263,6 +12272,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
556378e
   new_symbol (die, this_type, cu);
11eae30
 }
11eae30
 
556378e
+/* Create a new array dimension referencing its target type TYPE.
11eae30
+
556378e
+   Multidimensional arrays are internally represented as a stack of
556378e
+   singledimensional arrays being referenced by their TYPE_TARGET_TYPE.  */
11eae30
+
556378e
+static struct type *
556378e
+create_single_array_dimension (struct type *type, struct type *range_type,
556378e
+			       struct die_info *die, struct dwarf2_cu *cu)
20f9f67
+{
556378e
+  type = create_array_type (NULL, type, range_type);
11eae30
+
556378e
+  /* These generic type attributes need to be fetched by
556378e
+     evaluate_subexp_standard <multi_f77_subscript>'s call of
556378e
+     value_subscripted_rvalue only for the innermost array type.  */
556378e
+  fetch_die_type_attrs (die, type, cu);
11eae30
+
556378e
+  /* These generic type attributes are checked for allocated/associated
556378e
+     validity while accessing FIELD_LOC_KIND_DWARF_BLOCK.  */
556378e
+  fetch_die_type_attrs (die, range_type, cu);
11eae30
+
556378e
+  return type;
11eae30
+}
556378e
+
556378e
 /* Extract all information from a DW_TAG_array_type DIE and put it in
556378e
    the DIE's type field.  For now, this only handles one dimensional
556378e
    arrays.  */
872aab0
@@ -12276,7 +12308,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
556378e
   struct type *element_type, *range_type, *index_type;
556378e
   struct type **range_types = NULL;
556378e
   struct attribute *attr;
556378e
-  int ndim = 0;
556378e
+  int ndim = 0, i;
556378e
   struct cleanup *back_to;
ab333d9
   const char *name;
11eae30
 
872aab0
@@ -12329,17 +12361,19 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
556378e
   type = element_type;
11eae30
 
556378e
   if (read_array_order (die, cu) == DW_ORD_col_major)
556378e
-    {
556378e
-      int i = 0;
11eae30
-
11eae30
-      while (i < ndim)
11eae30
-	type = create_array_type (NULL, type, range_types[i++]);
11eae30
-    }
11eae30
-  else
11eae30
-    {
11eae30
-      while (ndim-- > 0)
11eae30
-	type = create_array_type (NULL, type, range_types[ndim]);
11eae30
-    }
11eae30
+    for (i = 0; i < ndim; i++)
11eae30
+      type = create_single_array_dimension (type, range_types[i], die, cu);
11eae30
+  else /* (read_array_order (die, cu) == DW_ORD_row_major) */
11eae30
+    for (i = ndim - 1; i >= 0; i--)
11eae30
+      type = create_single_array_dimension (type, range_types[i], die, cu);
11eae30
+
11eae30
+  /* Data locations should be set only for the outermost dimension as they
11eae30
+     would be confusing for the dereferenced offset on the inner ones.  */
11eae30
+  attr = dwarf2_attr (die, DW_AT_data_location, cu);
11eae30
+  if (attr_form_is_block (attr))
11eae30
+    TYPE_DATA_LOCATION_DWARF_BLOCK (type)
11eae30
+      = dwarf2_attr_to_locexpr_baton (attr, cu);
11eae30
+  gdb_assert (!TYPE_DATA_LOCATION_IS_ADDR (type));
11eae30
 
11eae30
   /* Understand Dwarf2 support for vector types (like they occur on
11eae30
      the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
872aab0
@@ -12973,29 +13007,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
11eae30
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
11eae30
   struct type *type, *range_type, *index_type, *char_type;
11eae30
   struct attribute *attr;
e00e5ea
-  unsigned int length;
e00e5ea
+  int length;
1592379
+
e00e5ea
+  index_type = objfile_type (objfile)->builtin_int;
e00e5ea
+  /* RANGE_TYPE is allocated from OBJFILE, not as a permanent type.  */
e00e5ea
+  range_type = alloc_type (objfile);
e00e5ea
+  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
e00e5ea
+  range_type = create_range_type (range_type, index_type, 0, -1);
1592379
+
e00e5ea
+  /* C/C++ should probably have the low bound 0 but C/C++ does not use
e00e5ea
+     DW_TAG_string_type.  */
e00e5ea
+  TYPE_LOW_BOUND (range_type) = 1;
e00e5ea
 
e00e5ea
   attr = dwarf2_attr (die, DW_AT_string_length, cu);
e00e5ea
-  if (attr)
e00e5ea
+  if (attr && attr_form_is_block (attr))
f314eb3
     {
f314eb3
-      length = DW_UNSND (attr);
e00e5ea
+      /* Security check for a size overflow.  */
e00e5ea
+      if (DW_BLOCK (attr)->size + 2 < DW_BLOCK (attr)->size)
e00e5ea
+	TYPE_HIGH_BOUND (range_type) = 1;
e00e5ea
+      /* Extend the DWARF block by a new DW_OP_deref/DW_OP_deref_size
e00e5ea
+	 instruction as DW_AT_string_length specifies the length location, not
e00e5ea
+	 its value.  */
e00e5ea
+      else
e00e5ea
+	{
e00e5ea
+	  struct dwarf2_locexpr_baton *length_baton = NULL;
e00e5ea
+	  struct dwarf_block *blk = DW_BLOCK (attr);
e5611bf
+
e00e5ea
+	  /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
e00e5ea
+	     DW_OP_deref* in such case.  */
e5611bf
+
e00e5ea
+	  if (blk->size == 1 && blk->data[0] >= DW_OP_reg0
e00e5ea
+	      && blk->data[0] <= DW_OP_reg31)
e00e5ea
+	    length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+	  else if (blk->size > 1 && blk->data[0] == DW_OP_regx)
e00e5ea
+	    {
e00e5ea
+	      ULONGEST ulongest;
e00e5ea
+	      const gdb_byte *end;
e5611bf
+
f8eee05
+	      end = safe_read_uleb128 (&blk->data[1], &blk->data[blk->size],
f8eee05
+				       &ulongest);
e00e5ea
+	      if (end == &blk->data[blk->size])
e00e5ea
+		length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+	    }
20f9f67
+
e00e5ea
+	  if (length_baton == NULL)
e00e5ea
+	    {
e00e5ea
+	      struct attribute *size_attr;
e00e5ea
+	      gdb_byte *data;
20f9f67
+
e00e5ea
+	      length_baton = obstack_alloc (&cu->comp_unit_obstack,
e00e5ea
+					    sizeof (*length_baton));
e00e5ea
+	      length_baton->per_cu = cu->per_cu;
e00e5ea
+	      length_baton->size = DW_BLOCK (attr)->size + 2;
e00e5ea
+	      data = obstack_alloc (&cu->comp_unit_obstack,
e00e5ea
+				    length_baton->size);
e00e5ea
+	      length_baton->data = data;
e00e5ea
+	      memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size);
20f9f67
+
e00e5ea
+	      /* DW_AT_BYTE_SIZE existing together with DW_AT_STRING_LENGTH
e00e5ea
+		 specifies the size of an integer to fetch.  */
e00e5ea
+	      size_attr = dwarf2_attr (die, DW_AT_byte_size, cu);
e00e5ea
+	      if (size_attr)
e00e5ea
+		{
e00e5ea
+		  data[DW_BLOCK (attr)->size] = DW_OP_deref_size;
e00e5ea
+		  data[DW_BLOCK (attr)->size + 1] = DW_UNSND (size_attr);
e00e5ea
+		  if (data[DW_BLOCK (attr)->size + 1] != DW_UNSND (size_attr))
e00e5ea
+		    complaint (&symfile_complaints,
e00e5ea
+			       _("DW_AT_string_length's DW_AT_byte_size "
e00e5ea
+				 "integer exceeds the byte size storage"));
e00e5ea
+		}
e00e5ea
+	      else
e00e5ea
+		{
e00e5ea
+		  data[DW_BLOCK (attr)->size] = DW_OP_deref;
e00e5ea
+		  data[DW_BLOCK (attr)->size + 1] = DW_OP_nop;
e00e5ea
+		}
e00e5ea
+	    }
20f9f67
+
e00e5ea
+	  TYPE_RANGE_DATA (range_type)->high.kind
e00e5ea
+	    = RANGE_BOUND_KIND_DWARF_BLOCK;
e00e5ea
+	  TYPE_RANGE_DATA (range_type)->high.u.dwarf_block = length_baton;
e00e5ea
+	  TYPE_DYNAMIC (range_type) = 1;
e00e5ea
+	}
e00e5ea
     }
e00e5ea
   else
e00e5ea
     {
b0e03f5
-      /* Check for the DW_AT_byte_size attribute.  */
e00e5ea
+      if (attr && attr_form_is_constant (attr))
e00e5ea
+	{
e00e5ea
+	  /* We currently do not support a constant address where the location
e00e5ea
+	     should be read from - attr_form_is_block is expected instead.  See
e00e5ea
+	     DWARF for the DW_AT_STRING_LENGTH vs. DW_AT_BYTE_SIZE difference.
e00e5ea
+	     */
e00e5ea
+	  /* PASSTHRU */
e00e5ea
+	}
20f9f67
+
e00e5ea
       attr = dwarf2_attr (die, DW_AT_byte_size, cu);
e00e5ea
-      if (attr)
e00e5ea
-        {
e00e5ea
-          length = DW_UNSND (attr);
e00e5ea
-        }
e00e5ea
+      if (attr && attr_form_is_block (attr))
e00e5ea
+	{
e00e5ea
+	  TYPE_RANGE_DATA (range_type)->high.kind
e00e5ea
+	    = RANGE_BOUND_KIND_DWARF_BLOCK;
e00e5ea
+	  TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
e00e5ea
+					dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+	  TYPE_DYNAMIC (range_type) = 1;
e00e5ea
+	}
e00e5ea
+      else if (attr && attr_form_is_constant (attr))
e00e5ea
+	TYPE_HIGH_BOUND (range_type) = dwarf2_get_attr_constant_value (attr, 0);
e00e5ea
       else
e00e5ea
-        {
e00e5ea
-          length = 1;
e00e5ea
-        }
e00e5ea
+	TYPE_HIGH_BOUND (range_type) = 1;
e00e5ea
     }
e00e5ea
 
e00e5ea
-  index_type = objfile_type (objfile)->builtin_int;
e00e5ea
-  range_type = create_range_type (NULL, index_type, 1, length);
e00e5ea
   char_type = language_string_char_type (cu->language_defn, gdbarch);
e00e5ea
   type = create_string_type (NULL, char_type, range_type);
e00e5ea
 
872aab0
@@ -13320,7 +13439,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
1054fa6
   struct type *base_type, *orig_base_type;
e00e5ea
   struct type *range_type;
e00e5ea
   struct attribute *attr;
f8eee05
-  LONGEST low, high;
e00e5ea
+  LONGEST low;
f8eee05
   int low_default_is_valid;
ab333d9
   const char *name;
e00e5ea
   LONGEST negative_mask;
872aab0
@@ -13379,42 +13498,6 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
f8eee05
 				      "- DIE at 0x%x [in module %s]"),
f8eee05
 	       die->offset.sect_off, cu->objfile->name);
e00e5ea
 
f8eee05
-  attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
f8eee05
-  if (attr)
f8eee05
-    {
872aab0
-      if (attr_form_is_block (attr) || attr_form_is_ref (attr))
f8eee05
-        {
f8eee05
-          /* GCC encodes arrays with unspecified or dynamic length
f8eee05
-             with a DW_FORM_block1 attribute or a reference attribute.
f8eee05
-             FIXME: GDB does not yet know how to handle dynamic
f8eee05
-             arrays properly, treat them as arrays with unspecified
f8eee05
-             length for now.
f8eee05
-
f8eee05
-             FIXME: jimb/2003-09-22: GDB does not really know
f8eee05
-             how to handle arrays of unspecified length
f8eee05
-             either; we just represent them as zero-length
f8eee05
-             arrays.  Choose an appropriate upper bound given
f8eee05
-             the lower bound we've computed above.  */
f8eee05
-          high = low - 1;
f8eee05
-        }
f8eee05
-      else
f8eee05
-        high = dwarf2_get_attr_constant_value (attr, 1);
f8eee05
-    }
f8eee05
-  else
ebad377
-    {
f8eee05
-      attr = dwarf2_attr (die, DW_AT_count, cu);
f8eee05
-      if (attr)
f8eee05
-	{
f8eee05
-	  int count = dwarf2_get_attr_constant_value (attr, 1);
f8eee05
-	  high = low + count - 1;
f8eee05
-	}
f8eee05
-      else
f8eee05
-	{
f8eee05
-	  /* Unspecified array length.  */
f8eee05
-	  high = low - 1;
f8eee05
-	}
ebad377
-    }
f8eee05
-
f8eee05
   /* Dwarf-2 specifications explicitly allows to create subrange types
f8eee05
      without specifying a base type.
f8eee05
      In that case, the base type must be set to the type of
872aab0
@@ -13453,24 +13536,163 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
f8eee05
 	}
f8eee05
     }
f8eee05
 
f8eee05
-  negative_mask =
e00e5ea
+  /* LOW_BOUND and HIGH_BOUND are set for real below.  */
1054fa6
+  range_type = create_range_type (NULL, orig_base_type, 0, -1);
b0e03f5
+  TYPE_UNSIGNED (range_type) = 0;
254f0e9
+
b0e03f5
+  negative_mask = 
f8eee05
     (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
f8eee05
-  if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
f8eee05
-    low |= negative_mask;
f8eee05
-  if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
f8eee05
-    high |= negative_mask;
f8eee05
 
1054fa6
-  range_type = create_range_type (NULL, orig_base_type, low, high);
f8eee05
+  /* Exclude language_ada from any TYPE_DYNAMIC constructs below.  GDB Ada
f8eee05
+     supports implements the dynamic bounds in a non-DWARF way and the
b0e03f5
+     existing DWARF dynamic bounds are invalid, leading to memory access
b0e03f5
+     errors.  */
254f0e9
 
f8eee05
-  /* Mark arrays with dynamic length at least as an array of unspecified
f8eee05
-     length.  GDB could check the boundary but before it gets implemented at
f8eee05
-     least allow accessing the array elements.  */
f8eee05
-  if (attr && attr_form_is_block (attr))
f8eee05
-    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
f8eee05
+  attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
e00e5ea
+  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
254f0e9
+    {
e00e5ea
+      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
e00e5ea
+      TYPE_RANGE_DATA (range_type)->low.u.dwarf_block =
e00e5ea
+					dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+      TYPE_DYNAMIC (range_type) = 1;
e00e5ea
+      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
e00e5ea
+      low = 0;
ebad377
+    }
872aab0
+  else if (attr && attr_form_is_ref (attr) && cu->language != language_ada)
dd46ae6
+    {
e00e5ea
+      struct die_info *target_die;
e00e5ea
+      struct dwarf2_cu *target_cu = cu;
e00e5ea
+      struct attribute *target_loc_attr;
556378e
+
e00e5ea
+      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
e00e5ea
+      gdb_assert (target_cu->objfile == cu->objfile);
e00e5ea
+      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
ebad377
+
e00e5ea
+      TYPE_RANGE_DATA (range_type)->low.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
e00e5ea
+      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.loclist
e00e5ea
+        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
e00e5ea
+      TYPE_RANGE_DATA (range_type)->low.u.dwarf_loclist.type
e00e5ea
+        = die_type (target_die, target_cu);
e00e5ea
+      TYPE_DYNAMIC (range_type) = 1;
e00e5ea
+      /* For setting a default if DW_AT_UPPER_BOUND would be missing.  */
e00e5ea
+      low = 0;
254f0e9
+    }
254f0e9
+  else
f8eee05
+    {
254f0e9
+      if (attr && attr_form_is_constant (attr))
254f0e9
+	low = dwarf2_get_attr_constant_value (attr, 0);
f8eee05
+      else
254f0e9
+	{
e00e5ea
+	  if (cu->language == language_fortran)
e00e5ea
+	    {
e00e5ea
+	      /* FORTRAN implies a lower bound of 1, if not given.  */
e00e5ea
+	      low = 1;
e00e5ea
+	    }
e00e5ea
+	  else
e00e5ea
+	    {
e00e5ea
+	      /* According to DWARF we should assume the value 0 only for
e00e5ea
+		 LANGUAGE_C and LANGUAGE_CPLUS.  */
e00e5ea
+	      low = 0;
e00e5ea
+	    }
254f0e9
+	}
e00e5ea
+      if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
e00e5ea
+	low |= negative_mask;
e00e5ea
+      TYPE_LOW_BOUND (range_type) = low;
e00e5ea
+      if (low >= 0)
e00e5ea
+	TYPE_UNSIGNED (range_type) = 1;
f8eee05
+    }
556378e
 
556378e
-  /* Ada expects an empty array on no boundary attributes.  */
556378e
-  if (attr == NULL && cu->language != language_ada)
556378e
-    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
b0e03f5
+  attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
e00e5ea
+  if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
872aab0
+		&& !attr_form_is_ref (attr)))
f8eee05
+    {
f8eee05
+      attr = dwarf2_attr (die, DW_AT_count, cu);
e00e5ea
+      /* It does not hurt but it is needlessly ineffective in check_typedef.  */
e00e5ea
+      if (attr && (attr_form_is_block (attr) || attr_form_is_constant (attr)))
e00e5ea
+      	{
e00e5ea
+	  TYPE_RANGE_HIGH_BOUND_IS_COUNT (range_type) = 1;
e00e5ea
+	  TYPE_DYNAMIC (range_type) = 1;
f8eee05
+	}
e00e5ea
+      /* Pass it now as the regular DW_AT_upper_bound.  */
dd46ae6
+    }
ee681d3
+
e00e5ea
+  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
dd46ae6
+    {
e00e5ea
+      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_BLOCK;
e00e5ea
+      TYPE_RANGE_DATA (range_type)->high.u.dwarf_block =
e00e5ea
+					dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+      TYPE_DYNAMIC (range_type) = 1;
dd46ae6
+    }
872aab0
+  else if (attr && attr_form_is_ref (attr) && cu->language != language_ada)
e00e5ea
+    {
e00e5ea
+      struct die_info *target_die;
e00e5ea
+      struct dwarf2_cu *target_cu = cu;
e00e5ea
+      struct attribute *target_loc_attr;
20f9f67
+
e00e5ea
+      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
e00e5ea
+      gdb_assert (target_cu->objfile == cu->objfile);
e00e5ea
+      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
20f9f67
+
e00e5ea
+      TYPE_RANGE_DATA (range_type)->high.kind = RANGE_BOUND_KIND_DWARF_LOCLIST;
e00e5ea
+      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.loclist
e00e5ea
+        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
e00e5ea
+      TYPE_RANGE_DATA (range_type)->high.u.dwarf_loclist.type
e00e5ea
+        = die_type (target_die, target_cu);
e00e5ea
+      TYPE_DYNAMIC (range_type) = 1;
b0e03f5
+    }
b0e03f5
+  else
b0e03f5
+    {
e00e5ea
+      LONGEST high;
20f9f67
+
e00e5ea
+      if (attr && attr_form_is_constant (attr))
e00e5ea
+	high = dwarf2_get_attr_constant_value (attr, 0);
f8eee05
+      else
f8eee05
+	{
e00e5ea
+	  /* Ada expects an empty array on no boundary attributes.  */
e00e5ea
+	  if (cu->language != language_ada)
e00e5ea
+	    TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
f8eee05
+	  high = low - 1;
f8eee05
+	}
e00e5ea
+      if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
e00e5ea
+	high |= negative_mask;
e00e5ea
+      TYPE_HIGH_BOUND (range_type) = high;
f8eee05
+    }
f8eee05
+
e00e5ea
+  /* DW_AT_bit_stride is currently unsupported as we count in bytes.  */
e00e5ea
+  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
e00e5ea
+  if (attr && attr_form_is_block (attr) && cu->language != language_ada)
dd46ae6
+    {
e00e5ea
+      TYPE_RANGE_DATA (range_type)->byte_stride.kind
e00e5ea
+        = RANGE_BOUND_KIND_DWARF_BLOCK;
e00e5ea
+      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_block =
e00e5ea
+					dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+      TYPE_DYNAMIC (range_type) = 1;
20f9f67
+    }
872aab0
+  else if (attr && attr_form_is_ref (attr) && cu->language != language_ada)
dd46ae6
+    {
e00e5ea
+      struct die_info *target_die;
e00e5ea
+      struct dwarf2_cu *target_cu = cu;
e00e5ea
+      struct attribute *target_loc_attr;
f8eee05
+
b0e03f5
+      target_die = follow_die_ref_or_sig (die, attr, &target_cu);
b0e03f5
+      gdb_assert (target_cu->objfile == cu->objfile);
b0e03f5
+      target_loc_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
f8eee05
+
e00e5ea
+      TYPE_RANGE_DATA (range_type)->byte_stride.kind
e00e5ea
+        = RANGE_BOUND_KIND_DWARF_LOCLIST;
e00e5ea
+      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.loclist
e00e5ea
+        = dwarf2_attr_to_loclist_baton (target_loc_attr, target_cu);
e00e5ea
+      TYPE_RANGE_DATA (range_type)->byte_stride.u.dwarf_loclist.type
e00e5ea
+        = die_type (target_die, target_cu);
e00e5ea
+      TYPE_DYNAMIC (range_type) = 1;
dd46ae6
+    }
e00e5ea
+  else if (attr && attr_form_is_constant (attr))
dd46ae6
+    {
e00e5ea
+      TYPE_BYTE_STRIDE (range_type) = dwarf2_get_attr_constant_value (attr, 0);
e00e5ea
+      if (TYPE_BYTE_STRIDE (range_type) == 0)
e00e5ea
+	complaint (&symfile_complaints,
e00e5ea
+		   _("Found DW_AT_byte_stride with unsupported value 0"));
dd46ae6
+    }
e00e5ea
 
e00e5ea
   name = dwarf2_name (die, cu);
e00e5ea
   if (name)
872aab0
@@ -16380,11 +16602,14 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
e00e5ea
      (i.e. when the value of a register or memory location is
e00e5ea
      referenced, or a thread-local block, etc.).  Then again, it might
e00e5ea
      not be worthwhile.  I'm assuming that it isn't unless performance
e00e5ea
-     or memory numbers show me otherwise.  */
e00e5ea
+     or memory numbers show me otherwise.
e00e5ea
+     
e00e5ea
+     SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed.  */
e00e5ea
 
872aab0
   dwarf2_symbol_mark_computed (attr, sym, cu, 0);
e00e5ea
 
872aab0
-  if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
872aab0
+  if (SYMBOL_COMPUTED_OPS (sym) != NULL
872aab0
+      && SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
ebad377
     cu->has_loclist = 1;
872aab0
 }
872aab0
 
872aab0
@@ -17225,6 +17450,9 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
11eae30
       break;
e00e5ea
     }
e00e5ea
 
e00e5ea
+  if (this_type)
e00e5ea
+    finalize_type (this_type);
dd46ae6
+
e00e5ea
   return this_type;
e00e5ea
 }
e00e5ea
 
872aab0
@@ -19910,66 +20138,109 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
f8eee05
   baton->from_dwo = cu->dwo_unit != NULL;
e00e5ea
 }
e00e5ea
 
e00e5ea
-static void
872aab0
-dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
872aab0
-			     struct dwarf2_cu *cu, int is_block)
e00e5ea
+/* Convert DW_BLOCK into struct dwarf2_locexpr_baton.  ATTR must be a DW_BLOCK
e00e5ea
+   attribute type.  */
e5611bf
+
e00e5ea
+static struct dwarf2_locexpr_baton *
872aab0
+dwarf2_attr_to_locexpr_baton (const struct attribute *attr,
872aab0
+			      struct dwarf2_cu *cu)
f8eee05
+{
f8eee05
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
254f0e9
+  struct dwarf2_locexpr_baton *baton;
f8eee05
+
872aab0
+  gdb_assert (attr == NULL || attr_form_is_block (attr));
254f0e9
+
254f0e9
+  baton = obstack_alloc (&objfile->objfile_obstack, sizeof (*baton));
e00e5ea
+  baton->per_cu = cu->per_cu;
e00e5ea
+  gdb_assert (baton->per_cu);
f8eee05
+
e00e5ea
+  /* Note that we're just copying the block's data pointer
e00e5ea
+     here, not the actual data.  We're still pointing into the
e00e5ea
+     info_buffer for SYM's objfile; right now we never release
e00e5ea
+     that buffer, but when we do clean up properly this may
e00e5ea
+     need to change.  */
872aab0
+  if (attr != NULL)
872aab0
+    {
872aab0
+      baton->size = DW_BLOCK (attr)->size;
872aab0
+      baton->data = DW_BLOCK (attr)->data;
872aab0
+    }
872aab0
+  else
872aab0
+    {
872aab0
+      baton->size = 0;
872aab0
+      baton->data = NULL;
872aab0
+    }
e00e5ea
+  gdb_assert (baton->size == 0 || baton->data != NULL);
f8eee05
+
b0e03f5
+  return baton;
b0e03f5
+}
f8eee05
+
e00e5ea
+static struct dwarf2_loclist_baton *
872aab0
+dwarf2_attr_to_loclist_baton (const struct attribute *attr,
872aab0
+			      struct dwarf2_cu *cu)
f8eee05
 {
f8eee05
   struct objfile *objfile = dwarf2_per_objfile->objfile;
f8eee05
   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
e00e5ea
+  struct dwarf2_loclist_baton *baton;
556378e
 
556378e
-  if (attr_form_is_section_offset (attr)
e00e5ea
+  /* DW_AT_location of the referenced DIE may be missing if the referenced
e00e5ea
+     variable has been optimized out.  */
e00e5ea
+  if (!attr)
e00e5ea
+    return NULL;
f314eb3
+
f8eee05
+  dwarf2_read_section (dwarf2_per_objfile->objfile, section);
556378e
+
e00e5ea
+  if (!(attr_form_is_section_offset (attr)
f8eee05
       /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
f8eee05
 	 the section.  If so, fall through to the complaint in the
f8eee05
 	 other branch.  */
f8eee05
-      && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
f8eee05
-    {
f8eee05
-      struct dwarf2_loclist_baton *baton;
f8eee05
+      && DW_UNSND (attr) < dwarf2_section_size (objfile, section)))
e00e5ea
+    return NULL;
f8eee05
 
f8eee05
-      baton = obstack_alloc (&objfile->objfile_obstack,
f8eee05
-			     sizeof (struct dwarf2_loclist_baton));
f8eee05
+  baton = obstack_alloc (&objfile->objfile_obstack,
e00e5ea
+			 sizeof (struct dwarf2_loclist_baton));
f8eee05
 
f8eee05
-      fill_in_loclist_baton (cu, baton, attr);
6fa2f55
+  fill_in_loclist_baton (cu, baton, attr);
f8eee05
 
f8eee05
-      if (cu->base_known == 0)
f8eee05
-	complaint (&symfile_complaints,
f8eee05
-		   _("Location list used without "
f8eee05
-		     "specifying the CU base address."));
e00e5ea
+  if (cu->base_known == 0)
e00e5ea
+    complaint (&symfile_complaints,
33ff709
+	       _("Location list used without "
33ff709
+		 "specifying the CU base address."));
f8eee05
+
e00e5ea
+  return baton;
20f9f67
+}
3080c0e
+
e00e5ea
+/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content.  */
e00e5ea
+
20f9f67
+static void
872aab0
+dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
872aab0
+			     struct dwarf2_cu *cu, int is_block)
20f9f67
+{
e00e5ea
+  struct dwarf2_loclist_baton *loclist_baton;
f8eee05
 
e00e5ea
+  loclist_baton = dwarf2_attr_to_loclist_baton (attr, cu);
e00e5ea
+  if (loclist_baton)
20f9f67
+    {
872aab0
       SYMBOL_ACLASS_INDEX (sym) = (is_block
872aab0
 				   ? dwarf2_loclist_block_index
872aab0
 				   : dwarf2_loclist_index);
e00e5ea
-      SYMBOL_LOCATION_BATON (sym) = baton;
e00e5ea
+      SYMBOL_LOCATION_BATON (sym) = loclist_baton;
20f9f67
+    }
e00e5ea
+  else if (attr_form_is_block (attr))
dd46ae6
+    {
872aab0
+      SYMBOL_ACLASS_INDEX (sym) = (is_block
872aab0
+				   ? dwarf2_locexpr_block_index
872aab0
+				   : dwarf2_locexpr_index);
e00e5ea
+      SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
     }
e00e5ea
   else
e00e5ea
     {
e00e5ea
-      struct dwarf2_locexpr_baton *baton;
872aab0
-
254f0e9
-      baton = obstack_alloc (&objfile->objfile_obstack,
e00e5ea
-			     sizeof (struct dwarf2_locexpr_baton));
e00e5ea
-      baton->per_cu = cu->per_cu;
e00e5ea
-      gdb_assert (baton->per_cu);
872aab0
-
e00e5ea
-      if (attr_form_is_block (attr))
e00e5ea
-	{
e00e5ea
-	  /* Note that we're just copying the block's data pointer
e00e5ea
-	     here, not the actual data.  We're still pointing into the
e00e5ea
-	     info_buffer for SYM's objfile; right now we never release
e00e5ea
-	     that buffer, but when we do clean up properly this may
e00e5ea
-	     need to change.  */
e00e5ea
-	  baton->size = DW_BLOCK (attr)->size;
e00e5ea
-	  baton->data = DW_BLOCK (attr)->data;
e00e5ea
-	}
e00e5ea
-      else
e00e5ea
-	{
e00e5ea
-	  dwarf2_invalid_attrib_class_complaint ("location description",
e00e5ea
-						 SYMBOL_NATURAL_NAME (sym));
e00e5ea
-	  baton->size = 0;
e00e5ea
-	}
872aab0
+      dwarf2_invalid_attrib_class_complaint ("location description",
872aab0
+					     SYMBOL_NATURAL_NAME (sym));
e00e5ea
 
872aab0
       SYMBOL_ACLASS_INDEX (sym) = (is_block
872aab0
 				   ? dwarf2_locexpr_block_index
872aab0
 				   : dwarf2_locexpr_index);
e00e5ea
-      SYMBOL_LOCATION_BATON (sym) = baton;
872aab0
+      SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (NULL, cu);
e00e5ea
     }
e00e5ea
 }
e00e5ea
 
872aab0
@@ -20342,6 +20613,25 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
556378e
 	  && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
556378e
 }
e00e5ea
 
e00e5ea
+/* Fill in generic attributes applicable for type DIEs.  */
79563d6
+
dd46ae6
+static void
e00e5ea
+fetch_die_type_attrs (struct die_info *die, struct type *type,
e00e5ea
+		      struct dwarf2_cu *cu)
dd46ae6
+{
e00e5ea
+  struct attribute *attr;
a97b573
+
e00e5ea
+  attr = dwarf2_attr (die, DW_AT_allocated, cu);
e00e5ea
+  if (attr_form_is_block (attr))
e00e5ea
+    TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+  gdb_assert (!TYPE_NOT_ALLOCATED (type));
a97b573
+
e00e5ea
+  attr = dwarf2_attr (die, DW_AT_associated, cu);
e00e5ea
+  if (attr_form_is_block (attr))
e00e5ea
+    TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
e00e5ea
+  gdb_assert (!TYPE_NOT_ASSOCIATED (type));
dd46ae6
+}
ee681d3
+
09dd777
 /* Set the type associated with DIE to TYPE.  Save it in CU's hash
09dd777
    table if necessary.  For convenience, return TYPE.
09dd777
 
872aab0
@@ -20366,6 +20656,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
f8eee05
   struct dwarf2_per_cu_offset_and_type **slot, ofs;
09dd777
   struct objfile *objfile = cu->objfile;
09dd777
 
09dd777
+  fetch_die_type_attrs (die, type, cu);
48cf710
+
09dd777
   /* For Ada types, make sure that the gnat-specific data is always
09dd777
      initialized (if not already set).  There are a few types where
09dd777
      we should not be doing so, because the type-specific area is
254f0e9
diff --git a/gdb/eval.c b/gdb/eval.c
872aab0
index 539489f..13ba1a9 100644
254f0e9
--- a/gdb/eval.c
254f0e9
+++ b/gdb/eval.c
c5c713f
@@ -41,6 +41,7 @@
c5c713f
 #include "gdb_obstack.h"
48cf710
 #include "objfiles.h"
48cf710
 #include "python/python.h"
48cf710
+#include "dwarf2loc.h"
48cf710
 
48cf710
 #include "gdb_assert.h"
48cf710
 
872aab0
@@ -393,27 +394,221 @@ init_array_element (struct value *array, struct value *element,
48cf710
 }
48cf710
 
48cf710
 static struct value *
48cf710
-value_f90_subarray (struct value *array,
b0e03f5
-		    struct expression *exp, int *pos, enum noside noside)
b0e03f5
+value_f90_subarray (struct value *array, struct expression *exp, int *pos,
b0e03f5
+		    int nargs, enum noside noside)
b0e03f5
 {
b0e03f5
-  int pc = (*pos) + 1;
b0e03f5
-  LONGEST low_bound, high_bound;
b0e03f5
-  struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
b0e03f5
-  enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
b0e03f5
- 
b0e03f5
-  *pos += 3;
254f0e9
-
f314eb3
-  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
f314eb3
-    low_bound = TYPE_LOW_BOUND (range);
254f0e9
+  /* Type to use for the newly allocated value ARRAY.  */
254f0e9
+  struct type *new_array_type;
254f0e9
+
b0e03f5
+  /* Type being iterated for each dimension.  */
d515913
+  struct type *type, *type_last_target;
b0e03f5
+
b0e03f5
+  /* Pointer in the last holder to the type of current dimension.  */
b0e03f5
+  struct type **typep = &new_array_type;
b0e03f5
+
b0e03f5
+  struct subscript_index
b0e03f5
+    {
b0e03f5
+      enum { SUBSCRIPT_RANGE, SUBSCRIPT_NUMBER } kind;
b0e03f5
+      union
b0e03f5
+	{
b0e03f5
+	  struct subscript_range
b0e03f5
+	    {
b0e03f5
+	      enum f90_range_type f90_range_type;
b0e03f5
+	      LONGEST low_bound, high_bound;
b0e03f5
+	    }
b0e03f5
+	  range;
b0e03f5
+	  LONGEST number;
b0e03f5
+	};
b0e03f5
+    }
b0e03f5
+  *subscript_array;
d515913
+  struct type **type_array;
b0e03f5
+  int i;
b0e03f5
+  struct cleanup *old_chain;
b0e03f5
+  CORE_ADDR value_byte_address, value_byte_offset = 0;
b0e03f5
+  htab_t copied_types;
b0e03f5
+  struct value *saved_array;
b0e03f5
+
b0e03f5
+  old_chain = make_cleanup (null_cleanup, 0);
b0e03f5
+  object_address_set (value_raw_address (array));
b0e03f5
+
b0e03f5
+  if (value_optimized_out (array)
b0e03f5
+      || (VALUE_LVAL (array) != not_lval
b0e03f5
+          && VALUE_LVAL (array) != lval_memory
b0e03f5
+	  && VALUE_LVAL (array) != lval_internalvar_component
b0e03f5
+	  && VALUE_LVAL (array) != lval_internalvar))
b0e03f5
+    error (_("value being subranged must be in memory"));
b0e03f5
+  type = check_typedef (value_type (array));
b0e03f5
+  f_object_address_data_valid_or_error (type);
b0e03f5
+
b0e03f5
+  copied_types = create_copied_types_hash (NULL);
b0e03f5
+  type = copy_type_recursive (type, copied_types);
b0e03f5
+  htab_delete (copied_types);
b0e03f5
+
b0e03f5
+  if (nargs != calc_f77_array_dims (type))
b0e03f5
+    error (_("Wrong number of subscripts"));
b0e03f5
+
b0e03f5
+  if (TYPE_DATA_LOCATION_IS_ADDR (type))
b0e03f5
+    {
b0e03f5
+      value_byte_address = (TYPE_DATA_LOCATION_ADDR (type)
b0e03f5
+			    + value_offset (array));
b0e03f5
+      TYPE_DATA_LOCATION_IS_ADDR (type) = 0;
3080c0e
+      TYPE_DATA_LOCATION_DWARF_BLOCK (type) = NULL;
b0e03f5
+    }
b0e03f5
   else
b0e03f5
-    low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
3080c0e
+    {
3080c0e
+      gdb_assert (TYPE_DATA_LOCATION_DWARF_BLOCK (type) == NULL);
3080c0e
+      value_byte_address = value_address (array);
3080c0e
+    }
b0e03f5
+
b0e03f5
+  new_array_type = type;
b0e03f5
+
b0e03f5
+  subscript_array = alloca (sizeof (*subscript_array) * nargs);
b0e03f5
+
b0e03f5
+  gdb_assert (nargs > 0);
b0e03f5
+
b0e03f5
+  /* Now that we know we have a legal array subscript expression 
b0e03f5
+     let us actually find out where this element exists in the array.  */
b0e03f5
+
b0e03f5
+  /* Take array indices left to right.  */
b0e03f5
+  for (i = 0; i < nargs; i++)
b0e03f5
+    {
b0e03f5
+      struct subscript_index *index = &subscript_array[i];
b0e03f5
+
b0e03f5
+      if (exp->elts[*pos].opcode == OP_F90_RANGE)
b0e03f5
+	{
b0e03f5
+	  int pc = (*pos) + 1;
b0e03f5
+	  struct subscript_range *range;
b0e03f5
+
b0e03f5
+	  index->kind = SUBSCRIPT_RANGE;
b0e03f5
+	  range = &index->range;
b0e03f5
+
b0e03f5
+	  *pos += 3;
b0e03f5
+	  range->f90_range_type = longest_to_int (exp->elts[pc].longconst);
b0e03f5
+
b0e03f5
+	  if (range->f90_range_type == HIGH_BOUND_DEFAULT
b0e03f5
+	      || range->f90_range_type == NONE_BOUND_DEFAULT)
b0e03f5
+	    range->low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp,
b0e03f5
+							       pos, noside));
b0e03f5
+
b0e03f5
+	  if (range->f90_range_type == LOW_BOUND_DEFAULT
b0e03f5
+	      || range->f90_range_type == NONE_BOUND_DEFAULT)
b0e03f5
+	    range->high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp,
b0e03f5
+								pos, noside));
b0e03f5
+	}
b0e03f5
+      else
b0e03f5
+	{
b0e03f5
+	  struct value *val;
d515913
 
d515913
-  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
d515913
-    high_bound = TYPE_HIGH_BOUND (range);
872aab0
+	  index->kind = SUBSCRIPT_NUMBER;
872aab0
+
b0e03f5
+	  /* Evaluate each subscript; it must be a legal integer in F77.  */
b0e03f5
+	  val = evaluate_subexp_with_coercion (exp, pos, noside);
b0e03f5
+	  index->number = value_as_long (val);
b0e03f5
+	}
b0e03f5
+    }
b0e03f5
+
b0e03f5
+  /* Internal type of array is arranged right to left.  */
b0e03f5
+  for (i = nargs - 1; i >= 0; i--)
b0e03f5
+    {
b0e03f5
+      struct subscript_index *index = &subscript_array[i];
b0e03f5
+      struct type *range_type = TYPE_INDEX_TYPE (type);
d515913
+
b0e03f5
+      switch (index->kind)
b0e03f5
+	{
b0e03f5
+	case SUBSCRIPT_RANGE:
b0e03f5
+	  {
b0e03f5
+	    struct subscript_range *range = &index->range;
b0e03f5
+	    CORE_ADDR byte_offset;
b0e03f5
+
b0e03f5
+	    if (range->f90_range_type == LOW_BOUND_DEFAULT
b0e03f5
+		|| range->f90_range_type == BOTH_BOUND_DEFAULT)
b0e03f5
+	      range->low_bound = TYPE_LOW_BOUND (range_type);
b0e03f5
+
b0e03f5
+	    if (range->f90_range_type == HIGH_BOUND_DEFAULT
b0e03f5
+		|| range->f90_range_type == BOTH_BOUND_DEFAULT)
b0e03f5
+	      range->high_bound = TYPE_HIGH_BOUND (range_type);
b0e03f5
+
b0e03f5
+	    if (range->low_bound < TYPE_LOW_BOUND (range_type)
b0e03f5
+		|| (!TYPE_HIGH_BOUND_UNDEFINED (range_type)
b0e03f5
+		    && range->high_bound > TYPE_HIGH_BOUND (range_type)))
b0e03f5
+	      error (_("slice out of range"));
b0e03f5
+
b0e03f5
+	    byte_offset = ((range->low_bound - TYPE_LOW_BOUND (range_type))
b0e03f5
+			   * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
b0e03f5
+	    TYPE_LOW_BOUND (range_type) = range->low_bound;
b0e03f5
+	    TYPE_HIGH_BOUND (range_type) = range->high_bound;
b0e03f5
+	    if (range->f90_range_type == LOW_BOUND_DEFAULT
b0e03f5
+		|| range->f90_range_type == NONE_BOUND_DEFAULT)
b0e03f5
+	      TYPE_HIGH_BOUND_UNDEFINED (range_type) = 0;
b0e03f5
+
b0e03f5
+	    typep = &TYPE_TARGET_TYPE (type);
b0e03f5
+	    value_byte_offset += byte_offset;
b0e03f5
+	    type = TYPE_TARGET_TYPE (type);
b0e03f5
+	  }
b0e03f5
+	  break;
b0e03f5
+
b0e03f5
+	case SUBSCRIPT_NUMBER:
b0e03f5
+	  {
b0e03f5
+	    CORE_ADDR byte_offset;
b0e03f5
+
b0e03f5
+	    if (index->number < TYPE_LOW_BOUND (range_type)
b0e03f5
+		|| (!TYPE_HIGH_BOUND_UNDEFINED (range_type)
b0e03f5
+		    && index->number > TYPE_HIGH_BOUND (range_type)))
b0e03f5
+	      error (_("no such vector element"));
b0e03f5
+
b0e03f5
+	    byte_offset = ((index->number - TYPE_LOW_BOUND (range_type))
b0e03f5
+			   * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
b0e03f5
+
b0e03f5
+	    type = TYPE_TARGET_TYPE (type);
b0e03f5
+	    *typep = type;
b0e03f5
+	    value_byte_offset += byte_offset;
b0e03f5
+	  }
b0e03f5
+	  break;
b0e03f5
+	}
b0e03f5
+    }
b0e03f5
+
d515913
+  type_last_target = type;
d515913
+  type_array = alloca (sizeof (*type_array) * nargs);
d515913
+  i = 0;
d515913
+  for (type = new_array_type; type != type_last_target;
d515913
+       type = TYPE_TARGET_TYPE (type))
d515913
+    type_array[i++] = type;
d515913
+  while (i > 0)
d515913
+    {
d515913
+      struct type *type = type_array[--i];
d515913
+
d515913
+      /* Force TYPE_LENGTH (type) recalculation.  */
d515913
+      TYPE_TARGET_STUB (type) = 1;
d515913
+      check_typedef (type);
d515913
+    }
d515913
+
b0e03f5
+  saved_array = array;
b0e03f5
+  array = allocate_value_lazy (new_array_type);
b0e03f5
+  VALUE_LVAL (array) = VALUE_LVAL (saved_array);
b0e03f5
+  if (VALUE_LVAL (saved_array) == lval_internalvar_component)
b0e03f5
+    VALUE_LVAL (array) = lval_internalvar;
b0e03f5
   else
b0e03f5
-    high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
b0e03f5
+    VALUE_LVAL (array) = VALUE_LVAL (saved_array);
b0e03f5
+  VALUE_FRAME_ID (array) = VALUE_FRAME_ID (saved_array);
b0e03f5
+  if (VALUE_LVAL (array) != lval_internalvar)
b0e03f5
+    set_value_address (array, value_byte_address + value_byte_offset);
254f0e9
+
872aab0
+  if (!value_lazy (saved_array)
872aab0
+      && TYPE_LENGTH (value_type (saved_array)) > 0
872aab0
+      && TYPE_LENGTH (new_array_type) > 0)
b0e03f5
+    {
872aab0
+      gdb_assert (TYPE_LENGTH (new_array_type)
872aab0
+		  <= TYPE_LENGTH (value_type (saved_array)));
b0e03f5
+      allocate_value_contents (array);
b0e03f5
+      set_value_lazy (array, 0);
872aab0
+
b0e03f5
+      memcpy (value_contents_writeable (array),
b0e03f5
+	      value_contents (saved_array) + value_byte_offset,
b0e03f5
+	      TYPE_LENGTH (new_array_type));
b0e03f5
+    }
872aab0
 
872aab0
-  return value_slice (array, low_bound, high_bound - low_bound + 1);
b0e03f5
+  do_cleanups (old_chain);
b0e03f5
+  return array;
b0e03f5
 }
b0e03f5
 
b0e03f5
 
872aab0
@@ -710,6 +905,7 @@ evaluate_subexp_standard (struct type *expect_type,
e00e5ea
   int save_pos1;
e00e5ea
   struct symbol *function = NULL;
e00e5ea
   char *function_name = NULL;
e00e5ea
+  struct cleanup *old_chain;
79563d6
 
e00e5ea
   pc = (*pos)++;
e00e5ea
   op = exp->elts[pc].opcode;
872aab0
@@ -1776,6 +1972,8 @@ evaluate_subexp_standard (struct type *expect_type,
79563d6
 
e00e5ea
       /* First determine the type code we are dealing with.  */
e00e5ea
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
e00e5ea
+      old_chain = make_cleanup (null_cleanup, 0);
e00e5ea
+      object_address_set (value_raw_address (arg1));
e00e5ea
       type = check_typedef (value_type (arg1));
e00e5ea
       code = TYPE_CODE (type);
79563d6
 
872aab0
@@ -1796,23 +1994,13 @@ evaluate_subexp_standard (struct type *expect_type,
e00e5ea
 	      code = TYPE_CODE (type);
e00e5ea
 	    }
e00e5ea
 	} 
e00e5ea
+      do_cleanups (old_chain);
79563d6
 
e00e5ea
       switch (code)
dd46ae6
 	{
b0e03f5
 	case TYPE_CODE_ARRAY:
b0e03f5
-	  if (exp->elts[*pos].opcode == OP_F90_RANGE)
b0e03f5
-	    return value_f90_subarray (arg1, exp, pos, noside);
b0e03f5
-	  else
b0e03f5
-	    goto multi_f77_subscript;
b0e03f5
-
b0e03f5
 	case TYPE_CODE_STRING:
b0e03f5
-	  if (exp->elts[*pos].opcode == OP_F90_RANGE)
b0e03f5
-	    return value_f90_subarray (arg1, exp, pos, noside);
b0e03f5
-	  else
b0e03f5
-	    {
b0e03f5
-	      arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
b0e03f5
-	      return value_subscript (arg1, value_as_long (arg2));
b0e03f5
-	    }
b0e03f5
+	  return value_f90_subarray (arg1, exp, pos, nargs, noside);
79563d6
 
b0e03f5
 	case TYPE_CODE_PTR:
b0e03f5
 	case TYPE_CODE_FUNC:
872aab0
@@ -2225,49 +2413,6 @@ evaluate_subexp_standard (struct type *expect_type,
b0e03f5
 	}
b0e03f5
       return (arg1);
dd46ae6
 
b0e03f5
-    multi_f77_subscript:
b0e03f5
-      {
b0e03f5
-	LONGEST subscript_array[MAX_FORTRAN_DIMS];
b0e03f5
-	int ndimensions = 1, i;
b0e03f5
-	struct value *array = arg1;
b0e03f5
-
b0e03f5
-	if (nargs > MAX_FORTRAN_DIMS)
b0e03f5
-	  error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
b0e03f5
-
b0e03f5
-	ndimensions = calc_f77_array_dims (type);
b0e03f5
-
b0e03f5
-	if (nargs != ndimensions)
b0e03f5
-	  error (_("Wrong number of subscripts"));
b0e03f5
-
b0e03f5
-	gdb_assert (nargs > 0);
b0e03f5
-
b0e03f5
-	/* Now that we know we have a legal array subscript expression 
b0e03f5
-	   let us actually find out where this element exists in the array.  */
b0e03f5
-
b0e03f5
-	/* Take array indices left to right.  */
b0e03f5
-	for (i = 0; i < nargs; i++)
b0e03f5
-	  {
b0e03f5
-	    /* Evaluate each subscript; it must be a legal integer in F77.  */
b0e03f5
-	    arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
b0e03f5
-
b0e03f5
-	    /* Fill in the subscript array.  */
b0e03f5
-
b0e03f5
-	    subscript_array[i] = value_as_long (arg2);
b0e03f5
-	  }
b0e03f5
-
b0e03f5
-	/* Internal type of array is arranged right to left.  */
b0e03f5
-	for (i = nargs; i > 0; i--)
b0e03f5
-	  {
b0e03f5
-	    struct type *array_type = check_typedef (value_type (array));
b0e03f5
-	    LONGEST index = subscript_array[i - 1];
b0e03f5
-
556378e
-	    array = value_subscripted_rvalue (array, index,
556378e
-					      f77_get_lowerbound (array_type));
b0e03f5
-	  }
b0e03f5
-
b0e03f5
-	return array;
b0e03f5
-      }
b0e03f5
-
e00e5ea
     case BINOP_LOGICAL_AND:
b0e03f5
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
b0e03f5
       if (noside == EVAL_SKIP)
872aab0
@@ -2499,15 +2644,23 @@ evaluate_subexp_standard (struct type *expect_type,
e00e5ea
       if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
e00e5ea
 	expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
e00e5ea
       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
e00e5ea
+      old_chain = make_cleanup (null_cleanup, 0);
e00e5ea
+      object_address_set (value_raw_address (arg1));
e00e5ea
       type = check_typedef (value_type (arg1));
e00e5ea
       if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
e00e5ea
 	  || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
33ff709
 	error (_("Attempt to dereference pointer "
33ff709
 		 "to member without an object"));
e00e5ea
       if (noside == EVAL_SKIP)
e00e5ea
-	goto nosideret;
20f9f67
+	{
e00e5ea
+	  do_cleanups (old_chain);
e00e5ea
+	  goto nosideret;
e00e5ea
+	}
e00e5ea
       if (unop_user_defined_p (op, arg1))
e00e5ea
-	return value_x_unop (arg1, op, noside);
e00e5ea
+	{
e00e5ea
+	  do_cleanups (old_chain);
e00e5ea
+	  return value_x_unop (arg1, op, noside);
e00e5ea
+	}
e00e5ea
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
e00e5ea
 	{
e00e5ea
 	  type = check_typedef (value_type (arg1));
872aab0
@@ -2516,12 +2669,18 @@ evaluate_subexp_standard (struct type *expect_type,
e00e5ea
 	  /* In C you can dereference an array to get the 1st elt.  */
e00e5ea
 	      || TYPE_CODE (type) == TYPE_CODE_ARRAY
e00e5ea
 	    )
e00e5ea
-	    return value_zero (TYPE_TARGET_TYPE (type),
e00e5ea
-			       lval_memory);
20f9f67
+	    {
e00e5ea
+	      do_cleanups (old_chain);
e00e5ea
+	      return value_zero (TYPE_TARGET_TYPE (type),
e00e5ea
+				 lval_memory);
20f9f67
+	    }
e00e5ea
 	  else if (TYPE_CODE (type) == TYPE_CODE_INT)
e00e5ea
-	    /* GDB allows dereferencing an int.  */
e00e5ea
-	    return value_zero (builtin_type (exp->gdbarch)->builtin_int,
e00e5ea
-			       lval_memory);
20f9f67
+	    {
e00e5ea
+	      do_cleanups (old_chain);
e00e5ea
+	      /* GDB allows dereferencing an int.  */
e00e5ea
+	      return value_zero (builtin_type (exp->gdbarch)->builtin_int,
e00e5ea
+				 lval_memory);
20f9f67
+	    }
e00e5ea
 	  else
e00e5ea
 	    error (_("Attempt to take contents of a non-pointer value."));
e00e5ea
 	}
872aab0
@@ -2531,9 +2690,14 @@ evaluate_subexp_standard (struct type *expect_type,
e00e5ea
 	 do.  "long long" variables are rare enough that
e00e5ea
 	 BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
e00e5ea
       if (TYPE_CODE (type) == TYPE_CODE_INT)
e00e5ea
-	return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
e00e5ea
-			      (CORE_ADDR) value_as_address (arg1));
e00e5ea
-      return value_ind (arg1);
20f9f67
+	{
e00e5ea
+	  do_cleanups (old_chain);
e00e5ea
+	  return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
e00e5ea
+				(CORE_ADDR) value_as_address (arg1));
20f9f67
+	}
e00e5ea
+      arg1 = value_ind (arg1);
e00e5ea
+      do_cleanups (old_chain);
e00e5ea
+      return arg1;
79563d6
 
e00e5ea
     case UNOP_ADDR:
e00e5ea
       /* C++: check for and handle pointer to members.  */
872aab0
@@ -2963,7 +3127,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
e00e5ea
 {
e00e5ea
   enum exp_opcode op;
e00e5ea
   int pc;
e00e5ea
-  struct value *val;
e00e5ea
+  struct value *val = NULL;
e00e5ea
   struct symbol *var;
e00e5ea
   struct type *type;
79563d6
 
872aab0
@@ -2974,13 +3138,18 @@ evaluate_subexp_with_coercion (struct expression *exp,
e00e5ea
     {
e00e5ea
     case OP_VAR_VALUE:
e00e5ea
       var = exp->elts[pc + 2].symbol;
e00e5ea
+      /* address_of_variable will call object_address_set for check_typedef.
e00e5ea
+	 Call it only if required as it can error-out on VAR in register.  */
e00e5ea
+      if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
e00e5ea
+	val = address_of_variable (var, exp->elts[pc + 1].block);
e00e5ea
       type = check_typedef (SYMBOL_TYPE (var));
e00e5ea
       if (TYPE_CODE (type) == TYPE_CODE_ARRAY
e00e5ea
 	  && !TYPE_VECTOR (type)
e00e5ea
 	  && CAST_IS_CONVERSION (exp->language_defn))
e00e5ea
 	{
e00e5ea
 	  (*pos) += 4;
e00e5ea
-	  val = address_of_variable (var, exp->elts[pc + 1].block);
e00e5ea
+	  if (!val)
e00e5ea
+	    val = address_of_variable (var, exp->elts[pc + 1].block);
e00e5ea
 	  return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
e00e5ea
 			     val);
e00e5ea
 	}
872aab0
@@ -3038,9 +3207,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
dd46ae6
 
e00e5ea
     case OP_VAR_VALUE:
e00e5ea
       (*pos) += 4;
e00e5ea
-      type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
e00e5ea
-      return
e00e5ea
-	value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
e00e5ea
+      /* We do not need to call read_var_value but the object evaluation may
e00e5ea
+	 need to have executed object_address_set which needs valid
e00e5ea
+	 SYMBOL_VALUE_ADDRESS of the symbol.  Still VALUE returned by
e00e5ea
+	 read_var_value we left as lazy.  */
e00e5ea
+      type = value_type (read_var_value (exp->elts[pc + 2].symbol,
e00e5ea
+					deprecated_safe_get_selected_frame ()));
e00e5ea
+      return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
dd46ae6
 
e00e5ea
     default:
e00e5ea
       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
872aab0
@@ -3071,18 +3244,25 @@ parse_and_eval_type (char *p, int length)
b0e03f5
 int
b0e03f5
 calc_f77_array_dims (struct type *array_type)
b0e03f5
 {
b0e03f5
-  int ndimen = 1;
b0e03f5
-  struct type *tmp_type;
b0e03f5
+  switch (TYPE_CODE (array_type))
b0e03f5
+    {
b0e03f5
+    case TYPE_CODE_STRING:
b0e03f5
+      return 1;
b0e03f5
 
b0e03f5
-  if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
b0e03f5
-    error (_("Can't get dimensions for a non-array type"));
b0e03f5
+    case TYPE_CODE_ARRAY:
b0e03f5
+      {
b0e03f5
+	int ndimen = 1;
b0e03f5
 
b0e03f5
-  tmp_type = array_type;
b0e03f5
+	while ((array_type = TYPE_TARGET_TYPE (array_type)))
b0e03f5
+	  {
b0e03f5
+	    if (TYPE_CODE (array_type) == TYPE_CODE_ARRAY)
b0e03f5
+	      ++ndimen;
b0e03f5
+	  }
b0e03f5
+	return ndimen;
b0e03f5
+      }
b0e03f5
 
b0e03f5
-  while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
b0e03f5
-    {
b0e03f5
-      if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
b0e03f5
-	++ndimen;
b0e03f5
+    default:
b0e03f5
+      error (_("Can't get dimensions for a non-array/non-string type"));
b0e03f5
     }
b0e03f5
-  return ndimen;
b0e03f5
+
b0e03f5
 }
254f0e9
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
556378e
index 846cc02..9283183 100644
254f0e9
--- a/gdb/f-exp.y
254f0e9
+++ b/gdb/f-exp.y
556378e
@@ -297,7 +297,9 @@ arglist :	subrange
b0e03f5
 			{ arglist_len = 1; }
b0e03f5
 	;
b0e03f5
    
b0e03f5
-arglist	:	arglist ',' exp   %prec ABOVE_COMMA
b0e03f5
+arglist	:	arglist ',' exp       %prec ABOVE_COMMA
b0e03f5
+			{ arglist_len++; }
b0e03f5
+	|	arglist ',' subrange  %prec ABOVE_COMMA
b0e03f5
 			{ arglist_len++; }
b0e03f5
 	;
b0e03f5
 
254f0e9
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
556378e
index 4ef1acf..8da016b 100644
254f0e9
--- a/gdb/f-lang.h
254f0e9
+++ b/gdb/f-lang.h
556378e
@@ -29,6 +29,10 @@ extern void f_error (char *);	/* Defined in f-exp.y */
e00e5ea
 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
556378e
 			  int, const struct type_print_options *);
79563d6
 
e00e5ea
+extern const char *f_object_address_data_valid_print_to_stream
e00e5ea
+  (struct type *type, struct ui_file *stream);
e00e5ea
+extern void f_object_address_data_valid_or_error (struct type *type);
20f9f67
+
f8eee05
 extern void f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
f8eee05
 			 struct ui_file *, int,
f8eee05
 			 const struct value *,
254f0e9
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
556378e
index aa33231..df998c4 100644
254f0e9
--- a/gdb/f-typeprint.c
254f0e9
+++ b/gdb/f-typeprint.c
556378e
@@ -30,7 +30,7 @@
e00e5ea
 #include "gdbcore.h"
e00e5ea
 #include "target.h"
e00e5ea
 #include "f-lang.h"
e00e5ea
-
e00e5ea
+#include "dwarf2loc.h"
e00e5ea
 #include "gdb_string.h"
e00e5ea
 #include <errno.h>
79563d6
 
556378e
@@ -47,6 +47,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
e00e5ea
 void f_type_print_base (struct type *, struct ui_file *, int, int);
e00e5ea
 
e00e5ea
 
e00e5ea
+const char *
e00e5ea
+f_object_address_data_valid_print_to_stream (struct type *type,
e00e5ea
+					     struct ui_file *stream)
e00e5ea
+{
e00e5ea
+  const char *msg;
e00e5ea
+
e00e5ea
+  msg = object_address_data_not_valid (type);
e00e5ea
+  if (msg != NULL)
20f9f67
+    {
e00e5ea
+      /* Assuming the content printed to STREAM should not be localized.  */
e00e5ea
+      fprintf_filtered (stream, "<%s>", msg);
20f9f67
+    }
20f9f67
+
e00e5ea
+  return msg;
e00e5ea
+}
20f9f67
+
e00e5ea
+void
e00e5ea
+f_object_address_data_valid_or_error (struct type *type)
e00e5ea
+{
e00e5ea
+  const char *msg;
20f9f67
+
e00e5ea
+  msg = object_address_data_not_valid (type);
e00e5ea
+  if (msg != NULL)
20f9f67
+    {
e00e5ea
+      error (_("Cannot access it because the %s."), _(msg));
20f9f67
+    }
e00e5ea
+}
20f9f67
+
e00e5ea
 /* LEVEL is the depth to indent lines by.  */
e00e5ea
 
e00e5ea
 void
556378e
@@ -56,6 +84,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
e00e5ea
   enum type_code code;
e00e5ea
   int demangled_args;
e00e5ea
 
e00e5ea